Subversion Repositories Kolibri OS

Rev

Rev 1810 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1810 Rev 2829
1
#include "kolibri.h"
1
#include "kolibri.h"
2
#include "string.h"
2
#include "string.h"
3
 
3
 
4
 
4
 
5
extern char KOL_PATH[256];
5
extern char KOL_PATH[256];
6
extern char KOL_PARAM[256];
6
extern char KOL_PARAM[256];
7
extern char KOL_DIR[256];
7
extern char KOL_DIR[256];
8
 
8
 
9
 
9
 
10
void kol_exit()
10
void kol_exit()
11
{
11
{
12
asm ("int $0x40"::"a"(-1));
12
asm volatile ("int $0x40"::"a"(-1));
13
}
13
}
14
 
14
 
15
 
15
 
16
void kol_sleep(unsigned d)
16
void kol_sleep(unsigned d)
17
{
17
{
18
asm ("int $0x40"::"a"(5), "b"(d));
18
asm volatile ("int $0x40"::"a"(5), "b"(d));
19
}
19
}
20
 
20
 
21
 
21
 
-
 
22
// define a window
-
 
23
// x, y - position; w, h - size; cs - color and style; c - caption; b - boder
22
void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
24
void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned cs, unsigned b, char *t)
23
{
25
{
24
asm ("nop"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
26
asm volatile ("int $0x40"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(cs), "D"(t), "S"(b) );
25
asm ("movl $0xffffff, %esi \n int $0x40");
-
 
26
}
27
}
27
 
28
 
28
 
29
 
29
void kol_wnd_move(unsigned x, unsigned y)
30
void kol_wnd_move(unsigned x, unsigned y)
30
{
31
{
31
asm ("nop"::"a"(67), "b"(x), "c"(y));
32
asm volatile ("int $0x40"::"a"(67), "b"(x), "c"(y), "d"(-1), "S"(-1));
32
asm ("movl $-1, %edx \n movl $-1, %esi \n int $0x40");
33
}
33
}
-
 
34
 
34
 
35
 
35
 
36
void kol_event_mask(unsigned e)
36
void kol_event_mask(unsigned e)
37
{
37
{
38
asm ("int $0x40"::"a"(40), "b"(e));
38
asm volatile ("int $0x40"::"a"(40), "b"(e));
39
}
39
}
40
 
40
 
41
 
41
 
42
unsigned kol_event_wait()
42
unsigned kol_event_wait() 
43
{
43
{
44
asm ("int $0x40"::"a"(10));
44
asm volatile ("int $0x40"::"a"(10));
45
}
45
}
46
 
46
 
47
 
47
 
48
unsigned kol_event_wait_time(unsigned time)
48
unsigned kol_event_wait_time(unsigned time)
49
{
49
{
50
asm ("int $0x40"::"a"(23), "b"(time));
50
asm volatile ("int $0x40"::"a"(23), "b"(time));
51
}
51
}
52
 
52
 
53
 
53
 
54
unsigned kol_event_check()
54
unsigned kol_event_check()
55
{
55
{
56
asm ("int $0x40"::"a"(11));
56
asm volatile ("int $0x40"::"a"(11));
57
}
57
}
58
 
58
 
59
 
59
 
60
void kol_paint_start()
60
void __attribute__((__always_inline__)) kol_paint_start()
61
{
61
{
62
asm ("int $0x40"::"a"(12), "b"(1));
62
asm volatile ("int $0x40"::"a"(12), "b"(1));
63
}
63
}
64
 
64
 
65
 
65
 
66
void kol_paint_end()
66
void __attribute__((__always_inline__)) kol_paint_end()
67
{
67
{
68
asm ("int $0x40"::"a"(12), "b"(2));
68
asm volatile ("int $0x40"::"a"(12), "b"(2));
69
}
69
}
70
 
70
 
71
 
71
 
72
void kol_paint_pixel(unsigned x, unsigned y, unsigned c)
72
void kol_paint_pixel(unsigned x, unsigned y, unsigned c)
73
{
73
{
74
asm ("int $0x40"::"a"(1), "b"(x), "c"(y), "d"(c));
74
asm volatile ("int $0x40"::"a"(1), "b"(x), "c"(y), "d"(c));
75
}
75
}
76
 
76
 
77
 
77
 
78
void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
78
void kol_paint_bar(unsigned x, unsigned y, unsigned w, unsigned h, unsigned c)
79
{
79
{
80
asm ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
80
asm volatile ("int $0x40"::"a"(13), "b"(x*65536+w), "c"(y*65536+h), "d"(c));
81
}
81
}
82
 
82
 
83
 
83
 
84
void kol_paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c)
84
void kol_paint_line(unsigned x1, unsigned y1, unsigned x2, unsigned y2, unsigned c)
85
{
85
{
86
asm ("int $0x40"::"a"(38), "b"(x1*65536+x2), "c"(y1*65536+y2), "d"(c));
86
asm volatile ("int $0x40"::"a"(38), "b"(x1*65536+x2), "c"(y1*65536+y2), "d"(c));
87
}
87
}
88
 
