ソースを参照

Update edit for brfs, removed wget, uploadToBDOS now infers filename.

bart 7 ヶ月 前
コミット
b81ee12022
3 ファイル変更94 行追加650 行削除
  1. 4 1
      BCC/uploadToBDOS.sh
  2. 90 208
      BCC/userBDOS/edit.c
  3. 0 441
      BCC/userBDOS/toFix/wget.c

+ 4 - 1
BCC/uploadToBDOS.sh

@@ -8,7 +8,10 @@ then
     exit 1
 fi
 
-OUTFILE="file.out"
+# Default output filename is filename of first argument
+OUTFILE=$(basename $1)
+# Remove file extension
+OUTFILE=${OUTFILE%.*}
 
 if [ "$2" != "" ]
 then

+ 90 - 208
BCC/userBDOS/toFix/edit.c → BCC/userBDOS/edit.c

@@ -1,5 +1,8 @@
 // Simple text editor
 
+// NOTE: this uses more memory than is allowed in FPGC7, so update this when new BDOS memory map.
+// Also, code should be refactored.
+
 /* global structure of program:
 - check first argument, exit if none
 - read file from first argument into mem
@@ -40,9 +43,8 @@
 #include "lib/sys.c"
 #include "lib/gfx.c"
 #include "lib/stdlib.c"
-#include "lib/fs.c"
+#include "lib/brfs.c"
 
-#define FBUF_ADDR           0x440000 // location of input file buffer
 #define FILE_MEMORY_ADDR    0x480000 // location of file content
 #define MAX_LINE_WIDTH      240     // max width of line in mem buffer, multiple of 40 (screen width)
 #define MAX_LINES           8192    // maximum number of lines to prevent out of memory writes (8192*256*4 = 8MiB)
@@ -68,21 +70,14 @@
 #define BTN_END       263
 #define BTN_PAGEDOWN  264
 
-
-char infilename[96];  // input filename to edit the contents of
-
 char headerText[SCREEN_WIDTH]; // text on header (first line)
 
 // Buffer for file contents in memory
 char (*mem)[MAX_LINE_WIDTH] = (char (*)[MAX_LINE_WIDTH]) FILE_MEMORY_ADDR; // 2d array containing all lines of the input file
 
 // Buffer for file reading
-// Length of buffer always should be less than 65536, since this is the maximum FS_readFile can do in a single call
 #define FBUF_LEN 4096
 #define EOF -1
-char *inputBuffer = (char*) FBUF_ADDR; //[FBUF_LEN];
-word inbufStartPos = 0; // where in the file the buffer starts
-word inbufCursor = 0; // where in the buffer we currently are working
 word lastLineNumber = 0;
 
 // Cursors
@@ -91,126 +86,17 @@ word windowXscroll = 0; // horizontal position offset for drawing window
 word userCursorX = 0; // char position within line, of user cursor
 word userCursorY = 0; // line of user cursor
 
-// Opens file for reading
-// requires full paths
-// returns 1 on success
-word fopenRead()
-{
-  if (infilename[0] != '/')
-  {
-    BDOS_PrintConsole("E: Filename should be a full path\n");
-    return 0;
-  }
-
-  FS_close(); // to be sure
-
-  // convert to uppercase
-  strToUpper(infilename);
-
-  // init read buffer
-  inbufStartPos = 0; // start at 0
-  inbufCursor = 0; // start at 0
-
-  // if the resulting path is correct (can be file or directory)
-  if (FS_sendFullPath(infilename) == FS_ANSW_USB_INT_SUCCESS)
-  {
-
-    // if we can successfully open the file (not directory)
-    if (FS_open() == FS_ANSW_USB_INT_SUCCESS)
-    {
-      FS_setCursor(0); // set cursor to start
-      return 1;
-    }
-    else
-    {
-      return 0;
-    }
-  }
-  else
-  {
-    return 0;
-  }
-
-  return 0;
-}
-
-// opens file for writing by recreating it
-// should not be called before fopenRead, therefore exits on error
-word fopenWrite()
+// Write mem to file
+void writeMemToFile(char* absolute_path)
 {
-  if (infilename[0] != '/')
-  {
-    BDOS_PrintConsole("E: Filename should be a full path\n");
-    exit();
-  }
-
-  FS_close(); // to be sure
-
-  // convert to uppercase
-  strToUpper(infilename);
-
-  // if current path is correct (can be file or directory)
-  if (FS_sendFullPath(infilename) == FS_ANSW_USB_INT_SUCCESS)
-  {
-    // create the file
-    
-    if (FS_createFile() == FS_ANSW_USB_INT_SUCCESS)
-    {
-      //BDOS_PrintConsole("File created\n");
-      // open again and start at 0
-      FS_sendFullPath(infilename);
-      FS_open();
-      FS_setCursor(0); // set cursor to start
-      return 1;
-    }
-    else
-    {
-      BDOS_PrintConsole("E: Could not create file\n");
-      exit();
-    }
-  }
-  else
+  // Open file
+  word fd = fs_open(absolute_path);
+  if (fd == -1)
   {
-    BDOS_PrintConsole("E: Invalid path\n");
+    bdos_println("File not found");
     exit();
   }
 
-  exit();
-  return 0;
-}
-
-// Writes data of given length to opened file
-void fputData(char* datBuf, word lenOfData)
-{
-  if (lenOfData == 0)
-  {
-    return;
-  }
-
-  word bytesWritten = 0;
-
-  // loop until all bytes are sent
-  while (bytesWritten != lenOfData)
-  {
-    word partToSend = lenOfData - bytesWritten;
-    // send in parts of 0xFFFF
-    if (partToSend > 0xFFFF)
-      partToSend = 0xFFFF;
-
-    // write away
-    if (FS_writeFile((datBuf +bytesWritten), partToSend) != FS_ANSW_USB_INT_SUCCESS)
-      BDOS_PrintConsole("write error\n");
-
-    // Update the amount of bytes sent
-    bytesWritten += partToSend;
-  }
-}
-
-// Write mem to file
-void writeMemToFile()
-{
-  fopenWrite(); // open file for writing
-
   word y;
   for (y = 0; y <= lastLineNumber; y++)
   {
@@ -221,68 +107,46 @@ void writeMemToFile()
       if (lineEndPos == MAX_LINE_WIDTH)
       {
         exitRoutine();
-        BDOS_PrintConsole("E: could not find end of line\n");
-        FS_close();
+        bdos_print("E: could not find end of line\n");
+        fs_close(fd);
         exit();
       }
     }
 
     if (mem[y][lineEndPos] == EOF)
     {
-      fputData(mem[y], lineEndPos);
-      FS_close();
+      fs_write(fd, mem[y], lineEndPos);
+      fs_close(fd);
       return;
     }
 
     lineEndPos++; // include the newline token
-    fputData(mem[y], lineEndPos);
+    fs_write(fd, mem[y], lineEndPos);
   }
-  FS_close();
+  fs_close(fd);
 }
 
 
 // returns the current char at cursor within the opened file (EOF if end of file)
 // increments the cursor
-word fgetc()
+word fgetc(word fd, word filesize)
 {
-  // workaround for missing compiler check for ALU constants > 11 bit
-  word stdioBufLen = FBUF_LEN;
-
-  if (inbufCursor >= FBUF_LEN || inbufCursor == 0)  // we are at the end of the buffer (or it is not initialized yet)
+  word cursor = fs_getcursor(fd);
+  if (cursor == filesize)
   {
-    // get filesize
-    word sizeOfFile = FS_getFileSize();
-    
-    // if we cannot completely fill the buffer:
-    if (inbufStartPos + stdioBufLen > sizeOfFile)
-    {
-      //  fill the buffer, and append with EOF token
-      FS_readFile(inputBuffer, sizeOfFile - inbufStartPos, 0);
-      inputBuffer[sizeOfFile - inbufStartPos] = EOF;
-    }
-    else
-    {
-      //  fill buffer again
-      FS_readFile(inputBuffer, FBUF_LEN, 0);
-    }
-    
-    inbufStartPos += stdioBufLen; // for the next fill
-
-    inbufCursor = 0; // start at the beginning of the buffer again
+    return EOF;
   }
 
-  // return from the buffer, and increment
-  char gotchar = inputBuffer[inbufCursor];
-  inbufCursor++;
-  // BDOS_PrintcConsole(gotchar); // useful for debugging
-  return gotchar;
+  char c;
+  fs_read(fd, &c, 1);
+  return c;
 }
 
 
 // reads a line from the input file
-word readFileLine()
+word readFileLine(word fd, word filesize)
 {
-  char c = fgetc();
+  char c = fgetc(fd, filesize);
   char cprev = c;
 
   word currentChar = 0;
@@ -293,13 +157,14 @@ word readFileLine()
     mem[lastLineNumber][currentChar] = c;
     currentChar++;
     cprev = c;
-    c = fgetc();
+    c = fgetc(fd, filesize);
   }
 
   // error when line was too long
   if (c != EOF && c != '\n' && currentChar >= (MAX_LINE_WIDTH-1))
   {
-    BDOS_PrintConsole("E: line is too long\n");
+    bdos_print("E: line is too long\n");
+    fs_close(fd);
     exit();
   }
 
@@ -321,13 +186,22 @@ word readFileLine()
 }
 
 
-void readInputFile()
+void readInputFile(char* absolute_path, word filesize)
 {
-  while (readFileLine() != EOF)
+  // Open file
+  word fd = fs_open(absolute_path);
+  if (fd == -1)
+  {
+    bdos_println("File not found");
+    exit();
+  }
+
+  while (readFileLine(fd, filesize) != EOF)
   {
     if (lastLineNumber >= MAX_LINES)
     {
-      BDOS_PrintConsole("E: File too large\n");
+      fs_close(fd);
+      bdos_print("E: File too large\n");
       exit();
     }
     else
@@ -336,7 +210,7 @@ void readInputFile()
     }
   }
 
-  FS_close();
+  fs_close(fd);
 }
 
 
@@ -437,7 +311,7 @@ void fixCursorToNewline()
     if (newLinePos == MAX_LINE_WIDTH)
     {
       exitRoutine();
-      BDOS_PrintConsole("E: could not find newline\n");
+      bdos_print("E: could not find newline\n");
       exit();
     }
   }
@@ -461,7 +335,7 @@ void fixCursorToNewline()
       else
       {
         exitRoutine();
-        BDOS_PrintConsole("E: scroll left limit reached\n");
+        bdos_print("E: scroll left limit reached\n");
         exit();
       }
     }
@@ -498,7 +372,7 @@ void gotoPosOfPrevLine(word targetPos)
     else
     {
       exitRoutine();
-      BDOS_PrintConsole("E: could not move up a line\n");
+      bdos_print("E: could not move up a line\n");
       exit();
     }
   }
@@ -524,7 +398,7 @@ void gotoPosOfPrevLine(word targetPos)
     if (xpos == MAX_LINE_WIDTH)
     {
       exitRoutine();
-      BDOS_PrintConsole("E: target out of bounds\n");
+      bdos_print("E: target out of bounds\n");
       exit();
     }
   }
@@ -581,7 +455,7 @@ void gotoEndOfPrevLine()
     if (xpos == MAX_LINE_WIDTH)
     {
       exitRoutine();
-      BDOS_PrintConsole("E: could not find newline\n");
+      bdos_print("E: could not find newline\n");
       exit();
     }
   }
@@ -830,7 +704,7 @@ void end()
     if (xpos == MAX_LINE_WIDTH)
     {
       exitRoutine();
-      BDOS_PrintConsole("E: could not find newline\n");
+      bdos_print("E: could not find newline\n");
       exit();
     }
   }
@@ -934,7 +808,7 @@ void removeCharacter()
         if (newLinePos == MAX_LINE_WIDTH)
         {
           exitRoutine();
-          BDOS_PrintConsole("E: could not find newline\n");
+          bdos_print("E: could not find newline\n");
           exit();
         }
       }
@@ -995,44 +869,47 @@ void exitRoutine()
 
 int main() 
 {
-  // input file
-  BDOS_GetArgN(1, infilename);
-
-  // error if none
-  if (infilename[0] == 0)
+  // Read number of arguments
+  word argc = shell_argc();
+  if (argc < 2)
   {
-    BDOS_PrintConsole("E: Missing filename\n");
-    exit();
+    bdos_println("Usage: edit <file>");
+    return 1;
   }
+  
+  // Read filename
+  char** args = shell_argv();
+  char* filename = args[1];
 
-  // Make full path if it is not already
-  if (infilename[0] != '/')
+  char absolute_path[MAX_PATH_LENGTH];
+  // Check if absolute path
+  if (filename[0] != '/')
   {
-    char bothPath[96];
-    bothPath[0] = 0;
-    strcat(bothPath, BDOS_GetPath());
-    if (bothPath[strlen(bothPath)-1] != '/')
-    {
-      strcat(bothPath, "/");
-    }
-    strcat(bothPath, infilename);
-    strcpy(infilename, bothPath);
+    char* cwd = fs_getcwd();
+    strcpy(absolute_path, cwd);
+    strcat(absolute_path, "/");
+    strcat(absolute_path, filename);
   }
-
-  if (!fopenRead())
+  else
   {
-    BDOS_PrintConsole("E: Could not open file\n");
-    exit();
+    strcpy(absolute_path, filename);
   }
 
-  // Open the input file
-  BDOS_PrintConsole("Opening ");
-  BDOS_PrintConsole(infilename);
-  BDOS_PrintConsole("...\n");
+  // Get file size
+  struct brfs_dir_entry* entry = (struct brfs_dir_entry*)fs_stat(absolute_path);
+  if ((word)entry == -1)
+  {
+    bdos_println("File not found");
+    return 1;
+  }
+  word filesize = entry->filesize;
 
-  readInputFile();
+  // Get filename
+  char decompressed_filename[17];
+  strdecompress(decompressed_filename, entry->filename);
+  strcpy(headerText, decompressed_filename);
 
-  strcpy(headerText, infilename);
+  readInputFile(absolute_path, filesize);
 
   // init gfx
   GFX_clearWindowtileTable();
@@ -1047,9 +924,9 @@ int main()
   // main loop
   while (1)
   {
-    if (HID_FifoAvailable())
+    if (hid_checkfifo())
     {
-      word c = HID_FifoRead();
+      word c = hid_fiforead();
       switch (c)
       {
         case 27: // escape
@@ -1060,14 +937,19 @@ int main()
           while (c != 'y' && c != 'n' && c != 'Y' && c != 'N' && c != 'c' && c != 'C')
           {
             // wait until a character is pressed
-            while (HID_FifoAvailable() == 0);
+            while (!hid_checkfifo());
 
-            c = HID_FifoRead();
+            c = hid_fiforead();
           }
 
           if (c == 'y' || c == 'Y')
           {
-            writeMemToFile();
+            // First delete file
+            fs_delete(absolute_path);
+            // Then create file
+            fs_mkfile(absolute_path);
+            // Then write to file
+            writeMemToFile(absolute_path);
             exitRoutine();
             return 'q'; // exit
           }
@@ -1131,7 +1013,7 @@ int main()
 void interrupt()
 {
   // Handle all interrupts
-  word i = getIntID();
+  word i = get_int_id();
   switch(i)
   {
     case INTID_TIMER1:

+ 0 - 441
BCC/userBDOS/toFix/wget.c

@@ -1,441 +0,0 @@
-// Wget
-// Tool to do a HTTP GET request
-
-#define word char
-
-#include "lib/math.c"
-#include "lib/stdlib.c"
-#include "lib/sys.c"
-#include "lib/fs.c"
-#include "lib/wiz5500.c"
-
-#define HEAP_LOCATION 0x500000
-
-// Which socket to use
-#define SOCKET_CLIENT 0
-
-#define CONNECT_MAX_RETRIES 1000
-
-
-// Initializes w5500 in client TCP mode, with a static ip (last digit as arg)
-// Port is also given as arg
-void initClient(word ip, word port)
-{
-  word ip_addr[4] = {192, 168, 0, 213};
-
-  word gateway_addr[4] = {192, 168, 0, 1};
-
-  word mac_addr[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0x24, 0x64};
-
-  word sub_mask[4] = {255, 255, 255, 0};
-
-  wiz_init(ip_addr, gateway_addr, mac_addr, sub_mask);
-
-  // Open socket in TCP Client mode at port
-  wiz_init_socket_tcp_client(SOCKET_CLIENT, port);
-}
-
-
-// Connect to target at given ip and port
-// Return 1 on success, 0 on failure
-word connectToTarget(char* ipTarget, word portTarget)
-{
-  wiz_write(WIZNET_SnDIPR,  WIZNET_WRITE_SnR + (SOCKET_CLIENT << 5), ipTarget, 4);
-  wiz_set_sock_reg_16(SOCKET_CLIENT, WIZNET_SnDPORT, portTarget);
-  wiz_send_cmd(SOCKET_CLIENT, WIZNET_CR_CONNECT);
-
-  word sxStatus = wiz_get_sock_reg_8(SOCKET_CLIENT, WIZNET_SnSR);
-
-  word retries = 0;
-
-  while (sxStatus != WIZNET_SOCK_ESTABLISHED && retries < CONNECT_MAX_RETRIES)
-  {
-    //BDOS_PrintHexConsole(sxStatus);
-    if (sxStatus == WIZNET_SOCK_CLOSED)
-    {
-      return 0;
-    }
-
-    sxStatus = wiz_get_sock_reg_8(SOCKET_CLIENT, WIZNET_SnSR);
-
-    if (sxStatus != WIZNET_SOCK_ESTABLISHED)
-    {
-      retries++;
-      delay(1);
-    }
-  }
-
-  return 1;
-}
-
-
-
-// Send request (headers should use \r\n according to the HTTP specs)
-void sendRequest()
-{
-  char* rTxt = (char*) HEAP_LOCATION; // we use heap for the request text
-  word rLen = 0;
-  word catLen = 0;
-
-  catLen = strcpy(rTxt + rLen, "GET /");
-  rLen += catLen;
-
-  char targetURL[64];
-  BDOS_GetArgN(2, targetURL);
-  catLen = strcpy(rTxt + rLen, targetURL);
-  rLen += catLen;
-
-  catLen = strcpy(rTxt + rLen, " HTTP/1.1\r\nUser-Agent: WGET(FPGC)\r\nAccept: */*\r\nHost: ");
-  rLen += catLen;
-
-  char ipstr[24];
-  BDOS_GetArgN(1, ipstr);
-  catLen = strcpy(rTxt + rLen, ipstr);
-  rLen += catLen;
-
-  catLen = strcpy(rTxt + rLen, "\r\n\r\n");
-  rLen += catLen;
-
-  wiz_write_data(SOCKET_CLIENT, rTxt, rLen);
-  BDOS_PrintConsole("Request sent\n");
-}
-
-
-// Init output file for download
-// Returns 1 on success, else 0
-word initOutputFile(char* path, char* fname, char* rbuf, word rsize)
-{
-  // sanity check current path
-  if (FS_sendFullPath(path) == FS_ANSW_USB_INT_SUCCESS)
-  {
-    word retval = FS_open();
-    // check that we can open the path
-    if (retval == FS_ANSW_USB_INT_SUCCESS || retval == FS_ANSW_ERR_OPEN_DIR)
-    {
-      // check length of filename
-      if (strlen(fname) <= 12)
-      {
-        // uppercase filename
-        strToUpper(fname);
-        // send filename
-        FS_sendSinglePath(fname);
-
-        // create the file
-        if (FS_createFile() == FS_ANSW_USB_INT_SUCCESS)
-        {
-          // open the path again
-          FS_sendFullPath(path);
-          FS_open();
-
-          // send filename again
-          FS_sendSinglePath(fname);
-          // open the newly created file
-          if (FS_open() == FS_ANSW_USB_INT_SUCCESS)
-          {
-            // set cursor to start
-            if (FS_setCursor(0) == FS_ANSW_USB_INT_SUCCESS)
-            {
-              if (FS_writeFile(rbuf, rsize) != FS_ANSW_USB_INT_SUCCESS)
-              {
-                FS_close();
-                BDOS_PrintConsole("Error while writing to file\n");
-                return 0;
-              }
-            }
-            else
-            {
-              FS_close();
-              BDOS_PrintConsole("Cursor error\n");
-              return 0;
-            }
-          }
-        }
-        else
-        {
-          BDOS_PrintConsole("Error while creating output file\n");
-          return 0;
-        }
-      }
-      else
-      {
-        BDOS_PrintConsole("Filename too long\n");
-        return 0;
-      }
-    }
-    else
-    {
-      BDOS_PrintConsole("Could not open path\n");
-      return 0;
-    }
-  }
-  else
-  {
-    BDOS_PrintConsole("Error sending path\n");
-    return 0;
-  }
-  return 1;
-}
-
-
-// Parses HTTP header, returns location of the first data byte
-word getDataStart(char* rbuf, word rsize)
-{
-  word dataStart = 0;
-
-  word i = 0;
-  while (i < rsize - 4 && dataStart == 0)
-  {
-    //BDOS_PrintcConsole(rbuf[i]);
-    if (rbuf[i] == '\r' && rbuf[i+1] == '\n' && rbuf[i+2] == '\r' && rbuf[i+3] == '\n')
-    {
-      dataStart = i+4;
-    }
-    else if (rbuf[i] == '\n' && rbuf[i+1] == '\n')
-    {
-      dataStart = i+2;
-    }
-
-    i++;
-  }
-
-  return dataStart;
-}
-
-
-// Parses HTTP header, returns status code
-word getStatusCode(char* rbuf, word rsize)
-{
-  word i = 0;
-  // look for first space, then 3 digits
-  while (i < rsize - 4)
-  {
-    if (rbuf[i] == ' ')
-    {
-      char statusStr[4];
-      statusStr[0] = rbuf[i+1];
-      statusStr[1] = rbuf[i+2];
-      statusStr[2] = rbuf[i+3];
-      statusStr[3] = 0;
-      return strToInt(statusStr);
-    }
-
-    i++;
-  }
-
-  return 0;
-}
-
-
-// Parses HTTP header, returns content length header field
-word getContentLength(char* rbuf, word rsize)
-{
-  word i = 0;
-  word strBufIndex = 0;
-  // look for Content-Length field
-  while (i < rsize - 4)
-  {
-    if (memcmp(&rbuf[i], "Content-Length: ", 16))
-    {
-      i = i + 16;
-      // when found, add all following characters to buffer until newline
-      char contentLengthStrBuf[32];
-      contentLengthStrBuf[0] = 0;
-
-      while (rbuf[i] != '\r' && rbuf[i] != '\n')
-      {
-        contentLengthStrBuf[strBufIndex] = rbuf[i];
-        i++;
-        strBufIndex++;
-      }
-
-      contentLengthStrBuf[strBufIndex] = 0; // terminate buffer
-      // finally, convert to int and return
-      return strToInt(contentLengthStrBuf);
-    }
-    i++;
-  }
-  return 0;
-}
-
-
-word getPercentageDone(word remaining, word full)
-{
-  word x = remaining * 100;
-  return 100 - MATH_divU(x, full);
-}
-
-// Receive response while connected
-// Write to file and terminal
-void receiveResponse(char* path, char* fname)
-{
-
-  word firstResponse = 1;
-  word contentLengthOrig[1]; // its an array now, because of a compiler bug in DeprCcompiler (ShivyC)
-  contentLengthOrig[0] = 0;
-  word contentLength = 0;
-
-  word currentProgress = 0;
-
-  BDOS_PrintConsole("Downloading response (any key to stop)\n");
-  while (wiz_get_sock_reg_8(SOCKET_CLIENT, WIZNET_SnSR) == WIZNET_SOCK_ESTABLISHED)
-  {
-    word rsize = wiz_get_sock_reg_16(SOCKET_CLIENT, WIZNET_SnRX_RSR);
-    if (rsize != 0)
-    {
-      char* rbuf = (char*) HEAP_LOCATION; // we use heap for the receive data buffer
-      wiz_read_recv_data(SOCKET_CLIENT, rbuf, rsize);
-      if (firstResponse)
-      {
-        word dataStart = getDataStart(rbuf, rsize);
-        contentLength = getContentLength(rbuf, rsize);
-        contentLengthOrig[0] = contentLength;
-
-        BDOS_PrintConsole("Status code: ");
-        BDOS_PrintDecConsole(getStatusCode(rbuf, rsize));
-        BDOS_PrintConsole("\n");
-
-        if (!initOutputFile(path, fname, &rbuf[dataStart], rsize - dataStart))
-          return;
-
-        contentLength -= (rsize - dataStart);
-
-        firstResponse = 0;
-
-        // all data downloaded
-        if (contentLength == 0)
-          break;
-      }
-      else
-      {
-        if (FS_writeFile(rbuf, rsize) != FS_ANSW_USB_INT_SUCCESS)
-        {
-          FS_close();
-          BDOS_PrintConsole("Error while writing to file\n");
-          return;
-        }
-        contentLength -= rsize;
-
-        if (getPercentageDone(contentLength, contentLengthOrig[0]) >= currentProgress)
-        {
-          BDOS_PrintDecConsole(currentProgress);
-          BDOS_PrintConsole("%\n");
-          currentProgress += 10;
-        }
-
-        // all data downloaded
-        if (contentLength == 0)
-          break;
-      }
-    }
-
-    // Allow manual cancel
-    if (HID_FifoAvailable())
-    {
-      HID_FifoRead(); // remove it from the buffer
-      break;
-    }
-  }
-  wiz_send_cmd(SOCKET_CLIENT, WIZNET_CR_DISCON);
-  BDOS_PrintConsole("Output written to ");
-  BDOS_PrintConsole(path);
-  BDOS_PrintConsole("/");
-  BDOS_PrintConsole(fname);
-  BDOS_PrintConsole("\n");
-  FS_close();
-}
-
-
-// convert string to IP by looking at the dots
-void strToIP(char* str, char* IP)
-{
-  word i = 0;
-  word dotsFound = 0;
-  word digitCounter = 0;
-  char tmp[16];
-  while (str[i] != 0)
-  {
-    if (str[i] == '.')
-    {
-      tmp[digitCounter] = 0;
-      IP[dotsFound] = strToInt(tmp);
-      dotsFound += 1;
-      digitCounter = 0;
-    }
-    else
-    {
-      tmp[digitCounter] = str[i];
-      digitCounter++;
-    }
-
-    i++;
-  }
-  tmp[digitCounter] = 0;
-  IP[dotsFound] = strToInt(tmp);
-}
-
-
-int main()
-{
-  // Init
-  BDOS_PrintConsole("WGET (IP path output [port])\n");
-  initClient(213, 1024);
-
-  // TODO: DNS lookup
-
-  // IP
-  char ipstr[24];
-  BDOS_GetArgN(1, ipstr);
-  char ipTarget[4];
-  strToIP(ipstr, ipTarget);
-
-  // Port
-  word portTarget = 0;
-  char portstr[16];
-  BDOS_GetArgN(4, portstr);
-  if (portstr[0] != 0)
-    portTarget = strToInt(portstr);
-
-  if (portTarget == 0)
-      portTarget = 80;
-
-
-  // Connect to target
-  if (!connectToTarget(ipTarget, portTarget))
-  {
-    BDOS_PrintConsole("Could not connect to host\n");
-    return 'q';
-  }
-  else
-    BDOS_PrintConsole("Connected to host\n");
-
-
-  // Send request
-  sendRequest();
-
-  // Receive response
-  char* path = BDOS_GetPath();
-
-  // If no filename is given, use OUT.TXT as default
-  char fname[16];
-  BDOS_GetArgN(3, fname);
-  if (fname[0] == 0)
-  {
-    strcpy(fname, "OUT.TXT");
-  }
-  receiveResponse(path, fname);
-
-
-  return 'q';
-}
-
-void interrupt()
-{
-  // Handle all interrupts
-  word i = getIntID();
-  switch(i)
-  {
-    case INTID_TIMER1:
-      timer1Value = 1;  // Notify ending of timer1
-      break;
-  }
-}