Subversion Repositories Kolibri OS

Rev

Rev 5115 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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