88
 
89
 
89
 
90
void kol_paint_string(unsigned x, unsigned y, char *s, unsigned c)
90
void kol_paint_string(unsigned x, unsigned y, char *s, unsigned c)
91
{
91
{
92
asm ("int $0x40"::"a"(4), "b"(x*65536+y), "c"(c), "d"(s));
92
asm volatile ("int $0x40"::"a"(4), "b"(x*65536+y), "c"(c), "d"(s));
93
}
93
}
94
 
94
 
95
 
95
 
96
void kol_paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
96
void kol_paint_image(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
97
{
97
{
98
asm ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(d));
98
asm volatile ("int $0x40"::"a"(7), "c"(w*65536+h), "d"(x*65536+y), "b"(d));
99
}
99
}
100
 
100
 
101
 
101
 
102
void kol_paint_image_pal(unsigned x, unsigned y, unsigned w, unsigned h, char *d, unsigned *palette)
102
void kol_paint_image_pal(unsigned x, unsigned y, unsigned w, unsigned h, char *d, unsigned *palette)
103
{
103
{
104
asm ("nop"::"c"(w*65536+h), "d"(x*65536+y), "b"(d));
104
asm volatile ("int $0x40"::"a"(65), "b"(d), "c"(w*65536+h), "d"(x*65536+y), "D"(palette), "S"(8));
105
asm ("nop"::"a"(palette));
105
}
106
asm ("movl %eax, %edi");
-
 
107
asm ("xor %eax, %eax");
-
 
108
asm ("movl %eax, %ebp");
-
 
109
asm ("pushl $8");
-
 
110
asm ("popl %esi");
-
 
111
asm ("int $0x40"::"a"(65));
-
 
112
}
-
 
113
 
106
 
114
 
107
 
115
unsigned kol_key_get()
108
unsigned kol_key_get()
116
{
109
{
117
asm ("int $0x40"::"a"(2));
110
asm volatile ("int $0x40"::"a"(2));
118
}
111
}
119
 
112
 
120
 
113
 
121
unsigned kol_key_control()
114
unsigned kol_key_control()
122
{
115
{
123
asm ("int $0x40"::"a"(66), "b"(3));
116
asm volatile ("int $0x40"::"a"(66), "b"(3));
124
}
117
}
125
 
118
 
126
 
119
 
127
void kol_key_lang_set(unsigned lang)
120
void kol_key_lang_set(unsigned lang)
128
{
121
{
129
asm ("int $0x40"::"a"(21), "b"(2), "c"(9), "d"(lang));
122
asm volatile ("int $0x40"::"a"(21), "b"(2), "c"(9), "d"(lang));
130
}
123
}
131
 
124
 
132
 
125
 
133
unsigned kol_key_lang_get()
126
unsigned kol_key_lang_get()
134
{
127
{
135
asm ("int $0x40"::"a"(26), "b"(2), "c"(9));
128
asm volatile ("int $0x40"::"a"(26), "b"(2), "c"(9));
136
}
129
}
137
 
130
 
138
 
131
 
139
void kol_key_mode_set(unsigned mode)
132
void kol_key_mode_set(unsigned mode)
140
{
133
{
141
asm ("int $0x40"::"a"(66), "b"(1), "c"(mode));
134
asm volatile ("int $0x40"::"a"(66), "b"(1), "c"(mode));
142
}
135
}
143
 
136
 
144
 
137
 
145
unsigned kol_key_mode_get()
138
unsigned kol_key_mode_get()
146
{
139
{
147
asm ("int $0x40"::"a"(66), "b"(2));
140
asm volatile ("int $0x40"::"a"(66), "b"(2));
148
}
141
}
149
 
142
 
150
 
143
 
151
unsigned kol_btn_get()
144
unsigned kol_btn_get()
152
{
145
{
153
asm ("int $0x40"::"a"(17));
146
asm volatile ("int $0x40"::"a"(17));
154
}
147
}
155
 
148
 
156
 
149
 
