Rev 8793 | Rev 9093 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8687 | turbocat | 1 | #ifndef _KSYS_H_ |
2 | #define _KSYS_H_ |
||
3 | |||
4 | #ifdef __cplusplus |
||
5 | extern "C" { |
||
6 | #endif |
||
7 | |||
8 | #include |
||
9 | |||
10 | #define asm_inline __asm__ __volatile__ |
||
11 | |||
12 | #define KSYS_FS_ERR_SUCCESS 0 // Success |
||
13 | #define KSYS_FS_ERR_1 1 // Base and/or partition of a hard disk is not defined (fn21.7 & fn21.8) |
||
14 | #define KSYS_FS_ERR_2 2 // Function is not supported for the given file system |
||
15 | #define KSYS_FS_ERR_3 3 // Unknown file system |
||
16 | #define KSYS_FS_ERR_4 4 // Reserved, is never returned in the current implementation |
||
17 | #define KSYS_FS_ERR_5 5 // File not found |
||
18 | #define KSYS_FS_ERR_EOF 6 // End of file, EOF |
||
19 | #define KSYS_FS_ERR_7 7 // Pointer lies outside of application memory |
||
20 | #define KSYS_FS_ERR_8 8 // Disk is full |
||
21 | #define KSYS_FS_ERR_9 9 // FAT table is destroyed |
||
22 | #define KSYS_FS_ERR_10 10 // Access denied |
||
23 | #define KSYS_FS_ERR_11 11 // Device error |
||
24 | |||
25 | typedef void ksys_panic(char *func_name); |
||
26 | |||
27 | typedef struct { |
||
28 | unsigned char blue; |
||
29 | unsigned char green; |
||
30 | unsigned char red; |
||
31 | }rgb_t; |
||
32 | |||
33 | #pragma pack(push,1) |
||
34 | typedef union{ |
||
35 | unsigned val; |
||
36 | struct{ |
||
37 | short x; |
||
38 | short y; |
||
39 | }; |
||
40 | }ksys_pos_t; |
||
41 | |||
42 | typedef union ksys_oskey_t{ |
||
43 | unsigned val; |
||
44 | struct{ |
||
45 | unsigned char state; |
||
46 | unsigned char code; |
||
47 | unsigned char ctrl_key; |
||
48 | }; |
||
49 | }ksys_oskey_t; |
||
50 | |||
51 | typedef struct{ |
||
52 | void *data; |
||
53 | size_t size; |
||
54 | }ksys_ufile_t; |
||
55 | |||
56 | |||
57 | typedef struct{ |
||
58 | unsigned p00; |
||
59 | union{ |
||
60 | uint64_t p04; |
||
61 | struct { |
||
62 | unsigned p04dw; |
||
63 | unsigned p08dw; |
||
64 | }; |
||
65 | }; |
||
66 | unsigned p12; |
||
67 | union { |
||
68 | unsigned p16; |
||
69 | const char *new_name; |
||
70 | void *bdfe; |
||
71 | void *buf16; |
||
72 | const void *cbuf16; |
||
73 | }; |
||
74 | char p20; |
||
75 | const char *p21; |
||
76 | }ksys70_t; |
||
77 | |||
78 | |||
79 | typedef struct { |
||
80 | unsigned attributes; |
||
81 | unsigned name_cp; |
||
82 | char creation_time[4]; |
||
83 | char creation_date[4]; |
||
84 | char last_access_time[4]; |
||
85 | char last_access_date[4]; |
||
86 | char last_modification_time[4]; |
||
87 | char last_modification_date[4]; |
||
88 | unsigned long long size; |
||
89 | char name[0]; |
||
90 | }ksys_bdfe_t; |
||
91 | |||
92 | typedef struct { |
||
93 | int cpu_usage; //+0 |
||
94 | int window_pos_info; //+4 |
||
95 | short int reserved1; //+8 |
||
96 | char name[12]; //+10 |
||
97 | int memstart; //+22 |
||
98 | int memused; //+26 |
||
99 | int pid; //+30 |
||
100 | int winx_start; //+34 |
||
101 | int winy_start; //+38 |
||
102 | int winx_size; //+42 |
||
103 | int winy_size; //+46 |
||
104 | short int slot_info; //+50 |
||
105 | short int reserved2; //+52 |
||
106 | int clientx; //+54 |
||
107 | int clienty; //+58 |
||
108 | int clientwidth; //+62 |
||
109 | int clientheight; //+66 |
||
110 | unsigned char window_state;//+70 |
||
111 | char reserved3[1024-71]; //+71 |
||
112 | }ksys_proc_table_t; |
||
113 | |||
114 | typedef unsigned int ksys_color_t; |
||
115 | |||
116 | typedef struct{ |
||
117 | ksys_color_t frame_area; |
||
118 | ksys_color_t grab_bar; |
||
119 | ksys_color_t grab_bar_button; |
||
120 | ksys_color_t grab_button_text; |
||
121 | ksys_color_t grab_text; |
||
122 | ksys_color_t work_area; |
||
123 | ksys_color_t work_button; |
||
124 | ksys_color_t work_button_text; |
||
125 | ksys_color_t work_text; |
||
126 | ksys_color_t work_graph; |
||
127 | }ksys_colors_table_t; |
||
128 | |||
129 | typedef struct{ |
||
130 | unsigned pid; // PID of sending thread |
||
131 | unsigned datalen; // data bytes |
||
132 | char *data; // data begin |
||
133 | }ksys_ipc_msg; |
||
134 | |||
135 | typedef struct{ |
||
136 | unsigned lock; // nonzero is locked |
||
137 | unsigned used; // used bytes in buffer |
||
138 | ksys_ipc_msg *data; // data begin |
||
139 | }ksys_ipc_buffer; |
||
140 | |||
141 | typedef struct { |
||
142 | char* func_name; |
||
143 | void* func_ptr; |
||
144 | }ksys_coff_etable_t; |
||
145 | |||
8702 | turbocat | 146 | typedef unsigned ksys_drv_hand_t; |
8699 | turbocat | 147 | |
148 | typedef struct{ |
||
149 | ksys_drv_hand_t handler; |
||
150 | unsigned func_num; |
||
151 | void* in_data_ptr; |
||
152 | unsigned in_data_size; |
||
153 | void* out_data_ptr; |
||
154 | unsigned out_data_size; |
||
8718 | turbocat | 155 | }ksys_ioctl_t; |
8699 | turbocat | 156 | |
8687 | turbocat | 157 | #pragma pack(pop) |
158 | |||
159 | enum KSYS_EVENTS { |
||
160 | KSYS_EVENT_NONE = 0, /* Event queue is empty */ |
||
161 | KSYS_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */ |
||
162 | KSYS_EVENT_KEY = 2, /* A key on the keyboard was pressed */ |
||
163 | KSYS_EVENT_BUTTON = 3, /* A button was clicked with the mouse */ |
||
164 | KSYS_EVENT_DESKTOP = 5, /* Desktop redraw finished */ |
||
165 | KSYS_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */ |
||
166 | KSYS_EVENT_IPC = 7, /* Interprocess communication notify */ |
||
167 | KSYS_EVENT_NETWORK = 8, /* Network event */ |
||
168 | KSYS_EVENT_DEBUG = 9, /* Debug subsystem event */ |
||
169 | KSYS_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ |
||
170 | }; |
||
171 | |||
172 | enum KSYS_FILE_ENCODING{ |
||
173 | KSYS_FILE_CP866 =1, |
||
174 | KSYS_FILE_UTF16LE = 2, |
||
175 | KSYS_FILE_UTF8 = 3 |
||
176 | }; |
||
177 | |||
178 | enum KSYS_CLIP_ENCODING{ |
||
179 | KSYS_CLIP_UTF8 = 0, |
||
180 | KSYS_CLIP_CP866 = 1, |
||
181 | KSYS_CLIP_CP1251 = 2 |
||
182 | }; |
||
183 | |||
184 | enum KSYS_CLIP_TYPES{ |
||
185 | KSYS_CLIP_TEXT = 0, |
||
186 | KSYS_CLIP_IMAGE = 1, |
||
187 | KSYS_CLIP_RAW = 2 |
||
188 | }; |
||
189 | |||
190 | enum KSYS_MOUSE_POS{ |
||
191 | KSYS_MOUSE_SCREEN_POS = 0, |
||
192 | KSYS_MOUSE_WINDOW_POS = 1 |
||
193 | }; |
||
194 | |||
195 | enum KSYS_SHM_MODE{ |
||
196 | KSYS_SHM_OPEN = 0x00, |
||
197 | KSYS_SHM_OPEN_ALWAYS = 0x04, |
||
198 | KSYS_SHM_CREATE = 0x08, |
||
199 | KSYS_SHM_READ = 0x00, |
||
200 | KSYS_SHM_WRITE = 0x01, |
||
201 | }; |
||
202 | |||
8818 | turbocat | 203 | enum KSYS_EVENT_MASK{ |
204 | KSYS_EVM_REDRAW = 1, |
||
205 | KSYS_EVM_KEY = 2, |
||
206 | KSYS_EVM_BUTTON = 4, |
||
207 | KSYS_EVM_EXIT = 8, |
||
208 | KSYS_EVM_BACKGROUND = 16, |
||
209 | KSYS_EVM_MOUSE = 32, |
||
210 | KSYS_EVM_IPC = 64, |
||
211 | KSYS_EVM_STACK = 128, |
||
212 | KSYS_EVM_DEBUG = 256, |
||
213 | KSYS_EVM_STACK2 = 512, |
||
214 | KSYS_EVM_MOUSE_FILTER = 0x80000000, |
||
215 | KSYS_EVM_CURSOR_FILTER = 0x40000000, |
||
216 | }; |
||
217 | |||
8687 | turbocat | 218 | static inline |
219 | int _ksys_strcmp(const char * s1, const char * s2 ) |
||
220 | { |
||
221 | while ((*s1) && (*s1 == *s2)){ ++s1; ++s2; } |
||
222 | return(*(unsigned char*)s1 - *(unsigned char *)s2); |
||
223 | } |
||
224 | |||
225 | // Functions for working with the graphical interface |
||
226 | |||
227 | static inline |
||
228 | void _ksys_start_draw() |
||
229 | { |
||
230 | asm_inline("int $0x40"::"a"(12),"b"(1)); |
||
231 | } |
||
232 | |||
233 | static inline |
||
234 | void _ksys_end_draw() |
||
235 | { |
||
236 | asm_inline("int $0x40" ::"a"(12),"b"(2)); |
||
237 | } |
||
238 | |||
239 | static inline |
||
240 | void _ksys_create_window(int x, int y, int w, int h, const char *name, ksys_color_t workcolor, unsigned style) |
||
241 | { |
||
242 | asm_inline( |
||
243 | "int $0x40" |
||
244 | ::"a"(0), |
||
245 | "b"((x << 16) | ((w-1) & 0xFFFF)), |
||
246 | "c"((y << 16) | ((h-1) & 0xFFFF)), |
||
247 | "d"((style << 24) | (workcolor & 0xFFFFFF)), |
||
248 | "D"(name), |
||
249 | "S"(0) |
||
250 | :"memory" |
||
251 | ); |
||
252 | }; |
||
253 | |||
254 | static inline |
||
255 | void _ksys_change_window(int new_x, int new_y, int new_w, int new_h) |
||
256 | { |
||
257 | asm_inline( |
||
258 | "int $0x40" |
||
259 | ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h) |
||
260 | ); |
||
261 | } |
||
262 | |||
263 | static inline |
||
264 | void _ksys_define_button(unsigned x, unsigned y, unsigned w, unsigned h, unsigned id, ksys_color_t color) |
||
265 | { |
||
266 | asm_inline( |
||
267 | "int $0x40" |
||
268 | ::"a"(8), |
||
269 | "b"((x<<16)+w), |
||
270 | "c"((y<<16)+h), |
||
271 | "d"(id), |
||
272 | "S"(color) |
||
273 | ); |
||
274 | }; |
||
275 | |||
276 | static inline |
||
277 | void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color) |
||
278 | { |
||
279 | asm_inline( |
||
280 | "int $0x40" |
||
281 | ::"a"(38), "d"(color), |
||
282 | "b"((xs << 16) | xe), |
||
283 | "c"((ys << 16) | ye) |
||
284 | ); |
||
285 | } |
||
286 | |||
287 | static inline |
||
288 | void _ksys_draw_bar(int x, int y, int w, int h, ksys_color_t color) |
||
289 | { |
||
290 | asm_inline( |
||
291 | "int $0x40" |
||
292 | ::"a"(13), "d"(color), |
||
293 | "b"((x << 16) | w), |
||
294 | "c"((y << 16) | h) |
||
295 | ); |
||
296 | } |
||
297 | |||
298 | static inline |
||
299 | void _ksys_draw_bitmap(void *bitmap, int x, int y, int w, int h) |
||
300 | { |
||
301 | asm_inline( |
||
302 | "int $0x40" |
||
303 | ::"a"(7), "b"(bitmap), |
||
304 | "c"((w << 16) | h), |
||
305 | "d"((x << 16) | y) |
||
306 | :"memory" |
||
307 | ); |
||
308 | } |
||
309 | |||
310 | static inline |
||
311 | void _ksys_draw_text(const char *text, int x, int y, int len, ksys_color_t color) |
||
312 | { |
||
313 | asm_inline( |
||
314 | "int $0x40" |
||
315 | ::"a"(4),"d"(text), |
||
316 | "b"((x << 16) | y), |
||
317 | "S"(len),"c"(color) |
||
318 | :"memory" |
||
319 | ); |
||
320 | } |
||
321 | |||
322 | static inline |
||
323 | void _ksys_draw_text_bg(const char *text, int x, int y, int len, ksys_color_t color, ksys_color_t bg) |
||
324 | { |
||
325 | asm_inline( |
||
326 | "int $0x40" |
||
327 | ::"a"(4),"d"(text), |
||
328 | "b"((x << 16) | y), |
||
329 | "S"(len),"c"(color), "D"(bg) |
||
330 | :"memory" |
||
331 | ); |
||
332 | } |
||
333 | |||
334 | static inline |
||
335 | void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color){ |
||
336 | unsigned fmt; |
||
337 | fmt = len << 16 | 0x80000000; // no leading zeros + width |
||
338 | asm_inline( |
||
339 | "int $0x40" |
||
340 | ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color) |
||
341 | ); |
||
342 | } |
||
343 | |||
344 | static inline |
||
345 | void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg){ |
||
346 | unsigned fmt; |
||
347 | fmt = len << 16 | 0x80000000; // no leading zeros + width |
||
348 | asm_inline( |
||
349 | "int $0x40" |
||
350 | ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg) |
||
351 | ); |
||
352 | } |
||
353 | |||
354 | static inline |
||
355 | unsigned _ksys_get_skin_height() |
||
356 | { |
||
357 | unsigned height; |
||
358 | asm_inline( |
||
359 | "int $0x40 \n\t" |
||
360 | :"=a"(height) |
||
361 | :"a"(48),"b"(4) |
||
362 | ); |
||
363 | return height; |
||
364 | } |
||
365 | |||
366 | static inline |
||
8705 | turbocat | 367 | void _ksys_get_system_colors(ksys_colors_table_t *color_table) |
8687 | turbocat | 368 | { |
369 | asm_inline( |
||
370 | "int $0x40" |
||
371 | ::"a"(48),"b"(3),"c"(color_table),"d"(40) |
||
372 | ); |
||
373 | } |
||
374 | |||
375 | /* Functions for working with a screen. */ |
||
376 | |||
377 | static inline |
||
378 | ksys_pos_t _ksys_screen_size() |
||
379 | { |
||
380 | ksys_pos_t size; |
||
381 | ksys_pos_t size_tmp; |
||
382 | asm_inline( |
||
383 | "int $0x40" |
||
384 | :"=a"(size_tmp) |
||
385 | :"a"(14) |
||
386 | ); |
||
387 | size.x = size_tmp.y; |
||
388 | size.y = size_tmp.x; |
||
389 | return size; |
||
390 | } |
||
391 | |||
392 | |||
393 | /* Functions for working with a mouse and cursors. */ |
||
394 | |||
395 | static inline |
||
396 | ksys_pos_t _ksys_get_mouse_pos(int origin) |
||
397 | { |
||
398 | ksys_pos_t pos; |
||
399 | asm_inline( |
||
400 | "int $0x40 \n\t" |
||
401 | "rol $16, %%eax" |
||
402 | :"=a"(pos) |
||
403 | :"a"(37),"b"(origin) |
||
404 | ); |
||
405 | return pos; |
||
406 | } |
||
407 | |||
408 | static inline |
||
409 | unsigned _ksys_get_mouse_buttons() |
||
410 | { |
||
411 | unsigned val; |
||
412 | asm_inline( |
||
413 | "int $0x40" |
||
414 | :"=a"(val) |
||
415 | :"a"(37),"b"(2) |
||
416 | ); |
||
417 | return val; |
||
418 | } |
||
419 | |||
420 | static inline |
||
421 | unsigned _ksys_get_mouse_wheels() |
||
422 | { |
||
423 | unsigned val; |
||
424 | asm_inline( |
||
425 | "int $0x40 \n\t" |
||
426 | :"=a"(val) |
||
427 | :"a"(37),"b"(7) |
||
428 | ); |
||
429 | return val; |
||
430 | } |
||
431 | |||
432 | static inline |
||
433 | unsigned _ksys_load_cursor(void *path, unsigned flags) |
||
434 | { |
||
435 | unsigned val; |
||
436 | asm_inline( |
||
437 | "int $0x40" |
||
438 | :"=a"(val) |
||
439 | :"a"(37), "b"(4), "c"(path), "d"(flags) |
||
440 | :"memory" |
||
441 | ); |
||
442 | return val; |
||
443 | } |
||
444 | |||
445 | static inline |
||
446 | unsigned _ksys_set_cursor(unsigned cursor) |
||
447 | { |
||
448 | unsigned old; |
||
449 | asm_inline( |
||
450 | "int $0x40" |
||
451 | :"=a"(old) |
||
452 | :"a"(37), "b"(5), "c"(cursor) |
||
453 | ); |
||
454 | return old; |
||
455 | } |
||
456 | |||
457 | static inline |
||
458 | int _ksys_destroy_cursor(unsigned cursor) |
||
459 | { |
||
460 | int ret; |
||
461 | asm_inline( |
||
462 | "int $0x40" |
||
463 | :"=a"(ret) |
||
464 | :"a"(37), "b"(6), "c"(cursor) |
||
465 | :"memory" |
||
466 | ); |
||
467 | return ret; |
||
468 | } |
||
469 | |||
470 | static inline |
||
471 | unsigned _ksys_get_mouse_eventstate() |
||
472 | { |
||
473 | unsigned val; |
||
474 | asm_inline( |
||
475 | "int $0x40" |
||
476 | :"=a"(val) |
||
477 | :"a"(37),"b"(3) |
||
478 | ); |
||
479 | return val; |
||
480 | } |
||
481 | |||
482 | |||
483 | /* Functions for working with events and buttons. */ |
||
484 | |||
485 | static inline |
||
486 | unsigned _ksys_set_event_mask(unsigned mask) |
||
487 | { |
||
488 | unsigned val; |
||
489 | asm_inline( |
||
490 | "int $0x40" |
||
491 | :"=a"(val) |
||
492 | :"a"(40), "b"(mask) |
||
493 | ); |
||
494 | return val; |
||
495 | } |
||
496 | |||
497 | static inline |
||
498 | unsigned _ksys_wait_event(unsigned time) |
||
499 | { |
||
500 | unsigned val; |
||
501 | asm_inline( |
||
502 | "int $0x40" |
||
503 | :"=a"(val) |
||
504 | :"a"(23), "b"(time) |
||
505 | ); |
||
506 | return val; |
||
507 | } |
||
508 | |||
509 | static inline |
||
510 | unsigned _ksys_check_event() |
||
511 | { |
||
512 | unsigned val; |
||
513 | asm_inline( |
||
514 | "int $0x40" |
||
515 | :"=a"(val) |
||
516 | :"a"(11) |
||
517 | ); |
||
518 | return val; |
||
519 | } |
||
520 | |||
521 | static inline |
||
522 | unsigned _ksys_get_event() |
||
523 | { |
||
524 | unsigned val; |
||
525 | asm_inline( |
||
526 | "int $0x40" |
||
527 | :"=a"(val) |
||
528 | :"a"(10) |
||
529 | ); |
||
530 | return val; |
||
531 | } |
||
532 | |||
533 | static inline |
||
534 | unsigned _ksys_get_button() |
||
535 | { |
||
536 | unsigned val; |
||
537 | asm_inline( |
||
538 | "int $0x40" |
||
539 | :"=a"(val) |
||
540 | :"a"(17) |
||
541 | ); |
||
542 | return val>>8; |
||
543 | } |
||
544 | |||
545 | static inline |
||
546 | ksys_oskey_t _ksys_get_key(void) |
||
547 | { |
||
548 | ksys_oskey_t val; |
||
549 | asm_inline( |
||
550 | "int $0x40" |
||
551 | :"=a"(val) |
||
552 | :"a"(2) |
||
553 | ); |
||
554 | return val; |
||
555 | } |
||
556 | |||
557 | /* Functions for working with the clipboard */ |
||
558 | |||
559 | static inline |
||
560 | int _ksys_clip_num() |
||
561 | { |
||
562 | unsigned val; |
||
563 | asm_inline( |
||
564 | "int $0x40" |
||
565 | :"=a"(val) |
||
566 | :"a"(54), "b"(0) |
||
567 | ); |
||
568 | return val; |
||
569 | } |
||
570 | |||
571 | static inline |
||
572 | char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free() |
||
573 | { |
||
574 | char* val; |
||
575 | asm_inline( |
||
576 | "int $0x40" |
||
577 | :"=a"(val) |
||
578 | :"a"(54), "b"(1), "c"(n) |
||
579 | ); |
||
580 | return val; |
||
581 | } |
||
582 | |||
583 | static inline |
||
584 | int _ksys_clip_set(int n, char *buffer) |
||
585 | { |
||
586 | unsigned val; |
||
587 | asm_inline( |
||
588 | "int $0x40" |
||
589 | :"=a"(val) |
||
590 | :"a"(54), "b"(2), "c"(n), "d"(buffer) |
||
591 | :"memory" |
||
592 | ); |
||
593 | return val; |
||
594 | } |
||
595 | |||
596 | static inline |
||
597 | int _ksys_clip_pop() |
||
598 | { |
||
599 | unsigned val; |
||
600 | asm_inline ( |
||
601 | "int $0x40" |
||
602 | :"=a"(val) |
||
603 | :"a"(54), "b"(3) |
||
604 | ); |
||
605 | return val; |
||
606 | } |
||
607 | |||
608 | static inline |
||
609 | int _ksys_clip_unlock() |
||
610 | { |
||
611 | unsigned val; |
||
612 | asm_inline( |
||
613 | "int $0x40" |
||
614 | :"=a"(val) |
||
615 | :"a"(54), "b"(4) |
||
616 | ); |
||
617 | return val; |
||
618 | } |
||
619 | |||
620 | |||
621 | /* Working with time */ |
||
622 | |||
623 | static inline |
||
624 | unsigned _ksys_get_tick_count() |
||
625 | { |
||
626 | unsigned val; |
||
627 | asm_inline( |
||
628 | "int $0x40" |
||
629 | :"=a"(val) |
||
630 | :"a"(26),"b"(9) |
||
631 | ); |
||
632 | return val; |
||
633 | } |
||
634 | |||
635 | static inline |
||
636 | uint64_t _ksys_get_ns_count() |
||
637 | { |
||
638 | uint64_t val; |
||
639 | asm_inline( |
||
640 | "int $0x40" |
||
641 | :"=A"(val) |
||
642 | :"a"(26), "b"(10) |
||
643 | ); |
||
644 | return val; |
||
645 | } |
||
646 | |||
647 | static inline |
||
648 | void _ksys_delay(unsigned time) |
||
649 | { |
||
650 | asm_inline( |
||
651 | "int $0x40" |
||
652 | ::"a"(5), "b"(time) |
||
653 | :"memory" |
||
654 | ); |
||
655 | } |
||
656 | |||
657 | static inline |
||
658 | unsigned _ksys_get_date() |
||
659 | { |
||
660 | unsigned val; |
||
661 | asm_inline("int $0x40":"=a"(val):"a"(29)); |
||
662 | return val; |
||
663 | } |
||
664 | |||
665 | static inline |
||
666 | unsigned _ksys_get_clock() |
||
667 | { |
||
668 | unsigned val; |
||
669 | asm_inline("int $0x40":"=a"(val):"a"(3)); |
||
670 | return val; |
||
671 | } |
||
672 | |||
673 | |||
674 | /* Working with memory allocation */ |
||
675 | |||
676 | static inline |
||
677 | void* _ksys_alloc(size_t size){ |
||
678 | void *val; |
||
679 | asm_inline( |
||
680 | "int $0x40" |
||
681 | :"=a"(val) |
||
682 | :"a"(68),"b"(12),"c"(size) |
||
683 | ); |
||
684 | return val; |
||
685 | } |
||
686 | |||
687 | static inline |
||
688 | int _ksys_free(void *mem) |
||
689 | { |
||
690 | int val; |
||
691 | asm_inline( |
||
692 | "int $0x40" |
||
693 | :"=a"(val) |
||
694 | :"a"(68),"b"(13),"c"(mem) |
||
695 | ); |
||
696 | return val; |
||
697 | } |
||
698 | |||
699 | static inline |
||
700 | void* _ksys_realloc(void *mem, size_t size) |
||
701 | { |
||
702 | void *val; |
||
703 | asm_inline( |
||
704 | "int $0x40" |
||
705 | :"=a"(val) |
||
706 | :"a"(68),"b"(20),"c"(size),"d"(mem) |
||
707 | :"memory" |
||
708 | ); |
||
709 | return val; |
||
710 | } |
||
711 | |||
712 | static inline |
||
713 | int* _ksys_unmap(void *base, size_t offset, size_t size) |
||
714 | { |
||
715 | int *val; |
||
716 | asm_inline( |
||
717 | "int $0x40" |
||
718 | :"=a"(val) |
||
719 | :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size) |
||
720 | ); |
||
721 | return val; |
||
722 | } |
||
723 | |||
724 | |||
725 | /* Loading the dynamic coff library */ |
||
726 | |||
727 | static inline |
||
728 | ksys_coff_etable_t* _ksys_load_coff(const char* path) |
||
729 | { |
||
730 | ksys_coff_etable_t *table; |
||
731 | asm_inline( |
||
732 | "int $0x40" |
||
733 | :"=a"(table) |
||
734 | :"a"(68),"b"(19), "c"(path) |
||
735 | :"memory" |
||
736 | ); |
||
737 | return table; |
||
738 | } |
||
739 | |||
740 | static inline |
||
741 | void* _ksys_get_coff_func(ksys_coff_etable_t *table, const char* fun_name, ksys_panic* panic) |
||
742 | { |
||
743 | unsigned i=0; |
||
744 | while (1){ |
||
745 | if (NULL == (table+i)->func_name){ |
||
746 | break; |
||
747 | }else{ |
||
748 | if (!_ksys_strcmp(fun_name, (table+i)->func_name)){ |
||
749 | return (table+i)->func_ptr; |
||
750 | } |
||
751 | } |
||
752 | i++; |
||
753 | } |
||
754 | panic((char*)fun_name); |
||
755 | return NULL; |
||
756 | } |
||
757 | |||
758 | |||
759 | /* Debug board functions */ |
||
760 | |||
761 | static inline |
||
762 | void _ksys_debug_putc(char c) |
||
763 | { |
||
764 | asm_inline("int $0x40"::"a"(63), "b"(1), "c"(c)); |
||
765 | } |
||
766 | |||
767 | static inline |
||
768 | void _ksys_debug_puts(char *s) |
||
769 | { |
||
770 | unsigned i=0; |
||
771 | while (*(s+i)){ |
||
772 | asm_inline ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i))); |
||
773 | i++; |
||
774 | } |
||
775 | } |
||
776 | |||
777 | |||
778 | /* Working with threads and process */ |
||
779 | |||
780 | static inline |
||
781 | int _ksys_start_thread(void* proc, char* stack_top) |
||
782 | { |
||
783 | int val; |
||
784 | asm_inline( |
||
785 | "int $0x40" |
||
786 | :"=a"(val) |
||
787 | :"a"(51), "b"(1), "c"(proc), "d"(stack_top) |
||
788 | ); |
||
789 | return val; |
||
790 | } |
||
791 | |||
792 | static inline |
||
793 | void _ksys_focus_window(int slot){ |
||
794 | asm_inline( |
||
795 | "int $0x40" |
||
796 | ::"a"(18), "b"(3), "c"(slot) |
||
797 | ); |
||
798 | } |
||
799 | |||
800 | static inline |
||
801 | int _ksys_get_thread_slot(int tid){ |
||
802 | int val; |
||
803 | asm_inline( |
||
804 | "int $0x40" |
||
805 | :"=a"(val) |
||
806 | :"a"(18), "b"(21), "c"(tid) |
||
807 | ); |
||
808 | return val; |
||
809 | } |
||
810 | |||
811 | static inline |
||
812 | int _ksys_process_info(ksys_proc_table_t* table, int pid) |
||
813 | { |
||
814 | int val; |
||
815 | asm_inline( |
||
816 | "int $0x40" |
||
817 | :"=a"(val) |
||
818 | :"a"(9), "b"(table), "c"(pid) |
||
819 | :"memory" |
||
820 | ); |
||
821 | return val; |
||
822 | } |
||
823 | |||
824 | static inline |
||
825 | void _ksys_exit() |
||
826 | { |
||
827 | asm_inline("int $0x40"::"a"(-1)); |
||
828 | } |
||
829 | |||
830 | |||
831 | /* Working with files and directories */ |
||
832 | |||
833 | static inline |
||
834 | void _ksys_setcwd(char* dir){ |
||
835 | asm_inline( |
||
836 | "int $0x40" |
||
837 | ::"a"(30), "b"(1), "c"(dir) |
||
838 | ); |
||
839 | } |
||
840 | |||
841 | static inline |
||
842 | int _ksys_getcwd(char* buf, int bufsize){ |
||
843 | register int val; |
||
844 | asm_inline( |
||
845 | "int $0x40" |
||
846 | :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize) |
||
847 | ); |
||
848 | return val; |
||
849 | } |
||
850 | |||
851 | static inline |
||
852 | ksys_ufile_t _ksys_load_file(const char *path) |
||
853 | { |
||
854 | ksys_ufile_t uf; |
||
855 | asm_inline( |
||
856 | "int $0x40" |
||
857 | :"=a"(uf.data), "=d"(uf.size) |
||
858 | :"a"(68), "b"(27),"c"(path) |
||
859 | :"memory" |
||
860 | ); |
||
861 | return uf; |
||
862 | } |
||
863 | |||
864 | static inline |
||
865 | ksys_ufile_t _ksys_load_file_enc(const char *path, unsigned file_encoding) |
||
866 | { |
||
867 | ksys_ufile_t uf; |
||
868 | asm_inline( |
||
869 | "int $0x40" |
||
870 | :"=a"(uf.data), "=d"(uf.size) |
||
871 | :"a"(68), "b"(28),"c"(path), "d"(file_encoding) |
||
872 | :"memory" |
||
873 | ); |
||
874 | return uf; |
||
875 | } |
||
876 | |||
877 | static inline |
||
878 | int _ksys_work_files(const ksys70_t *k) |
||
879 | { |
||
880 | int status; |
||
881 | asm_inline( |
||
882 | "int $0x40" |
||
883 | :"=a"(status) |
||
884 | :"a"(70), "b"(k) |
||
885 | :"memory" |
||
886 | ); |
||
887 | return status; |
||
888 | } |
||
889 | |||
890 | static inline |
||
891 | int _ksys_file_read_file(const char *name, unsigned long long offset, unsigned size, void *buf, unsigned *bytes_read) |
||
892 | { |
||
893 | ksys70_t k; |
||
894 | k.p00 = 0; |
||
895 | k.p04 = offset; |
||
896 | k.p12 = size; |
||
897 | k.buf16 = buf; |
||
898 | k.p20 = 0; |
||
899 | k.p21 = name; |
||
900 | int status; |
||
901 | unsigned bytes_read_v; |
||
8730 | turbocat | 902 | asm_inline( |
903 | "int $0x40" |
||
904 | :"=a"(status), "=b"(bytes_read_v) |
||
905 | :"a"(70), "b"(&k) |
||
906 | :"memory" |
||
907 | ); |
||
8687 | turbocat | 908 | if (!status) { |
909 | *bytes_read = bytes_read_v; |
||
910 | } |
||
911 | return status; |
||
912 | } |
||
913 | |||
914 | static inline |
||
915 | int _ksys_file_write_file(const char *name, unsigned long long offset, unsigned size, const void *buf, unsigned *bytes_written) |
||
916 | { |
||
917 | ksys70_t k; |
||
918 | k.p00 = 3; |
||
919 | k.p04 = offset; |
||
920 | k.p12 = size; |
||
921 | k.cbuf16 = buf; |
||
922 | k.p20 = 0; |
||
923 | k.p21 = name; |
||
924 | int status; |
||
925 | unsigned bytes_written_v; |
||
926 | asm_inline( |
||
927 | "int $0x40" |
||
928 | :"=a"(status), "=b"(bytes_written_v) |
||
929 | :"a"(70), "b"(&k) |
||
930 | :"memory" |
||
931 | ); |
||
932 | if (!status) { |
||
933 | *bytes_written = bytes_written_v; |
||
934 | } |
||
935 | return status; |
||
936 | } |
||
937 | |||
938 | static inline |
||
939 | int _ksys_file_create(const char* name){ |
||
940 | ksys70_t k; |
||
941 | k.p00 = 2; |
||
942 | k.p12 = 0; |
||
943 | k.p21 = name; |
||
944 | return _ksys_work_files(&k); |
||
945 | } |
||
946 | |||
947 | static inline |
||
948 | int _ksys_file_get_info(const char *name, ksys_bdfe_t *bdfe) |
||
949 | { |
||
950 | ksys70_t k; |
||
951 | k.p00 = 5; |
||
952 | k.bdfe = bdfe; |
||
953 | k.p20 = 0; |
||
954 | k.p21 = name; |
||
955 | return _ksys_work_files(&k); |
||
956 | } |
||
957 | |||
958 | static inline |
||
959 | int _ksys_file_delete(const char *name) |
||
960 | { |
||
961 | ksys70_t k; |
||
962 | k.p00 = 8; |
||
963 | k.p20 = 0; |
||
964 | k.p21 = name; |
||
965 | return _ksys_work_files(&k); |
||
966 | } |
||
967 | |||
968 | static inline |
||
969 | int _ksys_file_rename(const char *name, const char *new_name) |
||
970 | { |
||
971 | ksys70_t k; |
||
972 | k.p00 = 10; |
||
973 | k.new_name = new_name; |
||
974 | k.p20 = 0; |
||
975 | k.p21 = name; |
||
976 | return _ksys_work_files(&k); |
||
977 | } |
||
978 | |||
979 | |||
980 | static inline |
||
981 | int _ksys_exec(char *app_name, char *args) |
||
982 | { |
||
983 | ksys70_t file_opt; |
||
984 | file_opt.p00 = 7; |
||
985 | file_opt.p04dw = 0; |
||
986 | file_opt.p08dw = (unsigned)args; |
||
987 | file_opt.p21 = app_name; |
||
988 | return _ksys_work_files(&file_opt); |
||
989 | } |
||
990 | |||
991 | static inline |
||
992 | int _ksys_mkdir(const char *path) |
||
993 | { |
||
994 | ksys70_t dir_opt; |
||
995 | dir_opt.p00 = 9; |
||
996 | dir_opt.p21 = path; |
||
997 | return _ksys_work_files(&dir_opt); |
||
998 | } |
||
999 | |||
1000 | /* Working with a named shared memory area. */ |
||
1001 | |||
1002 | static inline |
||
1003 | int _ksys_shm_open(char *name, int mode, int size, char **new_shm) |
||
1004 | { |
||
1005 | int error; |
||
1006 | asm_inline( |
||
1007 | "int $0x40" |
||
1008 | :"=a"(*new_shm), "=d"(error) |
||
1009 | :"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode) |
||
1010 | ); |
||
1011 | return error; |
||
1012 | } |
||
1013 | |||
1014 | |||
1015 | static inline |
||
1016 | void _ksys_shm_close(char *shm_name) |
||
1017 | { |
||
1018 | asm_inline( |
||
1019 | "int $0x40": |
||
1020 | :"a"(68), "b"(23), "c"(shm_name) |
||
1021 | ); |
||
1022 | } |
||
1023 | |||
8699 | turbocat | 1024 | /* Driver functions */ |
1025 | |||
1026 | static inline |
||
1027 | ksys_drv_hand_t _ksys_load_driver(char *driver_name) |
||
1028 | { |
||
1029 | ksys_drv_hand_t driver_h; |
||
1030 | asm_inline( |
||
1031 | "int $0x40" |
||
1032 | :"=a"(driver_h) |
||
1033 | :"a"(68), "b"(16), "c"(driver_name) |
||
1034 | ); |
||
1035 | return driver_h; |
||
1036 | } |
||
1037 | |||
8705 | turbocat | 1038 | static inline |
8702 | turbocat | 1039 | ksys_drv_hand_t _ksys_load_pe_driver(char *driver_path, char *cmd_line) |
1040 | { |
||
1041 | ksys_drv_hand_t driver_h; |
||
1042 | asm_inline( |
||
1043 | "int $0x40" |
||
1044 | :"=a"(driver_h) |
||
1045 | :"a"(68), "b"(21), "c"(driver_path), "d"(cmd_line) |
||
1046 | ); |
||
1047 | return driver_h; |
||
1048 | } |
||
1049 | |||
8699 | turbocat | 1050 | static inline |
8718 | turbocat | 1051 | unsigned _ksys_work_driver(ksys_ioctl_t *ioctl) |
8699 | turbocat | 1052 | { |
1053 | unsigned status; |
||
1054 | asm_inline( |
||
1055 | "int $0x40" |
||
1056 | :"=a"(status) |
||
1057 | :"a"(68), "b"(17), "c"(ioctl) |
||
1058 | :"memory" |
||
1059 | ); |
||
1060 | return status; |
||
1061 | } |
||
1062 | |||
8687 | turbocat | 1063 | #ifdef __cplusplus |
1064 | } |
||
1065 | #endif |
||
1066 | |||
1067 | #endif // _KSYS_H_><>><>><>><>><>><>><>><>><>><>><>><>16)+h), |