Subversion Repositories Kolibri OS

Rev

Rev 4481 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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