Subversion Repositories Kolibri OS

Rev

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

  1.  
  2.  
  3. #include "func.h"
  4.  
  5. int convert_error = 0;
  6. int SysColor = 0;
  7. char debuf[50] = "";
  8.  
  9.  
  10. void kos_DrawRegion(Word x, Word y,Word width, Word height, Dword color1, Word invert)
  11. {
  12.         kos_DrawLine(x,y,x+width-2,y,color1,invert);
  13.         kos_DrawLine(x,y+1,x,y+height-1,color1,invert);
  14.         kos_DrawLine(x+width-1,y,x+width-1,y+height-2,color1,invert);
  15.         kos_DrawLine(x+1,y+height-1,x+width-1,y+height-1,color1,invert);
  16. }
  17.  
  18. void kos_DrawCutTextSmall(Word x, Word y, int areaWidth, Dword textColour, char *textPtr)
  19. {
  20.         if (textPtr) {
  21.                 int textLen = strlen(textPtr);
  22.                 if (textLen*6 > areaWidth) textLen = areaWidth / 6;
  23.                 kos_WriteTextToWindow(x,y,0,textColour,textPtr,textLen);       
  24.         }
  25. }
  26.  
  27. // äà, ýòî áàÿí
  28. int atoi(const char* string)
  29. {
  30.         int res=0;
  31.         int sign=0;
  32.         const char* ptr;
  33.         for (ptr=string; *ptr && *ptr<=' ';ptr++);
  34.         if (*ptr=='-') {sign=1;++ptr;}
  35.         while (*ptr >= '0' && *ptr <= '9')
  36.         {
  37.                 res = res*10 + *ptr++ - '0';
  38.         }
  39.         if (sign) res = -res;
  40.         return res;
  41. }
  42.  
  43. /*int abs(int n)
  44. {
  45.         return (n<0)?-n:n;
  46. }*/
  47.  
  48.  
  49.  
  50.  
  51.  
  52. double fabs(double x)
  53. {
  54.         __asm   fld     x
  55.         __asm   fabs
  56. }
  57. #define M_PI       3.14159265358979323846
  58. double cos(double x)
  59. {
  60.         __asm   fld     x
  61.         __asm   fcos
  62. }
  63. double sin(double x)
  64. {
  65.         __asm   fld     x
  66.         __asm   fsin
  67. }
  68.  
  69. bool isalpha(char c)
  70. {
  71.         return (c==' ' || c=='\n' || c=='\t' || c=='\r');
  72. }
  73.  
  74. // ýòà ôóíêöèÿ - âåëîñèïåä. íî ïðîùå áûëî íàïèñàòü ÷åì íàéòè.
  75. double convert(char *s, int *len)
  76. {
  77.  
  78.         int i;
  79.  
  80.  
  81.         double sign,res, tail, div;
  82.  
  83.         convert_error = 0;
  84.  
  85.         res = 0.0;
  86.  
  87.         i=0;
  88.         while (s[i] && isalpha(s[i])) i++;
  89.         if (len) *len=i;
  90.         if (s[i] == '\0')
  91.         {
  92.                 convert_error = ERROR_END;
  93.                 return 0.0;
  94.         }
  95.  
  96.         sign=1.0;
  97.         if (s[i] == '-')
  98.         {
  99.                 sign=-1.0;
  100.                 i++;
  101.         }
  102.         while (s[i] && s[i] >= '0' && s[i] <= '9')
  103.         {
  104.                 res *= 10.0;
  105.                 res += id(s[i] - '0');
  106.                 i++;
  107.         }
  108.         if (len) *len=i;
  109.         if (!s[i] || isalpha(s[i]))
  110.                 return sign*res;
  111.         if (s[i] != '.' && s[i] != ',')
  112.         {
  113.                 convert_error = ERROR;
  114.                 return 0;
  115.         }
  116.         i++;
  117.         if (len) *len=i;
  118.         if (!s[i])
  119.                 return sign*res;
  120.        
  121.         div = 1.0;
  122.         tail = 0.0;
  123.         while (s[i] && s[i] >= '0' && s[i] <= '9')
  124.         {
  125.                 tail *= 10.0;
  126.                 tail += id(s[i] - '0');
  127.                 div *= 10.0;
  128.                 i++;           
  129.         }
  130.         res += tail/div;
  131.         if (len) *len=i;
  132.         return sign*res;
  133. }
  134.  
  135. /*
  136. #define PREC 2
  137.  
  138. double double_tab[]={1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15};
  139.  
  140. // ýòî sprintf, óìåþùèé ôîðìàòèðîâàòü _òîëüêî_ âåùåñòâåííûå ÷èñëà (double) %f
  141. void format( char *Str, int len, char* Format, ... )
  142. {
  143.         int i, fmtlinesize, j, k, flag;
  144.         char c;
  145.         va_list arglist;
  146.         //
  147.         va_start(arglist, Format);
  148.  
  149.         //
  150.         fmtlinesize = strlen( Format );
  151.         //
  152.         if( fmtlinesize == 0 ) return;
  153.  
  154.         for (i = 0; i < len; i++)
  155.                 Str[i] = 0;
  156.  
  157.         //
  158.         for( i = 0, j = 0; i < fmtlinesize; i++ )
  159.         {
  160.                 //
  161.                 c = Format[i];
  162.                 //
  163.                 if( c != '%' )
  164.                 {
  165.                         Str[j++] = c;
  166.                         continue;
  167.                 }
  168.                 //
  169.                 i++;
  170.                 //
  171.                 if( i >= fmtlinesize ) break;
  172.  
  173.                 //
  174.                 flag = 0;
  175.                 //
  176.                 c = Format[i];
  177.                 //
  178.                 switch( c )
  179.                 {
  180.                 //
  181.                 case '%':
  182.                         Str[j++] = c;
  183.                         break;
  184.                 // auaia aauanoaaiiiai ?enea
  185.                 case 'f':
  186.                         // ii?aaaeeou ?enei oeo? ai oi?ee
  187.                         double val, w;
  188.                         int p;
  189.                         val = va_arg(arglist, double);
  190.                         if (val < 0.0)
  191.                         {
  192.                                 Str[j++] = '-';
  193.                                 val = -val;
  194.                         }
  195.                         for (k = 0; k < 15; k++)
  196.                                 if (val < double_tab[k])
  197.                                         break;
  198.  
  199.                         if (val < 1.0)
  200.                         {
  201.                                 Str[j++] = '0';
  202.                         }
  203.                        
  204.                         for (p = 1; p < k + 1; p++)
  205.                         {
  206.                                 Str[j++] = '0' + di(val / double_tab[k - p] - 0.499) % 10;
  207.                         }
  208.                         Str[j++] = '.';
  209.                         w = 0.1;
  210.                         for (p = 0; p < 2; p++)
  211.                         {
  212.                                 val-=floor(val);
  213.                                 Str[j++] = '0' + di(val / w - 0.499) % 10;
  214.                                 w /= 10.0;
  215.                         }
  216.  
  217.                 //
  218.                 default:
  219.                         break;
  220.                 }
  221.         }
  222.         //
  223.         Str[j] = 0;
  224. }
  225.  
  226. void *memcpy2(void *dst, const void *src, unsigned size)
  227. {
  228.         while (size--)
  229.                 *((char*)dst+size) = *((char*)src+size);
  230.         return dst;
  231. }
  232. */
  233.  
  234.  
  235.  
  236. int strcmp(const char *s1, const char *s2)
  237. {
  238.         int i;
  239.  
  240.         if (s1 == NULL)
  241.                 if (s2 == NULL)
  242.                         return 0;
  243.                 else
  244.                         return 1;
  245.         else
  246.                 if (s2 == NULL)
  247.                         return 1;
  248.  
  249.         for (i = 0;;i++)
  250.         {
  251.                 if (s1[i] == '\0')
  252.                         if (s2[i] == '\0')
  253.                                 return 0;
  254.                         else
  255.                                 return 1;
  256.                 else
  257.                         if (s2[i] == '\0')
  258.                                 return 1;
  259.                         else
  260.                         {
  261.                                 if (s1[i] != s2[i])
  262.                                         return 1;
  263.                         }
  264.         }
  265.         return 0;
  266. }
  267.  
  268. kol_struct_import* kol_cofflib_load(char *name)
  269. {
  270. //asm ("int $0x40"::"a"(68), "b"(19), "c"(name));
  271.         __asm
  272.         {
  273.                 mov eax, 68
  274.                 mov ebx, 19
  275.                 mov ecx, name
  276.                 int 0x40
  277.         }
  278. }
  279.  
  280.  
  281. void* kol_cofflib_procload (kol_struct_import *imp, char *name)
  282. {
  283.        
  284. int i;
  285. for (i=0;;i++)
  286.         if ( NULL == ((imp+i) -> name))
  287.                 break;
  288.         else
  289.                 if ( 0 == strcmp(name, (imp+i)->name) )
  290.                         return (imp+i)->data;
  291. return NULL;
  292.  
  293. }
  294.  
  295.  
  296. unsigned kol_cofflib_procnum (kol_struct_import *imp)
  297. {
  298.        
  299. unsigned i, n;
  300.  
  301. for (i=n=0;;i++)
  302.         if ( NULL == ((imp+i) -> name))
  303.                 break;
  304.         else
  305.                 n++;
  306.  
  307. return n;
  308.  
  309. }
  310.  
  311.  
  312. void kol_cofflib_procname (kol_struct_import *imp, char *name, unsigned n)
  313. {
  314.        
  315. unsigned i;
  316. *name = 0;
  317.  
  318. for (i=0;;i++)
  319.         if ( NULL == ((imp+i) -> name))
  320.                 break;
  321.         else
  322.                 if ( i == n )
  323.                         {
  324.                         strcpy(name, ((imp+i)->name));
  325.                         break;
  326.                         }
  327.  
  328. }
  329.  
  330.  
  331.  
  332. /*
  333. end of system part
  334. */
  335.  
  336.  
  337. // ïîñêîëüêó ÿ ïîðòèðîâàë ñ äðåâíåãî äîñà...
  338. void line( int x1, int y1, int x2, int y2)
  339. {
  340.         kos_DrawLine(x1,y1,x2,y2,SysColor,0);
  341. }
  342.  
  343. void outtextxy( int x, int y, char *s, int len)
  344. {
  345.         kos_WriteTextToWindow(x,y,0,SysColor,s,len);
  346. }
  347.  
  348. double textwidth( char *s, int len)
  349. {
  350.         int i;
  351.         for (i = 0; i < len; i++)
  352.                 if (s[i] == 0)
  353.                         break;
  354.         return id(i * 6);
  355. }
  356.  
  357. double textheight( char *s, int len)
  358. {
  359.         return 8.0;
  360. }
  361.  
  362. void setcolor( DWORD color)
  363. {
  364.         SysColor = color;
  365. }
  366.  
  367. void rectangle( int x1, int y1, int x2, int y2)
  368. {
  369.         kos_DrawBar(x1,y1,x2-x1,y2-y1,SysColor);
  370. }
  371.  
  372.  
  373.  
  374. Dword kos_GetSkinHeight()
  375. {
  376.         __asm{
  377.                 mov             eax, 48
  378.                 mov             ebx, 4
  379.                 int             0x40
  380.         }
  381. }
  382.  
  383. Dword kos_GetSpecialKeyState()
  384. {
  385.         __asm{
  386.                 mov             eax, 66
  387.                 mov             ebx, 3
  388.                 int             0x40
  389.         }
  390. }
  391.  
  392.  
  393.  
  394. Dword kos_GetSlotByPID(Dword PID)
  395. {
  396.         __asm
  397.         {
  398.                 push ebx
  399.                 push ecx
  400.                 mov eax, 18
  401.                 mov ebx, 21
  402.                 mov ecx, PID
  403.                 int     0x40
  404.                 pop ecx
  405.                 pop ebx
  406.         }
  407. }
  408.  
  409.  
  410. Dword kos_GetActiveSlot()
  411. {
  412.         __asm
  413.         {
  414.                 push ebx
  415.                 mov eax, 18
  416.                 mov ebx, 7
  417.                 int     0x40
  418.                 pop ebx
  419.         }
  420. }
  421.  
  422.  
  423.  
  424. void kos_GetScrollInfo(int &vert, int &hor)
  425. {
  426.         short v, h;
  427.         __asm
  428.         {
  429.                 mov eax, 37
  430.                 mov ebx, 7
  431.                 int     0x40
  432.                 mov ebx, eax
  433.                 and eax, 0xffff
  434.                 mov v, ax
  435.                 shr ebx, 16
  436.                 mov h, bx
  437.         }
  438.         vert = v;
  439.         hor = h;
  440. }
  441.  
  442.  
  443. // ïîëó÷åíèå èíôîðìàöèè î ñîñòîÿíèè "ìûøè" ôóíêöèÿ 37/1
  444. void kos_GetMouseStateWnd( Dword & buttons, int & cursorX, int & cursorY )
  445. {
  446.         Dword mB;
  447.         Word curX;
  448.         Word curY;
  449.         sProcessInfo sPI;
  450.  
  451.         //
  452.         __asm{
  453.                 mov             eax, 37
  454.                 mov             ebx, 1
  455.                 int             0x40
  456.                 mov             curY, ax
  457.                 shr             eax, 16
  458.                 mov             curX, ax
  459.                 mov             eax, 37
  460.                 mov             ebx, 2
  461.                 int             0x40
  462.                 mov             mB, eax
  463.         }
  464.         //
  465.         kos_ProcessInfo( &sPI );
  466.         //
  467.         buttons = mB;
  468.         cursorX = curX - sPI.processInfo.x_start;
  469.         cursorY = curY - sPI.processInfo.y_start;
  470. }
  471.  
  472. char *ftoa(double d)
  473. {
  474.         char buffer[256], *p;
  475.         sprintf(buffer, "%f", d);
  476.         p = (char*)allocmem(strlen(buffer)+1);
  477.         strcpy(p, buffer);
  478.         return p;
  479. }
  480.  
  481. double atof(char *s)
  482. {
  483.         return convert(s, NULL);
  484. }
  485.  
  486.  
  487. int di(double x)
  488. {
  489.         int a;
  490.         __asm fld x
  491.         __asm fistp a
  492.         return a;
  493. }
  494.  
  495. double id(int x)
  496. {
  497.         double a;
  498.         __asm fild x
  499.         __asm fstp a
  500.         return a;
  501. }
  502.