Renamed prepare for init

This commit is contained in:
Devine Lu Linvega 2021-11-07 10:30:56 -05:00
parent db0efaeff1
commit dee04ff44a
4 changed files with 44 additions and 62 deletions

View File

@ -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,19 +69,9 @@ get_entry(char *p, Uint16 len, const char *pathname, const char *basename, int f
return strlen(p);
}
Uint16
file_read(void *dest, Uint16 len)
static Uint16
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];
char *p = dest;
if(de == NULL) de = readdir(d);
@ -105,7 +88,30 @@ file_read(void *dest, Uint16 len)
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)
{
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;
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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;
}
}