Subversion Repositories Kolibri OS

Rev

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

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