Rev 7504 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
990 | barsuk | 1 | #include "kosSyst.h" |
2 | #include "func.h" |
||
3 | #include |
||
4 | |||
5 | #define atexitBufferSize 32 |
||
6 | |||
1764 | clevermous | 7 | // Autobuild uses FASM method for exe->kos, |
8 | // MENUET01 header should be present in EXE. |
||
9 | #ifdef AUTOBUILD |
||
10 | char kosExePath[1024]; |
||
11 | char exeStack[16384]; |
||
12 | // must be alphabetically first in the image |
||
13 | #pragma data_seg(".1seg") |
||
14 | extern "C" struct |
||
15 | { |
||
16 | char header[8]; |
||
17 | int headerver; |
||
18 | void* entry; |
||
19 | void* i_end; |
||
20 | void* memsize; |
||
21 | void* stack; |
||
22 | void* params; |
||
23 | void* icon; |
||
24 | } header = { |
||
25 | {'M', 'E', 'N', 'U', 'E', 'T', '0', '1'}, |
||
26 | 1, |
||
27 | &crtStartUp, |
||
28 | 0, // filled by doexe2.asm |
||
29 | 0, // filled by doexe2.asm |
||
30 | exeStack + sizeof(exeStack), |
||
31 | NULL, |
||
32 | kosExePath |
||
33 | }; |
||
34 | #pragma data_seg() |
||
35 | #else |
||
36 | char *kosExePath = NULL; |
||
37 | #endif |
||
990 | barsuk | 38 | |
39 | char pureCallMessage[] = "PURE function call!"; |
||
40 | |||
41 | // |
||
42 | void (__cdecl *atExitList[atexitBufferSize])(); |
||
43 | int atExitFnNum = 0; |
||
44 | // |
||
45 | int __cdecl atexit( void (__cdecl *func )( void )) |
||
46 | { |
||
47 | // |
||
48 | if ( atExitFnNum < atexitBufferSize ) |
||
49 | { |
||
50 | // |
||
51 | atExitList[atExitFnNum++] = func; |
||
52 | return 0; |
||
53 | } |
||
54 | else |
||
55 | { |
||
56 | return 1; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | |||
61 | // |
||
62 | Dword RandomSeed = 1; |
||
63 | // |
||
64 | void rtlSrand( Dword seed ) |
||
65 | { |
||
66 | RandomSeed = seed; |
||
67 | } |
||
68 | // |
||
69 | Dword rtlRand( void ) |
||
70 | { |
||
71 | //маска 0x80000776 |
||
72 | |||
73 | Dword dwi, i; |
||
74 | |||
75 | for ( i = 0; i < 32; i++ ) |
||
76 | { |
||
77 | |||
78 | dwi = RandomSeed & 0x80000776; |
||
79 | |||
80 | __asm{ |
||
81 | mov eax, dwi |
||
82 | mov edx, eax |
||
83 | bswap eax |
||
84 | xor eax, edx |
||
85 | xor al, ah |
||
86 | setpo al |
||
87 | movzx eax, al |
||
88 | mov dwi, eax |
||
89 | } |
||
90 | |||
91 | RandomSeed = ( RandomSeed << 1 ) | ( dwi & 1 ); |
||
92 | } |
||
93 | |||
94 | return RandomSeed; |
||
95 | } |
||
96 | |||
7495 | leency | 97 | //#ifdef AUTOBUILD |
1764 | clevermous | 98 | // Well, not really related to auto-build, but some compilation issue |
99 | void memcpy( void *dst, const void *src, size_t bytesCount ) |
||
990 | barsuk | 100 | { |
101 | __asm{ |
||
102 | mov edi, dst |
||
1764 | clevermous | 103 | // mov eax, dst |
990 | barsuk | 104 | mov esi, src |
105 | mov ecx, bytesCount |
||
106 | rep movsb |
||
107 | } |
||
108 | } |
||
109 | |||
110 | // |
||
111 | void memset( Byte *dst, Byte filler, Dword count ) |
||
112 | { |
||
113 | // |
||
114 | __asm{ |
||
115 | mov edi, dst |
||
116 | mov al, filler |
||
117 | mov ecx, count |
||
118 | rep stosb |
||
119 | } |
||
1764 | clevermous | 120 | } |
7495 | leency | 121 | //#endif |
990 | barsuk | 122 | |
123 | |||
124 | // |
||
125 | Dword rtlInterlockedExchange( Dword *target, Dword value ) |
||
126 | { |
||
127 | // Dword result; |
||
128 | |||
129 | // |
||
130 | __asm{ |
||
131 | mov eax, value |
||
132 | mov ebx, target |
||
133 | xchg eax, [ebx] |
||
134 | // mov result, eax |
||
135 | } |
||
136 | // |
||
137 | // return result; |
||
138 | } |
||
139 | |||
140 | |||
141 | ////////////////////////////////////////////////////////////////////// |
||
142 | // |
||
143 | // копирование строки |
||
144 | // |
||
145 | |||
146 | char * __cdecl strcpy( char *target, const char *source ) |
||
147 | { |
||
148 | char *result = target; |
||
149 | |||
150 | while( target[0] = source[0] ) |
||
151 | { |
||
152 | target++; |
||
153 | source++; |
||
154 | } |
||
155 | |||
156 | return result; |
||
157 | } |
||
158 | |||
159 | |||
160 | ////////////////////////////////////////////////////////////////////// |
||
161 | // |
||
162 | // реверсивный поиск символа |
||
163 | // |
||
164 | |||
165 | char * __cdecl strrchr( const char * string, int c ) |
||
166 | { |
||
167 | char *cPtr; |
||
168 | |||
169 | // |
||
170 | for ( cPtr = (char *)string + strlen( string ); cPtr >= string; cPtr-- ) |
||
171 | { |
||
172 | // |
||
173 | if ( *cPtr == c ) return cPtr; |
||
174 | } |
||
175 | // |
||
176 | return NULL; |
||
177 | } |
||
178 | |||
179 | |||
180 | ////////////////////////////////////////////////////////////////////// |
||
181 | // |
||
182 | // определение длины строки |
||
183 | // |
||
184 | |||
185 | int __cdecl strlen( const char *line ) |
||
186 | { |
||
187 | int i; |
||
188 | |||
189 | for( i=0; line[i] != 0; i++ ); |
||
190 | return i; |
||
191 | } |
||
192 | |||
193 | |||
194 | |||
195 | ////////////////////////////////////////////////////////////////////// |
||
196 | // |
||
197 | // перевод шестнадцатиричного числа в символ |
||
198 | // |
||
199 | |||
200 | unsigned int num2hex( unsigned int num ) |
||
201 | { |
||
202 | if( num < 10 ) |
||
203 | return num + '0'; |
||
204 | return num - 10 + 'A'; |
||
205 | } |
||
206 | |||
207 | |||
208 | ////////////////////////////////////////////////////////////////////// |
||
209 | // |
||
210 | // вывод строки на печать. barsuk добавил %f |
||
211 | |||
212 | //#define PREC 2 |
||
213 | //#define HALF 0.499 |
||
214 | #define PREC 6 |
||
215 | #define HALF 0.4999999 |
||
216 | |||
217 | double double_tab[]={1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, |
||
218 | 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27, 1e28, 1e29, 1e30}; |
||
219 | |||
220 | |||
221 | // |
||
222 | |||
223 | Dword dectab[] = { 1000000000, 100000000, 10000000, 1000000, 100000, |
||
224 | 10000, 1000, 100, 10, 0 }; |
||
225 | |||
226 | // |
||
227 | void sprintf( char *Str, char* Format, ... ) |
||
228 | { |
||
229 | int i, fmtlinesize, j, k, flag; |
||
230 | Dword head, tail; |
||
231 | char c; |
||
232 | va_list arglist; |
||
233 | // |
||
234 | va_start(arglist, Format); |
||
235 | |||
236 | // |
||
237 | fmtlinesize = strlen( Format ); |
||
238 | // |
||
239 | if( fmtlinesize == 0 ) return; |
||
240 | |||
241 | // |
||
242 | for( i = 0, j = 0; i < fmtlinesize; i++ ) |
||
243 | { |
||
244 | // |
||
245 | c = Format[i]; |
||
246 | // |
||
247 | if( c != '%' ) |
||
248 | { |
||
249 | Str[j++] = c; |
||
250 | continue; |
||
251 | } |
||
252 | // |
||
253 | i++; |
||
254 | // |
||
255 | if( i >= fmtlinesize ) break; |
||
256 | |||
257 | // |
||
258 | flag = 0; |
||
259 | // |
||
260 | c = Format[i]; |
||
261 | // |
||
262 | switch( c ) |
||
263 | { |
||
264 | // |
||
265 | case '%': |
||
266 | Str[j++] = c; |
||
267 | break; |
||
268 | // вывод строки |
||
269 | case 'S': |
||
270 | Byte* str; |
||
271 | str = va_arg(arglist, Byte*); |
||
272 | for( k = 0; ( c = str[k] ) != 0; k++ ) |
||
273 | { |
||
274 | Str[j++] = c; |
||
275 | } |
||
276 | break; |
||
277 | // вывод байта |
||
278 | case 'B': |
||
279 | k = va_arg(arglist, int) & 0xFF; |
||
280 | Str[j++] = num2hex( ( k >> 4 ) & 0xF ); |
||
281 | Str[j++] = num2hex( k & 0xF ); |
||
282 | break; |
||
283 | // вывод символа |
||
284 | case 'C': |
||
285 | Str[j++] = va_arg(arglist, int) & 0xFF; |
||
286 | break; |
||
287 | // вывод двойного слова в шестнадцатиричном виде |
||
288 | case 'X': |
||
289 | Dword val; |
||
290 | val = va_arg(arglist, Dword); |
||
291 | for( k = 7; k >= 0; k-- ) |
||
292 | { |
||
293 | // |
||
294 | c = num2hex ( ( val >> (k * 4) ) & 0xF ); |
||
295 | // |
||
296 | if( c == '0' ) |
||
297 | { |
||
298 | if( flag ) Str[j++] = c; |
||
299 | } |
||
300 | else |
||
301 | { |
||
302 | flag++; |
||
303 | Str[j++] = c; |
||
304 | } |
||
305 | } |
||
306 | // |
||
307 | if( flag == 0 ) Str[j++] = '0'; |
||
308 | break; |
||
309 | // вывод двойного слова в десятичном виде |
||
310 | case 'U': |
||
311 | head = va_arg(arglist, Dword); |
||
312 | tail = 0; |
||
313 | for( k = 0; dectab[k] != 0; k++ ) |
||
314 | { |
||
315 | tail = head % dectab[k]; |
||
316 | head /= dectab[k]; |
||
317 | c = head + '0'; |
||
318 | if( c == '0' ) |
||
319 | { |
||
320 | if( flag ) Str[j++] = c; |
||
321 | } |
||
322 | else |
||
323 | { |
||
324 | flag++; |
||
325 | Str[j++] = c; |
||
326 | } |
||
327 | // |
||
328 | head = tail; |
||
329 | } |
||
330 | // |
||
331 | c = head + '0'; |
||
332 | Str[j++] = c; |
||
333 | break; |
||
334 | // вещественное число в формате 7.2 |
||
335 | case 'f': |
||
336 | case 'F': |
||
337 | case 'g': |
||
338 | case 'G': |
||
339 | { |
||
340 | double val, w; |
||
341 | int p; |
||
342 | val = va_arg(arglist, double); |
||
343 | if (val < 0.0) |
||
344 | { |
||
345 | Str[j++] = '-'; |
||
346 | val = -val; |
||
347 | } |
||
348 | for (k = 0; k < 30; k++) |
||
349 | if (val < double_tab[k]) |
||
350 | break; |
||
351 | |||
352 | if (val < 1.0) |
||
353 | { |
||
354 | Str[j++] = '0'; |
||
355 | } |
||
356 | |||
357 | for (p = 1; p < k + 1; p++) |
||
358 | { |
||
359 | int d = (int)di(val / double_tab[k - p] - HALF) % 10; |
||
360 | Str[j++] = '0' + d; |
||
361 | val -= d * double_tab[k - p]; |
||
362 | } |
||
363 | Str[j++] = '.'; |
||
364 | w = 0.1; |
||
365 | for (p = 0; p < PREC - 1; p++) |
||
366 | { |
||
367 | val-=floor(val); |
||
368 | Str[j++] = '0' + di(val / w - HALF) % 10; |
||
369 | w /= 10.0; |
||
370 | } |
||
371 | } |
||
372 | break; |
||
373 | |||
374 | // вывод 64-битного слова в шестнадцатиричном виде |
||
375 | case 'Q': |
||
376 | unsigned int low_dword, high_dword; |
||
377 | low_dword = va_arg(arglist, unsigned int); |
||
378 | high_dword = va_arg(arglist, unsigned int); |
||
379 | for( k = 7; k >= 0; k-- ) |
||
380 | { |
||
381 | // |
||
382 | c = num2hex ( ( ( high_dword + 1) >> (k * 4) ) & 0xF ); |
||
383 | // |
||
384 | if( c == '0' ) |
||
385 | { |
||
386 | if( flag ) Str[j++] = c; |
||
387 | } |
||
388 | else |
||
389 | { |
||
390 | flag++; |
||
391 | Str[j++] = c; |
||
392 | } |
||
393 | } |
||
394 | // |
||
395 | for( k=7; k >= 0; k-- ) |
||
396 | { |
||
397 | // |
||
398 | c = num2hex ( ( low_dword >> (k * 4) ) & 0xF ); |
||
399 | // |
||
400 | if( c == '0' ) |
||
401 | { |
||
402 | if( flag ) Str[j++] = c; |
||
403 | } |
||
404 | else |
||
405 | { |
||
406 | flag++; |
||
407 | Str[j++] = c; |
||
408 | } |
||
409 | } |
||
410 | // |
||
411 | if( flag == 0 ) Str[j++] = '0'; |
||
412 | // |
||
413 | break; |
||
414 | // |
||
415 | default: |
||
416 | break; |
||
417 | } |
||
418 | } |
||
419 | // |
||
420 | Str[j] = 0; |
||
421 | } |
||
422 | |||
423 | |||
7503 | leency | 424 | // function -1 завершения процесса |
990 | barsuk | 425 | void kos_ExitApp() |
426 | { |
||
427 | int i; |
||
428 | |||
429 | // |
||
430 | for ( i = atExitFnNum - 1; i >= 0; i-- ) |
||
431 | { |
||
432 | // |
||
433 | atExitList[i](); |
||
434 | } |
||
435 | // |
||
436 | __asm{ |
||
437 | mov eax, -1 |
||
438 | int 0x40 |
||
439 | } |
||
440 | } |
||
441 | |||
442 | |||
7503 | leency | 443 | // function 0 |
990 | barsuk | 444 | void kos_DefineAndDrawWindow( |
445 | Word x, Word y, |
||
446 | Word sizeX, Word sizeY, |
||
447 | Byte mainAreaType, |
||
448 | Dword mainAreaColour, |
||
449 | Byte headerType, |
||
450 | Dword headerColour, |
||
451 | Dword borderColour |
||
452 | ) |
||
453 | { |
||
454 | Dword arg1, arg2, arg3, arg4; |
||
455 | |||
456 | // |
||
457 | arg1 = ( x << 16 ) + sizeX; |
||
458 | arg2 = ( y << 16 ) + sizeY; |
||
459 | arg3 = ( mainAreaType << 24 ) | mainAreaColour; |
||
460 | arg4 = ( headerType << 24 ) | headerColour; |
||
461 | // |
||
462 | __asm{ |
||
463 | mov eax, 0 |
||
464 | mov ebx, arg1 |
||
465 | mov ecx, arg2 |
||
466 | mov edx, arg3 |
||
467 | mov esi, arg4 |
||
468 | mov edi, borderColour |
||
469 | int 0x40 |
||
470 | } |
||
471 | } |
||
472 | |||
473 | |||
7503 | leency | 474 | // function 1 поставить точку |
990 | barsuk | 475 | void kos_PutPixel( Dword x, Dword y, Dword colour ) |
476 | { |
||
477 | // |
||
478 | __asm{ |
||
479 | mov eax, 1 |
||
480 | mov ebx, x |
||
481 | mov ecx, y |
||
482 | mov edx, colour |
||
483 | int 0x40 |
||
484 | } |
||
485 | } |
||
486 | |||
7507 | leency | 487 | bool kos_GetKeys( Dword &key_editbox, Byte &key_ascii, Byte &key_scancode ) |
990 | barsuk | 488 | { |
489 | Dword result; |
||
490 | __asm{ |
||
491 | mov eax, 2 |
||
492 | int 0x40 |
||
493 | mov result, eax |
||
494 | } |
||
7507 | leency | 495 | key_editbox = result; |
496 | key_ascii = result >> 8; |
||
497 | key_scancode = result >> 16; |
||
498 | return ( key_ascii ) == 0; |
||
990 | barsuk | 499 | } |
500 | |||
7503 | leency | 501 | // function 3 получить время |
990 | barsuk | 502 | Dword kos_GetSystemClock() |
503 | { |
||
504 | // Dword result; |
||
505 | |||
506 | // |
||
507 | __asm{ |
||
508 | mov eax, 3 |
||
509 | int 0x40 |
||
510 | // mov result, eax |
||
511 | } |
||
512 | // |
||
513 | // return result; |
||
514 | } |
||
515 | |||
516 | |||
7503 | leency | 517 | // function 4 |
990 | barsuk | 518 | void kos_WriteTextToWindow( |
519 | Word x, |
||
520 | Word y, |
||
521 | Byte fontType, |
||
522 | Dword textColour, |
||
523 | char *textPtr, |
||
524 | Dword textLen |
||
525 | ) |
||
526 | { |
||
527 | Dword arg1, arg2; |
||
528 | |||
529 | // |
||
530 | arg1 = ( x << 16 ) | y; |
||
531 | arg2 = ( fontType << 24 ) | textColour; |
||
532 | // |
||
533 | __asm{ |
||
534 | mov eax, 4 |
||
535 | mov ebx, arg1 |
||
536 | mov ecx, arg2 |
||
537 | mov edx, textPtr |
||
538 | mov esi, textLen |
||
539 | int 0x40 |
||
540 | } |
||
541 | } |
||
542 | |||
543 | |||
7503 | leency | 544 | // function 5 пауза, в сотых долях секунды |
990 | barsuk | 545 | void kos_Pause( Dword value ) |
546 | { |
||
547 | // |
||
548 | __asm{ |
||
549 | mov eax, 5 |
||
550 | mov ebx, value |
||
551 | int 0x40 |
||
552 | } |
||
553 | } |
||
554 | |||
555 | |||
7503 | leency | 556 | // function 7 нарисовать изображение |
990 | barsuk | 557 | void kos_PutImage( RGB * imagePtr, Word sizeX, Word sizeY, Word x, Word y ) |
558 | { |
||
559 | Dword arg1, arg2; |
||
560 | |||
561 | // |
||
562 | arg1 = ( sizeX << 16 ) | sizeY; |
||
563 | arg2 = ( x << 16 ) | y; |
||
564 | // |
||
565 | __asm{ |
||
566 | mov eax, 7 |
||
567 | mov ebx, imagePtr |
||
568 | mov ecx, arg1 |
||
569 | mov edx, arg2 |
||
570 | int 0x40 |
||
571 | } |
||
572 | } |
||
573 | |||
574 | |||
575 | |||
7503 | leency | 576 | // function 8 определить кнопку |
990 | barsuk | 577 | void kos_DefineButton( Word x, Word y, Word sizeX, Word sizeY, Dword buttonID, Dword colour ) |
578 | { |
||
7503 | leency | 579 | kos_UnsaveDefineButton(NULL, NULL, NULL, NULL, buttonID+BT_DEL, NULL); |
580 | kos_UnsaveDefineButton(x, y, sizeX, sizeY, buttonID, colour); |
||
581 | } |
||
582 | |||
583 | // |
||
584 | void kos_UnsaveDefineButton( Word x, Word y, Word sizeX, Word sizeY, Dword buttonID, Dword colour ) |
||
585 | { |
||
990 | barsuk | 586 | Dword arg1, arg2; |
587 | |||
588 | // |
||
589 | arg1 = ( x << 16 ) | sizeX; |
||
590 | arg2 = ( y << 16 ) | sizeY; |
||
591 | // |
||
592 | __asm{ |
||
593 | mov eax, 8 |
||
594 | mov ebx, arg1 |
||
595 | mov ecx, arg2 |
||
596 | mov edx, buttonID |
||
597 | mov esi, colour |
||
598 | int 0x40 |
||
599 | } |
||
600 | } |
||
601 | |||
602 | |||
7503 | leency | 603 | // function 9 - информация о процессе |
990 | barsuk | 604 | Dword kos_ProcessInfo( sProcessInfo *targetPtr, Dword processID ) |
605 | { |
||
606 | // Dword result; |
||
607 | |||
608 | // |
||
609 | __asm{ |
||
610 | mov eax, 9 |
||
611 | mov ebx, targetPtr |
||
612 | mov ecx, processID |
||
613 | int 0x40 |
||
614 | // mov result, eax |
||
615 | } |
||
616 | // |
||
617 | // return result; |
||
618 | } |
||
619 | |||
620 | |||
7503 | leency | 621 | // function 10 |
990 | barsuk | 622 | Dword kos_WaitForEvent() |
623 | { |
||
624 | // Dword result; |
||
625 | |||
626 | __asm{ |
||
627 | mov eax, 10 |
||
628 | int 0x40 |
||
629 | // mov result, eax |
||
630 | } |
||
631 | |||
632 | // return result; |
||
633 | } |
||
634 | |||
635 | |||
7503 | leency | 636 | // function 11 |
990 | barsuk | 637 | Dword kos_CheckForEvent() |
638 | { |
||
639 | // Dword result; |
||
640 | |||
641 | __asm{ |
||
642 | mov eax, 11 |
||
643 | int 0x40 |
||
644 | // mov result, eax |
||
645 | } |
||
646 | |||
647 | // return result; |
||
648 | } |
||
649 | |||
650 | |||
7503 | leency | 651 | // function 12 |
990 | barsuk | 652 | void kos_WindowRedrawStatus( Dword status ) |
653 | { |
||
654 | __asm{ |
||
655 | mov eax, 12 |
||
656 | mov ebx, status |
||
657 | int 0x40 |
||
658 | } |
||
659 | } |
||
660 | |||
661 | |||
7503 | leency | 662 | // function 13 нарисовать полосу |
990 | barsuk | 663 | void kos_DrawBar( Word x, Word y, Word sizeX, Word sizeY, Dword colour ) |
664 | { |
||
665 | Dword arg1, arg2; |
||
666 | |||
667 | // |
||
668 | arg1 = ( x << 16 ) | sizeX; |
||
669 | arg2 = ( y << 16 ) | sizeY; |
||
670 | // |
||
671 | __asm{ |
||
672 | mov eax, 13 |
||
673 | mov ebx, arg1 |
||
674 | mov ecx, arg2 |
||
675 | mov edx, colour |
||
676 | int 0x40 |
||
677 | } |
||
678 | } |
||
679 | |||
680 | |||
7503 | leency | 681 | // function 17 |
990 | barsuk | 682 | bool kos_GetButtonID( Dword &buttonID ) |
683 | { |
||
684 | Dword result; |
||
685 | |||
686 | // |
||
687 | __asm{ |
||
688 | mov eax, 17 |
||
689 | int 0x40 |
||
690 | mov result, eax |
||
691 | } |
||
692 | // |
||
693 | buttonID = result >> 8; |
||
694 | // |
||
695 | return (result & 0xFF) == 0; |
||
696 | } |
||
697 | |||
698 | |||
7503 | leency | 699 | // function 23 |
2750 | leency | 700 | Dword kos_WaitForEventTimeout( Dword timeOut ) |
990 | barsuk | 701 | { |
702 | // Dword result; |
||
703 | |||
704 | __asm{ |
||
705 | mov eax, 23 |
||
706 | mov ebx, timeOut |
||
707 | int 0x40 |
||
708 | // mov result, eax |
||
709 | } |
||
710 | |||
711 | // return result; |
||
712 | } |
||
713 | |||
714 | |||
7503 | leency | 715 | // получение информации о состоянии "мыши" function 37 |
990 | barsuk | 716 | void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY ) |
717 | { |
||
718 | Dword mB; |
||
719 | Word curX; |
||
720 | Word curY; |
||
721 | sProcessInfo sPI; |
||
722 | |||
723 | // |
||
724 | __asm{ |
||
725 | mov eax, 37 |
||
726 | mov ebx, 0 |
||
727 | int 0x40 |
||
728 | mov curY, ax |
||
729 | shr eax, 16 |
||
730 | mov curX, ax |
||
731 | mov eax, 37 |
||
732 | mov ebx, 2 |
||
733 | int 0x40 |
||
734 | mov mB, eax |
||
735 | } |
||
736 | // |
||
737 | kos_ProcessInfo( &sPI ); |
||
738 | // |
||
739 | buttons = mB; |
||
740 | cursorX = curX - sPI.processInfo.x_start; |
||
741 | cursorY = curY - sPI.processInfo.y_start; |
||
742 | } |
||
743 | |||
7503 | leency | 744 | // function 38 |
745 | void kos_DrawLine( Word x1, Word y1, Word x2, Word y2, Dword colour, Dword invert ) |
||
746 | { |
||
747 | Dword arg1, arg2, arg3; |
||
990 | barsuk | 748 | |
7503 | leency | 749 | // |
750 | arg1 = ( x1 << 16 ) | x2; |
||
751 | arg2 = ( y1 << 16 ) | y2; |
||
752 | arg3 = (invert)?0x01000000:colour; |
||
753 | // |
||
754 | __asm{ |
||
755 | mov eax, 38 |
||
756 | mov ebx, arg1 |
||
757 | mov ecx, arg2 |
||
758 | mov edx, arg3 |
||
759 | int 0x40 |
||
760 | } |
||
761 | } |
||
762 | |||
763 | // function 40 установить маску событий |
||
990 | barsuk | 764 | void kos_SetMaskForEvents( Dword mask ) |
765 | { |
||
766 | // |
||
767 | __asm{ |
||
768 | mov eax, 40 |
||
769 | mov ebx, mask |
||
770 | int 0x40 |
||
771 | } |
||
772 | } |
||
773 | |||
774 | |||
7503 | leency | 775 | // function 47 вывести в окно приложения число |
990 | barsuk | 776 | void kos_DisplayNumberToWindow( |
777 | Dword value, |
||
778 | Dword digitsNum, |
||
779 | Word x, |
||
780 | Word y, |
||
781 | Dword colour, |
||
782 | eNumberBase nBase, |
||
783 | bool valueIsPointer |
||
784 | ) |
||
785 | { |
||
786 | Dword arg1, arg2; |
||
787 | |||
788 | // |
||
789 | arg1 = ( valueIsPointer ? 1 : 0 ) | |
||
790 | ( ((Byte)nBase) << 8 ) | |
||
791 | ( ( digitsNum & 0x1F ) << 16 ); |
||
792 | arg2 = ( x << 16 ) | y; |
||
793 | // |
||
794 | __asm{ |
||
795 | mov eax, 47 |
||
796 | mov ebx, arg1 |
||
797 | mov ecx, value |
||
798 | mov edx, arg2 |
||
799 | mov esi, colour |
||
800 | int 0x40 |
||
801 | } |
||
802 | } |
||
803 | |||
7504 | leency | 804 | // 48.3: get system colors |
805 | bool kos_GetSystemColors( kosSysColors *sc ) |
||
990 | barsuk | 806 | { |
807 | __asm{ |
||
7504 | leency | 808 | mov eax, 48 |
809 | mov ebx, 3 |
||
810 | mov ecx, sc |
||
811 | mov edx, 40 |
||
990 | barsuk | 812 | int 0x40 |
813 | } |
||
814 | } |
||
815 | |||
816 | |||
7503 | leency | 817 | // function 63 вывод символя в окно отладки |
990 | barsuk | 818 | void kos_DebugOutChar( char ccc ) |
819 | { |
||
820 | __asm{ |
||
821 | mov eax, 63 |
||
822 | mov ebx, 1 |
||
823 | mov cl, ccc |
||
824 | int 0x40 |
||
825 | } |
||
826 | } |
||
827 | |||
828 | |||
7503 | leency | 829 | // function 66 режим получения данных от клавиатуры |
990 | barsuk | 830 | void kos_SetKeyboardDataMode( Dword mode ) |
831 | { |
||
832 | // |
||
833 | __asm{ |
||
834 | mov eax, 66 |
||
835 | mov ebx, 1 |
||
836 | mov ecx, mode |
||
837 | int 0x40 |
||
838 | } |
||
839 | } |
||
840 | |||
841 | |||
842 | // вывод строки в окно отладки |
||
843 | void rtlDebugOutString( char *str ) |
||
844 | { |
||
845 | // |
||
846 | for ( ; str[0] != 0; str++ ) |
||
847 | { |
||
848 | kos_DebugOutChar( str[0] ); |
||
849 | } |
||
850 | // |
||
851 | kos_DebugOutChar( 13 ); |
||
852 | kos_DebugOutChar( 10 ); |
||
853 | } |
||
854 | |||
7503 | leency | 855 | void kos_DebugValue(char *str, int n) |
856 | { |
||
857 | char debuf[50]; |
||
858 | sprintf(debuf, "%S: %U", str, n); |
||
859 | rtlDebugOutString(debuf); |
||
860 | } |
||
990 | barsuk | 861 | |
7503 | leency | 862 | |
863 | // function 64 изменение количества памяти, выделенной для программы |
||
990 | barsuk | 864 | bool kos_ApplicationMemoryResize( Dword targetSize ) |
865 | { |
||
866 | Dword result; |
||
867 | |||
868 | // |
||
869 | __asm{ |
||
870 | mov eax, 64 |
||
871 | mov ebx, 1 |
||
872 | mov ecx, targetSize |
||
873 | int 0x40 |
||
874 | mov result, eax |
||
875 | } |
||
876 | // |
||
877 | return result == 0; |
||
878 | } |
||
879 | |||
880 | |||
7503 | leency | 881 | // function 67 изменить параметры окна, параметр == -1 не меняется |
990 | barsuk | 882 | void kos_ChangeWindow( Dword x, Dword y, Dword sizeX, Dword sizeY ) |
883 | { |
||
884 | // |
||
885 | __asm{ |
||
886 | mov eax, 67 |
||
887 | mov ebx, x |
||
888 | mov ecx, y |
||
889 | mov edx, sizeX |
||
890 | mov esi, sizeY |
||
891 | int 0x40 |
||
892 | } |
||
893 | } |
||
894 | |||
7504 | leency | 895 | // 68.11: init heap |
990 | barsuk | 896 | void kos_InitHeap() |
897 | { |
||
898 | __asm{ |
||
899 | mov eax, 68 |
||
900 | mov ebx, 11 |
||
901 | int 0x40 |
||
902 | } |
||
903 | } |
||
904 | |||
7504 | leency | 905 | // function 70 доступ к файловой системе |
906 | Dword kos_FileSystemAccess( kosFileInfo *fileInfo ) |
||
907 | { |
||
908 | __asm{ |
||
909 | mov eax, 70 |
||
910 | mov ebx, fileInfo |
||
911 | int 0x40 |
||
912 | } |
||
913 | } |
||
990 | barsuk | 914 | |
7504 | leency | 915 | // 70.7: run Kolibri application with param |
916 | int kos_AppRun(char* app_path, char* param) |
||
917 | { |
||
918 | kosFileInfo fileInfo; |
||
919 | fileInfo.rwMode = 7; |
||
920 | fileInfo.OffsetLow = 0; |
||
921 | fileInfo.OffsetHigh = param; |
||
922 | fileInfo.dataCount = 0; |
||
923 | fileInfo.bufferPtr = 0; |
||
924 | strcpy(fileInfo.fileURL, app_path); |
||
925 | return kos_FileSystemAccess(&fileInfo); |
||
926 | } |
||
990 | barsuk | 927 | |
7504 | leency | 928 | |
990 | barsuk | 929 | // вызов абстрактного метода |
930 | int __cdecl _purecall() |
||
931 | { |
||
932 | rtlDebugOutString( pureCallMessage ); |
||
933 | kos_ExitApp(); |
||
934 | return 0; |
||
935 | } |
||
936 | |||
937 | |||
938 | // вызов статических инициализаторов |
||
939 | // заодно инициализация генератора случайных чисел |
||
940 | //#pragma section(".CRT$XCA",long,read,write) |
||
941 | //#pragma section(".CRT$XCZ",long,read,write) |
||
942 | #pragma data_seg(".CRT$XCA") |
||
943 | #pragma data_seg(".CRT$XCZ") |
||
944 | typedef void (__cdecl *_PVFV)(void); |
||
1764 | clevermous | 945 | //__declspec(allocate(".CRT$XCA")) _PVFV __xc_a[1] = { NULL }; |
946 | //__declspec(allocate(".CRT$XCZ")) _PVFV __xc_z[1] = { NULL }; |
||
990 | barsuk | 947 | // |
1764 | clevermous | 948 | extern void ALMOST_HALF_init(); |
990 | barsuk | 949 | #pragma comment(linker, "/merge:.CRT=.rdata") |
950 | // |
||
951 | void crtStartUp() |
||
952 | { |
||
1764 | clevermous | 953 | #ifdef AUTOBUILD |
954 | // linker will try to remove unused variables; force header to be included |
||
955 | header.header; |
||
956 | #endif |
||
990 | barsuk | 957 | // вызываем инициализаторы по списку, NULL'ы игнорируем |
1764 | clevermous | 958 | /*for ( _PVFV *pbegin = __xc_a; pbegin < __xc_z; pbegin++ ) |
990 | barsuk | 959 | { |
960 | // |
||
961 | if ( *pbegin != NULL ) |
||
962 | (**pbegin)(); |
||
1764 | clevermous | 963 | }*/ |
964 | ALMOST_HALF_init(); |
||
990 | barsuk | 965 | // инициализируем генератор случайных чисел |
966 | rtlSrand( kos_GetSystemClock() ); |
||
1764 | clevermous | 967 | #ifndef AUTOBUILD |
990 | barsuk | 968 | // путь к файлу процесса |
969 | kosExePath = *((char **)0x20); |
||
1764 | clevermous | 970 | #endif |
990 | barsuk | 971 | // вызов главной функции приложения |
972 | kos_Main(); |
||
973 | // выход |
||
974 | kos_ExitApp(); |
||
975 | }>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>>>>>>>>>><>>> |
||
976 |