Rev 8623 | Go to most recent revision | Details | Compare with Previous | 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 | |||
8622 | Boppan | 192 | static inline |
193 | int _ksys_strcmp(const char * s1, const char * s2 ) |
||
194 | { |
||
195 | while ((*s1) && (*s1 == *s2)){ |
||
196 | ++s1; |
||
197 | ++s2; |
||
198 | } |
||
199 | |||
200 | return ( *( unsigned char * )s1 - * ( unsigned char * )s2 ); |
||
201 | } |
||
202 | |||
203 | // Functions for working with the graphical interface |
||
204 | |||
205 | static inline |
||
206 | void _ksys_start_draw() |
||
207 | { |
||
208 | asm_inline("int $0x40"::"a"(12),"b"(1)); |
||
209 | } |
||
210 | |||
211 | static inline |
||
212 | void _ksys_end_draw() |
||
213 | { |
||
214 | asm_inline("int $0x40" ::"a"(12),"b"(2)); |
||
215 | } |
||
216 | |||
217 | static inline |
||
218 | void _ksys_create_window(int x, int y, int w, int h, const char *name, ksys_color_t workcolor, unsigned style) |
||
219 | { |
||
220 | asm_inline( |
||
221 | "int $0x40" |
||
222 | ::"a"(0), |
||
223 | "b"((x << 16) | ((w-1) & 0xFFFF)), |
||
224 | "c"((y << 16) | ((h-1) & 0xFFFF)), |
||
225 | "d"((style << 24) | (workcolor & 0xFFFFFF)), |
||
226 | "D"(name), |
||
227 | "S"(0) : "memory" |
||
228 | ); |
||
229 | }; |
||
230 | |||
231 | static inline |
||
232 | void _ksys_change_window(int new_x, int new_y, int new_w, int new_h) |
||
233 | { |
||
234 | asm_inline( |
||
235 | "int $0x40" |
||
236 | ::"a"(67), "b"(new_x), "c"(new_y), "d"(new_w),"S"(new_h) |
||
237 | ); |
||
238 | } |
||
239 | |||
240 | static inline |
||
241 | void _ksys_define_button(unsigned x, unsigned y, unsigned w, unsigned h, unsigned id, ksys_color_t color) |
||
242 | { |
||
243 | asm_inline( |
||
244 | "int $0x40" |
||
245 | ::"a"(8), |
||
246 | "b"((x<<16)+w), |
||
247 | "c"((y<<16)+h), |
||
248 | "d"(id), |
||
249 | "S"(color) |
||
250 | ); |
||
251 | }; |
||
252 | |||
253 | static inline |
||
254 | void _ksys_draw_line(int xs, int ys, int xe, int ye, ksys_color_t color) |
||
255 | { |
||
256 | asm_inline( |
||
257 | "int $0x40" |
||
258 | ::"a"(38), "d"(color), |
||
259 | "b"((xs << 16) | xe), |
||
260 | "c"((ys << 16) | ye) |
||
261 | ); |
||
262 | } |
||
263 | |||
264 | static inline |
||
265 | void _ksys_draw_bar(int x, int y, int w, int h, ksys_color_t color) |
||
266 | { |
||
267 | asm_inline( |
||
268 | "int $0x40" |
||
269 | ::"a"(13), "d"(color), |
||
270 | "b"((x << 16) | w), |
||
271 | "c"((y << 16) | h) |
||
272 | ); |
||
273 | } |
||
274 | |||
275 | static inline |
||
276 | void _ksys_draw_bitmap(void *bitmap, int x, int y, int w, int h) |
||
277 | { |
||
278 | asm_inline( |
||
279 | "int $0x40" |
||
280 | ::"a"(7), "b"(bitmap), |
||
281 | "c"((w << 16) | h), |
||
282 | "d"((x << 16) | y) |
||
283 | ); |
||
284 | } |
||
285 | |||
286 | static inline |
||
287 | void _ksys_draw_text(const char *text, int x, int y, int len, ksys_color_t color) |
||
288 | { |
||
289 | asm_inline( |
||
290 | "int $0x40" |
||
291 | ::"a"(4),"d"(text), |
||
292 | "b"((x << 16) | y), |
||
293 | "S"(len),"c"(color) |
||
294 | :"memory" |
||
295 | ); |
||
296 | } |
||
297 | |||
298 | static inline |
||
299 | void _ksys_draw_text_bg(const char *text, int x, int y, int len, ksys_color_t color, ksys_color_t bg) |
||
300 | { |
||
301 | asm_inline( |
||
302 | "int $0x40" |
||
303 | ::"a"(4),"d"(text), |
||
304 | "b"((x << 16) | y), |
||
305 | "S"(len),"c"(color), "D"(bg) |
||
306 | :"memory" |
||
307 | ); |
||
308 | } |
||
309 | |||
310 | static inline |
||
311 | void _ksys_draw_number(int number, int x, int y, int len, ksys_color_t color){ |
||
312 | unsigned fmt; |
||
313 | fmt = len << 16 | 0x80000000; // no leading zeros + width |
||
314 | asm_inline( |
||
315 | "int $0x40" |
||
316 | ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color) |
||
317 | ); |
||
318 | } |
||
319 | |||
320 | static inline |
||
321 | void _ksys_draw_number_bg(unsigned number, int x, int y, int len, ksys_color_t color, ksys_color_t bg){ |
||
322 | unsigned fmt; |
||
323 | fmt = len << 16 | 0x80000000; // no leading zeros + width |
||
324 | asm_inline( |
||
325 | "int $0x40" |
||
326 | ::"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color), "D"(bg) |
||
327 | ); |
||
328 | } |
||
329 | |||
330 | static inline |
||
331 | unsigned _ksys_get_skin_height() |
||
332 | { |
||
333 | unsigned height; |
||
334 | asm_inline( |
||
335 | "int $0x40 \n\t" |
||
336 | :"=a"(height) |
||
337 | :"a"(48),"b"(4) |
||
338 | ); |
||
339 | return height; |
||
340 | } |
||
341 | |||
342 | static inline |
||
343 | void _ksys_get_colors(ksys_colors_table_t *color_table) |
||
344 | { |
||
345 | asm_inline( |
||
346 | "int $0x40" |
||
347 | ::"a"(48),"b"(3),"c"(color_table),"d"(40) |
||
348 | ); |
||
349 | } |
||
350 | |||
351 | |||
352 | /* Functions for working with a mouse and cursors. */ |
||
353 | |||
354 | static inline |
||
355 | ksys_pos_t _ksys_get_mouse_pos(int origin) |
||
356 | { |
||
357 | ksys_pos_t val; |
||
358 | asm_inline( |
||
359 | "int $0x40 \n\t" |
||
360 | "rol $16, %%eax" |
||
361 | :"=a"(val) |
||
362 | :"a"(37),"b"(origin) |
||
363 | ); |
||
364 | return val; |
||
365 | } |
||
366 | |||
367 | static inline |
||
368 | unsigned _ksys_get_mouse_buttons() |
||
369 | { |
||
370 | unsigned val; |
||
371 | asm_inline( |
||
372 | "int $0x40" |
||
373 | :"=a"(val) |
||
374 | :"a"(37),"b"(2) |
||
375 | ); |
||
376 | return val; |
||
377 | } |
||
378 | |||
379 | static inline |
||
380 | unsigned _ksys_get_mouse_wheels() |
||
381 | { |
||
382 | unsigned val; |
||
383 | asm_inline( |
||
384 | "int $0x40 \n\t" |
||
385 | :"=a"(val) |
||
386 | :"a"(37),"b"(7) |
||
387 | ); |
||
388 | return val; |
||
389 | } |
||
390 | |||
391 | static inline |
||
392 | unsigned _ksys_load_cursor(void *path, unsigned flags) |
||
393 | { |
||
394 | unsigned val; |
||
395 | asm_inline( |
||
396 | "int $0x40" |
||
397 | :"=a"(val) |
||
398 | :"a"(37), "b"(4), "c"(path), "d"(flags) |
||
399 | ); |
||
400 | return val; |
||
401 | } |
||
402 | |||
403 | static inline |
||
404 | unsigned _ksys_set_cursor(unsigned cursor) |
||
405 | { |
||
406 | unsigned old; |
||
407 | asm_inline( |
||
408 | "int $0x40" |
||
409 | :"=a"(old) |
||
410 | :"a"(37), "b"(5), "c"(cursor) |
||
411 | ); |
||
412 | return old; |
||
413 | } |
||
414 | |||
415 | static inline |
||
416 | int _ksys_destroy_cursor(unsigned cursor) |
||
417 | { |
||
418 | int ret; |
||
419 | asm_inline( |
||
420 | "int $0x40" |
||
421 | :"=a"(ret) |
||
422 | :"a"(37), "b"(6), "c"(cursor) |
||
423 | :"memory" |
||
424 | ); |
||
425 | return ret; |
||
426 | } |
||
427 | |||
428 | static inline |
||
429 | unsigned _ksys_get_mouse_eventstate() |
||
430 | { |
||
431 | unsigned val; |
||
432 | asm_inline( |
||
433 | "int $0x40" |
||
434 | :"=a"(val) |
||
435 | :"a"(37),"b"(3) |
||
436 | ); |
||
437 | return val; |
||
438 | } |
||
439 | |||
440 | |||
441 | /* Functions for working with events and buttons. */ |
||
442 | |||
443 | static inline |
||
444 | unsigned _ksys_set_event_mask(unsigned mask) |
||
445 | { |
||
446 | unsigned val; |
||
447 | asm_inline( |
||
448 | "int $0x40" |
||
449 | :"=a"(val) |
||
450 | :"a"(40), "b"(mask) |
||
451 | ); |
||
452 | return val; |
||
453 | } |
||
454 | |||
455 | static inline |
||
456 | unsigned _ksys_wait_event(unsigned time) |
||
457 | { |
||
458 | unsigned val; |
||
459 | asm_inline( |
||
460 | "int $0x40" |
||
461 | :"=a"(val) |
||
462 | :"a"(23), "b"(time) |
||
463 | ); |
||
464 | return val; |
||
465 | } |
||
466 | |||
467 | static inline |
||
468 | unsigned _ksys_check_event() |
||
469 | { |
||
470 | unsigned val; |
||
471 | asm_inline( |
||
472 | "int $0x40" |
||
473 | :"=a"(val) |
||
474 | :"a"(11) |
||
475 | ); |
||
476 | return val; |
||
477 | } |
||
478 | |||
479 | static inline |
||
480 | unsigned _ksys_get_event() |
||
481 | { |
||
482 | unsigned val; |
||
483 | asm_inline( |
||
484 | "int $0x40" |
||
485 | :"=a"(val) |
||
486 | :"a"(10) |
||
487 | ); |
||
488 | return val; |
||
489 | } |
||
490 | |||
491 | static inline |
||
492 | unsigned _ksys_get_button() |
||
493 | { |
||
494 | unsigned val; |
||
495 | asm_inline( |
||
496 | "int $0x40" |
||
497 | :"=a"(val) |
||
498 | :"a"(17) |
||
499 | ); |
||
500 | return val>>8; |
||
501 | } |
||
502 | |||
503 | static inline |
||
504 | ksys_oskey_t _ksys_get_key(void) |
||
505 | { |
||
506 | ksys_oskey_t val; |
||
507 | asm_inline( |
||
508 | "int $0x40" |
||
509 | :"=a"(val) |
||
510 | :"a"(2) |
||
511 | ); |
||
512 | return val; |
||
513 | } |
||
514 | |||
515 | /* Functions for working with the clipboard */ |
||
516 | |||
517 | static inline |
||
518 | int _ksys_clip_num() |
||
519 | { |
||
520 | unsigned val; |
||
521 | asm_inline( |
||
522 | "int $0x40" |
||
523 | :"=a"(val) |
||
524 | :"a"(54), "b"(0) |
||
525 | ); |
||
526 | return val; |
||
527 | } |
||
528 | |||
529 | static inline |
||
530 | char* _ksys_clip_get(int n) // returned buffer must be freed by _ksys_free() |
||
531 | { |
||
532 | char* val; |
||
533 | asm_inline( |
||
534 | "int $0x40" |
||
535 | :"=a"(val) |
||
536 | :"a"(54), "b"(1), "c"(n) |
||
537 | ); |
||
538 | return val; |
||
539 | } |
||
540 | |||
541 | static inline |
||
542 | int _ksys_clip_set(int n, char *buffer) |
||
543 | { |
||
544 | unsigned val; |
||
545 | asm_inline( |
||
546 | "int $0x40" |
||
547 | :"=a"(val) |
||
548 | :"a"(54), "b"(2), "c"(n), "d"(buffer) |
||
549 | ); |
||
550 | return val; |
||
551 | } |
||
552 | |||
553 | static inline |
||
554 | int _ksys_clip_pop() |
||
555 | { |
||
556 | unsigned val; |
||
557 | asm_inline ( |
||
558 | "int $0x40" |
||
559 | :"=a"(val) |
||
560 | :"a"(54), "b"(3) |
||
561 | ); |
||
562 | return val; |
||
563 | } |
||
564 | |||
565 | static inline |
||
566 | int _ksys_clip_unlock() |
||
567 | { |
||
568 | unsigned val; |
||
569 | asm_inline( |
||
570 | "int $0x40" |
||
571 | :"=a"(val) |
||
572 | :"a"(54), "b"(4) |
||
573 | ); |
||
574 | return val; |
||
575 | } |
||
576 | |||
577 | |||
578 | /* Working with time */ |
||
579 | |||
580 | static inline |
||
581 | unsigned _ksys_get_tick_count() |
||
582 | { |
||
583 | unsigned val; |
||
584 | asm_inline( |
||
585 | "int $0x40" |
||
586 | :"=a"(val) |
||
587 | :"a"(26),"b"(9) |
||
588 | ); |
||
589 | return val; |
||
590 | } |
||
591 | |||
592 | static inline |
||
593 | uint64_t _ksys_get_ns_count() |
||
594 | { |
||
595 | uint64_t val; |
||
596 | asm_inline( |
||
597 | "int $0x40" |
||
598 | :"=A"(val) |
||
599 | :"a"(26), "b"(10) |
||
600 | ); |
||
601 | return val; |
||
602 | } |
||
603 | |||
604 | static inline |
||
605 | void _ksys_delay(unsigned time) |
||
606 | { |
||
607 | asm_inline( |
||
608 | "int $0x40" |
||
609 | ::"a"(5), "b"(time) |
||
610 | :"memory" |
||
611 | ); |
||
612 | } |
||
613 | |||
614 | static inline |
||
615 | unsigned _ksys_get_date() |
||
616 | { |
||
617 | unsigned val; |
||
618 | asm_inline("int $0x40":"=a"(val):"a"(29)); |
||
619 | return val; |
||
620 | } |
||
621 | |||
622 | static inline |
||
623 | unsigned _ksys_get_clock() |
||
624 | { |
||
625 | unsigned val; |
||
626 | asm_inline("int $0x40":"=a"(val):"a"(3)); |
||
627 | return val; |
||
628 | } |
||
629 | |||
630 | |||
631 | /* Working with memory allocation */ |
||
632 | |||
633 | static inline |
||
634 | void* _ksys_alloc(size_t size){ |
||
635 | void *val; |
||
636 | asm_inline( |
||
637 | "int $0x40" |
||
638 | :"=a"(val) |
||
639 | :"a"(68),"b"(12),"c"(size) |
||
640 | ); |
||
641 | return val; |
||
642 | } |
||
643 | |||
644 | static inline |
||
645 | int _ksys_free(void *mem) |
||
646 | { |
||
647 | int val; |
||
648 | asm_inline( |
||
649 | "int $0x40" |
||
650 | :"=a"(val) |
||
651 | :"a"(68),"b"(13),"c"(mem) |
||
652 | ); |
||
653 | return val; |
||
654 | } |
||
655 | |||
656 | static inline |
||
657 | void* _ksys_realloc(void *mem, size_t size) |
||
658 | { |
||
659 | void *val; |
||
660 | asm_inline( |
||
661 | "int $0x40" |
||
662 | :"=a"(val) |
||
663 | :"a"(68),"b"(20),"c"(size),"d"(mem) |
||
664 | :"memory" |
||
665 | ); |
||
666 | return val; |
||
667 | } |
||
668 | |||
669 | static inline |
||
670 | int* _ksys_unmap(void *base, size_t offset, size_t size) |
||
671 | { |
||
672 | int *val; |
||
673 | asm_inline( |
||
674 | "int $0x40" |
||
675 | :"=a"(val) |
||
676 | :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size) |
||
677 | ); |
||
678 | return val; |
||
679 | } |
||
680 | |||
681 | |||
682 | /* Loading the dynamic coff library */ |
||
683 | |||
684 | static inline |
||
685 | ksys_coff_etable_t* not_optimized _ksys_cofflib_load(const char* path) |
||
686 | { |
||
687 | ksys_coff_etable_t *table; |
||
688 | asm_inline( |
||
689 | "int $0x40" |
||
690 | :"=a"(table) |
||
691 | :"a"(68),"b"(19), "c"(path) |
||
692 | ); |
||
693 | return table; |
||
694 | } |
||
695 | |||
696 | static inline |
||
697 | void* not_optimized _ksys_cofflib_getproc(ksys_coff_etable_t *table, const char* fun_name) |
||
698 | { |
||
699 | unsigned i=0; |
||
700 | while (1){ |
||
701 | if (NULL == (table+i)->func_name){ |
||
702 | break; |
||
703 | }else{ |
||
704 | if (!_ksys_strcmp(fun_name, (table+i)->func_name)){ |
||
705 | return (table+i)->func_ptr; |
||
706 | } |
||
707 | } |
||
708 | i++; |
||
709 | } |
||
710 | return NULL; |
||
711 | } |
||
712 | |||
713 | |||
714 | /* Debug board functions */ |
||
715 | |||
716 | static inline |
||
717 | void _ksys_debug_putc(char c) |
||
718 | { |
||
719 | asm_inline("int $0x40"::"a"(63), "b"(1), "c"(c)); |
||
720 | } |
||
721 | |||
722 | static inline |
||
723 | void _ksys_debug_puts(char *s) |
||
724 | { |
||
725 | unsigned i=0; |
||
726 | while (*(s+i)){ |
||
727 | asm_inline ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i))); |
||
728 | i++; |
||
729 | } |
||
730 | } |
||
731 | |||
732 | |||
733 | /* Working with threads and process */ |
||
734 | |||
735 | static inline |
||
736 | int _ksys_start_thread(void* proc, char* stack_top) |
||
737 | { |
||
738 | int val; |
||
739 | asm_inline( |
||
740 | "int $0x40" |
||
741 | :"=a"(val) |
||
742 | :"a"(51), "b"(1), "c"(proc), "d"(stack_top) |
||
743 | ); |
||
744 | return val; |
||
745 | } |
||
746 | |||
747 | static inline |
||
748 | void _ksys_focus_window(int slot){ |
||
749 | asm_inline( |
||
750 | "int $0x40" |
||
751 | ::"a"(18), "b"(3), "c"(slot) |
||
752 | ); |
||
753 | } |
||
754 | |||
755 | static inline |
||
756 | int _ksys_get_thread_slot(int tid){ |
||
757 | int val; |
||
758 | asm_inline( |
||
759 | "int $0x40" |
||
760 | :"=a"(val) |
||
761 | :"a"(18), "b"(21), "c"(tid) |
||
762 | ); |
||
763 | return val; |
||
764 | } |
||
765 | |||
766 | static inline |
||
767 | int not_optimized _ksys_process_info(ksys_proc_table_t* table, int pid) |
||
768 | { |
||
769 | int val; |
||
770 | asm_inline( |
||
771 | "int $0x40" |
||
772 | :"=a"(val) |
||
773 | :"a"(9), "b"(table), "c"(pid) |
||
774 | ); |
||
775 | return val; |
||
776 | } |
||
777 | |||
778 | static inline |
||
779 | void _ksys_exit() |
||
780 | { |
||
781 | asm_inline("int $0x40"::"a"(-1)); |
||
782 | } |
||
783 | |||
784 | |||
785 | /* Working with files and directories */ |
||
786 | |||
787 | static inline |
||
788 | void _ksys_setcwd(char* dir){ |
||
789 | asm_inline( |
||
790 | "int $0x40" |
||
791 | ::"a"(30), "b"(1), "c"(dir) |
||
792 | ); |
||
793 | } |
||
794 | |||
795 | static inline |
||
796 | int _ksys_getcwd(char* buf, int bufsize){ |
||
797 | register int val; |
||
798 | asm_inline( |
||
799 | "int $0x40" |
||
800 | :"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize) |
||
801 | ); |
||
802 | return val; |
||
803 | } |
||
804 | |||
805 | static inline |
||
806 | ksys_ufile_t _ksys_load_file(const char *path) |
||
807 | { |
||
808 | ksys_ufile_t uf; |
||
809 | asm_inline( |
||
810 | "int $0x40" |
||
811 | :"=a"(uf.data), "=d"(uf.size) |
||
812 | :"a"(68), "b"(27),"c"(path) |
||
813 | ); |
||
814 | return uf; |
||
815 | } |
||
816 | |||
817 | static inline |
||
818 | ksys_ufile_t _ksys_load_file_enc(const char *path, unsigned file_encoding) |
||
819 | { |
||
820 | ksys_ufile_t uf; |
||
821 | asm_inline( |
||
822 | "int $0x40" |
||
823 | :"=a"(uf.data), "=d"(uf.size) |
||
824 | :"a"(68), "b"(28),"c"(path), "d"(file_encoding) |
||
825 | ); |
||
826 | return uf; |
||
827 | } |
||
828 | |||
829 | static inline |
||
830 | int not_optimized _ksys_work_files(const ksys70_t *k) |
||
831 | { |
||
832 | int status; |
||
833 | asm_inline( |
||
834 | "int $0x40" |
||
835 | :"=a"(status) |
||
836 | :"a"(70), "b"(k) |
||
837 | ); |
||
838 | return status; |
||
839 | } |
||
840 | |||
841 | static inline |
||
842 | int not_optimized _ksys_file_read_file(const char *name, unsigned long long offset, unsigned size, void *buf, unsigned *bytes_read) |
||
843 | { |
||
844 | ksys70_t k; |
||
845 | k.p00 = 0; |
||
846 | k.p04 = offset; |
||
847 | k.p12 = size; |
||
848 | k.buf16 = buf; |
||
849 | k.p20 = 0; |
||
850 | k.p21 = name; |
||
851 | int status; |
||
852 | unsigned bytes_read_v; |
||
853 | asm_inline( |
||
854 | "int $0x40" |
||
855 | :"=a"(status), "=b"(bytes_read_v) |
||
856 | :"a"(70), "b"(&k) |
||
857 | ); |
||
858 | if (!status) { |
||
859 | *bytes_read = bytes_read_v; |
||
860 | } |
||
861 | return status; |
||
862 | } |
||
863 | |||
864 | static inline |
||
865 | int not_optimized _ksys_file_write_file(const char *name, unsigned long long offset, unsigned size, const void *buf, unsigned *bytes_written) |
||
866 | { |
||
867 | ksys70_t k; |
||
868 | k.p00 = 3; |
||
869 | k.p04 = offset; |
||
870 | k.p12 = size; |
||
871 | k.cbuf16 = buf; |
||
872 | k.p20 = 0; |
||
873 | k.p21 = name; |
||
874 | int status; |
||
875 | unsigned bytes_written_v; |
||
876 | asm_inline( |
||
877 | "int $0x40" |
||
878 | :"=a"(status), "=b"(bytes_written_v) |
||
879 | :"a"(70), "b"(&k) |
||
880 | ); |
||
881 | if (!status) { |
||
882 | *bytes_written = bytes_written_v; |
||
883 | } |
||
884 | return status; |
||
885 | } |
||
886 | |||
887 | static inline |
||
888 | int not_optimized _ksys_file_get_info(const char *name, ksys_bdfe_t *bdfe) |
||
889 | { |
||
890 | ksys70_t k; |
||
891 | k.p00 = 5; |
||
892 | k.bdfe = bdfe; |
||
893 | k.p20 = 0; |
||
894 | k.p21 = name; |
||
895 | return _ksys_work_files(&k); |
||
896 | } |
||
897 | |||
898 | static inline |
||
899 | int not_optimized _ksys_file_delete(const char *name) |
||
900 | { |
||
901 | ksys70_t k; |
||
902 | k.p00 = 8; |
||
903 | k.p20 = 0; |
||
904 | k.p21 = name; |
||
905 | return _ksys_work_files(&k); |
||
906 | } |
||
907 | |||
908 | static inline |
||
909 | int not_optimized _ksys_file_rename(const char *name, const char *new_name) |
||
910 | { |
||
911 | ksys70_t k; |
||
912 | k.p00 = 10; |
||
913 | k.new_name = new_name; |
||
914 | k.p20 = 0; |
||
915 | k.p21 = name; |
||
916 | return _ksys_work_files(&k); |
||
917 | } |
||
918 | |||
919 | |||
920 | static inline |
||
921 | int not_optimized _ksys_exec(char *app_name, char *args){ |
||
922 | ksys70_t file_op; |
||
923 | file_op.p00 = 7; |
||
924 | file_op.p04dw = 0; |
||
925 | file_op.p08dw = (unsigned)args; |
||
926 | file_op.p21 = app_name; |
||
927 | register int val; |
||
928 | asm_inline( |
||
929 | "int $0x40" |
||
930 | :"=a"(val) |
||
931 | :"a"(70), "b"(&file_op) |
||
932 | ); |
||
933 | return val; |
||
934 | } |
||
935 | |||
936 | #endif // _KSYS_H_><>><>><>><>><>><>><>><>><>><>><>><>16)+h), |