Split out relfile routines master
authorJakob Haufe <sur5r@sur5r.net>
Sat, 22 Sep 2018 21:34:05 +0000 (23:34 +0200)
committerJakob Haufe <sur5r@sur5r.net>
Sat, 22 Sep 2018 21:34:05 +0000 (23:34 +0200)
.gitignore
Makefile
relfile.c
relfile.h [new file with mode: 0644]
reltest.c [new file with mode: 0644]

index 67273c644085c25ece38a75902ac557f98620075..ae2f261f51e284549f6c905685298dfd2feb2c5c 100644 (file)
@@ -8,5 +8,9 @@ crctest.s
 diskbench
 diskbench.s
 
-relfile
+data
+
 relfile.s
+
+reltest
+reltest.s
index f95267cc947678b0a30aa9bd2e54745423e5fcbc..553ab610685a7149383e4490d6a611ac998313fc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ LD=cl65
 
 CFLAGS= -t c128
 
-all: diskbench.d71 crctest relfile.d71
+all: diskbench.d71 crctest reltest.d71
 
 
 diskbench.d71: diskbench
@@ -31,15 +31,18 @@ crctest: crctest.o crc16.o bcd2dec.o
 
 relfile.s: relfile.c
 
-relfile: relfile.o
+reltest.s: reltest.c
+
+reltest: reltest.o relfile.o
        ${LD} -t c128 $^ -o $@
 
-relfile.d71: relfile
-       c1541 -format "relfile",rf d71 relfile.d71
-       c1541 -attach relfile.d71 -write relfile
+reltest.d71: reltest
+       c1541 -format "reltest",rf d71 reltest.d71
+       c1541 -attach reltest.d71 -write reltest
 
 clean:
        rm -f bcd2dec.o crc16.o
        rm -f diskbench.d71 diskbench diskbench.o diskbench.s data
        rm -f crctest crctest.o crctest.s crctest.lbl
-       rm -f relfile.d71 relfile relfile.o relfile.s
+       rm -f relfile.o relfile.s
+       rm -f reltest.d71 reltest reltest.o reltest.s
index 5871c1b3639d64eaf495c3c03fe7aacf3c22dabe..a4e8f4c6159a1db3a1e6a0ab3788e329352a5bfd 100644 (file)
--- a/relfile.c
+++ b/relfile.c
@@ -2,20 +2,10 @@
 #include <cbm.h>
 #include <errno.h>
 #include <stdio.h>
-#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "bcd2dec.h"
-
-struct relfile
-{
-    uint8_t fd;
-    uint8_t cmdfd;
-    uint8_t devnr;
-    uint8_t sa;
-    uint8_t recsize;
-};
+#include "relfile.h"
 
 #define RELFILENAME_MAX (FILENAME_MAX + 4) // FOO,L,\xFF\0
 
@@ -80,138 +70,3 @@ void relfile_close(struct relfile *rf)
     cbm_close(rf->fd);
 }
 
