From 465b85d579f93af9ad41742beda733acf10a594b Mon Sep 17 00:00:00 2001 From: neauoire Date: Sun, 21 Mar 2021 13:52:38 -0700 Subject: [PATCH] About to move the device page --- build.sh | 2 +- emulator.c | 4 ++-- uxn.c | 12 ++++++------ uxn.h | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index 9bc2dea..a65f69a 100755 --- a/build.sh +++ b/build.sh @@ -20,5 +20,5 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wextra -Werr # cc uxn.c emulator.c -std=c89 -Os -DNDEBUG -g0 -s -Wall -Wno-unknown-pragmas -L/usr/local/lib -lSDL2 -o bin/emulator # run -./bin/assembler projects/software/left.usm bin/boot.rom +./bin/assembler projects/software/noodle.usm bin/boot.rom ./bin/emulator bin/boot.rom diff --git a/emulator.c b/emulator.c index 36187d9..74833ac 100644 --- a/emulator.c +++ b/emulator.c @@ -409,7 +409,7 @@ file_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) Uint8 system_poke(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1) { - loadtheme(&m[0xfff8]); + loadtheme(&m[PAGE_DEVICE + 0x00f8]); (void)ptr; (void)b0; return b1; @@ -431,7 +431,7 @@ start(Uxn *u) { int ticknext = 0; evaluxn(u, u->vreset); - loadtheme(u->ram.dat + 0xfff8); + loadtheme(u->ram.dat + PAGE_DEVICE + 0x00f8); if(screen.reqdraw) redraw(pixels, u); while(1) { diff --git a/uxn.c b/uxn.c index 205b7b3..96166f7 100644 --- a/uxn.c +++ b/uxn.c @@ -18,8 +18,8 @@ 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, 0xff00 + id * 0x10, b0, b1) : b1; } -void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = a >= 0xff00 ? devpoke8(u, (a & 0xff) >> 4, a & 0xf, b) : b; } +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; } +void mempoke8(Uxn *u, Uint16 a, Uint8 b) { u->ram.dat[a] = a >= 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); } Uint16 mempeek16(Uxn *u, Uint16 a) { return (mempeek8(u, a) << 8) + mempeek8(u, a + 1); } @@ -212,9 +212,9 @@ loaduxn(Uxn *u, char *filepath) if(!(f = fopen(filepath, "rb"))) return haltuxn(u, "Missing input rom.", 0); fread(u->ram.dat, sizeof(u->ram.dat), 1, f); - u->vreset = mempeek16(u, 0xfff0); - u->vframe = mempeek16(u, 0xfff2); - u->verror = mempeek16(u, 0xfff4); + u->vreset = mempeek16(u, PAGE_DEVICE + 0x00f0); + u->vframe = mempeek16(u, PAGE_DEVICE + 0x00f2); + u->verror = mempeek16(u, PAGE_DEVICE + 0x00f4); printf("Uxn loaded[%s] vrst:%04x vfrm:%04x verr:%04x.\n", filepath, u->vreset, @@ -227,7 +227,7 @@ Device * portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uint8 *m, Uint16 ptr, Uint8 b0, Uint8 b1)) { Device *d = &u->dev[u->devices++]; - d->addr = 0xff00 + (u->devices - 1) * 0x10; + d->addr = PAGE_DEVICE + (u->devices - 1) * 0x10; d->poke = pofn; printf("Device #%d: %s, at 0x%04x \n", u->devices - 1, name, d->addr); return d; diff --git a/uxn.h b/uxn.h index 6b1d35a..778a4f0 100644 --- a/uxn.h +++ b/uxn.h @@ -20,6 +20,7 @@ typedef signed short Sint16; #define FLAG_SHORT 0x02 #define FLAG_RETURN 0x04 #define FLAG_COND 0x08 +#define PAGE_DEVICE 0xff00 typedef struct { Uint8 ptr;