uxn

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

commit d111146eb6a2cdc6f62397b4f0710fb5842c0b31
parent 2ea0425c477c1d2cf6810f29c1cfeccff966ce70
Author: neauoire <aliceffekt@gmail.com>
Date:   Sun, 15 Aug 2021 17:48:15 -0700

Stack pointers can be written

Diffstat:
Msrc/uxncli.c | 54+++++++++++++++++++++++++++++++++---------------------
Msrc/uxnemu.c | 50+++++++++++++++++++++++++++++++-------------------
2 files changed, 64 insertions(+), 40 deletions(-)

diff --git a/src/uxncli.c b/src/uxncli.c @@ -26,28 +26,39 @@ error(char *msg, const char *err) return 0; } +static void +inspect(Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) +{ + Uint8 x, y; + fprintf(stderr, "\n\n"); + for(y = 0; y < 0x08; ++y) { + for(x = 0; x < 0x08; ++x) { + Uint8 p = y * 0x08 + x; + fprintf(stderr, + p == wptr ? "[%02x]" : " %02x ", + stack[p]); + } + fprintf(stderr, "\n"); + } +} + #pragma mark - Devices static void system_talk(Device *d, Uint8 b0, Uint8 w) { - if(!w) { - d->dat[0x2] = d->u->wst.ptr; - d->dat[0x3] = d->u->rst.ptr; - } else if(b0 == 0xe) { - Uint8 x, y; - fprintf(stderr, "\n\n"); - for(y = 0; y < 0x08; ++y) { - for(x = 0; x < 0x08; ++x) { - Uint8 p = y * 0x08 + x; - fprintf(stderr, - p == d->u->wst.ptr ? "[%02x]" : " %02x ", - d->u->wst.dat[p]); - } - fprintf(stderr, "\n"); + if(!w) { /* read */ + switch(b0) { + case 0x2: d->dat[0x2] = d->u->wst.ptr; break; + case 0x3: d->dat[0x3] = d->u->rst.ptr; break; + } + } else { /* write */ + switch(b0) { + case 0x2: d->u->wst.ptr = d->dat[0x2]; break; + case 0x3: d->u->rst.ptr = d->dat[0x3]; break; + case 0xf: d->u->ram.ptr = 0x0000; break; } - } else if(b0 == 0xf) - d->u->ram.ptr = 0x0000; + } } static void @@ -120,11 +131,12 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id) static void run(Uxn *u) { - if(!uxn_eval(u, PAGE_PROGRAM)) - error("Reset", "Failed"); - else if(mempeek16(devconsole->dat, 0)) - while(read(0, &devconsole->dat[0x2], 1) > 0) - uxn_eval(u, mempeek16(devconsole->dat, 0)); + uxn_eval(u, PAGE_PROGRAM); + while(read(0, &devconsole->dat[0x2], 1) > 0) { + if(devsystem->dat[0xe]) + inspect(u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); + uxn_eval(u, mempeek16(devconsole->dat, 0)); + } } static int diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -268,32 +268,44 @@ doctrl(Uxn *u, SDL_Event *event, int z) } else devctrl->dat[2] &= ~flag; } +static void +docolors(Device *d) +{ + SDL_Color pal[16]; + int i; + for(i = 0; i < 4; ++i) { + pal[i].r = ((d->dat[0x8 + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; + pal[i].g = ((d->dat[0xa + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; + pal[i].b = ((d->dat[0xc + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; + } + for(i = 4; i < 16; ++i) { + pal[i].r = pal[i / 4].r; + pal[i].g = pal[i / 4].g; + pal[i].b = pal[i / 4].b; + } + SDL_SetPaletteColors(idxSurface->format->palette, pal, 0, 16); + reqdraw = 1; +} #pragma mark - Devices static void system_talk(Device *d, Uint8 b0, Uint8 w) { - if(!w) { - d->dat[0x2] = d->u->wst.ptr; - d->dat[0x3] = d->u->rst.ptr; - } else if(b0 > 0x7 && b0 < 0xe) { - SDL_Color pal[16]; - int i; - for(i = 0; i < 4; ++i) { - pal[i].r = ((d->dat[0x8 + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; - pal[i].g = ((d->dat[0xa + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; - pal[i].b = ((d->dat[0xc + i / 2] >> (!(i % 2) << 2)) & 0x0f) * 0x11; + if(!w) { /* read */ + switch(b0) { + case 0x2: d->dat[0x2] = d->u->wst.ptr; break; + case 0x3: d->dat[0x3] = d->u->rst.ptr; break; } - for(i = 4; i < 16; ++i) { - pal[i].r = pal[i / 4].r; - pal[i].g = pal[i / 4].g; - pal[i].b = pal[i / 4].b; + } else { /* write */ + switch(b0) { + case 0x2: d->u->wst.ptr = d->dat[0x2]; break; + case 0x3: d->u->rst.ptr = d->dat[0x3]; break; + case 0xf: d->u->ram.ptr = 0x0000; break; } - SDL_SetPaletteColors(idxSurface->format->palette, pal, 0, 16); - reqdraw = 1; - } else if(b0 == 0xf) - d->u->ram.ptr = 0x0000; + if(b0 > 0x7 && b0 < 0xe) + docolors(d); + } } static void @@ -422,7 +434,7 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id) static void run(Uxn *u) { - uxn_eval(u, 0x0100); + uxn_eval(u, PAGE_PROGRAM); redraw(u); while(1) { SDL_Event event;