From: Jakob Haufe Date: Sat, 22 Sep 2018 21:34:05 +0000 (+0200) Subject: Split out relfile routines X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;ds=inline;p=rgb2r-2017 Split out relfile routines --- diff --git a/.gitignore b/.gitignore index 67273c6..ae2f261 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,9 @@ crctest.s diskbench diskbench.s -relfile +data + relfile.s + +reltest +reltest.s diff --git a/Makefile b/Makefile index f95267c..553ab61 100644 --- 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 diff --git a/relfile.c b/relfile.c index 5871c1b..a4e8f4c 100644 --- a/relfile.c +++ b/relfile.c @@ -2,20 +2,10 @@ #include #include #include -#include #include #include -#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 %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 %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 index 0000000..4f7e88f --- /dev/null +++ b/relfile.h @@ -0,0 +1,18 @@ +#include + +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 index 0000000..449959e --- /dev/null +++ b/reltest.c @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include +#include +#include + +#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 %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 %d.%d\r\n",start_sec,start_tenth,end_sec,end_tenth); + + return 0; +} +