Subversion Repositories Kolibri OS

Rev

Rev 8628 | Blame | Compare with Previous | 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 KSYS_FS_ERR_SUCCESS 0  // Success
  14. #define KSYS_FS_ERR_1       1  // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8)
  15. #define KSYS_FS_ERR_2       2  // Function is not supported for the given file system
  16. #define KSYS_FS_ERR_3       3  // Unknown file system
  17. #define KSYS_FS_ERR_4       4  // Reserved, is never returned in the current implementation
  18. #define KSYS_FS_ERR_5       5  // File not found
  19. #define KSYS_FS_ERR_EOF     6  // End of file, EOF
  20. #define KSYS_FS_ERR_7       7  // Pointer lies outside of application memory
  21. #define KSYS_FS_ERR_8       8  // Disk is full
  22. #define KSYS_FS_ERR_9       9  // FAT table is destroyed
  23. #define KSYS_FS_ERR_10      10 // Access denied
  24. #define KSYS_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. enum KSYS_MOUSE_POS{
  188.     KSYS_MOUSE_SCREEN_POS = 0,
  189.     KSYS_MOUSE_WINDOW_POS = 1
  190. };
  191.  
  192. enum KSYS_SHM_MODE{
  193.     KSYS_SHM_OPEN = 0x00,
  194.     KSYS_SHM_OPEN_ALWAYS = 0x04,
  195.     KSYS_SHM_CREATE = 0x08,
  196.     KSYS_SHM_READ = 0x00,
  197.     KSYS_SHM_WRITE = 0x01,
  198. };
  199.  
  200. static inline
  201. int _ksys_strcmp(const char * s1, const char * s2 )
  202. {
  203.     while ((*s1) && (*s1 == *s2)){ ++s1; ++s2; }
  204.     return(*(unsigned char*)s1 - *(unsigned char *)s2);
  205. }
  206.  
  207. // Functions for working with the graphical interface
  208.  
  209. static inline
  210. void _ksys_start_draw()
  211. {
  212.    asm_inline("int $0x40"::"a"(12),"b"(1));
  213. }
  214.  
  215. static inline
  216. void _ksys_end_draw()
  217. {
  218.     asm_inline("int $0x40" ::"a"(12),"b"(2));
  219. }
  220.  
  221. static inline
  222. void _ksys_create_window(int x, int y, int w, int h, const char *name, ksys_color_t workcolor, unsigned style)
  223. {
  224.     asm_inline(
  225.         "int $0x40"
  226.         ::"a"(0),
  227.         "b"((x << 16) | ((w-1) & 0xFFFF)),
  228.         "c"((y << 16) | ((h-1) & 0xFFFF)),
  229.         "d"((style << 24) | (workcolor & 0xFFFFFF)),
  230.         "D"(name),
  231.         "S"(0) : "memory"
  232.      );
  233. };
  234.  
  235. static inline
  236. void _ksys_change_window(int new_x, int new_y, int new_w, int new_h)
  237. {
  238.     asm_inline(
  239.         "int $0x40"
  240.         ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h)
  241.     );
  242. }
  243.  
  244. static inline
  245. void _ksys_define_button(unsigned x, unsigned y, unsigned w, unsigned h, unsigned id, ksys_color_t color)
  246. {
  247.    asm_inline(
  248.         "int $0x40"
  249.         ::"a"(8),
  250.         "b"((x<<16)+w),
  251.         "c"((y<<16)+h),
  252.         "d"(id),
  253.         "S"(color)
  254.     );
  255. };
  256.  
  257. static inline
  258. void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color)
  259. {
  260.     asm_inline(
  261.         "int $0x40"
  262.         ::"a"(38), "d"(color),
  263.         "b"((xs << 16) | xe),
  264.         "c"((ys << 16) | ye)
  265.     );
  266. }
  267.  
  268. static inline
  269. void _ksys_draw_bar(int x, int y, int w, int h, ksys_color_t color)
  270. {
  271.     asm_inline(
  272.         "int $0x40"
  273.         ::"a"(13), "d"(color),
  274.         "b"((x << 16) | w),
  275.         "c"((y << 16) | h)
  276.     );
  277. }
  278.  
  279. static inline
  280. void _ksys_draw_bitmap(void *bitmap, int x, int y, int w, int h)
  281. {
  282.     asm_inline(
  283.         "int $0x40"
  284.         ::"a"(7), "b"(bitmap),
  285.         "c"((w << 16) | h),
  286.         "d"((x << 16) | y)
  287.     );
  288. }
  289.  
  290. static inline
  291. void _ksys_draw_text(const char *text, int x, int y, int len, ksys_color_t color)
  292. {
  293.    asm_inline(
  294.         "int $0x40"
  295.         ::"a"(4),"d"(text),
  296.         "b"((x << 16) | y),
  297.         "S"(len),"c"(color)
  298.         :"memory"
  299.     );
  300. }
  301.  
  302. static inline
  303. void _ksys_draw_text_bg(const char *text, int x, int y, int len, ksys_color_t color, ksys_color_t bg)
  304. {
  305.     asm_inline(
  306.         "int $0x40"
  307.         ::"a"(4),"d"(text),
  308.         "b"((x << 16) | y),
  309.         "S"(len),"c"(color), "D"(bg)
  310.         :"memory"
  311.     );
  312. }
  313.  
  314. static inline
  315. void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color){
  316.     unsigned fmt;
  317.     fmt = len << 16 | 0x80000000; // no leading zeros + width
  318.     asm_inline(
  319.         "int $0x40"
  320.         ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color)
  321.     );
  322. }
  323.  
  324. static inline
  325. void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg){
  326.     unsigned fmt;
  327.     fmt = len << 16 | 0x80000000; // no leading zeros + width
  328.     asm_inline(
  329.         "int $0x40"
  330.         ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg)
  331.     );
  332. }
  333.  
  334. static inline
  335. unsigned _ksys_get_skin_height()
  336. {
  337.     unsigned height;
  338.     asm_inline(
  339.         "int $0x40 \n\t"
  340.         :"=a"(height)
  341.         :"a"(48),"b"(4)
  342.     );
  343.     return height;
  344. }
  345.  
  346. static inline
  347. void _ksys_get_colors(ksys_colors_table_t *color_table)
  348. {
  349.     asm_inline(
  350.        "int $0x40"
  351.         ::"a"(48),"b"(3),"c"(color_table),"d"(40)
  352.     );
  353. }
  354.  
  355.  
  356. /* Functions for working with a mouse and cursors. */
  357.  
  358. static inline
  359. ksys_pos_t _ksys_get_mouse_pos(int origin)
  360. {
  361.     ksys_pos_t val;
  362.     asm_inline(
  363.         "int $0x40 \n\t"
  364.         "rol $16, %%eax"
  365.         :"=a"(val)
  366.         :"a"(37),"b"(origin)
  367.         :"memory"
  368.     );
  369.     return val;
  370. }
  371.  
  372. static inline
  373. unsigned _ksys_get_mouse_buttons()
  374. {
  375.     unsigned val;
  376.     asm_inline(
  377.         "int $0x40"
  378.         :"=a"(val)
  379.         :"a"(37),"b"(2)
  380.     );
  381.     return val;
  382. }
  383.  
  384. static inline
  385. unsigned _ksys_get_mouse_wheels()
  386. {
  387.     unsigned val;
  388.     asm_inline(
  389.         "int $0x40 \n\t"
  390.         :"=a"(val)
  391.         :"a"(37),"b"(7)
  392.     );
  393.     return val;
  394. }
  395.  
  396. static inline
  397. unsigned _ksys_load_cursor(void *path, unsigned flags)
  398. {
  399.     unsigned val;
  400.     asm_inline(
  401.         "int $0x40"
  402.         :"=a"(val)
  403.         :"a"(37), "b"(4), "c"(path), "d"(flags)
  404.     );
  405.     return val;
  406. }
  407.  
  408. static inline
  409. unsigned _ksys_set_cursor(unsigned  cursor)
  410. {
  411.     unsigned old;
  412.     asm_inline(
  413.         "int $0x40"
  414.         :"=a"(old)
  415.         :"a"(37), "b"(5), "c"(cursor)
  416.     );
  417.     return old;
  418. }
  419.  
  420. static inline
  421. int _ksys_destroy_cursor(unsigned cursor)
  422. {
  423.     int ret;
  424.     asm_inline(
  425.         "int $0x40"
  426.         :"=a"(ret)
  427.         :"a"(37), "b"(6), "c"(cursor)
  428.         :"memory"
  429.     );
  430.     return ret;
  431. }
  432.  
  433. static inline
  434. unsigned _ksys_get_mouse_eventstate()
  435. {
  436.     unsigned val;
  437.     asm_inline(
  438.         "int $0x40"
  439.         :"=a"(val)
  440.         :"a"(37),"b"(3)
  441.     );
  442.     return val;
  443. }
  444.  
  445.  
  446. /* Functions for working with events and buttons. */
  447.  
  448. static inline
  449. unsigned _ksys_set_event_mask(unsigned mask)
  450. {
  451.     unsigned val;
  452.     asm_inline(
  453.         "int $0x40"
  454.         :"=a"(val)
  455.         :"a"(40), "b"(mask)
  456.     );
  457.     return val;
  458. }
  459.  
  460. static inline
  461. unsigned _ksys_wait_event(unsigned time)
  462. {
  463.     unsigned val;
  464.     asm_inline(
  465.         "int $0x40"
  466.         :"=a"(val)
  467.         :"a"(23), "b"(time)
  468.     );
  469.     return val;
  470. }
  471.  
  472. static inline
  473. unsigned _ksys_check_event()
  474. {
  475.     unsigned val;
  476.     asm_inline(
  477.         "int $0x40"
  478.         :"=a"(val)
  479.         :"a"(11)
  480.     );
  481.     return val;
  482. }
  483.  
  484. static inline
  485. unsigned _ksys_get_event()
  486. {
  487.     unsigned val;
  488.     asm_inline(
  489.         "int $0x40"
  490.         :"=a"(val)
  491.         :"a"(10)
  492.     );
  493.     return val;
  494. }
  495.  
  496. static inline
  497. unsigned _ksys_get_button()
  498. {
  499.     unsigned val;
  500.     asm_inline(
  501.         "int $0x40"
  502.         :"=a"(val)
  503.         :"a"(17)
  504.     );
  505.     return val>>8;
  506. }
  507.  
  508. static inline
  509. ksys_oskey_t _ksys_get_key(void)
  510. {
  511.     ksys_oskey_t val;
  512.     asm_inline(
  513.         "int $0x40"
  514.         :"=a"(val)
  515.         :"a"(2)
  516.     );
  517.     return val;
  518. }
  519.  
  520. /* Functions for working with the clipboard */
  521.  
  522. static inline
  523. int _ksys_clip_num()
  524. {
  525.     unsigned val;
  526.     asm_inline(
  527.         "int $0x40"
  528.         :"=a"(val)
  529.         :"a"(54), "b"(0)
  530.     );
  531.     return val;
  532. }
  533.  
  534. static inline
  535. char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free()
  536. {
  537.     char* val;
  538.     asm_inline(
  539.         "int $0x40"
  540.         :"=a"(val)
  541.         :"a"(54), "b"(1), "c"(n)
  542.     );
  543.     return val;
  544. }
  545.  
  546. static inline
  547. int _ksys_clip_set(int n, char *buffer)
  548. {
  549.     unsigned val;
  550.     asm_inline(
  551.         "int $0x40"
  552.         :"=a"(val)
  553.         :"a"(54), "b"(2), "c"(n), "d"(buffer)
  554.     );
  555.     return val;
  556. }
  557.  
  558. static inline
  559. int _ksys_clip_pop()
  560. {
  561.     unsigned val;
  562.     asm_inline (
  563.         "int $0x40"
  564.         :"=a"(val)
  565.         :"a"(54), "b"(3)
  566.     );
  567.     return val;
  568. }
  569.  
  570. static inline
  571. int _ksys_clip_unlock()
  572. {
  573.     unsigned val;
  574.     asm_inline(
  575.         "int $0x40"
  576.         :"=a"(val)
  577.         :"a"(54), "b"(4)
  578.     );
  579.     return val;
  580. }
  581.  
  582.  
  583. /* Working with time */
  584.  
  585. static inline
  586. unsigned _ksys_get_tick_count()
  587. {
  588.     unsigned val;
  589.     asm_inline(
  590.         "int $0x40"
  591.         :"=a"(val)
  592.         :"a"(26),"b"(9)
  593.     );
  594.     return val;
  595. }
  596.  
  597. static inline
  598. uint64_t  _ksys_get_ns_count()
  599. {
  600.     uint64_t val;
  601.     asm_inline(
  602.         "int $0x40"
  603.         :"=A"(val)
  604.         :"a"(26), "b"(10)
  605.     );
  606.     return val;
  607. }
  608.  
  609. static inline
  610. void _ksys_delay(unsigned time)
  611. {
  612.     asm_inline(
  613.         "int $0x40"
  614.         ::"a"(5), "b"(time)
  615.         :"memory"
  616.     );
  617. }
  618.  
  619. static inline
  620. unsigned _ksys_get_date()
  621. {
  622.     unsigned val;
  623.     asm_inline("int $0x40":"=a"(val):"a"(29));
  624.     return val;
  625. }
  626.  
  627. static inline
  628. unsigned _ksys_get_clock()
  629. {
  630.     unsigned val;
  631.     asm_inline("int $0x40":"=a"(val):"a"(3));
  632.     return val;
  633. }
  634.  
  635.  
  636. /* Working with memory allocation */
  637.  
  638. static inline
  639. void* _ksys_alloc(size_t size){
  640.     void  *val;
  641.     asm_inline(
  642.         "int $0x40"
  643.         :"=a"(val)
  644.         :"a"(68),"b"(12),"c"(size)
  645.     );
  646.     return val;
  647. }
  648.  
  649. static inline
  650. int _ksys_free(void *mem)
  651. {
  652.     int val;
  653.     asm_inline(
  654.         "int $0x40"
  655.         :"=a"(val)
  656.         :"a"(68),"b"(13),"c"(mem)
  657.     );
  658.     return val;
  659. }
  660.  
  661. static inline
  662. void* _ksys_realloc(void *mem, size_t size)
  663. {
  664.     void *val;
  665.     asm_inline(
  666.         "int $0x40"
  667.         :"=a"(val)
  668.         :"a"(68),"b"(20),"c"(size),"d"(mem)
  669.         :"memory"
  670.     );
  671.     return val;
  672. }
  673.  
  674. static inline
  675. int* _ksys_unmap(void *base, size_t offset, size_t size)
  676. {
  677.     int  *val;
  678.     asm_inline(
  679.         "int $0x40"
  680.         :"=a"(val)
  681.         :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)
  682.     );
  683.     return val;
  684. }
  685.  
  686.  
  687. /* Loading the dynamic coff library */
  688.  
  689. static inline
  690. ksys_coff_etable_t* not_optimized _ksys_cofflib_load(const char* path)
  691. {
  692.     ksys_coff_etable_t *table;
  693.     asm_inline(
  694.         "int $0x40"
  695.         :"=a"(table)
  696.         :"a"(68),"b"(19), "c"(path)
  697.     );
  698.     return table;
  699. }
  700.  
  701. static inline
  702. void* not_optimized _ksys_cofflib_getproc(ksys_coff_etable_t *table, const char* fun_name)
  703. {
  704.     unsigned i=0;
  705.     while (1){
  706.         if (NULL == (table+i)->func_name){
  707.             break;
  708.         }else{
  709.             if (!_ksys_strcmp(fun_name, (table+i)->func_name)){
  710.                 return (table+i)->func_ptr;
  711.             }
  712.         }
  713.         i++;
  714.     }
  715.     return NULL;
  716. }
  717.  
  718.  
  719. /* Debug board functions */
  720.  
  721. static inline
  722. void _ksys_debug_putc(char c)
  723. {
  724.     asm_inline("int $0x40"::"a"(63), "b"(1), "c"(c));
  725. }
  726.  
  727. static inline
  728. void _ksys_debug_puts(char *s)
  729. {
  730.     unsigned i=0;
  731.     while (*(s+i)){
  732.         asm_inline ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
  733.         i++;
  734.     }
  735. }
  736.  
  737.  
  738. /* Working with threads and process */
  739.  
  740. static inline
  741. int _ksys_start_thread(void* proc, char* stack_top)
  742. {
  743.     int val;
  744.     asm_inline(
  745.         "int $0x40"
  746.         :"=a"(val)
  747.         :"a"(51), "b"(1), "c"(proc), "d"(stack_top)
  748.     );
  749.     return val;
  750. }
  751.  
  752. static inline
  753. void _ksys_focus_window(int slot){
  754.     asm_inline(
  755.         "int $0x40"
  756.         ::"a"(18), "b"(3), "c"(slot)
  757.     );
  758. }
  759.  
  760. static inline
  761. int _ksys_get_thread_slot(int tid){
  762.     int val;
  763.     asm_inline(
  764.         "int $0x40"
  765.         :"=a"(val)
  766.         :"a"(18), "b"(21), "c"(tid)
  767.     );
  768.     return val;
  769. }
  770.  
  771. static inline
  772. int not_optimized _ksys_process_info(ksys_proc_table_t* table, int pid)
  773. {
  774.     int val;
  775.     asm_inline(
  776.         "int $0x40"
  777.         :"=a"(val)
  778.         :"a"(9), "b"(table), "c"(pid)
  779.     );
  780.     return val;
  781. }
  782.  
  783. static inline
  784. void _ksys_exit()
  785. {
  786.     asm_inline("int $0x40"::"a"(-1));
  787. }
  788.  
  789.  
  790. /* Working with files and directories */
  791.  
  792. static inline
  793. void _ksys_setcwd(char* dir){
  794.     asm_inline(
  795.         "int $0x40"
  796.         ::"a"(30), "b"(1), "c"(dir)
  797.     );
  798. }
  799.  
  800. static inline
  801. int _ksys_getcwd(char* buf, int bufsize){
  802.     register int val;
  803.     asm_inline(
  804.         "int $0x40"
  805.         :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize)
  806.     );
  807.     return val;
  808. }
  809.  
  810. static inline
  811. ksys_ufile_t _ksys_load_file(const char *path)
  812. {
  813.     ksys_ufile_t uf;
  814.     asm_inline(
  815.         "int $0x40"
  816.         :"=a"(uf.data), "=d"(uf.size)
  817.         :"a"(68), "b"(27),"c"(path)
  818.     );
  819.     return uf;
  820. }
  821.  
  822. static inline
  823. ksys_ufile_t _ksys_load_file_enc(const char *path, unsigned file_encoding)
  824. {
  825.     ksys_ufile_t uf;
  826.     asm_inline(
  827.         "int $0x40"
  828.         :"=a"(uf.data), "=d"(uf.size)
  829.         :"a"(68), "b"(28),"c"(path), "d"(file_encoding)
  830.     );
  831.     return uf;
  832. }
  833.  
  834. static inline
  835. int not_optimized _ksys_work_files(const ksys70_t *k)
  836. {
  837.     int status;
  838.     asm_inline(
  839.         "int $0x40"
  840.         :"=a"(status)
  841.         :"a"(70), "b"(k)
  842.     );
  843.     return status;
  844. }
  845.  
  846. static inline
  847. int not_optimized _ksys_file_read_file(const char *name, unsigned long long offset, unsigned size, void *buf, unsigned *bytes_read)
  848. {
  849.     ksys70_t k;
  850.     k.p00 = 0;
  851.     k.p04 = offset;
  852.     k.p12 = size;
  853.     k.buf16 = buf;
  854.     k.p20 = 0;
  855.     k.p21 = name;
  856.     int status;
  857.     unsigned bytes_read_v;
  858.     asm_inline(
  859.         "int $0x40"
  860.         :"=a"(status), "=b"(bytes_read_v)
  861.         :"a"(70), "b"(&k)
  862.     );
  863.     if (!status) {
  864.         *bytes_read = bytes_read_v;
  865.     }
  866.     return status;
  867. }
  868.  
  869. static inline
  870. int not_optimized _ksys_file_write_file(const char *name, unsigned long long offset, unsigned size, const void *buf, unsigned *bytes_written)
  871. {
  872.     ksys70_t k;
  873.     k.p00 = 3;
  874.     k.p04 = offset;
  875.     k.p12 = size;
  876.     k.cbuf16 = buf;
  877.     k.p20 = 0;
  878.     k.p21 = name;
  879.     int status;
  880.     unsigned bytes_written_v;
  881.     asm_inline(
  882.         "int $0x40"
  883.         :"=a"(status), "=b"(bytes_written_v)
  884.         :"a"(70), "b"(&k)
  885.     );
  886.     if (!status) {
  887.         *bytes_written = bytes_written_v;
  888.     }
  889.     return status;
  890. }
  891.  
  892. static inline
  893. int not_optimized _ksys_file_get_info(const char *name, ksys_bdfe_t *bdfe)
  894. {
  895.     ksys70_t k;
  896.     k.p00 = 5;
  897.     k.bdfe = bdfe;
  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_delete(const char *name)
  905. {
  906.     ksys70_t k;
  907.     k.p00 = 8;
  908.     k.p20 = 0;
  909.     k.p21 = name;
  910.     return _ksys_work_files(&k);
  911. }
  912.  
  913. static inline
  914. int not_optimized _ksys_file_rename(const char *name, const char *new_name)
  915. {
  916.     ksys70_t k;
  917.     k.p00 = 10;
  918.     k.new_name = new_name;
  919.     k.p20 = 0;
  920.     k.p21 = name;
  921.     return _ksys_work_files(&k);
  922. }
  923.  
  924.  
  925. static inline
  926. int not_optimized _ksys_exec(char *app_name, char *args)
  927. {
  928.     ksys70_t file_op;
  929.     file_op.p00 = 7;
  930.     file_op.p04dw = 0;
  931.     file_op.p08dw = (unsigned)args;
  932.     file_op.p21 = app_name;
  933.     register int val;
  934.     asm_inline(
  935.         "int $0x40"
  936.         :"=a"(val)
  937.         :"a"(70), "b"(&file_op)
  938.     );
  939.     return val;
  940. }
  941.  
  942. /* Working with a named shared memory area. */
  943.  
  944. static inline
  945. int _ksys_shm_open(char *name, int mode, int size, char **new_shm)
  946. {
  947.     int error;
  948.     asm_inline(
  949.         "int $0x40"
  950.         :"=a"(*new_shm), "=d"(error)
  951.         :"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode)
  952.     );
  953.     return error;
  954. }
  955.  
  956.  
  957. static inline
  958. void _ksys_shm_close(char *shm_name)
  959. {
  960.     asm_inline(
  961.         "int $0x40":
  962.         :"a"(68), "b"(23), "c"(shm_name)
  963.     );
  964. }
  965.  
  966. #endif // _KSYS_H_