Subversion Repositories Kolibri OS

Rev

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