uxn

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

commit 52eb7f11af2f3202e1278d01fc10372b29d2f611
parent ecc50fd9f22bce6675f877be908d5dbe02f61d9e
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Mon, 22 Mar 2021 21:22:06 +0000

Pass Uxn *u to poke routines instead of Uint8 *m.

Diffstat:
Memulator.c | 19++++++++++++-------
Muxn.c | 4++--
Muxn.h | 8+++++---
3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/emulator.c b/emulator.c @@ -339,8 +339,9 @@ doctrl(Uxn *u, SDL_Event *event, int z) #pragma mark - Devices Uint8 -console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) +console_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) { + Uint8 *m = u->ram.dat; switch(b0) { case 0x08: printf("%c", b1); break; case 0x09: printf("0x%02x\n", b1); break; @@ -354,8 +355,9 @@ console_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) } Uint8 -screen_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) +screen_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) { + Uint8 *m = u->ram.dat; ptr += 8; if(b0 == 0x0c) { Uint16 x = (m[ptr] << 8) + m[ptr + 1]; @@ -367,8 +369,9 @@ screen_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) } Uint8 -sprite_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) +sprite_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) { + Uint8 *m = u->ram.dat; ptr += 8; if(b0 == 0x0e) { Uint16 x = (m[ptr] << 8) + m[ptr + 1]; @@ -386,8 +389,9 @@ sprite_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) } Uint8 -file_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) +file_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) { + Uint8 *m = u->ram.dat; char *name = (char *)&m[(m[ptr + 8] << 8) + m[ptr + 8 + 1]]; Uint16 length = (m[ptr + 8 + 2] << 8) + m[ptr + 8 + 3]; if(b0 == 0x0d) { @@ -409,8 +413,9 @@ file_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) } Uint8 -system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) +system_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) { + Uint8 *m = u->ram.dat; loadtheme(&m[PAGE_DEVICE + 0x00f8]); (void)ptr; (void)b0; @@ -418,9 +423,9 @@ system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) } Uint8 -ppnil(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) +ppnil(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) { - (void)m; + (void)u; (void)ptr; (void)b0; return b1; diff --git a/uxn.c b/uxn.c @@ -18,7 +18,7 @@ WITH REGARD TO THIS SOFTWARE. /* clang-format off */ void setflag(Uint8 *a, char flag, int b) { if(b) *a |= flag; else *a &= (~flag); } int getflag(Uint8 *a, char flag) { return *a & flag; } -Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < u->devices ? u->dev[id].poke(u->ram.dat, PAGE_DEVICE + id * 0x10, b0, b1) : b1; } +Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < u->devices ? u->dev[id].poke(u, PAGE_DEVICE + id * 0x10, b0, b1) : b1; } void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = (a & 0xff00) == PAGE_DEVICE ? devpoke8(u, (a & 0xff) >> 4, a & 0xf, b) : b; } Uint8 mempeek8(Uxn *u, Uint16 a) { return u->ram.dat[a]; } void mempoke16(Uxn *u, Uint16 a, Uint16 b) { mempoke8(u, a, b >> 8); mempoke8(u, a + 1, b); } @@ -224,7 +224,7 @@ loaduxn(Uxn *u, char *filepath) } Device * -portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)) +portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)) { Device *d = &u->dev[u->devices++]; d->addr = PAGE_DEVICE + (u->devices - 1) * 0x10; diff --git a/uxn.h b/uxn.h @@ -32,12 +32,14 @@ typedef struct { Uint8 dat[65536]; } Memory; +struct Uxn; + typedef struct Device { Uint16 addr; - Uint8 (*poke)(Uint8 *, Uint16, Uint8, Uint8); + Uint8 (*poke)(struct Uxn *, Uint16, Uint8, Uint8); } Device; -typedef struct { +typedef struct Uxn { Uint8 literal, status, devices; Uint16 counter, vreset, vframe, verror; Stack wst, rst, *src, *dst; @@ -50,4 +52,4 @@ int getflag(Uint8 *status, char flag); int loaduxn(Uxn *c, char *filepath); int bootuxn(Uxn *c); int evaluxn(Uxn *u, Uint16 vec); -Device *portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uint8 *, Uint16, Uint8, Uint8)); +Device *portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8));