uxn

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

commit b9a37077c340d57267d6b73f233a8c8674fb3e22
parent 4cd52209ac58201130cf4ffcf93265590bfc08bf
Author: neauoire <aliceffekt@gmail.com>
Date:   Wed,  5 Jan 2022 19:48:51 -0800

Started work on the hypervisor

Diffstat:
Msrc/devices/system.c | 8++++----
Msrc/uxn.c | 10++++++----
Msrc/uxn.h | 4++--
Msrc/uxncli.c | 9+++++----
Msrc/uxnemu.c | 11++++++++---
5 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/devices/system.c b/src/devices/system.c @@ -45,8 +45,8 @@ Uint8 system_dei(Device *d, Uint8 port) { switch(port) { - case 0x2: return d->u->wst.ptr; - case 0x3: return d->u->rst.ptr; + case 0x2: return d->u->wst->ptr; + case 0x3: return d->u->rst->ptr; default: return d->dat[port]; } } @@ -56,8 +56,8 @@ system_deo(Device *d, Uint8 port) { switch(port) { case 0x1: DEVPEEK16(d->vector, 0x0); break; - case 0x2: d->u->wst.ptr = d->dat[port]; break; - case 0x3: d->u->rst.ptr = d->dat[port]; break; + case 0x2: d->u->wst->ptr = d->dat[port]; break; + case 0x3: d->u->rst->ptr = d->dat[port]; break; default: system_deo_special(d, port); } } diff --git a/src/uxn.c b/src/uxn.c @@ -39,13 +39,13 @@ uxn_eval(Uxn *u, Uint16 pc) Stack *src, *dst; Device *dev; if(!pc || u->dev[0].dat[0xf]) return 0; - if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8; + if(u->wst->ptr > 0xf8) u->wst->ptr = 0xf8; while((instr = u->ram[pc++])) { /* Return Mode */ if(instr & 0x40) { - src = &u->rst; dst = &u->wst; + src = u->rst; dst = u->wst; } else { - src = &u->wst; dst = &u->rst; + src = u->wst; dst = u->rst; } /* Keep Mode */ if(instr & 0x80) { @@ -108,12 +108,14 @@ err: /* clang-format on */ int -uxn_boot(Uxn *u, Uint8 *memory) +uxn_boot(Uxn *u, Stack *wst, Stack *rst, Uint8 *memory) { Uint32 i; char *cptr = (char *)u; for(i = 0; i < sizeof(*u); i++) cptr[i] = 0x00; + u->wst = wst; + u->rst = rst; u->ram = memory; return 1; } diff --git a/src/uxn.h b/src/uxn.h @@ -38,12 +38,12 @@ typedef struct Device { } Device; typedef struct Uxn { - Stack wst, rst; + Stack *wst, *rst; Uint8 *ram; Device dev[16]; } Uxn; -int uxn_boot(Uxn *c, Uint8 *memory); +int uxn_boot(Uxn *u, Stack *wst, Stack *rst, Uint8 *memory); int uxn_eval(Uxn *u, Uint16 pc); int uxn_halt(Uxn *u, Uint8 error, Uint16 addr); Device *uxn_port(Uxn *u, Uint8 id, Uint8 (*deifn)(Device *, Uint8), void (*deofn)(Device *, Uint8)); diff --git a/src/uxncli.c b/src/uxncli.c @@ -50,8 +50,8 @@ void system_deo_special(Device *d, Uint8 port) { if(port == 0xe) { - inspect(&d->u->wst, "Working-stack"); - inspect(&d->u->rst, "Return-stack"); + inspect(d->u->wst, "Working-stack"); + inspect(d->u->rst, "Return-stack"); } } @@ -133,7 +133,7 @@ load(Uxn *u, char *filepath) return 1; } -static Uint8 *memory; +static Uint8 *shadow, *memory; int main(int argc, char **argv) @@ -141,8 +141,9 @@ main(int argc, char **argv) Uxn u; int i, loaded = 0; + shadow = (Uint8 *)calloc(0xffff, sizeof(Uint8)); memory = (Uint8 *)calloc(0xffff, sizeof(Uint8)); - if(!uxn_boot(&u, memory)) + if(!uxn_boot(&u, (Stack *)(shadow + 0x200), (Stack *)(shadow + 0x400), memory)) return error("Boot", "Failed"); /* system */ devsystem = uxn_port(&u, 0x0, system_dei, system_deo); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -44,6 +44,7 @@ static SDL_Rect gRect; static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; static Uint8 zoom = 1; static Uint32 stdin_event, audio0_event; +static Uxn hypervisor; static int clamp(int val, int min, int max) @@ -126,7 +127,7 @@ static void redraw(Uxn *u) { if(devsystem->dat[0xe]) - screen_debug(&uxn_screen, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram); + screen_debug(&uxn_screen, u->wst->dat, u->wst->ptr, u->rst->ptr, u->ram); screen_redraw(&uxn_screen, uxn_screen.pixels); if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0) error("SDL_UpdateTexture", SDL_GetError()); @@ -272,13 +273,17 @@ load(Uxn *u, char *rom) return 1; } -static Uint8 *memory; +static Uint8 *shadow, *memory; static int start(Uxn *u, char *rom) { memory = (Uint8 *)calloc(0xffff, sizeof(Uint8)); - if(!uxn_boot(u, memory)) + shadow = (Uint8 *)calloc(0xffff, sizeof(Uint8)); + + if(!uxn_boot(&hypervisor, (Stack *)(shadow + 0x600), (Stack *)(shadow + 0x800), shadow)) + return error("Boot", "Failed to start uxn."); + if(!uxn_boot(u, (Stack *)(shadow + 0x200), (Stack *)(shadow + 0x400), memory)) return error("Boot", "Failed to start uxn."); if(!load(u, rom)) return error("Boot", "Failed to load rom.");