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