commit dee04ff44ae2c3f4e24fa2e4d3fe59be5dec5754
parent db0efaeff1a3170cb89aef4107e902c3c0123a9c
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date: Sun, 7 Nov 2021 10:30:56 -0500
Renamed prepare for init
Diffstat:
4 files changed, 44 insertions(+), 62 deletions(-)
diff --git a/src/devices/file.c b/src/devices/file.c
@@ -48,13 +48,6 @@ reset(void)
state = IDLE;
}
-void
-file_prepare(void *filename)
-{
- reset();
- current_filename = (char *)filename;
-}
-
static Uint16
get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int fail_nonzero)
{
@@ -76,6 +69,35 @@ get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int f
return strlen(p);
}
+static Uint16
+file_read_dir(void *dest, Uint16 len)
+{
+ static char pathname[PATH_MAX];
+ char *p = dest;
+ if(de == NULL) de = readdir(d);
+ for(; de != NULL; de = readdir(d)) {
+ Uint16 n;
+ if(de->d_name[0] == '.' && de->d_name[1] == '\0')
+ continue;
+ strncpy(pathname, current_filename, sizeof(pathname) - 1);
+ strncat(pathname, "/", sizeof(pathname) - 1);
+ strncat(pathname, de->d_name, sizeof(pathname) - 1);
+ n = get_entry(p, len, pathname, de->d_name, 1);
+ if(!n) break;
+ p += n;
+ len -= n;
+ }
+ return p - (char *)dest;
+}
+
+Uint16
+file_init(void *filename)
+{
+ reset();
+ current_filename = (char *)filename;
+ return 0;
+}
+
Uint16
file_read(void *dest, Uint16 len)
{
@@ -88,24 +110,8 @@ file_read(void *dest, Uint16 len)
}
if(state == FILE_READ)
return fread(dest, 1, len, f);
- if(state == DIR_READ) {
- static char pathname[PATH_MAX];
- char *p = dest;
- if(de == NULL) de = readdir(d);
- for(; de != NULL; de = readdir(d)) {
- Uint16 n;
- if(de->d_name[0] == '.' && de->d_name[1] == '\0')
- continue;
- strncpy(pathname, current_filename, sizeof(pathname) - 1);
- strncat(pathname, "/", sizeof(pathname) - 1);
- strncat(pathname, de->d_name, sizeof(pathname) - 1);
- n = get_entry(p, len, pathname, de->d_name, 1);
- if(!n) break;
- p += n;
- len -= n;
- }
- return p - (char *)dest;
- }
+ if(state == DIR_READ)
+ return file_read_dir(dest, len);
return 0;
}
diff --git a/src/devices/file.h b/src/devices/file.h
@@ -10,7 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
-void file_prepare(void *filename);
+Uint16 file_init(void *filename);
Uint16 file_read(void *dest, Uint16 len);
Uint16 file_write(void *src, Uint16 len, Uint8 flags);
Uint16 file_stat(void *dest, Uint16 len);
diff --git a/src/uxncli.c b/src/uxncli.c
@@ -80,24 +80,12 @@ static void
file_deo(Device *d, Uint8 port)
{
switch(port) {
- case 0x1:
- d->vector = peek16(d->dat, 0x0);
- break;
- case 0x9:
- file_prepare(&d->mem[peek16(d->dat, 0x8)]);
- break;
- case 0xd:
- poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa)));
- break;
- case 0xf:
- poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7]));
- break;
- case 0x5:
- poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa)));
- break;
- case 0x6:
- poke16(d->dat, 0x2, file_delete());
- break;
+ case 0x1: d->vector = peek16(d->dat, 0x0); break;
+ case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break;
+ case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break;
+ case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break;
+ case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break;
+ case 0x6: poke16(d->dat, 0x2, file_delete()); break;
}
}
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -372,24 +372,12 @@ static void
file_deo(Device *d, Uint8 port)
{
switch(port) {
- case 0x1:
- d->vector = peek16(d->dat, 0x0);
- break;
- case 0x9:
- file_prepare(&d->mem[peek16(d->dat, 0x8)]);
- break;
- case 0xd:
- poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa)));
- break;
- case 0xf:
- poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7]));
- break;
- case 0x5:
- poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa)));
- break;
- case 0x6:
- poke16(d->dat, 0x2, file_delete());
- break;
+ case 0x1: d->vector = peek16(d->dat, 0x0); break;
+ case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break;
+ case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break;
+ case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break;
+ case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break;
+ case 0x6: poke16(d->dat, 0x2, file_delete()); break;
}
}