uxn

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

commit e791dbd640dc106c369b2ef575359371bc331f77
parent edd7abdca54f0c9f7b3710f5e90818ecb5b32e82
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun,  4 Apr 2021 08:34:18 -0700

Removed old devices and counters bytes

Diffstat:
Msrc/emulator.c | 32++++++++++++++++----------------
Msrc/uxn.c | 13++++++-------
Msrc/uxn.h | 5++---
3 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/src/emulator.c b/src/emulator.c @@ -612,22 +612,22 @@ main(int argc, char **argv) if(!init()) return error("Init", "Failed"); - portuxn(&u, "console", console_poke); - devscreen = portuxn(&u, "screen", screen_poke); - portuxn(&u, "sprite", sprite_poke); - devctrl = portuxn(&u, "controller", ppnil); - devkey = portuxn(&u, "key", ppnil); - devmouse = portuxn(&u, "mouse", ppnil); - portuxn(&u, "file", file_poke); - devaudio = portuxn(&u, "audio", audio_poke); - portuxn(&u, "midi", ppnil); - portuxn(&u, "datetime", datetime_poke); - portuxn(&u, "---", ppnil); - portuxn(&u, "---", ppnil); - portuxn(&u, "---", ppnil); - portuxn(&u, "---", ppnil); - portuxn(&u, "---", ppnil); - portuxn(&u, "system", system_poke); + portuxn(&u, 0x00, "console", console_poke); + devscreen = portuxn(&u, 0x01, "screen", screen_poke); + portuxn(&u, 0x02, "sprite", sprite_poke); + devctrl = portuxn(&u, 0x03, "controller", ppnil); + devkey = portuxn(&u, 0x04, "key", ppnil); + devmouse = portuxn(&u, 0x05, "mouse", ppnil); + portuxn(&u, 0x06, "file", file_poke); + devaudio = portuxn(&u, 0x07, "audio", audio_poke); + portuxn(&u, 0x08, "midi", ppnil); + portuxn(&u, 0x09, "datetime", datetime_poke); + portuxn(&u, 0x0a, "---", ppnil); + portuxn(&u, 0x0b, "---", ppnil); + portuxn(&u, 0x0c, "---", ppnil); + portuxn(&u, 0x0d, "---", ppnil); + portuxn(&u, 0x0e, "---", ppnil); + portuxn(&u, 0x0f, "system", system_poke); /* Write screen size to dev/screen */ u.ram.dat[devscreen->addr + 0] = (HOR * 8 >> 8) & 0xff; diff --git a/src/uxn.c b/src/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, PAGE_DEVICE + id * 0x10, b0, b1) : b1; } +Uint8 devpoke8(Uxn *u, Uint8 id, Uint8 b0, Uint8 b1){ return id < 0x10 ? u->dev[id].poke(u, PAGE_DEVICE + id * 0x10, b0, b1) : b1; } void push8(Stack *s, Uint8 a) { if (s->ptr == 0xff) { s->error = 2; return; } s->dat[s->ptr++] = a; } Uint8 pop8(Stack *s) { if (s->ptr == 0) { s->error = 1; return 0; } return s->dat[--s->ptr]; } @@ -118,7 +118,7 @@ void (*ops[])(Uxn *u) = { int haltuxn(Uxn *u, char *name, int id) { - printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->counter); + printf("Halted: %s#%04x, at 0x%04x\n", name, id, u->ram.ptr); return 0; } @@ -164,7 +164,6 @@ evaluxn(Uxn *u, Uint16 vec) Uint8 instr = u->ram.dat[u->ram.ptr++]; if(!stepuxn(u, instr)) return 0; - u->counter++; } return 1; } @@ -191,11 +190,11 @@ loaduxn(Uxn *u, char *filepath) } Device * -portuxn(Uxn *u, char *name, Uint8 (*pofn)(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1)) +portuxn(Uxn *u, Uint8 id, 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; + Device *d = &u->dev[id]; + d->addr = PAGE_DEVICE + id * 0x10; d->poke = pofn; - printf("Device #%d: %s, at 0x%04x \n", u->devices - 1, name, d->addr); + printf("Device #%d: %s, at 0x%04x \n", id - 1, name, d->addr); return d; } diff --git a/src/uxn.h b/src/uxn.h @@ -38,8 +38,7 @@ typedef struct Device { } Device; typedef struct Uxn { - Uint8 literal, status, devices; - Uint16 counter; + Uint8 literal, status; Stack wst, rst, *src, *dst; Memory ram; Device dev[16]; @@ -50,4 +49,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)(Uxn *, Uint16, Uint8, Uint8)); +Device *portuxn(Uxn *u, Uint8 id, char *name, Uint8 (*pofn)(Uxn *, Uint16, Uint8, Uint8));