Parcourir la source

Added buffer for asm and bcc. Other minor improvements. fgpc build tools are confirmed working by compiling raycast on device.

bart il y a 7 mois
Parent
commit
24c2098f9e

+ 1 - 1
BCC/BDOS/lib/shell.c

@@ -141,7 +141,7 @@ word shell_run_program(word run_from_path)
   word fp = brfs_open_file(absolute_path);
   if (fp == -1)
   {
-    GFX_PrintConsole("Could not open file\n");
+    // No warning as a local dir could have the same name as a program in SHELL_BIN_PATH
     return 0;
   }
 

+ 12 - 12
BCC/FPGCbuildTools/asm/asm.c

@@ -28,15 +28,15 @@
 
 #define USERBDOS_OFFSET 0x400000 // applied offset to all labels
 
-#define OUTFILE_DATA_ADDR 0x500000
-#define OUTFILE_CODE_ADDR 0x540000
-#define OUTFILE_PASS1_ADDR 0x580000
-#define OUTFILE_PASS2_ADDR 0x600000
+#define OUTFILE_DATA_ADDR 0x420000
+#define OUTFILE_CODE_ADDR 0x4A0000
+#define OUTFILE_PASS1_ADDR 0x520000
+#define OUTFILE_PASS2_ADDR 0x610000
 
-#define LABELLISTLINENR_ADDR 0x65F000
-#define LABELLIST_ADDR 0x660000
+#define LABELLISTLINENR_ADDR 0x6F0000
+#define LABELLIST_ADDR 0x700000
 
-#define LINEBUFFER_ADDR 0x4C0000
+#define LINEBUFFER_ADDR 0x6E0000
 
 word fd_input = -1;
 word fd_output = -1;
