Subversion Repositories Kolibri OS

Rev

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

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