added example/test for cbm_read, related to issue #1306

This commit is contained in:
mrdudz 2022-07-25 21:01:31 +02:00
parent d03f28d0ed
commit f99cb177c6
5 changed files with 131 additions and 1 deletions

View File

@ -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)

82
targettest/cbm/cbmread.c Normal file
View File

@ -0,0 +1,82 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <cbm.h>
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;
}

0
targettest/cbm/read-0 Normal file
View File

1
targettest/cbm/read-1 Normal file
View File

@ -0,0 +1 @@
B

1
targettest/cbm/read-8 Normal file
View File

@ -0,0 +1 @@
GЊЛЬн