Subversion Repositories Kolibri OS

Rev

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