157
void kol_btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c)
150
void kol_btn_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned d, unsigned c)
158
{
151
{
159
asm ("nop"::"b"(x*65536+w), "c"(y*65536+h), "d"(d));
152
asm volatile ("int $0x40"::"a"(8), "b"(x*65536+w), "c"(y*65536+h), "d"(d), "S"(c));
160
asm ("nop"::"a"(c));
153
}
161
asm ("movl %eax, %esi");
-
 
162
asm ("int $0x40"::"a"(8));
-
 
163
}
-
 
164
 
154
 
165
 
155
 
166
void kol_btn_type(unsigned t)
156
void kol_btn_type(unsigned t)
167
{
157
{
168
asm ("int $0x40"::"a"(48), "b"(1), "c"(t));
158
asm volatile ("int $0x40"::"a"(48), "b"(1), "c"(t));
169
}
159
}
170
 
160
 
171
 
161
 
172
void kol_wnd_caption(char *s)
162
void kol_wnd_caption(char *s)
173
{
163
{
174
asm ("int $0x40"::"a"(71), "b"(1), "c"(s));
164
asm volatile ("int $0x40"::"a"(71), "b"(1), "c"(s));
175
}
165
}
176
 
166
 
177
 
167
 
178
unsigned kol_mouse_pos()
168
unsigned kol_mouse_pos()
179
{
169
{
180
asm ("int $0x40"::"a"(37), "b"(0));
170
asm volatile ("int $0x40"::"a"(37), "b"(0));
181
}
171
}
182
 
172
 
183
 
173
 
184
unsigned kol_mouse_posw()
174
unsigned kol_mouse_posw()
185
{
175
{
186
asm ("int $0x40"::"a"(37), "b"(1));
176
asm volatile ("int $0x40"::"a"(37), "b"(1));
187
}
177
}
188
 
178
 
189
 
179
 
190
unsigned kol_mouse_btn()
180
unsigned kol_mouse_btn()
191
{
181
{
192
asm ("int $0x40"::"a"(37), "b"(2));
182
asm volatile ("int $0x40"::"a"(37), "b"(2));
193
}
183
}
194
 
184
 
195
 
185
 
196
void kol_board_putc(char c)
186
void kol_board_putc(char c)
197
{
187
{
198
asm ("int $0x40"::"a"(63), "b"(1), "c"(c));
188
asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c));
199
}
189
}
200
 
190
 
201
 
191
 
202
void kol_board_puts(char *s)
192
void kol_board_puts(char *s)
203
{
193
{
204
unsigned i;
194
unsigned i;
205
i = 0;
195
i = 0;
206
while (*(s+i))
196
while (*(s+i))
207
	{
197
	{
208
	asm ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
198
	asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(*(s+i)));
209
	i++;
199
	i++;
210
	}
200
	}
211
}
201
}
212
 
202
 
213
 
203
 
214
void kol_board_puti(int n)
204
void kol_board_puti(int n)
215
{
205
{
216
char c;
206
char c;
217
int i = 0;
207
 
-
 
208
if ( n > 1 )
218
do 
209
	kol_board_puti(n / 10);
219
	{
210
 
220
	c = n % 10 + '0';
211
c = n % 10 + '0';
221
	asm ("int $0x40"::"a"(63), "b"(1), "c"(c));
212
asm volatile ("int $0x40"::"a"(63), "b"(1), "c"(c));
222
	i++;
213
 
223
	}
-
 
224
	while ((n /= 10) > 0);
214
}
225
}
-
 
226
 
215
 
227
 
216
 
228
int kol_file_70(kol_struct70 *k)
217
int kol_file_70(kol_struct70 *k)
229
{
218
{
230
asm ("int $0x40"::"a"(70), "b"(k));
219
asm volatile ("int $0x40"::"a"(70), "b"(k));
231
}
220
}
232
 
221
 
233
 
222
 
234
kol_struct_import* kol_cofflib_load(char *name)
223
kol_struct_import* kol_cofflib_load(char *name)
235
{
224
{
236
asm ("int $0x40"::"a"(68), "b"(19), "c"(name));
225
asm volatile ("int $0x40"::"a"(68), "b"(19), "c"(name));
237
}
226
}
238
 
227
 
239
 
228
 
240
void* kol_cofflib_procload (kol_struct_import *imp, char *name)
229
void* kol_cofflib_procload (kol_struct_import *imp, char *name)
241
{
230
{
242
int i;
231
int i;
243
for (i=0;;i++)
232
for (i=0;;i++)
244
	if ( NULL == ((imp+i) -> name))
233
	if ( NULL == ((imp+i) -> name))
245
		break;
234
		break;
246
	else
235
	else
247
		if ( 0 == strcmp(name, (imp+i)->name) )
236
		if ( 0 == strcmp(name, (imp+i)->name) )
248
			return (imp+i)->data;
237
			return (imp+i)->data;
249
return NULL;
238
return NULL;
250
}
239
}
251
 
