Subversion Repositories Kolibri OS

Rev

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