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