-void c128_perror(uint8_t c, char *msg) {
-  cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg,
-          _oserror);
-}
-
-int main(void)
-{
-    char bla[25];
-    struct relfile rf;
-    uint8_t c=0;
-    uint8_t start_sec, start_tenth;
-    uint8_t end_sec, end_tenth;
-    uint8_t i,j;
-
-    videomode(VIDEOMODE_80x25);
-    fast();
-
-    __asm__("jsr initsystime");
-
-    rf.fd=2;
-    rf.devnr=8;
-    rf.sa=3;
-    rf.recsize=25;
-
-    if(relfile_open(&rf, "reldata"))
-    {
-        c128_perror(c, "relfile_open");
-        return 1;
-    }
-
-    start_tenth = CIA1.tod_10;
-    start_sec = CIA1.tod_sec;
-
-    for(i=1;i<=25;i++)
-    {
-        //cgetc();
-        /*
-        cprintf("P%d\r",i);
-        if(relfile_pos(&rf, i, 0))
-        {
-            c128_perror(c, "relfile_pos1");
-            return 2;
-        }
-        */
-        if(relfile_is_split_record(&rf, i))
-        {
-            cprintf("\r\nSPLIT: %d!\r\n",i);
-        }
-        /*
-        if(relfile_pos(&rf, i, 0))
-        {
-            c128_perror(c, "relfile_pos2");
-            return 2;
-        }
-        cprintf("C%d\r",i);
-        if(relfile_clear(&rf))
-        {
-            c128_perror(c, "relfile_clear");
-            return 2;
-        }
-        */
-        cprintf("W%d: ", i);
-        for(j=0;j<rf.recsize;j++)
-        {
-            bla[j]=(i-1==j) ? 0xFF : 0xAA;
-            cprintf("%02X",bla[j]);
-        }
-        cprintf("\r\n");
-
-        if(relfile_pos(&rf, i, 0))
-        {
-            c128_perror(c, "relfile_pos3");
-            return 2;
-        }
-        if(relfile_write(&rf, bla))
-        {
-            c128_perror(c, "relfile_write");
-            return 2;
-        }
-    }
-
-    relfile_close(&rf);
-    end_tenth = CIA1.tod_10;
-    end_sec = CIA1.tod_sec;
-    cprintf("\r\n%d.%d -> %d.%d\r\n",start_sec,start_tenth,end_sec,end_tenth);
-
-
-    if(relfile_open(&rf, "reldata"))
-    {
-        c128_perror(0, "relfile_open");
-        return 3;
-    }
-
-    start_tenth = CIA1.tod_10;
-    start_sec = CIA1.tod_sec;
-
-    for(i=1;i<=25;i++)
-    {
-        cprintf("P%d\r",i);
-        if(relfile_pos(&rf, i, 0))
-        {
-            c128_perror(0, "relfile_pos");
-            return 1;
-        }
-        if(relfile_is_split_record(&rf, i))
-        {
-            cprintf("\r\nSPLIT!\r\n");
-        }
-        cprintf("R%d\r",i);
-        if(relfile_read(&rf, bla))
-        {
-            c128_perror(0, "relfile_read");
-            return 1;
-        }
-
-        cprintf("?%d\r",i);
-        for(j=0;j<rf.recsize;j++)
-        {
-            uint8_t exp=(i-1==j) ? 0xFF : 0xAA;
-            if(bla[j] != exp)
-            {
-                cprintf("\r\nMISMATCH(%2d): IS: %2X EXP: %2X\r\n",j,bla[j],exp);
-                cgetc();
-            }
-        }
-    }
-
-    relfile_close(&rf);
-    end_tenth = CIA1.tod_10;
-    end_sec = CIA1.tod_sec;
-    cprintf("\r\n%d.%d -> %d.%d\r\n",start_sec,start_tenth,end_sec,end_tenth);
-
-    return 0;
-}
-
diff --git a/relfile.h b/relfile.h
new file mode 100644 (file)
index 0000000..4f7e88f
--- /dev/null
+++ b/relfile.h
@@ -0,0 +1,18 @@
+#include <stdint.h>
+
+struct relfile
+{
+    uint8_t fd;
+    uint8_t cmdfd;
+    uint8_t devnr;
+    uint8_t sa;
+    uint8_t recsize;
+};
+
+uint8_t relfile_open(struct relfile *rf, char* name);
+uint8_t relfile_is_split_record(struct relfile *rf, uint16_t recnum);
+uint8_t relfile_pos(struct relfile *rf, uint16_t recnum, uint8_t offset);
+uint8_t relfile_read(struct relfile *rf, uint8_t *buf);
+uint8_t relfile_write(struct relfile *rf, uint8_t *buf);
+uint8_t relfile_clear(struct relfile *rf);
+void relfile_close(struct relfile *rf);
diff --git a/reltest.c b/reltest.c
new file mode 100644 (file)
index 0000000..449959e
--- /dev/null
+++ b/reltest.c
@@ -0,0 +1,145 @@
+#include <conio.h>
+#include <cbm.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "relfile.h"
+
+void c128_perror(uint8_t c, char *msg) {
+  cprintf("\r\nError (Code %d) while: %s\r\nOS Error = %d\r\n", c, msg,
+          _oserror);
+}
+
+int main(void)
+{
+    char bla[25];
+    struct relfile rf;
+    uint8_t c=0;
+    uint8_t start_sec, start_tenth;
+    uint8_t end_sec, end_tenth;
+    uint8_t i,j;
+
+    videomode(VIDEOMODE_80x25);
+    fast();
+
+    __asm__("jsr initsystime");
+
+    rf.fd=2;
+    rf.devnr=8;
+    rf.sa=3;
+    rf.recsize=25;
+
+    if(relfile_open(&rf, "reldata"))
+    {
+        c128_perror(c, "relfile_open");
+        return 1;
+    }
+
+    start_tenth = CIA1.tod_10;
+    start_sec = CIA1.tod_sec;
+
+    for(i=1;i<=25;i++)
+    {
+        //cgetc();
+        /*
+        cprintf("P%d\r",i);
+        if(relfile_pos(&rf, i, 0))
+        {
+            c128_perror(c, "relfile_pos1");
+            return 2;
+        }
+        */
+        if(relfile_is_split_record(&rf, i))
+        {
+            cprintf("\r\nSPLIT: %d!\r\n",i);
+        }
+        /*
+        if(relfile_pos(&rf, i, 0))
+        {
+            c128_perror(c, "relfile_pos2");
+            return 2;
+        }
+        cprintf("C%d\r",i);
+        if(relfile_clear(&rf))
+        {
+            c128_perror(c, "relfile_clear");
+            return 2;
+        }
+        */
+        cprintf("W%d: ", i);
+        for(j=0;j<rf.recsize;j++)
+        {
+            bla[j]=(i-1==j) ? 0xFF : 0xAA;
+            cprintf("%02X",bla[j]);
+        }
+        cprintf("\r\n");
+
+        if(relfile_pos(&rf, i, 0))
+        {
+            c128_perror(c, "relfile_pos3");
+            return 2;
+        }
+        if(relfile_write(&rf, bla))
+        {
+            c128_perror(c, "relfile_write");
+            return 2;
+        }
+    }
+
+    relfile_close(&rf);
+    end_tenth = CIA1.tod_10;
+    end_sec = CIA1.tod_sec;
+    cprintf("\r\n%d.%d -> %d.%d\r\n",start_sec,start_tenth,end_sec,end_tenth);
+
+
+    if(relfile_open(&rf, "reldata"))
+    {
+        c128_perror(0, "relfile_open");
+        return 3;
+    }
+
+    start_tenth = CIA1.tod_10;
+    start_sec = CIA1.tod_sec;
+
+    for(i=1;i<=25;i++)
+    {
+        cprintf("P%d\r",i);
+        if(relfile_pos(&rf, i, 0))
+        {
+            c128_perror(0, "relfile_pos");
+            return 1;
+        }
+        if(relfile_is_split_record(&rf, i))
+        {
+            cprintf("\r\nSPLIT!\r\n");
+        }
+        cprintf("R%d\r",i);
+        if(relfile_read(&rf, bla))
+        {
+            c128_perror(0, "relfile_read");
+            return 1;
+        }
+
+        cprintf("?%d\r",i);
+        for(j=0;j<rf.recsize;j++)
+        {
+            uint8_t exp=(i-1==j) ? 0xFF : 0xAA;
+            if(bla[j] != exp)
+            {
+                cprintf("\r\nMISMATCH(%2d): IS: %2X EXP: %2X\r\n",j,bla[j],exp);
+                cgetc();
+            }
+        }
+    }
+
+    relfile_close(&rf);
+    end_tenth = CIA1.tod_10;
+    end_sec = CIA1.tod_sec;
+    cprintf("\r\n%d.%d -> %d.%d\r\n",start_sec,start_tenth,end_sec,end_tenth);
+
+    return 0;
+}
+