?login_element?

Subversion Repositories NedoOS

Rev

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

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <intrz80.h>
  4. #include <stdlib.h>
  5. #include <oscalls.h>
  6. #include <terminal.c>
  7. #include <tcp.h>
  8. #include <osfs.h>
  9. #include <intrz80.h>
  10. #include <ctype.h>
  11. #include <math.h>
  12.  
  13. unsigned int RBR_THR = 0xf8ef;
  14. unsigned int IER = 0xf9ef;
  15. unsigned int IIR_FCR = 0xfaef;
  16. unsigned int LCR = 0xfbef;
  17. unsigned int MCR = 0xfcef;
  18. unsigned int LSR = 0xfdef;
  19. unsigned int MSR = 0xfeef;
  20. unsigned int SR = 0xffef;
  21. unsigned int divider = 1;
  22. unsigned char comType = 0;
  23. unsigned int espType = 32;
  24. unsigned char netDriver = 0;
  25.  
  26. unsigned char uVer[] = "0.48";
  27. unsigned char curPath[128];
  28. unsigned char curLetter;
  29. unsigned char oldBinExt;
  30. unsigned int errn, headlng;
  31. unsigned long contLen;
  32. unsigned char saveFlag, saveBak;
  33. unsigned char crlf[2] = {13, 10};
  34.  
  35. unsigned char status, curFormat;
  36. struct sockaddr_in targetadr;
  37. struct readstructure readStruct;
  38. FILE *fp2;
  39.  
  40. struct window
  41. {
  42.         unsigned char x;
  43.         unsigned char y;
  44.         unsigned char w;
  45.         unsigned char h;
  46.         unsigned char text;
  47.         unsigned char back;
  48.         unsigned char tittle[80];
  49.  
  50. } cw;
  51.  
  52. struct configuration
  53. {
  54.         unsigned char kernelName[32];
  55.         unsigned char machineName[32];
  56.         unsigned char kernelLink[256];
  57.         unsigned char is_atm;
  58. } config;
  59.  
  60. unsigned char netbuf[4096];
  61.  
  62. unsigned char cmdlist1[] = " HTTP/1.1\r\nHost: nedoos.ru\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS)\r\n\r\n\0";
  63. unsigned char binLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/&isdir=1";
  64. unsigned char pkunzipLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/pkunzip.com";
  65. unsigned char tarLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/tar.com";
  66. unsigned char cmdLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/cmd.com";
  67. unsigned char termLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/term.com";
  68. unsigned char updLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/updater.com";
  69. unsigned char newsLink[] = "/svn/dl.php?repname=NedoOS&path=/release/doc/updater.new";
  70. unsigned char wizNetLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/wizcfg.com";
  71. unsigned char netIniLink[] = "/svn/dl.php?repname=NedoOS&path=/release/bin/net.ini";
  72. unsigned char relLink[] = "http://nedoos.ru/images/release.zip";
  73. unsigned char nameBuf1[256];
  74. unsigned char *nameBuf = nameBuf1;
  75. // unsigned char *nameBuf = "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
  76. const unsigned char sendOk[] = "SEND OK";
  77. const unsigned char gotWiFi[] = "WIFI GOT IP";
  78. unsigned char cmd[256];
  79. unsigned char link[512];
  80. unsigned char dataBuffer[4096];
  81.  
  82. void clearStatus(void)
  83. {
  84.         AT(1, 24);
  85.         printf("                                                                                \r");
  86. }
  87.  
  88. void printTable(void)
  89. {
  90.         unsigned int cycle;
  91.  
  92.         for (cycle = 32; cycle < 256; cycle++)
  93.         {
  94.                 printf("%03u:", cycle);
  95.                 putchar(cycle);
  96.                 printf(" ");
  97.                 if (cycle % 10 == 0)
  98.                 {
  99.                         printf("\r\n");
  100.                 }
  101.         }
  102. }
  103.  
  104. void delay(unsigned long counter)
  105. {
  106.         unsigned long start, finish;
  107.         counter = counter / 20;
  108.         if (counter < 1)
  109.         {
  110.                 counter = 1;
  111.         }
  112.         start = time();
  113.         finish = start + counter;
  114.  
  115.         while (start < finish)
  116.         {
  117.                 start = time();
  118.         }
  119. }
  120.  
  121. void printNews(void) // max 20 lines in total and 59 col.
  122. {
  123.         FILE *fpNews;
  124.         unsigned char str[1];
  125.         unsigned char curLine, nbyte;
  126.  
  127.         fpNews = OS_OPENHANDLE("updater.new", 0x80);
  128.         if (((int)fpNews) & 0xff)
  129.         {
  130.  
  131. #include <printnews.c>
  132.  
  133.                 return;
  134.         }
  135.         curLine = 0;
  136.         while (curLine < 20)
  137.         {
  138.                 AT(20, 3 + curLine);
  139.                 while (1)
  140.                 {
  141.                         OS_READHANDLE(str, fpNews, sizeof(str));
  142.  
  143.                         if (errno != 0)
  144.                         {
  145.                                 OS_CLOSEHANDLE(fpNews);
  146.                                 return;
  147.                         }
  148.  
  149.                         nbyte = str[0];
  150.  
  151.                         if (nbyte != 13)
  152.                         {
  153.                                 putchar(nbyte);
  154.                         }
  155.                         else
  156.                         {
  157.                                 break;
  158.                         }
  159.                 }
  160.                 OS_READHANDLE(str, fpNews, sizeof(str));
  161.                 curLine++;
  162.         }
  163.         OS_CLOSEHANDLE(fpNews);
  164. }
  165.  
  166. void drawWindow(struct window w)
  167. {
  168.         unsigned char wcount, tempx, tittleStart;
  169.  
  170.         AT(w.x, w.y - 1);
  171.         tittleStart = w.x + (w.w / 2) - (strlen(w.tittle) / 2) + 1;
  172.         BOX(w.x, w.y, w.w + 1, w.h, w.back, 32);
  173.         AT(w.x, w.y);
  174.         ATRIB(w.text);
  175.         putchar(201);
  176.         for (wcount = 0; wcount < w.w; wcount++)
  177.         {
  178.                 putchar(205);
  179.         }
  180.         putchar(187);
  181.  
  182.         AT(w.x, w.y + w.h);
  183.         putchar(200);
  184.         for (wcount = 0; wcount < w.w; wcount++)
  185.         {
  186.                 putchar(205);
  187.         }
  188.         putchar(188);
  189.  
  190.         tempx = w.x + w.w + 1;
  191.         for (wcount = 1; wcount < w.h; wcount++)
  192.         {
  193.                 AT(w.x, w.y + wcount);
  194.                 putchar(186);
  195.                 AT(tempx, w.y + wcount);
  196.                 putchar(186);
  197.         }
  198.  
  199.         AT(w.x, w.y + 2);
  200.         putchar(199);
  201.         for (wcount = 0; wcount < w.w; wcount++)
  202.         {
  203.                 putchar(196);
  204.         }
  205.         putchar(182);
  206.  
  207.         AT(tittleStart, w.y + 1);
  208.         printf("%s", w.tittle);
  209. }
  210.  
  211. void fatalError(unsigned char *message)
  212. {
  213.         strcpy(cw.tittle, "FATAL ERROR!");
  214.  
  215.         if (strlen(message) > strlen(cw.tittle))
  216.         {
  217.                 cw.w = strlen(message) + 2;
  218.         }
  219.         else
  220.                 cw.w = strlen(cw.tittle) + 2;
  221.         cw.x = 80 / 2 - cw.w / 2;
  222.         cw.y = 11;
  223.         cw.h = 4;
  224.         cw.text = 97;
  225.         cw.back = 41;
  226.         drawWindow(cw);
  227.         AT(cw.x + 2, cw.y + 3);
  228.         printf("%s", message);
  229.         AT(1, 1);
  230.         getchar();
  231.         exit(0);
  232. }
  233.  
  234. void infoBox(unsigned char *message)
  235. {
  236.         strcpy(cw.tittle, "nedoOS system updater ");
  237.         strcat(cw.tittle, uVer);
  238.  
  239.         if (strlen(message) > strlen(cw.tittle))
  240.         {
  241.                 cw.w = strlen(message) + 2;
  242.         }
  243.         else
  244.                 cw.w = strlen(cw.tittle) + 2;
  245.         cw.x = 80 / 2 - cw.w / 2;
  246.         cw.y = 15;
  247.         cw.h = 4;
  248.         cw.text = 97;
  249.         cw.back = 42;
  250.  
  251.         drawWindow(cw);
  252.         AT(cw.x + 2, cw.y + 3);
  253.         printf("%s", message);
  254.         AT(1, 1);
  255. }
  256.  
  257. unsigned char OS_SHELL(unsigned char *command)
  258. {
  259.         unsigned char fileName[] = "bin/cmd.com";
  260.         unsigned char appCmd[128] = "cmd.com ";
  261.         unsigned int shellSize, loaded, loop, adr;
  262.         unsigned char pgbak;
  263.         union APP_PAGES shell_pg;
  264.         union APP_PAGES main_pg;
  265.         FILE *fp3;
  266.         main_pg.l = OS_GETMAINPAGES();
  267.         pgbak = main_pg.pgs.window_3;
  268.         OS_GETPATH((unsigned int)&curPath);
  269.         strcat(appCmd, command);
  270.         fp3 = OS_OPENHANDLE(fileName, 0x80);
  271.         if (((int)fp3) & 0xff)
  272.         {
  273.                 clearStatus();
  274.                 AT(1, 24);
  275.                 printf("%s", fileName);
  276.                 printf(" not found.");
  277.                 getchar();
  278.                 exit(0);
  279.         }
  280.         shellSize = OS_GETFILESIZE(fp3);
  281.  
  282.         OS_NEWAPP((unsigned int)&shell_pg);
  283.  
  284.         shell_pg.l = OS_GETAPPMAINPAGES(shell_pg.pgs.pId);
  285.  
  286.         SETPG32KHIGH(shell_pg.pgs.window_0);
  287.  
  288.         memcpy((unsigned char *)(0xC080), (unsigned char *)(&appCmd), strlen(appCmd) + 1);
  289.  
  290.         loop = 0;
  291.         while (loop < shellSize)
  292.         {
  293.                 loaded = OS_READHANDLE(netbuf, fp3, sizeof(netbuf));
  294.                 adr = 0xC100 + loop;
  295.                 memcpy((unsigned char *)(adr), &netbuf, loaded);
  296.                 loop = loop + loaded;
  297.         }
  298.         OS_CLOSEHANDLE(fp3);
  299.         SETPG32KHIGH(pgbak);
  300.         clearStatus();
  301.         AT(1, 24);
  302.         printf("Shell [pId:%u][%s][%s]", shell_pg.pgs.pId, curPath, appCmd);
  303.         AT(1, 24);
  304.         delay(300);
  305.         OS_RUNAPP(shell_pg.pgs.pId);
  306.         AT(1, 4);
  307.         OS_WAITPID(shell_pg.pgs.pId);
  308.         return shell_pg.pgs.pId;
  309. }
  310.  
  311. ////////////////////////ESP32 PROCEDURES//////////////////////
  312. void uart_write(unsigned char data)
  313. {
  314.         unsigned char status;
  315.         switch (comType)
  316.         {
  317.         case 0:
  318.         case 2:
  319.                 while ((input(LSR) & 64) == 0)
  320.                 {
  321.                 }
  322.                 output(RBR_THR, data);
  323.                 break;
  324.         case 1:
  325.                 disable_interrupt();
  326.                 do
  327.                 {
  328.                         input(0x55fe);                  // Переход в режим команд
  329.                         status = input(0x42fe); // Команда прочесть статус
  330.                 } while ((status & 64) == 0); // Проверяем 6 бит
  331.  
  332.                 input(0x55fe);                           // Переход в режим команд
  333.                 input(0x03fe);                           // Команда записать в порт
  334.                 input((data << 8) | 0x00fe); // Записываем data в порт
  335.                 enable_interrupt();
  336.                 break;
  337.         }
  338. }
  339.  
  340. void uart_setrts(unsigned char mode)
  341. {
  342.         switch (comType)
  343.         {
  344.         case 0:
  345.                 switch (mode)
  346.                 {
  347.                 case 1:
  348.                         output(MCR, 2);
  349.                         break;
  350.                 case 0:
  351.                         output(MCR, 0);
  352.                         break;
  353.                 default:
  354.                         disable_interrupt();
  355.                         output(MCR, 2);
  356.                         output(MCR, 0);
  357.                         enable_interrupt();
  358.                         break;
  359.                 }
  360.         case 1:
  361.                 switch (mode)
  362.                 {
  363.                 case 1:
  364.                         disable_interrupt();
  365.                         input(0x55fe); // Переход в режим команд
  366.                         input(0x43fe); // Команда установить статус
  367.                         input(0x03fe); // Устанавливаем готовность DTR и RTS
  368.                         enable_interrupt();
  369.                         break;
  370.                 case 0:
  371.                         disable_interrupt();
  372.                         input(0x55fe); // Переход в режим команд
  373.                         input(0x43fe); // Команда установить статус
  374.                         input(0x00fe); // Снимаем готовность DTR и RTS
  375.                         enable_interrupt();
  376.                         break;
  377.                 default:
  378.                         disable_interrupt();
  379.                         input(0x55fe); // Переход в режим команд
  380.                         input(0x43fe); // Команда установить статус
  381.                         input(0x03fe); // Устанавливаем готовность DTR и RTS
  382.                         input(0x55fe); // Переход в режим команд
  383.                         input(0x43fe); // Команда установить статус
  384.                         input(0x00fe); // Снимаем готовность DTR и RTS
  385.                         enable_interrupt();
  386.                         break;
  387.                 }
  388.         case 2:
  389.                 break;
  390.         }
  391. }
  392.  
  393. void uart_init(unsigned char divisor)
  394. {
  395.         switch (comType)
  396.         {
  397.         case 0:
  398.         case 2:
  399.                 output(MCR, 0x00);                // Disable input
  400.                 output(IIR_FCR, 0x87);    // Enable fifo 8 level, and clear it
  401.                 output(LCR, 0x83);                // 8n1, DLAB=1
  402.                 output(RBR_THR, divisor); // 115200 (divider 1-115200, 3 - 38400)
  403.                 output(IER, 0x00);                // (divider 0). Divider is 16 bit, so we get (#0002 divider)
  404.                 output(LCR, 0x03);                // 8n1, DLAB=0
  405.                 output(IER, 0x00);                // Disable int
  406.                 output(MCR, 0x2f);                // Enable AFE
  407.                 break;
  408.         case 1:
  409.                 disable_interrupt();
  410.                 input(0x55fe);
  411.                 input(0xc3fe);
  412.                 input((divisor << 8) | 0x00fe);
  413.                 enable_interrupt();
  414.                 break;
  415.         }
  416. }
  417.  
  418. unsigned char uart_hasByte(void)
  419. {
  420.         unsigned char queue;
  421.         switch (comType)
  422.         {
  423.         case 0:
  424.         case 2:
  425.                 return (1 & input(LSR));
  426.         case 1:
  427.                 disable_interrupt();
  428.                 input(0x55fe);             // Переход в режим команд
  429.                 queue = input(0xc2fe); // Получаем количество байт в приемном буфере
  430.                 enable_interrupt();
  431.                 return queue;
  432.         }
  433.         return 255;
  434. }
  435.  
  436. unsigned char uart_read(void)
  437. {
  438.         unsigned char data;
  439.         switch (comType)
  440.         {
  441.         case 0:
  442.         case 2:
  443.                 return input(RBR_THR);
  444.         case 1:
  445.                 disable_interrupt();
  446.                 input(0x55fe);            // Переход в режим команд
  447.                 data = input(0x02fe); // Команда прочесть из порта
  448.                 enable_interrupt();
  449.                 return data;
  450.         }
  451.         return 255;
  452. }
  453.  
  454. unsigned char uart_readBlock(void)
  455. {
  456.         unsigned char data;
  457.         switch (comType)
  458.         {
  459.         case 0:
  460.                 while (uart_hasByte() == 0)
  461.                 {
  462.                         uart_setrts(2);
  463.                 }
  464.                 return input(RBR_THR);
  465.         case 1:
  466.                 while (uart_hasByte() == 0)
  467.                 {
  468.                         uart_setrts(2);
  469.                 }
  470.                 disable_interrupt();
  471.                 input(0x55fe);            // Переход в режим команд
  472.                 data = input(0x02fe); // Команда прочесть из порта
  473.                 enable_interrupt();
  474.                 return data;
  475.         case 2:
  476.                 while (uart_hasByte() == 0)
  477.                 {
  478.                 }
  479.                 return input(RBR_THR);
  480.         }
  481.         return 255;
  482. }
  483.  
  484. void uart_flush(void)
  485. {
  486.         unsigned int count;
  487.         for (count = 0; count < 6000; count++)
  488.         {
  489.                 uart_setrts(1);
  490.                 uart_read();
  491.         }
  492. }
  493.  
  494. void getdataEsp(unsigned int counted)
  495. {
  496.         unsigned int counter;
  497.         for (counter = 0; counter < counted; counter++)
  498.         {
  499.                 netbuf[counter] = uart_readBlock();
  500.         }
  501.         netbuf[counter] = 0;
  502. }
  503.  
  504. void sendcommand(char *commandline)
  505. {
  506.         unsigned int count, cmdLen;
  507.         cmdLen = strlen(commandline);
  508.         for (count = 0; count < cmdLen; count++)
  509.         {
  510.                 uart_write(commandline[count]);
  511.         }
  512.         uart_write('\r');
  513.         uart_write('\n');
  514.         // printf("Sended:[%s] \r\n", commandline);
  515. }
  516.  
  517. unsigned char getAnswer2(void)
  518. {
  519.         unsigned char readbyte;
  520.         unsigned int curPos = 0;
  521.         do
  522.         {
  523.                 readbyte = uart_readBlock();
  524.                 // putdec(readbyte);
  525.         } while (((readbyte == 0x0a) || (readbyte == 0x0d)));
  526.  
  527.         netbuf[curPos] = readbyte;
  528.         curPos++;
  529.         do
  530.         {
  531.                 readbyte = uart_readBlock();
  532.                 netbuf[curPos] = readbyte;
  533.                 curPos++;
  534.         } while (readbyte != 0x0d);
  535.         netbuf[curPos - 1] = 0;
  536.         uart_readBlock(); // 0xa
  537.         // printf("Answer:[%s]\r\n", netbuf);
  538.         //    getchar();
  539.         return curPos;
  540. }
  541.  
  542. void espReBoot(void)
  543. {
  544.         unsigned char byte, count;
  545.         uart_flush();
  546.         sendcommand("AT+RST");
  547.         printf("Resetting ESP...");
  548.         count = 0;
  549.         do
  550.         {
  551.                 byte = uart_readBlock();
  552.                 if (byte == gotWiFi[count])
  553.                 {
  554.                         count++;
  555.                 }
  556.                 else
  557.                 {
  558.                         count = 0;
  559.                 }
  560.         } while (count < strlen(gotWiFi));
  561.         uart_readBlock(); // CR
  562.         uart_readBlock(); // LF
  563.         printf("Reset complete.");
  564.  
  565.         sendcommand("ATE0");
  566.         do
  567.         {
  568.                 byte = uart_readBlock();
  569.         } while (byte != 'K'); // OK
  570.         // puts("ATE0 Answer:[OK]");
  571.         uart_readBlock(); // CR
  572.         uart_readBlock(); // LN
  573.  
  574.         sendcommand("AT+CIPCLOSE");
  575.         getAnswer2();
  576.         sendcommand("AT+CIPDINFO=0");
  577.         getAnswer2();
  578.         sendcommand("AT+CIPMUX=0");
  579.         getAnswer2();
  580.         sendcommand("AT+CIPSERVER=0");
  581.         getAnswer2();
  582.         sendcommand("AT+CIPRECVMODE=0");
  583.         getAnswer2();
  584. }
  585.  
  586. unsigned int recvHead(void)
  587. {
  588.         unsigned char byte, dataRead = 0;
  589.         unsigned int loaded;
  590.         do
  591.         {
  592.                 byte = uart_readBlock();
  593.         } while (byte != ',');
  594.  
  595.         dataRead = 0;
  596.         do
  597.         {
  598.                 byte = uart_readBlock();
  599.                 netbuf[dataRead] = byte;
  600.                 dataRead++;
  601.         } while (byte != ':');
  602.         netbuf[dataRead] = 0;
  603.         loaded = atoi(netbuf); // <actual_len>
  604.         // printf("\r\n loaded %u\r\n", loaded);
  605.         return loaded;
  606. }
  607.  
  608. void loadEspConfig(void)
  609. {
  610.         unsigned char curParam[256];
  611.         unsigned char res;
  612.         FILE *espcom;
  613.         OS_SETSYSDRV();
  614.         OS_CHDIR("browser");
  615.         espcom = OS_OPENHANDLE("espcom.ini", 0x80);
  616.         if (((int)espcom) & 0xff)
  617.         {
  618.                 clearStatus();
  619.                 printf("mrfesp.ini opening error");
  620.                 return;
  621.         }
  622.  
  623.         OS_READHANDLE(curParam, espcom, 256);
  624.  
  625.         res = sscanf(curParam, "%x %x %x %x %x %x %x %x %u %u %u", &RBR_THR, &IER, &IIR_FCR, &LCR, &MCR, &LSR, &MSR, &SR, &divider, &comType, &espType);
  626.         puts("Config loaded:");
  627.         if (comType == 1)
  628.         {
  629.                 puts("     Controller base port: 0x55fe");
  630.         }
  631.         else
  632.         {
  633.                 printf("     RBR_THR:0x%4x     IER    :0x%4x\r\n     IIR_FCR:0x%4x     LCR    :0x%4x\r\n", RBR_THR, IER, IIR_FCR, LCR);
  634.                 printf("     MCR    :0x%4x     LSR    :0x%4x\r\n     MSR    :0x%4x     SR     :0x%4x\r\n", MCR, LSR, MSR, SR);
  635.         }
  636.         printf("     DIV    :%u    TYPE    :%u    ESP    :%u ", divider, comType, espType);
  637.         switch (comType)
  638.         {
  639.         case 0:
  640.                 puts("(16550 like w/o AFC)");
  641.                 break;
  642.         case 1:
  643.                 puts("(ATM Turbo 2+)");
  644.                 break;
  645.         case 2:
  646.                 puts("(16550 with AFC)");
  647.         default:
  648.                 puts("(Unknown type)");
  649.                 break;
  650.         }
  651. }
  652.  
  653. ////////////////////////ESP32 PROCEDURES//////////////////////
  654.  
  655. //////////////// NETWORK PART //////////////////////
  656. void errorPrint(unsigned int error)
  657. {
  658.         clearStatus();
  659.         switch (error)
  660.         {
  661.         case 2:
  662.                 printf("02 SHUT_RDWR");
  663.                 break;
  664.         case 4:
  665.                 printf("04 ERR_INTR");
  666.                 break;
  667.         case 23:
  668.                 printf("23 ERR_NFILE");
  669.                 break;
  670.         case 35:
  671.                 printf("35 ERR_EAGAIN");
  672.                 break;
  673.         case 37:
  674.                 printf("37 ERR_ALREADY");
  675.                 break;
  676.         case 38:
  677.                 printf("38 ERR_NOTSOCK");
  678.                 break;
  679.         case 40:
  680.                 printf("40 ERR_EMSGSIZE");
  681.                 break;
  682.         case 41:
  683.                 printf("41 ERR_PROTOTYPE");
  684.                 break;
  685.         case 47:
  686.                 printf("47 ERR_AFNOSUPPORT");
  687.                 break;
  688.         case 53:
  689.                 printf("53 ERR_ECONNABORTED");
  690.                 break;
  691.         case 54:
  692.                 printf("54 ERR_CONNRESET");
  693.                 break;
  694.         case 57:
  695.                 printf("57 ERR_NOTCONN");
  696.                 break;
  697.         case 65:
  698.                 printf("65 ERR_HOSTUNREACH");
  699.                 break;
  700.         default:
  701.                 printf("[%u] UNKNOWN ERROR", error);
  702.                 break;
  703.         }
  704.         do
  705.         {
  706.                 YIELD();
  707.         } while (_low_level_get() == 0);
  708. }
  709.  
  710. unsigned int httpError(void)
  711. {
  712.         unsigned char *httpRes;
  713.         unsigned int httpErr;
  714.         httpRes = strstr(netbuf, "HTTP/1.1 ");
  715.  
  716.         if (httpRes != NULL)
  717.         {
  718.                 httpErr = atol(httpRes + 9);
  719.         }
  720.         else
  721.         {
  722.                 httpErr = 0;
  723.         }
  724.         return httpErr;
  725. }
  726.  
  727. unsigned char OpenSock(unsigned char family, unsigned char protocol)
  728. {
  729.         unsigned char socket;
  730.         unsigned int todo;
  731.         todo = OS_NETSOCKET((family << 8) + protocol);
  732.         if (todo > 32767)
  733.         {
  734.                 clearStatus();
  735.                 AT(1, 24);
  736.                 printf("OS_NETSOCKET: ");
  737.                 errorPrint(todo & 255);
  738.                 exit(0);
  739.         }
  740.         else
  741.         {
  742.                 socket = ((todo & 65280) >> 8);
  743.         }
  744.         return socket;
  745. }
  746.  
  747. signed char netShutDown(signed char socket, unsigned char type)
  748. {
  749.         unsigned int todo;
  750.         todo = OS_NETSHUTDOWN(socket, type);
  751.         if (todo > 32767)
  752.         {
  753.                 clearStatus();
  754.                 printf("OS_NETSHUTDOWN: [ERROR:");
  755.                 errorPrint(todo & 255);
  756.                 printf("] Press any key.");
  757.                 return -1;
  758.         }
  759.         else
  760.         {
  761.                 // printf("Socket #%d closed.\n\r", socket);
  762.         }
  763.         return 1;
  764. }
  765.  
  766. unsigned char netConnect(unsigned char socket)
  767. {
  768.         unsigned int todo;
  769.         unsigned char retry = 10;
  770.  
  771.         targetadr.family = AF_INET;
  772.         targetadr.porth = 00;
  773.         targetadr.portl = 80;
  774.         targetadr.b1 = 31;
  775.         targetadr.b2 = 31;
  776.         targetadr.b3 = 65;
  777.         targetadr.b4 = 35;
  778.  
  779.         while (retry > 0)
  780.         {
  781.                 todo = OS_NETCONNECT(socket, &targetadr);
  782.  
  783.                 if (todo > 32767)
  784.                 {
  785.                         retry--;
  786.                         clearStatus();
  787.                         printf("OS_NETCONNECT [ERROR:");
  788.                         errorPrint(todo & 255);
  789.                         printf("] [Retry:%u]", retry);
  790.                         YIELD();
  791.                         netShutDown(socket, 0);
  792.                         socket = OpenSock(AF_INET, SOCK_STREAM);
  793.                 }
  794.                 else
  795.                 {
  796.                         // printf("OS_NETCONNECT: connection successful, %u\n\r", (todo & 255));
  797.                         return 1;
  798.                 }
  799.         }
  800.         getchar();
  801.         exit(0);
  802.         return 0;
  803. }
  804.  
  805. unsigned char saveBuf(unsigned char *fileNamePtr, unsigned char operation, unsigned int sizeOfBuf)
  806. {
  807.         if (operation == 00)
  808.         {
  809.                 fp2 = OS_CREATEHANDLE(fileNamePtr, 0x80);
  810.                 if (((int)fp2) & 0xff)
  811.                 {
  812.                         clearStatus();
  813.                         AT(1, 24);
  814.                         printf("%s", fileNamePtr);
  815.                         printf(" creating error.");
  816.                         exit(0);
  817.                 }
  818.                 OS_CLOSEHANDLE(fp2);
  819.  
  820.                 fp2 = OS_OPENHANDLE(fileNamePtr, 0x80);
  821.                 if (((int)fp2) & 0xff)
  822.                 {
  823.                         clearStatus();
  824.                         AT(1, 24);
  825.                         printf("%s", fileNamePtr);
  826.                         printf(" opening error. ");
  827.  
  828.                         exit(0);
  829.                 }
  830.                 AT(1, 24);
  831.                 return 0;
  832.         }
  833.  
  834.         if (operation == 01)
  835.         {
  836.                 OS_WRITEHANDLE(netbuf + headlng, fp2, sizeOfBuf);
  837.                 return 0;
  838.         }
  839.  
  840.         if (operation == 02)
  841.         {
  842.                 OS_CLOSEHANDLE(fp2);
  843.                 return 0;
  844.         }
  845.         return 0;
  846. }
  847.  
  848. unsigned int tcpRead(unsigned char socket)
  849. {
  850.         unsigned char retry = 20;
  851.         unsigned int todo;
  852.         readStruct.socket = socket;
  853.         readStruct.BufAdr = (unsigned int)&netbuf;
  854.         readStruct.bufsize = sizeof(netbuf);
  855.         readStruct.protocol = SOCK_STREAM;
  856.  
  857.         while (retry > 0)
  858.         {
  859.                 todo = OS_WIZNETREAD(&readStruct);
  860.  
  861.                 if (todo > 32767)
  862.                 {
  863.                         if ((todo & 255) != ERR_EAGAIN)
  864.                         {
  865.                                 clearStatus();
  866.                                 printf("OS_WIZNETREAD: [ERROR:");
  867.                                 errorPrint(todo & 255);
  868.                                 printf("] [Retry:%u]", retry);
  869.                                 YIELD();
  870.                                 retry--;
  871.                         }
  872.                 }
  873.                 else
  874.                 {
  875.                         // printf("OS_WIZNETREAD: %u bytes read. \n\r", todo);
  876.                         return todo;
  877.                 }
  878.         }
  879.         getchar();
  880.         exit(0);
  881.         return todo;
  882. }
  883.  
  884. unsigned int cutHeader(unsigned int todo)
  885. {
  886.         unsigned int err;
  887.         unsigned char *count1;
  888.  
  889.         err = httpError();
  890.         if (err != 200)
  891.         {
  892.                 BOX(1, 1, 80, 25, 40, 32);
  893.                 AT(1, 1);
  894.                 printf("HTTP ERROR %u", err);
  895.                 puts("^^^^^^^^^^^^^^^^^^^^^");
  896.                 puts(netbuf);
  897.                 getchar();
  898.                 fatalError("Server response error!");
  899.         }
  900.         count1 = strstr(netbuf, "Content-Length:");
  901.         if (count1 == NULL)
  902.         {
  903.                 printf("contLen  not found \r\n");
  904.                 contLen = 0;
  905.         }
  906.         else
  907.         {
  908.                 contLen = atol(count1 + 15);
  909.                 // printf("Content-Length: %lu \n\r", contLen);
  910.         }
  911.  
  912.         count1 = strstr(netbuf, "\r\n\r\n");
  913.         if (count1 == NULL)
  914.         {
  915.                 printf("header not found\r\n");
  916.         }
  917.         else
  918.         {
  919.                 headlng = ((unsigned int)count1 - (unsigned int)netbuf + 4);
  920.                 // printf("header %u bytes\r\n", headlng);
  921.         }
  922.         return todo - headlng;
  923. }
  924.  
  925. unsigned int tcpSend(unsigned char socket, unsigned int messageadr, unsigned int size)
  926. {
  927.         unsigned char retry = 20;
  928.         unsigned int todo;
  929.         readStruct.socket = socket;
  930.         readStruct.BufAdr = messageadr;
  931.         readStruct.bufsize = size;
  932.         readStruct.protocol = SOCK_STREAM;
  933.  
  934. wizwrite:
  935.         todo = OS_WIZNETWRITE(&readStruct);
  936.         if (todo > 32767)
  937.         {
  938.                 clearStatus();
  939.                 AT(1, 24);
  940.                 printf("OS_WIZNETWRITE: ");
  941.                 errorPrint(todo & 255);
  942.                 if (retry == 0)
  943.                 {
  944.                         exit(0);
  945.                 }
  946.                 retry--;
  947.                 if (_low_level_get() == 27)
  948.                 {
  949.                         fatalError("File download aborted!");
  950.                 }
  951.                 delay(100);
  952.                 goto wizwrite;
  953.         }
  954.  
  955.         return todo;
  956. }
  957. unsigned char getFile(unsigned char *fileLink, unsigned char *fileNamePtr)
  958. {
  959.         unsigned int todo;
  960.         unsigned char socket;
  961.         unsigned int skipHeader = 0;
  962.         unsigned int fileSize1;
  963.         unsigned long downloaded = 0;
  964.  
  965.         unsigned char sizeLink;
  966.         unsigned char byte, count = 0, try = 0;
  967.         unsigned char *count1;
  968.  
  969.         strcpy(netbuf, "GET ");
  970.         strcat(netbuf, fileLink);
  971.         strcat(netbuf, cmdlist1);
  972.         clearStatus();
  973.         AT(1, 24);
  974.         printf("%s", fileNamePtr);
  975.  
  976.         if (netDriver == 0)
  977.         {
  978.                 socket = OpenSock(AF_INET, SOCK_STREAM);
  979.                 todo = netConnect(socket);
  980.                 todo = tcpSend(socket, (unsigned int)&netbuf, strlen(netbuf));
  981.                 do
  982.                 {
  983.                         headlng = 0;
  984.                         todo = tcpRead(socket);
  985.                         if (todo == 0)
  986.                         {
  987.                                 break;
  988.                         }
  989.                         if (skipHeader == 0)
  990.                         {
  991.                                 skipHeader = 1;
  992.                                 todo = cutHeader(todo);
  993.                                 fileSize1 = contLen / 1024;
  994.                                 saveBuf(fileNamePtr, 00, 0);
  995.                         }
  996.                         downloaded = downloaded + todo;
  997.                         AT(32, 24);
  998.                         printf("%lu of %u kb  ", downloaded / 1024, fileSize1);
  999.  
  1000.                         saveBuf(fileNamePtr, 01, todo);
  1001.                         if (_low_level_get() == 27)
  1002.                         {
  1003.                                 fatalError("File download aborted!");
  1004.                         }
  1005.                 } while (downloaded < contLen);
  1006.  
  1007.                 netShutDown(socket, 0);
  1008.                 saveBuf(fileNamePtr, 02, 00);
  1009.  
  1010.                 if (downloaded != contLen)
  1011.                 {
  1012.                         fatalError("File download error!");
  1013.                 }
  1014.         }
  1015.         if (netDriver == 1)
  1016.         {
  1017.                 strcpy(link, netbuf);
  1018.                 sizeLink = strlen(link);
  1019.                 try = 0;
  1020.                 do
  1021.                 {
  1022.                         try++;
  1023.                         if (try > 1)
  1024.                         {
  1025.                                 clearStatus();
  1026.                                 printf("----->Retry:%u", try);
  1027.                                 delay(500);
  1028.                         }
  1029.                         sendcommand("AT+CIPSTART=\"TCP\",\"nedoos.ru\",80");
  1030.                         getAnswer2(); // CONNECT or ERROR or link is not valid
  1031.                         count1 = strstr(netbuf, "CONNECT");
  1032.                 } while (count1 == NULL);
  1033.  
  1034.                 getAnswer2(); // OK
  1035.  
  1036.                 strcpy(cmd, "AT+CIPSEND=");
  1037.                 sprintf(netbuf, "%u", sizeLink + 2); // second CRLF in send command
  1038.                 strcat(cmd, netbuf);
  1039.                 sendcommand(cmd);
  1040.                 getAnswer2();
  1041.  
  1042.                 do
  1043.                 {
  1044.                         byte = uart_readBlock();
  1045.                         // putchar(byte);
  1046.                 } while (byte != '>');
  1047.                 sendcommand(link);
  1048.                 count = 0;
  1049.  
  1050.                 do
  1051.                 {
  1052.                         byte = uart_readBlock();
  1053.                         if (byte == sendOk[count])
  1054.                         {
  1055.                                 count++;
  1056.                         }
  1057.                         else
  1058.                         {
  1059.                                 count = 0;
  1060.                         }
  1061.                 } while (count < strlen(sendOk));
  1062.                 uart_readBlock(); // CR
  1063.                 uart_readBlock(); // LF
  1064.  
  1065.                 do
  1066.                 {
  1067.                         headlng = 0;
  1068.                         todo = recvHead();
  1069.                         getdataEsp(todo); // Requested size
  1070.                         if (skipHeader == 0)
  1071.                         {
  1072.                                 skipHeader = 1;
  1073.                                 todo = cutHeader(todo);
  1074.                                 fileSize1 = contLen / 1024;
  1075.                                 saveBuf(fileNamePtr, 00, 0);
  1076.                         }
  1077.                         downloaded = downloaded + todo;
  1078.                         AT(32, 24);
  1079.                         printf("%lu of %u kb   ", downloaded / 1024, fileSize1);
  1080.  
  1081.                         saveBuf(fileNamePtr, 01, todo);
  1082.  
  1083.                         if (_low_level_get() == 27)
  1084.                         {
  1085.                                 fatalError("File download aborted!");
  1086.                         }
  1087.                 } while (downloaded < contLen);
  1088.                 saveBuf(fileNamePtr, 02, 00);
  1089.                 sendcommand("AT+CIPCLOSE");
  1090.                 getAnswer2(); // CLOSED
  1091.                 getAnswer2(); // OK
  1092.         }
  1093.  
  1094.         return 0;
  1095. }
  1096. ////////////////////////////////////////////////////
  1097. /*
  1098. unsigned char getTrack2(unsigned long fileId)
  1099. {
  1100.         unsigned int todo;
  1101.         unsigned char socket;
  1102.         unsigned int skipHeader = 0;
  1103.         unsigned long bytecount;
  1104.         unsigned int packSize = 2000;
  1105.         unsigned char sizeLink;
  1106.         unsigned long toDownload, downloaded;
  1107.         unsigned char try = 0, byte = 0;
  1108.         unsigned int todo, count;
  1109.         unsigned char *count1;
  1110.         clearStatus();
  1111.         printf("Getting track...");
  1112.  
  1113.         if (netDriver == 0)
  1114.         {
  1115.                 strcpy(netbuf, cmdlist1);
  1116.                 sprintf(buffer, "%lu", fileId);
  1117.                 strcat(netbuf, buffer);
  1118.                 strcat(netbuf, userAgent);
  1119.  
  1120.                 socket = OpenSock(AF_INET, SOCK_STREAM);
  1121.                 todo = netConnect(socket);
  1122.                 todo = tcpSend(socket, (unsigned int)&netbuf, strlen(netbuf));
  1123.                 saveBuf(curFileStruct.picId, 00, 0);
  1124.                 do
  1125.                 {
  1126.                         todo = tcpRead(socket);
  1127.                         if (todo == 0)
  1128.                         {
  1129.                                 break;
  1130.                         }
  1131.                         if (skipHeader == 0)
  1132.                         {
  1133.                                 skipHeader = 1;
  1134.                                 todo = cutHeader(todo);
  1135.                                 bytecount = contLen;
  1136.                         }
  1137.                         saveBuf(curFileStruct.picId, 01, todo);
  1138.                         bytecount = bytecount - todo;
  1139.                 } while (bytecount != 0);
  1140.                 netShutDown(socket, 0);
  1141.         }
  1142.         else
  1143.         {
  1144.                 sprintf(buffer, "%lu", fileId);
  1145.                 strcpy(netbuf, cmdlist1);
  1146.                 strcat(netbuf, buffer);
  1147.                 strcat(netbuf, userAgent);
  1148.                 saveBuf(curFileStruct.picId, 00, 0);
  1149.  
  1150.                 strcpy(link, netbuf);
  1151.                 sizeLink = strlen(link);
  1152.                 try = 0;
  1153.                 do
  1154.                 {
  1155.                         try++;
  1156.                         if (try > 1)
  1157.                         {
  1158.                                 clearStatus();
  1159.                                 printf("----->Retry:%u", try);
  1160.                                 delay(500);
  1161.                         }
  1162.                         sendcommand("AT+CIPSTART=\"TCP\",\"zxart.ee\",80");
  1163.                         getAnswer2(); // CONNECT or ERROR or link is not valid
  1164.                         count1 = strstr(netbuf, "CONNECT");
  1165.                 } while (count1 == NULL);
  1166.  
  1167.                 getAnswer2(); // OK
  1168.  
  1169.                 strcpy(netbuf, cmdlist1);
  1170.                 sprintf(buffer, "%lu", fileId);
  1171.                 strcat(netbuf, buffer);
  1172.                 strcat(netbuf, userAgent);
  1173.                 strcpy(cmd, "AT+CIPSEND=");
  1174.                 sprintf(netbuf, "%u", sizeLink + 2); // second CRLF in send command
  1175.                 strcat(cmd, netbuf);
  1176.                 sendcommand(cmd);
  1177.                 getAnswer2();
  1178.  
  1179.                 do
  1180.                 {
  1181.                         byte = uart_readBlock();
  1182.                         // putchar(byte);
  1183.                 } while (byte != '>');
  1184.                 sendcommand(link);
  1185.                 count = 0;
  1186.  
  1187.                 do
  1188.                 {
  1189.                         byte = uart_readBlock();
  1190.                         if (byte == sendOk[count])
  1191.                         {
  1192.                                 count++;
  1193.                         }
  1194.                         else
  1195.                         {
  1196.                                 count = 0;
  1197.                         }
  1198.                 } while (count < strlen(sendOk));
  1199.                 uart_readBlock(); // CR
  1200.                 uart_readBlock(); // LF
  1201.                 skipHeader = 0;
  1202.                 downloaded = 0;
  1203.  
  1204.                 do
  1205.                 {
  1206.                         headlng = 0;
  1207.                         todo = recvHead();
  1208.                         getdataEsp(todo); // Requested size
  1209.                         if (skipHeader == 0)
  1210.                         {
  1211.                                 todo = cutHeader(todo);
  1212.                                 toDownload = contLen;
  1213.                                 skipHeader = 1;
  1214.                         }
  1215.                         downloaded = downloaded + todo;
  1216.                         saveBuf(curFileStruct.picId, 01, todo);
  1217.                         toDownload = toDownload - todo;
  1218.                 } while (toDownload > 0);
  1219.                 sendcommand("AT+CIPCLOSE");
  1220.                 getAnswer2(); // CLOSED
  1221.                 getAnswer2(); // OK
  1222.         }
  1223.         return 0;
  1224. }
  1225. */
  1226. unsigned char getConfig(void)
  1227. {
  1228.         config.is_atm = (unsigned char)OS_GETCONFIG();
  1229.         // H=system drive, L= 1-Evo 2-ATM2 3-ATM3 6-p2.666 ;E=pgsys(system page) D= TR-DOS page
  1230.         switch ((config.is_atm))
  1231.         {
  1232.         case 1:
  1233.                 strcpy(config.machineName, "ZX-Evolution");
  1234.                 strcpy(config.kernelName, "sd_boot.$C");
  1235.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/sd_boot.%24C");
  1236.                 break;
  1237.         case 2:
  1238.                 strcpy(config.machineName, "TURBO 2+");
  1239.                 strcpy(config.kernelName, "osatm2hd.$C");
  1240.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/osatm2hd.%24C");
  1241.  
  1242.                 break;
  1243.  
  1244.         case 3: // SD HDD versions
  1245.                 strcpy(config.machineName, "TURBO 3 [SD]");
  1246.                 strcpy(config.kernelName, "osatm3hd.$C");
  1247.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/osatm3hd.%24C");
  1248.                 break;
  1249.         case 6: // SD HDD versions
  1250.                 strcpy(config.machineName, "P2.666 [SD]");
  1251.                 strcpy(config.kernelName, "osp26sd.$C");
  1252.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/osp26sd.%24C");
  1253.                 break;
  1254.  
  1255.         default:
  1256.                 strcpy(config.machineName, "NOT DETECED (ZX-Evo)");
  1257.                 strcpy(config.kernelName, "sd_boot.$C");
  1258.                 strcpy(config.kernelLink, "/svn/dl.php?repname=NedoOS&path=/release/sd_boot.s%24C");
  1259.                 break;
  1260.         }
  1261.         return config.is_atm;
  1262. }
  1263. // Downloading minimal tools for updating/boot
  1264. void getTools(void)
  1265. {
  1266.         OS_MKDIR("bin"); // Create if not exist
  1267.         ATRIB(cw.text);
  1268.         ATRIB(cw.back);
  1269.         getFile(wizNetLink, "bin/wizcfg.com");
  1270.         getFile(newsLink, "updater.new");
  1271.         getFile(pkunzipLink, "bin/pkunzip.com");
  1272.         getFile(tarLink, "bin/tar.com");
  1273.         getFile(cmdLink, "bin/cmd.com");
  1274.         getFile(termLink, "bin/term.com");
  1275.         getFile(updLink, "bin/updater.com");
  1276.         getFile(netIniLink, "bin/net_.ini");
  1277. }
  1278.  
  1279. void deleteWorkFiles(void)
  1280. {
  1281.         OS_DELETE("bin.zip");
  1282.         OS_DELETE("bin.tar");
  1283. }
  1284.  
  1285. unsigned char ren2old(unsigned char *name)
  1286. {
  1287.         unsigned char counter = 255; // For OLD must be 255
  1288.         OS_MKDIR((void *)name);
  1289.         sprintf(nameBuf, "%s.old", name);
  1290.         while (OS_RENAME((void *)name, (void *)nameBuf) != 0)
  1291.         {
  1292.                 counter++;
  1293.                 sprintf(nameBuf, "%s.%u", name, counter);
  1294.                 if (counter == 255)
  1295.                 {
  1296.                         fatalError("Unable to rename old folder");
  1297.                 }
  1298.         }
  1299.         return counter;
  1300. }
  1301.  
  1302. void ren2tar(void)
  1303. {
  1304.         unsigned int counter = 2400;
  1305.         do
  1306.         {
  1307.                 sprintf(nameBuf, "bin.r%u", counter);
  1308.  
  1309.                 errn = OS_RENAME((void *)nameBuf, "bin.tar");
  1310.                 counter--;
  1311.                 if (counter < 2000)
  1312.                 {
  1313.                         fatalError("Unable to rename TAR file");
  1314.                 }
  1315.         } while (errn != 0);
  1316. }
  1317.  
  1318. void ren2bin(void)
  1319. {
  1320.         unsigned char counter = 20;
  1321.         sprintf(nameBuf, "bin.r%u", counter);
  1322.         do
  1323.         {
  1324.                 errn = OS_RENAME((void *)nameBuf, "bin");
  1325.                 counter++;
  1326.                 sprintf(nameBuf, "bin.r%u", counter);
  1327.                 if (counter > 99)
  1328.                 {
  1329.                         fatalError("Unable to rename BIN folder");
  1330.                 }
  1331.         } while (errn != 0);
  1332. }
  1333.  
  1334. void restoreConfig(unsigned char oldBinExt)
  1335. {
  1336.         unsigned char count;
  1337.         errn = OS_CHDIR("/");
  1338.         errn = OS_RENAME("bin/autoexec.bat", "bin/autoexec.bat.new");
  1339.         errn = OS_RENAME("bin/net.ini", "bin/net.ini.new");
  1340.         errn = OS_RENAME("bin/nv.ext", "bin/nv.ext.new");
  1341.         errn = OS_RENAME("bin/gp/gp.ini", "bin/gp/gp.ini.new");
  1342.         errn = OS_RENAME("/bin/browser/index.gph", "/bin/browser/index.gph.new");
  1343.  
  1344.         errn = OS_CHDIR("/");
  1345.  
  1346.         if (oldBinExt == 255)
  1347.         {
  1348.                 errn = OS_SHELL("copy bin.old/autoexec.bat bin/autoexec.bat");
  1349.  
  1350.                 errn = OS_SHELL("copy bin.old/net.ini bin/net.ini");
  1351.  
  1352.                 errn = OS_SHELL("copy bin.old/nv.ext bin/nv.ext");
  1353.  
  1354.                 errn = OS_SHELL("copy bin.old/gp/gp.ini bin/gp/gp.ini");
  1355.                 errn = OS_SHELL("copy bin.old/browser/index.gph bin/browser/index.gph");
  1356.         }
  1357.         else
  1358.         {
  1359.                 sprintf(nameBuf, "copy bin.%u/autoexec.bat bin/autoexec.bat", oldBinExt);
  1360.                 OS_SHELL((void *)nameBuf);
  1361.  
  1362.                 sprintf(nameBuf, "copy bin.%u/net.ini bin/net.ini", oldBinExt);
  1363.                 OS_SHELL((void *)nameBuf);
  1364.  
  1365.                 sprintf(nameBuf, "copy bin.%u/nv.ext bin/nv.ext", oldBinExt);
  1366.                 OS_SHELL((void *)nameBuf);
  1367.                 sprintf(nameBuf, "copy bin.%u/gp/gp.ini bin/gp/gp.ini", oldBinExt);
  1368.                 OS_SHELL((void *)nameBuf);
  1369.                 sprintf(nameBuf, "copy bin.%u/browser/index.gph bin/browser/index.gph", oldBinExt);
  1370.                 OS_SHELL((void *)nameBuf);
  1371.         }
  1372.         AT(1, 4);
  1373.         for (count = 0; count < 15; count++)
  1374.         {
  1375.                 putchar(176);
  1376.         }
  1377.         errn = OS_RENAME("bin/autoexec.bat.new", "bin/autoexec.bat"); // If file already exist we dont rename
  1378.         errn = OS_RENAME("bin/net.ini.new", "bin/net.ini");
  1379.         errn = OS_RENAME("bin/nv.ext.new", "bin/nv.ext");
  1380.         errn = OS_RENAME("bin/gp/gp.ini.new", "bin/gp/gp.ini");
  1381.         errn = OS_RENAME("bin/browser/index.gph.new", "bin/browser/index.gph");
  1382. }
  1383.  
  1384. // Download, backup, unpack release.bin
  1385. void fullUpdate(void)
  1386. {
  1387.         BOX(1, 1, 80, 25, 40, 176);
  1388.         cw.x = 20;
  1389.         cw.y = 5;
  1390.         cw.w = 40;
  1391.         cw.h = 7;
  1392.         cw.text = 97;
  1393.         cw.back = 45;
  1394.  
  1395.         AT(1, 1);
  1396.         ATRIB(cw.text);
  1397.         ATRIB(cw.back);
  1398.         printf("                   [FULL UPDATE - UPDATING ALL SYSTEM FILES]                    ");
  1399.  
  1400.         strcpy(cw.tittle, "nedoOS FULL updater ");
  1401.         strcat(cw.tittle, uVer);
  1402.  
  1403.         getConfig();
  1404.  
  1405.         OS_GETPATH((unsigned int)&curPath);
  1406.         curLetter = curPath[0];
  1407.         errn = OS_CHDIR("/");
  1408.  
  1409.         strcat(cw.tittle, " (");
  1410.         strcat(cw.tittle, config.machineName);
  1411.         strcat(cw.tittle, ")");
  1412.         drawWindow(cw);
  1413.  
  1414.         OS_DELETE("release.zip");
  1415.  
  1416.         clearStatus();
  1417.         AT(cw.x + 2, cw.y + 3);
  1418.         printf("1.Downloading release.zip...");
  1419.  
  1420.         errn = getFile(relLink, "release.zip"); //  Downloading the file
  1421.  
  1422.         clearStatus();
  1423.  
  1424.         clearStatus();
  1425.         AT(cw.x + 2, cw.y + 4);
  1426.         printf("2.Backuping old system...\r\n");
  1427.  
  1428.         oldBinExt = ren2old("bin");
  1429.         ren2old("doc");
  1430.         ren2old("nedodemo");
  1431.         ren2old("nedogame");
  1432.  
  1433.         AT(cw.x + 2, cw.y + 5);
  1434.         printf("3.Downloading tools...\r\n");
  1435.  
  1436.         getTools();
  1437.  
  1438.         BOX(1, 1, 80, 25, 40, 32);
  1439.         AT(1, 1);
  1440.         printf("Depacking release. Its take about 10 hours. Please wait.\r\n");
  1441.         printf("First hours going without signs of life.\r\n");
  1442.  
  1443.         printNews();
  1444.  
  1445.         YIELD();
  1446.         OS_SHELL("pkunzip.com release.zip");
  1447.         BOX(1, 1, 80, 25, 40, 176);
  1448.         drawWindow(cw);
  1449.         AT(cw.x + 2, cw.y + 3);
  1450.         ATRIB(cw.text);
  1451.         ATRIB(cw.back);
  1452.         printf("Restoring configs...");
  1453. }
  1454. // Updating only BIN folders, where is OS lives.
  1455. void binUpdate(void)
  1456. {
  1457.         BOX(1, 1, 80, 25, 40, 176);
  1458.         cw.x = 20;
  1459.         cw.y = 5;
  1460.         cw.w = 40;
  1461.         cw.h = 11;
  1462.         cw.text = 97;
  1463.         cw.back = 44;
  1464.  
  1465.         AT(1, 1);
  1466.         ATRIB(cw.text);
  1467.         ATRIB(cw.back);
  1468.         printf("                  [STANDART UPDATE - UPDATING ONLY BIN FOLDER]                  ");
  1469.  
  1470.         strcpy(cw.tittle, "nedoOS BIN updater ");
  1471.         strcat(cw.tittle, uVer);
  1472.         getConfig();
  1473.         strcat(cw.tittle, " (");
  1474.         strcat(cw.tittle, config.machineName);
  1475.         strcat(cw.tittle, ")");
  1476.         drawWindow(cw);
  1477.  
  1478.         OS_CHDIR("/");
  1479.         OS_GETPATH((unsigned int)&curPath);
  1480.         curLetter = curPath[0];
  1481.  
  1482.         deleteWorkFiles();
  1483.  
  1484.         clearStatus();
  1485.  
  1486.         AT(cw.x + 2, cw.y + 10);
  1487.         printf(">To full update start 'updater.com F'<");
  1488.  
  1489.         AT(cw.x + 2, cw.y + 3);
  1490.         printf("1.Downloading bin.zip...");
  1491.  
  1492.         getFile(binLink, "bin.zip"); //  Downloading the file
  1493.  
  1494.         clearStatus();
  1495.         AT(cw.x + 2, cw.y + 4);
  1496.         printf("2.Downloading tools...");
  1497.  
  1498.         getTools();
  1499.  
  1500.         BOX(1, 1, 80, 25, 40, 32);
  1501.         AT(1, 1);
  1502.         printf("Please, make sure you don't have bin.r* folder on disk!!!\r\n");
  1503.         printf("Depacking release. Its take about 10 minutes. Please wait...\r\n");
  1504.  
  1505.         printNews();
  1506.         YIELD();
  1507.  
  1508.         OS_SHELL("pkunzip.com bin.zip");
  1509.         BOX(1, 1, 80, 25, 40, 176);
  1510.         drawWindow(cw);
  1511.         clearStatus();
  1512.         AT(cw.x + 2, cw.y + 3);
  1513.         ATRIB(cw.text);
  1514.         ATRIB(cw.back);
  1515.         printf("3.Renaming bin.r?? to bin.tar...");
  1516.  
  1517.         ren2tar();
  1518.  
  1519.         AT(cw.x + 2, cw.y + 4);
  1520.         ATRIB(cw.text);
  1521.         ATRIB(cw.back);
  1522.         printf("4.Untaring bin.tar, please wait...");
  1523.         clearStatus();
  1524.         OS_SHELL("tar.com bin.tar");
  1525.  
  1526.         AT(cw.x + 2, cw.y + 5);
  1527.         ATRIB(cw.text);
  1528.         ATRIB(cw.back);
  1529.         printf("5.Backuping old bin to bin.old...");
  1530.  
  1531.         oldBinExt = ren2old("bin");
  1532.  
  1533.         AT(cw.x + 2, cw.y + 6);
  1534.         ATRIB(cw.text);
  1535.         ATRIB(cw.back);
  1536.         printf("6.Renaming NEW BIN...");
  1537.  
  1538.         ren2bin();
  1539.  
  1540.         AT(cw.x + 2, cw.y + 7);
  1541.         ATRIB(cw.text);
  1542.         ATRIB(cw.back);
  1543.         printf("7.Deleting zip & tar...");
  1544.  
  1545.         AT(cw.x + 2, cw.y + 8);
  1546.         ATRIB(cw.text);
  1547.         ATRIB(cw.back);
  1548.         printf("8.Downloading kernel [%s]...", config.machineName);
  1549.         errn = OS_CHDIR("/");
  1550.         errn = getFile(config.kernelLink, config.kernelName); //  Downloading the file
  1551.         AT(cw.x + 2, cw.y + 9);
  1552.         ATRIB(cw.text);
  1553.         ATRIB(cw.back);
  1554.         printf("9.Restoring configs...");
  1555. }
  1556.  
  1557. C_task main(int argc, char *argv[])
  1558. {
  1559.         os_initstdio();
  1560.  
  1561.         if (argc > 1)
  1562.         {
  1563.                 if (argv[1][0] == 'F')
  1564.                 {
  1565.                         fullUpdate();
  1566.                 }
  1567.                 else if (argv[1][0] == 'e')
  1568.                 {
  1569.                         netDriver = 1;
  1570.                         clearStatus();
  1571.                         printf("    ESP-COM mode enabled...");
  1572.                         loadEspConfig();
  1573.                         uart_init(divider);
  1574.                         espReBoot();
  1575.                         binUpdate();
  1576.                 }
  1577.                 else if (argv[1][0] == 'E')
  1578.                 {
  1579.                         netDriver = 1;
  1580.                         clearStatus();
  1581.                         printf("    ESP-COM mode enabled...");
  1582.                         loadEspConfig();
  1583.                         uart_init(divider);
  1584.                         espReBoot();
  1585.                         fullUpdate();
  1586.                 }
  1587.                 else
  1588.                 {
  1589.                         AT(1, 1);
  1590.                         // printTable();
  1591.                         // printNews();
  1592.                         // getchar();
  1593.                         fatalError("Use 'F' key to FULL update");
  1594.                         exit(0);
  1595.                 }
  1596.         }
  1597.         else
  1598.         {
  1599.                 binUpdate();
  1600.         }
  1601.         restoreConfig(oldBinExt);
  1602.         deleteWorkFiles();
  1603.         clearStatus();
  1604.         infoBox("System Updated successfully!");
  1605.         getchar();
  1606.         OS_DELETE("release.zip");
  1607.         ATRIB(40);
  1608.         ATRIB(32);
  1609.         exit(0);
  1610. }
  1611.