240
 
252
 
241
 
253
unsigned kol_cofflib_procnum (kol_struct_import *imp)
242
unsigned kol_cofflib_procnum (kol_struct_import *imp)
254
{
243
{
255
unsigned i, n;
244
unsigned i, n;
256
 
245
 
257
for (i=n=0;;i++)
246
for (i=n=0;;i++)
258
	if ( NULL == ((imp+i) -> name))
247
	if ( NULL == ((imp+i) -> name))
259
		break;
248
		break;
260
	else
249
	else
261
		n++;
250
		n++;
262
 
251
 
263
return n;
252
return n;
264
}
253
}
265
 
254
 
266
 
255
 
267
void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n)
256
void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n)
268
{
257
{
269
unsigned i;
258
unsigned i;
270
*name = 0;
259
*name = 0;
271
 
260
 
272
for (i=0;;i++)
261
for (i=0;;i++)
273
	if ( NULL == ((imp+i) -> name))
262
	if ( NULL == ((imp+i) -> name))
274
		break;
263
		break;
275
	else
264
	else
276
		if ( i == n )
265
		if ( i == n )
277
			{
266
			{
278
			strcpy(name, ((imp+i)->name));
267
			strcpy(name, ((imp+i)->name));
279
			break;
268
			break;
280
			}
269
			}
281
 
270
 
282
}
271
}
283
 
272
 
284
 
273
 
285
unsigned kol_system_cpufreq()
274
unsigned kol_system_cpufreq()
286
{
275
{
287
asm ("int $0x40"::"a"(18), "b"(5));
276
asm volatile ("int $0x40"::"a"(18), "b"(5));
288
}
277
}
289
 
278
 
290
 
279
 
291
unsigned kol_system_mem()
280
unsigned kol_system_mem()
292
{
281
{
293
asm ("int $0x40"::"a"(18), "b"(17));
282
asm volatile ("int $0x40"::"a"(18), "b"(17));
294
}
283
}
295
 
284
 
296
 
285
 
297
unsigned kol_system_memfree()
286
unsigned kol_system_memfree()
298
{
287
{
299
asm ("int $0x40"::"a"(18), "b"(16));
288
asm volatile ("int $0x40"::"a"(18), "b"(16));
300
}
289
}
301
 
290
 
302
 
291
 
303
unsigned kol_system_time_get()
292
unsigned kol_system_time_get()
304
{
293
{
305
asm ("int $0x40"::"a"(3));
294
asm volatile ("int $0x40"::"a"(3));
306
}
295
}
307
 
296
 
308
 
297
 
309
unsigned kol_system_date_get()
298
unsigned kol_system_date_get()
310
{
299
{
311
asm ("int $0x40"::"a"(29));
300
asm volatile ("int $0x40"::"a"(29));
312
}
301
}
313
 
302
 
314
 
303
 
315
unsigned kol_system_end(unsigned param)
304
unsigned kol_system_end(unsigned param)
316
{
305
{
317
asm ("int $0x40"::"a"(18), "b"(9), "c"(param));
306
asm volatile ("int $0x40"::"a"(18), "b"(9), "c"(param));
318
}
307
}
319
 
308
 
320
 
309
 
321
void kol_path_file2dir(char *dir, char *fname)
310
void kol_path_file2dir(char *dir, char *fname)
322
{
311
{
323
unsigned i;
312
unsigned i;
324
strcpy (dir, fname);
313
strcpy (dir, fname);
325
for ( i = strlen(dir);; --i)
314
for ( i = strlen(dir);; --i)
326
	if ( '/' == dir[i])
315
	if ( '/' == dir[i])
327
		{
316
		{
328
		dir[i] = '\0';
317
		dir[i] = '\0';
329
		return;
318
		return;
330
		}
319
		}
331
}
320
}
332
 
321
 
333
 
322
 
334
void kol_path_full(char *full, char *fname)
323
void kol_path_full(char *full, char *fname)
335
{
324
{
336
char temp[256];
325
char temp[256];
337
 
326
 
338
switch (*fname)
327
switch (*fname)
339
{
328
	{
340
 
329
 
341
case '/':
330
	case '/':
342
	strncpy(temp, fname+1, 2);
331
		strncpy(temp, fname+1, 2);
343
	temp[2]=0;
332
		temp[2]=0;
344
	if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) )
333
		if ( (!strcmp("rd", temp)) || (!strcmp("hd", temp)) || (!strcmp("cd", temp)) )
345
		strcpy (full, fname);
334
			strcpy (full, fname);
346
	break;
335
		break;
347
 
336
 
348
case '.':
337
	case '.':
349
	break;
338
		break;
350
 
339
 
351
default:
340
	default:
352
	break;
341
		break;
353
 
342
 
354
};
343
	};
