Subversion Repositories Kolibri OS

Rev

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