mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-23 14:25:10 +00:00
Renamed prepare for init
This commit is contained in:
parent
db0efaeff1
commit
dee04ff44a
4 changed files with 44 additions and 62 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
24
src/uxncli.c
24
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
24
src/uxnemu.c
24
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue