Subversion Repositories Kolibri OS

Rev

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