diff --git a/targettest/cbm/Makefile b/targettest/cbm/Makefile index 47ae5171d..c3171b13e 100644 --- a/targettest/cbm/Makefile +++ b/targettest/cbm/Makefile @@ -2,6 +2,10 @@ # var. to build for another target system. SYS ?= c64 +# This one comes with the VICE emulator. +# See http://vice-emu.sourceforge.net/ +C1541 ?= c1541 + # Just the usual way to find out if we're # using cmd.exe to execute make rules. ifneq ($(shell echo),) @@ -32,11 +36,20 @@ endif EXELIST_c64 = \ petscii.prg \ - cbmdir-test.prg + cbmdir-test.prg \ + cbmread.prg + +EXTRALIST_c64 = \ + read-0 \ + read-1 \ + read-8 EXELIST_vic20 = \ cbmdir-test.prg +DISK_c64 = testcode.d64 +DISK_vic20 = testcode.d64 + ifneq ($(EXELIST_$(SYS)),) testcode: $(EXELIST_$(SYS)) else @@ -66,5 +79,38 @@ else $(CL) -t $(SYS) -Oris -o $@ $< endif +cbmread.prg: cbmread.c +ifeq ($(SYS),vic20) + $(CL) -t $(SYS) -C vic20-32k.cfg -Oris -o $@ $< +else + $(CL) -t $(SYS) -Oris -o $@ $< +endif + +# -------------------------------------------------------------------------- +# Rule to make a CBM disk with all testcode. Needs the c1541 program that comes +# with the VICE emulator. + +define D64_WRITE_PRG_recipe + +$(C1541) -attach $@ -write "$(subst ?,$(SPACE),$(file))" "$(subst ?,$(SPACE),$(subst .prg,,$(notdir $(file))))",p >$(NULLDEV) + +endef # D64_WRITE_PRG_recipe + +define D64_WRITE_SEQ_recipe + +$(C1541) -attach $@ -write "$(subst ?,$(SPACE),$(file))" $(notdir $(file)),s >$(NULLDEV) + +endef # D64_WRITE_SEQ_recipe + +disk: $(DISK_$(SYS)) + +testcode.d64: testcode + @$(C1541) -format "testcode,00" d64 $@ >$(NULLDEV) + $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_PRG_recipe)) + $(foreach file,$(EXTRALIST_$(SYS)),$(D64_WRITE_SEQ_recipe)) +# $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_SEQ_recipe)) + clean: @$(DEL) *.lbl petscii.prg cbmdir-test.prg 2>$(NULLDEV) + @$(DEL) $(DISK_c64) + @$(DEL) $(DISK_vic20) diff --git a/targettest/cbm/cbmread.c b/targettest/cbm/cbmread.c new file mode 100644 index 000000000..b48410e00 --- /dev/null +++ b/targettest/cbm/cbmread.c @@ -0,0 +1,82 @@ +#include +#include +#include + +#include + +int res = 0; +int tests = 0; + +#define LFN 8 + +#define MAXREADSIZE 256 + +static char data[MAXREADSIZE]; + +void test1 (char * what, char * filename, int len1, int len2, int rlen1, int rlen2) +{ + int rlen; + unsigned char err; + + printf ("1:%s (%d bytes)..." , what, rlen1); + + err = cbm_open (LFN, 8, 8, filename); + if (err != 0) { + printf ("\nError: could not open file.\n"); + goto test1exit; + } + + rlen = cbm_read (LFN, data, rlen1); + if (rlen == -1) { + printf ("\ncbm_read error (%d)\n", _oserror); + res++; + goto test1exit; + } + if (rlen != len1) { + printf ("\nError: 1st read returned %d instead of %d\n", rlen, len1); + res++; + goto test1exit; + } + + printf (" OK\n"); + + printf ("2:%s (%d bytes)..." , what, rlen2); + + rlen = cbm_read (LFN, data, rlen2); + if (rlen == -1) { + printf ("\ncbm_read error (%d)\n", _oserror); + res++; + goto test1exit; + } + if (rlen != len2) { + printf ("\nError: 2nd read returned %d instead of %d\n", rlen, len2); + res++; + goto test1exit; + } + + printf (" OK\n"); + +test1exit: + cbm_close (LFN); + tests++; +} + +int main(void) +{ + test1 ("Read empty file", "read-0", 0, 0, 0, 0); + test1 ("Read empty file", "read-0", 0, 0, 1, 1); + test1 ("Read empty file", "read-0", 0, 0, 8, 8); + + test1 ("Read 1 byte file", "read-1", 0, 0, 0, 0); + test1 ("Read 1 byte file", "read-1", 1, 0, 1, 1); + test1 ("Read 1 byte file", "read-1", 1, 0, 8, 8); + + test1 ("Read 8 byte file", "read-8", 0, 0, 0, 0); + test1 ("Read 8 byte file", "read-8", 1, 1, 1, 1); + test1 ("Read 8 byte file", "read-8", 4, 4, 4, 4); + test1 ("Read 8 byte file", "read-8", 8, 0, 8, 8); + test1 ("Read 8 byte file", "read-8", 8, 0,10, 1); + + printf ("%d/%d Tests failed.\n", res, tests); + return res; +} diff --git a/targettest/cbm/read-0 b/targettest/cbm/read-0 new file mode 100644 index 000000000..e69de29bb diff --git a/targettest/cbm/read-1 b/targettest/cbm/read-1 new file mode 100644 index 000000000..7371f47a6 --- /dev/null +++ b/targettest/cbm/read-1 @@ -0,0 +1 @@ +B \ No newline at end of file diff --git a/targettest/cbm/read-8 b/targettest/cbm/read-8 new file mode 100644 index 000000000..42ec1bdb8 --- /dev/null +++ b/targettest/cbm/read-8 @@ -0,0 +1 @@ +Gͺ»Μέ \ No newline at end of file