Subversion Repositories Kolibri OS

Rev

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