Subversion Repositories Kolibri OS

Rev

Rev 7482 | 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. // function -1 termanate process
  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. // function 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. // function 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. // function 2 get key code
  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. // function 3 get system clock
  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. // function 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. // function 4
  495. void kos_WriteTextWithBg(
  496.         Word x,
  497.         Word y,
  498.         Byte fontType,
  499.         Dword textColour,
  500.         Dword bgcolour,
  501.         char *textPtr,
  502.         Dword textLen
  503.         )
  504. {
  505.         Dword arg1, arg2;
  506.  
  507.         //
  508.         arg1 = ( x << 16 ) | y;
  509.         arg2 = ( fontType << 24 ) | textColour;
  510.         //
  511.         __asm{
  512.                 mov edi, bgcolour
  513.         }
  514.         kos_WriteTextToWindow(x,y,fontType,textColour,textPtr,textLen);
  515. }
  516.  
  517.  
  518. // function 5 pause, in value is 1/100 of second
  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. // function 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. // function 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. // function 9 get process info
  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. // function 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. // function 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. // function 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. // function 13 draw filled area
  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. // function 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. // function 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. // function 26.9 ïîëó÷èòü çíà÷åíèå ñ÷¸ò÷èêà âðåìåíè
  682. Dword kos_GetTime()
  683. {
  684.         __asm{
  685.                 mov eax, 26
  686.                 mov ebx, 9
  687.                 int 0x40
  688.         }
  689. }
  690.  
  691. // function 37 ïîëó÷åíèå èíôîðìàöèè î ñîñòîÿíèè "ìûøè"
  692. void kos_GetMouseState( Dword & buttons, int & cursorX, int & cursorY )
  693. {
  694.         Dword mB;
  695.         Word curX;
  696.         Word curY;
  697.         sProcessInfo sPI;
  698.  
  699.         //
  700.         __asm{
  701.                 mov             eax, 37
  702.                 mov             ebx, 0
  703.                 int             0x40
  704.                 mov             curY, ax
  705.                 shr             eax, 16
  706.                 mov             curX, ax
  707.                 mov             eax, 37
  708.                 mov             ebx, 2
  709.                 int             0x40
  710.                 mov             mB, eax
  711.         }
  712.         //
  713.         kos_ProcessInfo( &sPI );
  714.         //
  715.         buttons = mB;
  716.         cursorX = curX - sPI.processInfo.x_start;
  717.         cursorY = curY - sPI.processInfo.y_start;
  718. }
  719.  
  720. // function 37.1 ïîëó÷åíèå êîîðäèíàò "ìûøè" îòíîñèòåëüíî îêíà
  721. void kos_GetMouseWindowXY( int & cursorX, int & cursorY )
  722. {
  723.         Word curX;
  724.         Word curY;
  725.  
  726.         __asm{
  727.                 mov eax, 37
  728.                 mov ebx, 1
  729.                 int 0x40
  730.  
  731.                 mov ebx, eax
  732.                 shr eax, 16
  733.                 and ebx, 0xffff
  734.  
  735.                 mov curX, ax
  736.                 mov curY, bx
  737.         }
  738.  
  739.         cursorX = curX;
  740.         cursorY = curY;
  741. }
  742.  
  743. // function 37.2 ïîëó÷åíèå èíôîðìàöèè î íàæàòûõ êíîïêè "ìûøè"
  744. void kos_GetMouseButtonsState( Dword & buttons )
  745. {
  746.         Dword mB;
  747.  
  748.         __asm{
  749.                 mov             eax, 37
  750.                 mov             ebx, 2
  751.                 int             0x40
  752.                 mov             mB, eax
  753.         }
  754.  
  755.         buttons = mB;
  756. }
  757.  
  758. // function 37.4 çàãðóçêà êóðñîðà "ìûøè"
  759. Dword * kos_LoadMouseCursor( Dword * cursor, Dword loadstate )
  760. {
  761.         //Dword handle;
  762.         __asm{
  763.                 mov             eax, 37
  764.                 mov             ebx, 4
  765.                 mov             edx, loadstate
  766.                 mov             ecx, cursor
  767.                 int             0x40
  768.                 //mov           handle, eax
  769.         }
  770.         //return handle;
  771. }
  772.  
  773. // function 37.5 óñòàíîâêà êóðñîðà "ìûøè"
  774. Dword * kos_SetMouseCursor( Dword * handle )
  775. {
  776.         //Dword handle;
  777.         __asm{
  778.                 mov             eax, 37
  779.                 mov             ebx, 5
  780.                 mov             ecx, handle
  781.                 int             0x40
  782.                 //mov           handle, eax
  783.         }
  784.         //return handle;
  785. }
  786.  
  787. // function 37.6 óäàëåíèå êóðñîðà "ìûøè"
  788. void kos_DeleteMouseCursor( Dword * handle )
  789. {
  790.         __asm{
  791.                 mov             eax, 37
  792.                 mov             ebx, 6
  793.                 mov             ecx, handle
  794.                 int             0x40
  795.         }
  796. }
  797.  
  798. // function 38
  799. void kos_DrawLine( Word x1, Word y1, Word x2, Word y2, Dword colour )
  800. {
  801.         Dword arg1, arg2;
  802.  
  803.         //
  804.         arg1 = ( x1 << 16 ) | x2;
  805.         arg2 = ( y1 << 16 ) | y2;
  806.         //
  807.         __asm{
  808.                 mov eax, 38
  809.                 mov ebx, arg1
  810.                 mov ecx, arg2
  811.                 mov edx, colour
  812.                 int 0x40
  813.         }
  814. }
  815.  
  816.  
  817. // function 40
  818. void kos_SetMaskForEvents( Dword mask )
  819. {
  820.         //
  821.         __asm{
  822.                 mov eax, 40
  823.                 mov ebx, mask
  824.                 int 0x40
  825.         }
  826. }
  827.  
  828.  
  829. // function 47 âûâåñòè â îêíî ïðèëîæåíèÿ ÷èñëî
  830. void kos_DisplayNumberToWindow(
  831.    Dword value,
  832.    Dword digitsNum,
  833.    Word x,
  834.    Word y,
  835.    Dword colour,
  836.    eNumberBase nBase,
  837.    bool valueIsPointer
  838.    )
  839. {
  840.         Dword arg1, arg2;
  841.  
  842.         //
  843.         arg1 = ( valueIsPointer ? 1 : 0 ) |
  844.                 ( ((Byte)nBase) << 8 ) |
  845.                 ( ( digitsNum & 0x1F ) << 16 );
  846.         arg2 = ( x << 16 ) | y;
  847.         //
  848.         __asm{
  849.                 mov eax, 47
  850.                 mov ebx, arg1
  851.                 mov ecx, value
  852.                 mov edx, arg2
  853.                 mov esi, colour
  854.                 int 0x40
  855.         }
  856. }
  857.  
  858. // function 47 âûâåñòè â îêíî ïðèëîæåíèÿ ÷èñëî c ôîíîì
  859. void kos_DisplayNumberToWindowBg(
  860.    Dword value,
  861.    Dword digitsNum,
  862.    Word x,
  863.    Word y,
  864.    Dword colour,
  865.    Dword bgcolour,
  866.    eNumberBase nBase,
  867.    bool valueIsPointer
  868.    )
  869. {
  870.         Dword arg1, arg2;
  871.  
  872.         //
  873.         arg1 = ( valueIsPointer ? 1 : 0 ) |
  874.                 ( ((Byte)nBase) << 8 ) |
  875.                 ( ( digitsNum & 0x1F ) << 16 );
  876.         arg2 = ( x << 16 ) | y;
  877.         //
  878.         __asm{
  879.                 mov eax, 47
  880.                 mov ebx, arg1
  881.                 mov ecx, value
  882.                 mov edx, arg2
  883.                 mov esi, colour
  884.                 or      esi, 0x40000000
  885.                 mov edi, bgcolour
  886.                 int 0x40
  887.         }
  888. }
  889.  
  890. // 48.4 get windows title bar height
  891. Dword kos_GetSkinHeight()
  892. {
  893.         __asm{
  894.                 mov             eax, 48
  895.                 mov             ebx, 4
  896.                 int             0x40
  897.         }
  898. }
  899.  
  900. // function 70 äîñòóï ê ôàéëîâîé ñèñòåìå
  901. Dword kos_FileSystemAccess( kosFileInfo *fileInfo )
  902. {
  903. //      Dword result;
  904.  
  905.         //
  906.         __asm{
  907.                 mov eax, 70
  908.                 mov ebx, fileInfo
  909.                 int 0x40
  910. //              mov result, eax
  911.         }
  912.         //
  913. //      return result;
  914. }
  915.  
  916.  
  917. // function 63 âûâîä ñèìâîëÿ â îêíî îòëàäêè
  918. void kos_DebugOutChar( char ccc )
  919. {
  920.         //
  921.         __asm{
  922.                 mov eax, 63
  923.                 mov ebx, 1
  924.                 mov cl, ccc
  925.                 int 0x40
  926.         }
  927. }
  928.  
  929.  
  930. // function 66 ðåæèì ïîëó÷åíèÿ äàííûõ îò êëàâèàòóðû
  931. void kos_SetKeyboardDataMode( Dword mode )
  932. {
  933.         //
  934.         __asm{
  935.                 mov eax, 66
  936.                 mov ebx, 1
  937.                 mov ecx, mode
  938.                 int 0x40
  939.         }
  940. }
  941.  
  942.  
  943. // âûâîä ñòðîêè â îêíî îòëàäêè
  944. void rtlDebugOutString( char *str )
  945. {
  946.         //
  947.         for ( ; str[0] != 0; str++ )
  948.         {
  949.                 kos_DebugOutChar( str[0] );
  950.         }
  951.         //
  952.         kos_DebugOutChar( 13 );
  953.         kos_DebugOutChar( 10 );
  954. }
  955.  
  956. void kos_DebugNumber(signed int n)
  957. {
  958.         if (n<0) {
  959.                 kos_DebugOutChar('-');
  960.                 n = -n;
  961.         }
  962.         while (n>10) {
  963.                 kos_DebugOutChar(n%10 + '0');
  964.                 n /= 10;
  965.         }
  966.         kos_DebugOutChar(n + '0');
  967.         kos_DebugOutChar('\n');
  968. }
  969.  
  970. // function 64 èçìåíåíèå êîëè÷åñòâà ïàìÿòè, âûäåëåííîé äëÿ ïðîãðàììû
  971. bool kos_ApplicationMemoryResize( Dword targetSize )
  972. {
  973.         Dword result;
  974.  
  975.         //
  976.         __asm{
  977.                 mov eax, 64
  978.                 mov ebx, 1
  979.                 mov ecx, targetSize
  980.                 int 0x40
  981.                 mov result, eax
  982.         }
  983.         //
  984.         return result == 0;
  985. }
  986.  
  987.  
  988. // function 67 change window size and position,
  989. // if  param == -1 then value does not change
  990. void kos_ChangeWindow( Dword x, Dword y, Dword sizeX, Dword sizeY )
  991. {
  992.         //
  993.         __asm{
  994.                 mov eax, 67
  995.                 mov ebx, x
  996.                 mov ecx, y
  997.                 mov edx, sizeX
  998.                 mov esi, sizeY
  999.                 int 0x40
  1000.         }
  1001. }
  1002.  
  1003.  
  1004.  
  1005. // âûçîâ àáñòðàêòíîãî ìåòîäà
  1006. int __cdecl _purecall()
  1007. {
  1008.         rtlDebugOutString( pureCallMessage );
  1009.         kos_ExitApp();
  1010.         return 0;
  1011. }
  1012.  
  1013.  
  1014. // âûçîâ ñòàòè÷åñêèõ èíèöèàëèçàòîðîâ
  1015. // çàîäíî èíèöèàëèçàöèÿ ãåíåðàòîðà ñëó÷àéíûõ ÷èñåë
  1016. //#pragma section(".CRT$XCA",long,read,write)
  1017. //#pragma section(".CRT$XCZ",long,read,write)
  1018. #pragma data_seg(".CRT$XCA")
  1019. #pragma data_seg(".CRT$XCZ")
  1020. typedef void (__cdecl *_PVFV)(void);
  1021. __declspec(allocate(".CRT$XCA"))  _PVFV __xc_a[1] = { NULL };
  1022. __declspec(allocate(".CRT$XCZ"))  _PVFV __xc_z[1] = { NULL };
  1023. //
  1024. #pragma comment(linker, "/merge:.CRT=.rdata")
  1025. //
  1026. void crtStartUp()
  1027. {
  1028. #ifdef AUTOBUILD
  1029. // linker will try to remove unused variables; force header to be included
  1030.         header.header;
  1031. #endif
  1032.         // âûçûâàåì èíèöèàëèçàòîðû ïî ñïèñêó, NULL'û èãíîðèðóåì
  1033.         for ( _PVFV *pbegin = __xc_a; pbegin < __xc_z; pbegin++ )
  1034.         {
  1035.                 //
  1036.                 if ( *pbegin != NULL )
  1037.                         (**pbegin)();
  1038.         }
  1039.         // èíèöèàëèçèðóåì ãåíåðàòîð ñëó÷àéíûõ ÷èñåë
  1040.         rtlSrand( kos_GetSystemClock() );
  1041. #ifndef AUTOBUILD
  1042.         // ïóòü ê ôàéëó ïðîöåññà
  1043.         kosExePath = *((char **)0x20);
  1044. #endif
  1045.         // âûçîâ ãëàâíîé ôóíêöèè ïðèëîæåíèÿ
  1046.         kos_Main();
  1047.         // âûõîä
  1048.         kos_ExitApp();
  1049. }
  1050.  
  1051.  
  1052.