]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Use dos.library directly to read directory
authorToni Wilen <twilen@winuae.net>
Tue, 4 Jul 2023 19:07:36 +0000 (22:07 +0300)
committerToni Wilen <twilen@winuae.net>
Tue, 4 Jul 2023 19:07:36 +0000 (22:07 +0300)
cputest/cputestgen.ini
cputest/dir.c [new file with mode: 0644]
cputest/main.c
cputest/makefile
cputest/makefile.st

index 3af7dcda45170b500c539b6069f9a433e4e28f69..c96802420e0eb247ac52ad2ab982791f62c25557 100644 (file)
@@ -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 (file)
index 0000000..052da4b
--- /dev/null
@@ -0,0 +1,97 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <memory.h>
+#include <string.h>
+#include <ctype.h>
+#include <math.h>
+#include <sys/stat.h>
+
+#ifdef _MSC_VER
+#include "msc_dirent.h"
+#else
+#include <dirent.h>
+#endif
+
+#ifdef AMIGA
+
+// Uses dos.library directly because -mcrt=nix13 directory routines
+// are not reliable at least when using FAT95
+
+#include <proto/exec.h>
+#include <proto/dos.h>
+#include <dos/dos.h>
+
+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
+}
index 76c60cbce878fdfba9282169d37240c6bca91908..0c9e01f34144962384dd48e36df6023721564e27 100644 (file)
@@ -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;
 }
index 7f2fc87c0241578aeffbc1396ed38aff289c5007..cfd5491a6c1428d52ef1b9d2eb4e60ad507396ba 100644 (file)
@@ -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
 
index badf5ab84387a4ac7b8125ad450cf82796dcde4e..788d3a9239772bd5d182ea01a148ad4608932e3b 100644 (file)
@@ -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