Subversion Repositories NedoOS

Rev

Rev 2334 | Blame | Compare with Previous | Last modification | View Log | Download

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <intrz80.h>
  4. #include <stdlib.h>
  5. #include <oscalls.h>
  6. #include <../common/terminal.c>
  7. #include <tcp.h>
  8. #include <osfs.h>
  9. #include <graphic.h>
  10. #include <ctype.h>
  11. #include <math.h>
  12. //
  13. #define true 1
  14. #define false 0
  15. #define screenHeight 23
  16. #define screenWidth 80
  17.  
  18. unsigned int RBR_THR = 0xf8ef;
  19. unsigned int IER = 0xf9ef;
  20. unsigned int IIR_FCR = 0xfaef;
  21. unsigned int LCR = 0xfbef;
  22. unsigned int MCR = 0xfcef;
  23. unsigned int LSR = 0xfdef;
  24. unsigned int MSR = 0xfeef;
  25. unsigned int SR = 0xffef;
  26. unsigned int divider = 1;
  27. unsigned char comType = 0;
  28. unsigned int espType = 32;
  29. unsigned char netDriver = 0;
  30. unsigned char curHost;
  31. unsigned long contLen;
  32. unsigned int httpErr;
  33.  
  34. unsigned char uVer[] = "0.4";
  35. unsigned char curPath[128];
  36. unsigned char cmd[256];
  37. unsigned char search[256];
  38. unsigned char crlf[2] = {13, 10};
  39. const unsigned char gotWiFi[] = "WIFI GOT IP";
  40. char hosts[3][32] = {"next.zxart.ee", "zxdb.remysharp.com", "hood.speccy.cz"};
  41. unsigned char userAgent1[] = " HTTP/1.1\r\nHost: ";
  42. unsigned char userAgent2[] = "\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS; ZXDB)\r\n\r\n\0";
  43. unsigned char netbuf[8192];
  44. unsigned char buf[16384];
  45. struct sockaddr_in targetadr;
  46. struct readstructure readStruct;
  47. struct sockaddr_in dnsaddress;
  48.  
  49. struct window
  50. {
  51.         unsigned char x;
  52.         unsigned char y;
  53.         unsigned char w;
  54.         unsigned char h;
  55.         unsigned char text;
  56.         unsigned char back;
  57.         unsigned char tittle[80];
  58. } curWin;
  59.  
  60. struct time
  61. {
  62.         unsigned int hours;
  63.         unsigned int minutes;
  64.         unsigned char oldMinutes;
  65.  
  66. } clock;
  67.  
  68. struct linkStruct
  69. {
  70.         unsigned char host[128];
  71.         unsigned char path[512];
  72.         unsigned int port;
  73.         unsigned char hasName;
  74.         unsigned char fname[256];
  75. } link;
  76.  
  77. struct line
  78. {
  79.         unsigned long id;
  80.         unsigned char name[512];
  81.         unsigned char file[512];
  82.         unsigned char ext[5];
  83.         unsigned long size;
  84.         unsigned char option;
  85.         unsigned int year;
  86. } table[12];
  87.  
  88. struct limit
  89. {
  90.         int first;
  91.         int second;
  92.         int total;
  93.         int curline;
  94.         int curOpt;
  95.         int headLng;
  96.         int curPage;
  97. } limiter;
  98.  
  99. void spaces(unsigned char number)
  100. {
  101.         while (number > 0)
  102.         {
  103.                 putchar(' ');
  104.                 number--;
  105.         }
  106. }
  107.  
  108. void waitKey(void)
  109. {
  110.         do
  111.         {
  112.                 YIELD();
  113.         } while (OS_GETKEY() == 0);
  114. }
  115.  
  116. void clearStatus(void)
  117. {
  118.         OS_SETCOLOR(5);
  119.         OS_SETXY(0, 24);
  120.         spaces(79);
  121.         putchar('\r');
  122. }
  123.  
  124. void quit(void)
  125. {
  126.         OS_CLS(0);
  127.         OS_SETGFX(-1);
  128.         exit(0);
  129. }
  130.  
  131. void printTable(void)
  132. {
  133.         unsigned int cycle;
  134.  
  135.         for (cycle = 1; cycle < 256; cycle++)
  136.         {
  137.                 OS_SETCOLOR(7);
  138.                 printf("%03u:", cycle);
  139.                 OS_SETCOLOR(71);
  140.                 putchar(cycle);
  141.                 OS_SETCOLOR(7);
  142.                 printf(" ");
  143.                 if (cycle % 12 == 0)
  144.                 {
  145.                         printf("\r\n");
  146.                 }
  147.         }
  148. }
  149.  
  150. void delay(unsigned long counter)
  151. {
  152.         unsigned long start, finish;
  153.         counter = counter / 20;
  154.         if (counter < 1)
  155.         {
  156.                 counter = 1;
  157.         }
  158.         start = time();
  159.         finish = start + counter;
  160.  
  161.         while (start < finish)
  162.         {
  163.                 start = time();
  164.         }
  165. }
  166.  
  167. ///////////////////////////
  168. #include <../common/esp-com.c>
  169. #include <../common/network.c>
  170. //////////////////////////
  171.  
  172. void clearNetbuf(void)
  173. {
  174.         unsigned int counter;
  175.         for (counter = 0; counter < sizeof(netbuf); counter++)
  176.         {
  177.                 netbuf[counter] = 0;
  178.         }
  179. }
  180.  
  181. int testOperation2(const char *process, int socket)
  182. {
  183.         if (socket < 0)
  184.         {
  185.                 printf("%s: [ERROR:", process);
  186.                 errorPrint(-socket);
  187.                 printf("]\r\n");
  188.                 YIELD();
  189.                 return -socket;
  190.         }
  191.         return 1;
  192. }
  193.  
  194. unsigned char saveBuf(unsigned char *fileNamePtr, unsigned char operation, unsigned int sizeOfBuf)
  195. {
  196.         FILE *fp2;
  197.  
  198.         switch (operation)
  199.         {
  200.         case 00:
  201.                 fp2 = OS_CREATEHANDLE(fileNamePtr, 0x80);
  202.                 if (((int)fp2) & 0xff)
  203.                 {
  204.                         clearStatus();
  205.                         printf("%s  creating error.", fileNamePtr);
  206.                         getchar();
  207.                         exit(0);
  208.                 }
  209.                 OS_CLOSEHANDLE(fp2);
  210.                 break;
  211.         case 01:
  212.                 fp2 = OS_OPENHANDLE(fileNamePtr, 0x80);
  213.                 if (((int)fp2) & 0xff)
  214.                 {
  215.                         clearStatus();
  216.                         printf("%s opening error.\r\n ", fileNamePtr);
  217.                         getchar();
  218.                         exit(0);
  219.                 }
  220.                 OS_SEEKHANDLE(fp2, OS_GETFILESIZE(fp2));
  221.                 OS_WRITEHANDLE(netbuf + limiter.headLng, fp2, sizeOfBuf);
  222.                 OS_CLOSEHANDLE(fp2);
  223.                 break;
  224.         case 02:
  225.                 OS_CLOSEHANDLE(fp2);
  226.                 break;
  227.         default:
  228.                 break;
  229.         }
  230.  
  231.         return 0;
  232. }
  233.  
  234. void drawClock(void)
  235. {
  236.         unsigned long dosTime;
  237.         dosTime = OS_GETTIME();
  238.         clock.hours = dosTime >> 11 & 31;        // 0b00011111
  239.         clock.minutes = (dosTime >> 5) & 63; // 0b00111111
  240.  
  241.         if (clock.minutes != clock.oldMinutes)
  242.         {
  243.                 clock.oldMinutes = clock.minutes;
  244.                 OS_SETCOLOR(103);
  245.                 OS_SETXY(73, 0);
  246.                 printf("[%02u:%02u]", clock.hours, clock.minutes);
  247.         }
  248. }
  249.  
  250. void drawPage(void)
  251. {
  252.         OS_SETCOLOR(103);
  253.         OS_SETXY(64, 0);
  254.         printf("[Page:%2d]", limiter.curPage);
  255. }
  256.  
  257. char readParamFromIni(void)
  258. {
  259.         FILE *fpini;
  260.         unsigned char *count1;
  261.         const char currentNetwork[] = "currentNetwork";
  262.         unsigned char curNet = 0;
  263.  
  264.         OS_GETPATH((unsigned int)&curPath);
  265.         OS_SETSYSDRV();
  266.         OS_CHDIR("/");
  267.         OS_CHDIR("ini");
  268.  
  269.         fpini = OS_OPENHANDLE("network.ini", 0x80);
  270.         if (((int)fpini) & 0xff)
  271.         {
  272.                 clearStatus();
  273.                 printf("network.ini not found.\r\n");
  274.                 getchar();
  275.                 return false;
  276.         }
  277.  
  278.         OS_READHANDLE(netbuf, fpini, sizeof(netbuf) - 1);
  279.         OS_CLOSEHANDLE(fpini);
  280.  
  281.         count1 = strstr(netbuf, currentNetwork);
  282.         if (count1 != NULL)
  283.         {
  284.                 sscanf(count1 + strlen(currentNetwork) + 1, "%u", &curNet);
  285.         }
  286.  
  287.         OS_CHDIR(curPath);
  288.         return curNet;
  289. }
  290.  
  291. void init(void)
  292. {
  293.         targetadr.family = AF_INET;
  294.         targetadr.porth = 00;
  295.         targetadr.portl = 80;
  296.         targetadr.b1 = 0;
  297.         targetadr.b2 = 0;
  298.         targetadr.b3 = 0;
  299.         targetadr.b4 = 0;
  300.         curHost = 0;
  301.         link.port = 80;
  302.         link.hasName = false;
  303.         limiter.curOpt = 1;
  304.         limiter.curPage = 0;
  305.         get_dns();
  306.         netDriver = readParamFromIni();
  307.         if (netDriver == 1)
  308.         {
  309.                 loadEspConfig();
  310.                 uart_init(divider);
  311.                 espReBoot();
  312.         }
  313.         OS_SETSYSDRV();
  314.         OS_MKDIR("../downloads");          // Create if not exist
  315.         OS_MKDIR("../downloads/zxdb"); // Create if not exist
  316.         OS_CHDIR("../downloads/zxdb");
  317.  
  318.         strcpy(link.host, hosts[curHost]);
  319.         clock.oldMinutes = 255;
  320. }
  321.  
  322. void errorBox(struct window w, const char *message)
  323. {
  324.         unsigned char wcount, tempx, tittleStart;
  325.  
  326.         w.h++;
  327.         OS_SETXY(w.x, w.y - 1);
  328.         BDBOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
  329.         OS_SETXY(w.x, w.y);
  330.         OS_SETCOLOR(w.text);
  331.         putchar(201);
  332.         for (wcount = 0; wcount < w.w; wcount++)
  333.         {
  334.                 putchar(205);
  335.         }
  336.         putchar(187);
  337.         OS_SETXY(w.x, w.y + w.h);
  338.         putchar(200);
  339.         for (wcount = 0; wcount < w.w; wcount++)
  340.         {
  341.                 putchar(205);
  342.         }
  343.         putchar(188);
  344.  
  345.         tempx = w.x + w.w + 1;
  346.         for (wcount = 1; wcount < w.h; wcount++)
  347.         {
  348.                 OS_SETXY(w.x, w.y + wcount);
  349.                 putchar(186);
  350.                 OS_SETXY(tempx, w.y + wcount);
  351.                 putchar(186);
  352.         }
  353.         tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2);
  354.         OS_SETXY(tittleStart, w.y);
  355.         printf("[%s]", w.tittle);
  356.         OS_SETXY(w.x + 1, w.y + 1);
  357.         OS_SETCOLOR(w.back);
  358.         tittleStart = w.x + (w.w / 2) - (strlen(message) / 2);
  359.         OS_SETXY(tittleStart, w.y + 1);
  360.         printf("%s", message);
  361. }
  362.  
  363. void simpleBox(struct window w)
  364. {
  365.         unsigned char wcount, tempx;
  366.         w.h = w.h - 2;
  367.         OS_SETXY(w.x, w.y);
  368.         BDBOX(w.x, w.y + 1, w.w, w.h, w.back, 32);
  369.         w.w = w.w - 2;
  370.         OS_SETXY(w.x, w.y);
  371.         OS_SETCOLOR(w.text);
  372.         putchar(201);
  373.         for (wcount = 0; wcount < w.w; wcount++)
  374.         {
  375.                 putchar(205);
  376.         }
  377.         putchar(187);
  378.  
  379.         OS_SETXY(w.x, w.y + w.h);
  380.         putchar(200);
  381.         for (wcount = 0; wcount < w.w; wcount++)
  382.         {
  383.                 putchar(205);
  384.         }
  385.         putchar(188);
  386.         tempx = w.x + w.w + 1;
  387.         for (wcount = 1; wcount < w.h; wcount++)
  388.         {
  389.                 OS_SETXY(w.x, w.y + wcount);
  390.                 putchar(186);
  391.                 OS_SETXY(tempx, w.y + wcount);
  392.                 putchar(186);
  393.         }
  394. }
  395.  
  396. unsigned char inputBox(struct window w, const char *prefilled)
  397. {
  398.         unsigned char wcount, tempx, tittleStart;
  399.         unsigned char byte, counter;
  400.         w.h++;
  401.         OS_SETXY(w.x, w.y - 1);
  402.         BDBOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
  403.         OS_SETXY(w.x, w.y);
  404.         OS_SETCOLOR(w.text);
  405.         putchar(201);
  406.         for (wcount = 0; wcount < w.w; wcount++)
  407.         {
  408.                 putchar(205);
  409.         }
  410.         putchar(187);
  411.         OS_SETXY(w.x, w.y + w.h);
  412.         putchar(200);
  413.         for (wcount = 0; wcount < w.w; wcount++)
  414.         {
  415.                 putchar(205);
  416.         }
  417.         putchar(188);
  418.  
  419.         tempx = w.x + w.w + 1;
  420.         for (wcount = 1; wcount < w.h; wcount++)
  421.         {
  422.                 OS_SETXY(w.x, w.y + wcount);
  423.                 putchar(186);
  424.                 OS_SETXY(tempx, w.y + wcount);
  425.                 putchar(186);
  426.         }
  427.         tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2);
  428.         OS_SETXY(tittleStart, w.y);
  429.         printf("[%s]", w.tittle);
  430.         OS_SETXY(w.x + 1, w.y + 1);
  431.         OS_SETCOLOR(w.back);
  432.         putchar(219);
  433.  
  434.         cmd[0] = 0;
  435.  
  436.         counter = strlen(prefilled);
  437.         if (counter != 0)
  438.         {
  439.                 strcpy(cmd, prefilled);
  440.                 goto skipKeys;
  441.         }
  442.  
  443.         do
  444.         {
  445.                 byte = OS_GETKEY();
  446.                 /*
  447.                 clearStatus();
  448.                 OS_SETCOLOR(103);
  449.                 printf("key = %u", byte);
  450.                 */
  451.                 if (byte != 0)
  452.                 {
  453.                         switch (byte)
  454.                         {
  455.                         case 0x08:
  456.                                 if (counter > 0)
  457.                                 {
  458.                                         counter--;
  459.                                         cmd[counter] = 0;
  460.                                 }
  461.                                 break;
  462.                         case 0x0d:
  463.  
  464.                                 if (counter == 0)
  465.                                 {
  466.                                         return false;
  467.                                 }
  468.                                 else
  469.                                 {
  470.                                         return true;
  471.                                 }
  472.  
  473.                         case 31:
  474.                                 break;
  475.                         case 250:
  476.                                 break;
  477.                         case 249:
  478.                                 break;
  479.                         case 248:
  480.                                 break;
  481.                         case 251: // Right
  482.                                 break;
  483.                         case 252: // Del
  484.                                 OS_SETXY(w.x + 1, w.y + 1);
  485.                                 spaces(counter + 1);
  486.                                 cmd[0] = 0;
  487.                                 counter = 0;
  488.                                 break;
  489.                         case 27:
  490.                                 cmd[0] = 0;
  491.                                 return false;
  492.  
  493.                         default:
  494.                                 if (counter < w.w - 1)
  495.                                 {
  496.                                         cmd[counter] = byte;
  497.                                         counter++;
  498.                                         cmd[counter] = 0;
  499.                                 }
  500.                                 break;
  501.                         }
  502.                 skipKeys:
  503.                         OS_SETXY(w.x + 1, w.y + 1);
  504.                         printf("%s", cmd);
  505.                         putchar(219);
  506.                         if (byte == 0x08)
  507.                         {
  508.                                 putchar(' ');
  509.                         }
  510.                 }
  511.                 YIELD();
  512.         } while (42);
  513.         return false;
  514. }
  515.  
  516. void sendReqdialog(void)
  517. {
  518.         curWin.w = 50;
  519.         curWin.x = 39 - curWin.w / 2;
  520.         curWin.y = 10;
  521.         curWin.h = 4;
  522.         curWin.text = 223;
  523.         curWin.back = 223;
  524.         simpleBox(curWin);
  525.         OS_SETXY(30, curWin.y + 1);
  526.         printf("Sending request...");
  527. }
  528.  
  529. void tittleDraw(void)
  530. {
  531.         clock.oldMinutes = 255;
  532.         OS_SETCOLOR(103);
  533.         OS_SETXY(0, 0);
  534.         spaces(79);
  535.         OS_SETXY(0, 0);
  536.         printf(" ZXDB downloader [%s]", uVer);
  537.         OS_SETXY(38 - strlen(link.host) / 2, 0);
  538.         printf("[");
  539.         OS_SETCOLOR(102);
  540.         printf("%s", link.host);
  541.         OS_SETCOLOR(103);
  542.         printf("]");
  543.         drawPage();
  544.         drawClock();
  545. }
  546. void drawSearch(void)
  547. {
  548.         OS_SETCOLOR(207);
  549.         OS_SETXY(38 - strlen(search) / 2, 1);
  550.         putchar('[');
  551.         OS_SETCOLOR(71);
  552.         printf("%s", search);
  553.         OS_SETCOLOR(curWin.text);
  554.         OS_SETCOLOR(207);
  555.         putchar(']');
  556. }
  557.  
  558. void mainWinDraw(void)
  559. {
  560.         tittleDraw();
  561.         OS_SETXY(0, 23);
  562.         OS_SETCOLOR(71);
  563.         printf("[");
  564.         OS_SETCOLOR(87);
  565.         printf("H");
  566.         OS_SETCOLOR(71);
  567.         printf("]change host       [");
  568.         OS_SETCOLOR(87);
  569.         printf("S");
  570.  
  571.         OS_SETCOLOR(71);
  572.         printf("]Search item        [");
  573.         OS_SETCOLOR(87);
  574.         printf("ENTER");
  575.         OS_SETCOLOR(71);
  576.         printf("]Download item       [");
  577.         OS_SETCOLOR(87);
  578.         printf("ESC");
  579.         OS_SETCOLOR(71);
  580.         printf("]Exit   ");
  581.  
  582.         curWin.x = 0;
  583.         curWin.y = 1;
  584.         curWin.w = 80;
  585.         curWin.h = 23;
  586.         curWin.text = 207;
  587.         curWin.back = 207;
  588.         simpleBox(curWin);
  589.         drawSearch();
  590.         clearStatus();
  591. }
  592.  
  593. int pos(unsigned char *s, unsigned char *c, unsigned int n, unsigned int startPos)
  594. {
  595.         unsigned int i, j;
  596.         unsigned int lenC, lenS;
  597.  
  598.         for (lenC = 0; c[lenC]; lenC++)
  599.                 ;
  600.         for (lenS = 0; s[lenS]; lenS++)
  601.                 ;
  602.  
  603.         for (i = startPos; i <= lenS - lenC; i++)
  604.         {
  605.                 for (j = 0; s[i + j] == c[j]; j++)
  606.                         ;
  607.  
  608.                 if (j - lenC == 1 && i == lenS - lenC && !(n - 1))
  609.                         return i;
  610.                 if (j == lenC)
  611.                         if (n - 1)
  612.                                 n--;
  613.                         else
  614.                                 return i;
  615.         }
  616.         return -1;
  617. }
  618.  
  619. void squeeze(char s[], int c)
  620. {
  621.         int i, j;
  622.  
  623.         for (i = j = 0; s[i] != '\0'; i++)
  624.                 if (s[i] != c)
  625.                         s[j++] = s[i];
  626.         s[j] = '\0';
  627. }
  628.  
  629. char *insert_string(const char *original, const char *to_insert, unsigned int position)
  630. {
  631.         unsigned int original_len = strlen(original);
  632.         unsigned int insert_len = strlen(to_insert);
  633.         unsigned int new_len = original_len + insert_len;
  634.  
  635.         char *new_string = (char *)malloc(new_len + 1); // +1 для \0
  636.         if (new_string == NULL)
  637.         {
  638.                 return NULL; // Обработка ошибки выделения памяти
  639.         }
  640.  
  641.         // Копирование части исходной строки до позиции вставки
  642.         strncpy(new_string, original, position);
  643.         new_string[position] = '\0';
  644.  
  645.         // Вставка строки
  646.         strcat(new_string, to_insert);
  647.  
  648.         // Добавление оставшейся части исходной строки
  649.         strcat(new_string, original + position);
  650.  
  651.         return new_string;
  652. }
  653.  
  654. int cutHeader(void)
  655. {
  656.         unsigned char *count1;
  657.         int counter;
  658.  
  659.         httpErr = httpError();
  660.         if (httpError() != 200)
  661.         {
  662.                 clearStatus();
  663.                 printf("HTTP response:[%u]", httpErr);
  664.                 return 0;
  665.         }
  666.         count1 = strstr(netbuf, "Content-Length:");
  667.         if (count1 == NULL)
  668.         {
  669.                 clearStatus();
  670.                 printf("contLen not found");
  671.                 contLen = 0;
  672.                 httpErr = 999; // bad kostil
  673.                 return 0;
  674.         }
  675.         contLen = atol(count1 + 15);
  676.         // printf("Content-Length: %lu \n\r", contLen);
  677.  
  678.         count1 = strstr(netbuf, "Content-Disposition: attachment; filename="); // 42
  679.                                                                                                                                                    // Content-Disposition: attachment; filename="WED_PRO.TRD"
  680.         if (count1 != NULL)
  681.         {
  682.                 strncpy(link.fname, count1 + 43, 64);
  683.                 strcat(link.fname, "\0");
  684.                 counter = 0;
  685.                 while (link.fname[counter] != '\"')
  686.                 {
  687.                         counter++;
  688.                 }
  689.                 link.fname[counter] = 0;
  690.                 link.hasName = true;
  691.         }
  692.         else
  693.         {
  694.                 strncpy(link.fname, table[limiter.curline].file, 57);
  695.                 strcat(link.fname, ".");
  696.                 strcat(link.fname, table[limiter.curline].ext);
  697.  
  698.                 counter = strlen(link.fname);
  699.                 while (counter != 0)
  700.                 {
  701.                         counter--;
  702.                         if (link.fname[counter] == '.' && table[limiter.curline].option > 1)
  703.                         {
  704.                                 const char *new_string;
  705.                                 char temp[65];
  706.                                 sprintf(temp, "-%02d", limiter.curOpt);
  707.                                 new_string = insert_string(link.fname, temp, counter);
  708.                                 strcpy(link.fname, new_string);
  709.                         }
  710.                 }
  711.                 link.hasName = false;
  712.         }
  713.  
  714.         count1 = strstr(netbuf, "\r\n\r\n");
  715.         if (count1 == NULL)
  716.         {
  717.                 clearStatus();
  718.                 printf("end of header not found\r\n");
  719.         }
  720.         else
  721.         {
  722.                 // printf("header %u bytes\r\n", ((unsigned int)count1 - (unsigned int)netbuf + 4));
  723.         }
  724.         return ((unsigned int)count1 - (unsigned int)netbuf + 4);
  725. }
  726.  
  727. void downDialog(void)
  728. {
  729.         unsigned int nameLong;
  730.  
  731.         mainWinDraw();
  732.  
  733.         nameLong = strlen(link.fname);
  734.         if (nameLong < 21)
  735.         {
  736.                 curWin.w = 23;
  737.         }
  738.         else
  739.         {
  740.                 curWin.w = nameLong + 4;
  741.         }
  742.         curWin.x = 39 - curWin.w / 2;
  743.         curWin.y = 10;
  744.         curWin.h = 4;
  745.         curWin.text = 223;
  746.         curWin.back = 223;
  747.         simpleBox(curWin);
  748.         OS_SETXY(38 - nameLong / 2, curWin.y);
  749.         printf("[%s]", link.fname);
  750. }
  751.  
  752. char getFileEsp(void)
  753. {
  754.         int todo;
  755.         unsigned char byte, firstPacket;
  756.         unsigned long downloaded = 0;
  757.         unsigned int count, fileSize1, down;
  758.         const unsigned char sendOk[] = "SEND OK";
  759.  
  760.         sprintf(cmd, "AT+CIPSTART=\"TCP\",\"%s\",%u", link.host, link.port);
  761.         sendcommand(cmd);
  762.  
  763.         do
  764.         {
  765.                 getAnswer2(); // CONNECT or ERROR or link is not valid
  766.  
  767.                 if (strstr(netbuf, "CONNECT") != NULL)
  768.                 {
  769.                         break;
  770.                 }
  771.                 else
  772.                 {
  773.                         if (strstr(netbuf, "ERROR") != NULL)
  774.                         {
  775.                                 return false;
  776.                         }
  777.                 }
  778.         } while (42); // Try until endo of the days recieve CONNECT or ERROR
  779.  
  780.         getAnswer2(); // OK
  781.  
  782.         sprintf(cmd, "AT+CIPSEND=%u", strlen(link.path) + 2);
  783.         sendcommand(cmd);
  784.         getAnswer2();
  785.  
  786.         do
  787.         {
  788.                 byte = uart_readBlock();
  789.         } while (byte != '>');
  790.  
  791.         // sendcommandNrn(link.path);
  792.         sendcommand(link.path);
  793.  
  794.         count = 0;
  795.         do
  796.         {
  797.                 byte = uart_readBlock();
  798.                 if (byte == sendOk[count])
  799.                 {
  800.                         count++;
  801.                         // putchar(byte);
  802.                 }
  803.                 else
  804.                 {
  805.                         count = 0;
  806.                 }
  807.         } while (count < strlen(sendOk));
  808.  
  809.         uart_readBlock(); // CR
  810.         uart_readBlock(); // LF
  811.  
  812.         firstPacket = true;
  813.         do
  814.         {
  815.                 unsigned char temp[64];
  816.                 limiter.headLng = 0;
  817.                 todo = recvHead();
  818.                 getdataEsp(todo); // Requested size
  819.  
  820.                 if (firstPacket)
  821.                 {
  822.                         firstPacket = false;
  823.                         limiter.headLng = cutHeader();
  824.                         todo = todo - limiter.headLng;
  825.                         fileSize1 = contLen / 1024;
  826.  
  827.                         if (!link.hasName)
  828.                         {
  829.                                 curWin.w = 66;
  830.                                 curWin.x = 39 - curWin.w / 2;
  831.                                 curWin.y = 9;
  832.                                 curWin.h = 1;
  833.                                 curWin.text = 103;
  834.                                 curWin.back = 103;
  835.  
  836.                                 strcpy(curWin.tittle, "Введите имя файла");
  837.                                 if (inputBox(curWin, link.fname))
  838.                                 {
  839.                                         strncpy(link.fname, cmd, 64);
  840.                                         strcat(link.fname, "\0");
  841.                                 }
  842.                         }
  843.                         if (httpErr != 200)
  844.                         {
  845.                                 sendcommand("AT+CIPCLOSE");
  846.                                 getAnswer2(); // CLOSED
  847.                                 getAnswer2(); // OK
  848.                                 mainWinDraw();
  849.                                 return false;
  850.                         }
  851.                         downDialog();
  852.                         OS_DELETE(link.fname);
  853.                         saveBuf(link.fname, 00, 0);
  854.                 }
  855.  
  856.                 downloaded = downloaded + todo;
  857.                 down = downloaded / 1024;
  858.                 OS_SETCOLOR(223);
  859.                 sprintf(temp, "%4u  of %4u kb", down, fileSize1);
  860.                 OS_SETXY(38 - strlen(temp) / 2, 11);
  861.                 puts(temp);
  862.                 saveBuf(link.fname, 01, todo);
  863.                 drawClock();
  864.         } while (downloaded < contLen);
  865.         sendcommand("AT+CIPCLOSE");
  866.         getAnswer2(); // CLOSED
  867.         getAnswer2(); // OK
  868.         mainWinDraw();
  869.         return true;
  870. }
  871.  
  872. char getFileNet(void)
  873. {
  874.         int todo, socket;
  875.         char firstPacket;
  876.  
  877.         unsigned int fileSize1;
  878.         unsigned long downloaded = 0;
  879.         unsigned int down;
  880.  
  881.         socket = OpenSock(AF_INET, SOCK_STREAM);
  882.         if (testOperation2("OS_NETSOCKET", socket) != 1)
  883.         {
  884.                 getchar();
  885.                 quit();
  886.         }
  887.  
  888.         todo = netConnect(socket, 1);
  889.         if (testOperation2("OS_NETCONNECT", todo) != 1)
  890.         {
  891.                 getchar();
  892.                 quit();
  893.         }
  894.  
  895.         todo = tcpSend(socket, (unsigned int)&link.path, strlen(link.path), 1);
  896.         if (testOperation2("OS_WIZNETWRITE", todo) != 1)
  897.         {
  898.                 getchar();
  899.                 quit();
  900.         }
  901.  
  902.         firstPacket = true;
  903.         do
  904.         {
  905.                 unsigned char temp[64];
  906.                 limiter.headLng = 0;
  907.                 todo = tcpRead(socket, 1);
  908.                 testOperation("OS_WIZNETREAD", todo);
  909.                 if (todo == 0)
  910.                 {
  911.                         break;
  912.                 }
  913.                 if (firstPacket)
  914.                 {
  915.                         firstPacket = false;
  916.                         limiter.headLng = cutHeader();
  917.                         todo = todo - limiter.headLng;
  918.                         fileSize1 = contLen / 1024;
  919.  
  920.                         if (!link.hasName)
  921.                         {
  922.                                 curWin.w = 66;
  923.                                 curWin.x = 39 - curWin.w / 2;
  924.                                 curWin.y = 9;
  925.                                 curWin.h = 1;
  926.                                 curWin.text = 103;
  927.                                 curWin.back = 103;
  928.  
  929.                                 strcpy(curWin.tittle, "Введите имя файла");
  930.                                 if (inputBox(curWin, link.fname))
  931.                                 {
  932.                                         strncpy(link.fname, cmd, 64);
  933.                                         strcat(link.fname, "\0");
  934.                                 }
  935.                         }
  936.                         if (httpErr != 200)
  937.                         {
  938.                                 netShutDown(socket, 0);
  939.                                 mainWinDraw();
  940.                                 return false;
  941.                         }
  942.                         downDialog();
  943.                         saveBuf(link.fname, 00, 0);
  944.                 }
  945.                 downloaded = downloaded + todo;
  946.                 down = downloaded / 1024;
  947.                 OS_SETCOLOR(223);
  948.                 sprintf(temp, "%4u  of %4u kb", down, fileSize1);
  949.                 OS_SETXY(38 - strlen(temp) / 2, 11);
  950.                 puts(temp);
  951.                 saveBuf(link.fname, 01, todo);
  952.                 drawClock();
  953.         } while (downloaded < contLen);
  954.  
  955.         netShutDown(socket, 0);
  956.  
  957.         if (downloaded != contLen)
  958.         {
  959.                 puts("File download error!");
  960.                 puts("File download error!");
  961.                 puts("File download error!");
  962.                 puts("File download error!");
  963.                 waitKey();
  964.         }
  965.         mainWinDraw();
  966.         return true;
  967. }
  968.  
  969. char getFile(unsigned char number)
  970. {
  971.         int result = 0;
  972.         unsigned char option = 1;
  973.  
  974.         for (option = 1; option <= table[number].option; option++)
  975.         {
  976.                 sprintf(link.path, "GET /get/%lu/%u%s%s%s", table[number].id, option, userAgent1, link.host, userAgent2);
  977.                 limiter.curOpt = option;
  978.                 switch (netDriver)
  979.                 {
  980.                 case 0:
  981.                         result = getFileNet();
  982.                         break;
  983.                 case 1:
  984.                         result = getFileEsp();
  985.                         break;
  986.                 default:
  987.                         break;
  988.                 }
  989.         }
  990.         return result;
  991. }
  992.  
  993. char makeRequestEsp(void)
  994. {
  995.  
  996.         int todo;
  997.         unsigned char byte, firstPacket;
  998.         unsigned long downloaded = 0;
  999.         unsigned int count;
  1000.         const unsigned char sendOk[] = "SEND OK";
  1001.  
  1002.         sprintf(cmd, "AT+CIPSTART=\"TCP\",\"%s\",%u", link.host, link.port);
  1003.         sendcommand(cmd);
  1004.  
  1005.         do
  1006.         {
  1007.                 getAnswer2(); // CONNECT or ERROR or link is not valid
  1008.  
  1009.                 if (strstr(netbuf, "CONNECT") != NULL)
  1010.                 {
  1011.                         break;
  1012.                 }
  1013.                 else
  1014.                 {
  1015.                         if (strstr(netbuf, "ERROR") != NULL)
  1016.                         {
  1017.                                 return false;
  1018.                         }
  1019.                 }
  1020.         } while (42); // Try until endo of the days recieve CONNECT or ERROR
  1021.  
  1022.         getAnswer2(); // OK
  1023.  
  1024.         sprintf(cmd, "AT+CIPSEND=%u", strlen(link.path) + 2);
  1025.         sendcommand(cmd);
  1026.         getAnswer2();
  1027.  
  1028.         do
  1029.         {
  1030.                 byte = uart_readBlock();
  1031.         } while (byte != '>');
  1032.  
  1033.         // sendcommandNrn(link.path);
  1034.         sendcommand(link.path);
  1035.  
  1036.         count = 0;
  1037.         do
  1038.         {
  1039.                 byte = uart_readBlock();
  1040.                 if (byte == sendOk[count])
  1041.                 {
  1042.                         count++;
  1043.                         // putchar(byte);
  1044.                 }
  1045.                 else
  1046.                 {
  1047.                         count = 0;
  1048.                 }
  1049.         } while (count < strlen(sendOk));
  1050.  
  1051.         uart_readBlock(); // CR
  1052.         uart_readBlock(); // LF
  1053.  
  1054.         firstPacket = true;
  1055.         do
  1056.         {
  1057.                 limiter.headLng = 0;
  1058.                 todo = recvHead();
  1059.                 getdataEsp(todo); // Requested size
  1060.                 if (firstPacket)
  1061.                 {
  1062.                         firstPacket = false;
  1063.                         limiter.headLng = cutHeader();
  1064.                         todo = todo - limiter.headLng;
  1065.  
  1066.                         if (httpErr != 200)
  1067.                         {
  1068.                                 sendcommand("AT+CIPCLOSE");
  1069.                                 getAnswer2(); // CLOSED
  1070.                                 getAnswer2(); // OK
  1071.                                 return false;
  1072.                         }
  1073.                 }
  1074.                 if (downloaded + todo > sizeof(buf))
  1075.                 {
  1076.                         printf("dataBuffer overrun... %lu reached \n\r", downloaded + todo);
  1077.                         return false;
  1078.                 }
  1079.                 memcpy(buf + downloaded, netbuf + limiter.headLng, todo);
  1080.                 downloaded = downloaded + todo;
  1081.         } while (downloaded < contLen);
  1082.  
  1083.         sendcommand("AT+CIPCLOSE");
  1084.         getAnswer2(); // CLOSED
  1085.         getAnswer2(); // OK
  1086.         buf[downloaded + 1] = 0;
  1087.         return downloaded;
  1088. }
  1089.  
  1090. char makeRequestNet(void)
  1091. {
  1092.         int socket, todo;
  1093.         char firstPacket;
  1094.         unsigned long downloaded = 0;
  1095.  
  1096.         if (!dnsResolve(link.host))
  1097.         {
  1098.                 clearStatus();
  1099.                 printf("Ошибка определения адреса '%s'", link.host);
  1100.                 return false;
  1101.         }
  1102.  
  1103.         targetadr.porth = link.port >> 8;
  1104.         targetadr.portl = link.port;
  1105.         // clearStatus();
  1106.         // printf("Connecting to %u.%u.%u.%u:%u", targetadr.b1, targetadr.b2, targetadr.b3, targetadr.b4, targetadr.porth * 256 + targetadr.portl);
  1107.  
  1108.         socket = OpenSock(AF_INET, SOCK_STREAM);
  1109.         if (testOperation2("OS_NETSOCKET", socket) != 1)
  1110.         {
  1111.                 getchar();
  1112.                 quit();
  1113.         }
  1114.  
  1115.         todo = netConnect(socket, 1);
  1116.         if (testOperation2("OS_NETCONNECT", todo) != 1)
  1117.         {
  1118.                 getchar();
  1119.                 quit();
  1120.         }
  1121.         todo = tcpSend(socket, (unsigned int)&link.path, strlen(link.path), 1);
  1122.         if (testOperation2("OS_WIZNETWRITE", todo) != 1)
  1123.         {
  1124.                 getchar();
  1125.                 quit();
  1126.         }
  1127.         firstPacket = true;
  1128.         do
  1129.         {
  1130.                 limiter.headLng = 0;
  1131.                 todo = tcpRead(socket, 1);
  1132.                 testOperation("OS_WIZNETREAD", todo); // Quit if too many retries
  1133.  
  1134.                 if (firstPacket)
  1135.                 {
  1136.                         firstPacket = false;
  1137.                         limiter.headLng = cutHeader();
  1138.                         todo = todo - limiter.headLng;
  1139.  
  1140.                         if (httpErr != 200)
  1141.                         {
  1142.                                 netShutDown(socket, 0);
  1143.                                 return false;
  1144.                         }
  1145.                 }
  1146.  
  1147.                 if (downloaded + todo > sizeof(buf))
  1148.                 {
  1149.                         printf("dataBuffer overrun... %lu reached \n\r", downloaded + todo);
  1150.                         return false;
  1151.                 }
  1152.                 memcpy(buf + downloaded, netbuf + limiter.headLng, todo);
  1153.                 downloaded = downloaded + todo;
  1154.         } while (downloaded != contLen); // ref < лучше
  1155.  
  1156.         netShutDown(socket, 0);
  1157.         buf[downloaded + 1] = 0;
  1158.         return downloaded;
  1159. }
  1160.  
  1161. char makeRequest(const char *request)
  1162. {
  1163.         char result;
  1164.         unsigned int counter, len;
  1165.         char tempreq[256];
  1166.  
  1167.         sendReqdialog();
  1168.  
  1169.         strcpy(tempreq, request);
  1170.         len = strlen(tempreq);
  1171.         for (counter = 0; counter < len; counter++)
  1172.         {
  1173.                 if (tempreq[counter] == ' ' || tempreq[counter] == '-')
  1174.                 {
  1175.                         tempreq[counter] = '*';
  1176.                 }
  1177.         }
  1178.         sprintf(link.path, "GET /?s=%s&p=%d%s%s%s", tempreq, limiter.curPage, userAgent1, link.host, userAgent2);
  1179.  
  1180.         switch (netDriver)
  1181.         {
  1182.         case 0:
  1183.                 result = makeRequestNet();
  1184.                 break;
  1185.         case 1:
  1186.                 result = makeRequestEsp();
  1187.                 break;
  1188.  
  1189.         default:
  1190.                 return false;
  1191.         }
  1192.  
  1193.         return result;
  1194. }
  1195.  
  1196. int findLimiters(int n)
  1197. {
  1198.         n = pos(buf, "^", 1, n + 1);
  1199.         if (n == -1)
  1200.         {
  1201.                 return -2;
  1202.         }
  1203.         limiter.first = n + 1;
  1204.         n = pos(buf, "^", 1, n + 1);
  1205.         if (n == -1)
  1206.         {
  1207.                 return -2;
  1208.         }
  1209.         limiter.second = n - 1;
  1210.         return n;
  1211. }
  1212. void fillTable(void)
  1213. {
  1214.         int counter = 0;
  1215.         limiter.second = -1;
  1216.         limiter.total = 0;
  1217.         do
  1218.         {
  1219.                 if (findLimiters(limiter.second) != -2)
  1220.                 {
  1221.                         table[counter].id = atol(buf + limiter.first);
  1222.                         limiter.total++;
  1223.                 }
  1224.  
  1225.                 if (findLimiters(limiter.second) != -2)
  1226.                 {
  1227.                         strncpy(table[counter].name, buf + limiter.first, limiter.second - limiter.first + 1);
  1228.                         strcat(table[counter].name, "\0");
  1229.                         table[counter].name[limiter.second - limiter.first + 1] = 0;
  1230.                 }
  1231.                 if (findLimiters(limiter.second) != -2)
  1232.                 {
  1233.                         strncpy(table[counter].file, buf + limiter.first, limiter.second - limiter.first - 3);
  1234.                         strcat(table[counter].file, "\0");
  1235.                         table[counter].file[limiter.second - limiter.first - 3] = 0;
  1236.                         strncpy(table[counter].ext, buf + limiter.second - 2, 3);
  1237.                         strcat(table[counter].ext, "\0");
  1238.                 }
  1239.  
  1240.                 if (findLimiters(limiter.second) != -2)
  1241.                 {
  1242.                         table[counter].size = atol(buf + limiter.first);
  1243.                 }
  1244.  
  1245.                 if (findLimiters(limiter.second) != -2)
  1246.                 {
  1247.                         table[counter].option = atoi(buf + limiter.first);
  1248.                 }
  1249.  
  1250.                 if (findLimiters(limiter.second) != -2)
  1251.                 {
  1252.                         table[counter].year = atoi(buf + limiter.first);
  1253.                 }
  1254.  
  1255.                 limiter.second++;
  1256.                 counter++;
  1257.         } while (counter < 12);
  1258. }
  1259.  
  1260. void renderResult(char currentLine)
  1261. {
  1262.         int counter, line = 2;
  1263.  
  1264.         for (counter = 0; counter < limiter.total; counter++)
  1265.         {
  1266.                 // printf("[%lu] ", table[counter].id);
  1267.  
  1268.                 if (counter == currentLine)
  1269.                 {
  1270.                         OS_SETCOLOR(121);
  1271.                         OS_SETXY(2, line);
  1272.                         spaces(76);
  1273.                         OS_SETXY(2, line + 1);
  1274.                         spaces(76);
  1275.                 }
  1276.                 else
  1277.                 {
  1278.                         if (counter % 2 == 0)
  1279.                         {
  1280.                                 OS_SETCOLOR(206);
  1281.                         }
  1282.                         else
  1283.                         {
  1284.                                 OS_SETCOLOR(207);
  1285.                         }
  1286.                 }
  1287.                 OS_SETXY(2, line);
  1288.                 spaces(76);
  1289.                 OS_SETXY(2, line);
  1290.                 printf("%s ", table[counter].name);
  1291.                 OS_SETXY(48, line);
  1292.                 printf("%s  %6lu  %u  %4u", table[counter].ext, table[counter].size, table[counter].option, table[counter].year);
  1293.                 line++;
  1294.                 OS_SETXY(2, line);
  1295.                 spaces(76);
  1296.                 OS_SETXY(5, line);
  1297.                 printf("%s ", table[counter].file);
  1298.                 line++;
  1299.         }
  1300.         OS_SETCOLOR(206);
  1301.         for (counter = limiter.total; counter < 10; counter++)
  1302.         {
  1303.                 OS_SETXY(2, line);
  1304.                 spaces(76);
  1305.                 line++;
  1306.                 OS_SETXY(2, line);
  1307.                 spaces(76);
  1308.                 line++;
  1309.         }
  1310. }
  1311.  
  1312. char getKey(void)
  1313. {
  1314.         char key;
  1315.         key = OS_GETKEY();
  1316.         switch (key)
  1317.         {
  1318.         case 27: // escape - exit
  1319.                 OS_CLS(0);
  1320.                 OS_SETGFX(-1);
  1321.                 exit(0);
  1322.                 break;
  1323.         case 's':
  1324.         case 'ы':
  1325.         case 'Ы':
  1326.         case 'S':
  1327.         fuckingoto:
  1328.                 limiter.total = 0;
  1329.                 limiter.curline = 0;
  1330.                 curWin.w = 40;
  1331.                 curWin.x = 80 / 2 - curWin.w / 2 - 1;
  1332.                 curWin.y = 10;
  1333.                 curWin.h = 1;
  1334.                 curWin.text = 103;
  1335.                 curWin.back = 103;
  1336.                 strcpy(curWin.tittle, "Введите поисковый запрос");
  1337.  
  1338.                 if (inputBox(curWin, ""))
  1339.                 {
  1340.                         strcpy(search, cmd);
  1341.                         limiter.curPage = 0;
  1342.                         drawSearch();
  1343.                 }
  1344.                 else
  1345.                 {
  1346.                         mainWinDraw();
  1347.                         OS_SETXY(32, 11);
  1348.                         OS_SETCOLOR(206);
  1349.                         puts("No results found");
  1350.                         limiter.total = 0;
  1351.                         limiter.curline = 0;
  1352.                         break;
  1353.                 }
  1354.  
  1355.                 if (makeRequest(search) < 2)
  1356.                 {
  1357.                         mainWinDraw();
  1358.                         OS_SETXY(32, 11);
  1359.                         OS_SETCOLOR(206);
  1360.                         puts("No results found");
  1361.                         limiter.total = 0;
  1362.                         limiter.curline = 0;
  1363.                         return key;
  1364.                 }
  1365.  
  1366.                 OS_SETXY(1, 2);
  1367.                 OS_SETCOLOR(206);
  1368.                 fillTable();
  1369.                 break;
  1370.         case 'h':
  1371.         case 'H':
  1372.         case 'р':
  1373.         case 'Р':
  1374.                 limiter.total = 0;
  1375.                 limiter.curline = 0;
  1376.                 curHost++;
  1377.                 if (curHost > 1)
  1378.                 {
  1379.                         curHost = 0;
  1380.                 }
  1381.                 strcpy(link.host, hosts[curHost]);
  1382.                 mainWinDraw();
  1383.                 break;
  1384.         case 'q':
  1385.         case 'Q':
  1386.         case 'Й':
  1387.         case 'й':
  1388.         case 250:
  1389.                 if (limiter.total != 0)
  1390.                 {
  1391.                         if (limiter.curline < 1)
  1392.                         {
  1393.                                 limiter.curline = limiter.total - 1;
  1394.                         }
  1395.                         else
  1396.                         {
  1397.                                 limiter.curline--;
  1398.                         }
  1399.                 }
  1400.                 break;
  1401.         case 'a':
  1402.         case 'A':
  1403.         case 'ф':
  1404.         case 'Ф':
  1405.         case 249:
  1406.                 if (limiter.total != 0)
  1407.                 {
  1408.                         if (limiter.curline > limiter.total - 2)
  1409.                         {
  1410.                                 limiter.curline = 0;
  1411.                         }
  1412.                         else
  1413.                         {
  1414.                                 limiter.curline++;
  1415.                         }
  1416.                 }
  1417.                 break;
  1418.         case 248: // left
  1419.         case 'o':
  1420.  
  1421.                 if (limiter.curPage != 0 && limiter.total != 0)
  1422.                 {
  1423.                         limiter.curPage--;
  1424.                         mainWinDraw();
  1425.                         if (makeRequest(search) < 2)
  1426.                         {
  1427.                                 OS_SETXY(32, 11);
  1428.                                 OS_SETCOLOR(206);
  1429.                                 puts("No results found");
  1430.                                 limiter.total = 0;
  1431.                                 limiter.curline = 0;
  1432.                                 break;
  1433.                         }
  1434.                         // OS_SETXY(1, 2);
  1435.                         // OS_SETCOLOR(206);
  1436.                         fillTable();
  1437.                         limiter.curline = 0;
  1438.                 }
  1439.                 break;
  1440.         case 251: // right
  1441.         case 'p':
  1442.                 if (limiter.total != 0)
  1443.                 {
  1444.                         limiter.curPage++;
  1445.                         mainWinDraw();
  1446.                         if (makeRequest(search) < 2)
  1447.                         {
  1448.                                 limiter.curPage--;
  1449.                                 drawPage();
  1450.                                 makeRequest(search);
  1451.                         }
  1452.                         // OS_SETXY(1, 2);
  1453.                         // OS_SETCOLOR(206);
  1454.                         fillTable();
  1455.                         limiter.curline = 0;
  1456.                 }
  1457.                 break;
  1458.         case 13:
  1459.                 if (limiter.total != 0)
  1460.                 {
  1461.                         getFile(limiter.curline);
  1462.                 }
  1463.                 else
  1464.                 {
  1465.                         goto fuckingoto;
  1466.                 }
  1467.                 break;
  1468.         default:
  1469.                 break;
  1470.         }
  1471.  
  1472.         if (key != 0)
  1473.         {
  1474.                 renderResult(limiter.curline);
  1475.         }
  1476.         else
  1477.         {
  1478.                 YIELD();
  1479.         }
  1480.         return key;
  1481. }
  1482.  
  1483. C_task main(int argc, const char *argv[])
  1484. {
  1485.         OS_HIDEFROMPARENT();
  1486.         OS_SETGFX(0x86);
  1487.         OS_CLS(0);
  1488.         OS_SETSYSDRV();
  1489.         init();
  1490.         // printTable();
  1491.         //  waitKey();
  1492.         OS_CLS(0);
  1493.         mainWinDraw();
  1494.  
  1495.         do
  1496.         {
  1497.                 getKey();
  1498.         } while (42);
  1499. }
  1500.