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