Subversion Repositories Kolibri OS

Rev

Rev 9764 | Rev 9767 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) KolibriOS team 2004-2021. All rights reserved. */
  2. /* Distributed under terms of the GNU General Public License    */
  3.  
  4. /* This file contains basic wrappers over KolibriOS system calls. */
  5. /* See sysfuncs.txt file for details. */
  6.  
  7. /*
  8.  * This file was created with you in mind. Lest you reinvent the wheel.
  9.  * If for some reason there is not enough wrapper add! I ask you to stick to the same style: snake_case.
  10.  * Structure names must start with "ksys_" and end with "_t".
  11.  * All wrappers must start with the "_ksys_" prefix.
  12.  * I consider it mandatory to place the wrappers in the correct order in the official documentation.
  13.  * Enjoy writing your code :)
  14.  
  15.  * Warning! The end of the file is the old definitions of function/structure names.
  16.  * They are for compatibility... Better not to use them.
  17. */
  18.  
  19. #ifndef _KSYS_H_
  20. #define _KSYS_H_
  21.  
  22. #include <stddef.h>
  23. #include <stdint.h>
  24.  
  25. #define KOSAPI     static inline
  26. #define asm_inline __asm__ __volatile__
  27.  
  28. /*============== General structures ==============*/
  29.  
  30. #pragma pack(push, 1)
  31.  
  32. typedef struct {
  33.     uint8_t blue;
  34.     uint8_t green;
  35.     uint8_t red;
  36. } rgb_t;
  37.  
  38. typedef union {
  39.     uint32_t val;
  40.     struct {
  41.         uint8_t hour;
  42.         uint8_t min;
  43.         uint8_t sec;
  44.         uint8_t _zero;
  45.     };
  46. } ksys_time_t;
  47.  
  48. typedef union {
  49.     uint32_t val;
  50.     struct {
  51.         uint8_t year;
  52.         uint8_t month;
  53.         uint8_t day;
  54.         uint8_t _zero;
  55.     };
  56. } ksys_date_t;
  57.  
  58. typedef union {
  59.     uint32_t val;
  60.     struct {
  61.         uint16_t x;
  62.         uint16_t y;
  63.     };
  64. } ksys_pos_t;
  65.  
  66. typedef union ksys_oskey_t {
  67.     uint32_t val;
  68.     struct {
  69.         uint8_t state;
  70.         uint8_t code;
  71.         uint8_t ctrl_key;
  72.     };
  73. } ksys_oskey_t;
  74.  
  75. typedef struct {
  76.     void* data;
  77.     size_t size;
  78. } ksys_ufile_t;
  79.  
  80. typedef struct {
  81.     uint32_t p00;
  82.     union {
  83.         uint64_t p04;
  84.         struct {
  85.             uint32_t p04dw;
  86.             uint32_t p08dw;
  87.         };
  88.     };
  89.     uint32_t p12;
  90.     union {
  91.         uint32_t p16;
  92.         const char* new_name;
  93.         void* bdfe;
  94.         void* buf16;
  95.         const void* cbuf16;
  96.     };
  97.     char p20;
  98.     const char* p21;
  99. } ksys70_t;
  100.  
  101. typedef struct {
  102.     uint32_t status;
  103.     uint32_t rw_bytes;
  104. } ksys70_status_t;
  105.  
  106. typedef struct {
  107.     uint32_t attributes;
  108.     uint32_t name_cp;
  109.     ksys_time_t creation_time;
  110.     ksys_date_t creation_date;
  111.     ksys_time_t last_access_time;
  112.     ksys_date_t last_access_date;
  113.     ksys_time_t last_modification_time;
  114.     ksys_date_t last_modification_date;
  115.     uint64_t size;
  116.     char name[0];
  117. } ksys_bdfe_t;
  118.  
  119. typedef struct {
  120.     int cpu_usage;                //+0
  121.     int window_pos_info;          //+4
  122.     uint16_t reserved1;           //+8
  123.     char name[12];                //+10
  124.     int memstart;                 //+22
  125.     int memused;                  //+26
  126.     int pid;                      //+30
  127.     int winx_start;               //+34
  128.     int winy_start;               //+38
  129.     int winx_size;                //+42
  130.     int winy_size;                //+46
  131.     uint16_t slot_info;           //+50
  132.     uint16_t reserved2;           //+52
  133.     int clientx;                  //+54
  134.     int clienty;                  //+58
  135.     int clientwidth;              //+62
  136.     int clientheight;             //+66
  137.     uint8_t window_state;         //+70
  138.     uint8_t reserved3[1024 - 71]; //+71
  139. } ksys_thread_t;
  140.  
  141. typedef unsigned int ksys_color_t;
  142.  
  143. typedef struct {
  144.     ksys_color_t frame_area;
  145.     ksys_color_t grab_bar;
  146.     ksys_color_t grab_bar_button;
  147.     ksys_color_t grab_button_text;
  148.     ksys_color_t grab_text;
  149.     ksys_color_t work_area;
  150.     ksys_color_t work_button;
  151.     ksys_color_t work_button_text;
  152.     ksys_color_t work_text;
  153.     ksys_color_t work_graph;
  154. } ksys_colors_table_t;
  155.  
  156. typedef struct {
  157.     unsigned pid;     // PID of sending thread
  158.     unsigned datalen; // data bytes
  159.     char* data;       // data begin
  160. } ksys_ipc_msg;
  161.  
  162. typedef struct {
  163.     unsigned lock;      // nonzero is locked
  164.     unsigned used;      // used bytes in buffer
  165.     ksys_ipc_msg* data; // data begin
  166. } ksys_ipc_buffer;
  167.  
  168. typedef struct {
  169.     char* func_name;
  170.     void* func_ptr;
  171. } ksys_dll_t;
  172.  
  173. typedef unsigned ksys_drv_hand_t;
  174.  
  175. typedef struct {
  176.     ksys_drv_hand_t handler;
  177.     unsigned func_num;
  178.     void* in_data_ptr;
  179.     unsigned in_data_size;
  180.     void* out_data_ptr;
  181.     unsigned out_data_size;
  182. } ksys_ioctl_t;
  183.  
  184. typedef struct {
  185.     char key[64];
  186.     char path[64];
  187. } ksys_dir_key_t;
  188.  
  189. #pragma pack(pop)
  190.  
  191. typedef rgb_t ksys_bitmap_t;
  192.  
  193. enum KSYS_FS_ERRORS {
  194.     KSYS_FS_ERR_SUCCESS = 0, // Success
  195.     KSYS_FS_ERR_1 = 1,       // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8)
  196.     KSYS_FS_ERR_2 = 2,       // Function is not supported for the given file system
  197.     KSYS_FS_ERR_3 = 3,       // Unknown file system
  198.     KSYS_FS_ERR_4 = 4,       // Reserved, is never returned in the current implementation
  199.     KSYS_FS_ERR_5 = 5,       // File not found
  200.     KSYS_FS_ERR_EOF = 6,     // End of file, EOF
  201.     KSYS_FS_ERR_7 = 7,       // Pointer lies outside of application memory
  202.     KSYS_FS_ERR_8 = 8,       // Disk is full
  203.     KSYS_FS_ERR_9 = 9,       // FAT table is destroyed
  204.     KSYS_FS_ERR_10 = 10,     // Access denied
  205.     KSYS_FS_ERR_11 = 11      // Device error
  206. };
  207.  
  208. enum KSYS_EVENTS {
  209.     KSYS_EVENT_NONE = 0,     /* Event queue is empty */
  210.     KSYS_EVENT_REDRAW = 1,   /* Window and window elements should be redrawn */
  211.     KSYS_EVENT_KEY = 2,      /* A key on the keyboard was pressed */
  212.     KSYS_EVENT_BUTTON = 3,   /* A button was clicked with the mouse */
  213.     KSYS_EVENT_DESKTOP = 5,  /* Desktop redraw finished */
  214.     KSYS_EVENT_MOUSE = 6,    /* Mouse activity (movement, button press) was detected */
  215.     KSYS_EVENT_IPC = 7,      /* Interprocess communication notify */
  216.     KSYS_EVENT_NETWORK = 8,  /* Network event */
  217.     KSYS_EVENT_DEBUG = 9,    /* Debug subsystem event */
  218.     KSYS_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */
  219. };
  220.  
  221. enum KSYS_FILE_ENCODING {
  222.     KSYS_FILE_CP866 = 1,
  223.     KSYS_FILE_UTF16LE = 2,
  224.     KSYS_FILE_UTF8 = 3
  225. };
  226.  
  227. KOSAPI int __strcmp(const char* s1, const char* s2)
  228. {
  229.     while ((*s1) && (*s1 == *s2)) {
  230.         ++s1;
  231.         ++s2;
  232.     }
  233.     return (*(unsigned char*)s1 - *(unsigned char*)s2);
  234. }
  235.  
  236. /* ####################################################################### */
  237. /* ############### С wrappers for system calls Kolibri OS ################ */
  238. /* ####################################################################### */
  239.  
  240. /*=============== Function -1 - terminate thread/process ===============*/
  241.  
  242. KOSAPI void _ksys_exit(void)
  243. {
  244.     asm_inline("int $0x40" ::"a"(-1));
  245. }
  246.  
  247. /*============== Function 0 - define and draw the window. ==============*/
  248.  
  249. KOSAPI void _ksys_create_window(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const char* name, ksys_color_t workcolor, uint32_t style)
  250. {
  251.     asm_inline(
  252.         "int $0x40" ::"a"(0),
  253.         "b"((x << 16) | ((w - 1) & 0xFFFF)),
  254.         "c"((y << 16) | ((h - 1) & 0xFFFF)),
  255.         "d"((style << 24) | (workcolor & 0xFFFFFF)),
  256.         "D"(name),
  257.         "S"(0)
  258.         : "memory");
  259. };
  260.  
  261. /*================ Function 1 - put pixel in the window. ===============*/
  262.  
  263. KOSAPI void _ksys_draw_pixel(uint32_t x, uint32_t y, ksys_color_t color)
  264. {
  265.     asm_inline(
  266.         "int $0x40" ::"a"(1), "b"(x), "c"(y), "d"(color));
  267. }
  268.  
  269. /*============ Function 2 - get the code of the pressed key. ===========*/
  270.  
  271. KOSAPI ksys_oskey_t _ksys_get_key(void)
  272. {
  273.     ksys_oskey_t val;
  274.     asm_inline(
  275.         "int $0x40"
  276.         : "=a"(val)
  277.         : "a"(2));
  278.     return val;
  279. }
  280.  
  281. /*==================== Function 3 - get system time. ===================*/
  282.  
  283. KOSAPI ksys_time_t _ksys_get_time(void)
  284. {
  285.     ksys_time_t c_time;
  286.     asm_inline(
  287.         "int $0x40"
  288.         : "=a"(c_time)
  289.         : "a"(3)
  290.         : "memory");
  291.     return c_time;
  292. }
  293.  
  294. /*=================== Function 4 - draw text string. ===================*/
  295. KOSAPI void _ksys_draw_text(const char* text, uint32_t x, uint32_t y, uint32_t len, ksys_color_t color)
  296. {
  297.     asm_inline(
  298.         "int $0x40" ::"a"(4), "d"(text),
  299.         "b"((x << 16) | y),
  300.         "S"(len), "c"(color)
  301.         : "memory");
  302. }
  303.  
  304. /*========================= Function 5 - delay. ========================*/
  305.  
  306. KOSAPI void _ksys_delay(uint32_t time)
  307. {
  308.     asm_inline(
  309.         "int $0x40" ::"a"(5), "b"(time)
  310.         : "memory");
  311. }
  312.  
  313. /*=============== Function 7 - draw image in the window. ===============*/
  314.  
  315. KOSAPI void _ksys_draw_bitmap(void* bitmap, int x, int y, int w, int h)
  316. {
  317.     asm_inline(
  318.         "int $0x40" ::"a"(7), "b"(bitmap),
  319.         "c"((w << 16) | h),
  320.         "d"((x << 16) | y)
  321.         : "memory");
  322. }
  323.  
  324. /*=============== Function 8 - define/delete the button. ===============*/
  325.  
  326. KOSAPI void _ksys_define_button(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t id, ksys_color_t color)
  327. {
  328.     asm_inline(
  329.         "int $0x40" ::"a"(8),
  330.         "b"((x << 16) + w),
  331.         "c"((y << 16) + h),
  332.         "d"(id),
  333.         "S"(color));
  334. };
  335.  
  336. KOSAPI void _ksys_delete_button(uint32_t id)
  337. {
  338.     asm_inline(
  339.         "int $0x40" ::"a"(8), "d"(id & 0x00FFFFFF | 0x80000000));
  340. }
  341.  
  342. /*============ Function 9 - information on execution thread. ===========*/
  343.  
  344. KOSAPI int _ksys_thread_info(ksys_thread_t* table, int slot)
  345. {
  346.     int val;
  347.     asm_inline(
  348.         "int $0x40"
  349.         : "=a"(val)
  350.         : "a"(9), "b"(table), "c"(slot)
  351.         : "memory");
  352.     return val;
  353. }
  354.  
  355. /*==================== Function 10 - wait for event. ===================*/
  356.  
  357. KOSAPI uint32_t _ksys_wait_event(void)
  358. {
  359.     uint32_t val;
  360.     asm_inline(
  361.         "int $0x40"
  362.         : "=a"(val)
  363.         : "a"(10));
  364.     return val;
  365. }
  366.  
  367. /*=============== Function 11 - check for event, no wait. ==============*/
  368.  
  369. KOSAPI uint32_t _ksys_check_event(void)
  370. {
  371.     uint32_t val;
  372.     asm_inline(
  373.         "int $0x40"
  374.         : "=a"(val)
  375.         : "a"(11));
  376.     return val;
  377. }
  378.  
  379. /*=============== Function 12 - begin/end window redraw. ===============*/
  380.  
  381. KOSAPI void _ksys_start_draw(void)
  382. {
  383.     asm_inline("int $0x40" ::"a"(12), "b"(1));
  384. }
  385.  
  386. KOSAPI void _ksys_end_draw(void)
  387. {
  388.     asm_inline("int $0x40" ::"a"(12), "b"(2));
  389. }
  390.  
  391. /*============ Function 13 - draw a rectangle in the window. ===========*/
  392.  
  393. KOSAPI void _ksys_draw_bar(uint32_t x, uint32_t y, uint32_t w, uint32_t h, ksys_color_t color)
  394. {
  395.     asm_inline(
  396.         "int $0x40" ::"a"(13), "d"(color),
  397.         "b"((x << 16) | w),
  398.         "c"((y << 16) | h));
  399. }
  400.  
  401. /*=================== Function 14 - get screen size. ===================*/
  402.  
  403. KOSAPI ksys_pos_t _ksys_screen_size(void)
  404. {
  405.     ksys_pos_t size;
  406.     ksys_pos_t size_tmp;
  407.     asm_inline(
  408.         "int $0x40"
  409.         : "=a"(size_tmp)
  410.         : "a"(14));
  411.     size.x = size_tmp.y;
  412.     size.y = size_tmp.x;
  413.     return size;
  414. }
  415.  
  416. /*== Function 15, subfunction 1 - set a size of the background image. ==*/
  417.  
  418. KOSAPI void _ksys_bg_set_size(uint32_t w, uint32_t h)
  419. {
  420.     asm_inline(
  421.         "int $0x40" ::"a"(15), "b"(1), "c"(w), "d"(h));
  422. }
  423.  
  424. /*=== Function 15, subfunction 2 - put pixel on the background image. ==*/
  425.  
  426. KOSAPI void _ksys_bg_put_pixel(uint32_t x, uint32_t y, uint32_t w, ksys_color_t color)
  427. {
  428.     asm_inline(
  429.         "int $0x40" ::"a"(15), "b"(2), "c"((x + y * w) * 3), "d"(color));
  430. }
  431.  
  432. /*=========== Function 15, subfunction 3 - redraw background. ==========*/
  433.  
  434. KOSAPI void _ksys_bg_redraw(void)
  435. {
  436.     asm_inline(
  437.         "int $0x40" ::"a"(15), "b"(3));
  438. }
  439.  
  440. /*== Function 15, subfunction 4 - set drawing mode for the background. =*/
  441.  
  442. enum KSYS_BG_MODES {
  443.     KSYS_BG_MODE_PAVE = 1,
  444.     KSYS_BG_MODE_STRETCH = 2
  445. };
  446.  
  447. KOSAPI void _ksys_bg_set_mode(uint32_t mode)
  448. {
  449.     asm_inline(
  450.         "int $0x40" ::"a"(15), "b"(4), "c"(mode));
  451. }
  452.  
  453. /*===================== Function 15, subfunction 5 =====================*/
  454. /*============ Put block of pixels on the background image. ============*/
  455.  
  456. KOSAPI void _ksys_bg_put_bitmap(ksys_bitmap_t* bitmap, size_t bitmap_size, uint32_t x, uint32_t y, uint32_t w)
  457. {
  458.     asm_inline(
  459.         "int $0x40" ::"a"(15), "b"(5), "c"(bitmap), "d"((x + y * w) * 3), "S"(bitmap_size));
  460. }
  461.  
  462. /*===================== Function 15, subfunction 6 =====================*/
  463. /*======= Map background data to the address space of process. ==========*/
  464.  
  465. KOSAPI ksys_bitmap_t* _ksys_bg_get_map(void)
  466. {
  467.     ksys_bitmap_t* bitmap;
  468.     asm_inline(
  469.         "int $0x40"
  470.         : "=a"(bitmap)
  471.         : "a"(15), "b"(6));
  472.     return bitmap;
  473. }
  474.  
  475. /*===== Function 15, subfunction 7 - close mapped background data. =====*/
  476.  
  477. KOSAPI int _ksys_bg_close_map(ksys_bitmap_t* bitmap)
  478. {
  479.     int status; // 1 - OK, 0 - ERROR
  480.     asm_inline(
  481.         "int $0x40"
  482.         : "=a"(status)
  483.         : "a"(15), "b"(7), "c"(bitmap));
  484.     return status;
  485. }
  486.  
  487. /*===================== Function 15, subfunction 9 =====================*/
  488. /*============= Redraws a rectangular part of the background ===========*/
  489.  
  490. KOSAPI void _ksys_bg_redraw_bar(ksys_pos_t angle1, ksys_pos_t angle2)
  491. {
  492.     asm_inline(
  493.         "int $0x40" ::"a"(15), "b"(9),
  494.         "c"(angle1.x * (1 << 16) + angle2.x),
  495.         "d"(angle1.y * (1 << 16) + angle2.y));
  496. }
  497.  
  498. /*=============== Function 16 - save ramdisk on a floppy. ==============*/
  499.  
  500. KOSAPI int _ksys_save_ramdisk_fd(uint32_t floppy_id)
  501. {
  502.     int status; // 0 - OK, 1 - ERROR
  503.     asm_inline(
  504.         "int $0x40"
  505.         : "=a"(status)
  506.         : "a"(16), "b"(floppy_id));
  507.     return status;
  508. }
  509.  
  510. /*======= Function 17 - get the identifier of the pressed button. ======*/
  511.  
  512. KOSAPI uint32_t _ksys_get_button(void)
  513. {
  514.     unsigned val;
  515.     asm_inline(
  516.         "int $0x40"
  517.         : "=a"(val)
  518.         : "a"(17));
  519.     return val >> 8;
  520. }
  521.  
  522. /*===================== Function 18, subfunction 1 =====================*/
  523. /*============= Make deactive the window of the given thread. ==========*/
  524.  
  525. KOSAPI void _ksys_unfocus_window(int slot)
  526. {
  527.     asm_inline(
  528.         "int $0x40" ::"a"(18), "b"(1), "c"(slot));
  529. }
  530.  
  531. /*= Function 18, subfunction 2 - terminate process/thread by the slot. =*/
  532.  
  533. KOSAPI void _ksys_kill_by_slot(int slot)
  534. {
  535.     asm_inline(
  536.         "int $0x40" ::"a"(18), "b"(2), "c"(slot));
  537. }
  538.  
  539. /*===================== Function 18, subfunction 3 =====================*/
  540. /*============= Make active the window of the given thread. ============*/
  541.  
  542. KOSAPI void _ksys_focus_window(int slot)
  543. {
  544.     asm_inline(
  545.         "int $0x40" ::"a"(18), "b"(3), "c"(slot));
  546. }
  547.  
  548. /*===================== Function 18, subfunction 4 =====================*/
  549. /*=========== Get counter of idle time units per one second. ===========*/
  550.  
  551. KOSAPI uint32_t _ksys_get_idle(void)
  552. {
  553.     uint32_t sec;
  554.     asm_inline(
  555.         "int $0x40"
  556.         : "=a"(sec)
  557.         : "a"(18), "b"(4));
  558.     return sec;
  559. }
  560.  
  561. /*========== Function 18, subfunction 5 - get CPU clock rate. ==========*/
  562. /*================ modulo 2^32 clock ticks = 4GHz ======================*/
  563.  
  564. KOSAPI uint32_t _ksys_get_cpu_clock(void)
  565. {
  566.     uint32_t clock;
  567.     asm_inline(
  568.         "int $0x40"
  569.         : "=a"(clock)
  570.         : "a"(18), "b"(5));
  571.     return clock;
  572. }
  573.  
  574. /* Function 18, subfunction 6 - save ramdisk to the file on hard drive. */
  575.  
  576. KOSAPI uint32_t _ksys_save_ramdisk_hd(const char* ramdisk_path)
  577. {
  578.     uint32_t fs_err;
  579.     asm_inline(
  580.         "int $0x40"
  581.         : "=a"(fs_err)
  582.         : "a"(18), "b"(6), "c"(ramdisk_path));
  583.     return fs_err;
  584. }
  585.  
  586. /* Function 18, subfunction 9 - system shutdown with the parameter. */
  587.  
  588. enum KSYS_SHD_PARAM {
  589.     KSYS_SHD_POWEROFF = 2,
  590.     KSYS_SHD_REBOOT = 3,
  591.     KSYS_SHD_RESTART_KRN = 4
  592. };
  593.  
  594. KOSAPI void _ksys_shutdown(uint32_t shd_param)
  595. {
  596.     asm_inline(
  597.         "int $0x40" ::"a"(18), "b"(9), "c"(shd_param));
  598. }
  599.  
  600. /*========= Function 18, subfunction 16 - get size of free RAM. ========*/
  601.  
  602. KOSAPI size_t _ksys_get_ram_size(void)
  603. {
  604.     size_t size;
  605.     asm_inline(
  606.         "int $0x40"
  607.         : "=a"(size)
  608.         : "a"(18), "b"(16));
  609.     return size;
  610. }
  611.  
  612. /*======== Function 18, subfunction 17 - get full amount of RAM. =======*/
  613.  
  614. KOSAPI size_t _ksys_get_full_ram(void)
  615. {
  616.     size_t size;
  617.     asm_inline(
  618.         "int $0x40"
  619.         : "=a"(size)
  620.         : "a"(18), "b"(17));
  621.     return size;
  622. }
  623.  
  624. /*===================== Function 18, subfunction 18 ====================*/
  625. /*============= Terminate process/thread by the identifier. ============*/
  626.  
  627. KOSAPI void _ksys_kill_by_pid(uint32_t PID)
  628. {
  629.     asm_inline(
  630.         "int $0x40" ::"a"(18), "b"(18), "c"(PID));
  631. }
  632.  
  633. /*===================== Function 18, subfunction 21 ====================*/
  634. /*=====Get the slot number of the process / thread by identifier.. =====*/
  635.  
  636. KOSAPI int _ksys_get_thread_slot(int PID)
  637. {
  638.     int val;
  639.     asm_inline(
  640.         "int $0x40"
  641.         : "=a"(val)
  642.         : "a"(18), "b"(21), "c"(PID));
  643.     return val;
  644. }
  645.  
  646. /*============= Function 23 - wait for event with timeout. =============*/
  647.  
  648. KOSAPI uint32_t _ksys_wait_event_timeout(uint32_t timeout)
  649. {
  650.     unsigned val;
  651.     asm_inline(
  652.         "int $0x40"
  653.         : "=a"(val)
  654.         : "a"(23), "b"(timeout));
  655.     return val;
  656. }
  657.  
  658. /*=== Function 26, subfunction 9 - get the value of the time counter. ==*/
  659.  
  660. KOSAPI uint32_t _ksys_get_tick_count(void)
  661. {
  662.     unsigned val;
  663.     asm_inline(
  664.         "int $0x40"
  665.         : "=a"(val)
  666.         : "a"(26), "b"(9));
  667.     return val;
  668. }
  669.  
  670. /*===================== Function 26, subfunction 10 ====================*/
  671. /*========== Get the value of the high precision time counter. =========*/
  672.  
  673. KOSAPI uint64_t _ksys_get_ns_count(void)
  674. {
  675.     uint64_t val;
  676.     asm_inline(
  677.         "int $0x40"
  678.         : "=A"(val)
  679.         : "a"(26), "b"(10));
  680.     return val;
  681. }
  682.  
  683. /*=================== Function 29 - get system date. ===================*/
  684.  
  685. KOSAPI ksys_date_t _ksys_get_date(void)
  686. {
  687.     ksys_date_t val;
  688.     asm_inline("int $0x40"
  689.                : "=a"(val)
  690.                : "a"(29));
  691.     return val;
  692. }
  693.  
  694. /*===========+ Function 30 - work with the current folder.==============*/
  695. /*--------- Subfunction 1 - set current folder for the thread. ---------*/
  696.  
  697. KOSAPI void _ksys_setcwd(char* dir)
  698. {
  699.     asm_inline(
  700.         "int $0x40" ::"a"(30), "b"(1), "c"(dir));
  701. }
  702.  
  703. /*--------- Subfunction 2 - get current folder for the thread. ---------*/
  704.  
  705. KOSAPI int _ksys_getcwd(char* buf, int bufsize)
  706. {
  707.     register int val;
  708.     asm_inline(
  709.         "int $0x40"
  710.         : "=a"(val)
  711.         : "a"(30), "b"(2), "c"(buf), "d"(bufsize));
  712.     return val;
  713. }
  714.  
  715. /* ---- Subfunction 3 - install the add.system directory for the kernel ------*/
  716.  
  717. KOSAPI int _ksys_set_kernel_dir(ksys_dir_key_t* table)
  718. {
  719.     register int val;
  720.     asm_inline(
  721.         "int $0x40"
  722.         : "=a"(val)
  723.         : "a"(30), "b"(3), "c"(table)
  724.         : "memory");
  725.     return val;
  726. }
  727.  
  728. /*=================== Function 37 - work with mouse. ===================*/
  729.  
  730. enum KSYS_MOUSE_POS {
  731.     KSYS_MOUSE_SCREEN_POS = 0,
  732.     KSYS_MOUSE_WINDOW_POS = 1
  733. };
  734.  
  735. KOSAPI ksys_pos_t _ksys_get_mouse_pos(int origin)
  736. {
  737.     ksys_pos_t pos;
  738.     asm_inline(
  739.         "int $0x40 \n\t"
  740.         "rol $16, %%eax"
  741.         : "=a"(pos)
  742.         : "a"(37), "b"(origin));
  743.     return pos;
  744. }
  745.  
  746. KOSAPI uint32_t _ksys_get_mouse_buttons(void) // subfunction 2 - states of the mouse buttons
  747. {
  748.     uint32_t val;
  749.     asm_inline(
  750.         "int $0x40"
  751.         : "=a"(val)
  752.         : "a"(37), "b"(2));
  753.     return val;
  754. }
  755.  
  756. KOSAPI uint32_t _ksys_get_mouse_eventstate(void) // subfunction 3 - states and events of the mouse buttons
  757. {
  758.     uint32_t val;
  759.     asm_inline(
  760.         "int $0x40"
  761.         : "=a"(val)
  762.         : "a"(37), "b"(3));
  763.     return val;
  764. }
  765.  
  766. KOSAPI uint32_t _ksys_load_cursor(void* path, uint32_t flags) // subfunction 4 - load cursor
  767. {
  768.     uint32_t val;
  769.     asm_inline(
  770.         "int $0x40"
  771.         : "=a"(val)
  772.         : "a"(37), "b"(4), "c"(path), "d"(flags)
  773.         : "memory");
  774.     return val;
  775. }
  776.  
  777. KOSAPI uint32_t _ksys_set_cursor(uint32_t cursor) // subfunction 5 - set cursor
  778. {
  779.     uint32_t old;
  780.     asm_inline(
  781.         "int $0x40"
  782.         : "=a"(old)
  783.         : "a"(37), "b"(5), "c"(cursor));
  784.     return old;
  785. }
  786.  
  787. KOSAPI int _ksys_delete_cursor(uint32_t cursor) // subfunction 6 - delete cursor
  788. {
  789.     int ret;
  790.     asm_inline(
  791.         "int $0x40"
  792.         : "=a"(ret)
  793.         : "a"(37), "b"(6), "c"(cursor)
  794.         : "memory");
  795.     return ret;
  796. }
  797.  
  798. KOSAPI uint32_t _ksys_get_mouse_wheels(void) // subfunction 7 - get scroll data
  799. {
  800.     uint32_t val;
  801.     asm_inline(
  802.         "int $0x40"
  803.         : "=a"(val)
  804.         : "a"(37), "b"(7));
  805.     return val;
  806. }
  807.  
  808. /*=========== Function 40 - set the mask for expected events. ==========*/
  809.  
  810. enum KSYS_EVENT_MASK {
  811.     KSYS_EVM_REDRAW = 1,
  812.     KSYS_EVM_KEY = 2,
  813.     KSYS_EVM_BUTTON = 4,
  814.     KSYS_EVM_EXIT = 8,
  815.     KSYS_EVM_BACKGROUND = 16,
  816.     KSYS_EVM_MOUSE = 32,
  817.     KSYS_EVM_IPC = 64,
  818.     KSYS_EVM_STACK = 128,
  819.     KSYS_EVM_DEBUG = 256,
  820.     KSYS_EVM_STACK2 = 512,
  821.     KSYS_EVM_MOUSE_FILTER = 0x80000000,
  822.     KSYS_EVM_CURSOR_FILTER = 0x40000000,
  823. };
  824.  
  825. KOSAPI uint32_t _ksys_set_event_mask(uint32_t mask)
  826. {
  827.     unsigned val;
  828.     asm_inline(
  829.         "int $0x40"
  830.         : "=a"(val)
  831.         : "a"(40), "b"(mask));
  832.     return val;
  833. }
  834.  
  835. /*====================== Function 38 - draw line. ======================*/
  836.  
  837. KOSAPI void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color)
  838. {
  839.     asm_inline(
  840.         "int $0x40" ::"a"(38), "d"(color),
  841.         "b"((xs << 16) | xe),
  842.         "c"((ys << 16) | ye));
  843. }
  844.  
  845. /*============= Function 47 - draw a number in the window. =============*/
  846.  
  847. KOSAPI void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color)
  848. {
  849.     unsigned fmt;
  850.     fmt = len << 16 | 0x80000000; // no leading zeros + width
  851.     asm_inline(
  852.         "int $0x40" ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color));
  853. }
  854.  
  855. KOSAPI void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg)
  856. {
  857.     unsigned fmt;
  858.     fmt = len << 16 | 0x80000000; // no leading zeros + width
  859.     asm_inline(
  860.         "int $0x40" ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg));
  861. }
  862.  
  863. /*====== Function 48, subfunction 3 - get standard window colors. ======*/
  864.  
  865. KOSAPI void _ksys_get_system_colors(ksys_colors_table_t* color_table)
  866. {
  867.     asm_inline(
  868.         "int $0x40" ::"a"(48), "b"(3), "c"(color_table), "d"(40));
  869. }
  870.  
  871. /*============ Function 48, subfunction 4 - get skin height. ===========*/
  872.  
  873. KOSAPI uint32_t _ksys_get_skin_height()
  874. {
  875.     unsigned height;
  876.     asm_inline(
  877.         "int $0x40"
  878.         : "=a"(height)
  879.         : "a"(48), "b"(4));
  880.     return height;
  881. }
  882.  
  883. /*==================== Function 51 - create thread. ====================*/
  884.  
  885. KOSAPI int _ksys_create_thread(void* thread_entry, void* stack_top)
  886. {
  887.     int val;
  888.     asm_inline(
  889.         "int $0x40"
  890.         : "=a"(val)
  891.         : "a"(51), "b"(1), "c"(thread_entry), "d"(stack_top)
  892.         : "memory");
  893.     return val;
  894. }
  895.  
  896. /*==================== Function 54, subfunction 0 ======================*/
  897. /*============== Get the number of slots in the clipboard. =============*/
  898.  
  899. enum KSYS_CLIP_ENCODING {
  900.     KSYS_CLIP_UTF8 = 0,
  901.     KSYS_CLIP_CP866 = 1,
  902.     KSYS_CLIP_CP1251 = 2
  903. };
  904.  
  905. enum KSYS_CLIP_TYPES {
  906.     KSYS_CLIP_TEXT = 0,
  907.     KSYS_CLIP_IMAGE = 1,
  908.     KSYS_CLIP_RAW = 2
  909. };
  910.  
  911. KOSAPI int _ksys_clip_num(void)
  912. {
  913.     unsigned val;
  914.     asm_inline(
  915.         "int $0x40"
  916.         : "=a"(val)
  917.         : "a"(54), "b"(0));
  918.     return val;
  919. }
  920.  
  921. /*==================== Function 54, subfunction 1 ======================*/
  922. /*================= Read the data from the clipboard. ==================-*/
  923.  
  924. KOSAPI char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free()
  925. {
  926.     char* val;
  927.     asm_inline(
  928.         "int $0x40"
  929.         : "=a"(val)
  930.         : "a"(54), "b"(1), "c"(n));
  931.     return val;
  932. }
  933.  
  934. /*==================== Function 54, subfunction 2 ======================*/
  935. /*================= Write the data to the clipboard. ===================*/
  936.  
  937. KOSAPI int _ksys_clip_set(int n, char* buffer)
  938. {
  939.     unsigned val;
  940.     asm_inline(
  941.         "int $0x40"
  942.         : "=a"(val)
  943.         : "a"(54), "b"(2), "c"(n), "d"(buffer)
  944.         : "memory");
  945.     return val;
  946. }
  947.  
  948. /*===================== Function 54, subfunction 3 =====================*/
  949. /*================ Delete the last slot in the clipboard ===============*/
  950.  
  951. KOSAPI int _ksys_clip_pop()
  952. {
  953.     unsigned val;
  954.     asm_inline(
  955.         "int $0x40"
  956.         : "=a"(val)
  957.         : "a"(54), "b"(3));
  958.     return val;
  959. }
  960.  
  961. /*===================== Function 54, subfunction 4 =====================*/
  962. /*===================== Alarm reset the lock buffer ====================*/
  963.  
  964. KOSAPI int _ksys_clip_unlock()
  965. {
  966.     unsigned val;
  967.     asm_inline(
  968.         "int $0x40"
  969.         : "=a"(val)
  970.         : "a"(54), "b"(4));
  971.     return val;
  972. }
  973.  
  974. /*============== Function 63 - work with the debug board. ==============*/
  975.  
  976. KOSAPI void _ksys_debug_putc(char c)
  977. {
  978.     asm_inline("int $0x40" ::"a"(63), "b"(1), "c"(c));
  979. }
  980.  
  981. KOSAPI void _ksys_debug_puts(const char* s)
  982. {
  983.     unsigned i = 0;
  984.     while (*(s + i)) {
  985.         asm_inline("int $0x40" ::"a"(63), "b"(1), "c"(*(s + i)));
  986.         i++;
  987.     }
  988. }
  989.  
  990. /*========= Function 66, subfunction 1 - set keyboard input mode. ==============*/
  991.  
  992. typedef enum KSYS_KEY_INPUT_MODE {
  993.     KSYS_KEY_INPUT_MODE_ASCII = 0,
  994.     KSYS_KEY_INPUT_MODE_SCANC = 1,
  995. } ksys_key_input_mode_t;
  996.  
  997. KOSAPI void _ksys_set_key_input_mode(ksys_key_input_mode_t mode)
  998. {
  999.     asm_inline(
  1000.         "int $0x40" ::"a"(66), "b"(1), "c"(mode));
  1001. }
  1002.  
  1003. /*========= Function 67 - change position/sizes of the window. =========*/
  1004.  
  1005. KOSAPI void _ksys_change_window(int new_x, int new_y, int new_w, int new_h)
  1006. {
  1007.     asm_inline(
  1008.         "int $0x40" ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w), "S"(new_h));
  1009. }
  1010.  
  1011. /*======== Function 68, subfunction 12 - allocate memory block. ========*/
  1012.  
  1013. KOSAPI void* _ksys_alloc(size_t size)
  1014. {
  1015.     void* val;
  1016.     asm_inline(
  1017.         "int $0x40"
  1018.         : "=a"(val)
  1019.         : "a"(68), "b"(12), "c"(size));
  1020.     return val;
  1021. }
  1022.  
  1023. /*========== Function 68, subfunction 13 - free memory block. ==========*/
  1024.  
  1025. KOSAPI int _ksys_free(void* mem)
  1026. {
  1027.     int val;
  1028.     asm_inline(
  1029.         "int $0x40"
  1030.         : "=a"(val)
  1031.         : "a"(68), "b"(13), "c"(mem));
  1032.     return val;
  1033. }
  1034.  
  1035. /*============= Function 68, subfunction 16 - load driver. =============*/
  1036.  
  1037. KOSAPI ksys_drv_hand_t _ksys_load_driver(char* driver_name)
  1038. {
  1039.     ksys_drv_hand_t driver_h;
  1040.     asm_inline(
  1041.         "int $0x40"
  1042.         : "=a"(driver_h)
  1043.         : "a"(68), "b"(16), "c"(driver_name));
  1044.     return driver_h;
  1045. }
  1046.  
  1047. /*============ Function 68, subfunction 17 - driver control. ===========*/
  1048.  
  1049. KOSAPI int _ksys_driver_control(ksys_ioctl_t* ioctl)
  1050. {
  1051.     int status;
  1052.     asm_inline(
  1053.         "int $0x40"
  1054.         : "=a"(status)
  1055.         : "a"(68), "b"(17), "c"(ioctl)
  1056.         : "memory");
  1057.     return status;
  1058. }
  1059.  
  1060. /*== Function 68, subfunction 18 - subfunction 19 - load DLL (MS COFF) ==*/
  1061.  
  1062. KOSAPI ksys_dll_t* _ksys_dlopen(const char* path)
  1063. {
  1064.     ksys_dll_t* table;
  1065.     asm_inline(
  1066.         "int $0x40"
  1067.         : "=a"(table)
  1068.         : "a"(68), "b"(19), "c"(path)
  1069.         : "memory");
  1070.     return table;
  1071. }
  1072.  
  1073. /* It is not a system call, it serves as an auxiliary tool*/
  1074.  
  1075. KOSAPI void* _ksys_dlsym(ksys_dll_t* table, const char* fun_name)
  1076. {
  1077.     unsigned i = 0;
  1078.     while (1) {
  1079.         if (!(table + i)->func_name) {
  1080.             break;
  1081.         } else {
  1082.             if (!__strcmp(fun_name, (table + i)->func_name)) {
  1083.                 return (table + i)->func_ptr;
  1084.             }
  1085.         }
  1086.         i++;
  1087.     }
  1088.     return NULL;
  1089. }
  1090.  
  1091. /* Function 68, subfunction 20 - reallocate memory block.*/
  1092.  
  1093. KOSAPI void* _ksys_realloc(void* mem, size_t size)
  1094. {
  1095.     void* val;
  1096.     asm_inline(
  1097.         "int $0x40"
  1098.         : "=a"(val)
  1099.         : "a"(68), "b"(20), "c"(size), "d"(mem)
  1100.         : "memory");
  1101.     return val;
  1102. }
  1103.  
  1104. /* Function 68, subfunction 21 - load driver by full name. */
  1105.  
  1106. KOSAPI ksys_drv_hand_t _ksys_load_driver_opt(char* driver_path, char* cmd_line)
  1107. {
  1108.     ksys_drv_hand_t driver_h;
  1109.     asm_inline(
  1110.         "int $0x40"
  1111.         : "=a"(driver_h)
  1112.         : "a"(68), "b"(21), "c"(driver_path), "d"(cmd_line));
  1113.     return driver_h;
  1114. }
  1115.  
  1116. /*======== Function 68, subfunction 22 - open named memory area. =======*/
  1117.  
  1118. enum KSYS_SHM_MODE {
  1119.     KSYS_SHM_OPEN = 0x00,
  1120.     KSYS_SHM_OPEN_ALWAYS = 0x04,
  1121.     KSYS_SHM_CREATE = 0x08,
  1122.     KSYS_SHM_READ = 0x00,
  1123.     KSYS_SHM_WRITE = 0x01,
  1124. };
  1125.  
  1126. KOSAPI int _ksys_shm_open(char* name, int mode, int size, char** new_shm)
  1127. {
  1128.     int error;
  1129.     asm_inline(
  1130.         "int $0x40"
  1131.         : "=a"(*new_shm), "=d"(error)
  1132.         : "a"(68), "b"(22), "c"(name), "d"(size), "S"(mode));
  1133.     return error;
  1134. }
  1135.  
  1136. /*======= Function 68, subfunction 23 - close named memory area. =======*/
  1137.  
  1138. KOSAPI void _ksys_shm_close(char* shm_name)
  1139. {
  1140.     asm_inline(
  1141.         "int $0x40"
  1142.         :
  1143.         : "a"(68), "b"(23), "c"(shm_name));
  1144. }
  1145.  
  1146. /*====== Function 68, subfunction 26 - release memory pages ============*/
  1147.  
  1148. KOSAPI int* _ksys_unmap(void* base, size_t offset, size_t size)
  1149. {
  1150.     int* val;
  1151.     asm_inline(
  1152.         "int $0x40"
  1153.         : "=a"(val)
  1154.         : "a"(68), "b"(26), "c"(base), "d"(offset), "S"(size));
  1155.     return val;
  1156. }
  1157.  
  1158. /*========== Function 68, subfunction 27 - load file ===================*/
  1159.  
  1160. KOSAPI ksys_ufile_t _ksys_load_file(const char* path)
  1161. {
  1162.     ksys_ufile_t uf;
  1163.     asm_inline(
  1164.         "int $0x40"
  1165.         : "=a"(uf.data), "=d"(uf.size)
  1166.         : "a"(68), "b"(27), "c"(path)
  1167.         : "memory");
  1168.     return uf;
  1169. }
  1170.  
  1171. /*==== Function 68, subfunction 28 - load file, specifying the encoding ===*/
  1172.  
  1173. KOSAPI ksys_ufile_t _ksys_load_file_enc(const char* path, unsigned file_encoding)
  1174. {
  1175.     ksys_ufile_t uf;
  1176.     asm_inline(
  1177.         "int $0x40"
  1178.         : "=a"(uf.data), "=d"(uf.size)
  1179.         : "a"(68), "b"(28), "c"(path), "d"(file_encoding)
  1180.         : "memory");
  1181.     return uf;
  1182. }
  1183.  
  1184. /*==== Function 70 - work with file system with long names support. ====*/
  1185.  
  1186. KOSAPI ksys70_status_t _ksys70(const ksys70_t* k)
  1187. {
  1188.     ksys70_status_t status;
  1189.     asm_inline(
  1190.         "int $0x40"
  1191.         : "=a"(status.status), "=b"(status.rw_bytes)
  1192.         : "a"(70), "b"(k)
  1193.         : "memory");
  1194.     return status;
  1195. }
  1196.  
  1197. /*====== Function 70, subfunction 0 - read file with long names support. ======*/
  1198.  
  1199. KOSAPI ksys70_status_t _ksys_file_read(const char* name, uint64_t offset, uint32_t size, void* buf)
  1200. {
  1201.     ksys70_t k;
  1202.     k.p00 = 0;
  1203.     k.p04 = offset;
  1204.     k.p12 = size;
  1205.     k.buf16 = buf;
  1206.     k.p20 = 0;
  1207.     k.p21 = name;
  1208.     return _ksys70(&k);
  1209. }
  1210.  
  1211. /*===================== Function 70, subfunction 2 =====================*/
  1212. /*============ Create/rewrite file with long names support. ============*/
  1213.  
  1214. KOSAPI int _ksys_file_create(const char* name)
  1215. {
  1216.     ksys70_t k;
  1217.     k.p00 = 2;
  1218.     k.p04dw = 0;
  1219.     k.p08dw = 0;
  1220.     k.p12 = 0;
  1221.     k.p21 = name;
  1222.     return _ksys70(&k).status;
  1223. }
  1224.  
  1225. /*===================== Function 70, subfunction 3 =====================*/
  1226. /*=========== Write to existing file with long names support. ==========*/
  1227.  
  1228. KOSAPI ksys70_status_t _ksys_file_write(const char* name, uint64_t offset, uint32_t size, const void* buf)
  1229. {
  1230.     ksys70_t k;
  1231.     k.p00 = 3;
  1232.     k.p04 = offset;
  1233.     k.p12 = size;
  1234.     k.cbuf16 = buf;
  1235.     k.p20 = 0;
  1236.     k.p21 = name;
  1237.     return _ksys70(&k);
  1238. }
  1239.  
  1240. /*========== Function 70, subfunction 5 - get information on file/folder. =====*/
  1241.  
  1242. KOSAPI int _ksys_file_info(const char* name, ksys_bdfe_t* bdfe)
  1243. {
  1244.     ksys70_t k;
  1245.     k.p00 = 5;
  1246.     k.p04dw = 0;
  1247.     k.p08dw = 0;
  1248.     k.p12 = 0;
  1249.     k.bdfe = bdfe;
  1250.     k.p20 = 0;
  1251.     k.p21 = name;
  1252.     return _ksys70(&k).status;
  1253. }
  1254.  
  1255. #define _ksys_dir_info _ksys_file_info
  1256.  
  1257. /*=========== Function 70, subfunction 7 - start application. ===========*/
  1258.  
  1259. KOSAPI int _ksys_exec(const char* app_name, char* args)
  1260. {
  1261.     ksys70_t file_opt;
  1262.     file_opt.p00 = 7;
  1263.     file_opt.p04dw = 0;
  1264.     file_opt.p08dw = (uint32_t)args;
  1265.  
  1266.     file_opt.p12 = 0;
  1267.     file_opt.p16 = 0;
  1268.     file_opt.p20 = 0;
  1269.  
  1270.     file_opt.p21 = app_name;
  1271.     return _ksys70(&file_opt).status;
  1272. }
  1273.  
  1274. /*========== Function 70, subfunction 8 - delete file/folder. ==========*/
  1275.  
  1276. KOSAPI int _ksys_file_delete(const char* name)
  1277. {
  1278.     ksys70_t k;
  1279.     k.p00 = 8;
  1280.     k.p20 = 0;
  1281.     k.p21 = name;
  1282.     return _ksys70(&k).status;
  1283. }
  1284.  
  1285. /*============= Function 70, subfunction 9 - create folder. ============*/
  1286.  
  1287. KOSAPI int _ksys_mkdir(const char* path)
  1288. {
  1289.     ksys70_t dir_opt;
  1290.     dir_opt.p00 = 9;
  1291.     dir_opt.p21 = path;
  1292.     return _ksys70(&dir_opt).status;
  1293. }
  1294.  
  1295. /*============= Function 70, subfunction 10 - rename/move. =============*/
  1296.  
  1297. KOSAPI int _ksys_file_rename(const char* name, const char* new_name)
  1298. {
  1299.     ksys70_t k;
  1300.     k.p00 = 10;
  1301.     k.new_name = new_name;
  1302.     k.p20 = 0;
  1303.     k.p21 = name;
  1304.     return _ksys70(&k).status;
  1305. }
  1306.  
  1307. #define _ksys_dir_rename _ksys_file_rename
  1308.  
  1309. /*============= Function 77 - implements the POSIX subsystem. =============*/
  1310.  
  1311. KOSAPI int _ksys_posix_read(int pipefd, void* buff, int n)
  1312. {
  1313.     int count;
  1314.     asm_inline(
  1315.         "int $0x40"
  1316.         : "=a"(count)
  1317.         : "a"(77), "b"(10), "c"(pipefd), "d"(buff), "S"(n)
  1318.         : "memory");
  1319.     return count;
  1320. }
  1321.  
  1322. KOSAPI int _ksys_posix_write(int pipefd, void* buff, int n)
  1323. {
  1324.     int count;
  1325.     asm_inline(
  1326.         "int $0x40"
  1327.         : "=a"(count)
  1328.         : "a"(77), "b"(11), "c"(pipefd), "d"(buff), "S"(n)
  1329.         : "memory");
  1330.     return count;
  1331. }
  1332.  
  1333. KOSAPI int _ksys_posix_pipe2(int pipefd[2], int flags)
  1334. {
  1335.     int err;
  1336.     asm_inline(
  1337.         "int $0x40"
  1338.         : "=a"(err)
  1339.         : "a"(77), "b"(13), "c"(pipefd), "d"(flags)
  1340.         : "memory");
  1341.     return err;
  1342. }
  1343.  
  1344. /* ######### Old names of functions and structures. Do not use again! ##########*/
  1345.  
  1346. #define _ksys_get_event     _ksys_wait_event
  1347. #define _ksys_file_get_info _ksys_file_info
  1348.  
  1349. static inline int _ksys_file_read_file(const char* name, unsigned long long offset, unsigned size, void* buff, unsigned* bytes_read)
  1350. {
  1351.     ksys70_status_t res = _ksys_file_read(name, offset, size, buff);
  1352.     *bytes_read = res.rw_bytes;
  1353.     return res.status;
  1354. }
  1355.  
  1356. static inline int _ksys_file_write_file(const char* name, unsigned long long offset, unsigned size, const void* buff, unsigned* bytes_write)
  1357. {
  1358.     ksys70_status_t res = _ksys_file_write(name, offset, size, buff);
  1359.     *bytes_write = res.rw_bytes;
  1360.     return res.status;
  1361. }
  1362.  
  1363. #endif // _KSYS_H_
  1364.