From: Toni Wilen Date: Tue, 4 Jul 2023 19:07:36 +0000 (+0300) Subject: Use dos.library directly to read directory X-Git-Tag: 5.1.0~166 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=af1a4f3ee65fa7ec7944a2ae62079724891570c8;p=francis%2Fwinuae.git Use dos.library directly to read directory --- diff --git a/cputest/cputestgen.ini b/cputest/cputestgen.ini index 3af7dcda..c9680242 100644 --- a/cputest/cputestgen.ini +++ b/cputest/cputestgen.ini @@ -1,7 +1,7 @@ [cputest] ; CPU model (68000, 68020, 68030, 68040 or 68060). -cpu=68040 +cpu=68000 ; CPU address space. ; If 24-bit, tester will assume upper 8-bits of addresses gets ignored. @@ -250,10 +250,23 @@ feature_sr_mask=0x8000 feature_undefined_ccr=1 mode=all +; interrupt timing test +[test=IPL] +cpu=68000-68010 +enabled=1 +verbose=0 +feature_undefined_ccr=1 +feature_interrupts=2 +feature_sr_mask=0x2000 +#feature_addressing_modes_dst=apdi +feature_condition_codes=pl +rnd_seed=11 +mode=all + ; interrupt timing test with waitstates [test=WIPL] cpu=68000-68010 -enabled=1 +enabled=0 verbose=0 feature_undefined_ccr=1 feature_interrupts=2 @@ -266,20 +279,8 @@ test_memory_size=0x20000 rnd_seed=10 mode=btst.b -; interrupt timing test -[test=IPL] -cpu=68000-68010 -enabled=1 -verbose=0 -feature_undefined_ccr=1 -feature_interrupts=2 -feature_sr_mask=0x2000 -#feature_addressing_modes_dst=apdi -feature_condition_codes=pl -rnd_seed=10 -mode=btst.b - ; STOP/SR modification timing special test +; (not -cycles compatible) [test=SR] cpu=68000-68010 enabled=0 @@ -292,6 +293,7 @@ feature_sr_mask=0x8000 mode=stop ; interrupt exception +; (not -cycles compatible) [test=IRQ] enabled=0 verbose=0 diff --git a/cputest/dir.c b/cputest/dir.c new file mode 100644 index 00000000..052da4b7 --- /dev/null +++ b/cputest/dir.c @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _MSC_VER +#include "msc_dirent.h" +#else +#include +#endif + +#ifdef AMIGA + +// Uses dos.library directly because -mcrt=nix13 directory routines +// are not reliable at least when using FAT95 + +#include +#include +#include + +struct DosLibrary *DOSBase; + +struct DirInfo +{ + BPTR lock; + struct FileInfoBlock fib; +}; + +#else + +static char tmpbuffer[256]; +static int isdir(const char *dirpath, const char *name) +{ + struct stat buf; + + snprintf(tmpbuffer, sizeof(tmpbuffer), "%s%s", dirpath, name); + return stat(tmpbuffer, &buf) == 0 && S_ISDIR(buf.st_mode); +} + +#endif + +void *x_opendir(char *path) +{ +#ifdef AMIGA + struct DirInfo *di = AllocMem(sizeof(struct DirInfo), MEMF_CLEAR | MEMF_PUBLIC); + if (!di) { + return NULL; + } + di->lock = Lock(path, SHARED_LOCK); + if (!di->lock) { + FreeMem(di, sizeof(struct DirInfo)); + return NULL; + } + if (!Examine(di->lock, &di->fib)) { + FreeMem(di, sizeof(struct DirInfo)); + return NULL; + } + return (void*)di; +#else + return opendir(path); +#endif +} + +void x_closedir(void *v) +{ +#ifdef AMIGA + struct DirInfo *di = (struct DirInfo*)v; + if (di) { + UnLock(di->lock); + FreeMem(di, sizeof(struct DirInfo)); + } +#else + closedir((DIR*)v); +#endif +} + +int x_readdir(char *path, void *v, char *s) +{ +#ifdef AMIGA + struct DirInfo *di = (struct DirInfo*)v; + if (!ExNext(di->lock, &di->fib)) { + return 0; + } + strcpy(s, di->fib.fib_FileName); + return di->fib.fib_DirEntryType < 0 ? 1 : - 1; +#else + struct dirent *d = readdir((DIR*)v); + if (!d) + return 0; + strcpy(s, d->d_name); + return isdir(path, s) ? -1 : 1; +#endif +} diff --git a/cputest/main.c b/cputest/main.c index 76c60cbc..0c9e01f3 100644 --- a/cputest/main.c +++ b/cputest/main.c @@ -186,6 +186,10 @@ static int ipl_pc_cnt[MAX_IPL_PC_VALUES]; static char opcode[32], group[32], cpustr[10]; +void *x_opendir(char *path); +void x_closedir(void *v); +int x_readdir(char *path, void *v, char *s); + #ifndef M68K #define xmemcpy memcpy @@ -3867,14 +3871,6 @@ static int getparamval(const char *p) } } -static int isdir(const char *dirpath, const char *name) -{ - struct stat buf; - - snprintf(tmpbuffer, sizeof(tmpbuffer), "%s%s", dirpath, name); - return stat(tmpbuffer, &buf) == 0 && S_ISDIR(buf.st_mode); -} - int main(int argc, char *argv[]) { int stop_on_error = 1; @@ -4098,7 +4094,7 @@ int main(int argc, char *argv[]) } } - DIR *groupd = NULL; + void *groupd = NULL; char *p = strchr(opcode, '/'); if (p) { @@ -4109,7 +4105,7 @@ int main(int argc, char *argv[]) } if (!strcmp(group, "all")) { - groupd = opendir(path); + groupd = x_opendir(path); } int cpumodel = cpu_lvl == 5 ? 6 : cpu_lvl; @@ -4120,17 +4116,18 @@ int main(int argc, char *argv[]) if (groupd) { pathptr[0] = 0; - struct dirent *groupdr = readdir(groupd); + char dname[256]; + int groupdr = x_readdir(path, groupd, dname); if (!groupdr) break; - if (!isdir(path, groupdr->d_name)) + if (groupdr > 0) continue; - if (groupdr->d_name[0] == '.') + if (dname[0] == '.') continue; - if (strnicmp(cpustr, groupdr->d_name, strlen(cpustr))) + if (strnicmp(cpustr, dname, strlen(cpustr))) continue; - sprintf(pathptr, "%s/", groupdr->d_name); - strcpy(group, groupdr->d_name + strlen(cpustr)); + sprintf(pathptr, "%s/", dname); + strcpy(group, dname + strlen(cpustr)); } else { sprintf(pathptr, "%u_%s/",cpumodel, group); } @@ -4168,7 +4165,7 @@ int main(int argc, char *argv[]) } if (!_stricmp(opcode, "all") || (opcode[0] && opcode[strlen(opcode) - 1] == '*')) { - DIR *d = opendir(path); + void *d = x_opendir(path); if (!d) { printf("Couldn't list directory '%s'\n", path); return 0; @@ -4183,12 +4180,10 @@ int main(int argc, char *argv[]) // get directory for (;;) { - struct dirent *dr = readdir(d); + int dr = x_readdir(path, d, dirs + diroff); if (!dr) break; - int d = isdir(path, dr->d_name); - if (d && dr->d_name[0] != '.') { - strcpy(dirs + diroff, dr->d_name); + if (dr < 0 && dirs[diroff] != '.') { dircnt++; diroff += MAX_FILE_LEN; if (dircnt >= MAX_FILES) { @@ -4197,7 +4192,7 @@ int main(int argc, char *argv[]) } } } - closedir(d); + x_closedir(d); // sort directory for (int i = 0; i < diroff; i += MAX_FILE_LEN) { @@ -4272,7 +4267,7 @@ int main(int argc, char *argv[]) } if (groupd) - closedir(groupd); + x_closedir(groupd); return 0; } diff --git a/cputest/makefile b/cputest/makefile index 7f2fc87c..cfd5491a 100644 --- a/cputest/makefile +++ b/cputest/makefile @@ -8,7 +8,7 @@ AS=/opt/amiga/bin/m68k-amigaos-as CFLAGS = -mcrt=nix13 -O2 -m68000 -fomit-frame-pointer -msoft-float -DREVDATE=$(NOWDATE) -DREVTIME=$(NOWTIME) -DAMIGA -DM68K LINK_CFLAGS = -mcrt=nix13 -lm -s -OBJS = main.o asm040.o asm060.o amiga.o \ +OBJS = main.o dir.o asm040.o asm060.o amiga.o \ decode_ea.o globals.o opcode_handler_cpu.o opcode_handler_fpu.o \ opcode_handler_mmu.o opcodes_cpu.o opcodes_fpu.o opcodes_mmu.o util.o \ inflate.o @@ -19,6 +19,9 @@ all: $(OBJS) main.o: main.c $(CC) $(CFLAGS) -I. -c -o $@ main.c +dir.o: dir.c + $(CC) $(CFLAGS) -I. -c -o $@ dir.c + decode_ea.o: adis/decode_ea.c $(CC) $(CFLAGS) -I. -c -o $@ adis/decode_ea.c diff --git a/cputest/makefile.st b/cputest/makefile.st index badf5ab8..788d3a92 100644 --- a/cputest/makefile.st +++ b/cputest/makefile.st @@ -8,7 +8,7 @@ AS=/opt/m68k-atari/bin/m68k-atari-mint-as CFLAGS = -O2 -m68000 -fomit-frame-pointer -msoft-float -DREVDATE=$(NOWDATE) -DREVTIME=$(NOWTIME) -DM68K -DWAITEXIT LINK_CFLAGS = -lm -s -OBJS = main.o asm040.o asm060.o atari.o \ +OBJS = main.o dir.o asm040.o asm060.o atari.o \ decode_ea.o globals.o opcode_handler_cpu.o opcode_handler_fpu.o \ opcode_handler_mmu.o opcodes_cpu.o opcodes_fpu.o opcodes_mmu.o util.o \ inflate.o @@ -19,6 +19,9 @@ all: $(OBJS) main.o: main.c $(CC) $(CFLAGS) -I. -c -o $@ main.c +dir.o: dir.c + $(CC) $(CFLAGS) -I. -c -o $@ dir.c + decode_ea.o: adis/decode_ea.c $(CC) $(CFLAGS) -I. -c -o $@ adis/decode_ea.c