Subversion Repositories Kolibri OS

Rev

Rev 9766 | Rev 9774 | 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. enum KSYS_TITLE_ENCODING {
  228.     KSYS_TITLE_CP866 = 1,
  229.     KSYS_TITLE_UTF16LE = 2,
  230.     KSYS_TITLE_UTF8 = 3
  231. };
  232.  
  233. KOSAPI int __strcmp(const char* s1, const char* s2)
  234. {
  235.     while ((*s1) && (*s1 == *s2)) {
  236.         ++s1;
  237.         ++s2;
  238.     }
  239.     return (*(unsigned char*)s1 - *(unsigned char*)s2);
  240. }
  241.  
  242. /* ####################################################################### */
  243. /* ############### С wrappers for system calls Kolibri OS ################ */
  244. /* ####################################################################### */
  245.  
  246. /*=============== Function -1 - terminate thread/process ===============*/
  247.  
  248. KOSAPI void _ksys_exit(void)
  249. {
  250.     asm_inline("int $0x40" ::"a"(-1));
  251. }
  252.  
  253. /*============== Function 0 - define and draw the window. ==============*/
  254.  
  255. 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)
  256. {
  257.     asm_inline(
  258.         "int $0x40" ::"a"(0),
  259.         "b"((x << 16) | ((w - 1) & 0xFFFF)),
  260.         "c"((y << 16) | ((h - 1) & 0xFFFF)),
  261.         "d"((style << 24) | (workcolor & 0xFFFFFF)),
  262.         "D"(name),
  263.         "S"(0)
  264.         : "memory");
  265. }
  266.  
  267. /*================ Function 1 - put pixel in the window. ===============*/
  268.  
  269. KOSAPI void _ksys_draw_pixel(uint32_t x, uint32_t y, ksys_color_t color)
  270. {
  271.     asm_inline(
  272.         "int $0x40" ::"a"(1), "b"(x), "c"(y), "d"(color));
  273. }
  274.  
  275. /*============ Function 2 - get the code of the pressed key. ===========*/
  276.  
  277. KOSAPI ksys_oskey_t _ksys_get_key(void)
  278. {
  279.     ksys_oskey_t val;
  280.     asm_inline(
  281.         "int $0x40"
  282.         : "=a"(val)
  283.         : "a"(2));
  284.     return val;
  285. }
  286.  
  287. /*==================== Function 3 - get system time. ===================*/
  288.  
  289. KOSAPI ksys_time_t _ksys_get_time(void)
  290. {
  291.     ksys_time_t c_time;
  292.     asm_inline(
  293.         "int $0x40"
  294.         : "=a"(c_time)
  295.         : "a"(3)
  296.         : "memory");
  297.     return c_time;
  298. }
  299.  
  300. /*=================== Function 4 - draw text string. ===================*/
  301. KOSAPI void _ksys_draw_text(const char* text, uint32_t x, uint32_t y, uint32_t len, ksys_color_t color)
  302. {
  303.     asm_inline(
  304.         "int $0x40" ::"a"(4), "d"(text),
  305.         "b"((x << 16) | y),
  306.         "S"(len), "c"(color)
  307.         : "memory");
  308. }
  309.  
  310. /*========================= Function 5 - delay. ========================*/
  311.  
  312. KOSAPI void _ksys_delay(uint32_t time)
  313. {
  314.     asm_inline(
  315.         "int $0x40" ::"a"(5), "b"(time)
  316.         : "memory");
  317. }
  318.  
  319. /*=============== Function 7 - draw image in the window. ===============*/
  320.  
  321. KOSAPI void _ksys_draw_bitmap(void* bitmap, int x, int y, int w, int h)
  322. {
  323.     asm_inline(
  324.         "int $0x40" ::"a"(7), "b"(bitmap),
  325.         "c"((w << 16) | h),
  326.         "d"((x << 16) | y)
  327.         : "memory");
  328. }
  329.  
  330. /*=============== Function 8 - define/delete the button. ===============*/
  331.  
  332. KOSAPI void _ksys_define_button(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t id, ksys_color_t color)
  333. {
  334.     asm_inline(
  335.         "int $0x40" ::"a"(8),
  336.         "b"((x << 16) + w),
  337.         "c"((y << 16) + h),
  338.         "d"(id),
  339.         "S"(color));
  340. };
  341.  
  342. KOSAPI void _ksys_delete_button(uint32_t id)
  343. {
  344.     asm_inline(
  345.         "int $0x40" ::"a"(8), "d"(id & 0x00FFFFFF | 0x80000000));
  346. }
  347.  
  348. /*============ Function 9 - information on execution thread. ===========*/
  349.  
  350. KOSAPI int _ksys_thread_info(ksys_thread_t* table, int slot)
  351. {
  352.     int val;
  353.     asm_inline(
  354.         "int $0x40"
  355.         : "=a"(val)
  356.         : "a"(9), "b"(table), "c"(slot)
  357.         : "memory");
  358.     return val;
  359. }
  360.  
  361. /*==================== Function 10 - wait for event. ===================*/
  362.  
  363. KOSAPI uint32_t _ksys_wait_event(void)
  364. {
  365.     uint32_t val;
  366.     asm_inline(
  367.         "int $0x40"
  368.         : "=a"(val)
  369.         : "a"(10));
  370.     return val;
  371. }
  372.  
  373. /*=============== Function 11 - check for event, no wait. ==============*/
  374.  
  375. KOSAPI uint32_t _ksys_check_event(void)
  376. {
  377.     uint32_t val;
  378.     asm_inline(
  379.         "int $0x40"
  380.         : "=a"(val)
  381.         : "a"(11));
  382.     return val;
  383. }
  384.  
  385. /*=============== Function 12 - begin/end window redraw. ===============*/
  386.  
  387. KOSAPI void _ksys_start_draw(void)
  388. {
  389.     asm_inline("int $0x40" ::"a"(12), "b"(1));
  390. }
  391.  
  392. KOSAPI void _ksys_end_draw(void)
  393. {
  394.     asm_inline("int $0x40" ::"a"(12), "b"(2));
  395. }
  396.  
  397. /*============ Function 13 - draw a rectangle in the window. ===========*/
  398.  
  399. KOSAPI void _ksys_draw_bar(uint32_t x, uint32_t y, uint32_t w, uint32_t h, ksys_color_t color)
  400. {
  401.     asm_inline(
  402.         "int $0x40" ::"a"(13), "d"(color),
  403.         "b"((x << 16) | w),
  404.         "c"((y << 16) | h));
  405. }
  406.  
  407. /*=================== Function 14 - get screen size. ===================*/
  408.  
  409. KOSAPI ksys_pos_t _ksys_screen_size(void)
  410. {
  411.     ksys_pos_t size;
  412.     ksys_pos_t size_tmp;
  413.     asm_inline(
  414.         "int $0x40"
  415.         : "=a"(size_tmp)
  416.         : "a"(14));
  417.     size.x = size_tmp.y;
  418.     size.y = size_tmp.x;
  419.     return size;
  420. }
  421.  
  422. /*== Function 15, subfunction 1 - set a size of the background image. ==*/
  423.  
  424. KOSAPI void _ksys_bg_set_size(uint32_t w, uint32_t h)
  425. {
  426.     asm_inline(
  427.         "int $0x40" ::"a"(15), "b"(1), "c"(w), "d"(h));
  428. }
  429.  
  430. /*=== Function 15, subfunction 2 - put pixel on the background image. ==*/
  431.  
  432. KOSAPI void _ksys_bg_put_pixel(uint32_t x, uint32_t y, uint32_t w, ksys_color_t color)
  433. {
  434.     asm_inline(
  435.         "int $0x40" ::"a"(15), "b"(2), "c"((x + y * w) * 3), "d"(color));
  436. }
  437.  
  438. /*=========== Function 15, subfunction 3 - redraw background. ==========*/
  439.  
  440. KOSAPI void _ksys_bg_redraw(void)
  441. {
  442.     asm_inline(
  443.         "int $0x40" ::"a"(15), "b"(3));
  444. }
  445.  
  446. /*== Function 15, subfunction 4 - set drawing mode for the background. =*/
  447.  
  448. enum KSYS_BG_MODES {
  449.     KSYS_BG_MODE_PAVE = 1,
  450.     KSYS_BG_MODE_STRETCH = 2
  451. };
  452.  
  453. KOSAPI void _ksys_bg_set_mode(uint32_t mode)
  454. {
  455.     asm_inline(
  456.         "int $0x40" ::"a"(15), "b"(4), "c"(mode));
  457. }
  458.  
  459. /*===================== Function 15, subfunction 5 =====================*/
  460. /*============ Put block of pixels on the background image. ============*/
  461.  
  462. KOSAPI void _ksys_bg_put_bitmap(ksys_bitmap_t* bitmap, size_t bitmap_size, uint32_t x, uint32_t y, uint32_t w)
  463. {
  464.     asm_inline(
  465.         "int $0x40" ::"a"(15), "b"(5), "c"(bitmap), "d"((x + y * w) * 3), "S"(bitmap_size));
  466. }
  467.  
  468. /*===================== Function 15, subfunction 6 =====================*/
  469. /*======= Map background data to the address space of process. ==========*/
  470.  
  471. KOSAPI ksys_bitmap_t* _ksys_bg_get_map(void)
  472. {
  473.     ksys_bitmap_t* bitmap;
  474.     asm_inline(
  475.         "int $0x40"
  476.         : "=a"(bitmap)
  477.         : "a"(15), "b"(6));
  478.     return bitmap;
  479. }
  480.  
  481. /*===== Function 15, subfunction 7 - close mapped background data. =====*/
  482.  
  483. KOSAPI int _ksys_bg_close_map(ksys_bitmap_t* bitmap)
  484. {
  485.     int status; // 1 - OK, 0 - ERROR
  486.     asm_inline(
  487.         "int $0x40"
  488.         : "=a"(status)
  489.         : "a"(15), "b"(7), "c"(bitmap));
  490.     return status;
  491. }
  492.  
  493. /*===================== Function 15, subfunction 9 =====================*/
  494. /*============= Redraws a rectangular part of the background ===========*/
  495.  
  496. KOSAPI void _ksys_bg_redraw_bar(ksys_pos_t angle1, ksys_pos_t angle2)
  497. {
  498.     asm_inline(
  499.         "int $0x40" ::"a"(15), "b"(9),
  500.         "c"(angle1.x * (1 << 16) + angle2.x),
  501.         "d"(angle1.y * (1 << 16) + angle2.y));
  502. }
  503.  
  504. /*=============== Function 16 - save ramdisk on a floppy. ==============*/
  505.  
  506. KOSAPI int _ksys_save_ramdisk_fd(uint32_t floppy_id)
  507. {
  508.     int status; // 0 - OK, 1 - ERROR
  509.     asm_inline(
  510.         "int $0x40"
  511.         : "=a"(status)
  512.         : "a"(16), "b"(floppy_id));
  513.     return status;
  514. }
  515.  
  516. /*======= Function 17 - get the identifier of the pressed button. ======*/
  517.  
  518. KOSAPI uint32_t _ksys_get_button(void)
  519. {
  520.     unsigned val;
  521.     asm_inline(
  522.         "int $0x40"
  523.         : "=a"(val)
  524.         : "a"(17));
  525.     return val >> 8;
  526. }
  527.  
  528. /*===================== Function 18, subfunction 1 =====================*/
  529. /*============= Make deactive the window of the given thread. ==========*/
  530.  
  531. KOSAPI void _ksys_unfocus_window(int slot)
  532. {
  533.     asm_inline(
  534.         "int $0x40" ::"a"(18), "b"(1), "c"(slot));
  535. }
  536.  
  537. /*= Function 18, subfunction 2 - terminate process/thread by the slot. =*/
  538.  
  539. KOSAPI void _ksys_kill_by_slot(int slot)
  540. {
  541.     asm_inline(
  542.         "int $0x40" ::"a"(18), "b"(2), "c"(slot));
  543. }
  544.  
  545. /*===================== Function 18, subfunction 3 =====================*/
  546. /*============= Make active the window of the given thread. ============*/
  547.  
  548. KOSAPI void _ksys_focus_window(int slot)
  549. {
  550.     asm_inline(
  551.         "int $0x40" ::"a"(18), "b"(3), "c"(slot));
  552. }
  553.  
  554. /*===================== Function 18, subfunction 4 =====================*/
  555. /*=========== Get counter of idle time units per one second. ===========*/
  556.  
  557. KOSAPI uint32_t _ksys_get_idle(void)
  558. {
  559.     uint32_t sec;
  560.     asm_inline(
  561.         "int $0x40"
  562.         : "=a"(sec)
  563.         : "a"(18), "b"(4));
  564.     return sec;
  565. }
  566.  
  567. /*========== Function 18, subfunction 5 - get CPU clock rate. ==========*/
  568. /*================ modulo 2^32 clock ticks = 4GHz ======================*/
  569.  
  570. KOSAPI uint32_t _ksys_get_cpu_clock(void)
  571. {
  572.     uint32_t clock;
  573.     asm_inline(
  574.         "int $0x40"
  575.         : "=a"(clock)
  576.         : "a"(18), "b"(5));
  577.     return clock;
  578. }
  579.  
  580. /* Function 18, subfunction 6 - save ramdisk to the file on hard drive. */
  581.  
  582. KOSAPI uint32_t _ksys_save_ramdisk_hd(const char* ramdisk_path)
  583. {
  584.     uint32_t fs_err;
  585.     asm_inline(
  586.         "int $0x40"
  587.         : "=a"(fs_err)
  588.         : "a"(18), "b"(6), "c"(ramdisk_path));
  589.     return fs_err;
  590. }
  591.  
  592. /* Function 18, subfunction 9 - system shutdown with the parameter. */
  593.  
  594. enum KSYS_SHD_PARAM {
  595.     KSYS_SHD_POWEROFF = 2,
  596.     KSYS_SHD_REBOOT = 3,
  597.     KSYS_SHD_RESTART_KRN = 4
  598. };
  599.  
  600. KOSAPI void _ksys_shutdown(uint32_t shd_param)
  601. {
  602.     asm_inline(
  603.         "int $0x40" ::"a"(18), "b"(9), "c"(shd_param));
  604. }
  605.  
  606. /*========= Function 18, subfunction 16 - get size of free RAM. ========*/
  607.  
  608. KOSAPI size_t _ksys_get_ram_size(void)
  609. {
  610.     size_t size;
  611.     asm_inline(
  612.         "int $0x40"
  613.         : "=a"(size)
  614.         : "a"(18), "b"(16));
  615.     return size;
  616. }
  617.  
  618. /*======== Function 18, subfunction 17 - get full amount of RAM. =======*/
  619.  
  620. KOSAPI size_t _ksys_get_full_ram(void)
  621. {
  622.     size_t size;
  623.     asm_inline(
  624.         "int $0x40"
  625.         : "=a"(size)
  626.         : "a"(18), "b"(17));
  627.     return size;
  628. }
  629.  
  630. /*===================== Function 18, subfunction 18 ====================*/
  631. /*============= Terminate process/thread by the identifier. ============*/
  632.  
  633. KOSAPI void _ksys_kill_by_pid(uint32_t PID)
  634. {
  635.     asm_inline("int $0x40" ::"a"(18), "b"(18), "c"(PID));
  636. }
  637.  
  638. /*========= Fuction 18, subfunction 19 - get/set mouse settings. ========*/
  639.  
  640. KOSAPI void _ksys_set_mouse_pos(int x, int y) // sub-subfunction 4 - set the position of the mouse cursor
  641. {
  642.     asm_inline("int $0x40" ::"a"(18), "b"(19), "c"(4), "d"(x * 65536 + y));
  643. }
  644.  
  645. /*===================== Function 18, subfunction 21 ====================*/
  646. /*=====Get the slot number of the process / thread by identifier.. =====*/
  647.  
  648. KOSAPI int _ksys_get_thread_slot(int PID)
  649. {
  650.     int val;
  651.     asm_inline(
  652.         "int $0x40"
  653.         : "=a"(val)
  654.         : "a"(18), "b"(21), "c"(PID));
  655.     return val;
  656. }
  657.  
  658. /*============= Function 23 - wait for event with timeout. =============*/
  659.  
  660. KOSAPI uint32_t _ksys_wait_event_timeout(uint32_t timeout)
  661. {
  662.     unsigned val;
  663.     asm_inline(
  664.         "int $0x40"
  665.         : "=a"(val)
  666.         : "a"(23), "b"(timeout));
  667.     return val;
  668. }
  669.  
  670. /*=== Function 26, subfunction 9 - get the value of the time counter. ==*/
  671.  
  672. KOSAPI uint32_t _ksys_get_tick_count(void)
  673. {
  674.     unsigned val;
  675.     asm_inline(
  676.         "int $0x40"
  677.         : "=a"(val)
  678.         : "a"(26), "b"(9));
  679.     return val;
  680. }
  681.  
  682. /*===================== Function 26, subfunction 10 ====================*/
  683. /*========== Get the value of the high precision time counter. =========*/
  684.  
  685. KOSAPI uint64_t _ksys_get_ns_count(void)
  686. {
  687.     uint64_t val;
  688.     asm_inline(
  689.         "int $0x40"
  690.         : "=A"(val)
  691.         : "a"(26), "b"(10));
  692.     return val;
  693. }
  694.  
  695. /*=================== Function 29 - get system date. ===================*/
  696.  
  697. KOSAPI ksys_date_t _ksys_get_date(void)
  698. {
  699.     ksys_date_t val;
  700.     asm_inline("int $0x40"
  701.                : "=a"(val)
  702.                : "a"(29));
  703.     return val;
  704. }
  705.  
  706. /*===========+ Function 30 - work with the current folder.==============*/
  707. /*--------- Subfunction 1 - set current folder for the thread. ---------*/
  708.  
  709. KOSAPI void _ksys_setcwd(char* dir)
  710. {
  711.     asm_inline(
  712.         "int $0x40" ::"a"(30), "b"(1), "c"(dir));
  713. }
  714.  
  715. /*--------- Subfunction 2 - get current folder for the thread. ---------*/
  716.  
  717. KOSAPI int _ksys_getcwd(char* buf, int bufsize)
  718. {
  719.     register int val;
  720.     asm_inline(
  721.         "int $0x40"
  722.         : "=a"(val)
  723.         : "a"(30), "b"(2), "c"(buf), "d"(bufsize));
  724.     return val;
  725. }
  726.  
  727. /* ---- Subfunction 3 - install the add.system directory for the kernel ------*/
  728.  
  729. KOSAPI int _ksys_set_kernel_dir(ksys_dir_key_t* table)
  730. {
  731.     register int val;
  732.     asm_inline(
  733.         "int $0x40"
  734.         : "=a"(val)
  735.         : "a"(30), "b"(3), "c"(table)
  736.         : "memory");
  737.     return val;
  738. }
  739.  
  740. /*=================== Function 37 - work with mouse. ===================*/
  741.  
  742. enum KSYS_MOUSE_POS {
  743.     KSYS_MOUSE_SCREEN_POS = 0,
  744.     KSYS_MOUSE_WINDOW_POS = 1
  745. };
  746.  
  747. KOSAPI ksys_pos_t _ksys_get_mouse_pos(int origin)
  748. {
  749.     ksys_pos_t pos;
  750.     asm_inline(
  751.         "int $0x40 \n\t"
  752.         "rol $16, %%eax"
  753.         : "=a"(pos)
  754.         : "a"(37), "b"(origin));
  755.     return pos;
  756. }
  757.  
  758. KOSAPI uint32_t _ksys_get_mouse_buttons(void) // subfunction 2 - states of the mouse buttons
  759. {
  760.     uint32_t val;
  761.     asm_inline(
  762.         "int $0x40"
  763.         : "=a"(val)
  764.         : "a"(37), "b"(2));
  765.     return val;
  766. }
  767.  
  768. KOSAPI uint32_t _ksys_get_mouse_eventstate(void) // subfunction 3 - states and events of the mouse buttons
  769. {
  770.     uint32_t val;
  771.     asm_inline(
  772.         "int $0x40"
  773.         : "=a"(val)
  774.         : "a"(37), "b"(3));
  775.     return val;
  776. }
  777.  
  778. enum KSYS_CURSOR_SRC {
  779.     KSYS_CURSOR_FROM_FILE = 0,
  780.     KSYS_CURSOR_FROM_MEM = 1,
  781.     KSYS_CURSOR_INDIRECT = 2
  782. };
  783.  
  784. KOSAPI void* _ksys_load_cursor(void* path, uint32_t flags) // subfunction 4 - load cursor
  785. {
  786.     uint32_t val;
  787.     asm_inline(
  788.         "int $0x40"
  789.         : "=a"(val)
  790.         : "a"(37), "b"(4), "c"(path), "d"(flags)
  791.         : "memory");
  792.     return val;
  793. }
  794.  
  795. KOSAPI void* _ksys_set_cursor(void* cursor) // subfunction 5 - set cursor
  796. {
  797.     uint32_t old;
  798.     asm_inline(
  799.         "int $0x40"
  800.         : "=a"(old)
  801.         : "a"(37), "b"(5), "c"(cursor));
  802.     return old;
  803. }
  804.  
  805. KOSAPI int _ksys_delete_cursor(void* cursor) // subfunction 6 - delete cursor
  806. {
  807.     int ret;
  808.     asm_inline(
  809.         "int $0x40"
  810.         : "=a"(ret)
  811.         : "a"(37), "b"(6), "c"(cursor)
  812.         : "memory");
  813.     return ret;
  814. }
  815.  
  816. KOSAPI uint32_t _ksys_get_mouse_wheels(void) // subfunction 7 - get scroll data
  817. {
  818.     uint32_t val;
  819.     asm_inline(
  820.         "int $0x40"
  821.         : "=a"(val)
  822.         : "a"(37), "b"(7));
  823.     return val;
  824. }
  825.  
  826. /*=========== Function 40 - set the mask for expected events. ==========*/
  827.  
  828. enum KSYS_EVENT_MASK {
  829.     KSYS_EVM_REDRAW = 1,
  830.     KSYS_EVM_KEY = 2,
  831.     KSYS_EVM_BUTTON = 4,
  832.     KSYS_EVM_EXIT = 8,
  833.     KSYS_EVM_BACKGROUND = 16,
  834.     KSYS_EVM_MOUSE = 32,
  835.     KSYS_EVM_IPC = 64,
  836.     KSYS_EVM_STACK = 128,
  837.     KSYS_EVM_DEBUG = 256,
  838.     KSYS_EVM_STACK2 = 512,
  839.     KSYS_EVM_MOUSE_FILTER = 0x80000000,
  840.     KSYS_EVM_CURSOR_FILTER = 0x40000000,
  841. };
  842.  
  843. KOSAPI uint32_t _ksys_set_event_mask(uint32_t mask)
  844. {
  845.     unsigned val;
  846.     asm_inline(
  847.         "int $0x40"
  848.         : "=a"(val)
  849.         : "a"(40), "b"(mask));
  850.     return val;
  851. }
  852.  
  853. /*====================== Function 38 - draw line. ======================*/
  854.  
  855. KOSAPI void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color)
  856. {
  857.     asm_inline(
  858.         "int $0x40" ::"a"(38), "d"(color),
  859.         "b"((xs << 16) | xe),
  860.         "c"((ys << 16) | ye));
  861. }
  862.  
  863. /*============= Function 47 - draw a number in the window. =============*/
  864.  
  865. KOSAPI void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color)
  866. {
  867.     unsigned fmt;
  868.     fmt = len << 16 | 0x80000000; // no leading zeros + width
  869.     asm_inline(
  870.         "int $0x40" ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color));
  871. }
  872.  
  873. KOSAPI void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg)
  874. {
  875.     unsigned fmt;
  876.     fmt = len << 16 | 0x80000000; // no leading zeros + width
  877.     asm_inline(
  878.         "int $0x40" ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg));
  879. }
  880.  
  881. /*====== Function 48, subfunction 3 - get standard window colors. ======*/
  882.  
  883. KOSAPI void _ksys_get_system_colors(ksys_colors_table_t* color_table)
  884. {
  885.     asm_inline(
  886.         "int $0x40" ::"a"(48), "b"(3), "c"(color_table), "d"(40));
  887. }
  888.  
  889. /*============ Function 48, subfunction 4 - get skin height. ===========*/
  890.  
  891. KOSAPI uint32_t _ksys_get_skin_height()
  892. {
  893.     unsigned height;
  894.     asm_inline(
  895.         "int $0x40"
  896.         : "=a"(height)
  897.         : "a"(48), "b"(4));
  898.     return height;
  899. }
  900.  
  901. /*==================== Function 51 - create thread. ====================*/
  902.  
  903. KOSAPI int _ksys_create_thread(void* thread_entry, void* stack_top)
  904. {
  905.     int val;
  906.     asm_inline(
  907.         "int $0x40"
  908.         : "=a"(val)
  909.         : "a"(51), "b"(1), "c"(thread_entry), "d"(stack_top)
  910.         : "memory");
  911.     return val;
  912. }
  913.  
  914. /*==================== Function 54, subfunction 0 ======================*/
  915. /*============== Get the number of slots in the clipboard. =============*/
  916.  
  917. enum KSYS_CLIP_ENCODING {
  918.     KSYS_CLIP_UTF8 = 0,
  919.     KSYS_CLIP_CP866 = 1,
  920.     KSYS_CLIP_CP1251 = 2
  921. };
  922.  
  923. enum KSYS_CLIP_TYPES {
  924.     KSYS_CLIP_TEXT = 0,
  925.     KSYS_CLIP_IMAGE = 1,
  926.     KSYS_CLIP_RAW = 2
  927. };
  928.  
  929. KOSAPI int _ksys_clip_num(void)
  930. {
  931.     unsigned val;
  932.     asm_inline(
  933.         "int $0x40"
  934.         : "=a"(val)
  935.         : "a"(54), "b"(0));
  936.     return val;
  937. }
  938.  
  939. /*==================== Function 54, subfunction 1 ======================*/
  940. /*================= Read the data from the clipboard. ==================-*/
  941.  
  942. KOSAPI char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free()
  943. {
  944.     char* val;
  945.     asm_inline(
  946.         "int $0x40"
  947.         : "=a"(val)
  948.         : "a"(54), "b"(1), "c"(n));
  949.     return val;
  950. }
  951.  
  952. /*==================== Function 54, subfunction 2 ======================*/
  953. /*================= Write the data to the clipboard. ===================*/
  954.  
  955. KOSAPI int _ksys_clip_set(int n, char* buffer)
  956. {
  957.     unsigned val;
  958.     asm_inline(
  959.         "int $0x40"
  960.         : "=a"(val)
  961.         : "a"(54), "b"(2), "c"(n), "d"(buffer)
  962.         : "memory");
  963.     return val;
  964. }
  965.  
  966. /*===================== Function 54, subfunction 3 =====================*/
  967. /*================ Delete the last slot in the clipboard ===============*/
  968.  
  969. KOSAPI int _ksys_clip_pop()
  970. {
  971.     unsigned val;
  972.     asm_inline(
  973.         "int $0x40"
  974.         : "=a"(val)
  975.         : "a"(54), "b"(3));
  976.     return val;
  977. }
  978.  
  979. /*===================== Function 54, subfunction 4 =====================*/
  980. /*===================== Alarm reset the lock buffer ====================*/
  981.  
  982. KOSAPI int _ksys_clip_unlock()
  983. {
  984.     unsigned val;
  985.     asm_inline(
  986.         "int $0x40"
  987.         : "=a"(val)
  988.         : "a"(54), "b"(4));
  989.     return val;
  990. }
  991.  
  992. /*============== Function 63 - work with the debug board. ==============*/
  993.  
  994. KOSAPI void _ksys_debug_putc(char c)
  995. {
  996.     asm_inline("int $0x40" ::"a"(63), "b"(1), "c"(c));
  997. }
  998.  
  999. KOSAPI void _ksys_debug_puts(const char* s)
  1000. {
  1001.     unsigned i = 0;
  1002.     while (*(s + i)) {
  1003.         asm_inline("int $0x40" ::"a"(63), "b"(1), "c"(*(s + i)));
  1004.         i++;
  1005.     }
  1006. }
  1007.  
  1008. /*========= Function 66, subfunction 1 - set keyboard input mode. ==============*/
  1009.  
  1010. typedef enum KSYS_KEY_INPUT_MODE {
  1011.     KSYS_KEY_INPUT_MODE_ASCII = 0,
  1012.     KSYS_KEY_INPUT_MODE_SCANC = 1,
  1013. } ksys_key_input_mode_t;
  1014.  
  1015. KOSAPI void _ksys_set_key_input_mode(ksys_key_input_mode_t mode)
  1016. {
  1017.     asm_inline(
  1018.         "int $0x40" ::"a"(66), "b"(1), "c"(mode));
  1019. }
  1020.  
  1021. /*========= Function 67 - change position/sizes of the window. =========*/
  1022.  
  1023. KOSAPI void _ksys_change_window(int new_x, int new_y, int new_w, int new_h)
  1024. {
  1025.     asm_inline(
  1026.         "int $0x40" ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w), "S"(new_h));
  1027. }
  1028.  
  1029. /*======== Function 68, subfunction 12 - allocate memory block. ========*/
  1030.  
  1031. KOSAPI void* _ksys_alloc(size_t size)
  1032. {
  1033.     void* val;
  1034.     asm_inline(
  1035.         "int $0x40"
  1036.         : "=a"(val)
  1037.         : "a"(68), "b"(12), "c"(size));
  1038.     return val;
  1039. }
  1040.  
  1041. /*========== Function 68, subfunction 13 - free memory block. ==========*/
  1042.  
  1043. KOSAPI int _ksys_free(void* mem)
  1044. {
  1045.     int val;
  1046.     asm_inline(
  1047.         "int $0x40"
  1048.         : "=a"(val)
  1049.         : "a"(68), "b"(13), "c"(mem));
  1050.     return val;
  1051. }
  1052.  
  1053. /*============= Function 68, subfunction 16 - load driver. =============*/
  1054.  
  1055. KOSAPI ksys_drv_hand_t _ksys_load_driver(char* driver_name)
  1056. {
  1057.     ksys_drv_hand_t driver_h;
  1058.     asm_inline(
  1059.         "int $0x40"
  1060.         : "=a"(driver_h)
  1061.         : "a"(68), "b"(16), "c"(driver_name));
  1062.     return driver_h;
  1063. }
  1064.  
  1065. /*============ Function 68, subfunction 17 - driver control. ===========*/
  1066.  
  1067. KOSAPI int _ksys_driver_control(ksys_ioctl_t* ioctl)
  1068. {
  1069.     int status;
  1070.     asm_inline(
  1071.         "int $0x40"
  1072.         : "=a"(status)
  1073.         : "a"(68), "b"(17), "c"(ioctl)
  1074.         : "memory");
  1075.     return status;
  1076. }
  1077.  
  1078. /*== Function 68, subfunction 18 - subfunction 19 - load DLL (MS COFF) ==*/
  1079.  
  1080. KOSAPI ksys_dll_t* _ksys_dlopen(const char* path)
  1081. {
  1082.     ksys_dll_t* table;
  1083.     asm_inline(
  1084.         "int $0x40"
  1085.         : "=a"(table)
  1086.         : "a"(68), "b"(19), "c"(path)
  1087.         : "memory");
  1088.     return table;
  1089. }
  1090.  
  1091. /* It is not a system call, it serves as an auxiliary tool*/
  1092.  
  1093. KOSAPI void* _ksys_dlsym(ksys_dll_t* table, const char* fun_name)
  1094. {
  1095.     unsigned i = 0;
  1096.     while (1) {
  1097.         if (!(table + i)->func_name) {
  1098.             break;
  1099.         } else {
  1100.             if (!__strcmp(fun_name, (table + i)->func_name)) {
  1101.                 return (table + i)->func_ptr;
  1102.             }
  1103.         }
  1104.         i++;
  1105.     }
  1106.     return NULL;
  1107. }
  1108.  
  1109. /* Function 68, subfunction 20 - reallocate memory block.*/
  1110.  
  1111. KOSAPI void* _ksys_realloc(void* mem, size_t size)
  1112. {
  1113.     void* val;
  1114.     asm_inline(
  1115.         "int $0x40"
  1116.         : "=a"(val)
  1117.         : "a"(68), "b"(20), "c"(size), "d"(mem)
  1118.         : "memory");
  1119.     return val;
  1120. }
  1121.  
  1122. /* Function 68, subfunction 21 - load driver by full name. */
  1123.  
  1124. KOSAPI ksys_drv_hand_t _ksys_load_driver_opt(char* driver_path, char* cmd_line)
  1125. {
  1126.     ksys_drv_hand_t driver_h;
  1127.     asm_inline(
  1128.         "int $0x40"
  1129.         : "=a"(driver_h)
  1130.         : "a"(68), "b"(21), "c"(driver_path), "d"(cmd_line));
  1131.     return driver_h;
  1132. }
  1133.  
  1134. /*======== Function 68, subfunction 22 - open named memory area. =======*/
  1135.  
  1136. enum KSYS_SHM_MODE {
  1137.     KSYS_SHM_OPEN = 0x00,
  1138.     KSYS_SHM_OPEN_ALWAYS = 0x04,
  1139.     KSYS_SHM_CREATE = 0x08,
  1140.     KSYS_SHM_READ = 0x00,
  1141.     KSYS_SHM_WRITE = 0x01,
  1142. };
  1143.  
  1144. KOSAPI int _ksys_shm_open(char* name, int mode, int size, char** new_shm)
  1145. {
  1146.     int error;
  1147.     asm_inline(
  1148.         "int $0x40"
  1149.         : "=a"(*new_shm), "=d"(error)
  1150.         : "a"(68), "b"(22), "c"(name), "d"(size), "S"(mode));
  1151.     return error;
  1152. }
  1153.  
  1154. /*======= Function 68, subfunction 23 - close named memory area. =======*/
  1155.  
  1156. KOSAPI void _ksys_shm_close(char* shm_name)
  1157. {
  1158.     asm_inline(
  1159.         "int $0x40"
  1160.         :
  1161.         : "a"(68), "b"(23), "c"(shm_name));
  1162. }
  1163.  
  1164. /*====== Function 68, subfunction 26 - release memory pages ============*/
  1165.  
  1166. KOSAPI int* _ksys_unmap(void* base, size_t offset, size_t size)
  1167. {
  1168.     int* val;
  1169.     asm_inline(
  1170.         "int $0x40"
  1171.         : "=a"(val)
  1172.         : "a"(68), "b"(26), "c"(base), "d"(offset), "S"(size));
  1173.     return val;
  1174. }
  1175.  
  1176. /*========== Function 68, subfunction 27 - load file ===================*/
  1177.  
  1178. KOSAPI ksys_ufile_t _ksys_load_file(const char* path)
  1179. {
  1180.     ksys_ufile_t uf;
  1181.     asm_inline(
  1182.         "int $0x40"
  1183.         : "=a"(uf.data), "=d"(uf.size)
  1184.         : "a"(68), "b"(27), "c"(path)
  1185.         : "memory");
  1186.     return uf;
  1187. }
  1188.  
  1189. /*==== Function 68, subfunction 28 - load file, specifying the encoding ===*/
  1190.  
  1191. KOSAPI ksys_ufile_t _ksys_load_file_enc(const char* path, unsigned file_encoding)
  1192. {
  1193.     ksys_ufile_t uf;
  1194.     asm_inline(
  1195.         "int $0x40"
  1196.         : "=a"(uf.data), "=d"(uf.size)
  1197.         : "a"(68), "b"(28), "c"(path), "d"(file_encoding)
  1198.         : "memory");
  1199.     return uf;
  1200. }
  1201.  
  1202. /*==== Function 70 - work with file system with long names support. ====*/
  1203.  
  1204. KOSAPI ksys70_status_t _ksys70(const ksys70_t* k)
  1205. {
  1206.     ksys70_status_t status;
  1207.     asm_inline(
  1208.         "int $0x40"
  1209.         : "=a"(status.status), "=b"(status.rw_bytes)
  1210.         : "a"(70), "b"(k)
  1211.         : "memory");
  1212.     return status;
  1213. }
  1214.  
  1215. /*====== Function 70, subfunction 0 - read file with long names support. ======*/
  1216.  
  1217. KOSAPI ksys70_status_t _ksys_file_read(const char* name, uint64_t offset, uint32_t size, void* buf)
  1218. {
  1219.     ksys70_t k;
  1220.     k.p00 = 0;
  1221.     k.p04 = offset;
  1222.     k.p12 = size;
  1223.     k.buf16 = buf;
  1224.     k.p20 = 0;
  1225.     k.p21 = name;
  1226.     return _ksys70(&k);
  1227. }
  1228.  
  1229. /*===================== Function 70, subfunction 2 =====================*/
  1230. /*============ Create/rewrite file with long names support. ============*/
  1231.  
  1232. KOSAPI int _ksys_file_create(const char* name)
  1233. {
  1234.     ksys70_t k;
  1235.     k.p00 = 2;
  1236.     k.p04dw = 0;
  1237.     k.p08dw = 0;
  1238.     k.p12 = 0;
  1239.     k.p21 = name;
  1240.     return _ksys70(&k).status;
  1241. }
  1242.  
  1243. /*===================== Function 70, subfunction 3 =====================*/
  1244. /*=========== Write to existing file with long names support. ==========*/
  1245.  
  1246. KOSAPI ksys70_status_t _ksys_file_write(const char* name, uint64_t offset, uint32_t size, const void* buf)
  1247. {
  1248.     ksys70_t k;
  1249.     k.p00 = 3;
  1250.     k.p04 = offset;
  1251.     k.p12 = size;
  1252.     k.cbuf16 = buf;
  1253.     k.p20 = 0;
  1254.     k.p21 = name;
  1255.     return _ksys70(&k);
  1256. }
  1257.  
  1258. /*========== Function 70, subfunction 5 - get information on file/folder. =====*/
  1259.  
  1260. KOSAPI int _ksys_file_info(const char* name, ksys_bdfe_t* bdfe)
  1261. {
  1262.     ksys70_t k;
  1263.     k.p00 = 5;
  1264.     k.p04dw = 0;
  1265.     k.p08dw = 0;
  1266.     k.p12 = 0;
  1267.     k.bdfe = bdfe;
  1268.     k.p20 = 0;
  1269.     k.p21 = name;
  1270.     return _ksys70(&k).status;
  1271. }
  1272.  
  1273. #define _ksys_dir_info _ksys_file_info
  1274.  
  1275. /*=========== Function 70, subfunction 7 - start application. ===========*/
  1276.  
  1277. KOSAPI int _ksys_exec(const char* app_name, char* args)
  1278. {
  1279.     ksys70_t file_opt;
  1280.     file_opt.p00 = 7;
  1281.     file_opt.p04dw = 0;
  1282.     file_opt.p08dw = (uint32_t)args;
  1283.  
  1284.     file_opt.p12 = 0;
  1285.     file_opt.p16 = 0;
  1286.     file_opt.p20 = 0;
  1287.  
  1288.     file_opt.p21 = app_name;
  1289.     return _ksys70(&file_opt).status;
  1290. }
  1291.  
  1292. /*========== Function 70, subfunction 8 - delete file/folder. ==========*/
  1293.  
  1294. KOSAPI int _ksys_file_delete(const char* name)
  1295. {
  1296.     ksys70_t k;
  1297.     k.p00 = 8;
  1298.     k.p20 = 0;
  1299.     k.p21 = name;
  1300.     return _ksys70(&k).status;
  1301. }
  1302.  
  1303. /*============= Function 70, subfunction 9 - create folder. ============*/
  1304.  
  1305. KOSAPI int _ksys_mkdir(const char* path)
  1306. {
  1307.     ksys70_t dir_opt;
  1308.     dir_opt.p00 = 9;
  1309.     dir_opt.p21 = path;
  1310.     return _ksys70(&dir_opt).status;
  1311. }
  1312.  
  1313. /*============= Function 70, subfunction 10 - rename/move. =============*/
  1314.  
  1315. KOSAPI int _ksys_file_rename(const char* name, const char* new_name)
  1316. {
  1317.     ksys70_t k;
  1318.     k.p00 = 10;
  1319.     k.new_name = new_name;
  1320.     k.p20 = 0;
  1321.     k.p21 = name;
  1322.     return _ksys70(&k).status;
  1323. }
  1324.  
  1325. #define _ksys_dir_rename _ksys_file_rename
  1326.  
  1327. /*============  Function 71, subfunction 1 - set window title ============= */
  1328.  
  1329. KOSAPI void _ksys_set_window_title(const char* title)
  1330. {
  1331.     asm_inline("int $0x40" ::"a"(71), "b"(1), "c"(title)
  1332.                : "memory");
  1333. }
  1334.  
  1335. #define _ksys_clear_window_title() _ksys_set_window_title(NULL)
  1336.  
  1337. /*============= Function 77 - implements the POSIX subsystem. =============*/
  1338.  
  1339. KOSAPI int _ksys_posix_read(int pipefd, void* buff, int n)
  1340. {
  1341.     int count;
  1342.     asm_inline(
  1343.         "int $0x40"
  1344.         : "=a"(count)
  1345.         : "a"(77), "b"(10), "c"(pipefd), "d"(buff), "S"(n)
  1346.         : "memory");
  1347.     return count;
  1348. }
  1349.  
  1350. KOSAPI int _ksys_posix_write(int pipefd, void* buff, int n)
  1351. {
  1352.     int count;
  1353.     asm_inline(
  1354.         "int $0x40"
  1355.         : "=a"(count)
  1356.         : "a"(77), "b"(11), "c"(pipefd), "d"(buff), "S"(n)
  1357.         : "memory");
  1358.     return count;
  1359. }
  1360.  
  1361. KOSAPI int _ksys_posix_pipe2(int pipefd[2], int flags)
  1362. {
  1363.     int err;
  1364.     asm_inline(
  1365.         "int $0x40"
  1366.         : "=a"(err)
  1367.         : "a"(77), "b"(13), "c"(pipefd), "d"(flags)
  1368.         : "memory");
  1369.     return err;
  1370. }
  1371.  
  1372. /* ######### Old names of functions and structures. Do not use again! ##########*/
  1373.  
  1374. #define _ksys_get_event     _ksys_wait_event
  1375. #define _ksys_file_get_info _ksys_file_info
  1376.  
  1377. static inline int _ksys_file_read_file(const char* name, unsigned long long offset, unsigned size, void* buff, unsigned* bytes_read)
  1378. {
  1379.     ksys70_status_t res = _ksys_file_read(name, offset, size, buff);
  1380.     *bytes_read = res.rw_bytes;
  1381.     return res.status;
  1382. }
  1383.  
  1384. static inline int _ksys_file_write_file(const char* name, unsigned long long offset, unsigned size, const void* buff, unsigned* bytes_write)
  1385. {
  1386.     ksys70_status_t res = _ksys_file_write(name, offset, size, buff);
  1387.     *bytes_write = res.rw_bytes;
  1388.     return res.status;
  1389. }
  1390.  
  1391. #endif // _KSYS_H_
  1392.