Rev 9788 | Rev 9830 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9788 | turbocat | 1 | #ifndef _KSYS_H_ |
2 | #define _KSYS_H_ |
||
3 | |||
9767 | turbocat | 4 | /* Copyright (C) KolibriOS team 2004-2021. All rights reserved. */ |
5 | /* Distributed under terms of the GNU General Public License */ |
||
6 | |||
7 | /* This file contains basic wrappers over KolibriOS system calls. */ |
||
8 | /* See sysfuncs.txt file for details. */ |
||
9 | |||
10 | /* |
||
11 | * This file was created with you in mind. Lest you reinvent the wheel. |
||
12 | * If for some reason there is not enough wrapper add! I ask you to stick to the same style: snake_case. |
||
13 | * Structure names must start with "ksys_" and end with "_t". |
||
14 | * All wrappers must start with the "_ksys_" prefix. |
||
15 | * I consider it mandatory to place the wrappers in the correct order in the official documentation. |
||
16 | * Enjoy writing your code :) |
||
17 | |||
18 | * Warning! The end of the file is the old definitions of function/structure names. |
||
19 | * They are for compatibility... Better not to use them. |
||
20 | */ |
||
21 | |||
22 | #include |
||
23 | #include |
||
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 { |
||
9784 | turbocat | 61 | int16_t y; |
62 | int16_t x; |
||
9767 | turbocat | 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 | |||
9784 | turbocat | 119 | #define KSYS_THREAD_INFO_SIZE 1024 |
120 | |||
121 | typedef union { |
||
122 | struct { |
||
123 | uint32_t cpu_usage; // CPU usage (cycles per secondgoes) |
||
124 | uint16_t pos_in_window_stack; // position of the thread window in the window stack |
||
125 | uint16_t slot_num_window_stack; // slot number in window stack |
||
126 | uint16_t __reserved1; // reserved |
||
127 | char name[12]; // process/thread name |
||
128 | uint32_t memstart; // process address in memory |
||
129 | uint32_t memused; // used memory size - 1 |
||
130 | int pid; // identifier (PID/TID) |
||
131 | int winx_start; // window x-coordinate |
||
132 | int winy_start; // window y-coordinate |
||
133 | int winx_size; // x-axis flow window size |
||
134 | int winy_size; // y-axis flow window size |
||
135 | uint16_t slot_state; // thread slot state |
||
136 | uint16_t __reserved2; // reserved |
||
137 | int clientx; // client area start coordinate x-axis |
||
138 | int clienty; // client area start coordinate y-axis |
||
139 | int clientwidth; // client area width |
||
140 | int clientheight; // client area height |
||
141 | uint8_t window_state; // window state - bitfield |
||
142 | uint8_t event_mask; // event mask |
||
143 | uint8_t key_input_mode; // keyboard input mode |
||
144 | }; |
||
145 | uint8_t __reserved3[KSYS_THREAD_INFO_SIZE]; |
||
9767 | turbocat | 146 | } ksys_thread_t; |
147 | |||
148 | typedef unsigned int ksys_color_t; |
||
149 | |||
150 | typedef struct { |
||
151 | ksys_color_t frame_area; |
||
152 | ksys_color_t grab_bar; |
||
153 | ksys_color_t grab_bar_button; |
||
154 | ksys_color_t grab_button_text; |
||
155 | ksys_color_t grab_text; |
||
156 | ksys_color_t work_area; |
||
157 | ksys_color_t work_button; |
||
158 | ksys_color_t work_button_text; |
||
159 | ksys_color_t work_text; |
||
160 | ksys_color_t work_graph; |
||
161 | } ksys_colors_table_t; |
||
162 | |||
163 | typedef struct { |
||
164 | unsigned pid; // PID of sending thread |
||
165 | unsigned datalen; // data bytes |
||
166 | char* data; // data begin |
||
167 | } ksys_ipc_msg; |
||
168 | |||
169 | typedef struct { |
||
170 | unsigned lock; // nonzero is locked |
||
171 | unsigned used; // used bytes in buffer |
||
172 | ksys_ipc_msg* data; // data begin |
||
173 | } ksys_ipc_buffer; |
||
174 | |||
175 | typedef struct { |
||
176 | char* func_name; |
||
177 | void* func_ptr; |
||
178 | } ksys_dll_t; |
||
179 | |||
180 | typedef unsigned ksys_drv_hand_t; |
||
181 | |||
182 | typedef struct { |
||
183 | ksys_drv_hand_t handler; |
||
184 | unsigned func_num; |
||
185 | void* in_data_ptr; |
||
186 | unsigned in_data_size; |
||
187 | void* out_data_ptr; |
||
188 | unsigned out_data_size; |
||
189 | } ksys_ioctl_t; |
||
190 | |||
191 | typedef struct { |
||
192 | char key[64]; |
||
193 | char path[64]; |
||
194 | } ksys_dir_key_t; |
||
195 | |||
9788 | turbocat | 196 | typedef union { |
197 | uint8_t raw_data[24]; |
||
198 | struct { |
||
199 | uint32_t id; |
||
200 | uint8_t data[20]; |
||
201 | }; |
||
202 | } ksys_signal_info_t; |
||
203 | |||
9767 | turbocat | 204 | #pragma pack(pop) |
205 | |||
206 | typedef rgb_t ksys_bitmap_t; |
||
207 | |||
208 | enum KSYS_FS_ERRORS { |
||
209 | KSYS_FS_ERR_SUCCESS = 0, // Success |
||
210 | KSYS_FS_ERR_1 = 1, // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8) |
||
211 | KSYS_FS_ERR_2 = 2, // Function is not supported for the given file system |
||
212 | KSYS_FS_ERR_3 = 3, // Unknown file system |
||
213 | KSYS_FS_ERR_4 = 4, // Reserved, is never returned in the current implementation |
||
214 | KSYS_FS_ERR_5 = 5, // File not found |
||
215 | KSYS_FS_ERR_EOF = 6, // End of file, EOF |
||
216 | KSYS_FS_ERR_7 = 7, // Pointer lies outside of application memory |
||
217 | KSYS_FS_ERR_8 = 8, // Disk is full |
||
218 | KSYS_FS_ERR_9 = 9, // FAT table is destroyed |
||
219 | KSYS_FS_ERR_10 = 10, // Access denied |
||
220 | KSYS_FS_ERR_11 = 11 // Device error |
||
221 | }; |
||
222 | |||
223 | enum KSYS_EVENTS { |
||
224 | KSYS_EVENT_NONE = 0, /* Event queue is empty */ |
||
225 | KSYS_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */ |
||
226 | KSYS_EVENT_KEY = 2, /* A key on the keyboard was pressed */ |
||
227 | KSYS_EVENT_BUTTON = 3, /* A button was clicked with the mouse */ |
||
228 | KSYS_EVENT_DESKTOP = 5, /* Desktop redraw finished */ |
||
229 | KSYS_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */ |
||
230 | KSYS_EVENT_IPC = 7, /* Interprocess communication notify */ |
||
231 | KSYS_EVENT_NETWORK = 8, /* Network event */ |
||
232 | KSYS_EVENT_DEBUG = 9, /* Debug subsystem event */ |
||
233 | KSYS_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ |
||
234 | }; |
||
235 | |||
236 | enum KSYS_FILE_ENCODING { |
||
237 | KSYS_FILE_CP866 = 1, |
||
238 | KSYS_FILE_UTF16LE = 2, |
||
239 | KSYS_FILE_UTF8 = 3 |
||
240 | }; |
||
241 | |||
242 | enum KSYS_TITLE_ENCODING { |
||
243 | KSYS_TITLE_CP866 = 1, |
||
244 | KSYS_TITLE_UTF16LE = 2, |
||
245 | KSYS_TITLE_UTF8 = 3 |
||
246 | }; |
||
247 | |||
9829 | vitalkrilo | 248 | enum KSYS_SCANCODES { |
249 | KSYS_SCANCODE_ANY = 0, |
||
250 | KSYS_SCANCODE_ESC = 1, |
||
251 | KSYS_SCANCODE_1 = 2, |
||
252 | KSYS_SCANCODE_2 = 3, |
||
253 | KSYS_SCANCODE_3 = 4, |
||
254 | KSYS_SCANCODE_4 = 5, |
||
255 | KSYS_SCANCODE_5 = 6, |
||
256 | KSYS_SCANCODE_6 = 7, |
||
257 | KSYS_SCANCODE_7 = 8, |
||
258 | KSYS_SCANCODE_8 = 9, |
||
259 | KSYS_SCANCODE_9 = 10, |
||
260 | KSYS_SCANCODE_0 = 11, |
||
261 | KSYS_SCANCODE_MINUS = 12, |
||
262 | KSYS_SCANCODE_EQUAL = 13, |
||
263 | KSYS_SCANCODE_BACKSPACE = 14, |
||
264 | KSYS_SCANCODE_TAB = 15, |
||
265 | KSYS_SCANCODE_Q = 16, |
||
266 | KSYS_SCANCODE_W = 17, |
||
267 | KSYS_SCANCODE_E = 18, |
||
268 | KSYS_SCANCODE_R = 19, |
||
269 | KSYS_SCANCODE_T = 20, |
||
270 | KSYS_SCANCODE_Y = 21, |
||
271 | KSYS_SCANCODE_U = 22, |
||
272 | KSYS_SCANCODE_I = 23, |
||
273 | KSYS_SCANCODE_O = 24, |
||
274 | KSYS_SCANCODE_P = 25, |
||
275 | KSYS_SCANCODE_LBRACE = 26, |
||
276 | KSYS_SCANCODE_RBRACE = 27, |
||
277 | KSYS_SCANCODE_ENTER = 28, |
||
278 | KSYS_SCANCODE_EXT_NUMPAD_ENTER = 28, |
||
279 | KSYS_SCANCODE_LCTRL = 29, |
||
280 | KSYS_SCANCODE_EXT_RCTRL = 29, |
||
281 | KSYS_SCANCODE_A = 30, |
||
282 | KSYS_SCANCODE_S = 31, |
||
283 | KSYS_SCANCODE_D = 32, |
||
284 | KSYS_SCANCODE_F = 33, |
||
285 | KSYS_SCANCODE_G = 34, |
||
286 | KSYS_SCANCODE_H = 35, |
||
287 | KSYS_SCANCODE_J = 36, |
||
288 | KSYS_SCANCODE_K = 37, |
||
289 | KSYS_SCANCODE_L = 38, |
||
290 | KSYS_SCANCODE_SEMICOLON = 39, |
||
291 | KSYS_SCANCODE_SQUOTE = 40, |
||
292 | KSYS_SCANCODE_BQUOTE = 41, |
||
293 | KSYS_SCANCODE_LSHIFT = 42, |
||
294 | KSYS_SCANCODE_BACKSLASH = 43, |
||
295 | KSYS_SCANCODE_Z = 44, |
||
296 | KSYS_SCANCODE_X = 45, |
||
297 | KSYS_SCANCODE_C = 46, |
||
298 | KSYS_SCANCODE_V = 47, |
||
299 | KSYS_SCANCODE_B = 48, |
||
300 | KSYS_SCANCODE_N = 49, |
||
301 | KSYS_SCANCODE_M = 50, |
||
302 | KSYS_SCANCODE_COMMA = 51, |
||
303 | KSYS_SCANCODE_POINT = 52, |
||
304 | KSYS_SCANCODE_SLASH = 53, |
||
305 | KSYS_SCANCODE_EXT_NUMPAD_DIV = 53, |
||
306 | KSYS_SCANCODE_RSHIFT = 54, |
||
307 | KSYS_SCANCODE_NUMPAD_MULT = 55, |
||
308 | KSYS_SCANCODE_EXT_PRTSCR = 55, |
||
309 | KSYS_SCANCODE_LALT = 56, |
||
310 | KSYS_SCANCODE_EXT_RALT = 56, |
||
311 | KSYS_SCANCODE_SPACE = 57, |
||
312 | KSYS_SCANCODE_CAPSLOCK = 58, |
||
313 | KSYS_SCANCODE_F1 = 59, |
||
314 | KSYS_SCANCODE_F2 = 60, |
||
315 | KSYS_SCANCODE_F3 = 61, |
||
316 | KSYS_SCANCODE_F4 = 62, |
||
317 | KSYS_SCANCODE_F5 = 63, |
||
318 | KSYS_SCANCODE_F6 = 64, |
||
319 | KSYS_SCANCODE_F7 = 65, |
||
320 | KSYS_SCANCODE_F8 = 66, |
||
321 | KSYS_SCANCODE_F9 = 67, |
||
322 | KSYS_SCANCODE_F10 = 68, |
||
323 | KSYS_SCANCODE_NUMLOCK = 69, |
||
324 | KSYS_SCANCODE_SCRLOCK = 70, |
||
325 | KSYS_SCANCODE_NUMPAD_7 = 71, |
||
326 | KSYS_SCANCODE_EXT_HOME = 71, |
||
327 | KSYS_SCANCODE_NUMPAD_8 = 72, |
||
328 | KSYS_SCANCODE_EXT_UP = 72, |
||
329 | KSYS_SCANCODE_NUMPAD_9 = 73, |
||
330 | KSYS_SCANCODE_EXT_PGUP = 73, |
||
331 | KSYS_SCANCODE_NUMPAD_MINUS = 74, |
||
332 | KSYS_SCANCODE_NUMPAD_4 = 75, |
||
333 | KSYS_SCANCODE_EXT_LEFT = 75, |
||
334 | KSYS_SCANCODE_NUMPAD_5 = 76, |
||
335 | KSYS_SCANCODE_NUMPAD_6 = 77, |
||
336 | KSYS_SCANCODE_EXT_RIGHT = 77, |
||
337 | KSYS_SCANCODE_NUMPAD_PLUS = 78, |
||
338 | KSYS_SCANCODE_NUMPAD_1 = 79, |
||
339 | KSYS_SCANCODE_EXT_END = 79, |
||
340 | KSYS_SCANCODE_NUMPAD_2 = 80, |
||
341 | KSYS_SCANCODE_EXT_DOWN = 80, |
||
342 | KSYS_SCANCODE_NUMPAD_3 = 81, |
||
343 | KSYS_SCANCODE_EXT_PGDOWN = 81, |
||
344 | KSYS_SCANCODE_NUMPAD_0 = 82, |
||
345 | KSYS_SCANCODE_EXT_INSERT = 82, |
||
346 | KSYS_SCANCODE_NUMPAD_COMMA = 83, |
||
347 | KSYS_SCANCODE_EXT_DELETE = 83, |
||
348 | //84-86 doesn't exist |
||
349 | KSYS_SCANCODE_F11 = 87, |
||
350 | KSYS_SCANCODE_F12 = 88, |
||
351 | //89,90 doesn't exist |
||
352 | KSYS_SCANCODE_EXT_LWIN = 91, |
||
353 | KSYS_SCANCODE_EXT_RWIN = 92, |
||
354 | KSYS_SCANCODE_EXT_MENU = 93, |
||
355 | KSYS_SCANCODE_EXT = 0xE0, |
||
356 | |||
357 | KSYS_SCANCODE_UNK_M_UP = 250 // Is it needed? |
||
358 | }; |
||
359 | |||
9767 | turbocat | 360 | KOSAPI int __strcmp(const char* s1, const char* s2) |
361 | { |
||
362 | while ((*s1) && (*s1 == *s2)) { |
||
363 | ++s1; |
||
364 | ++s2; |
||
365 | } |
||
366 | return (*(unsigned char*)s1 - *(unsigned char*)s2); |
||
367 | } |
||
368 | |||
369 | /* ####################################################################### */ |
||
370 | /* ############### С wrappers for system calls Kolibri OS ################ */ |
||
371 | /* ####################################################################### */ |
||
372 | |||
373 | /*=============== Function -1 - terminate thread/process ===============*/ |
||
374 | |||
375 | KOSAPI void _ksys_exit(void) |
||
376 | { |
||
377 | asm_inline("int $0x40" ::"a"(-1)); |
||
378 | } |
||
379 | |||
380 | /*============== Function 0 - define and draw the window. ==============*/ |
||
381 | |||
382 | 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) |
||
383 | { |
||
384 | asm_inline( |
||
385 | "int $0x40" ::"a"(0), |
||
386 | "b"((x << 16) | ((w - 1) & 0xFFFF)), |
||
387 | "c"((y << 16) | ((h - 1) & 0xFFFF)), |
||
388 | "d"((style << 24) | (workcolor & 0xFFFFFF)), |
||
389 | "D"(name), |
||
390 | "S"(0) |
||
391 | : "memory"); |
||
392 | } |
||
393 | |||
394 | /*================ Function 1 - put pixel in the window. ===============*/ |
||
395 | |||
396 | KOSAPI void _ksys_draw_pixel(uint32_t x, uint32_t y, ksys_color_t color) |
||
397 | { |
||
398 | asm_inline( |
||
399 | "int $0x40" ::"a"(1), "b"(x), "c"(y), "d"(color)); |
||
400 | } |
||
401 | |||
402 | /*============ Function 2 - get the code of the pressed key. ===========*/ |
||
403 | |||
404 | KOSAPI ksys_oskey_t _ksys_get_key(void) |
||
405 | { |
||
406 | ksys_oskey_t val; |
||
407 | asm_inline( |
||
408 | "int $0x40" |
||
9784 | turbocat | 409 | : "=a"(val.val) |
9767 | turbocat | 410 | : "a"(2)); |
411 | return val; |
||
412 | } |
||
413 | |||
414 | /*==================== Function 3 - get system time. ===================*/ |
||
415 | |||
416 | KOSAPI ksys_time_t _ksys_get_time(void) |
||
417 | { |
||
418 | ksys_time_t c_time; |
||
419 | asm_inline( |
||
420 | "int $0x40" |
||
421 | : "=a"(c_time) |
||
422 | : "a"(3) |
||
423 | : "memory"); |
||
424 | return c_time; |
||
425 | } |
||
426 | |||
427 | /*=================== Function 4 - draw text string. ===================*/ |
||
428 | KOSAPI void _ksys_draw_text(const char* text, uint32_t x, uint32_t y, uint32_t len, ksys_color_t color) |
||
429 | { |
||
430 | asm_inline( |
||
431 | "int $0x40" ::"a"(4), "d"(text), |
||
432 | "b"((x << 16) | y), |
||
433 | "S"(len), "c"(color) |
||
434 | : "memory"); |
||
435 | } |
||
436 | |||
437 | /*========================= Function 5 - delay. ========================*/ |
||
438 | |||
439 | KOSAPI void _ksys_delay(uint32_t time) |
||
440 | { |
||
441 | asm_inline( |
||
442 | "int $0x40" ::"a"(5), "b"(time) |
||
443 | : "memory"); |
||
444 | } |
||
445 | |||
446 | /*=============== Function 7 - draw image in the window. ===============*/ |
||
447 | |||
448 | KOSAPI void _ksys_draw_bitmap(void* bitmap, int x, int y, int w, int h) |
||
449 | { |
||
450 | asm_inline( |
||
451 | "int $0x40" ::"a"(7), "b"(bitmap), |
||
452 | "c"((w << 16) | h), |
||
453 | "d"((x << 16) | y) |
||
454 | : "memory"); |
||
455 | } |
||
456 | |||
457 | /*=============== Function 8 - define/delete the button. ===============*/ |
||
458 | |||
459 | KOSAPI void _ksys_define_button(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t id, ksys_color_t color) |
||
460 | { |
||
461 | asm_inline( |
||
462 | "int $0x40" ::"a"(8), |
||
463 | "b"((x << 16) + w), |
||
464 | "c"((y << 16) + h), |
||
465 | "d"(id), |
||
466 | "S"(color)); |
||
467 | }; |
||
468 | |||
469 | KOSAPI void _ksys_delete_button(uint32_t id) |
||
470 | { |
||
471 | asm_inline( |
||
472 | "int $0x40" ::"a"(8), "d"(id & 0x00FFFFFF | 0x80000000)); |
||
473 | } |
||
474 | |||
475 | /*============ Function 9 - information on execution thread. ===========*/ |
||
476 | |||
9788 | turbocat | 477 | #define KSYS_THIS_SLOT -1 |
478 | |||
479 | enum KSYS_SLOT_STATES { |
||
480 | KSYS_SLOT_STATE_RUNNING = 0, |
||
481 | KSYS_SLOT_STATE_SUSPENDED = 1, |
||
482 | KSYS_SLOT_STATE_SUSPENDED_WAIT_EVENT = 2, |
||
483 | KSYS_SLOT_STATE_NORMAL_TERM = 3, |
||
484 | KSYS_SLOT_STATE_EXCEPT_TERM = 4, |
||
485 | KSYS_SLOT_STATE_WAIT_EVENT = 5, |
||
486 | KSYS_SLOT_STATE_FREE = 6 |
||
487 | }; |
||
488 | |||
9767 | turbocat | 489 | KOSAPI int _ksys_thread_info(ksys_thread_t* table, int slot) |
490 | { |
||
491 | int val; |
||
492 | asm_inline( |
||
493 | "int $0x40" |
||
494 | : "=a"(val) |
||
495 | : "a"(9), "b"(table), "c"(slot) |
||
496 | : "memory"); |
||
497 | return val; |
||
498 | } |
||
499 | |||
500 | /*==================== Function 10 - wait for event. ===================*/ |
||
501 | |||
502 | KOSAPI uint32_t _ksys_wait_event(void) |
||
503 | { |
||
504 | uint32_t val; |
||
505 | asm_inline( |
||
506 | "int $0x40" |
||
507 | : "=a"(val) |
||
508 | : "a"(10)); |
||
509 | return val; |
||
510 | } |
||
511 | |||
512 | /*=============== Function 11 - check for event, no wait. ==============*/ |
||
513 | |||
514 | KOSAPI uint32_t _ksys_check_event(void) |
||
515 | { |
||
516 | uint32_t val; |
||
517 | asm_inline( |
||
518 | "int $0x40" |
||
519 | : "=a"(val) |
||
520 | : "a"(11)); |
||
521 | return val; |
||
522 | } |
||
523 | |||
524 | /*=============== Function 12 - begin/end window redraw. ===============*/ |
||
525 | |||
526 | KOSAPI void _ksys_start_draw(void) |
||
527 | { |
||
528 | asm_inline("int $0x40" ::"a"(12), "b"(1)); |
||
529 | } |
||
530 | |||
531 | KOSAPI void _ksys_end_draw(void) |
||
532 | { |
||
533 | asm_inline("int $0x40" ::"a"(12), "b"(2)); |
||
534 | } |
||
535 | |||
536 | /*============ Function 13 - draw a rectangle in the window. ===========*/ |
||
537 | |||
538 | KOSAPI void _ksys_draw_bar(uint32_t x, uint32_t y, uint32_t w, uint32_t h, ksys_color_t color) |
||
539 | { |
||
540 | asm_inline( |
||
541 | "int $0x40" ::"a"(13), "d"(color), |
||
542 | "b"((x << 16) | w), |
||
543 | "c"((y << 16) | h)); |
||
544 | } |
||
545 | |||
546 | /*=================== Function 14 - get screen size. ===================*/ |
||
547 | |||
548 | KOSAPI ksys_pos_t _ksys_screen_size(void) |
||
549 | { |
||
550 | ksys_pos_t size; |
||
551 | asm_inline( |
||
552 | "int $0x40" |
||
9784 | turbocat | 553 | : "=a"(size) |
9767 | turbocat | 554 | : "a"(14)); |
555 | return size; |
||
556 | } |
||
557 | |||
558 | /*== Function 15, subfunction 1 - set a size of the background image. ==*/ |
||
559 | |||
560 | KOSAPI void _ksys_bg_set_size(uint32_t w, uint32_t h) |
||
561 | { |
||
562 | asm_inline( |
||
563 | "int $0x40" ::"a"(15), "b"(1), "c"(w), "d"(h)); |
||
564 | } |
||
565 | |||
566 | /*=== Function 15, subfunction 2 - put pixel on the background image. ==*/ |
||
567 | |||
568 | KOSAPI void _ksys_bg_put_pixel(uint32_t x, uint32_t y, uint32_t w, ksys_color_t color) |
||
569 | { |
||
570 | asm_inline( |
||
571 | "int $0x40" ::"a"(15), "b"(2), "c"((x + y * w) * 3), "d"(color)); |
||
572 | } |
||
573 | |||
574 | /*=========== Function 15, subfunction 3 - redraw background. ==========*/ |
||
575 | |||
576 | KOSAPI void _ksys_bg_redraw(void) |
||
577 | { |
||
578 | asm_inline( |
||
579 | "int $0x40" ::"a"(15), "b"(3)); |
||
580 | } |
||
581 | |||
582 | /*== Function 15, subfunction 4 - set drawing mode for the background. =*/ |
||
583 | |||
584 | enum KSYS_BG_MODES { |
||
585 | KSYS_BG_MODE_PAVE = 1, |
||
586 | KSYS_BG_MODE_STRETCH = 2 |
||
587 | }; |
||
588 | |||
589 | KOSAPI void _ksys_bg_set_mode(uint32_t mode) |
||
590 | { |
||
591 | asm_inline( |
||
592 | "int $0x40" ::"a"(15), "b"(4), "c"(mode)); |
||
593 | } |
||
594 | |||
595 | /*===================== Function 15, subfunction 5 =====================*/ |
||
596 | /*============ Put block of pixels on the background image. ============*/ |
||
597 | |||
598 | KOSAPI void _ksys_bg_put_bitmap(ksys_bitmap_t* bitmap, size_t bitmap_size, uint32_t x, uint32_t y, uint32_t w) |
||
599 | { |
||
600 | asm_inline( |
||
601 | "int $0x40" ::"a"(15), "b"(5), "c"(bitmap), "d"((x + y * w) * 3), "S"(bitmap_size)); |
||
602 | } |
||
603 | |||
604 | /*===================== Function 15, subfunction 6 =====================*/ |
||
605 | /*======= Map background data to the address space of process. ==========*/ |
||
606 | |||
607 | KOSAPI ksys_bitmap_t* _ksys_bg_get_map(void) |
||
608 | { |
||
609 | ksys_bitmap_t* bitmap; |
||
610 | asm_inline( |
||
611 | "int $0x40" |
||
612 | : "=a"(bitmap) |
||
613 | : "a"(15), "b"(6)); |
||
614 | return bitmap; |
||
615 | } |
||
616 | |||
617 | /*===== Function 15, subfunction 7 - close mapped background data. =====*/ |
||
618 | |||
619 | KOSAPI int _ksys_bg_close_map(ksys_bitmap_t* bitmap) |
||
620 | { |
||
621 | int status; // 1 - OK, 0 - ERROR |
||
622 | asm_inline( |
||
623 | "int $0x40" |
||
624 | : "=a"(status) |
||
625 | : "a"(15), "b"(7), "c"(bitmap)); |
||
626 | return status; |
||
627 | } |
||
628 | |||
629 | /*===================== Function 15, subfunction 9 =====================*/ |
||
630 | /*============= Redraws a rectangular part of the background ===========*/ |
||
631 | |||
632 | KOSAPI void _ksys_bg_redraw_bar(ksys_pos_t angle1, ksys_pos_t angle2) |
||
633 | { |
||
634 | asm_inline( |
||
635 | "int $0x40" ::"a"(15), "b"(9), |
||
636 | "c"(angle1.x * (1 << 16) + angle2.x), |
||
637 | "d"(angle1.y * (1 << 16) + angle2.y)); |
||
638 | } |
||
639 | |||
640 | /*=============== Function 16 - save ramdisk on a floppy. ==============*/ |
||
641 | |||
642 | KOSAPI int _ksys_save_ramdisk_fd(uint32_t floppy_id) |
||
643 | { |
||
644 | int status; // 0 - OK, 1 - ERROR |
||
645 | asm_inline( |
||
646 | "int $0x40" |
||
647 | : "=a"(status) |
||
648 | : "a"(16), "b"(floppy_id)); |
||
649 | return status; |
||
650 | } |
||
651 | |||
652 | /*======= Function 17 - get the identifier of the pressed button. ======*/ |
||
653 | |||
654 | KOSAPI uint32_t _ksys_get_button(void) |
||
655 | { |
||
656 | unsigned val; |
||
657 | asm_inline( |
||
658 | "int $0x40" |
||
659 | : "=a"(val) |
||
660 | : "a"(17)); |
||
661 | return val >> 8; |
||
662 | } |
||
663 | |||
664 | /*===================== Function 18, subfunction 1 =====================*/ |
||
665 | /*============= Make deactive the window of the given thread. ==========*/ |
||
666 | |||
667 | KOSAPI void _ksys_unfocus_window(int slot) |
||
668 | { |
||
669 | asm_inline( |
||
670 | "int $0x40" ::"a"(18), "b"(1), "c"(slot)); |
||
671 | } |
||
672 | |||
673 | /*= Function 18, subfunction 2 - terminate process/thread by the slot. =*/ |
||
674 | |||
675 | KOSAPI void _ksys_kill_by_slot(int slot) |
||
676 | { |
||
677 | asm_inline( |
||
678 | "int $0x40" ::"a"(18), "b"(2), "c"(slot)); |
||
679 | } |
||
680 | |||
681 | /*===================== Function 18, subfunction 3 =====================*/ |
||
682 | /*============= Make active the window of the given thread. ============*/ |
||
683 | |||
684 | KOSAPI void _ksys_focus_window(int slot) |
||
685 | { |
||
686 | asm_inline( |
||
687 | "int $0x40" ::"a"(18), "b"(3), "c"(slot)); |
||
688 | } |
||
689 | |||
690 | /*===================== Function 18, subfunction 4 =====================*/ |
||
691 | /*=========== Get counter of idle time units per one second. ===========*/ |
||
692 | |||
693 | KOSAPI uint32_t _ksys_get_idle(void) |
||
694 | { |
||
695 | uint32_t sec; |
||
696 | asm_inline( |
||
697 | "int $0x40" |
||
698 | : "=a"(sec) |
||
699 | : "a"(18), "b"(4)); |
||
700 | return sec; |
||
701 | } |
||
702 | |||
703 | /*========== Function 18, subfunction 5 - get CPU clock rate. ==========*/ |
||
704 | /*================ modulo 2^32 clock ticks = 4GHz ======================*/ |
||
705 | |||
706 | KOSAPI uint32_t _ksys_get_cpu_clock(void) |
||
707 | { |
||
708 | uint32_t clock; |
||
709 | asm_inline( |
||
710 | "int $0x40" |
||
711 | : "=a"(clock) |
||
712 | : "a"(18), "b"(5)); |
||
713 | return clock; |
||
714 | } |
||
715 | |||
716 | /* Function 18, subfunction 6 - save ramdisk to the file on hard drive. */ |
||
717 | |||
718 | KOSAPI uint32_t _ksys_save_ramdisk_hd(const char* ramdisk_path) |
||
719 | { |
||
720 | uint32_t fs_err; |
||
721 | asm_inline( |
||
722 | "int $0x40" |
||
723 | : "=a"(fs_err) |
||
724 | : "a"(18), "b"(6), "c"(ramdisk_path)); |
||
725 | return fs_err; |
||
726 | } |
||
727 | |||
728 | /* Function 18, subfunction 9 - system shutdown with the parameter. */ |
||
729 | |||
730 | enum KSYS_SHD_PARAM { |
||
731 | KSYS_SHD_POWEROFF = 2, |
||
732 | KSYS_SHD_REBOOT = 3, |
||
733 | KSYS_SHD_RESTART_KRN = 4 |
||
734 | }; |
||
735 | |||
736 | KOSAPI void _ksys_shutdown(uint32_t shd_param) |
||
737 | { |
||
738 | asm_inline( |
||
739 | "int $0x40" ::"a"(18), "b"(9), "c"(shd_param)); |
||
740 | } |
||
741 | |||
742 | /*========= Function 18, subfunction 16 - get size of free RAM. ========*/ |
||
743 | |||
744 | KOSAPI size_t _ksys_get_ram_size(void) |
||
745 | { |
||
746 | size_t size; |
||
747 | asm_inline( |
||
748 | "int $0x40" |
||
749 | : "=a"(size) |
||
750 | : "a"(18), "b"(16)); |
||
751 | return size; |
||
752 | } |
||
753 | |||
754 | /*======== Function 18, subfunction 17 - get full amount of RAM. =======*/ |
||
755 | |||
756 | KOSAPI size_t _ksys_get_full_ram(void) |
||
757 | { |
||
758 | size_t size; |
||
759 | asm_inline( |
||
760 | "int $0x40" |
||
761 | : "=a"(size) |
||
762 | : "a"(18), "b"(17)); |
||
763 | return size; |
||
764 | } |
||
765 | |||
766 | /*===================== Function 18, subfunction 18 ====================*/ |
||
767 | /*============= Terminate process/thread by the identifier. ============*/ |
||
768 | |||
769 | KOSAPI void _ksys_kill_by_pid(uint32_t PID) |
||
770 | { |
||
771 | asm_inline("int $0x40" ::"a"(18), "b"(18), "c"(PID)); |
||
772 | } |
||
773 | |||
774 | /*========= Fuction 18, subfunction 19 - get/set mouse settings. ========*/ |
||
775 | |||
9784 | turbocat | 776 | typedef enum KSYS_MOUSE_SETTINGS { |
777 | KSYS_MOUSE_GET_SPEED = 0, // Get mouse speed |
||
778 | KSYS_MOUSE_SET_SPEED = 1, // Set mouse speed |
||
779 | KSYS_MOUSE_GET_SENS = 2, // Get mouse sensitivity |
||
780 | KSYS_MOUSE_SET_SENS = 3, // Set mouse sensitivity |
||
781 | KSYS_MOUSE_SET_POS = 4, // Set the position of the mouse cursor |
||
782 | KSYS_MOUSE_SIM_STATE = 5, // Simulate the state of the mouse buttons |
||
783 | KSYS_MOUSE_GET_DOUBLE_CLICK_DELAY = 6, // Get double click delay. |
||
784 | KSYS_MOUSE_SET_DOUBLE_CLICK_DELAY = 7 // Set double click delay. |
||
785 | } ksys_mouse_settings_t; |
||
786 | |||
787 | KOSAPI uint32_t _ksys_set_mouse_settings(ksys_mouse_settings_t settings, uint32_t arg) |
||
9767 | turbocat | 788 | { |
9784 | turbocat | 789 | uint32_t retval; |
790 | asm_inline( |
||
791 | "int $0x40" |
||
792 | : "=a"(retval) |
||
793 | : "a"(18), "b"(19), "c"(settings), "d"(arg) |
||
794 | : "memory"); |
||
795 | return retval; |
||
9767 | turbocat | 796 | } |
797 | |||
9784 | turbocat | 798 | #define _ksys_set_mouse_pos(X, Y) _ksys_set_mouse_settings(KSYS_MOUSE_SET_POS, X * 65536 + Y) |
799 | |||
9767 | turbocat | 800 | /*===================== Function 18, subfunction 21 ====================*/ |
801 | /*=====Get the slot number of the process / thread by identifier.. =====*/ |
||
802 | |||
803 | KOSAPI int _ksys_get_thread_slot(int PID) |
||
804 | { |
||
805 | int val; |
||
806 | asm_inline( |
||
807 | "int $0x40" |
||
808 | : "=a"(val) |
||
809 | : "a"(18), "b"(21), "c"(PID)); |
||
810 | return val; |
||
811 | } |
||
812 | |||
813 | /*============= Function 23 - wait for event with timeout. =============*/ |
||
814 | |||
815 | KOSAPI uint32_t _ksys_wait_event_timeout(uint32_t timeout) |
||
816 | { |
||
817 | unsigned val; |
||
818 | asm_inline( |
||
819 | "int $0x40" |
||
820 | : "=a"(val) |
||
821 | : "a"(23), "b"(timeout)); |
||
822 | return val; |
||
823 | } |
||
824 | |||
825 | /*=== Function 26, subfunction 9 - get the value of the time counter. ==*/ |
||
826 | |||
827 | KOSAPI uint32_t _ksys_get_tick_count(void) |
||
828 | { |
||
829 | unsigned val; |
||
830 | asm_inline( |
||
831 | "int $0x40" |
||
832 | : "=a"(val) |
||
833 | : "a"(26), "b"(9)); |
||
834 | return val; |
||
835 | } |
||
836 | |||
837 | /*===================== Function 26, subfunction 10 ====================*/ |
||
838 | /*========== Get the value of the high precision time counter. =========*/ |
||
839 | |||
840 | KOSAPI uint64_t _ksys_get_ns_count(void) |
||
841 | { |
||
842 | uint64_t val; |
||
843 | asm_inline( |
||
844 | "int $0x40" |
||
845 | : "=A"(val) |
||
846 | : "a"(26), "b"(10)); |
||
847 | return val; |
||
848 | } |
||
849 | |||
850 | /*=================== Function 29 - get system date. ===================*/ |
||
851 | |||
852 | KOSAPI ksys_date_t _ksys_get_date(void) |
||
853 | { |
||
854 | ksys_date_t val; |
||
855 | asm_inline("int $0x40" |
||
856 | : "=a"(val) |
||
857 | : "a"(29)); |
||
858 | return val; |
||
859 | } |
||
860 | |||
861 | /*===========+ Function 30 - work with the current folder.==============*/ |
||
862 | /*--------- Subfunction 1 - set current folder for the thread. ---------*/ |
||
863 | |||
864 | KOSAPI void _ksys_setcwd(char* dir) |
||
865 | { |
||
866 | asm_inline( |
||
867 | "int $0x40" ::"a"(30), "b"(1), "c"(dir)); |
||
868 | } |
||
869 | |||
870 | /*--------- Subfunction 2 - get current folder for the thread. ---------*/ |
||
871 | |||
872 | KOSAPI int _ksys_getcwd(char* buf, int bufsize) |
||
873 | { |
||
9784 | turbocat | 874 | int val; |
9767 | turbocat | 875 | asm_inline( |
876 | "int $0x40" |
||
877 | : "=a"(val) |
||
878 | : "a"(30), "b"(2), "c"(buf), "d"(bufsize)); |
||
879 | return val; |
||
880 | } |
||
881 | |||
882 | /* ---- Subfunction 3 - install the add.system directory for the kernel ------*/ |
||
883 | |||
884 | KOSAPI int _ksys_set_kernel_dir(ksys_dir_key_t* table) |
||
885 | { |
||
9784 | turbocat | 886 | int val; |
9767 | turbocat | 887 | asm_inline( |
888 | "int $0x40" |
||
889 | : "=a"(val) |
||
890 | : "a"(30), "b"(3), "c"(table) |
||
891 | : "memory"); |
||
892 | return val; |
||
893 | } |
||
894 | |||
895 | /*=================== Function 37 - work with mouse. ===================*/ |
||
896 | |||
897 | enum KSYS_MOUSE_POS { |
||
898 | KSYS_MOUSE_SCREEN_POS = 0, |
||
899 | KSYS_MOUSE_WINDOW_POS = 1 |
||
900 | }; |
||
901 | |||
902 | KOSAPI ksys_pos_t _ksys_get_mouse_pos(int origin) |
||
903 | { |
||
904 | ksys_pos_t pos; |
||
905 | asm_inline( |
||
9784 | turbocat | 906 | "int $0x40" |
9767 | turbocat | 907 | : "=a"(pos) |
908 | : "a"(37), "b"(origin)); |
||
909 | return pos; |
||
910 | } |
||
911 | |||
9784 | turbocat | 912 | enum KSYS_MOUSE_BUTTON { |
913 | KSYS_MOUSE_LBUTTON_PRESSED = (1 << 0), |
||
914 | KSYS_MOUSE_RBUTTON_PRESSED = (1 << 1), |
||
915 | KSYS_MOUSE_MBUTTON_PRESSED = (1 << 2), |
||
916 | KSYS_MOUSE_4BUTTON_PRESSED = (1 << 3), |
||
917 | KSYS_MOUSE_5BUTTON_PRESSED = (1 << 4) |
||
918 | }; |
||
919 | |||
9767 | turbocat | 920 | KOSAPI uint32_t _ksys_get_mouse_buttons(void) // subfunction 2 - states of the mouse buttons |
921 | { |
||
922 | uint32_t val; |
||
923 | asm_inline( |
||
924 | "int $0x40" |
||
925 | : "=a"(val) |
||
926 | : "a"(37), "b"(2)); |
||
927 | return val; |
||
928 | } |
||
929 | |||
930 | KOSAPI uint32_t _ksys_get_mouse_eventstate(void) // subfunction 3 - states and events of the mouse buttons |
||
931 | { |
||
932 | uint32_t val; |
||
933 | asm_inline( |
||
934 | "int $0x40" |
||
935 | : "=a"(val) |
||
936 | : "a"(37), "b"(3)); |
||
937 | return val; |
||
938 | } |
||
939 | |||
940 | enum KSYS_CURSOR_SRC { |
||
941 | KSYS_CURSOR_FROM_FILE = 0, |
||
942 | KSYS_CURSOR_FROM_MEM = 1, |
||
943 | KSYS_CURSOR_INDIRECT = 2 |
||
944 | }; |
||
945 | |||
946 | KOSAPI void* _ksys_load_cursor(void* path, uint32_t flags) // subfunction 4 - load cursor |
||
947 | { |
||
9784 | turbocat | 948 | void* val; |
9767 | turbocat | 949 | asm_inline( |
950 | "int $0x40" |
||
951 | : "=a"(val) |
||
952 | : "a"(37), "b"(4), "c"(path), "d"(flags) |
||
953 | : "memory"); |
||
954 | return val; |
||
955 | } |
||
956 | |||
957 | KOSAPI void* _ksys_set_cursor(void* cursor) // subfunction 5 - set cursor |
||
958 | { |
||
9784 | turbocat | 959 | void* old; |
9767 | turbocat | 960 | asm_inline( |
961 | "int $0x40" |
||
962 | : "=a"(old) |
||
963 | : "a"(37), "b"(5), "c"(cursor)); |
||
964 | return old; |
||
965 | } |
||
966 | |||
967 | KOSAPI int _ksys_delete_cursor(void* cursor) // subfunction 6 - delete cursor |
||
968 | { |
||
969 | int ret; |
||
970 | asm_inline( |
||
971 | "int $0x40" |
||
972 | : "=a"(ret) |
||
973 | : "a"(37), "b"(6), "c"(cursor) |
||
974 | : "memory"); |
||
975 | return ret; |
||
976 | } |
||
977 | |||
978 | KOSAPI uint32_t _ksys_get_mouse_wheels(void) // subfunction 7 - get scroll data |
||
979 | { |
||
980 | uint32_t val; |
||
981 | asm_inline( |
||
982 | "int $0x40" |
||
983 | : "=a"(val) |
||
984 | : "a"(37), "b"(7)); |
||
985 | return val; |
||
986 | } |
||
987 | |||
988 | /*=========== Function 40 - set the mask for expected events. ==========*/ |
||
989 | |||
990 | enum KSYS_EVENT_MASK { |
||
991 | KSYS_EVM_REDRAW = 1, |
||
992 | KSYS_EVM_KEY = 2, |
||
993 | KSYS_EVM_BUTTON = 4, |
||
994 | KSYS_EVM_EXIT = 8, |
||
995 | KSYS_EVM_BACKGROUND = 16, |
||
996 | KSYS_EVM_MOUSE = 32, |
||
997 | KSYS_EVM_IPC = 64, |
||
998 | KSYS_EVM_STACK = 128, |
||
999 | KSYS_EVM_DEBUG = 256, |
||
1000 | KSYS_EVM_STACK2 = 512, |
||
1001 | KSYS_EVM_MOUSE_FILTER = 0x80000000, |
||
1002 | KSYS_EVM_CURSOR_FILTER = 0x40000000, |
||
1003 | }; |
||
1004 | |||
1005 | KOSAPI uint32_t _ksys_set_event_mask(uint32_t mask) |
||
1006 | { |
||
1007 | unsigned val; |
||
1008 | asm_inline( |
||
1009 | "int $0x40" |
||
1010 | : "=a"(val) |
||
1011 | : "a"(40), "b"(mask)); |
||
1012 | return val; |
||
1013 | } |
||
1014 | |||
1015 | /*====================== Function 38 - draw line. ======================*/ |
||
1016 | |||
1017 | KOSAPI void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color) |
||
1018 | { |
||
1019 | asm_inline( |
||
1020 | "int $0x40" ::"a"(38), "d"(color), |
||
1021 | "b"((xs << 16) | xe), |
||
1022 | "c"((ys << 16) | ye)); |
||
1023 | } |
||
1024 | |||
1025 | /*============= Function 47 - draw a number in the window. =============*/ |
||
1026 | |||
1027 | KOSAPI void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color) |
||
1028 | { |
||
1029 | unsigned fmt; |
||
1030 | fmt = len << 16 | 0x80000000; // no leading zeros + width |
||
1031 | asm_inline( |
||
1032 | "int $0x40" ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color)); |
||
1033 | } |
||
1034 | |||
1035 | KOSAPI void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg) |
||
1036 | { |
||
1037 | unsigned fmt; |
||
1038 | fmt = len << 16 | 0x80000000; // no leading zeros + width |
||
1039 | asm_inline( |
||
1040 | "int $0x40" ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg)); |
||
1041 | } |
||
1042 | |||
1043 | /*====== Function 48, subfunction 3 - get standard window colors. ======*/ |
||
1044 | |||
1045 | KOSAPI void _ksys_get_system_colors(ksys_colors_table_t* color_table) |
||
1046 | { |
||
1047 | asm_inline( |
||
1048 | "int $0x40" ::"a"(48), "b"(3), "c"(color_table), "d"(40)); |
||
1049 | } |
||
1050 | |||
1051 | /*============ Function 48, subfunction 4 - get skin height. ===========*/ |
||
1052 | |||
1053 | KOSAPI uint32_t _ksys_get_skin_height() |
||
1054 | { |
||
1055 | unsigned height; |
||
1056 | asm_inline( |
||
1057 | "int $0x40" |
||
1058 | : "=a"(height) |
||
1059 | : "a"(48), "b"(4)); |
||
1060 | return height; |
||
1061 | } |
||
1062 | |||
1063 | /*==================== Function 51 - create thread. ====================*/ |
||
1064 | |||
1065 | KOSAPI int _ksys_create_thread(void* thread_entry, void* stack_top) |
||
1066 | { |
||
1067 | int val; |
||
1068 | asm_inline( |
||
1069 | "int $0x40" |
||
1070 | : "=a"(val) |
||
1071 | : "a"(51), "b"(1), "c"(thread_entry), "d"(stack_top) |
||
1072 | : "memory"); |
||
1073 | return val; |
||
1074 | } |
||
1075 | |||
1076 | /*==================== Function 54, subfunction 0 ======================*/ |
||
1077 | /*============== Get the number of slots in the clipboard. =============*/ |
||
1078 | |||
1079 | enum KSYS_CLIP_ENCODING { |
||
1080 | KSYS_CLIP_UTF8 = 0, |
||
1081 | KSYS_CLIP_CP866 = 1, |
||
1082 | KSYS_CLIP_CP1251 = 2 |
||
1083 | }; |
||
1084 | |||
1085 | enum KSYS_CLIP_TYPES { |
||
1086 | KSYS_CLIP_TEXT = 0, |
||
1087 | KSYS_CLIP_IMAGE = 1, |
||
1088 | KSYS_CLIP_RAW = 2 |
||
1089 | }; |
||
1090 | |||
1091 | KOSAPI int _ksys_clip_num(void) |
||
1092 | { |
||
1093 | unsigned val; |
||
1094 | asm_inline( |
||
1095 | "int $0x40" |
||
1096 | : "=a"(val) |
||
1097 | : "a"(54), "b"(0)); |
||
1098 | return val; |
||
1099 | } |
||
1100 | |||
1101 | /*==================== Function 54, subfunction 1 ======================*/ |
||
1102 | /*================= Read the data from the clipboard. ==================-*/ |
||
1103 | |||
1104 | KOSAPI char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free() |
||
1105 | { |
||
1106 | char* val; |
||
1107 | asm_inline( |
||
1108 | "int $0x40" |
||
1109 | : "=a"(val) |
||
1110 | : "a"(54), "b"(1), "c"(n)); |
||
1111 | return val; |
||
1112 | } |
||
1113 | |||
1114 | /*==================== Function 54, subfunction 2 ======================*/ |
||
1115 | /*================= Write the data to the clipboard. ===================*/ |
||
1116 | |||
1117 | KOSAPI int _ksys_clip_set(int n, char* buffer) |
||
1118 | { |
||
1119 | unsigned val; |
||
1120 | asm_inline( |
||
1121 | "int $0x40" |
||
1122 | : "=a"(val) |
||
1123 | : "a"(54), "b"(2), "c"(n), "d"(buffer) |
||
1124 | : "memory"); |
||
1125 | return val; |
||
1126 | } |
||
1127 | |||
1128 | /*===================== Function 54, subfunction 3 =====================*/ |
||
1129 | /*================ Delete the last slot in the clipboard ===============*/ |
||
1130 | |||
1131 | KOSAPI int _ksys_clip_pop() |
||
1132 | { |
||
1133 | unsigned val; |
||
1134 | asm_inline( |
||
1135 | "int $0x40" |
||
1136 | : "=a"(val) |
||
1137 | : "a"(54), "b"(3)); |
||
1138 | return val; |
||
1139 | } |
||
1140 | |||
1141 | /*===================== Function 54, subfunction 4 =====================*/ |
||
1142 | /*===================== Alarm reset the lock buffer ====================*/ |
||
1143 | |||
1144 | KOSAPI int _ksys_clip_unlock() |
||
1145 | { |
||
1146 | unsigned val; |
||
1147 | asm_inline( |
||
1148 | "int $0x40" |
||
1149 | : "=a"(val) |
||
1150 | : "a"(54), "b"(4)); |
||
1151 | return val; |
||
1152 | } |
||
1153 | |||
1154 | /*============== Function 63 - work with the debug board. ==============*/ |
||
1155 | |||
1156 | KOSAPI void _ksys_debug_putc(char c) |
||
1157 | { |
||
1158 | asm_inline("int $0x40" ::"a"(63), "b"(1), "c"(c)); |
||
1159 | } |
||
1160 | |||
1161 | KOSAPI void _ksys_debug_puts(const char* s) |
||
1162 | { |
||
1163 | unsigned i = 0; |
||
1164 | while (*(s + i)) { |
||
1165 | asm_inline("int $0x40" ::"a"(63), "b"(1), "c"(*(s + i))); |
||
1166 | i++; |
||
1167 | } |
||
1168 | } |
||
1169 | |||
1170 | /*========= Function 66, subfunction 1 - set keyboard input mode. ==============*/ |
||
1171 | |||
1172 | typedef enum KSYS_KEY_INPUT_MODE { |
||
1173 | KSYS_KEY_INPUT_MODE_ASCII = 0, |
||
1174 | KSYS_KEY_INPUT_MODE_SCANC = 1, |
||
1175 | } ksys_key_input_mode_t; |
||
1176 | |||
1177 | KOSAPI void _ksys_set_key_input_mode(ksys_key_input_mode_t mode) |
||
1178 | { |
||
1179 | asm_inline( |
||
1180 | "int $0x40" ::"a"(66), "b"(1), "c"(mode)); |
||
1181 | } |
||
1182 | |||
9784 | turbocat | 1183 | /*========= Function 66, subfunction 3 - get the state of the control keys. ========*/ |
1184 | |||
1185 | enum KSYS_CONTROL_KEYS { |
||
1186 | KSYS_CONTROL_LSHIFT = (1 << 0), |
||
1187 | KSYS_CONTROL_RSHIFT = (1 << 1), |
||
1188 | KSYS_CONTROL_LCTRL = (1 << 2), |
||
1189 | KSYS_CONTROL_RCTRL = (1 << 3), |
||
1190 | KSYS_CONTROL_LALT = (1 << 4), |
||
1191 | KSYS_CONTROL_RALT = (1 << 5), |
||
1192 | KSYS_CONTROL_CAPS = (1 << 6), |
||
1193 | KSYS_CONTROL_NUM_LOCK = (1 << 7), |
||
1194 | KSYS_CONTROL_SCROLL_LOCK = (1 << 8) |
||
1195 | }; |
||
1196 | |||
1197 | KOSAPI uint32_t _ksys_get_control_key_state(void) |
||
1198 | { |
||
1199 | uint32_t key_state; |
||
1200 | asm_inline( |
||
1201 | "int $0x40" |
||
1202 | : "=a"(key_state) |
||
1203 | : "a"(66), "b"(3)); |
||
1204 | return key_state; |
||
1205 | } |
||
1206 | |||
9829 | vitalkrilo | 1207 | /*========= Function 66, subfunction 4 - set system-wide hotkey. ========*/ |
1208 | |||
1209 | enum KSYS_SYS_HOTKEY_CONTROL_KEY_STATES { |
||
1210 | KSYS_SYS_HOTKEY_SHIFT_NONE = 0x0, |
||
1211 | KSYS_SYS_HOTKEY_SHIFT_ONE = 0x1, |
||
1212 | KSYS_SYS_HOTKEY_SHIFT_BOTH = 0x2, |
||
1213 | KSYS_SYS_HOTKEY_SHIFT_LEFTONLY = 0x3, |
||
1214 | KSYS_SYS_HOTKEY_SHIFT_RIGHTONLY = 0x4, |
||
1215 | |||
1216 | KSYS_SYS_HOTKEY_CTRL_NONE = 0x00, |
||
1217 | KSYS_SYS_HOTKEY_CTRL_ONE = 0x10, |
||
1218 | KSYS_SYS_HOTKEY_CTRL_BOTH = 0x20, |
||
1219 | KSYS_SYS_HOTKEY_CTRL_LEFTONLY = 0x30, |
||
1220 | KSYS_SYS_HOTKEY_CTRL_RIGHTONLY = 0x40, |
||
1221 | |||
1222 | KSYS_SYS_HOTKEY_ALT_NONE = 0x000, |
||
1223 | KSYS_SYS_HOTKEY_ALT_ONE = 0x100, |
||
1224 | KSYS_SYS_HOTKEY_ALT_BOTH = 0x200, |
||
1225 | KSYS_SYS_HOTKEY_ALT_LEFTONLY = 0x300, |
||
1226 | KSYS_SYS_HOTKEY_ALT_RIGHTONLY = 0x400, |
||
1227 | }; |
||
1228 | |||
1229 | KOSAPI int _ksys_set_sys_hotkey(uint8_t scancode, uint16_t control_key_states) { |
||
1230 | int res; |
||
1231 | asm_inline( |
||
1232 | "int $0x40" |
||
1233 | : "=a"(res) |
||
1234 | : "a"(66), "b"(4), "c"(scancode), "d"(control_key_states) |
||
1235 | : "memory"); |
||
1236 | return res; |
||
1237 | } |
||
1238 | |||
1239 | /*========= Function 66, subfunction 5 - delete installed hotkey. ========*/ |
||
1240 | |||
1241 | KOSAPI int _ksys_del_sys_hotkey(uint8_t scancode, uint16_t control_key_states) { |
||
1242 | int res; |
||
1243 | asm_inline( |
||
1244 | "int $0x40" |
||
1245 | : "=a"(res) |
||
1246 | : "a"(66), "b"(5), "c"(scancode), "d"(control_key_states) |
||
1247 | : "memory"); |
||
1248 | return res; |
||
1249 | } |
||
1250 | |||
9767 | turbocat | 1251 | /*========= Function 67 - change position/sizes of the window. =========*/ |
1252 | |||
1253 | KOSAPI void _ksys_change_window(int new_x, int new_y, int new_w, int new_h) |
||
1254 | { |
||
1255 | asm_inline( |
||
1256 | "int $0x40" ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w), "S"(new_h)); |
||
1257 | } |
||
1258 | |||
9788 | turbocat | 1259 | /*===== Function 68, subfunction 1 - switch to the next thread of execution ====*/ |
1260 | |||
1261 | KOSAPI void _ksys_thread_yield(void) |
||
1262 | { |
||
1263 | asm_inline("int $0x40" :: "a"(68),"b"(1)); |
||
1264 | } |
||
1265 | |||
9767 | turbocat | 1266 | /*======== Function 68, subfunction 12 - allocate memory block. ========*/ |
1267 | |||
1268 | KOSAPI void* _ksys_alloc(size_t size) |
||
1269 | { |
||
1270 | void* val; |
||
1271 | asm_inline( |
||
1272 | "int $0x40" |
||
1273 | : "=a"(val) |
||
1274 | : "a"(68), "b"(12), "c"(size)); |
||
1275 | return val; |
||
1276 | } |
||
1277 | |||
1278 | /*========== Function 68, subfunction 13 - free memory block. ==========*/ |
||
1279 | |||
1280 | KOSAPI int _ksys_free(void* mem) |
||
1281 | { |
||
1282 | int val; |
||
1283 | asm_inline( |
||
1284 | "int $0x40" |
||
1285 | : "=a"(val) |
||
1286 | : "a"(68), "b"(13), "c"(mem)); |
||
1287 | return val; |
||
1288 | } |
||
1289 | |||
9788 | turbocat | 1290 | /*====== Function 68, subfunction 14 - Wait signal from other applications/drivers. =====*/ |
1291 | |||
1292 | KOSAPI void _ksys_wait_signal(ksys_signal_info_t* signal) |
||
1293 | { |
||
1294 | asm_inline("int $0x40" :: "a"(68),"b"(14),"c"(signal) : "memory"); |
||
1295 | } |
||
1296 | |||
9767 | turbocat | 1297 | /*============= Function 68, subfunction 16 - load driver. =============*/ |
1298 | |||
1299 | KOSAPI ksys_drv_hand_t _ksys_load_driver(char* driver_name) |
||
1300 | { |
||
1301 | ksys_drv_hand_t driver_h; |
||
1302 | asm_inline( |
||
1303 | "int $0x40" |
||
1304 | : "=a"(driver_h) |
||
1305 | : "a"(68), "b"(16), "c"(driver_name)); |
||
1306 | return driver_h; |
||
1307 | } |
||
1308 | |||
1309 | /*============ Function 68, subfunction 17 - driver control. ===========*/ |
||
1310 | |||
1311 | KOSAPI int _ksys_driver_control(ksys_ioctl_t* ioctl) |
||
1312 | { |
||
1313 | int status; |
||
1314 | asm_inline( |
||
1315 | "int $0x40" |
||
1316 | : "=a"(status) |
||
1317 | : "a"(68), "b"(17), "c"(ioctl) |
||
1318 | : "memory"); |
||
1319 | return status; |
||
1320 | } |
||
1321 | |||
1322 | /*== Function 68, subfunction 18 - subfunction 19 - load DLL (MS COFF) ==*/ |
||
1323 | |||
1324 | KOSAPI ksys_dll_t* _ksys_dlopen(const char* path) |
||
1325 | { |
||
1326 | ksys_dll_t* table; |
||
1327 | asm_inline( |
||
1328 | "int $0x40" |
||
1329 | : "=a"(table) |
||
1330 | : "a"(68), "b"(19), "c"(path) |
||
1331 | : "memory"); |
||
1332 | return table; |
||
1333 | } |
||
1334 | |||
1335 | /* It is not a system call, it serves as an auxiliary tool*/ |
||
1336 | |||
1337 | KOSAPI void* _ksys_dlsym(ksys_dll_t* table, const char* fun_name) |
||
1338 | { |
||
1339 | unsigned i = 0; |
||
1340 | while (1) { |
||
1341 | if (!(table + i)->func_name) { |
||
1342 | break; |
||
1343 | } else { |
||
1344 | if (!__strcmp(fun_name, (table + i)->func_name)) { |
||
1345 | return (table + i)->func_ptr; |
||
1346 | } |
||
1347 | } |
||
1348 | i++; |
||
1349 | } |
||
1350 | return NULL; |
||
1351 | } |
||
1352 | |||
1353 | /* Function 68, subfunction 20 - reallocate memory block.*/ |
||
1354 | |||
1355 | KOSAPI void* _ksys_realloc(void* mem, size_t size) |
||
1356 | { |
||
1357 | void* val; |
||
1358 | asm_inline( |
||
1359 | "int $0x40" |
||
1360 | : "=a"(val) |
||
1361 | : "a"(68), "b"(20), "c"(size), "d"(mem) |
||
1362 | : "memory"); |
||
1363 | return val; |
||
1364 | } |
||
1365 | |||
1366 | /* Function 68, subfunction 21 - load driver by full name. */ |
||
1367 | |||
1368 | KOSAPI ksys_drv_hand_t _ksys_load_driver_opt(char* driver_path, char* cmd_line) |
||
1369 | { |
||
1370 | ksys_drv_hand_t driver_h; |
||
1371 | asm_inline( |
||
1372 | "int $0x40" |
||
1373 | : "=a"(driver_h) |
||
1374 | : "a"(68), "b"(21), "c"(driver_path), "d"(cmd_line)); |
||
1375 | return driver_h; |
||
1376 | } |
||
1377 | |||
1378 | /*======== Function 68, subfunction 22 - open named memory area. =======*/ |
||
1379 | |||
1380 | enum KSYS_SHM_MODE { |
||
1381 | KSYS_SHM_OPEN = 0x00, |
||
1382 | KSYS_SHM_OPEN_ALWAYS = 0x04, |
||
1383 | KSYS_SHM_CREATE = 0x08, |
||
1384 | KSYS_SHM_READ = 0x00, |
||
1385 | KSYS_SHM_WRITE = 0x01, |
||
1386 | }; |
||
1387 | |||
1388 | KOSAPI int _ksys_shm_open(char* name, int mode, int size, char** new_shm) |
||
1389 | { |
||
1390 | int error; |
||
1391 | asm_inline( |
||
1392 | "int $0x40" |
||
1393 | : "=a"(*new_shm), "=d"(error) |
||
1394 | : "a"(68), "b"(22), "c"(name), "d"(size), "S"(mode)); |
||
1395 | return error; |
||
1396 | } |
||
1397 | |||
1398 | /*======= Function 68, subfunction 23 - close named memory area. =======*/ |
||
1399 | |||
1400 | KOSAPI void _ksys_shm_close(char* shm_name) |
||
1401 | { |
||
1402 | asm_inline( |
||
1403 | "int $0x40" |
||
1404 | : |
||
1405 | : "a"(68), "b"(23), "c"(shm_name)); |
||
1406 | } |
||
1407 | |||
1408 | /*====== Function 68, subfunction 26 - release memory pages ============*/ |
||
1409 | |||
1410 | KOSAPI int* _ksys_unmap(void* base, size_t offset, size_t size) |
||
1411 | { |
||
1412 | int* val; |
||
1413 | asm_inline( |
||
1414 | "int $0x40" |
||
1415 | : "=a"(val) |
||
1416 | : "a"(68), "b"(26), "c"(base), "d"(offset), "S"(size)); |
||
1417 | return val; |
||
1418 | } |
||
1419 | |||
1420 | /*========== Function 68, subfunction 27 - load file ===================*/ |
||
1421 | |||
1422 | KOSAPI ksys_ufile_t _ksys_load_file(const char* path) |
||
1423 | { |
||
1424 | ksys_ufile_t uf; |
||
1425 | asm_inline( |
||
1426 | "int $0x40" |
||
1427 | : "=a"(uf.data), "=d"(uf.size) |
||
1428 | : "a"(68), "b"(27), "c"(path) |
||
1429 | : "memory"); |
||
1430 | return uf; |
||
1431 | } |
||
1432 | |||
1433 | /*==== Function 68, subfunction 28 - load file, specifying the encoding ===*/ |
||
1434 | |||
1435 | KOSAPI ksys_ufile_t _ksys_load_file_enc(const char* path, unsigned file_encoding) |
||
1436 | { |
||
1437 | ksys_ufile_t uf; |
||
1438 | asm_inline( |
||
1439 | "int $0x40" |
||
1440 | : "=a"(uf.data), "=d"(uf.size) |
||
1441 | : "a"(68), "b"(28), "c"(path), "d"(file_encoding) |
||
1442 | : "memory"); |
||
1443 | return uf; |
||
1444 | } |
||
1445 | |||
1446 | /*==== Function 70 - work with file system with long names support. ====*/ |
||
1447 | |||
1448 | KOSAPI ksys70_status_t _ksys70(const ksys70_t* k) |
||
1449 | { |
||
1450 | ksys70_status_t status; |
||
1451 | asm_inline( |
||
1452 | "int $0x40" |
||
1453 | : "=a"(status.status), "=b"(status.rw_bytes) |
||
1454 | : "a"(70), "b"(k) |
||
1455 | : "memory"); |
||
1456 | return status; |
||
1457 | } |
||
1458 | |||
1459 | /*====== Function 70, subfunction 0 - read file with long names support. ======*/ |
||
1460 | |||
1461 | KOSAPI ksys70_status_t _ksys_file_read(const char* name, uint64_t offset, uint32_t size, void* buf) |
||
1462 | { |
||
1463 | ksys70_t k; |
||
1464 | k.p00 = 0; |
||
1465 | k.p04 = offset; |
||
1466 | k.p12 = size; |
||
1467 | k.buf16 = buf; |
||
1468 | k.p20 = 0; |
||
1469 | k.p21 = name; |
||
1470 | return _ksys70(&k); |
||
1471 | } |
||
1472 | |||
1473 | /*===================== Function 70, subfunction 2 =====================*/ |
||
1474 | /*============ Create/rewrite file with long names support. ============*/ |
||
1475 | |||
1476 | KOSAPI int _ksys_file_create(const char* name) |
||
1477 | { |
||
1478 | ksys70_t k; |
||
1479 | k.p00 = 2; |
||
1480 | k.p04dw = 0; |
||
1481 | k.p08dw = 0; |
||
1482 | k.p12 = 0; |
||
1483 | k.p21 = name; |
||
1484 | return _ksys70(&k).status; |
||
1485 | } |
||
1486 | |||
1487 | /*===================== Function 70, subfunction 3 =====================*/ |
||
1488 | /*=========== Write to existing file with long names support. ==========*/ |
||
1489 | |||
1490 | KOSAPI ksys70_status_t _ksys_file_write(const char* name, uint64_t offset, uint32_t size, const void* buf) |
||
1491 | { |
||
1492 | ksys70_t k; |
||
1493 | k.p00 = 3; |
||
1494 | k.p04 = offset; |
||
1495 | k.p12 = size; |
||
1496 | k.cbuf16 = buf; |
||
1497 | k.p20 = 0; |
||
1498 | k.p21 = name; |
||
1499 | return _ksys70(&k); |
||
1500 | } |
||
1501 | |||
1502 | /*========== Function 70, subfunction 5 - get information on file/folder. =====*/ |
||
1503 | |||
1504 | KOSAPI int _ksys_file_info(const char* name, ksys_bdfe_t* bdfe) |
||
1505 | { |
||
1506 | ksys70_t k; |
||
1507 | k.p00 = 5; |
||
1508 | k.p04dw = 0; |
||
1509 | k.p08dw = 0; |
||
1510 | k.p12 = 0; |
||
1511 | k.bdfe = bdfe; |
||
1512 | k.p20 = 0; |
||
1513 | k.p21 = name; |
||
1514 | return _ksys70(&k).status; |
||
1515 | } |
||
1516 | |||
1517 | #define _ksys_dir_info _ksys_file_info |
||
1518 | |||
1519 | /*=========== Function 70, subfunction 7 - start application. ===========*/ |
||
1520 | |||
1521 | KOSAPI int _ksys_exec(const char* app_name, char* args) |
||
1522 | { |
||
1523 | ksys70_t file_opt; |
||
1524 | file_opt.p00 = 7; |
||
1525 | file_opt.p04dw = 0; |
||
1526 | file_opt.p08dw = (uint32_t)args; |
||
1527 | |||
1528 | file_opt.p12 = 0; |
||
1529 | file_opt.p16 = 0; |
||
1530 | file_opt.p20 = 0; |
||
1531 | |||
1532 | file_opt.p21 = app_name; |
||
1533 | return _ksys70(&file_opt).status; |
||
1534 | } |
||
1535 | |||
1536 | /*========== Function 70, subfunction 8 - delete file/folder. ==========*/ |
||
1537 | |||
1538 | KOSAPI int _ksys_file_delete(const char* name) |
||
1539 | { |
||
1540 | ksys70_t k; |
||
1541 | k.p00 = 8; |
||
1542 | k.p20 = 0; |
||
1543 | k.p21 = name; |
||
1544 | return _ksys70(&k).status; |
||
1545 | } |
||
1546 | |||
9829 | vitalkrilo | 1547 | /*============= Function 70, subfunction 9 - create folder. =============*/ |
9767 | turbocat | 1548 | |
1549 | KOSAPI int _ksys_mkdir(const char* path) |
||
1550 | { |
||
1551 | ksys70_t dir_opt; |
||
1552 | dir_opt.p00 = 9; |
||
1553 | dir_opt.p21 = path; |
||
1554 | return _ksys70(&dir_opt).status; |
||
1555 | } |
||
1556 | |||
1557 | /*============= Function 70, subfunction 10 - rename/move. =============*/ |
||
1558 | |||
1559 | KOSAPI int _ksys_file_rename(const char* name, const char* new_name) |
||
1560 | { |
||
1561 | ksys70_t k; |
||
1562 | k.p00 = 10; |
||
1563 | k.new_name = new_name; |
||
1564 | k.p20 = 0; |
||
1565 | k.p21 = name; |
||
1566 | return _ksys70(&k).status; |
||
1567 | } |
||
1568 | |||
1569 | #define _ksys_dir_rename _ksys_file_rename |
||
1570 | |||
9829 | vitalkrilo | 1571 | /*============= Function 71, subfunction 1 - set window title =============*/ |
9767 | turbocat | 1572 | |
1573 | KOSAPI void _ksys_set_window_title(const char* title) |
||
1574 | { |
||
1575 | asm_inline("int $0x40" ::"a"(71), "b"(1), "c"(title) |
||
1576 | : "memory"); |
||
1577 | } |
||
1578 | |||
1579 | #define _ksys_clear_window_title() _ksys_set_window_title(NULL) |
||
1580 | |||
9829 | vitalkrilo | 1581 | /*============= Function 77, subfunction 0 - create futex object =============*/ |
9767 | turbocat | 1582 | |
9829 | vitalkrilo | 1583 | KOSAPI void* _ksys_futex_create(void* futexControlAddr) { |
1584 | void* futexDesc; |
||
1585 | asm_inline( |
||
1586 | "int $0x40" |
||
1587 | : "=a"(futexDesc) |
||
1588 | : "a"(77), "b"(0), "c"(futexControlAddr) |
||
1589 | : "memory"); |
||
1590 | return futexDesc; |
||
1591 | } |
||
1592 | |||
1593 | /*============= Function 77, subfunction 1 - destroy futex object =============*/ |
||
1594 | |||
1595 | KOSAPI int _ksys_futex_destroy(void* futexDesc) { |
||
1596 | int res; |
||
1597 | asm_inline( |
||
1598 | "int $0x40" |
||
1599 | : "=a"(res) |
||
1600 | : "a"(77), "b"(1), "c"(futexDesc) |
||
1601 | : "memory"); |
||
1602 | return res; |
||
1603 | } |
||
1604 | |||
1605 | /*============= Function 77, subfunction 2 - futex wait =============*/ |
||
1606 | |||
1607 | KOSAPI int _ksys_futex_wait(void* futexDesc, int controlVal, int timeout) { |
||
1608 | int res; |
||
1609 | asm_inline( |
||
1610 | "int $0x40" |
||
1611 | : "=a"(res) |
||
1612 | : "a"(77), "b"(2), "c"(futexDesc), "d"(controlVal), "S"(timeout) |
||
1613 | : "memory"); |
||
1614 | return res; |
||
1615 | } |
||
1616 | |||
1617 | /*============= Function 77, subfunction 3 - futex wake =============*/ |
||
1618 | |||
1619 | KOSAPI int _ksys_futex_wake(void* futexDesc, int maxWakeCount) { |
||
1620 | int count; |
||
1621 | asm_inline( |
||
1622 | "int $0x40" |
||
1623 | : "=a"(count) |
||
1624 | : "a"(77), "b"(3), "c"(futexDesc), "d"(maxWakeCount) |
||
1625 | : "memory"); |
||
1626 | return count; |
||
1627 | } |
||
1628 | |||
1629 | /*============= Function 77, subfunction 10 - read from file to buffer =============*/ |
||
1630 | |||
9767 | turbocat | 1631 | KOSAPI int _ksys_posix_read(int pipefd, void* buff, int n) |
1632 | { |
||
1633 | int count; |
||
1634 | asm_inline( |
||
1635 | "int $0x40" |
||
1636 | : "=a"(count) |
||
1637 | : "a"(77), "b"(10), "c"(pipefd), "d"(buff), "S"(n) |
||
1638 | : "memory"); |
||
1639 | return count; |
||
1640 | } |
||
1641 | |||
9829 | vitalkrilo | 1642 | /*============= Function 77, subfunction 11 - write from buffer to file =============*/ |
1643 | |||
9767 | turbocat | 1644 | KOSAPI int _ksys_posix_write(int pipefd, void* buff, int n) |
1645 | { |
||
1646 | int count; |
||
1647 | asm_inline( |
||
1648 | "int $0x40" |
||
1649 | : "=a"(count) |
||
1650 | : "a"(77), "b"(11), "c"(pipefd), "d"(buff), "S"(n) |
||
1651 | : "memory"); |
||
1652 | return count; |
||
1653 | } |
||
1654 | |||
9829 | vitalkrilo | 1655 | /*============= Function 77, subfunction 13 - create new pipe =============*/ |
1656 | |||
9767 | turbocat | 1657 | KOSAPI int _ksys_posix_pipe2(int pipefd[2], int flags) |
1658 | { |
||
1659 | int err; |
||
1660 | asm_inline( |
||
1661 | "int $0x40" |
||
1662 | : "=a"(err) |
||
1663 | : "a"(77), "b"(13), "c"(pipefd), "d"(flags) |
||
1664 | : "memory"); |
||
1665 | return err; |
||
1666 | } |
||
1667 | |||
1668 | /* ######### Old names of functions and structures. Do not use again! ##########*/ |
||
1669 | |||
1670 | #define _ksys_get_event _ksys_wait_event |
||
1671 | #define _ksys_file_get_info _ksys_file_info |
||
1672 | |||
1673 | static inline int _ksys_file_read_file(const char* name, unsigned long long offset, unsigned size, void* buff, unsigned* bytes_read) |
||
1674 | { |
||
1675 | ksys70_status_t res = _ksys_file_read(name, offset, size, buff); |
||
1676 | *bytes_read = res.rw_bytes; |
||
1677 | return res.status; |
||
1678 | } |
||
1679 | |||
1680 | static inline int _ksys_file_write_file(const char* name, unsigned long long offset, unsigned size, const void* buff, unsigned* bytes_write) |
||
1681 | { |
||
1682 | ksys70_status_t res = _ksys_file_write(name, offset, size, buff); |
||
1683 | *bytes_write = res.rw_bytes; |
||
1684 | return res.status; |
||
1685 | } |
||
1686 | |||
1687 | #endif // _KSYS_H_><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><> |