mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
Added a program that tests the Commodore-specific directory functions.
This commit is contained in:
parent
62da869e49
commit
52e4387929
@ -30,10 +30,13 @@ else
|
|||||||
LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65)
|
LD := $(if $(wildcard ../../../bin/ld65*),../../../bin/ld65,ld65)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: petscii.prg
|
all: petscii.prg cbmdir-test.prg
|
||||||
|
|
||||||
petscii.prg: petscii.c
|
petscii.prg: petscii.c
|
||||||
$(CL) -t $(SYS) -O -o petscii.prg petscii.c
|
$(CL) -t $(SYS) -O -o petscii.prg petscii.c
|
||||||
|
|
||||||
|
cbmdir-test.prg: cbmdir-test.c
|
||||||
|
$(CL) -t $(SYS) -Oris -o $@ $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@$(DEL) petscii.prg 2>$(NULLDEV)
|
@$(DEL) petscii.prg cbmdir-test.prg 2>$(NULLDEV)
|
||||||
|
119
targettest/cbm/cbmdir-test.c
Normal file
119
targettest/cbm/cbmdir-test.c
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
** Tests the CBM-specific directory functions.
|
||||||
|
**
|
||||||
|
** 2021-08-12, Greg King
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <conio.h>
|
||||||
|
#include <cbm.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* device number */
|
||||||
|
#define UNIT 8
|
||||||
|
|
||||||
|
/* directory patterm */
|
||||||
|
static const char name[] = "$";
|
||||||
|
|
||||||
|
|
||||||
|
static const char* const type[] = {
|
||||||
|
"DEL",
|
||||||
|
"CBM",
|
||||||
|
"DIR",
|
||||||
|
"LNK",
|
||||||
|
"???",
|
||||||
|
"Directory header",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"SEQ",
|
||||||
|
"PRG",
|
||||||
|
"USR",
|
||||||
|
"REL",
|
||||||
|
"VRP"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* const access[] = {
|
||||||
|
"unknown",
|
||||||
|
"read-only",
|
||||||
|
"write-only",
|
||||||
|
"read/write"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char* const error[] = {
|
||||||
|
"",
|
||||||
|
"couldn't read it",
|
||||||
|
"",
|
||||||
|
"couldn't find start of file-name",
|
||||||
|
"couldn't find end of file-name",
|
||||||
|
"couldn't read file-type",
|
||||||
|
"premature end of file"
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
unsigned char go = 0;
|
||||||
|
unsigned char rc;
|
||||||
|
struct cbm_dirent E;
|
||||||
|
|
||||||
|
/* Explain use, and wait for a key. */
|
||||||
|
printf ("use the following keys:\n"
|
||||||
|
" g -> go ahead without stopping\n"
|
||||||
|
" q -> quit directory lister\n"
|
||||||
|
"tap any key to start ...\n\n");
|
||||||
|
cgetc ();
|
||||||
|
|
||||||
|
/* Open the directory. */
|
||||||
|
if (cbm_opendir (1, UNIT, name) != 0) {
|
||||||
|
printf("error opening %s:\n %s\n", name, _stroserror (_oserror));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Output the directory. */
|
||||||
|
printf("contents of \"%s\":\n", name);
|
||||||
|
while ((rc = cbm_readdir (1, &E)) != 2) {
|
||||||
|
if (rc != 0) {
|
||||||
|
goto oops;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf (" name[]: \"%s\"\n", E.name);
|
||||||
|
printf (" size :%6u\n", E.size);
|
||||||
|
printf (" type : %s\n", type[E.type]);
|
||||||
|
printf (" access: %s\n", access[E.access > 3 ? 0 : E.access]);
|
||||||
|
printf ("----\n");
|
||||||
|
|
||||||
|
if (!go) {
|
||||||
|
switch (cgetc ()) {
|
||||||
|
case 'q':
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
case 'g':
|
||||||
|
go = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf (" size :%6u free.\n", E.size);
|
||||||
|
|
||||||
|
done:
|
||||||
|
/* Close the directory. */
|
||||||
|
cbm_closedir (1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
oops:
|
||||||
|
if (rc <= 6) {
|
||||||
|
printf ("\ndirectory error:\n %s.\n", error[rc]);
|
||||||
|
}
|
||||||
|
cbm_closedir (1);
|
||||||
|
return 1;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user