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