355
 
344
 
356
}
345
}
357
 
346
 
358
 
347
 
359
 
348
 
360
void kol_screen_wait_rr()
349
void __attribute__((__always_inline__)) kol_screen_wait_rr()
361
{
350
{
362
asm ("int $0x40"::"a"(18), "b"(14));
351
asm volatile ("int $0x40"::"a"(18), "b"(14));
363
}
352
}
364
 
353
 
365
 
354
 
366
 
355
 
367
void kol_screen_get_size(unsigned *w, unsigned *h)
356
void kol_screen_get_size(unsigned *w, unsigned *h)
368
{
357
{
369
unsigned size;
358
unsigned size;
370
asm ("int $0x40":"=a"(size):"a"(14));
359
asm volatile ("int $0x40":"=a"(size):"a"(14));
371
*w = size / 65536;
360
*w = size / 65536;
372
*h = size % 65536;
361
*h = size % 65536;
373
}
362
}
374
 
363
 
375
 
364
 
376
 
365
 
377
unsigned kol_skin_height()
366
unsigned kol_skin_height()
378
{
367
{
379
asm ("int $0x40"::"a"(48), "b"(4));
368
asm volatile ("int $0x40"::"a"(48), "b"(4));
380
}
369
}
381
 
370
 
382
 
371
 
383
unsigned kol_thread_start(unsigned start, unsigned stack)
372
unsigned kol_thread_start(unsigned start, unsigned stack)
384
{
373
{
385
asm ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack));
374
asm volatile ("int $0x40"::"a"(51), "b"(1), "c"(start), "d"(stack));
386
}
375
}
387
 
376
 
388
 
377
 
389
unsigned kol_time_tick()
378
unsigned kol_time_tick()
390
{
379
{
391
asm ("int $0x40"::"a"(26), "b"(9));
380
asm volatile ("int $0x40"::"a"(26), "b"(9));
392
}
381
}
393
 
382
 
394
 
383
 
395
unsigned kol_sound_speaker(char data[])
384
unsigned kol_sound_speaker(char data[])
396
{
385
{
397
asm ("movl %0, %%esi"::"a"(data));
386
asm volatile ("movl %0, %%esi"::"a"(data));
398
asm ("int $0x40"::"a"(55), "b"(55));
387
asm volatile ("int $0x40"::"a"(55), "b"(55));
399
}
388
}
400
 
389
 
401
 
390
 
402
unsigned kol_process_info(unsigned slot, char buf1k[])
391
unsigned kol_process_info(unsigned slot, char buf1k[])
403
{
392
{
404
asm ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot));
393
asm volatile ("int $0x40"::"a"(9), "b"(buf1k), "c"(slot));
405
}
394
}
406
 
395
 
407
 
396
 
408
int kol_process_kill_pid(unsigned process)
397
int kol_process_kill_pid(unsigned process)
409
{
398
{
410
asm ("int $0x40"::"a"(18), "b"(18), "c"(process));
399
asm volatile ("int $0x40"::"a"(18), "b"(18), "c"(process));
411
}
400
}
412
 
401
 
413
int kol_kill_process(unsigned process)
402
int kol_kill_process(unsigned process)
414
{
403
{
415
asm ("int $0x40"::"a"(18), "b"(2), "c"(process));
404
asm volatile ("int $0x40"::"a"(18), "b"(2), "c"(process));
416
}
405
}
417
 
406
 
418
void kol_get_kernel_ver(char buff16b[])
407
void kol_get_kernel_ver(char buff16b[])
419
{
408
{
420
asm ("int $0x40"::"a"(18), "b"(13), "c"(buff16b));
409
asm volatile ("int $0x40"::"a"(18), "b"(13), "c"(buff16b));
421
}
410
}
-
 
411
 
-
 
412
int kol_buffer_open(char name[], int mode, int size, char **buf)
-
 
413
{
-
 
414
int error;
-
 
415
asm volatile ("int $0x40":"=a"(*buf), "=d"(error):"a"(68), "b"(22), "c"(name), "d"(size), "S"(mode));
-
 
416
return error;
-
 
417
}
-
 
418
 
-
 
419
void kol_buffer_close(char name[])
-
 
420
{
-
 
421
asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(name));
-
 
422
}
422
423