uxn

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

commit fa2d290351c48268d4a178e40643c15215e63973
parent 43a0ad26c8b18c21dabb5169f3fc091cd21ed1a2
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Sat, 24 Apr 2021 09:10:24 +0100

Made poke functions return void.

Diffstat:
Msrc/debugger.c | 13++++++-------
Msrc/emulator.c | 32+++++++++++++-------------------
Msrc/uxn.c | 2+-
Msrc/uxn.h | 6+++---
4 files changed, 23 insertions(+), 30 deletions(-)

diff --git a/src/debugger.c b/src/debugger.c @@ -37,7 +37,7 @@ printstack(Stack *s) #pragma mark - Devices -Uint8 +void console_poke(Device *d, Uint8 b0, Uint8 b1) { switch(b0) { @@ -48,10 +48,9 @@ console_poke(Device *d, Uint8 b0, Uint8 b1) fflush(stdout); (void)d; (void)b0; - return b1; } -Uint8 +void file_poke(Device *d, Uint8 b0, Uint8 b1) { Uint8 read = b0 == 0xd; @@ -59,7 +58,7 @@ file_poke(Device *d, Uint8 b0, Uint8 b1) char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)]; Uint16 result = 0, length = mempeek16(d->dat, 0xa); Uint16 offset = mempeek16(d->dat, 0x4); - Uint16 addr = (d->dat[b0 - 1] << 8) | b1; + Uint16 addr = mempeek16(d->dat, b0 - 1); FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w")); if(f) { if(fseek(f, offset, SEEK_SET) != -1 && (result = read ? fread(&d->mem[addr], 1, length, f) : fwrite(&d->mem[addr], 1, length, f))) @@ -68,15 +67,15 @@ file_poke(Device *d, Uint8 b0, Uint8 b1) } mempoke16(d->dat, 0x2, result); } - return b1; + (void)b1; } -Uint8 +void ppnil(Device *d, Uint8 b0, Uint8 b1) { (void)d; (void)b0; - return b1; + (void)b1; } #pragma mark - Generics diff --git a/src/emulator.c b/src/emulator.c @@ -181,17 +181,16 @@ doctrl(Uxn *u, SDL_Event *event, int z) #pragma mark - Devices -Uint8 +void system_poke(Device *d, Uint8 b0, Uint8 b1) { putcolors(&ppu, &d->dat[0x8]); reqdraw = 1; - (void)d; (void)b0; - return b1; + (void)b1; } -Uint8 +void console_poke(Device *d, Uint8 b0, Uint8 b1) { switch(b0) { @@ -201,10 +200,9 @@ console_poke(Device *d, Uint8 b0, Uint8 b1) case 0xd: printf("%s\n", &d->mem[(d->dat[0xc] << 8) + b1]); break; } fflush(stdout); - return b1; } -Uint8 +void screen_poke(Device *d, Uint8 b0, Uint8 b1) { if(b0 == 0xe) { @@ -219,10 +217,9 @@ screen_poke(Device *d, Uint8 b0, Uint8 b1) } reqdraw = 1; } - return b1; } -Uint8 +void file_poke(Device *d, Uint8 b0, Uint8 b1) { Uint8 read = b0 == 0xd; @@ -230,7 +227,7 @@ file_poke(Device *d, Uint8 b0, Uint8 b1) char *name = (char *)&d->mem[mempeek16(d->dat, 0x8)]; Uint16 result = 0, length = mempeek16(d->dat, 0xa); Uint16 offset = mempeek16(d->dat, 0x4); - Uint16 addr = (d->dat[b0 - 1] << 8) | b1; + Uint16 addr = mempeek16(d->dat, b0 - 1); FILE *f = fopen(name, read ? "r" : (offset ? "a" : "w")); if(f) { if(fseek(f, offset, SEEK_SET) != -1 && (result = read ? fread(&d->mem[addr], 1, length, f) : fwrite(&d->mem[addr], 1, length, f))) @@ -239,10 +236,10 @@ file_poke(Device *d, Uint8 b0, Uint8 b1) } mempoke16(d->dat, 0x2, result); } - return b1; + (void)b1; } -static Uint8 +static void audio_poke(Device *d, Uint8 b0, Uint8 b1) { if(b0 == 0xa) { @@ -258,14 +255,12 @@ audio_poke(Device *d, Uint8 b0, Uint8 b1) apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) >> 1; else apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xb) + 0x8000; - apu.queue->dat[apu.queue->n++] = (d->dat[0xd] << 8) + b1; + apu.queue->dat[apu.queue->n++] = mempeek16(d->dat, 0xd); } else if(b0 == 0xf && apu.queue != NULL) apu.queue->finishes = 1; - (void)d; - return b1; } -Uint8 +void datetime_poke(Device *d, Uint8 b0, Uint8 b1) { time_t seconds = time(NULL); @@ -280,17 +275,16 @@ datetime_poke(Device *d, Uint8 b0, Uint8 b1) d->dat[0x7] = t->tm_wday; mempoke16(d->dat, 0x08, t->tm_yday); d->dat[0xa] = t->tm_isdst; - (void)d; (void)b0; - return b1; + (void)b1; } -Uint8 +void ppnil(Device *d, Uint8 b0, Uint8 b1) { (void)d; (void)b0; - return b1; + (void)b1; } #pragma mark - Generics diff --git a/src/uxn.c b/src/uxn.c @@ -179,7 +179,7 @@ loaduxn(Uxn *u, char *filepath) } Device * -portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Device *d, Uint8 b0, Uint8 b1)) +portuxn(Uxn *u, Uint8 id, char *name, void (*pofn)(Device *d, Uint8 b0, Uint8 b1)) { Device *d = &u->dev[id]; d->addr = id * 0x10; diff --git a/src/uxn.h b/src/uxn.h @@ -32,7 +32,7 @@ struct Uxn; typedef struct Device { Uint8 addr, dat[16], *mem; - Uint8 (*poke)(struct Device *d, Uint8, Uint8); + void (*poke)(struct Device *d, Uint8, Uint8); } Device; typedef struct Uxn { @@ -47,4 +47,4 @@ int evaluxn(Uxn *u, Uint16 vec); void mempoke16(Uint8 *m, Uint16 a, Uint16 b); Uint16 mempeek16(Uint8 *m, Uint16 a); -Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Device *, Uint8, Uint8)); -\ No newline at end of file +Device *portuxn(Uxn *u, Uint8 id, char *name, void (*pofn)(Device *, Uint8, Uint8)); +\ No newline at end of file