uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 13fd0d9724519dfeba86693d28ad90c32d7c902c
parent 0523bcc06d1eece8bf72941e93be760d9d39ff8d
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun, 26 Dec 2021 20:26:27 -0800

Moved file APIs in device/file

Diffstat:
Msrc/devices/file.c | 29+++++++++++++++++++++++------
Msrc/devices/file.h | 7++-----
Msrc/uxncli.c | 13-------------
Msrc/uxnemu.c | 19+++----------------
4 files changed, 28 insertions(+), 40 deletions(-)

diff --git a/src/devices/file.c b/src/devices/file.c @@ -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; + } +} +\ No newline at end of file diff --git a/src/devices/file.h b/src/devices/file.h @@ -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); +\ No newline at end of file diff --git a/src/uxncli.c b/src/uxncli.c @@ -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) { diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -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) {