@@ -528,7 +528,7 @@ void LinePass1(char* outputAddr, char* outputCursor)
 
 void doPass1()
 {
-    bdos_print("Doing pass 1\n");
+    bdos_print("Performing pass 1\n");
 
     memCursor = 0; // reset cursor for readMemLine
     globalLineCursor = 0; // keep track of the line number for the labels
@@ -658,7 +658,7 @@ void LinePass2(char* outputAddr, char* outputCursor)
 // returns the length of the binary
 word doPass2()
 {
-    bdos_print("Doing pass 2\n");
+    bdos_print("Performing pass 2\n");
 
     memCursor = 0; // reset cursor for readMemLine
 
@@ -685,7 +685,7 @@ void moveDataDown()
     *outfileCodeAddr = 0; // initialize to 0
     word fileCodeCursor = 0;
 
-    bdos_print("Looking for .data and .code sections\n");
+    bdos_print("Reading .data and .code sections\n");
 
     // Open file
     fd_input = fs_open(absolute_path_in);
@@ -752,7 +752,7 @@ void moveDataDown()
     *(outfileCodeAddr+fileCodeCursor) = 0; // terminate code section
     // do not increment the codeCursor, because we will append the data section
 
-    bdos_print("Looking for .rdata and .bss sections\n");
+    bdos_print("Reading .rdata and .bss sections\n");
 
     // reopen file to reiterate
     fs_close(fd_input);
@@ -887,7 +887,7 @@ int main()
     word pass2Length = doPass2();
 
 
-    bdos_print("Writing to file\n");
+    bdos_print("Writing binary file\n");
     fd_output = fs_open(absolute_path_out);
     if (fd_output == -1)
     {

+ 20 - 5
BCC/FPGCbuildTools/asm/lib/stdio.c

@@ -1,20 +1,35 @@
 /*
 * Very simple stdio library for mapping stdio functions to brfs.
+* Adds buffer for fgetc to improve performance.
 */
 
 #define EOF -1
 
+#define FGETC_BUFFER_SIZE 512
+
+word fgetc_buffer[FGETC_BUFFER_SIZE];
+word fgetc_buffer_cursor = -1;
+
 // returns the current char at cursor within the opened file (EOF if end of file)
 // increments the cursor
 word fgetc(word fd, word filesize)
 {
-  word cursor = fs_getcursor(fd);
-  if (cursor == filesize)
+  if (fgetc_buffer_cursor == -1 || fgetc_buffer_cursor == FGETC_BUFFER_SIZE)
   {
-    return EOF;
+    word cursor = fs_getcursor(fd);
+    if (filesize - cursor < FGETC_BUFFER_SIZE)
+    {
+      fs_read(fd, fgetc_buffer, filesize - cursor);
+      fgetc_buffer[filesize - cursor] = EOF;
+    }
+    else
+    {
+      fs_read(fd, fgetc_buffer, FGETC_BUFFER_SIZE);
+    }
+    fgetc_buffer_cursor = 0;
   }
 
-  char c;
-  fs_read(fd, &c, 1);
+  char c = fgetc_buffer[fgetc_buffer_cursor];
+  fgetc_buffer_cursor++;
   return c;
 }

+ 4 - 4
BCC/FPGCbuildTools/bcc/backend.c

@@ -627,13 +627,13 @@ void GenWriteFrameSize(void) //WORDSIZE
 void GenUpdateFrameSize(void)
 {
   word curpos = 0;
-  curpos = fs_getcursor(OutFile);
+  curpos = stdio_getcursor(OutFile);
   //printf("cur: ");
   //printd(curpos);
   //printf("\ngoto: ");
   //printd(GenPrologPos);
   //printf("\n");
-  fs_setcursor(OutFile, GenPrologPos);
+  stdio_setcursor(OutFile, GenPrologPos);
   GenWriteFrameSize();
 
   //printf("back to cur: ");
@@ -641,7 +641,7 @@ void GenUpdateFrameSize(void)
   //printf("\n");
   //printf("\n");
 
-  fs_setcursor(OutFile, curpos);
+  stdio_setcursor(OutFile, curpos);
 }
 
 void GenFxnProlog(void)
@@ -664,7 +664,7 @@ void GenFxnProlog(void)
 
   GenLeaf = 1; // will be reset to 0 if a call is generated
 
-  GenPrologPos = fs_getcursor(OutFile);
+  GenPrologPos = stdio_getcursor(OutFile);
   
   // write an empty space for the frame size
   word x;

+ 9 - 4
BCC/FPGCbuildTools/bcc/bcc.c

@@ -78,6 +78,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #define SYNSTACK1_ADDR 0x470000
 #define INPUTBUFFER_ADDR 0x480000
 #define FILENAMES_ADDR 0x490000
+#define OUTFILE_DATA_ADDR 0x500000
 
 #include "lib/math.c"
 #include "lib/sys.c"
@@ -857,6 +858,8 @@ word GetNextChar(void)
       fs_close(Files[FileCnt - 1]);
       Files[FileCnt - 1] = NULL;
 
+      bdos_println(" Done");
+
       // store the last line/pos, they may still be needed later
       LineNos[FileCnt - 1] = LineNo;
       LinePoss[FileCnt - 1] = LinePos;
@@ -945,7 +948,7 @@ void IncludeFile(word quot)
     Files[FileCnt] = fs_open(cFileDir);
 
     bdos_print("- Compiling: ");
-    bdos_println(cFileDir);
+    bdos_print(basename(cFileDir));
 
     // Get file size
     struct brfs_dir_entry* entry = (struct brfs_dir_entry*)fs_stat(cFileDir);
@@ -982,7 +985,7 @@ void IncludeFile(word quot)
           if ((Files[FileCnt] = fs_open(FileNames[FileCnt])) != NULL)
           {
             bdos_print("- Compiling: ");
-            bdos_println(FileNames[FileCnt]);
+            bdos_println(basename(FileNames[FileCnt]));
             // Get file size
             struct brfs_dir_entry* entry = (struct brfs_dir_entry*)fs_stat(FileNames[FileCnt]);
             word filesize = entry->filesize;
@@ -7871,7 +7874,7 @@ int main()
     Files[0] = fs_open(FileNames[0]);
 
     bdos_print("Compiling: ");
-    bdos_println(FileNames[0]);
+    bdos_println(basename(FileNames[0]));
 
     // Get file size
     struct brfs_dir_entry* entry = (struct brfs_dir_entry*)fs_stat(FileNames[0]);
@@ -7954,7 +7957,9 @@ int main()
   */
 
   //GenStartCommentLine(); 
-  printf("Finished compiling\n");
+
+  printf("Writing to file\n");
+  stdio_flush(OutFile);
 
   if (OutFile)
     fs_close(OutFile);

+ 96 - 14
BCC/FPGCbuildTools/bcc/lib/stdio.c

@@ -1,47 +1,129 @@
 /*
 * Stdio replacement library
 * Maps common stdio functions to brfs functions
+* Adds buffers to improve performance.
+* Outputfile is written in memory first and then written to disk.
 */
 
 #define EOF -1
 
+#define FGETC_BUFFER_SIZE 512
+
+word fgetc_buffer_main[FGETC_BUFFER_SIZE];
+word fgetc_buffer_lib[FGETC_BUFFER_SIZE];
+word fgetc_buffer_cursor_main = -1;
+word fgetc_buffer_cursor_lib = -1;
+word fgetc_buffer_fd_main = -1;
+word fgetc_buffer_fd_lib = -1;
+
+char *outfileData = (char*) OUTFILE_DATA_ADDR;
+word outfileCursor = 0;
 
 // returns the current char at cursor within the opened file (EOF if end of file)
 // increments the cursor
+// For the buffer, it assumes that not more than two files are open for reading at the same time
 word fgetc(word fd, word filesize)
 {
-  word cursor = fs_getcursor(fd);
-  if (cursor == filesize)
+  if (fgetc_buffer_fd_main == -1)
+  {
+    fgetc_buffer_fd_main = fd;
+  }
+
+  if (fd != fgetc_buffer_fd_main)
+  {
+    if (fd != fgetc_buffer_fd_lib)
+    {
+      // Clear buffer for new lib file
+      fgetc_buffer_cursor_lib = -1;
+    }
+    fgetc_buffer_fd_lib = fd;
+  }
+
+
+  if (fd == fgetc_buffer_fd_main)
+  {
+    if (fgetc_buffer_cursor_main == -1 || fgetc_buffer_cursor_main == FGETC_BUFFER_SIZE)
+    {
+      word cursor = fs_getcursor(fd);
+      if (filesize - cursor < FGETC_BUFFER_SIZE)
+      {
+        fs_read(fd, fgetc_buffer_main, filesize - cursor);
+        fgetc_buffer_main[filesize - cursor] = EOF;
+      }
+      else
+      {
+        fs_read(fd, fgetc_buffer_main, FGETC_BUFFER_SIZE);
+      }
+      fgetc_buffer_cursor_main = 0;
+    }
+
+    char c = fgetc_buffer_main[fgetc_buffer_cursor_main];
+    fgetc_buffer_cursor_main++;
+    return c;
+  }
+  else if (fd == fgetc_buffer_fd_lib)
   {
-    return EOF;
+    if (fgetc_buffer_cursor_lib == -1 || fgetc_buffer_cursor_lib == FGETC_BUFFER_SIZE)
+    {
+      word cursor = fs_getcursor(fd);
+      if (filesize - cursor < FGETC_BUFFER_SIZE)
+      {
+        fs_read(fd, fgetc_buffer_lib, filesize - cursor);
+        fgetc_buffer_lib[filesize - cursor] = EOF;
+      }
+      else
+      {
+        fs_read(fd, fgetc_buffer_lib, FGETC_BUFFER_SIZE);
+      }
+      fgetc_buffer_cursor_lib = 0;
+    }
+
+    char c = fgetc_buffer_lib[fgetc_buffer_cursor_lib];
+    fgetc_buffer_cursor_lib++;
+    return c;
   }
+  bdos_println("UNEXPECTED ERROR IN FGETC");
+  return EOF;
+}
 
-  char c;
-  fs_read(fd, &c, 1);
-  return c;
+// Ignore fp as we assume only one output file
+void stdio_setcursor(word fp, word pos)
+{
+  outfileCursor = pos;
 }
 
+// Ignore fp as we assume only one output file
+word stdio_getcursor(word fp)
+{
+  return outfileCursor;
+}
 
-// write string to file
 word fputs(word fd, char* s)
 {
-    fs_write(fd, s, strlen(s));
-    return 1;
+  word len = strlen(s);
+  memcpy(outfileData + outfileCursor, s, len);
+  outfileCursor += len;
 }
 
-// write string to file
 word fputc(word fd, char c)
 {
-    fs_write(fd, &c, 1);
-    return 1;
+  outfileData[outfileCursor] = c;
+  outfileCursor++;
+}
+
+// Flush output buffer to filesystem
+void stdio_flush(word fd)
+{
+  fs_write(fd, outfileData, outfileCursor);
+  outfileCursor = 0;
 }
 
 word printf(char* s)
 {
-    bdos_print(s);
+  bdos_print(s);
 }
 
 word printd(word d)
 {
-    bdos_printdec(d);
+  bdos_printdec(d);
 }

+ 7 - 3
BCC/syncCsourceFiles.sh

@@ -13,13 +13,13 @@ echo "clear" | python3 "$MAINPATH/../Programmer/sendCommand.py"
 echo "cd /" | python3 "$MAINPATH/../Programmer/sendCommand.py"
 
 # Create directories
-echo "mkdir c" | python3 "$MAINPATH/../Programmer/sendCommand.py"
-echo "mkdir c/src" | python3 "$MAINPATH/../Programmer/sendCommand.py"
+echo "mkdir src" | python3 "$MAINPATH/../Programmer/sendCommand.py"
+echo "mkdir src/c" | python3 "$MAINPATH/../Programmer/sendCommand.py"
 
 for i in $(find . -type f -print)
 do
     FNAME=$(basename $i)
-    DIR="/c/src$(dirname $i | cut -c 2-)"
+    DIR="/src/c$(dirname $i | cut -c 2-)"
 
     # Create directory
     echo "mkdir $DIR" | python3 "$MAINPATH/../Programmer/sendCommand.py"
@@ -31,4 +31,8 @@ do
     cd $MAINPATH/../Programmer
     sh sendTextFile.sh $MAINPATH/userBDOS/$i
 
+    echo "sync" | python3 "$MAINPATH/../Programmer/sendCommand.py"
+
+    sleep 2
+
 done

+ 1 - 1
Programmer/sendTextFile.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 
-if [ "$1" == "" ]
+if [ $# -eq 0 ]
 then
     echo "No file to send"
     exit 1