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