Moved file APIs in device/file

This commit is contained in:
neauoire 2021-12-26 20:26:27 -08:00
parent 0523bcc06d
commit 13fd0d9724
4 changed files with 26 additions and 40 deletions

View File

@ -24,11 +24,12 @@ WITH REGARD TO THIS SOFTWARE.
static FILE *f;
static DIR *d;
static char *current_filename = "";
static struct dirent *de;
static enum { IDLE,
FILE_READ,
FILE_WRITE,
DIR_READ } state;
static struct dirent *de;
static void
reset(void)
@ -80,7 +81,7 @@ file_read_dir(char *dest, Uint16 len)
return p - dest;
}
Uint16
static Uint16
file_init(void *filename)
{
reset();
@ -88,7 +89,7 @@ file_init(void *filename)
return 0;
}
Uint16
static Uint16
file_read(void *dest, Uint16 len)
{
if(state != FILE_READ && state != DIR_READ) {
@ -105,7 +106,7 @@ file_read(void *dest, Uint16 len)
return 0;
}
Uint16
static Uint16
file_write(void *src, Uint16 len, Uint8 flags)
{
Uint16 ret = 0;
@ -121,7 +122,7 @@ file_write(void *src, Uint16 len, Uint8 flags)
return ret;
}
Uint16
static Uint16
file_stat(void *dest, Uint16 len)
{
char *basename = strrchr(current_filename, '/');
@ -132,8 +133,23 @@ file_stat(void *dest, Uint16 len)
return get_entry(dest, len, current_filename, basename, 0);
}
Uint16
static Uint16
file_delete(void)
{
return unlink(current_filename);
}
/* API */
void
file_deo(Device *d, Uint8 port)
{
switch(port) {
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

@ -10,8 +10,4 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
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);
Uint16 file_delete(void);
void file_deo(Device *d, Uint8 port);

View File

@ -76,19 +76,6 @@ console_deo(Device *d, Uint8 port)
write(port - 0x7, (char *)&d->dat[port], 1);
}
static void
file_deo(Device *d, Uint8 port)
{
switch(port) {
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;
}
}
static Uint8
datetime_dei(Device *d, Uint8 port)
{

View File

@ -291,27 +291,14 @@ screen_deo(Device *d, Uint8 port)
Uint8 *addr = &d->mem[peek16(d->dat, 0xc)];
Uint8 twobpp = !!(d->dat[0xf] & 0x80);
ppu_blit(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp);
if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp*8); /* auto addr+8 / auto addr+16 */
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8); /* auto x+8 */
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8); /* auto y+8 */
if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp * 8); /* auto addr+8 / auto addr+16 */
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8); /* auto x+8 */
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8); /* auto y+8 */
break;
}
}
}
static void
file_deo(Device *d, Uint8 port)
{
switch(port) {
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;
}
}
static Uint8
audio_dei(Device *d, Uint8 port)
{