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