Renamed prepare for init
This commit is contained in:
parent
db0efaeff1
commit
dee04ff44a
|
@ -48,13 +48,6 @@ reset(void)
|
||||||
state = IDLE;
|
state = IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
file_prepare(void *filename)
|
|
||||||
{
|
|
||||||
reset();
|
|
||||||
current_filename = (char *)filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Uint16
|
static Uint16
|
||||||
get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int fail_nonzero)
|
get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int fail_nonzero)
|
||||||
{
|
{
|
||||||
|
@ -76,19 +69,9 @@ get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int f
|
||||||
return strlen(p);
|
return strlen(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
Uint16
|
static Uint16
|
||||||
file_read(void *dest, Uint16 len)
|
file_read_dir(void *dest, Uint16 len)
|
||||||
{
|
{
|
||||||
if(state != FILE_READ && state != DIR_READ) {
|
|
||||||
reset();
|
|
||||||
if((d = opendir(current_filename)) != NULL)
|
|
||||||
state = DIR_READ;
|
|
||||||
else if((f = fopen(current_filename, "rb")) != NULL)
|
|
||||||
state = FILE_READ;
|
|
||||||
}
|
|
||||||
if(state == FILE_READ)
|
|
||||||
return fread(dest, 1, len, f);
|
|
||||||
if(state == DIR_READ) {
|
|
||||||
static char pathname[PATH_MAX];
|
static char pathname[PATH_MAX];
|
||||||
char *p = dest;
|
char *p = dest;
|
||||||
if(de == NULL) de = readdir(d);
|
if(de == NULL) de = readdir(d);
|
||||||
|
@ -105,7 +88,30 @@ file_read(void *dest, Uint16 len)
|
||||||
len -= n;
|
len -= n;
|
||||||
}
|
}
|
||||||
return p - (char *)dest;
|
return p - (char *)dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16
|
||||||
|
file_init(void *filename)
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
current_filename = (char *)filename;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint16
|
||||||
|
file_read(void *dest, Uint16 len)
|
||||||
|
{
|
||||||
|
if(state != FILE_READ && state != DIR_READ) {
|
||||||
|
reset();
|
||||||
|
if((d = opendir(current_filename)) != NULL)
|
||||||
|
state = DIR_READ;
|
||||||
|
else if((f = fopen(current_filename, "rb")) != NULL)
|
||||||
|
state = FILE_READ;
|
||||||
}
|
}
|
||||||
|
if(state == FILE_READ)
|
||||||
|
return fread(dest, 1, len, f);
|
||||||
|
if(state == DIR_READ)
|
||||||
|
return file_read_dir(dest, len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
WITH REGARD TO THIS SOFTWARE.
|
WITH REGARD TO THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void file_prepare(void *filename);
|
Uint16 file_init(void *filename);
|
||||||
Uint16 file_read(void *dest, Uint16 len);
|
Uint16 file_read(void *dest, Uint16 len);
|
||||||
Uint16 file_write(void *src, Uint16 len, Uint8 flags);
|
Uint16 file_write(void *src, Uint16 len, Uint8 flags);
|
||||||
Uint16 file_stat(void *dest, Uint16 len);
|
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)
|
file_deo(Device *d, Uint8 port)
|
||||||
{
|
{
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x1:
|
case 0x1: d->vector = peek16(d->dat, 0x0); break;
|
||||||
d->vector = peek16(d->dat, 0x0);
|
case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break;
|
||||||
break;
|
case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break;
|
||||||
case 0x9:
|
case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break;
|
||||||
file_prepare(&d->mem[peek16(d->dat, 0x8)]);
|
case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break;
|
||||||
break;
|
case 0x6: poke16(d->dat, 0x2, file_delete()); 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)
|
file_deo(Device *d, Uint8 port)
|
||||||
{
|
{
|
||||||
switch(port) {
|
switch(port) {
|
||||||
case 0x1:
|
case 0x1: d->vector = peek16(d->dat, 0x0); break;
|
||||||
d->vector = peek16(d->dat, 0x0);
|
case 0x9: poke16(d->dat, 0x2, file_init(&d->mem[peek16(d->dat, 0x8)])); break;
|
||||||
break;
|
case 0xd: poke16(d->dat, 0x2, file_read(&d->mem[peek16(d->dat, 0xc)], peek16(d->dat, 0xa))); break;
|
||||||
case 0x9:
|
case 0xf: poke16(d->dat, 0x2, file_write(&d->mem[peek16(d->dat, 0xe)], peek16(d->dat, 0xa), d->dat[0x7])); break;
|
||||||
file_prepare(&d->mem[peek16(d->dat, 0x8)]);
|
case 0x5: poke16(d->dat, 0x2, file_stat(&d->mem[peek16(d->dat, 0x4)], peek16(d->dat, 0xa))); break;
|
||||||
break;
|
case 0x6: poke16(d->dat, 0x2, file_delete()); 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 New Issue