?login_element?

Subversion Repositories NedoOS

Rev

Rev 1827 | Rev 1968 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download

  1. #include <math.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <oscalls.h>
  6. #include <osfs.h>
  7. #include <intrz80.h>
  8. #include <ctype.h>
  9. #include <tcp.h>
  10. #include <graphic.h>
  11. #include <terminal.c>
  12. #define COMMANDLINE 0x0080
  13. unsigned char ver[] = "1.8";
  14. unsigned char queryType[64];
  15. unsigned char netbuf[1452];
  16. unsigned char dataBuffer[6096];
  17. unsigned char crlf[2] = {13, 10};
  18. unsigned char formats[4][4] = {"pt3", "pt2", "tfc", "ts"};
  19. unsigned long bytecount;
  20. unsigned char status, key, curFormat;
  21. struct sockaddr_in targetadr;
  22. struct readstructure readStruct;
  23. unsigned long contLen;
  24. long count;
  25. unsigned char saveFlag, saveBak, logFlag, rptFlag;
  26. union APP_PAGES main_pg;
  27. union APP_PAGES player_pg;
  28. extern void dns_resolve(void);
  29.  
  30. struct fileStruct
  31. {
  32.   long picId;
  33.   unsigned long fileSize;
  34.   unsigned int picYear;
  35.   unsigned long totalAmount;
  36.   unsigned int curPos;
  37.   unsigned int startBar;
  38.   unsigned int trackInSeconds;
  39.   unsigned char time[16];
  40.   unsigned char picRating[8];
  41.   unsigned char trackName[256];
  42.   unsigned char fileName[256];
  43.   unsigned char authorIds[64];
  44.   unsigned char authorTitle[64];
  45.   unsigned char authorRealName[64];
  46.   unsigned char afn[64];
  47.   unsigned char tfn[64];
  48.   unsigned char fileName2[256];
  49. } curFileStruct;
  50.  
  51. void delay(unsigned long counter)
  52. {
  53.   unsigned long start, finish;
  54.   counter = counter / 20;
  55.   if (counter < 1)
  56.   {
  57.     counter = 1;
  58.   }
  59.   start = time();
  60.   finish = start + counter;
  61.  
  62.   while (start < finish)
  63.   {
  64.     start = time();
  65.     YIELD();
  66.   }
  67. }
  68.  
  69. void clearStatus(void)
  70. {
  71.   AT(1, 25);
  72.   printf("                                                                               \r");
  73. }
  74.  
  75. void printProgress(unsigned char type)
  76. {
  77.   unsigned char bar, minutes, seconds;
  78.   unsigned char *position;
  79.   long barLenght;
  80.   int timer;
  81.   switch (type)
  82.   {
  83.   case 0: // print empty bar
  84.     AT(6, 11);
  85.     ATRIB(93);
  86.     printf("%02u:%02u", 0, 0);
  87.     AT(15, 11);
  88.     ATRIB(97);
  89.     for (bar = 0; bar < 50; bar++)
  90.     {
  91.       putchar(176);
  92.     }
  93.     putchar(' ');
  94.     putchar(' ');
  95.     minutes = atoi(curFileStruct.time);
  96.     position = (strstr(curFileStruct.time, ":")) + 1;
  97.     seconds = atoi(position);
  98.     curFileStruct.trackInSeconds = minutes * 60 + seconds;
  99.     curFileStruct.curPos = 0;
  100.     curFileStruct.startBar = 0;
  101.     break;
  102.   case 1: // print progress bar
  103.  
  104.     AT(6, 11);
  105.     ATRIB(93);
  106.     timer = floor(curFileStruct.curPos / 60);
  107.     printf("%02u:%02u", timer, (curFileStruct.curPos - (timer * 60)));
  108.  
  109.     barLenght = (curFileStruct.curPos * 50 / curFileStruct.trackInSeconds);
  110.     if (barLenght > 49)
  111.     {
  112.       barLenght = 50;
  113.     }
  114.     AT(15 + curFileStruct.startBar, 11);
  115.     ATRIB(97);
  116.     for (bar = 0; bar < barLenght - curFileStruct.startBar; bar++)
  117.     {
  118.       putchar(178);
  119.     }
  120.     AT(1, 1);
  121.     curFileStruct.startBar = bar;
  122.     break;
  123.   case 2: // print full bar
  124.     AT(15, 11);
  125.     ATRIB(97);
  126.     for (bar = 0; bar < 50; bar++)
  127.     {
  128.       putchar(178);
  129.     }
  130.     break;
  131.   }
  132. }
  133. void errorPrint(unsigned int error)
  134. {
  135.   switch (error)
  136.   {
  137.   case 2:
  138.     printf("02 SHUT_RDWR");
  139.     break;
  140.   case 4:
  141.     printf("04 ERR_INTR");
  142.     break;
  143.   case 23:
  144.     printf("23 ERR_NFILE");
  145.     break;
  146.   case 35:
  147.     printf("35 ERR_EAGAIN");
  148.     break;
  149.   case 37:
  150.     printf("37 ERR_ALREADY");
  151.     break;
  152.   case 38:
  153.     printf("38 ERR_NOTSOCK");
  154.     break;
  155.   case 40:
  156.     printf("40 ERR_EMSGSIZE");
  157.     break;
  158.   case 41:
  159.     printf("41 ERR_PROTOTYPE");
  160.     break;
  161.   case 47:
  162.     printf("47 ERR_AFNOSUPPORT");
  163.     break;
  164.   case 53:
  165.     printf("53 ERR_ECONNABORTED");
  166.     break;
  167.   case 54:
  168.     printf("54 ERR_CONNRESET");
  169.     break;
  170.   case 57:
  171.     printf("57 ERR_NOTCONN");
  172.     break;
  173.   case 65:
  174.     printf("65 ERR_HOSTUNREACH");
  175.     break;
  176.   default:
  177.     printf("%u UNKNOWN ERROR", error);
  178.     break;
  179.   }
  180.   YIELD();
  181.   //    do {key = _low_level_get();} while (key == 0);
  182. }
  183.  
  184. unsigned char OpenSock(unsigned char family, unsigned char protocol)
  185. {
  186.   unsigned char socket;
  187.   unsigned int todo;
  188.   todo = OS_NETSOCKET((family << 8) + protocol);
  189.   if (todo > 32767)
  190.   {
  191.     clearStatus();
  192.     printf("OS_NETSOCKET: ");
  193.     errorPrint(todo & 255);
  194.     exit(0);
  195.   }
  196.   else
  197.   {
  198.     socket = ((todo & 65280) >> 8);
  199.     if (logFlag)
  200.     {
  201.       clearStatus();
  202.       printf("OS_NETSOCKET: Socket #%d created.", socket);
  203.     }
  204.   }
  205.   return socket;
  206. }
  207.  
  208. unsigned char netConnect(unsigned char socket)
  209. {
  210.   unsigned int todo;
  211.  
  212.   targetadr.family = AF_INET;
  213.   targetadr.porth = 00;
  214.   targetadr.portl = 80;
  215.   targetadr.b1 = 217;
  216.   targetadr.b2 = 146;
  217.   targetadr.b3 = 69;
  218.   targetadr.b4 = 13;
  219.  
  220.   todo = OS_NETCONNECT(socket, &targetadr);
  221.   if (todo > 32767)
  222.   {
  223.     clearStatus();
  224.     printf("OS_NETCONNECT: ");
  225.     errorPrint(todo & 255);
  226.  
  227.     exit(0);
  228.   }
  229.   else
  230.   {
  231.     if (logFlag)
  232.     {
  233.       clearStatus();
  234.       printf("OS_NETCONNECT: connected , %u", (todo & 255));
  235.     }
  236.   }
  237.   return 0;
  238. }
  239.  
  240. unsigned int tcpRead(unsigned char socket)
  241. {
  242.   unsigned char retry = 20;
  243.   unsigned int err, todo;
  244.   readStruct.socket = socket;
  245.   readStruct.BufAdr = (unsigned int)&netbuf;
  246.   readStruct.bufsize = sizeof(netbuf);
  247.   readStruct.protocol = SOCK_STREAM;
  248.  
  249. wizread:
  250.   todo = OS_WIZNETREAD(&readStruct);
  251.   if (todo > 32767)
  252.   {
  253.     if (retry == 0)
  254.     {
  255.       err = todo & 255;
  256.       clearStatus();
  257.       printf("OS_WIZNETREAD: ");
  258.       errorPrint(err);
  259.       if (err == 35)
  260.       {
  261.         return 0;
  262.       }
  263.       exit(0);
  264.     }
  265.     retry--;
  266.     if (logFlag)
  267.     {
  268.       AT(54, 25);
  269.       printf("OS_WIZNETREAD: retry %u   ", retry);
  270.     }
  271.     delay(200);
  272.     goto wizread;
  273.   }
  274.   if (logFlag)
  275.   {
  276.     clearStatus();
  277.     printf("OS_WIZNETREAD: %u bytes read.", todo);
  278.   }
  279.   return todo;
  280. }
  281.  
  282. unsigned int netShutDown(unsigned char socket)
  283. {
  284.   unsigned int todo;
  285.   todo = OS_NETSHUTDOWN(socket);
  286.   if (todo > 32767)
  287.   {
  288.     clearStatus();
  289.     printf("OS_NETSHUTDOWN: ");
  290.     errorPrint(todo & 255);
  291.     return 255;
  292.   }
  293.   else
  294.   {
  295.     if (logFlag)
  296.     {
  297.       clearStatus();
  298.       printf("OS_NETSHUTDOWN: Socket #%u closed.", socket);
  299.     }
  300.   }
  301.   return 0;
  302. }
  303. int pos(unsigned char *s, unsigned char *c, unsigned int n, unsigned int startPos)
  304. {
  305.   unsigned int i, j;
  306.   unsigned int lenC, lenS;
  307.  
  308.   for (lenC = 0; c[lenC]; lenC++)
  309.     ;
  310.   for (lenS = 0; s[lenS]; lenS++)
  311.     ;
  312.  
  313.   for (i = startPos; i <= lenS - lenC; i++)
  314.   {
  315.     for (j = 0; s[i + j] == c[j]; j++)
  316.       ;
  317.  
  318.     if (j - lenC == 1 && i == lenS - lenC && !(n - 1))
  319.       return i;
  320.     if (j == lenC)
  321.       if (n - 1)
  322.         n--;
  323.       else
  324.         return i;
  325.   }
  326.   return -1;
  327. }
  328.  
  329. char *str_replace(char *dst, int num, const char *str,
  330.                   const char *orig, const char *rep)
  331. {
  332.   const char *ptr;
  333.   size_t len1 = strlen(orig);
  334.   size_t len2 = strlen(rep);
  335.   char *tmp = dst;
  336.  
  337.   num -= 1;
  338.   while ((ptr = strstr(str, orig)) != NULL)
  339.   {
  340.     num -= (ptr - str) + len2;
  341.     if (num < 1)
  342.       break;
  343.  
  344.     strncpy(dst, str, (size_t)(ptr - str));
  345.     dst += ptr - str;
  346.     strncpy(dst, rep, len2);
  347.     dst += len2;
  348.     str = ptr + len1;
  349.   }
  350.  
  351.   for (; (*dst = *str) && (num > 0); --num)
  352.   {
  353.     ++dst;
  354.     ++str;
  355.   }
  356.   return tmp;
  357. }
  358.  
  359. const char *parseJson(unsigned char *property)
  360. {
  361.   unsigned int w, lng, lngp1, findEnd, listPos;
  362.   unsigned char terminator;
  363.   int n;
  364.   n = -1;
  365.   netbuf[0] = '\0';
  366.   n = pos(dataBuffer, property, 1, 0);
  367.   if (n == -1)
  368.   {
  369.     strcpy(netbuf, "0\0");
  370.     return netbuf;
  371.   }
  372.   lng = n - 1 + strlen(property);
  373.   if (dataBuffer[lng] == ':')
  374.   {
  375.     terminator = '\0';
  376.   }
  377.   if (dataBuffer[lng] == '\"')
  378.   {
  379.     terminator = '\"';
  380.   }
  381.   if (dataBuffer[lng] == '[')
  382.   {
  383.     terminator = ']';
  384.   }
  385.  
  386.   findEnd = 1;
  387.   lngp1 = lng + 1;
  388.  
  389.   while (42)
  390.   {
  391.  
  392.     if ((dataBuffer[lngp1 + findEnd] == ','))
  393.     {
  394.       if (terminator == '\0')
  395.       {
  396.         break;
  397.       }
  398.       if ((dataBuffer[lng + findEnd] == terminator))
  399.       {
  400.         findEnd--;
  401.         break;
  402.       }
  403.     }
  404.     findEnd++;
  405.   }
  406.   listPos = 0;
  407.   for (w = lngp1; w < findEnd + lngp1; w++)
  408.   {
  409.     netbuf[listPos] = dataBuffer[w];
  410.     listPos++;
  411.   }
  412.   netbuf[listPos] = '\0';
  413.   return netbuf;
  414. }
  415. void convert866(void)
  416. {
  417.   unsigned int lng, targetPos, w, q = 0;
  418.   unsigned char buffer[8], one, two;
  419.   unsigned int decVal;
  420.   lng = strlen(netbuf);
  421.   targetPos = lng + 1;
  422.  
  423.   while (q < lng)
  424.   {
  425.     one = netbuf[q];
  426.     two = netbuf[q + 1];
  427.     if (one == 92 && two == 117)
  428.     {
  429.       q = q + 2;
  430.       for (w = 0; w < 4; w++)
  431.       {
  432.         buffer[w] = netbuf[q + w];
  433.       }
  434.       q = q + 4;
  435.       buffer[4] = '\0';
  436.       decVal = (unsigned int)strtol(buffer, NULL, 16);
  437.  
  438.       if (decVal < 1088)
  439.       {
  440.         decVal = decVal - 912;
  441.       }
  442.       if (decVal > 1087)
  443.       {
  444.         decVal = decVal - 864;
  445.       }
  446.       if (decVal == 1025)
  447.       {
  448.         decVal = 240;
  449.       }
  450.       if (decVal == 1105)
  451.       {
  452.         decVal = 241;
  453.       }
  454.       netbuf[targetPos] = decVal;
  455.     }
  456.     else
  457.     {
  458.       netbuf[targetPos] = netbuf[q];
  459.       q++;
  460.     }
  461.     targetPos++;
  462.   }
  463.   netbuf[targetPos] = '\0';
  464.  
  465.   for (w = lng + 1; w < targetPos + 1; w++)
  466.   {
  467.     netbuf[w - lng - 1] = netbuf[w];
  468.   }
  469. }
  470.  
  471. unsigned int cutHeader(unsigned int todo)
  472. {
  473.   unsigned int q, headlng;
  474.   unsigned char *count;
  475.   count = strstr(netbuf, "Content-Length:");
  476.   if (count == NULL)
  477.   {
  478.     clearStatus();
  479.     printf("Content-Length:  not found.");
  480.     contLen = 0;
  481.   }
  482.   else
  483.   {
  484.     contLen = atol(count + 15);
  485.     bytecount = contLen;
  486.     curFileStruct.fileSize = bytecount;
  487.     //  printf("=> Dlinna  soderzhimogo = %lu \n\r", curFileStruct.fileSize);
  488.   }
  489.  
  490.   count = strstr(netbuf, "\r\n\r\n");
  491.   headlng = ((unsigned int)count - (unsigned int)netbuf + 4);
  492.   q = todo - headlng;
  493.   memcpy(&netbuf, count + 4, q);
  494.   // printf ("header removed. %u bytes\r\n", headlng);
  495.   return q;
  496. }
  497.  
  498. void nameRepair(unsigned char *pfn, unsigned int tfnSize)
  499. {
  500.   str_replace(pfn, tfnSize, pfn, "\\", "_");
  501.   str_replace(pfn, tfnSize, pfn, "/", "_");
  502.   str_replace(pfn, tfnSize, pfn, ":", "_");
  503.   str_replace(pfn, tfnSize, pfn, "*", "_");
  504.   str_replace(pfn, tfnSize, pfn, "?", "_");
  505.   str_replace(pfn, tfnSize, pfn, "<", "_");
  506.   str_replace(pfn, tfnSize, pfn, ">", "_");
  507.   str_replace(pfn, tfnSize, pfn, "|", "_");
  508.   str_replace(pfn, tfnSize, pfn, " ", "_");
  509.   str_replace(pfn, tfnSize, pfn, "&#039;", "'");
  510.   str_replace(pfn, tfnSize, pfn, "&amp;", "&");
  511.   str_replace(pfn, tfnSize, pfn, "&quot;", "'");
  512.   str_replace(pfn, tfnSize, pfn, "&gt;", ")");
  513.   str_replace(pfn, tfnSize, pfn, "&lt;", "(");
  514.   str_replace(pfn, tfnSize, pfn, "\"", "'");
  515. }
  516.  
  517. void stringRepair(unsigned char *pfn, unsigned int tSize)
  518. {
  519.   str_replace(pfn, tSize, pfn, "&#039;", "'");
  520.   str_replace(pfn, tSize, pfn, "&amp;", "&");
  521.   str_replace(pfn, tSize, pfn, "&gt;", ">");
  522.   str_replace(pfn, tSize, pfn, "&lt;", "<");
  523.   str_replace(pfn, tSize, pfn, "&quot;", "\"");
  524.   str_replace(pfn, tSize, pfn, "\\/", "/");
  525. }
  526.  
  527. unsigned char saveBuf(unsigned long fileId, unsigned char operation, unsigned int sizeOfBuf)
  528. {
  529.   FILE *fp2;
  530.   unsigned long fileSize;
  531.   unsigned char afnSize, tfnSize;
  532.   unsigned char fileIdChar[10];
  533.  
  534.   if (operation == 00)
  535.   {
  536.  
  537.     if (saveFlag == 0)
  538.     {
  539.       sprintf(curFileStruct.fileName, "temp.%s", formats[curFormat]);
  540.     }
  541.     else
  542.     {
  543.       afnSize = sizeof(curFileStruct.afn) - 1;
  544.       tfnSize = sizeof(curFileStruct.tfn) - 1;
  545.  
  546.       strcpy(curFileStruct.afn, curFileStruct.authorTitle);
  547.       nameRepair(curFileStruct.afn, afnSize);
  548.       /*
  549.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "\\", "_");
  550.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "/", "_");
  551.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, ":", "_");
  552.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "*", "_");
  553.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "?", "_");
  554.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "<", "_");
  555.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, ">", "_");
  556.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "|", "_");
  557.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, " ", "_");
  558.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "&#039;", "'");
  559.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "&amp;", "&");
  560.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "&quot;", "'");
  561.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "&gt;", ")");
  562.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "&lt;", "(");
  563.             str_replace(curFileStruct.afn, afnSize, curFileStruct.afn, "\"", "'");
  564.       */
  565.       strcpy(curFileStruct.tfn, curFileStruct.trackName);
  566.       nameRepair(curFileStruct.tfn, tfnSize);
  567.       /*
  568.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "\\", "_");
  569.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "/", "_");
  570.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, ":", "_");
  571.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "*", "_");
  572.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "?", "_");
  573.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "<", "_");
  574.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, ">", "_");
  575.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "|", "_");
  576.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, " ", "_");
  577.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "&#039;", "'");
  578.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "&amp;", "&");
  579.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "&quot;", "'");
  580.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "&gt;", ")");
  581.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "&lt;", "(");
  582.             str_replace(curFileStruct.tfn, tfnSize, curFileStruct.tfn, "\"", "'");
  583.       */
  584.       sprintf(curFileStruct.fileName, "%s-%s.%s", curFileStruct.afn, curFileStruct.tfn, formats[curFormat]);
  585.  
  586.       if (strlen(curFileStruct.fileName) > 63)
  587.       {
  588.         sprintf(fileIdChar, "-%ld", fileId);
  589.         str_replace(curFileStruct.fileName, sizeof(curFileStruct.fileName) - 1, curFileStruct.fileName, fileIdChar, "");
  590.         curFileStruct.fileName[50] = '\0';
  591.         strcat(curFileStruct.fileName, fileIdChar);
  592.         strcat(curFileStruct.fileName, formats[curFormat]);
  593.         // printf("filename = [%s]",curFileStruct.fileName);
  594.       }
  595.     }
  596.     OS_SETSYSDRV();
  597.     OS_MKDIR("../downloads/radio"); // Create if not exist
  598.     OS_CHDIR("../downloads/radio");
  599.     fp2 = OS_CREATEHANDLE(curFileStruct.fileName, 0x80);
  600.     if (((int)fp2) & 0xff)
  601.     {
  602.       clearStatus();
  603.       printf(curFileStruct.fileName);
  604.       printf(" creating error. Check for  downloads\\radio folder.");
  605.       getchar();
  606.       exit(0);
  607.     }
  608.     OS_CLOSEHANDLE(fp2);
  609.     return 0;
  610.   }
  611.  
  612.   if (operation == 01)
  613.   {
  614.     fp2 = OS_OPENHANDLE(curFileStruct.fileName, 0x80);
  615.     if (((int)fp2) & 0xff)
  616.     {
  617.  
  618.       clearStatus();
  619.       printf(curFileStruct.fileName);
  620.       printf(" opening error.");
  621.       exit(0);
  622.     }
  623.     fileSize = OS_GETFILESIZE(fp2);
  624.     OS_SEEKHANDLE(fp2, fileSize);
  625.     OS_WRITEHANDLE(netbuf, fp2, sizeOfBuf);
  626.     OS_CLOSEHANDLE(fp2);
  627.     return 0;
  628.   }
  629.  
  630.   if (operation == 02)
  631.   {
  632.     OS_CLOSEHANDLE(fp2);
  633.     return 0;
  634.   }
  635.  
  636.   return 0;
  637. }
  638.  
  639. void getData(unsigned char socket)
  640. {
  641.   unsigned int todo, w, bPos, bytes2read, headskip;
  642.  
  643.   headskip = 0;
  644.   bPos = 0;
  645.   bytecount = 255;
  646.   while (1)
  647.   {
  648.     todo = tcpRead(socket);
  649.     if (todo == 0)
  650.     {
  651.       break;
  652.     }
  653.     bytes2read = todo;
  654.     if (headskip == 0)
  655.     {
  656.       headskip = 1;
  657.       bytes2read = cutHeader(todo);
  658.     }
  659.  
  660.     if (bPos + bytes2read > sizeof(dataBuffer))
  661.     {
  662.       clearStatus();
  663.       printf("dataBuffer overrun...");
  664.       break;
  665.     }
  666.  
  667.     for (w = 0; w < bytes2read; w++)
  668.     {
  669.       dataBuffer[w + bPos] = netbuf[w];
  670.     }
  671.     bytecount = bytecount - bytes2read;
  672.     bPos = bPos + bytes2read;
  673.     if (bytecount == 0)
  674.     {
  675.       dataBuffer[bytes2read + bPos + 1] = '\0';
  676.       break;
  677.     }
  678.   }
  679.   netShutDown(socket);
  680. }
  681.  
  682. unsigned int tcpSend(unsigned char socket, unsigned int messageadr, unsigned int size)
  683. {
  684.   unsigned char retry = 20;
  685.   unsigned int todo;
  686.   readStruct.socket = socket;
  687.   readStruct.BufAdr = messageadr;
  688.   readStruct.bufsize = size;
  689.   readStruct.protocol = SOCK_STREAM;
  690.  
  691. wizwrite:
  692.   todo = OS_WIZNETWRITE(&readStruct);
  693.   if (todo > 32767)
  694.   {
  695.     clearStatus();
  696.     printf("OS_WIZNETWRITE: ");
  697.     errorPrint(todo & 255);
  698.     if (retry == 0)
  699.     {
  700.       exit(0);
  701.     }
  702.     retry--;
  703.     delay(150);
  704.     goto wizwrite;
  705.   }
  706.   else
  707.   {
  708.     if (logFlag)
  709.     {
  710.       clearStatus();
  711.       printf("OS_WIZNETWRITE: %u bytes written.", todo);
  712.     }
  713.   }
  714.   return todo;
  715. }
  716.  
  717. unsigned long processJson(unsigned long startPos, unsigned char limit, unsigned char queryNum)
  718. {
  719.   FILE *fp3;
  720.   unsigned int retry, tSize;
  721.   unsigned int todo;
  722.   unsigned char buffer[] = "000000000";
  723.   unsigned char *count, socket;
  724.   unsigned char userAgent[] = " HTTP/1.1\r\nHost: zxart.ee\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS; Radio)\r\n\r\n\0";
  725.   unsigned char userQuery[256] = "/api/export:zxMusic/limit:10/filter:zxMusicId=44816";
  726.   clearStatus();
  727.   printf("Getting data(%u)...", queryNum);
  728.  
  729.   switch (queryNum)
  730.   {
  731.   case 0: // GET /api/export:zxMusic/limit:1/start:1/filter:zxMusicFormat=pt3/order:date,desc HTTP/1.1\r\nHost: zxart.ee\r\nUser-Agent: User-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS)
  732.     strcpy(netbuf, "GET /api/export:zxMusic/limit:");
  733.     sprintf(buffer, "%u", limit);
  734.     strcat(netbuf, buffer);
  735.     strcat(netbuf, "/start:");
  736.     sprintf(buffer, "%lu", startPos);
  737.     strcat(netbuf, buffer);
  738.     strcat(netbuf, "/filter:zxMusicFormat=");
  739.     strcat(netbuf, formats[curFormat]);
  740.     strcat(netbuf, "/order:date,desc");
  741.     strcat(netbuf, userAgent);
  742.     break;
  743.   case 1: // GET /api/types:zxMusic/export:zxMusic/language:eng/limit:1/start:0/order:votes,rand/filter:zxMusicMinRating=4;
  744.     startPos = 0;
  745.     strcpy(netbuf, "GET /api/types:zxMusic/export:zxMusic/language:eng/limit:");
  746.     sprintf(buffer, "%u", limit);
  747.     strcat(netbuf, buffer);
  748.     strcat(netbuf, "/start:");
  749.     sprintf(buffer, "%lu", startPos);
  750.     strcat(netbuf, buffer);
  751.     strcat(netbuf, "/order:votes,rand/filter:zxMusicMinRating=4;zxMusicFormat=");
  752.     strcat(netbuf, formats[curFormat]);
  753.     strcat(netbuf, userAgent);
  754.     break;
  755.   case 2: // GET /api/types:zxMusic/export:zxMusic/language:eng/limit:1/start:0/order:rand/filter:zxMusicFormat=PT3 HTTP/1.1\r\nHost: zxart.ee\r\nUser-Agent: User-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS)
  756.     startPos = 0;
  757.     strcpy(netbuf, "GET /api/types:zxMusic/export:zxMusic/language:eng/limit:");
  758.     sprintf(buffer, "%u", limit);
  759.     strcat(netbuf, buffer);
  760.     strcat(netbuf, "/start:");
  761.     sprintf(buffer, "%lu", startPos);
  762.     strcat(netbuf, buffer);
  763.     strcat(netbuf, "/order:rand/filter:zxMusicFormat=");
  764.     strcat(netbuf, formats[curFormat]);
  765.     strcat(netbuf, userAgent);
  766.     break;
  767.  
  768.   case 3: // GET /api/export:zxMusic/limit:1/start:1/filter:zxMusicFormat=pt3;authorId=7744/order:date,desc HTTP/1.1\r\nHost: zxart.ee\r\nUser-Agent: User-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS)
  769.  
  770.     fp3 = OS_OPENHANDLE("radio/user.que", 0x80);
  771.     if (((int)fp3) & 0xff)
  772.     {
  773.       fp3 = OS_CREATEHANDLE("radio/user.que", 0x80);
  774.       OS_WRITEHANDLE(userQuery, fp3, sizeof(userQuery));
  775.       OS_CLOSEHANDLE(fp3);
  776.       fp3 = OS_OPENHANDLE("radio/user.que", 0x80);
  777.     }
  778.     OS_READHANDLE(userQuery, fp3, sizeof(userQuery));
  779.     OS_CLOSEHANDLE(fp3);
  780.  
  781.     strcpy(netbuf, "GET /api/limit:");
  782.     sprintf(buffer, "%u", limit);
  783.     strcat(netbuf, buffer);
  784.     strcat(netbuf, "/start:");
  785.     sprintf(buffer, "%lu", startPos);
  786.     strcat(netbuf, buffer);
  787.     strcat(netbuf, userQuery);
  788.     strcat(netbuf, userAgent);
  789.     break;
  790.  
  791.   case 99: // GET /jsonElementData/elementId:182798
  792.     strcpy(netbuf, "GET /jsonElementData/elementId:");
  793.     sprintf(buffer, "%lu", startPos);
  794.     strcat(netbuf, buffer);
  795.     strcat(netbuf, userAgent);
  796.     break;
  797.   }
  798.  
  799.   retry = 10;
  800. rejson:
  801.   socket = OpenSock(AF_INET, SOCK_STREAM);
  802.   netConnect(socket);
  803.  
  804.   todo = tcpSend(socket, (unsigned int)&netbuf, strlen(netbuf));
  805.  
  806.   getData(socket);
  807.  
  808.   clearStatus();
  809.   printf("Processing data (%u)...", queryNum);
  810.  
  811.   count = strstr(dataBuffer, "responseStatus\":\"success");
  812.   if (count == NULL)
  813.   {
  814.     clearStatus();
  815.     printf("BAD JSON, NO responseStatus: success. (%u)", retry);
  816.     retry--;
  817.     YIELD();
  818.     if (retry > 0)
  819.     {
  820.       netShutDown(socket);
  821.       goto rejson;
  822.     }
  823.     // AT(1, 1);
  824.     // printf("BAD JSON, NO responseStatus: success. JSON: %s \r\n", dataBuffer);
  825.     // getchar();
  826.     return -1;
  827.   }
  828.  
  829.   count = strstr(dataBuffer, "\"id\":");
  830.   if (count == NULL)
  831.   {
  832.     clearStatus();
  833.     printf("BAD JSON: not ID query = %u startPos = %lu", queryNum, startPos);
  834.     // AT(1, 10);
  835.     // printf("BAD JSON: ID not found JSON:\r\n %s \r\n", dataBuffer);
  836.     return -2;
  837.   }
  838.   if (queryNum < 4)
  839.   {
  840.     netbuf[0] = '\0';
  841.     parseJson("\"id\":");
  842.     curFileStruct.picId = atol(netbuf);
  843.     parseJson(",\"title\":\"");
  844.     convert866();
  845.     strcpy(curFileStruct.trackName, netbuf);
  846.  
  847.     tSize = sizeof(curFileStruct.trackName);
  848.     stringRepair(curFileStruct.trackName, tSize);
  849.  
  850.     /*
  851.         str_replace(curFileStruct.trackName, tnSize, curFileStruct.trackName, "&#039;", "'");
  852.         str_replace(curFileStruct.trackName, tnSize, curFileStruct.trackName, "&amp;", "&");
  853.         str_replace(curFileStruct.trackName, tnSize, curFileStruct.trackName, "&gt;", ">");
  854.         str_replace(curFileStruct.trackName, tnSize, curFileStruct.trackName, "&lt;", "<");
  855.         str_replace(curFileStruct.trackName, tnSize, curFileStruct.trackName, "&quot;", "\"");
  856.         str_replace(curFileStruct.trackName, tnSize, curFileStruct.trackName, "\\/", "/");
  857.     */
  858.     parseJson("\"rating\":\"");
  859.     strcpy(curFileStruct.picRating, netbuf);
  860.     parseJson("\"year\":\"");
  861.     curFileStruct.picYear = atoi(netbuf);
  862.     parseJson("\"totalAmount\":");
  863.     curFileStruct.totalAmount = atol(netbuf);
  864.     parseJson("\"time\":\"");
  865.     strcpy(curFileStruct.time, netbuf);
  866.     parseJson("\"authorIds\":[");
  867.     strcpy(curFileStruct.authorIds, netbuf);
  868.     parseJson("\"authorIds\":[");
  869.     strcpy(curFileStruct.fileName2, netbuf);
  870.   }
  871.   if (queryNum == 99)
  872.   {
  873.     parseJson(",\"title\":\"");
  874.     convert866();
  875.     strcpy(curFileStruct.authorTitle, netbuf);
  876.     parseJson(",\"realName\":\"");
  877.     convert866();
  878.     strcpy(curFileStruct.authorRealName, netbuf);
  879.   }
  880.   return curFileStruct.picId;
  881. }
  882.  
  883. unsigned char getTrack(unsigned long fileId)
  884. {
  885.   unsigned int todo;
  886.   unsigned char cmdlist1[] = "GET /file/id:";
  887.   unsigned char cmdlist2[] = " HTTP/1.1\r\nHost: zxart.ee\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE5.01; NedoOS; Radio)\r\n\r\n\0";
  888.   unsigned char buffer[] = "0000000000";
  889.   unsigned char socket;
  890.   unsigned int bytes2read, headskip;
  891.   clearStatus();
  892.   printf("Getting track...");
  893.  
  894.   socket = OpenSock(AF_INET, SOCK_STREAM);
  895.   todo = netConnect(socket);
  896.   netbuf[0] = '\0';
  897.   sprintf(buffer, "%lu", fileId);
  898.   strcat(netbuf, cmdlist1);
  899.   strcat(netbuf, buffer);
  900.   strcat(netbuf, cmdlist2);
  901.   todo = tcpSend(socket, (unsigned int)&netbuf, strlen(netbuf));
  902.  
  903.   headskip = 0;
  904.   bytecount = 255;
  905.   saveBuf(curFileStruct.picId, 00, 0);
  906.   while (bytecount != 0)
  907.   {
  908.     todo = tcpRead(socket);
  909.     if (todo == 0)
  910.     {
  911.       break;
  912.     }
  913.     bytes2read = todo;
  914.     if (headskip == 0)
  915.     {
  916.       headskip = 1;
  917.       bytes2read = cutHeader(todo);
  918.     }
  919.     saveBuf(curFileStruct.picId, 01, bytes2read);
  920.     bytecount = bytecount - bytes2read;
  921.   }
  922.   netShutDown(socket);
  923.   return 0;
  924. }
  925.  
  926. unsigned char runPlayer(void)
  927. {
  928.   FILE *fp2;
  929.   unsigned char fileName[] = "radio/player.ovl";
  930.   unsigned char appCmd[128] = "player.com ";
  931.   unsigned char curPath[128];
  932.   unsigned long playerSize, loaded, loop;
  933.   unsigned char pgbak;
  934.  
  935.   clearStatus();
  936.   printf("Running player...");
  937.  
  938.   strcat(appCmd, curFileStruct.fileName);
  939.   player_pg.l = OS_GETMAINPAGES();
  940.   pgbak = main_pg.pgs.window_3;
  941.   loaded = 0;
  942.   OS_GETPATH((unsigned int)&curPath);
  943.   OS_SETSYSDRV();
  944.   fp2 = OS_OPENHANDLE(fileName, 0x80);
  945.   if (((int)fp2) & 0xff)
  946.   {
  947.     clearStatus();
  948.     printf(fileName);
  949.     printf(" not found.");
  950.     exit(0);
  951.   }
  952.   playerSize = OS_GETFILESIZE(fp2);
  953.   OS_CHDIR(curPath);
  954.   OS_NEWAPP((unsigned int)&player_pg);
  955.   SETPG32KHIGH(player_pg.pgs.window_3);
  956.   memcpy((char *)(0xC080), &appCmd, sizeof(appCmd));
  957.   for (loop = 0; loop < playerSize; loop = loop + loaded)
  958.   {
  959.     loaded = OS_READHANDLE(dataBuffer, fp2, sizeof(dataBuffer));
  960.     memcpy((char *)(0xC100 + loop), &dataBuffer, loaded);
  961.   }
  962.   OS_CLOSEHANDLE(fp2);
  963.   SETPG32KHIGH(pgbak);
  964.   OS_RUNAPP(player_pg.pgs.pId);
  965.   return player_pg.pgs.pId;
  966. }
  967.  
  968. long trackSelector(unsigned char mode)
  969. {
  970.   switch (mode)
  971.   {
  972.   case 0: // Next track
  973.     count++;
  974.     if (count > curFileStruct.totalAmount - 1)
  975.     {
  976.       count = 0;
  977.     }
  978.     break;
  979.   case 1: // Prev. track
  980.     count--;
  981.     if (count < 0)
  982.     {
  983.       count = curFileStruct.totalAmount - 1;
  984.     }
  985.     break;
  986.   }
  987.   return count;
  988. }
  989.  
  990. void printStatus(void)
  991. {
  992.   AT(1, 9);
  993.   ATRIB(93);
  994.   printf(" [Q]Query : ");
  995.   ATRIB(97);
  996.   printf("%s", queryType);
  997.   printf("  ");
  998.   AT(1, 24);
  999.   ATRIB(45);
  1000.   printf("                                                                                ");
  1001.   AT(2, 24);
  1002.   ATRIB(93);
  1003.   printf(" [F]Format: ");
  1004.   ATRIB(97);
  1005.   printf("%s", formats[curFormat]);
  1006.   ATRIB(93);
  1007.   printf(" [K]Keep files: ");
  1008.   ATRIB(97);
  1009.   printf("%u", saveFlag);
  1010.   ATRIB(93);
  1011.   printf(" [R]Repeat: ");
  1012.   ATRIB(97);
  1013.   printf("%u", rptFlag);
  1014.   ATRIB(93);
  1015.   printf(" [J]Jump to ");
  1016.   printf(" [E]Exit        [%s]\r\n", ver);
  1017.  
  1018.   ATRIB(97);
  1019.   ATRIB(40);
  1020. }
  1021.  
  1022. void printInfo(void)
  1023. {
  1024.   BOX(30, 2, 50, 6, 40);
  1025.   AT(1, 2);
  1026.   ATRIB(97);
  1027.   ATRIB(93);
  1028.   printf(" #: ");
  1029.   ATRIB(97);
  1030.   printf("%lu", count);
  1031.   ATRIB(93);
  1032.   printf(" ID: ");
  1033.   ATRIB(97);
  1034.   printf("%lu", curFileStruct.picId);
  1035.   ATRIB(93);
  1036.   printf(" Total Tracks: ");
  1037.   ATRIB(97);
  1038.   printf("%lu", curFileStruct.totalAmount);
  1039.   printf(" \r\n");
  1040.   ATRIB(93);
  1041.   printf(" RATING: ");
  1042.   ATRIB(97);
  1043.   printf("%s", curFileStruct.picRating);
  1044.   ATRIB(93);
  1045.   printf(" YEAR: ");
  1046.   ATRIB(97);
  1047.   printf("%u", curFileStruct.picYear);
  1048.   ATRIB(93);
  1049.   printf(" DURATION: ");
  1050.   ATRIB(97);
  1051.   printf("%s", curFileStruct.time);
  1052.   printf(" \r\n\r\n");
  1053.   ATRIB(93);
  1054.   printf(" AuthorsIDs ");
  1055.   ATRIB(97);
  1056.   printf("%s", curFileStruct.authorIds);
  1057.   ATRIB(93);
  1058.   printf(" Author: ");
  1059.   ATRIB(97);
  1060.   printf("%s", curFileStruct.authorTitle);
  1061.   ATRIB(93);
  1062.   printf(" Real name: ");
  1063.   ATRIB(97);
  1064.   printf("%s", curFileStruct.authorRealName);
  1065.   printf(" \r\n\r\n");
  1066.   ATRIB(96);
  1067.   printf("                                                                           \r");
  1068.   printf("   TITLE: %s\r\n", curFileStruct.trackName);
  1069. }
  1070.  
  1071. void printHelp(void)
  1072. {
  1073.   AT(1, 13);
  1074.   ATRIB(97);
  1075.   printf(" [E] or [ESC] Exit to OS           \r\n");
  1076.   printf(" [B] or [<--] Previous track       \r\n");
  1077.   printf(" [ ] or [-->] Next track    \r\n");
  1078.   printf(" [S]          Stop player          \r\n");
  1079.   printf(" [K]          Toggle saving tracks \r\n");
  1080.   printf(" [Q]          Select Query type    \r\n");
  1081.   printf(" [D]          Download track       \r\n");
  1082.   printf(" [R]          Repeat track mode    \r\n");
  1083.   printf(" [J]          Jump to NNNN file from newest  \r\n");
  1084.   printf(" [F]          Change tracks format to play   \r\n");
  1085.   printf(" [L]          Toggle operation logging       \r\n");
  1086. }
  1087.  
  1088. unsigned char testPlayer(void)
  1089. {
  1090.   union APP_PAGES player2_pg;
  1091.   player2_pg.l = OS_GETAPPMAINPAGES(player_pg.pgs.pId);
  1092.  
  1093.   if (errno == 0)
  1094.   {
  1095.     return 1;
  1096.   }
  1097.   else
  1098.   {
  1099.     return 0;
  1100.   }
  1101. }
  1102.  
  1103. C_task main(void)
  1104. {
  1105.   unsigned char errn, keypress, queryNum, pId, alive, changedFormat;
  1106.   long iddqd, idkfa, ipadress;
  1107.   unsigned long curTimer, startTimer, oldTimer;
  1108.   os_initstdio();
  1109.   srand(time());
  1110.   count = 0;
  1111.   saveFlag = 0;
  1112.   logFlag = 0;
  1113.   queryNum = 0;
  1114.   curFormat = 0;
  1115.   changedFormat = 0;
  1116.   rptFlag = 0;
  1117.   strcpy(queryType, "from newest to oldest");
  1118.  
  1119.   BOX(1, 1, 80, 25, 40);
  1120.   AT(1, 1);
  1121.   ATRIB(97);
  1122.   ATRIB(45);
  1123.   printf("                           ZXART.EE radio for nedoNET                           \n\r");
  1124.   AT(1, 24);
  1125.   printf("  [L]Enable logging(press on startup)                                          ");
  1126.  
  1127.   ATRIB(33);
  1128.   ATRIB(40);
  1129.  
  1130.   /*
  1131.     ipadress = OS_DNSRESOLVE("zxart.ee");
  1132.     printf("\n\r  OS_DNSRESOLVE =  %lu \n\r", ipadress);
  1133.     printf("------------------------\n\r");
  1134.     printf("OS_GETPATH = %s\r\n", curPath);
  1135.   */
  1136.  
  1137.   keypress = _low_level_get();
  1138.   if (keypress == 'l' || keypress == 'L')
  1139.   {
  1140.     logFlag = 1;
  1141.     clearStatus();
  1142.     printf("Logging enabled");
  1143.     getchar();
  1144.   }
  1145.  
  1146. start:
  1147.   OS_SETSYSDRV();
  1148.   printHelp();
  1149.   curFileStruct.fileSize = 0;
  1150.  
  1151.   iddqd = processJson(count, 1, queryNum); // Query for track info
  1152.   if (iddqd < 0)
  1153.   {
  1154.     {
  1155.       clearStatus();
  1156.       printf("Error getting track info, next please(%ld)...", iddqd);
  1157.       count = trackSelector(0);
  1158.       goto start;
  1159.     }
  1160.   }
  1161.  
  1162.   idkfa = processJson(atol(curFileStruct.authorIds), 0, 99); // Query for AuthorID
  1163.  
  1164.   if (idkfa < 0)
  1165.   {
  1166.     clearStatus();
  1167.     printf("Error getting author %lu", atol(curFileStruct.authorIds));
  1168.     strcpy(curFileStruct.authorTitle, " Error getting Tittle ");
  1169.     // strcpy(curFileStruct.authorRealName, " \0");
  1170.   }
  1171. replay:
  1172.   errn = getTrack(iddqd); // Downloading the track
  1173. resume:
  1174.   startTimer = time();
  1175.   printProgress(0);
  1176.   pId = runPlayer(); // Start thr Player!
  1177.   printStatus();
  1178.   printInfo();
  1179. rekey:
  1180.   YIELD();
  1181.   keypress = _low_level_get();
  1182.   if (keypress != 0)
  1183.   {
  1184.     if (keypress == 27 || keypress == 'e' || keypress == 'E')
  1185.     {
  1186.       OS_DROPAPP(pId);
  1187.       printf("Good bye... %u \r\n", pId);
  1188.       ATRIB(37);
  1189.       ATRIB(40);
  1190.       exit(0);
  1191.     }
  1192.     if (keypress == 248 || keypress == 'b' || keypress == 'B')
  1193.     {
  1194.       changedFormat = 0;
  1195.       OS_DROPAPP(pId);
  1196.       clearStatus();
  1197.       printf("Player stopped...");
  1198.       count = trackSelector(1);
  1199.       goto start;
  1200.     }
  1201.  
  1202.     if (keypress == 251 || keypress == 32 || keypress == 'n' || keypress == 'N')
  1203.     {
  1204.       changedFormat = 0;
  1205.       OS_DROPAPP(pId);
  1206.       clearStatus();
  1207.       printf("Player stopped...");
  1208.       count = trackSelector(0);
  1209.       goto start;
  1210.     }
  1211.  
  1212.     if (keypress == 'k' || keypress == 'K')
  1213.     {
  1214.       OS_DROPAPP(pId);
  1215.       clearStatus();
  1216.       printf("Player stopped...");
  1217.       saveFlag = !saveFlag;
  1218.       printStatus();
  1219.       goto replay;
  1220.     }
  1221.  
  1222.     if (keypress == 'q' || keypress == 'Q')
  1223.     {
  1224.       OS_DROPAPP(pId);
  1225.       clearStatus();
  1226.       printf("Player stopped...");
  1227.       queryNum++;
  1228.       if (queryNum > 3)
  1229.       {
  1230.         queryNum = 0;
  1231.       }
  1232.       switch (queryNum)
  1233.       {
  1234.       case 0:
  1235.         strcpy(queryType, "from newest to oldest                   ");
  1236.         break;
  1237.       case 1:
  1238.         strcpy(queryType, "Random best and most voted tracks       ");
  1239.         break;
  1240.       case 2:
  1241.         strcpy(queryType, "Random play                             ");
  1242.         break;
  1243.       case 3:
  1244.         strcpy(queryType, "User defined query from \"user.que\"     ");
  1245.         break;
  1246.       }
  1247.       count = 0;
  1248.       printStatus();
  1249.       goto start;
  1250.     }
  1251.  
  1252.     if (keypress == 'j' || keypress == 'J')
  1253.     {
  1254.       AT(1, 7);
  1255.       printf("                                                                      \r");
  1256.       printf("Jump to track:");
  1257.       scanf("%lu", &count);
  1258.       OS_DROPAPP(pId);
  1259.       if (count > curFileStruct.totalAmount - 1)
  1260.       {
  1261.         count = curFileStruct.totalAmount - 1;
  1262.       }
  1263.       goto start;
  1264.     }
  1265.  
  1266.     if (keypress == 'f' || keypress == 'F')
  1267.     {
  1268.       OS_DROPAPP(pId);
  1269.       clearStatus();
  1270.       printf("Player stopped...");
  1271.       curFormat++;
  1272.       count = -1;
  1273.       if (curFormat > 3)
  1274.       {
  1275.         curFormat = 0;
  1276.       }
  1277.       changedFormat = 1;
  1278.       curFileStruct.totalAmount = 1;
  1279.       printStatus();
  1280.       printProgress(0);
  1281.       BOX(1, 2, 80, 6, 40);
  1282.       goto rekey;
  1283.     }
  1284.  
  1285.     if (keypress == 'l' || keypress == 'L')
  1286.     {
  1287.       logFlag = !logFlag;
  1288.       clearStatus();
  1289.       printf("Logging: %u", logFlag);
  1290.     }
  1291.  
  1292.     if (keypress == 's' || keypress == 'S')
  1293.     {
  1294.       OS_DROPAPP(pId);
  1295.       clearStatus();
  1296.       printf("Player stopped...");
  1297.       printProgress(0);
  1298.       getchar();
  1299.       goto resume;
  1300.     }
  1301.     if (keypress == 'r' || keypress == 'R')
  1302.     {
  1303.       rptFlag = !rptFlag;
  1304.       clearStatus();
  1305.       printStatus();
  1306.       goto rekey;
  1307.     }
  1308.     if (keypress == 'd' || keypress == 'D')
  1309.     {
  1310.       saveBak = saveFlag;
  1311.       saveFlag = 1;
  1312.       errn = getTrack(iddqd); // Downloading the track
  1313.       saveFlag = saveBak;
  1314.       clearStatus();
  1315.       printf("File saved: [%s]...", curFileStruct.fileName);
  1316.       goto rekey;
  1317.     }
  1318.   }
  1319.  
  1320.   curTimer = time();
  1321.   curFileStruct.curPos = (curTimer - startTimer) / 50;
  1322.   alive = testPlayer();
  1323.  
  1324.   if (alive == 0 && !changedFormat)
  1325.   {
  1326.     if (rptFlag == 1)
  1327.     {
  1328.       goto resume;
  1329.     }
  1330.     printProgress(2);
  1331.     count = trackSelector(0);
  1332.     goto start;
  1333.   }
  1334.  
  1335.   if (alive == 1 && ((curTimer - oldTimer) > 49))
  1336.   {
  1337.     printProgress(1);
  1338.     oldTimer = curTimer;
  1339.   }
  1340.  
  1341.   YIELD();
  1342.   YIELD();
  1343.   goto rekey;
  1344. }
  1345.