Subversion Repositories Kolibri OS

Rev

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