Subversion Repositories Kolibri OS

Rev

Rev 8622 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #ifndef _KSYS_H_
  2. #define _KSYS_H_
  3.  
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7.  
  8. #include <stddef.h>
  9.  
  10. #define asm_inline __asm__ __volatile__
  11. #define not_optimized __attribute__((optimize("O0")))
  12.  
  13. #define _KOS_FS_ERR_SUCCESS 0  // Success
  14. #define _KOS_FS_ERR_1       1  // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8)
  15. #define _KOS_FS_ERR_2       2  // Function is not supported for the given file system
  16. #define _KOS_FS_ERR_3       3  // Unknown file system
  17. #define _KOS_FS_ERR_4       4  // Reserved, is never returned in the current implementation
  18. #define _KOS_FS_ERR_5       5  // File not found
  19. #define _KOS_FS_ERR_EOF     6  // End of file, EOF
  20. #define _KOS_FS_ERR_7       7  // Pointer lies outside of application memory
  21. #define _KOS_FS_ERR_8       8  // Disk is full
  22. #define _KOS_FS_ERR_9       9  // FAT table is destroyed
  23. #define _KOS_FS_ERR_10      10 // Access denied
  24. #define _KOS_FS_ERR_11      11 // Device error
  25.  
  26. typedef struct {
  27.     unsigned char blue;
  28.     unsigned char green;
  29.     unsigned char red;
  30. }rgb_t;
  31.  
  32. #pragma pack(push,1)
  33. typedef union{
  34.     unsigned val;
  35.     struct{
  36.         short  x;
  37.         short  y;
  38.     };
  39. }ksys_pos_t;
  40.  
  41. typedef union ksys_oskey_t{
  42.     unsigned val;
  43.     struct{
  44.         unsigned char state;
  45.         unsigned char code;
  46.         unsigned char ctrl_key;
  47.     };
  48. }ksys_oskey_t;
  49.  
  50. typedef struct{
  51.   unsigned     handle;
  52.   unsigned     io_code;
  53.   unsigned     *input;
  54.   int          inp_size;
  55.   void         *output;
  56.   int          out_size;
  57. }ksys_ioctl_t;
  58.  
  59. typedef struct{
  60.     void *data;
  61.     size_t size;
  62. }ksys_ufile_t;
  63.  
  64.  
  65. typedef struct{
  66.     unsigned            p00;
  67.     union{
  68.         uint64_t        p04;
  69.         struct {
  70.             unsigned    p04dw;
  71.             unsigned    p08dw;
  72.         };
  73.     };
  74.     unsigned            p12;
  75.     union {
  76.         unsigned        p16;
  77.         const char     *new_name;
  78.         void           *bdfe;
  79.         void           *buf16;
  80.         const void     *cbuf16;
  81.     };
  82.     char                p20;
  83.     const char         *p21;
  84. }ksys70_t;
  85.  
  86.  
  87. typedef struct {
  88.     unsigned attributes;
  89.     unsigned name_cp;
  90.     char creation_time[4];
  91.     char creation_date[4];
  92.     char last_access_time[4];
  93.     char last_access_date[4];
  94.     char last_modification_time[4];
  95.     char last_modification_date[4];
  96.     unsigned long long size;
  97.     char name[0];
  98. }ksys_bdfe_t;
  99.  
  100. typedef struct {
  101.   int cpu_usage;             //+0
  102.   int window_pos_info;       //+4
  103.   short int reserved1;       //+8
  104.   char name[12];             //+10
  105.   int memstart;              //+22
  106.   int memused;               //+26
  107.   int pid;                   //+30
  108.   int winx_start;            //+34
  109.   int winy_start;            //+38
  110.   int winx_size;             //+42
  111.   int winy_size;             //+46
  112.   short int slot_info;       //+50
  113.   short int reserved2;       //+52
  114.   int clientx;               //+54
  115.   int clienty;               //+58
  116.   int clientwidth;           //+62
  117.   int clientheight;          //+66
  118.   unsigned char window_state;//+70
  119.   char reserved3[1024-71];   //+71
  120. }ksys_proc_table_t;
  121.  
  122. typedef unsigned int ksys_color_t;
  123.  
  124. typedef struct{
  125.     ksys_color_t frame_area;
  126.     ksys_color_t grab_bar;
  127.     ksys_color_t grab_bar_button;
  128.     ksys_color_t grab_button_text;
  129.     ksys_color_t grab_text;
  130.     ksys_color_t work_area;
  131.     ksys_color_t work_button;
  132.     ksys_color_t work_button_text;
  133.     ksys_color_t work_text;
  134.     ksys_color_t work_graph;
  135. }ksys_colors_table_t;
  136.  
  137. typedef struct{
  138.     unsigned pid;      // PID of sending thread
  139.     unsigned datalen;  // data bytes
  140.     char     *data;    // data begin
  141. }ksys_ipc_msg;
  142.  
  143. typedef struct{
  144.     unsigned lock;              // nonzero is locked
  145.     unsigned used;              // used bytes in buffer
  146.     ksys_ipc_msg *data;         // data begin
  147. }ksys_ipc_buffer;
  148.  
  149. typedef struct {
  150.     char* func_name;
  151.     void* func_ptr;
  152. }ksys_coff_etable_t;
  153.  
  154. #pragma pack(pop)
  155.  
  156. enum KSYS_EVENTS {
  157.     KSYS_EVENT_NONE = 0,     /* Event queue is empty */
  158.     KSYS_EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
  159.     KSYS_EVENT_KEY = 2,      /* A key on the keyboard was pressed */
  160.     KSYS_EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
  161.     KSYS_EVENT_DESKTOP = 5,  /* Desktop redraw finished */
  162.     KSYS_EVENT_MOUSE = 6,    /* Mouse activity (movement, button press) was detected */
  163.     KSYS_EVENT_IPC = 7,      /* Interprocess communication notify */
  164.     KSYS_EVENT_NETWORK = 8,  /* Network event */
  165.     KSYS_EVENT_DEBUG = 9,    /* Debug subsystem event */
  166.     KSYS_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
  167. };
  168.  
  169. enum KSYS_FILE_ENCODING{
  170.     KSYS_FILE_CP866 =1,
  171.     KSYS_FILE_UTF16LE = 2,
  172.     KSYS_FILE_UTF8 = 3
  173. };
  174.  
  175. enum KSYS_CLIP_ENCODING{
  176.     KSYS_CLIP_UTF8 = 0,
  177.     KSYS_CLIP_CP866 = 1,
  178.     KSYS_CLIP_CP1251 = 2
  179. };
  180.  
  181. enum KSYS_CLIP_TYPES{
  182.     KSYS_CLIP_TEXT = 0,
  183.     KSYS_CLIP_IMAGE = 1,
  184.     KSYS_CLIP_RAW = 2
  185. };
  186.  
  187. static inline
  188. int _ksys_strcmp(const char * s1, const char * s2 )
  189. {
  190.     while ((*s1) && (*s1 == *s2)){
  191.         ++s1;
  192.         ++s2;
  193.     }
  194.  
  195.     return ( *( unsigned char * )s1 - * ( unsigned char * )s2 );
  196. }
  197.  
  198. // Functions for working with the graphical interface
  199.  
  200. static inline
  201. void _ksys_start_draw()
  202. {
  203.    asm_inline("int $0x40"::"a"(12),"b"(1));
  204. }
  205.  
  206. static inline
  207. void _ksys_end_draw()
  208. {
  209.     asm_inline("int $0x40" ::"a"(12),"b"(2));
  210. }
  211.  
  212. static inline
  213. void _ksys_create_window(int x, int y, int w, int h, const char *name, ksys_color_t workcolor, unsigned style)
  214. {
  215.     asm_inline(
  216.         "int $0x40"
  217.         ::"a"(0),
  218.         "b"((x << 16) | ((w-1) & 0xFFFF)),
  219.         "c"((y << 16) | ((h-1) & 0xFFFF)),
  220.         "d"((style << 24) | (workcolor & 0xFFFFFF)),
  221.         "D"(name),
  222.         "S"(0) : "memory"
  223.      );
  224. };
  225.  
  226. static inline
  227. void _ksys_change_window(int new_x, int new_y, int new_w, int new_h)
  228. {
  229.     asm_inline(
  230.         "int $0x40"
  231.         ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
  232.     );
  233. }
  234.  
  235. static inline
  236. void _ksys_define_button(unsigned x, unsigned y, unsigned w, unsigned h, unsigned id, ksys_color_t color)
  237. {
  238.    asm_inline(
  239.         "int $0x40"
  240.         ::"a"(8),
  241.         "b"((x<<16)+w),
  242.         "c"((y<<16)+h),
  243.         "d"(id),
  244.         "S"(color)
  245.     );
  246. };
  247.  
  248. static inline
  249. void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color)
  250. {
  251.     asm_inline(
  252.         "int $0x40"
  253.         ::"a"(38), "d"(color),
  254.         "b"((xs << 16) | xe),
  255.         "c"((ys << 16) | ye)
  256.     );
  257. }
  258.  
  259. static inline
  260. void _ksys_draw_bar(int x, int y, int w, int h, ksys_color_t color)
  261. {
  262.     asm_inline(
  263.         "int $0x40"
  264.         ::"a"(13), "d"(color),
  265.         "b"((x << 16) | w),
  266.         "c"((y << 16) | h)
  267.     );
  268. }
  269.  
  270. static inline
  271. void _ksys_draw_bitmap(void *bitmap, int x, int y, int w, int h)
  272. {
  273.     asm_inline(
  274.         "int $0x40"
  275.         ::"a"(7), "b"(bitmap),
  276.         "c"((w << 16) | h),
  277.         "d"((x << 16) | y)
  278.     );
  279. }
  280.  
  281. static inline
  282. void _ksys_draw_text(const char *text, int x, int y, int len, ksys_color_t color)
  283. {
  284.    asm_inline(
  285.         "int $0x40"
  286.         ::"a"(4),"d"(text),
  287.         "b"((x << 16) | y),
  288.         "S"(len),"c"(color)
  289.         :"memory"
  290.     );
  291. }
  292.  
  293. static inline
  294. void _ksys_draw_text_bg(const char *text, int x, int y, int len, ksys_color_t color, ksys_color_t bg)
  295. {
  296.     asm_inline(
  297.         "int $0x40"
  298.         ::"a"(4),"d"(text),
  299.         "b"((x << 16) | y),
  300.         "S"(len),"c"(color), "D"(bg)
  301.         :"memory"
  302.     );
  303. }
  304.  
  305. static inline
  306. void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color){
  307.     unsigned fmt;
  308.     fmt = len << 16 | 0x80000000; // no leading zeros + width
  309.     asm_inline(
  310.         "int $0x40"
  311.         ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color)
  312.     );
  313. }
  314.  
  315. static inline
  316. void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg){
  317.     unsigned fmt;
  318.     fmt = len << 16 | 0x80000000; // no leading zeros + width
  319.     asm_inline(
  320.         "int $0x40"
  321.         ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg)
  322.     );
  323. }
  324.  
  325. static inline
  326. unsigned _ksys_get_skin_height()
  327. {
  328.     unsigned height;
  329.     asm_inline(
  330.         "int $0x40 \n\t"
  331.         :"=a"(height)
  332.         :"a"(48),"b"(4)
  333.     );
  334.     return height;
  335. }
  336.  
  337. static inline
  338. void _ksys_get_colors(ksys_colors_table_t *color_table)
  339. {
  340.     asm_inline(
  341.        "int $0x40"
  342.         ::"a"(48),"b"(3),"c"(color_table),"d"(40)
  343.     );
  344. }
  345.  
  346.  
  347. /* Functions for working with a mouse and cursors. */
  348.  
  349. static inline
  350. ksys_pos_t _ksys_get_mouse_pos(int origin)
  351. {
  352.     ksys_pos_t val;
  353.     asm_inline(
  354.         "int $0x40 \n\t"
  355.         "rol $16, %%eax"
  356.         :"=a"(val)
  357.         :"a"(37),"b"(origin)
  358.     );
  359.     return val;
  360. }
  361.  
  362. static inline
  363. unsigned _ksys_get_mouse_buttons()
  364. {
  365.     unsigned val;
  366.     asm_inline(
  367.         "int $0x40"
  368.         :"=a"(val)
  369.         :"a"(37),"b"(2)
  370.     );
  371.     return val;
  372. }
  373.  
  374. static inline
  375. unsigned _ksys_get_mouse_wheels()
  376. {
  377.     unsigned val;
  378.     asm_inline(
  379.         "int $0x40 \n\t"
  380.         :"=a"(val)
  381.         :"a"(37),"b"(7)
  382.     );
  383.     return val;
  384. }
  385.  
  386. static inline
  387. unsigned _ksys_load_cursor(void *path, unsigned flags)
  388. {
  389.     unsigned val;
  390.     asm_inline(
  391.         "int $0x40"
  392.         :"=a"(val)
  393.         :"a"(37), "b"(4), "c"(path), "d"(flags)
  394.     );
  395.     return val;
  396. }
  397.  
  398. static inline
  399. unsigned _ksys_set_cursor(unsigned  cursor)
  400. {
  401.     unsigned old;
  402.     asm_inline(
  403.         "int $0x40"
  404.         :"=a"(old)
  405.         :"a"(37), "b"(5), "c"(cursor)
  406.     );
  407.     return old;
  408. }
  409.  
  410. static inline
  411. int _ksys_destroy_cursor(unsigned cursor)
  412. {
  413.     int ret;
  414.     asm_inline(
  415.         "int $0x40"
  416.         :"=a"(ret)
  417.         :"a"(37), "b"(6), "c"(cursor)
  418.         :"memory"
  419.     );
  420.     return ret;
  421. }
  422.  
  423. static inline
  424. unsigned _ksys_get_mouse_eventstate()
  425. {
  426.     unsigned val;
  427.     asm_inline(
  428.         "int $0x40"
  429.         :"=a"(val)
  430.         :"a"(37),"b"(3)
  431.     );
  432.     return val;
  433. }
  434.  
  435.  
  436. /* Functions for working with events and buttons. */
  437.  
  438. static inline
  439. unsigned _ksys_set_event_mask(unsigned mask)
  440. {
  441.     unsigned val;
  442.     asm_inline(
  443.         "int $0x40"
  444.         :"=a"(val)
  445.         :"a"(40), "b"(mask)
  446.     );
  447.     return val;
  448. }
  449.  
  450. static inline
  451. unsigned _ksys_wait_event(unsigned time)
  452. {
  453.     unsigned val;
  454.     asm_inline(
  455.         "int $0x40"
  456.         :"=a"(val)
  457.         :"a"(23), "b"(time)
  458.     );
  459.     return val;
  460. }
  461.  
  462. static inline
  463. unsigned _ksys_check_event()
  464. {
  465.     unsigned val;
  466.     asm_inline(
  467.         "int $0x40"
  468.         :"=a"(val)
  469.         :"a"(11)
  470.     );
  471.     return val;
  472. }
  473.  
  474. static inline
  475. unsigned _ksys_get_event()
  476. {
  477.     unsigned val;
  478.     asm_inline(
  479.         "int $0x40"
  480.         :"=a"(val)
  481.         :"a"(10)
  482.     );
  483.     return val;
  484. }
  485.  
  486. static inline
  487. unsigned _ksys_get_button()
  488. {
  489.     unsigned val;
  490.     asm_inline(
  491.         "int $0x40"
  492.         :"=a"(val)
  493.         :"a"(17)
  494.     );
  495.     return val>>8;
  496. }
  497.  
  498. static inline
  499. ksys_oskey_t _ksys_get_key(void)
  500. {
  501.     ksys_oskey_t val;
  502.     asm_inline(
  503.         "int $0x40"
  504.         :"=a"(val)
  505.         :"a"(2)
  506.     );
  507.     return val;
  508. }
  509.  
  510. /* Functions for working with the clipboard */
  511.  
  512. static inline
  513. int _ksys_clip_num()
  514. {
  515.     unsigned val;
  516.     asm_inline(
  517.         "int $0x40"
  518.         :"=a"(val)
  519.         :"a"(54), "b"(0)
  520.     );
  521.     return val;
  522. }
  523.  
  524. static inline
  525. char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free()
  526. {
  527.     char* val;
  528.     asm_inline(
  529.         "int $0x40"
  530.         :"=a"(val)
  531.         :"a"(54), "b"(1), "c"(n)
  532.     );
  533.     return val;
  534. }
  535.  
  536. static inline
  537. int _ksys_clip_set(int n, char *buffer)
  538. {
  539.     unsigned val;
  540.     asm_inline(
  541.         "int $0x40"
  542.         :"=a"(val)
  543.         :"a"(54), "b"(2), "c"(n), "d"(buffer)
  544.     );
  545.     return val;
  546. }
  547.  
  548. static inline
  549. int _ksys_clip_pop()
  550. {
  551.     unsigned val;
  552.     asm_inline (
  553.         "int $0x40"
  554.         :"=a"(val)
  555.         :"a"(54), "b"(3)
  556.     );
  557.     return val;
  558. }
  559.  
  560. static inline
  561. int _ksys_clip_unlock()
  562. {
  563.     unsigned val;
  564.     asm_inline(
  565.         "int $0x40"
  566.         :"=a"(val)
  567.         :"a"(54), "b"(4)
  568.     );
  569.     return val;
  570. }
  571.  
  572.  
  573. /* Working with time */
  574.  
  575. static inline
  576. unsigned _ksys_get_tick_count()
  577. {
  578.     unsigned val;
  579.     asm_inline(
  580.         "int $0x40"
  581.         :"=a"(val)
  582.         :"a"(26),"b"(9)
  583.     );
  584.     return val;
  585. }
  586.  
  587. static inline
  588. uint64_t  _ksys_get_ns_count()
  589. {
  590.     uint64_t val;
  591.     asm_inline(
  592.         "int $0x40"
  593.         :"=A"(val)
  594.         :"a"(26), "b"(10)
  595.     );
  596.     return val;
  597. }
  598.  
  599. static inline
  600. void _ksys_delay(unsigned time)
  601. {
  602.     asm_inline(
  603.         "int $0x40"
  604.         ::"a"(5), "b"(time)
  605.         :"memory"
  606.     );
  607. }
  608.  
  609. static inline
  610. unsigned _ksys_get_date()
  611. {
  612.     unsigned val;
  613.     asm_inline("int $0x40":"=a"(val):"a"(29));
  614.     return val;
  615. }
  616.  
  617. static inline
  618. unsigned _ksys_get_clock()
  619. {
  620.     unsigned val;
  621.     asm_inline("int $0x40":"=a"(val):"a"(3));
  622.     return val;
  623. }
  624.  
  625.  
  626. /* Working with memory allocation */
  627.  
  628. static inline
  629. void* _ksys_alloc(size_t size){
  630.     void  *val;
  631.     asm_inline(
  632.         "int $0x40"
  633.         :"=a"(val)
  634.         :"a"(68),"b"(12),"c"(size)
  635.     );
  636.     return val;
  637. }
  638.  
  639. static inline
  640. int _ksys_free(void *mem)
  641. {
  642.     int val;
  643.     asm_inline(
  644.         "int $0x40"
  645.         :"=a"(val)
  646.         :"a"(68),"b"(13),"c"(mem)
  647.     );
  648.     return val;
  649. }
  650.  
  651. static inline
  652. void* _ksys_realloc(void *mem, size_t size)
  653. {
  654.     void *val;
  655.     asm_inline(
  656.         "int $0x40"
  657.         :"=a"(val)
  658.         :"a"(68),"b"(20),"c"(size),"d"(mem)
  659.         :"memory"
  660.     );
  661.     return val;
  662. }
  663.  
  664. static inline
  665. int* _ksys_unmap(void *base, size_t offset, size_t size)
  666. {
  667.     int  *val;
  668.     asm_inline(
  669.         "int $0x40"
  670.         :"=a"(val)
  671.         :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)
  672.     );
  673.     return val;
  674. }
  675.  
  676.  
  677. /* Loading the dynamic coff library */
  678.  
  679. static inline
  680. ksys_coff_etable_t* not_optimized _ksys_cofflib_load(const char* path)
  681. {
  682.     ksys_coff_etable_t *table;
  683.     asm_inline(
  684.         "int $0x40"
  685.         :"=a"(table)
  686.         :"a"(68),"b"(19), "c"(path)
  687.     );
  688.     return table;
  689. }
  690.  
  691. static inline
  692. void* not_optimized _ksys_cofflib_getproc(ksys_coff_etable_t *table, const char* fun_name)
  693. {
  694.     unsigned i=0;
  695.     while (1){
  696.         if (NULL == (table+i)->func_name){
  697.             break;
  698.         }else{
  699.             if (!_ksys_strcmp(fun_name, (table+i)->func_name)){
  700.                 return (table+i)->func_ptr;
  701.             }
  702.         }
  703.         i++;
  704.     }
  705.     return NULL;
  706. }
  707.  
  708.  
  709. /* Debug board functions */
  710.  
  711. static inline
  712. void _ksys_debug_putc(char c)
  713. {
  714.     asm_inline("int $0x40"::"a"(63), "b"(1), "c"(c));
  715. }
  716.  
  717. static inline
  718. void _ksys_debug_puts(char *s)
  719. {
  720.     unsigned i=0;
  721.     while (*(s+i)){
  722.         asm_inline ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
  723.         i++;
  724.     }
  725. }
  726.  
  727.  
  728. /* Working with threads and process */
  729.  
  730. static inline
  731. int _ksys_start_thread(void* proc, char* stack_top)
  732. {
  733.     int val;
  734.     asm_inline(
  735.         "int $0x40"
  736.         :"=a"(val)
  737.         :"a"(51), "b"(1), "c"(proc), "d"(stack_top)
  738.     );
  739.     return val;
  740. }
  741.  
  742. static inline
  743. void _ksys_focus_window(int slot){
  744.     asm_inline(
  745.         "int $0x40"
  746.         ::"a"(18), "b"(3), "c"(slot)
  747.     );
  748. }
  749.  
  750. static inline
  751. int _ksys_get_thread_slot(int tid){
  752.     int val;
  753.     asm_inline(
  754.         "int $0x40"
  755.         :"=a"(val)
  756.         :"a"(18), "b"(21), "c"(tid)
  757.     );
  758.     return val;
  759. }
  760.  
  761. static inline
  762. int not_optimized _ksys_process_info(ksys_proc_table_t* table, int pid)
  763. {
  764.     int val;
  765.     asm_inline(
  766.         "int $0x40"
  767.         :"=a"(val)
  768.         :"a"(9), "b"(table), "c"(pid)
  769.     );
  770.     return val;
  771. }
  772.  
  773. static inline
  774. void _ksys_exit()
  775. {
  776.     asm_inline("int $0x40"::"a"(-1));
  777. }
  778.  
  779.  
  780. /* Working with files and directories */
  781.  
  782. static inline
  783. void _ksys_setcwd(char* dir){
  784.     asm_inline(
  785.         "int $0x40"
  786.         ::"a"(30), "b"(1), "c"(dir)
  787.     );
  788. }
  789.  
  790. static inline
  791. int _ksys_getcwd(char* buf, int bufsize){
  792.     register int val;
  793.     asm_inline(
  794.         "int $0x40"
  795.         :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize)
  796.     );
  797.     return val;
  798. }
  799.  
  800. static inline
  801. ksys_ufile_t _ksys_load_file(const char *path)
  802. {
  803.     ksys_ufile_t uf;
  804.     asm_inline(
  805.         "int $0x40"
  806.         :"=a"(uf.data), "=d"(uf.size)
  807.         :"a"(68), "b"(27),"c"(path)
  808.     );
  809.     return uf;
  810. }
  811.  
  812. static inline
  813. ksys_ufile_t _ksys_load_file_enc(const char *path, unsigned file_encoding)
  814. {
  815.     ksys_ufile_t uf;
  816.     asm_inline(
  817.         "int $0x40"
  818.         :"=a"(uf.data), "=d"(uf.size)
  819.         :"a"(68), "b"(28),"c"(path), "d"(file_encoding)
  820.     );
  821.     return uf;
  822. }
  823.  
  824. static inline
  825. int not_optimized _ksys_work_files(const ksys70_t *k)
  826. {
  827.     int status;
  828.     asm_inline(
  829.         "int $0x40"
  830.         :"=a"(status)
  831.         :"a"(70), "b"(k)
  832.     );
  833.     return status;
  834. }
  835.  
  836. static inline
  837. int not_optimized _ksys_file_read_file(const char *name, unsigned long long offset, unsigned size, void *buf, unsigned *bytes_read)
  838. {
  839.     ksys70_t k;
  840.     k.p00 = 0;
  841.     k.p04 = offset;
  842.     k.p12 = size;
  843.     k.buf16 = buf;
  844.     k.p20 = 0;
  845.     k.p21 = name;
  846.     int status;
  847.     unsigned bytes_read_v;
  848.     asm_inline(
  849.         "int $0x40"
  850.         :"=a"(status), "=b"(bytes_read_v)
  851.         :"a"(70), "b"(&k)
  852.     );
  853.     if (!status) {
  854.         *bytes_read = bytes_read_v;
  855.     }
  856.     return status;
  857. }
  858.  
  859. static inline
  860. int not_optimized _ksys_file_write_file(const char *name, unsigned long long offset, unsigned size, const void *buf, unsigned *bytes_written)
  861. {
  862.     ksys70_t k;
  863.     k.p00 = 3;
  864.     k.p04 = offset;
  865.     k.p12 = size;
  866.     k.cbuf16 = buf;
  867.     k.p20 = 0;
  868.     k.p21 = name;
  869.     int status;
  870.     unsigned bytes_written_v;
  871.     asm_inline(
  872.         "int $0x40"
  873.         :"=a"(status), "=b"(bytes_written_v)
  874.         :"a"(70), "b"(&k)
  875.     );
  876.     if (!status) {
  877.         *bytes_written = bytes_written_v;
  878.     }
  879.     return status;
  880. }
  881.  
  882. static inline
  883. int not_optimized _ksys_file_get_info(const char *name, ksys_bdfe_t *bdfe)
  884. {
  885.     ksys70_t k;
  886.     k.p00 = 5;
  887.     k.bdfe = bdfe;
  888.     k.p20 = 0;
  889.     k.p21 = name;
  890.     return _ksys_work_files(&k);
  891. }
  892.  
  893. static inline
  894. int not_optimized _ksys_file_delete(const char *name)
  895. {
  896.     ksys70_t k;
  897.     k.p00 = 8;
  898.     k.p20 = 0;
  899.     k.p21 = name;
  900.     return _ksys_work_files(&k);
  901. }
  902.  
  903. static inline
  904. int not_optimized _ksys_file_rename(const char *name, const char *new_name)
  905. {
  906.     ksys70_t k;
  907.     k.p00 = 10;
  908.     k.new_name = new_name;
  909.     k.p20 = 0;
  910.     k.p21 = name;
  911.     return _ksys_work_files(&k);
  912. }
  913.  
  914.  
  915. static inline
  916. int not_optimized _ksys_exec(char *app_name, char *args){
  917.     ksys70_t file_op;
  918.     file_op.p00 = 7;
  919.     file_op.p04dw = 0;
  920.     file_op.p08dw = (unsigned)args;
  921.     file_op.p21 = app_name;
  922.     register int val;
  923.     asm_inline(
  924.         "int $0x40"
  925.         :"=a"(val)
  926.         :"a"(70), "b"(&file_op)
  927.     );
  928.     return val;
  929. }
  930.  
  931. #endif // _KSYS_H_