Rev 8436 | Rev 8452 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7475 | leency | 1 | #include "kolibri.h" |
2 | #include "string.h" |
||
8436 | maxcodehac | 3 | #include |
7475 | leency | 4 | |
5 | |||
6 | extern char KOL_PATH[256]; |
||
7 | extern char KOL_PARAM[256]; |
||
8 | extern char KOL_DIR[256]; |
||
9 | |||
10 | |||
11 | void kol_exit() |
||
12 | { |
||
13 | asm volatile ("int $0x40"::"a"(-1)); |
||
14 | } |
||
15 | |||
16 | |||
17 | void kol_sleep(unsigned d) |
||
18 | { |
||
19 | asm volatile ("int $0x40"::"a"(5), "b"(d)); |
||
20 | } |
||
21 | |||
22 | |||
23 | // define a window |
||
24 | // x, y - position; w, h - size; cs - color and style; c - caption; b - boder |
||
25 | void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned cs, unsigned b, char *t) |
||
26 | { |
||
27 | asm volatile ("int $0x40"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(cs), "D"(t), "S"(b) ); |
||
28 | } |
||
29 | |||
30 | |||
31 | void kol_wnd_move(unsigned x, unsigned y) |
||
32 | { |
||
33 | asm volatile ("int $0x40"::"a"(67), "b"(x), "c"(y), "d"(-1), "S"(-1)); |
||
34 | } |
||
35 | |||
36 | |||
37 | void kol_event_mask(unsigned e) |
||
38 | { |
||
39 | asm volatile ("int $0x40"::"a"(40), "b"(e)); |
||
40 | } |
||
41 | |||
42 | |||
43 | unsigned kol_event_wait() |
||
44 | { |
||
45 | asm volatile ("int $0x40"::"a"(10)); |
||
46 | } |
||
47 | |||
48 | |||
49 | unsigned kol_event_wait_time(unsigned time) |
||
50 | { |
||
51 | asm volatile ("int $0x40"::"a"(23), "b"(time)); |
||
52 | } |
||
53 | |||
54 | |||
55 | unsigned kol_event_check() |
||
56 | { |
||
57 | asm volatile ("int $0x40"::"a"(11)); |
||
58 | } |
||
59 | |||
60 | |||
61 | inline void __attribute__((__always_inline__)) kol_paint_start() |
||
62 | { |
||
63 | asm volatile ("int $0x40"::"a"(12), "b"(1)); |
||
64 | } |
||
65 | |||
66 | |||
67 | inline void __attribute__((__always_inline__)) kol_paint_end() |
||
68 | { |
||
69 | asm volatile ("int $0x40"::"a"(12), "b"(2)); |
||
70 | } |
||
71 | |||
72 | |||
73 | void kol_paint_pixel(unsigned x, unsigned y, unsigned c) |
||
74 | { |
||
75 | asm volatile ("int $0x40"::"a"(1), "b"(x), "c"(y), "d"(c)); |
||
76 | } |
||
77 | |||
78 | |||
79 | void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c) |
||
80 | { |
||
81 | asm volatile ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c)); |
||
82 | } |
||
83 | |||
84 | |||
85 | void kol_paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c) |
||
86 | { |
||
87 | asm volatile ("int $0x40"::"a"(38), "b"(x1*65536+x2), "c"(y1*65536+y2), "d"(c)); |
||
88 | } |
||
89 | |||
90 | |||
91 | void kol_paint_string(unsigned x, unsigned y, char *s, unsigned c) |
||
92 | { |
||
93 | asm volatile ("int $0x40"::"a"(4), "b"(x*65536+y), "c"(c), "d"(s)); |
||
94 | } |
||
95 | |||
96 | |||
97 | void kol_paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d) |
||
98 | { |
||
99 | asm volatile ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(d)); |
||
100 | } |
||
101 | |||
102 | |||
103 | void kol_paint_image_24(unsigned x, unsigned y, unsigned w, unsigned h, char *d) |
||
104 | { |
||
105 | asm volatile ("int $0x40"::"a"(65), "b"(d), "c"(w*65536+h), "d"(x*65536+y), "S"(32)); |
||
106 | } |
||
107 | |||
108 | |||
109 | unsigned kol_key_get() |
||
110 | { |
||
111 | asm volatile ("int $0x40"::"a"(2)); |
||
112 | } |
||
113 | |||
114 | |||
115 | unsigned kol_key_control() |
||
116 | { |
||
117 | asm volatile ("int $0x40"::"a"(66), "b"(3)); |
||
118 | } |
||
119 | |||
120 | |||
121 | void kol_key_lang_set(unsigned lang) |
||
122 | { |
||
123 | asm volatile ("int $0x40"::"a"(21), "b"(2), "c"(9), "d"(lang)); |
||
124 | } |
||
125 | |||
126 | |||
127 | unsigned kol_key_lang_get() |
||
128 | { |
||
129 | asm volatile ("int $0x40"::"a"(26), "b"(2), "c"(9)); |
||
130 | } |
||
131 | |||
132 | |||
133 | void kol_key_mode_set(unsigned mode) |
||
134 | { |
||
135 | asm volatile ("int $0x40"::"a"(66), "b"(1), "c"(mode)); |
||
136 | } |
||
137 | |||
138 | |||
139 | unsigned kol_key_mode_get() |
||
140 | { |
||
141 | asm volatile ("int $0x40"::"a"(66), "b"(2)); |
||
142 | } |
||
143 | |||
144 | |||
145 | unsigned kol_btn_get() |
||
146 | { |
||
147 | asm volatile ("int $0x40"::"a"(17)); |
||
148 | } |
||
149 | |||
150 | |||
151 | void kol_btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c) |
||
152 | { |
||
153 | asm volatile ("int $0x40"::"a"(8), "b"(x*65536+w), "c"(y*65536+h), "d"(d), "S"(c)); |
||
154 | } |
||
155 | |||
156 | |||
157 | void kol_btn_type(unsigned t) |
||
158 | { |
||
159 | asm volatile ("int $0x40"::"a"(48), "b"(1), "c"(t)); |
||
160 | } |
||
161 | |||
162 | |||
163 | void kol_wnd_caption(char *s) |
||
164 | { |
||
165 | asm volatile ("int $0x40"::"a"(71), "b"(1), "c"(s)); |
||
166 | } |
||
167 | |||
168 | |||
169 | unsigned kol_mouse_pos() |
||
170 | { |
||
171 | asm volatile ("int $0x40"::"a"(37), "b"(0)); |
||
172 | } |
||
173 | |||
174 | |||
175 | unsigned kol_mouse_posw() |
||
176 | { |
||
177 | asm volatile ("int $0x40"::"a"(37), "b"(1)); |
||
178 | } |
||
179 | |||
180 | |||
181 | unsigned kol_mouse_btn() |
||
182 | { |
||
183 | asm volatile ("int $0x40"::"a"(37), "b"(2)); |
||
184 | } |
||
185 | |||
186 | |||
187 | void kol_board_putc(char c) |
||
188 | { |
||
189 | asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c)); |
||
190 | } |
||
191 | |||
192 | |||
193 | void kol_board_puts(char *s) |
||
194 | { |
||
195 | unsigned i; |
||
196 | i = 0; |
||
197 | while (*(s+i)) |
||
198 | { |
||
199 | asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i))); |
||
200 | i++; |
||
201 | } |
||
202 | } |
||
203 | |||
204 | |||
205 | void kol_board_puti(int n) |
||
206 | { |
||
207 | char c; |
||
208 | |||
209 | if ( n > 1 ) |
||
210 | kol_board_puti(n / 10); |
||
211 | |||
212 | c = n % 10 + '0'; |
||
213 | asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c)); |
||
214 | |||
215 | } |
||
216 | |||
217 | |||
218 | int kol_file_70(kol_struct70 *k) |
||
219 | { |
||
220 | asm volatile ("int $0x40"::"a"(70), "b"(k)); |
||
221 | } |
||
222 | |||
223 | |||
224 | kol_struct_import* kol_cofflib_load(char *name) |
||
225 | { |
||
226 | asm volatile ("int $0x40"::"a"(68), "b"(19), "c"(name)); |
||
227 | } |
||
228 | |||
229 | |||
230 | void* kol_cofflib_procload (kol_struct_import *imp, char *name) |
||
231 | { |
||
232 | int i; |
||
233 | for (i=0;;i++) |
||
234 | if ( NULL == ((imp+i) -> name)) |
||
235 | break; |
||
236 | else |
||
237 | if ( 0 == strcmp(name, (imp+i)->name) ) |
||
238 | return (imp+i)->data; |
||
239 | return NULL; |
||
240 | } |
||
241 | |||
242 | |||
243 | unsigned kol_cofflib_procnum (kol_struct_import *imp) |
||
244 | { |
||
245 | unsigned i, n; |
||
246 | |||
247 | for (i=n=0;;i++) |
||
248 | if ( NULL == ((imp+i) -> name)) |
||
249 | break; |
||
250 | else |
||
251 | n++; |
||
252 | |||
253 | return n; |
||
254 | } |
||
255 | |||
256 | |||
257 | void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n) |
||
258 | { |
||
259 | unsigned i; |
||
260 | *name = 0; |
||
261 | |||
262 | for (i=0;;i++) |
||
263 | if ( NULL == ((imp+i) -> name)) |
||
264 | break; |
||
265 | else |
||
266 | if ( i == n ) |
||
267 | { |
||
268 | strcpy(name, ((imp+i)->name)); |
||
269 | break; |
||
270 | } |
||
271 | |||
272 | } |
||
273 | |||
274 | |||
275 | unsigned kol_system_cpufreq() |
||
276 | { |
||
277 | asm volatile ("int $0x40"::"a"(18), "b"(5)); |
||
278 | } |
||
279 | |||
280 | |||
281 | unsigned kol_system_mem() |
||
282 | { |
||
283 | asm volatile ("int $0x40"::"a"(18), "b"(17)); |
||
284 | } |
||
285 | |||
286 | |||
287 | unsigned kol_system_memfree() |
||
288 | { |
||
289 | asm volatile ("int $0x40"::"a"(18), "b"(16)); |
||
290 | } |
||
291 | |||
292 | |||
293 | unsigned kol_system_time_get() |
||
294 | { |
||
295 | asm volatile ("int $0x40"::"a"(3)); |
||
296 | } |
||
297 | |||
298 | |||
299 | unsigned kol_system_date_get() |
||
300 | { |
||
301 | asm volatile ("int $0x40"::"a"(29)); |
||
302 | } |
||
303 | |||
304 | |||
305 | unsigned kol_system_end(unsigned param) |
||
306 | { |
||
307 | asm volatile ("int $0x40"::"a"(18), "b"(9), "c"(param)); |
||
308 | } |
||
309 | |||
310 | |||
311 | void kol_path_file2dir(char *dir, char *fname) |
||
312 | { |
||
313 | unsigned i; |
||
314 | strcpy (dir, fname); |
||
315 | for ( i = strlen(dir);; --i) |
||
316 | if ( '/' == dir[i]) |
||
317 | { |
||
318 | dir[i] = '\0'; |
||
319 | return; |
||
320 | } |
||
321 | } |
||
322 | |||
323 | |||
324 | void kol_path_full(char *full, char *fname) |
||
325 | { |
||
326 | char temp[256]; |
||
327 | |||
328 | switch (*fname) |
||
329 | { |
||
330 | |||
331 | case '/': |
||
332 | strncpy(temp, fname+1, 2); |
||
333 | temp[2]=0; |
||
334 | if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) ) |
||
335 | strcpy (full, fname); |
||
336 | break; |
||
337 | |||
338 | case '.': |
||
339 | break; |
||
340 | |||
341 | default: |
||
342 | break; |
||
343 | |||
344 | }; |
||
345 | |||
346 | } |
||
347 | |||
348 | |||
349 | |||
350 | inline void __attribute__((__always_inline__)) kol_screen_wait_rr() |
||
351 | { |
||
352 | asm volatile ("int $0x40"::"a"(18), "b"(14)); |
||
353 | } |
||
354 | |||
355 | |||
356 | |||
357 | void kol_screen_get_size(unsigned *w, unsigned *h) |
||
358 | { |
||
359 | unsigned size; |
||
360 | asm volatile ("int $0x40":"=a"(size):"a"(14)); |
||
361 | *w = size / 65536; |
||
362 | *h = size % 65536; |
||
363 | } |
||
364 | |||
365 | |||
366 | |||
367 | unsigned kol_skin_height() |
||
368 | { |
||
369 | asm volatile ("int $0x40"::"a"(48), "b"(4)); |
||
370 | } |
||
371 | |||
372 | |||
373 | unsigned kol_thread_start(unsigned start, unsigned stack) |
||
374 | { |
||
375 | asm volatile ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack)); |
||
376 | } |
||
377 | |||
378 | |||
379 | unsigned kol_time_tick() |
||
380 | { |
||
381 | asm volatile ("int $0x40"::"a"(26), "b"(9)); |
||
382 | } |
||
383 | |||
384 | |||
385 | unsigned kol_sound_speaker(char data[]) |
||
386 | { |
||
387 | asm volatile ("movl %0, %%esi"::"a"(data)); |
||
388 | asm volatile ("int $0x40"::"a"(55), "b"(55)); |
||
389 | } |
||
390 | |||
391 | |||
392 | unsigned kol_process_info(unsigned slot, char buf1k[]) |
||
393 | { |
||
394 | asm volatile ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot)); |
||
395 | } |
||
396 | |||
397 | |||
398 | int kol_process_kill_pid(unsigned process) |
||
399 | { |
||
400 | asm volatile ("int $0x40"::"a"(18), "b"(18), "c"(process)); |
||
401 | } |
||
402 | |||
403 | int kol_kill_process(unsigned process) |
||
404 | { |
||
405 | asm volatile ("int $0x40"::"a"(18), "b"(2), "c"(process)); |
||
406 | } |
||
407 | |||
408 | void kol_get_kernel_ver(char buff16b[]) |
||
409 | { |
||
410 | asm volatile ("int $0x40"::"a"(18), "b"(13), "c"(buff16b)); |
||
411 | } |
||
412 | |||
413 | int kol_buffer_open(char name[], int mode, int size, char **buf) |
||
414 | { |
||
415 | int error; |
||
416 | asm volatile ("int $0x40":"=a"(*buf), "=d"(error):"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode)); |
||
417 | return error; |
||
418 | } |
||
419 | |||
420 | void kol_buffer_close(char name[]) |
||
421 | { |
||
422 | asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(name)); |
||
423 | } |
||
424 | |||
425 | int kol_clip_num() |
||
426 | { |
||
427 | asm volatile ("int $0x40"::"a"(54), "b"(0)); |
||
428 | } |
||
429 | |||
430 | char* kol_clip_get(int n) |
||
431 | { |
||
432 | asm volatile ("int $0x40"::"a"(54), "b"(1), "c"(n)); |
||
433 | } |
||
434 | |||
435 | int kol_clip_set(int n, char buffer[]) |
||
436 | { |
||
437 | asm volatile ("int $0x40"::"a"(54), "b"(2), "c"(n), "d"(buffer)); |
||
438 | } |
||
439 | |||
440 | int kos_random(int num) |
||
441 | { |
||
442 | srand(kol_time_tick()); |
||
443 | return rand() % num; |
||
444 | } |
||
445 | |||
7624 | leency | 446 | int kos_get_mouse_wheels(void) |
447 | { |
||
448 | int val; |
||
449 | asm ("int $0x40":"=a"(val):"a"(37),"b"(7)); |
||
450 | return val; |
||
451 | }; |
||
452 | |||
453 | |||
454 | struct blit_call |
||
455 | { |
||
456 | int dstx; |
||
457 | int dsty; |
||
458 | int w; |
||
459 | int h; |
||
460 | |||
461 | int srcx; |
||
462 | int srcy; |
||
463 | int srcw; |
||
464 | int srch; |
||
465 | |||
466 | unsigned char *d; |
||
467 | int stride; |
||
468 | }; |
||
469 | |||
470 | void kos_blit(int dstx, int dsty, int w, int h, int srcx, |
||
471 | int srcy,int srcw, int srch, int stride, char *d) |
||
472 | { |
||
8436 | maxcodehac | 473 | volatile struct blit_call image; |
7624 | leency | 474 | image.dstx=dstx; |
475 | image.dsty=dsty; |
||
476 | image.w=w; |
||
477 | image.h=h; |
||
478 | image.srcx=srcx; |
||
479 | image.srcy=srcy; |
||
480 | image.srcw=srcw; |
||
481 | image.srch=srch; |
||
482 | image.stride=stride; |
||
483 | image.d=d; |
||
8436 | maxcodehac | 484 | asm("int $0x40"::"a"(73),"b"(0),"c"(&image)); |
485 | |||
7624 | leency | 486 | } |
487 | |||
8446 | maxcodehac | 488 | void kos_move_window(int posx, int posy, int sizex, int sizey) |
489 | { |
||
490 | __asm__ __volatile__( |
||
491 | "int $0x40" |
||
492 | ::"a"(67), |
||
493 | "b"(posx), |
||
494 | "c"(posy), |
||
495 | "d"(sizex), |
||
496 | "S"(sizey)); |
||
497 | }; |
||
498 | |||
499 | void kos_text(int x, int y, int color, const char* text, int len) |
||
500 | { |
||
501 | asm volatile ("int $0x40"::"a"(4),"b"((x<<16) | y),"c"(color),"d"((unsigned long)text),"S"(len)); |
||
502 | }; |
||
503 | |||
504 | void kos_screen_max(int* x, int* y) |
||
505 | { |
||
506 | unsigned long v; |
||
507 | __asm__ __volatile__( |
||
508 | "int $0x40" |
||
509 | :"=a"(v) |
||
510 | :"a"(14)); |
||
511 | |||
512 | if(x) *x = v >> 16; |
||
513 | if(y) *y = v & 0xFFFF; |
||
514 | }; |
||
515 | |||
516 | int kol_get_key() |
||
517 | { |
||
518 | unsigned short __ret; |
||
519 | asm volatile("int $0x40":"=a"(__ret):"0"(2)); |
||
520 | if(!(__ret & 0xFF)) return (__ret>>8)&0xFF; else return 0; |
||
521 | }16)><16)> |