Subversion Repositories Kolibri OS

Rev

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

  1. #include "func.h"
  2. #include "parser.h"
  3. #include "use_library.h"
  4.  
  5. const char header[] = "Graph";
  6. const char empty_text[] = "No function loaded. Type file name and press Enter. ";
  7. const char er_file_not_found[] = "Cannot open file. ";
  8. const char str_filename[]="Filename:";
  9. const char str_editfile[]="Edit";
  10.  
  11. // íà÷àëüíûå ðàçìåðû
  12. #define WND_W 600
  13. #define WND_H 470
  14.  
  15. #define LIGHTGREEN 0xff0000
  16. #define WHITE 0xffffff
  17. #define BLACK 0x0
  18. #define LIGHTBLUE 0x0000ff
  19. #define LIGHTRED 0xff0000
  20.  
  21. // font colors
  22. #define BIGFONTCOLOR BLACK
  23. #define SMALLFONTCOLOR BLACK
  24.  
  25. #define THREE 3.0
  26. // minimum space: 3 pixels
  27.  
  28. #define BIG_HEIGHT 4.0
  29. #define SMALL_HEIGHT 2.0
  30. #define TEXT_X 15.0
  31. // numeric format for output
  32. #define FORMAT "%f"
  33. // format for two coords
  34. #define FORMAT_COORD "(%f,%f)"
  35. // special value to text if enough space
  36. #define FORMAT_TEST "0.00"
  37.  
  38. #define DELTA_BIG 1.0
  39. #define DELTA_SMALL 0.1
  40.  
  41. double *points;
  42. Dword point_count = 0;
  43. double x1,y1,x2,y2;
  44. char *funct = NULL;
  45.  
  46. char edit_path[1024];
  47. //Dword editbox_y = WND_H - 16, editbox_w = WND_W - 70;
  48. edit_box mybox = {0,9*8-5,WND_H - 16-32,0xffffff,0x94AECE,0,0x808080,0,sizeof(edit_path),0,(dword)&edit_path, 0, 0}; //100000000000010b};
  49.  
  50.  
  51. char *full_head;
  52.  
  53. char *HugeBuf = NULL;
  54.  
  55. //char fuck[64] = "$this is a fucking marker$";
  56. // ïàðàìåòðû êîìàíäíîé ñòðîêè
  57. #ifdef AUTOBUILD
  58. extern char params[1024];
  59. char params[1024];
  60. #else
  61. char params[1024] = "_FIND_ME_";
  62. #endif
  63.  
  64. /*
  65.  
  66.   fucking piece of shit
  67.  
  68.   */
  69.  
  70. // constructor of TCoord
  71. TCoord coord(double x, double y)
  72. {
  73.   TCoord r;
  74.   r.x = x;
  75.   r.y = y;
  76.   return r;
  77. }
  78.  
  79. // move and scale mathematical coords to fit screen coords
  80. TCoord mat2Graf(TCoord c, TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax)
  81. {
  82.   TCoord r;
  83.   if (c.x > mMax.x)
  84.     c.x = mMax.x;
  85.   if (c.x < mMin.x)
  86.     c.x = mMin.x;
  87.   if (c.y > mMax.y)
  88.     c.y = mMax.y;
  89.   if (c.y < mMin.y)
  90.     c.y = mMin.y;
  91.   r.x = (scrMax.x - scrMin.x) / (mMax.x - mMin.x) * (c.x - mMin.x) + scrMin.x;
  92.   r.y = (scrMax.y - scrMin.y) / (mMax.y - mMin.y) * (mMax.y - c.y) + scrMin.y;
  93.  
  94.   return r;
  95. }
  96.  
  97. // double-îáåðòêè
  98. void line_d( double x1, double y1, double x2, double y2)
  99. {
  100.    line(di(x1), di(y1), di(x2), di(y2));
  101. }
  102.  
  103. void outtextxy_d( double x, double y, char * text, int len)
  104. {
  105.    outtextxy(di(x), di(y), text, len);
  106. }
  107.  
  108. // huge function to draw all the stuff except the function itself
  109. void drawAxis( TCoord scrMin, TCoord scrMax, TCoord mMin, TCoord mMax)
  110. {
  111.   TCoord cZero={0.0,0.0},
  112.            gMin, gMax, gZero, step;
  113.   TCoord from, to;
  114.   double i=0.0;
  115.   int j;
  116.   double xmin, xmin2, ymin, ymin2;
  117.   char buf[30]="";
  118.  
  119.  
  120. // scr means Screen(bounding rect)
  121. // m   means Mathematical
  122. // g   means Graphic(real screen position)
  123.  
  124.   //rtlDebugOutString("draw axis called\n");
  125.  
  126.   //format(debuf, 30, "test: %f,%f,%f,%f\n", 123.45, 1.0, -0.9, 12.57);
  127.   //rtlDebugOutString(debuf);
  128.  
  129.   gMin = mat2Graf(mMin, scrMin, scrMax, mMin, mMax);
  130.   gMax = mat2Graf(mMax, scrMin, scrMax, mMin, mMax);
  131.   gZero = mat2Graf(cZero, scrMin, scrMax, mMin, mMax);
  132.  
  133.   // clear
  134.  // setcolor(WHITE);
  135.  //rectangle(di(gMin.x), di(gMin.y), di(gMax.x), di(gMax.y));
  136.   // ftopku
  137.  
  138.   setcolor(BLACK);
  139.   // osy X
  140.   line_d(gMin.x, gZero.y ,gMax.x, gZero.y);
  141.   // osy Y
  142.   line_d(gZero.x, gMin.y, gZero.x, gMax.y);
  143.   // bounding rect
  144.   line_d(gMin.x, gMin.y, gMax.x, gMin.y);
  145.   line_d(gMin.x, gMax.y, gMax.x, gMax.y);
  146.  
  147.   line_d(gMin.x, gMin.y, gMin.x, gMax.y);
  148.   line_d(gMax.x, gMin.y, gMax.x, gMax.y);
  149.  
  150.   // coords of the rect : lower left
  151.   format(buf, 30, FORMAT_COORD, x1, y1);
  152.   //rtlDebugOutString(buf);
  153.   outtextxy_d(gMin.x, gMin.y + textheight(buf, 20), buf, 20);
  154.   // upper left
  155.   format(buf, 30, FORMAT_COORD, x1, y2);
  156.   outtextxy_d(gMin.x, gMax.y - textheight(buf, 20), buf, 20);
  157.   // lower right
  158.   format(buf, 30, FORMAT_COORD, x2, y1);
  159.   outtextxy_d(gMax.x - textwidth(buf, 20), gMin.y + textheight(buf, 20), buf, 20);
  160.   // upper right
  161.   format(buf, 30, FORMAT_COORD, x2, y2);
  162.   outtextxy_d(gMax.x - textwidth(buf, 20), gMax.y - textheight(buf, 20), buf, 20);
  163.  
  164.   //rtlDebugOutString("some lines painted\n");
  165.  
  166.  
  167.   step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x);
  168.   step.y = (mMax.y - mMin.y) / (scrMax.y - scrMin.y);
  169.  
  170. // round values
  171.   xmin = id(di((mMin.x / DELTA_BIG) * DELTA_BIG));
  172.   ymin = id(di((mMin.y / DELTA_BIG) * DELTA_BIG));
  173.  
  174.   // (0,0)
  175.  
  176.   if ((x1 * x2 <= 0.0) && (y1 * y2 <= 0.0))
  177.   {
  178.           from.x=0.0;
  179.           from.y=0.0;
  180.           from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  181.           setcolor(BLACK);
  182.           format(buf, 30, FORMAT, 0.0);
  183.           outtextxy_d(from.x - textwidth(buf, 20), from.y + textheight(buf, 20), buf, 20);
  184.   }
  185.  
  186.  
  187.   // big marks on X
  188.   //settextstyle(0, 0, 1);
  189.   if (DELTA_BIG / step.x > THREE)
  190.   {
  191.     for (i = xmin; i <= mMax.x; i += DELTA_BIG)
  192.     {
  193.           if (i != 0.0)
  194.           {
  195.                   from.x = i;
  196.                   to.x = from.x;
  197.                   from.y = -BIG_HEIGHT * step.y;
  198.                   to.y = BIG_HEIGHT * step.y;
  199.                   from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  200.                   to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
  201.                   setcolor(BLACK);
  202.                   line_d(from.x, from.y, to.x, to.y);
  203.                   // write number
  204.                   format(buf, 30, FORMAT, i);
  205.                   // if it fits in the GAP, then write it
  206.                   if (from.y > scrMin.y && (DELTA_BIG > (textwidth(buf, 20) + 1.0) * step.x))
  207.                   {
  208.                            setcolor(BIGFONTCOLOR);
  209.                            outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20);
  210.                   }
  211.           }
  212.     }
  213.   }
  214.   //rtlDebugOutString("big marks x painted\n");
  215.  
  216.   // big marks on Y
  217.   if (DELTA_BIG / step.y > THREE)
  218.   {
  219.     for (i = ymin; i <= mMax.y; i += DELTA_BIG)
  220.     {
  221.           if (i != 0.0)
  222.           {
  223.                   from.y = i;
  224.                   to.y = from.y;
  225.                   from.x = -BIG_HEIGHT * step.x;
  226.                   to.x = BIG_HEIGHT * step.x;
  227.                   from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  228.                   to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
  229.                   setcolor(BLACK);
  230.                   line_d(from.x, from.y, to.x, to.y);
  231.                   format(buf, 30, FORMAT, i);
  232.                   if (from.x > scrMin.x && (DELTA_BIG > textheight(buf, 20) * step.y))
  233.                   {
  234.                            setcolor(BIGFONTCOLOR);
  235.                          outtextxy_d(from.x + TEXT_X, to.y - textheight(buf, 20) / 2.0, buf, 20);
  236.                   }
  237.           }
  238.     }
  239.   }
  240.  
  241.   xmin2 = id(di(mMin.x / DELTA_SMALL)) * DELTA_SMALL;
  242.   ymin2 = id(di(mMin.y / DELTA_SMALL)) * DELTA_SMALL;
  243.  
  244.   if (DELTA_SMALL / step.x  > THREE)
  245.   {
  246.     j = di((( - xmin + xmin2 ) / DELTA_SMALL));
  247.     for (i = xmin2; i <= mMax.x; i += DELTA_SMALL, j++)
  248.     {
  249.       if (j % 10 == 0)
  250.       {
  251.       // we need to skip every tenth mark, to avoid overwriting big marks
  252.                 j = 0;
  253.                 continue;
  254.       }
  255.       from.x = i;
  256.       to.x = from.x;
  257.       from.y = -SMALL_HEIGHT * step.y;
  258.       to.y = SMALL_HEIGHT * step.y;
  259.       from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  260.           to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
  261.       setcolor(BLACK);
  262.       line_d(from.x, from.y, to.x, to.y);
  263.       format(buf, 30, FORMAT, i);
  264.          
  265.       if (from.y > scrMin.y && (DELTA_SMALL > textwidth(buf, 20) * step.x))
  266.       {
  267.                 setcolor(SMALLFONTCOLOR);
  268.                 outtextxy_d(from.x - textwidth(buf, 20) / 2.0, to.y - textheight(buf, 20), buf, 20);
  269.       }
  270.          
  271.  
  272.     }
  273.      
  274.   }
  275.  
  276.   // finally small marks on Y
  277.   if (DELTA_SMALL / step.y > THREE)
  278.   {
  279.     //rtlDebugOutString("really small marks y painted\n");
  280.     j = di((( - ymin + ymin2) / DELTA_SMALL));
  281.     for (i = ymin2; i <= mMax.y; i += DELTA_SMALL, j++)
  282.     {
  283.       if (j % 10 == 0)
  284.       {
  285.       // we need to skip every tenth, to avoid overwriting
  286.                 j = 0;
  287.                 continue;
  288.       }
  289.       from.y = i;
  290.       to.y = from.y;
  291.       from.x = -SMALL_HEIGHT * step.x;
  292.       to.x = SMALL_HEIGHT * step.x;
  293.       from = mat2Graf(from, scrMin, scrMax, mMin, mMax);
  294.       to = mat2Graf(to, scrMin, scrMax, mMin, mMax);
  295.       setcolor(BLACK);
  296.       line_d(from.x, from.y, to.x, to.y);
  297.       format(buf, 30, FORMAT, i);
  298.       if (from.x > scrMin.x && (DELTA_SMALL > textheight(buf, 20) * step.y))
  299.       {
  300.         setcolor(SMALLFONTCOLOR);
  301.         outtextxy_d(from.x + TEXT_X, from.y - textheight(buf, 20) / 2.0, buf, 20);
  302.       }
  303.     }
  304.   }
  305.  
  306. }
  307.  
  308. /*
  309.   ends fucking piece of shit
  310. */
  311.  
  312. void drawFunction( function_t fi, TCoord scrMin, TCoord scrMax,
  313.                    TCoord mMin, TCoord mMax, DWORD color)
  314. {
  315.   double x;
  316.   double y;
  317.   int firstPoint = 1;
  318.   TCoord p, p0 = {0.0, 0.0}, step;
  319.  
  320.   drawAxis(scrMin, scrMax, mMin, mMax);
  321.  
  322.   setcolor(color);
  323.   step.x = (mMax.x - mMin.x) / (scrMax.x - scrMin.x);
  324.  
  325.   for (x = mMin.x; x < mMax.x; x += step.x)
  326.   {
  327.     y = fi(x);
  328. // function is defined here and gets in the range
  329.     if (1) // òóò áûëî óñëîâèå, ÷òî ôóíêöèÿ ïðàâèëüíî âû÷èñëåíà
  330.     {
  331.       if ((y > mMin.y) && (y < mMax.y))
  332.       {
  333.               p = mat2Graf(coord(x, y), scrMin, scrMax, mMin, mMax);
  334.         // if it's our first point, only remember its coords
  335.         // otherwise, draw a line_d from prev to current
  336.         if (firstPoint == 0)
  337.         {
  338.           line_d(p0.x, p0.y, p.x, p.y);
  339.         }
  340.         else
  341.           firstPoint = 0;
  342.  
  343.         p0 = p;
  344.       }
  345.       else // too big/small
  346.       {
  347.               firstPoint = 1;
  348.       }
  349.     }
  350.     else // no value
  351.     {
  352.       firstPoint = 1;
  353.     }
  354.   }
  355.  
  356. }
  357.  
  358. struct kosBDVK
  359. {
  360.         Dword attrib;
  361.         Dword name_type;
  362.         Dword create_time;
  363.         Dword create_date;
  364.         Dword access_time;
  365.         Dword access_date;
  366.         Dword modify_time;
  367.         Dword modify_date;
  368.         Dword size_low;
  369.         Dword size_high;       
  370. };
  371.  
  372. // èòîãîâàÿ âåðñèÿ ÷èòàëêè òåêñòîâûõ ôàéëîâ
  373. int load_points3()
  374. {
  375.         kosFileInfo fileInfo;
  376.         kosBDVK bdvk;
  377.         int filePointer = 0;
  378.  
  379.         int i,j,k;
  380.         double d;
  381.         Dword filesize, num_number;
  382.  
  383.         double *p2;
  384.  
  385.         if (edit_path[0] == '\0')
  386.                 return 0;
  387.  
  388.         // get file size
  389.         strcpy(fileInfo.fileURL,edit_path);
  390.         fileInfo.OffsetLow = 0;
  391.         fileInfo.OffsetHigh = 0;
  392.         fileInfo.dataCount = 0;
  393.         fileInfo.rwMode = 5;
  394.         fileInfo.bufferPtr = (Byte *)&bdvk;
  395.         Dword rr = kos_FileSystemAccess( &(fileInfo) ); // â CKosFile íåò îïðåäåëåíèÿ ðàçìåðà
  396.         sprintf(debuf, "getsize: %U\n", rr);
  397.         rtlDebugOutString(debuf);
  398.         if (rr != 0)
  399.         {
  400.                 kos_WriteTextToWindow(10,10,0,0x00,(char*)er_file_not_found,strlen(er_file_not_found));
  401.                 return 0;
  402.         }
  403.  
  404.         filesize = bdvk.size_low;
  405.         num_number = filesize / 2;
  406.  
  407.         HugeBuf = (char *)allocmem(filesize + 1); // ðàçáèðàåì êàê ñòðîêó, îòñþäà òåðìèíàòîð \0
  408.  
  409.         for (i=0;i<filesize+1;i++)
  410.                 HugeBuf[i] = 0;
  411.  
  412.         strcpy(fileInfo.fileURL,edit_path);
  413.         fileInfo.OffsetLow = 0;
  414.  
  415.         fileInfo.OffsetHigh = 0;
  416.         fileInfo.dataCount = filesize;
  417.         fileInfo.rwMode = 0;
  418.         fileInfo.bufferPtr = (Byte *)HugeBuf;
  419.         rr = kos_FileSystemAccess( &(fileInfo) );       // êàêàÿ-òî ïðîáëåìà ñ hands.dll, CKosFile íå ðàáîòàë
  420.                
  421.         sprintf(debuf, "read3: %U\n", rr);
  422.         rtlDebugOutString(debuf);
  423.  
  424.         strcpy(full_head, header);
  425.         strcpy(full_head+strlen(full_head), " - ");
  426.         strcpy(full_head+strlen(full_head), edit_path);         // bad code
  427.  
  428.         // à òåïåðü ðàçîáðàòüñÿ â ýòîì
  429.  
  430.         i=0;
  431.         k=0;
  432.         while (i < filesize)
  433.         {
  434.  
  435.                 while (isalpha(HugeBuf[i]) && i<filesize) i++;
  436.                 if (i == filesize) break;
  437.                 if (k==4 && HugeBuf[i] == '=')
  438.                 {
  439.                         //sprintf(debuf,"function: %S",HugeBuf + i);
  440.                         //rtlDebugOutString(debuf);
  441.                         // we have a function here
  442.                         //HugeBuf[0] = ' ';
  443.                         funct = HugeBuf + i + 1;
  444.                         strcpy(full_head+strlen(full_head), ". Function y=");
  445.                         strcpy(full_head+strlen(full_head), funct);
  446.                         return 1;
  447.                 }
  448.  
  449.                 d = convert(HugeBuf+i, &j);
  450.                 if (d == ERROR)
  451.                 {
  452.                         sprintf(debuf, "Error in input file, byte %U, count %U\n", i, k);
  453.                         rtlDebugOutString(debuf);
  454.                         kos_WriteTextToWindow(10, 10, 0, 0x00, (char*)debuf, strlen(debuf));
  455.                         return 0;
  456.                 }
  457.                 if (d == ERROR_END)
  458.                 {
  459.                         rtlDebugOutString("EOF :)!\n");
  460.                         break;
  461.                 }
  462.                
  463.                 i+=j;
  464.                 switch (k)
  465.                 {
  466.                 case 0:
  467.                         x1=d;
  468.                         break;
  469.                 case 1:
  470.                         x2=d;
  471.                         break;
  472.                 case 2:
  473.                         y1=d;
  474.                         break;
  475.                 case 3:
  476.                         y2=d;
  477.                         break;
  478.                 default:
  479.                         {
  480.                                 if (p2 == NULL)
  481.                                         p2 = (double *)allocmem(num_number * 8);
  482.                                 p2[k-4]=d;
  483.                         }
  484.                 }
  485.                 k++;
  486.         }
  487. //      format(debuf, 30, "(%f,%f)-(%f,%f)",x1,y1,x2,y2);
  488. //      rtlDebugOutString(debuf);
  489.         point_count=(k - 4)/2;
  490.  
  491.         //
  492.         points = (double *)allocmem(point_count * 2 * 8);
  493.         for (i = 0; i < point_count * 2; i++)
  494.                 points[i] = p2[i];
  495.         freemem(p2);
  496. //      sprintf(debuf, "count: %U\n", point_count);
  497. //      rtlDebugOutString(debuf);
  498.         sprintf(debuf, ". Number of points: %U.", point_count);
  499.         strcpy(full_head+strlen(full_head), debuf);
  500.         freemem(HugeBuf);
  501.         HugeBuf = NULL;
  502.         return 1;
  503. }
  504.  
  505. void LaunchTinypad()
  506. {
  507.         kosFileInfo fileInfo;
  508.  
  509.         strcpy(fileInfo.fileURL,"/sys/tinypad");
  510.         fileInfo.OffsetLow = 0;
  511.         fileInfo.OffsetHigh = (Dword)edit_path;
  512.         fileInfo.rwMode = 7;    // launch
  513.         kos_FileSystemAccess(&fileInfo);
  514.  
  515. }
  516.  
  517. // âû÷èñëèòü çàäàííóþ ôóíêöèþ èëè êóñî÷íî-ëèíåéíóþ ìåæäó òî÷êàìè
  518. double fu(double x)
  519. {
  520.         int i;
  521.         double res;
  522.  
  523.        
  524.         if (funct)
  525.         {
  526.                 set_exp(funct,x);
  527.                 get_exp(&res);          // ïàðñèòü äëÿ êàæäîãî çíà÷åíèÿ õ? äà ÿ ñ óìà ñîøåë.
  528.                 return res;
  529.         }
  530.  
  531.         if (point_count == 0)
  532.         {
  533.                 return 0.0;
  534.         }
  535.  
  536.         if (x <= points[0])
  537.                 return points[1];
  538.         if (x >= points[(point_count-1) * 2])
  539.                 return points[(point_count-1) * 2 + 1];
  540.  
  541.         for (i = 0; i < point_count; i++)
  542.         {
  543.                 if ((x >= points[2 * i]) && (x < points[2 * (i + 1)]))
  544.                         break;
  545.         }
  546.  
  547.         return (x - points[2 * i]) / (points[2 * (i + 1)] - points[2 * i])
  548.                 * (points[2 * (i + 1) + 1] - points[2 * i + 1]) + points[2 * i + 1];
  549.  
  550. }
  551.  
  552. void draw_window(void)
  553. {
  554.         double xx0=0.0, yy0=0.0;
  555.         sProcessInfo info;
  556.         Dword wi, he;
  557.         void *p;
  558.  
  559.         for (int i = 0; i < 1024; i++)
  560.                 info.rawData[i] = 0;
  561.         kos_ProcessInfo(&info, 0xFFFFFFFF);
  562.  
  563.         p = info.rawData + 42;                  // magic
  564.         wi = *(Dword *)(p);
  565.         he = *(Dword *)((Byte *)p + 4);
  566.  
  567.         if (wi == 0)
  568.                 wi = WND_W;
  569.         if (he == 0)
  570.                 he = WND_H;
  571.  
  572.         mybox.top = he - 50;
  573.         mybox.width = wi - mybox.left - 80;
  574.  
  575.         kos_WindowRedrawStatus(1);
  576.         kos_DefineAndDrawWindow(10,40,WND_W,WND_H, 0x33,0xFFFFFF,0,0,(Dword)full_head);
  577.         kos_WindowRedrawStatus(2);
  578.  
  579.         if (info.rawData[70]&0x04) return; //íè÷åãî íå äåëàòü åñëè îêíî ñõëîïíóòî â çàãîëîâîê
  580.  
  581.         if (point_count == 0 && funct == NULL)
  582.         {
  583.                 kos_WriteTextToWindow((wi - 6 * strlen(empty_text))/2,he/2,0,0x000000,(char *)empty_text,strlen(empty_text));
  584.         }
  585.         else
  586.         {
  587.                 drawFunction(&fu, coord(10, 20), coord(id(wi - 20), id(he - 70)),
  588.                                                         coord(x1,y1), coord(x2,y2), 0x00ff0000);
  589.  
  590.         }
  591.  
  592.         kos_WriteTextToWindow(4, mybox.top + 4, 0, 0, (char*)str_filename, strlen(str_filename));
  593.  
  594.         if ((void*)edit_box_draw != NULL)
  595.                 edit_box_draw((DWORD)&mybox);
  596.  
  597.         kos_DefineButton(wi - 70, mybox.top, 50, 12, 5, 0xc0c0c0);
  598.         kos_WriteTextToWindow(wi - 58, mybox.top + 4, 0, 0, (char*)str_editfile, strlen(str_editfile));
  599.  
  600. }
  601.  
  602. void kos_Main()
  603. {
  604.         kos_InitHeap();
  605.         full_head = (char*)allocmem(300);
  606.         strcpy(full_head, "Graph");
  607.         load_edit_box();
  608.         if (params[0]) // fuck[0] for debug
  609.         {
  610.                 rtlDebugOutString("launched with params");
  611.                 rtlDebugOutString((char*)params);
  612.                 strcpy(edit_path, params);
  613.                 mybox.size=mybox.pos=strlen(edit_path);
  614.                 //rtlDebugOutString((char*)edit_path);
  615.                 load_points3();
  616.         }
  617.         rtlDebugOutString("data loaded.\n");
  618.         draw_window();
  619.         for (;;)
  620.         {
  621.                 edit_box_mouse((dword)&mybox);
  622.                 switch (kos_WaitForEvent())
  623.                 {
  624.                 case 1:
  625.                         draw_window();
  626.                         break;
  627.                 case 2:
  628.                         // key pressed, read it
  629.                         Byte keyCode;
  630.                         kos_GetKey(keyCode);
  631.  
  632.                         switch (keyCode)
  633.                                 {
  634.                                         case 0x0D:
  635.                                                         if (HugeBuf!=NULL)
  636.                                                         {
  637.                                                                 //sprintf(debuf, "freemem: HugeBuf = %X", HugeBuf);
  638.                                                                 //rtlDebugOutString(debuf);
  639.                                                                 freemem((void*)HugeBuf);                // ÷òî çà áàã - ïîíÿòü íå ìîãó.
  640.                                                                 HugeBuf = NULL;
  641.                                                                 funct = NULL;
  642.                                                         }
  643.                                                         if (points!=NULL)
  644.                                                         {
  645.                                                                 //sprintf(debuf, "freemem: points = %X", points);
  646.                                                                 //rtlDebugOutString(debuf);
  647.                                                                 freemem((void*)points);         // è òóò. íó íå îáðàùàþñü ÿ ê ýòîìó óêàçàòåëþ, òîëüêî ïàìÿòü â íåãî
  648.                                                                                                                 // ïîòîì ñíîâà âûäåëÿþ
  649.                                                                 points = NULL;
  650.                                                         }
  651.                                                         point_count = 0;
  652.                                                         kos_DrawBar(10,10,200,20,0xFFFFFF); // ôîí äëÿ ñîîáùåíèé îá îøèáêàõ
  653.                                                         if (load_points3())
  654.                                                                 draw_window();
  655.                                                         break;
  656.                                         default:
  657.                                                 {
  658.                                                         __asm
  659.                                                         {
  660.                                                                 mov ah, keyCode
  661.                                                         }
  662.                                                         edit_box_key((dword)&mybox);
  663.                                                 }
  664.                                 }
  665.                         break;
  666.  
  667.  
  668.                 case 3:
  669.                         // button pressed; we have only one button, close
  670.                         Dword button;
  671.                         kos_GetButtonID(button);
  672.                         if (button == 1)
  673.                                 kos_ExitApp();
  674.                         if (button == 5)
  675.                                 LaunchTinypad();
  676.                 }
  677.         }
  678. }
  679.  
  680.