Subversion Repositories Kolibri OS

Rev

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