Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6429 | siemargl | 1 | #ifndef __KOS_32_SYS_H__ |
2 | #define __KOS_32_SYS_H__ |
||
3 | |||
4 | // file header taken from newlib |
||
5 | // added many sys functions, compatible with tcc |
||
7172 | siemargl | 6 | // with gcc USE gcc -mno-ms-bitfields!!! |
6429 | siemargl | 7 | |
7172 | siemargl | 8 | |
6429 | siemargl | 9 | //#include |
10 | //#include |
||
11 | #include |
||
12 | #include |
||
13 | typedef unsigned int uint32_t; |
||
14 | typedef int int32_t; |
||
15 | typedef unsigned char uint8_t; |
||
16 | typedef unsigned short int uint16_t; |
||
17 | typedef unsigned long long uint64_t; |
||
18 | |||
19 | #ifdef __cplusplus |
||
20 | extern "C" { |
||
21 | #endif |
||
22 | |||
23 | //#ifdef CONFIG_DEBUF |
||
24 | // #define DBG(format,...) printf(format,##__VA_ARGS__) |
||
25 | //#else |
||
26 | // #define DBG(format,...) |
||
27 | //#endif |
||
28 | |||
29 | #define TYPE_3_BORDER_WIDTH 5 |
||
30 | #define WIN_STATE_MINIMIZED 0x02 |
||
31 | #define WIN_STATE_ROLLED 0x04 |
||
6441 | siemargl | 32 | #define POS_SCREEN 0 |
33 | #define POS_WINDOW 1 |
||
6429 | siemargl | 34 | |
6441 | siemargl | 35 | #define IPC_NOBUFFER 1 |
36 | #define IPC_LOCKED 2 |
||
37 | #define IPC_OVERFLOW 3 |
||
38 | #define IPC_NOPID 4 |
||
39 | |||
40 | #define SHM_OPEN 0x00 |
||
41 | #define SHM_OPEN_ALWAYS 0x04 |
||
42 | #define SHM_CREATE 0x08 |
||
43 | #define SHM_READ 0x00 |
||
44 | #define SHM_WRITE 0x01 |
||
45 | |||
46 | |||
6429 | siemargl | 47 | typedef unsigned int color_t; |
48 | |||
6439 | siemargl | 49 | |
50 | typedef union __attribute__((packed)) pos_t |
||
6429 | siemargl | 51 | { |
52 | uint32_t val; |
||
53 | struct |
||
54 | { |
||
55 | short x; |
||
56 | short y; |
||
6439 | siemargl | 57 | }; |
58 | } pos_t; |
||
6429 | siemargl | 59 | |
6439 | siemargl | 60 | |
61 | typedef union __attribute__((packed)) oskey_t |
||
6429 | siemargl | 62 | { |
63 | uint32_t val; |
||
64 | struct |
||
65 | { |
||
66 | uint8_t state; |
||
67 | uint8_t code; |
||
68 | uint16_t ctrl_key; |
||
6439 | siemargl | 69 | }; |
70 | } oskey_t; |
||
6429 | siemargl | 71 | |
72 | typedef struct |
||
73 | { |
||
74 | unsigned handle; |
||
75 | unsigned io_code; |
||
76 | void *input; |
||
77 | int inp_size; |
||
78 | void *output; |
||
79 | int out_size; |
||
80 | }ioctl_t; |
||
81 | |||
6441 | siemargl | 82 | typedef union |
83 | { |
||
84 | struct |
||
85 | { |
||
86 | void *data; |
||
87 | size_t size; |
||
88 | } x; |
||
89 | unsigned long long raw; |
||
90 | }ufile_t; |
||
91 | |||
92 | struct kolibri_system_colors { |
||
93 | color_t frame_area; |
||
94 | color_t grab_bar; |
||
95 | color_t grab_bar_button; |
||
96 | color_t grab_button_text; |
||
97 | color_t grab_text; |
||
98 | color_t work_area; |
||
99 | color_t work_button; |
||
100 | color_t work_button_text; |
||
101 | color_t work_text; |
||
102 | color_t work_graph; |
||
103 | }; |
||
104 | |||
105 | |||
106 | struct blit_call |
||
107 | { |
||
108 | int dstx; |
||
109 | int dsty; |
||
110 | int w; |
||
111 | int h; |
||
112 | |||
113 | int srcx; |
||
114 | int srcy; |
||
115 | int srcw; |
||
116 | int srch; |
||
117 | |||
118 | void *bitmap; |
||
119 | int stride; |
||
120 | }; |
||
121 | |||
122 | struct ipc_message |
||
123 | { |
||
124 | uint32_t pid; // PID of sending thread |
||
125 | uint32_t datalen; // data bytes |
||
126 | char data[0]; // data begin |
||
127 | }; |
||
128 | |||
129 | struct ipc_buffer |
||
130 | { |
||
131 | uint32_t lock; // nonzero is locked |
||
132 | uint32_t used; // used bytes in buffer |
||
133 | struct ipc_message data[0]; // data begin |
||
134 | }; |
||
135 | |||
7172 | siemargl | 136 | |
137 | typedef struct __attribute__((packed)) file_op_t |
||
138 | { |
||
139 | uint32_t fn; |
||
140 | uint32_t flags; |
||
141 | char* args; |
||
142 | uint32_t res1, res2; |
||
143 | char zero; |
||
144 | char* app_name |
||
145 | #ifdef __TINYC__ |
||
146 | __attribute__((packed)) |
||
147 | #endif |
||
148 | ; |
||
149 | } file_op_t; |
||
150 | |||
151 | |||
6429 | siemargl | 152 | static inline void begin_draw(void) |
153 | { |
||
154 | __asm__ __volatile__( |
||
155 | "int $0x40" ::"a"(12),"b"(1)); |
||
156 | }; |
||
157 | |||
158 | static inline |
||
159 | void end_draw(void) |
||
160 | { |
||
161 | __asm__ __volatile__( |
||
162 | "int $0x40" ::"a"(12),"b"(2)); |
||
163 | }; |
||
164 | |||
165 | static inline |
||
166 | void sys_create_window(int x, int y, int w, int h, const char *name, |
||
167 | color_t workcolor, uint32_t style) |
||
168 | { |
||
169 | __asm__ __volatile__( |
||
170 | "int $0x40" |
||
171 | ::"a"(0), |
||
172 | "b"((x << 16) | ((w-1) & 0xFFFF)), |
||
173 | "c"((y << 16) | ((h-1) & 0xFFFF)), |
||
174 | "d"((style << 24) | (workcolor & 0xFFFFFF)), |
||
175 | "D"(name), |
||
176 | "S"(0) : "memory"); |
||
177 | }; |
||
178 | |||
179 | static inline |
||
180 | void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color) |
||
181 | { |
||
182 | __asm__ __volatile__( |
||
183 | "int $0x40" |
||
184 | ::"a"(8), |
||
185 | "b"(x_w), |
||
186 | "c"(y_h), |
||
187 | "d"(id), |
||
188 | "S"(color)); |
||
189 | }; |
||
190 | |||
191 | static inline |
||
192 | void draw_line(int xs, int ys, int xe, int ye, color_t color) |
||
193 | { |
||
194 | __asm__ __volatile__( |
||
195 | "int $0x40" |
||
196 | ::"a"(38), "d"(color), |
||
197 | "b"((xs << 16) | xe), |
||
198 | "c"((ys << 16) | ye)); |
||
199 | } |
||
200 | |||
201 | static inline |
||
202 | void draw_bar(int x, int y, int w, int h, color_t color) |
||
203 | { |
||
204 | __asm__ __volatile__( |
||
205 | "int $0x40" |
||
206 | ::"a"(13), "d"(color), |
||
207 | "b"((x << 16) | w), |
||
208 | "c"((y << 16) | h)); |
||
209 | } |
||
210 | |||
211 | static inline |
||
212 | void draw_bitmap(void *bitmap, int x, int y, int w, int h) |
||
213 | { |
||
214 | __asm__ __volatile__( |
||
215 | "int $0x40" |
||
216 | ::"a"(7), "b"(bitmap), |
||
217 | "c"((w << 16) | h), |
||
218 | "d"((x << 16) | y)); |
||
219 | } |
||
220 | |||
221 | static inline |
||
222 | void draw_text_sys(const char *text, int x, int y, int len, color_t color) |
||
223 | { |
||
224 | __asm__ __volatile__( |
||
225 | "int $0x40" |
||
226 | ::"a"(4),"d"(text), |
||
227 | "b"((x << 16) | y), |
||
228 | "S"(len),"c"(color) |
||
229 | :"memory"); |
||
230 | } |
||
231 | |||
232 | static inline |
||
233 | uint32_t get_skin_height(void) |
||
234 | { |
||
235 | uint32_t height; |
||
236 | |||
237 | __asm__ __volatile__( |
||
238 | "int $0x40 \n\t" |
||
239 | :"=a"(height) |
||
240 | :"a"(48),"b"(4)); |
||
241 | return height; |
||
242 | }; |
||
243 | |||
244 | static inline |
||
245 | pos_t get_mouse_pos(int origin) |
||
246 | { |
||
247 | pos_t val; |
||
248 | |||
249 | __asm__ __volatile__( |
||
250 | "int $0x40 \n\t" |
||
251 | "rol $16, %%eax" |
||
252 | :"=a"(val) |
||
253 | :"a"(37),"b"(origin)); |
||
254 | return val; |
||
255 | } |
||
256 | |||
257 | static inline |
||
258 | uint32_t get_mouse_buttons(void) |
||
259 | { |
||
260 | uint32_t val; |
||
261 | |||
262 | __asm__ __volatile__( |
||
263 | "int $0x40" |
||
264 | :"=a"(val) |
||
265 | :"a"(37),"b"(2)); |
||
266 | return val; |
||
267 | }; |
||
268 | |||
269 | static inline |
||
270 | uint32_t get_mouse_wheels(void) |
||
271 | { |
||
272 | uint32_t val; |
||
273 | |||
274 | __asm__ __volatile__( |
||
275 | "int $0x40 \n\t" |
||
276 | :"=a"(val) |
||
277 | :"a"(37),"b"(7)); |
||
278 | return val; |
||
279 | }; |
||
280 | |||
281 | static inline uint32_t load_cursor(void *path, uint32_t flags) |
||
282 | { |
||
283 | uint32_t val; |
||
284 | __asm__ __volatile__( |
||
285 | "int $0x40" |
||
286 | :"=a"(val) |
||
287 | :"a"(37), "b"(4), "c"(path), "d"(flags)); |
||
288 | return val; |
||
289 | } |
||
290 | |||
291 | static inline uint32_t set_cursor(uint32_t cursor) |
||
292 | { |
||
293 | uint32_t old; |
||
294 | __asm__ __volatile__( |
||
295 | "int $0x40" |
||
296 | :"=a"(old) |
||
297 | :"a"(37), "b"(5), "c"(cursor)); |
||
298 | return old; |
||
299 | }; |
||
300 | |||
301 | static inline int destroy_cursor(uint32_t cursor) |
||
302 | { |
||
303 | int ret; |
||
304 | __asm__ __volatile__( |
||
305 | "int $0x40" |
||
306 | :"=a"(ret) |
||
307 | :"a"(37), "b"(6), "c"(cursor) |
||
308 | :"memory"); |
||
309 | return ret; |
||
310 | }; |
||
311 | |||
312 | |||
313 | static inline |
||
314 | uint32_t wait_for_event(uint32_t time) |
||
315 | { |
||
316 | uint32_t val; |
||
317 | __asm__ __volatile__( |
||
318 | "int $0x40" |
||
319 | :"=a"(val) |
||
320 | :"a"(23), "b"(time)); |
||
321 | return val; |
||
322 | }; |
||
323 | |||
324 | static inline uint32_t check_os_event() |
||
325 | { |
||
326 | uint32_t val; |
||
327 | __asm__ __volatile__( |
||
328 | "int $0x40" |
||
329 | :"=a"(val) |
||
330 | :"a"(11)); |
||
331 | return val; |
||
332 | }; |
||
333 | |||
334 | static inline uint32_t get_os_event() |
||
335 | { |
||
336 | uint32_t val; |
||
337 | __asm__ __volatile__( |
||
338 | "int $0x40" |
||
339 | :"=a"(val) |
||
340 | :"a"(10)); |
||
341 | return val; |
||
342 | }; |
||
343 | |||
344 | static inline |
||
345 | uint32_t get_tick_count(void) |
||
346 | { |
||
347 | uint32_t val; |
||
348 | __asm__ __volatile__( |
||
349 | "int $0x40" |
||
350 | :"=a"(val) |
||
351 | :"a"(26),"b"(9)); |
||
352 | return val; |
||
353 | }; |
||
354 | |||
355 | static inline |
||
356 | uint64_t get_ns_count(void) |
||
357 | { |
||
358 | uint64_t val; |
||
359 | __asm__ __volatile__( |
||
360 | "int $0x40" |
||
361 | :"=A"(val) |
||
362 | :"a"(26), "b"(10)); |
||
363 | return val; |
||
364 | }; |
||
365 | |||
366 | static inline |
||
367 | oskey_t get_key(void) |
||
368 | { |
||
369 | oskey_t val; |
||
370 | __asm__ __volatile__( |
||
371 | "int $0x40" |
||
372 | :"=a"(val) |
||
373 | :"a"(2)); |
||
374 | return val; |
||
375 | } |
||
376 | |||
377 | static inline |
||
378 | uint32_t get_os_button() |
||
379 | { |
||
380 | uint32_t val; |
||
381 | __asm__ __volatile__( |
||
382 | "int $0x40" |
||
383 | :"=a"(val) |
||
384 | :"a"(17)); |
||
385 | return val>>8; |
||
386 | }; |
||
387 | |||
388 | static inline uint32_t get_service(char *name) |
||
389 | { |
||
390 | uint32_t retval = 0; |
||
391 | __asm__ __volatile__( |
||
392 | "int $0x40" |
||
393 | :"=a"(retval) |
||
394 | :"a"(68),"b"(16),"c"(name) |
||
395 | :"memory"); |
||
396 | |||
397 | return retval; |
||
398 | }; |
||
399 | |||
400 | static inline int call_service(ioctl_t *io) |
||
401 | { |
||
402 | int retval; |
||
403 | |||
404 | __asm__ __volatile__( |
||
405 | "int $0x40" |
||
406 | :"=a"(retval) |
||
407 | :"a"(68),"b"(17),"c"(io) |
||
408 | :"memory","cc"); |
||
409 | |||
410 | return retval; |
||
411 | }; |
||
412 | |||
413 | |||
414 | static inline void yield(void) |
||
415 | { |
||
416 | __asm__ __volatile__( |
||
417 | "int $0x40" |
||
418 | ::"a"(68), "b"(1)); |
||
419 | }; |
||
420 | |||
421 | static inline void delay(uint32_t time) |
||
422 | { |
||
423 | __asm__ __volatile__( |
||
424 | "int $0x40" |
||
425 | ::"a"(5), "b"(time) |
||
426 | :"memory"); |
||
427 | }; |
||
428 | |||
429 | static inline |
||
430 | void *user_alloc(size_t size) |
||
431 | { |
||
432 | void *val; |
||
433 | __asm__ __volatile__( |
||
434 | "int $0x40" |
||
435 | :"=a"(val) |
||
436 | :"a"(68),"b"(12),"c"(size)); |
||
437 | return val; |
||
438 | } |
||
439 | |||
440 | static inline |
||
441 | int user_free(void *mem) |
||
442 | { |
||
443 | int val; |
||
444 | __asm__ __volatile__( |
||
445 | "int $0x40" |
||
446 | :"=a"(val) |
||
447 | :"a"(68),"b"(13),"c"(mem)); |
||
448 | return val; |
||
449 | } |
||
450 | |||
451 | static inline |
||
452 | void* user_realloc(void *mem, size_t size) |
||
453 | { |
||
454 | void *val; |
||
455 | __asm__ __volatile__( |
||
456 | "int $0x40" |
||
457 | :"=a"(val) |
||
458 | :"a"(68),"b"(20),"c"(size),"d"(mem) |
||
459 | :"memory"); |
||
460 | |||
461 | return val; |
||
462 | }; |
||
463 | |||
464 | static inline |
||
465 | int *user_unmap(void *base, size_t offset, size_t size) |
||
466 | { |
||
467 | int *val; |
||
468 | __asm__ __volatile__( |
||
469 | "int $0x40" |
||
470 | :"=a"(val) |
||
471 | :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size)); |
||
472 | return val; |
||
473 | }; |
||
474 | |||
475 | static inline ufile_t load_file(const char *path) |
||
476 | { |
||
477 | ufile_t uf; |
||
478 | |||
479 | __asm__ __volatile__ ( |
||
480 | "int $0x40" |
||
481 | :"=A"(uf.raw) |
||
482 | :"a" (68), "b"(27),"c"(path)); |
||
483 | |||
484 | return uf; |
||
485 | }; |
||
486 | |||
487 | static inline int GetScreenSize() |
||
488 | { |
||
489 | int retval; |
||
490 | |||
491 | __asm__ __volatile__( |
||
492 | "int $0x40" |
||
493 | :"=a"(retval) |
||
494 | :"a"(61), "b"(1)); |
||
495 | return retval; |
||
496 | } |
||
497 | |||
498 | |||
499 | static inline void get_proc_info(char *info) |
||
500 | { |
||
501 | __asm__ __volatile__( |
||
502 | "int $0x40" |
||
503 | : |
||
504 | :"a"(9), "b"(info), "c"(-1) |
||
505 | :"memory"); |
||
506 | }; |
||
507 | |||
508 | static inline void Blit(void *bitmap, int dst_x, int dst_y, |
||
509 | int src_x, int src_y, int w, int h, |
||
510 | int src_w, int src_h, int stride) |
||
511 | { |
||
512 | volatile struct blit_call bc; |
||
513 | |||
514 | bc.dstx = dst_x; |
||
515 | bc.dsty = dst_y; |
||
516 | bc.w = w; |
||
517 | bc.h = h; |
||
518 | bc.srcx = src_x; |
||
519 | bc.srcy = src_y; |
||
520 | bc.srcw = src_w; |
||
521 | bc.srch = src_h; |
||
522 | bc.stride = stride; |
||
523 | bc.bitmap = bitmap; |
||
524 | |||
525 | __asm__ __volatile__( |
||
526 | "int $0x40" |
||
527 | ::"a"(73),"b"(0),"c"(&bc.dstx)); |
||
528 | }; |
||
529 | |||
6441 | siemargl | 530 | |
531 | // newlib exclusive |
||
532 | #ifndef __TINYC__ |
||
6429 | siemargl | 533 | int create_thread(int (*proc)(void *param), void *param, int stack_size); |
534 | |||
535 | void* load_library(const char *name); |
||
536 | |||
537 | void* get_proc_address(void *handle, const char *proc_name); |
||
538 | |||
539 | void enumerate_libraries(int (*callback)(void *handle, const char* name, |
||
540 | uint32_t base, uint32_t size, void *user_data), |
||
541 | void *user_data); |
||
6441 | siemargl | 542 | #endif |
6429 | siemargl | 543 | |
7172 | siemargl | 544 | /////////////////////////////////////////////////////////////////////////////// |
545 | /// May be next section need to be added in newlibc |
||
546 | // Siemargl addenium |
||
6429 | siemargl | 547 | |
7172 | siemargl | 548 | #define X_Y(x,y) (((x)<<16)|(y)) |
549 | |||
6429 | siemargl | 550 | enum KOLIBRI_GUI_EVENTS { |
551 | KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */ |
||
552 | KOLIBRI_EVENT_REDRAW = 1, /* Window and window elements should be redrawn */ |
||
553 | KOLIBRI_EVENT_KEY = 2, /* A key on the keyboard was pressed */ |
||
554 | KOLIBRI_EVENT_BUTTON = 3, /* A button was clicked with the mouse */ |
||
555 | KOLIBRI_EVENT_DESKTOP = 5, /* Desktop redraw finished */ |
||
556 | KOLIBRI_EVENT_MOUSE = 6, /* Mouse activity (movement, button press) was detected */ |
||
557 | KOLIBRI_EVENT_IPC = 7, /* Interprocess communication notify */ |
||
558 | KOLIBRI_EVENT_NETWORK = 8, /* Network event */ |
||
559 | KOLIBRI_EVENT_DEBUG = 9, /* Debug subsystem event */ |
||
560 | KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ |
||
561 | }; |
||
562 | |||
7172 | siemargl | 563 | enum control_keys { |
564 | KM_SHIFT = 0x00010000, |
||
565 | KM_CTRL = 0x00020000, |
||
566 | KM_ALT = 0x00040000, |
||
567 | KM_NUMLOCK = 0x00080000 |
||
568 | }; |
||
6429 | siemargl | 569 | |
7172 | siemargl | 570 | |
571 | struct __attribute__ ((__packed__)) fs_dirinfo { |
||
572 | uint32_t subfn; // 1 read dir |
||
573 | uint32_t start; |
||
574 | uint32_t flags; |
||
575 | uint32_t size; |
||
576 | uint32_t retval; |
||
577 | union { |
||
578 | struct __attribute__ ((__packed__)) { |
||
579 | uint8_t zero; // 0 |
||
580 | char* ppath; |
||
581 | }; |
||
582 | char path[5]; // up to 4096 |
||
583 | } ; |
||
584 | }; |
||
585 | |||
586 | static inline |
||
587 | uint32_t sf_file(int subfn, struct fs_dirinfo* dinfo) |
||
588 | /// SysFn70 call with subfunction |
||
589 | /// retval 0 if ok |
||
590 | { |
||
591 | uint32_t retval; |
||
592 | dinfo->subfn = subfn; |
||
593 | |||
594 | __asm__ __volatile__( |
||
595 | "int $0x40 " |
||
596 | :"=a"(retval) |
||
597 | :"a"(70),"b"(dinfo) |
||
598 | :); |
||
599 | |||
600 | return retval; |
||
601 | }; |
||
602 | |||
603 | |||
604 | struct fs_dirheader { |
||
605 | uint32_t version; // 1 |
||
606 | uint32_t curn_blocks; // number of read dir items (BDFE) |
||
607 | uint32_t totl_blocks; // directory full size |
||
608 | char other[20]; // reserved 0 |
||
609 | }; |
||
610 | |||
611 | enum filetype |
||
612 | { |
||
613 | FS_RONLY = 1, |
||
614 | FS_HIDDEN = 2, |
||
615 | FS_SYSTEM = 4, |
||
616 | FS_VOLID = 8, |
||
617 | FS_SUBDIR = 16, |
||
618 | FS_FOLDER = 16, |
||
619 | FS_ARCHIV = 32 |
||
620 | }; |
||
621 | |||
622 | struct __attribute__ ((__packed__)) fs_filetime { |
||
623 | uint8_t sec; |
||
624 | uint8_t mm; |
||
625 | uint8_t hour; |
||
626 | uint8_t zero; |
||
627 | }; |
||
628 | |||
629 | struct __attribute__ ((__packed__)) fs_filedate { |
||
630 | uint8_t day; |
||
631 | uint8_t month; |
||
632 | uint16_t year; |
||
633 | }; |
||
634 | |||
635 | /// directory entry cp866 |
||
636 | struct fsBDFE { |
||
637 | uint32_t filetype; |
||
638 | uint32_t encoding; // 0 - cp866, 1 - utf16le |
||
639 | struct fs_filetime tm_created; |
||
640 | struct fs_filedate dt_created; |
||
641 | struct fs_filetime tm_accessed; |
||
642 | struct fs_filedate dt_accessed; |
||
643 | struct fs_filetime tm_modified; |
||
644 | struct fs_filedate dt_modified; |
||
645 | uint64_t size; |
||
646 | char fname[264]; |
||
647 | }; // must be sized 304 |
||
648 | |||
649 | /// directory entry UTF16LE |
||
650 | struct fsBDFE_16 { |
||
651 | uint32_t filetype; |
||
652 | uint32_t encoding; // 0 - cp866, 1 - utf16le |
||
653 | struct fs_filetime tm_created; |
||
654 | struct fs_filedate dt_created; |
||
655 | struct fs_filetime tm_accessed; |
||
656 | struct fs_filedate dt_accessed; |
||
657 | struct fs_filetime tm_modified; |
||
658 | struct fs_filedate dt_modified; |
||
659 | uint64_t size; |
||
660 | wchar_t fname[260]; |
||
661 | }; // must be sized 560 |
||
662 | |||
663 | |||
664 | |||
6429 | siemargl | 665 | // copied from /programs/system/shell/system/kolibri.c |
666 | // fn's returned -1 as syserror, 1 as error, 0 as OK |
||
667 | static inline |
||
668 | int kol_clip_num() |
||
669 | { |
||
670 | register uint32_t val; |
||
671 | asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(0)); |
||
672 | return val; |
||
673 | } |
||
674 | |||
675 | static inline |
||
676 | char* kol_clip_get(int n) |
||
677 | // returned buffer must be freed by user_free() |
||
678 | { |
||
679 | register char* val; |
||
680 | asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(1), "c"(n)); |
||
681 | return val; |
||
682 | } |
||
683 | |||
684 | static inline |
||
685 | int kol_clip_set(int n, char buffer[]) |
||
686 | { |
||
687 | register uint32_t val; |
||
688 | asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(2), "c"(n), "d"(buffer)); |
||
689 | return val; |
||
690 | } |
||
691 | |||
692 | static inline |
||
693 | int kol_clip_pop() |
||
694 | { |
||
695 | register uint32_t val; |
||
696 | asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(3)); |
||
697 | return val; |
||
698 | } |
||
699 | |||
700 | static inline |
||
701 | int kol_clip_unlock() |
||
702 | { |
||
703 | register uint32_t val; |
||
704 | asm volatile ("int $0x40":"=a"(val):"a"(54), "b"(4)); |
||
705 | return val; |
||
706 | } |
||
707 | |||
708 | static inline void get_system_colors(struct kolibri_system_colors *color_table) |
||
709 | { |
||
710 | __asm__ volatile ("int $0x40" |
||
711 | : |
||
712 | :"a"(48),"b"(3),"c"(color_table),"d"(40) |
||
713 | ); |
||
714 | |||
715 | /* color_table should point to the system color table */ |
||
716 | } |
||
717 | |||
718 | static inline void debug_board_write_byte(const char ch){ |
||
719 | __asm__ __volatile__( |
||
720 | "int $0x40" |
||
721 | : |
||
722 | :"a"(63), "b"(1), "c"(ch)); |
||
723 | } |
||
724 | |||
725 | |||
726 | static inline void draw_number_sys(int32_t number, int x, int y, int len, color_t color){ |
||
727 | register uint32_t fmt; |
||
728 | fmt = len << 16 | 0x80000000; // no leading zeros + width |
||
729 | // fmt = len << 16 | 0x00000000; // leading zeros + width |
||
730 | __asm__ __volatile__( |
||
731 | "int $0x40" |
||
732 | : |
||
733 | :"a"(47), "b"(fmt), "c"(number), "d"((x << 16) | y), "S"(color)); |
||
734 | } |
||
735 | |||
736 | static inline |
||
737 | uint32_t get_mouse_eventstate(void) |
||
738 | { |
||
739 | uint32_t val; |
||
740 | |||
741 | __asm__ __volatile__( |
||
742 | "int $0x40" |
||
743 | :"=a"(val) |
||
744 | :"a"(37),"b"(3)); |
||
745 | return val; |
||
746 | }; |
||
747 | |||
748 | static inline |
||
749 | uint32_t set_event_mask(uint32_t mask) |
||
750 | { |
||
751 | register uint32_t val; |
||
752 | asm volatile ("int $0x40":"=a"(val):"a"(40), "b"(mask)); |
||
753 | return val; |
||
754 | } |
||
755 | |||
756 | typedef void (*thread_proc)(void*); |
||
757 | |||
6441 | siemargl | 758 | static inline |
6429 | siemargl | 759 | int start_thread(thread_proc proc, char* stack_top) |
760 | { |
||
761 | register int val; |
||
762 | asm volatile ("int $0x40":"=a"(val):"a"(51), "b"(1), "c"(proc), "d"(stack_top)); |
||
763 | return val; |
||
764 | } |
||
765 | |||
766 | static inline |
||
767 | void kos_exit() |
||
768 | { |
||
769 | asm volatile ("int $0x40"::"a"(-1)); |
||
770 | } |
||
771 | |||
772 | static inline void focus_window(int slot){ |
||
773 | asm volatile ("int $0x40"::"a"(18), "b"(3), "c"(slot)); |
||
774 | } |
||
775 | |||
776 | static inline int get_thread_slot(int tid){ |
||
777 | register int val; |
||
778 | asm volatile ("int $0x40":"=a"(val):"a"(18), "b"(21), "c"(tid)); |
||
779 | return val; |
||
780 | } |
||
781 | |||
782 | static inline void set_current_folder(char* dir){ |
||
783 | asm volatile ("int $0x40"::"a"(30), "b"(1), "c"(dir)); |
||
784 | } |
||
785 | |||
786 | static inline int get_current_folder(char* buf, int bufsize){ |
||
787 | register int val; |
||
788 | asm volatile ("int $0x40":"=a"(val):"a"(30), "b"(2), "c"(buf), "d"(bufsize)); |
||
789 | return val; |
||
790 | } |
||
791 | |||
6441 | siemargl | 792 | static inline |
793 | void ipc_set_area(void* buf, int bufsize){ |
||
794 | asm volatile ("int $0x40"::"a"(60), "b"(1), "c"(buf), "d"(bufsize)); |
||
795 | } |
||
796 | |||
797 | static inline |
||
798 | int ipc_send_message(int pid_reciever, void *data, int datalen) { |
||
799 | register int val; |
||
800 | asm volatile ("int $0x40":"=a"(val):"a"(60), "b"(2), "c"(pid_reciever), "d"(data), "S"(datalen)); |
||
801 | return val; |
||
802 | } |
||
803 | |||
804 | static inline |
||
805 | void* shm_open(char *shm_name, int msize, int flags, int *retsz){ |
||
806 | register int val, cod; |
||
807 | asm volatile ("int $0x40":"=a"(val),"=d"(cod):"a"(68), "b"(22), "c"(shm_name), "d"(msize), "S"(flags)); |
||
808 | |||
809 | if(retsz) *retsz = cod; // errcode if NULL or memsize when open |
||
810 | return (void*)val; |
||
811 | } |
||
812 | |||
813 | static inline |
||
814 | void shm_close(char *shm_name){ |
||
815 | asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name)); |
||
816 | } |
||
817 | |||
818 | static inline |
||
819 | int start_app(char *app_name, char *args){ |
||
7172 | siemargl | 820 | file_op_t file_op; |
6441 | siemargl | 821 | memset(&file_op, 0, sizeof(file_op)); |
822 | file_op.fn = 7; |
||
823 | file_op.args = args; |
||
824 | file_op.app_name = app_name; |
||
825 | |||
826 | register int val; |
||
827 | asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op)); |
||
828 | |||
829 | return val; |
||
830 | } |
||
831 | |||
7172 | siemargl | 832 | static inline |
833 | uint32_t get_control_keys(void) |
||
834 | { |
||
835 | uint32_t ctrl; |
||
6441 | siemargl | 836 | |
7172 | siemargl | 837 | __asm__ __volatile__( |
838 | "int $0x40 \n\t" |
||
839 | :"=a"(ctrl) |
||
840 | :"a"(66),"b"(3)); |
||
841 | |||
842 | return ctrl; |
||
843 | }; |
||
844 | |||
845 | static inline |
||
846 | int get_keyboard_layout(int opt, char* buf) |
||
847 | /// 128 byte buffer |
||
848 | /// opt: 1 - normal, 2 - shifted, 3 - alted, or 9 - return language |
||
849 | { |
||
850 | uint32_t lang; |
||
851 | |||
852 | __asm__ __volatile__( |
||
853 | "int $0x40 \n\t" |
||
854 | :"=a"(lang) |
||
855 | :"a"(26),"b"(2), "c"(opt), "d"(buf)); |
||
856 | |||
857 | return lang; |
||
858 | }; |
||
859 | |||
860 | |||
861 | static inline |
||
862 | int font_size(int color) |
||
863 | /// decode font size in pixels from color as SysFn4 |
||
864 | /// returns (width, hight) |
||
865 | { |
||
866 | int font = color >> 24; |
||
867 | int font_multipl = (font & 7) + 1; |
||
868 | int width_sym, hight_sym; |
||
869 | |||
870 | if (font & 0x10) // 8x16 |
||
871 | { |
||
872 | width_sym = 8 * font_multipl; |
||
873 | hight_sym = 16 * font_multipl; |
||
874 | } else // 6x9 |
||
875 | { |
||
876 | width_sym = 6 * font_multipl; |
||
877 | hight_sym = 9 * font_multipl; |
||
878 | } |
||
879 | return hight_sym + (width_sym << 16); |
||
880 | } |
||
881 | |||
6429 | siemargl | 882 | /* |
883 | static inline char *getcwd(char *buf, size_t size) |
||
884 | { |
||
885 | int rc = get_current_folder(buf, size); |
||
886 | if (rc > size) |
||
887 | { |
||
888 | errno = ERANGE; |
||
889 | return 0; |
||
890 | } |
||
891 | else |
||
892 | return buf; |
||
893 | } |
||
894 | */ |
||
7172 | siemargl | 895 | /* not finished |
896 | void staticnum_draw(staticnum *st) |
||
897 | { |
||
898 | register uint32_t fmt; |
||
899 | if (st->width < 0) |
||
900 | fmt = (-st->width << 16); // leading zeros, decimal |
||
901 | else |
||
902 | fmt = (st->width << 16) | 0x80000000; // no leading zeros, decimal |
||
6429 | siemargl | 903 | |
7172 | siemargl | 904 | __asm__ __volatile__( |
905 | "int $0x40" |
||
906 | ::"a"(47), |
||
907 | "b"(fmt), |
||
908 | "c"(st->number), |
||
909 | "d"(st->start_xy), |
||
910 | "S"(st->color_flags), |
||
911 | "D"(st->bg_color) |
||
912 | :); |
||
913 | } |
||
6429 | siemargl | 914 | |
7172 | siemargl | 915 | */ |
916 | //////////// end section |
||
6429 | siemargl | 917 | |
7172 | siemargl | 918 | |
919 | |||
6429 | siemargl | 920 | //added nonstatic inline because incomfortabre stepping in in debugger |
921 | void __attribute__ ((noinline)) debug_board_write_str(const char* str); |
||
922 | void __attribute__ ((noinline)) debug_board_printf(const char *format,...); |
||
923 | |||
924 | /* copy body to only one project file |
||
925 | void __attribute__ ((noinline)) debug_board_write_str(const char* str){ |
||
926 | while(*str) |
||
927 | debug_board_write_byte(*str++); |
||
928 | } |
||
929 | |||
930 | void __attribute__ ((noinline)) debug_board_printf(const char *format,...) |
||
931 | { |
||
932 | va_list ap; |
||
933 | char log_board[300]; |
||
934 | |||
935 | va_start (ap, format); |
||
936 | vsnprintf(log_board, sizeof log_board, format, ap); |
||
937 | va_end(ap); |
||
938 | debug_board_write_str(log_board); |
||
939 | } |
||
7172 | siemargl | 940 | |
941 | __attribute__ ((noinline)) void trap(int n) |
||
942 | { |
||
943 | // nothing todo, just see n in debugger. use "bp trap" command |
||
944 | __asm__ __volatile__( |
||
945 | "nop" |
||
946 | : |
||
947 | :"a"(n)); |
||
948 | } |
||
949 | |||
6429 | siemargl | 950 | */ |
951 | |||
6441 | siemargl | 952 | |
953 | |||
954 | // TinyC don't support aliasing of static inline funcs |
||
955 | #ifndef __TINYC__ |
||
956 | static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw"))); |
||
957 | static inline void EndDraw(void) __attribute__ ((alias ("end_draw"))); |
||
958 | static inline void DrawWindow(int x, int y, int w, int h, const char *name, |
||
959 | color_t workcolor, uint32_t style) |
||
960 | __attribute__ ((alias ("sys_create_window"))); |
||
961 | static inline void DefineButton(void) __attribute__ ((alias ("define_button"))); |
||
962 | static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color) |
||
963 | __attribute__ ((alias ("draw_line"))); |
||
964 | static inline void DrawBar(int x, int y, int w, int h, color_t color) |
||
965 | __attribute__ ((alias ("draw_bar"))); |
||
966 | static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h) |
||
967 | __attribute__ ((alias ("draw_bitmap"))); |
||
968 | static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height"))); |
||
969 | static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos"))); |
||
970 | static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons"))); |
||
971 | static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels"))); |
||
972 | static inline uint32_t LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor"))); |
||
973 | static inline uint32_t SetCursor(uint32_t cursor) __attribute__ ((alias ("set_cursor"))); |
||
974 | static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor"))); |
||
975 | static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event"))); |
||
976 | static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc"))); |
||
977 | static inline int UserFree(void *mem) __attribute__ ((alias ("user_free"))); |
||
978 | static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc"))); |
||
979 | static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap"))); |
||
980 | static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file"))); |
||
981 | static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info"))); |
||
982 | #endif |
||
983 | |||
6429 | siemargl | 984 | #ifdef __cplusplus |
985 | } |
||
986 | #endif |
||
987 | |||
988 | |||
989 | #endif><>><>>><>><>><>><>16)|(y)) |
||
990 | |||
991 | |||
992 | |||
993 | |||
994 |