Stack pointers can be written

This commit is contained in:
neauoire 2021-08-15 17:48:15 -07:00
parent 2ea0425c47
commit d111146eb6
2 changed files with 64 additions and 40 deletions

View File

@ -26,28 +26,39 @@ error(char *msg, const char *err)
return 0; return 0;
} }
#pragma mark - Devices
static void static void
system_talk(Device *d, Uint8 b0, Uint8 w) inspect(Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)
{ {
if(!w) {
d->dat[0x2] = d->u->wst.ptr;
d->dat[0x3] = d->u->rst.ptr;
} else if(b0 == 0xe) {
Uint8 x, y; Uint8 x, y;
fprintf(stderr, "\n\n"); fprintf(stderr, "\n\n");
for(y = 0; y < 0x08; ++y) { for(y = 0; y < 0x08; ++y) {
for(x = 0; x < 0x08; ++x) { for(x = 0; x < 0x08; ++x) {
Uint8 p = y * 0x08 + x; Uint8 p = y * 0x08 + x;
fprintf(stderr, fprintf(stderr,
p == d->u->wst.ptr ? "[%02x]" : " %02x ", p == wptr ? "[%02x]" : " %02x ",
d->u->wst.dat[p]); stack[p]);
} }
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
} else if(b0 == 0xf) }
d->u->ram.ptr = 0x0000;
#pragma mark - Devices
static void
system_talk(Device *d, Uint8 b0, Uint8 w)
{
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;
}
}
} }
static void static void
@ -120,11 +131,12 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id)
static void static void
run(Uxn *u) run(Uxn *u)
{ {
if(!uxn_eval(u, PAGE_PROGRAM)) uxn_eval(u, PAGE_PROGRAM);
error("Reset", "Failed"); while(read(0, &devconsole->dat[0x2], 1) > 0) {
else if(mempeek16(devconsole->dat, 0)) if(devsystem->dat[0xe])
while(read(0, &devconsole->dat[0x2], 1) > 0) inspect(u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat);
uxn_eval(u, mempeek16(devconsole->dat, 0)); uxn_eval(u, mempeek16(devconsole->dat, 0));
}
} }
static int static int

View File

@ -268,16 +268,9 @@ doctrl(Uxn *u, SDL_Event *event, int z)
} else } else
devctrl->dat[2] &= ~flag; devctrl->dat[2] &= ~flag;
} }
#pragma mark - Devices
static void static void
system_talk(Device *d, Uint8 b0, Uint8 w) docolors(Device *d)
{ {
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]; SDL_Color pal[16];
int i; int i;
for(i = 0; i < 4; ++i) { for(i = 0; i < 4; ++i) {
@ -292,8 +285,27 @@ system_talk(Device *d, Uint8 b0, Uint8 w)
} }
SDL_SetPaletteColors(idxSurface->format->palette, pal, 0, 16); SDL_SetPaletteColors(idxSurface->format->palette, pal, 0, 16);
reqdraw = 1; reqdraw = 1;
} else if(b0 == 0xf) }
d->u->ram.ptr = 0x0000;
#pragma mark - Devices
static void
system_talk(Device *d, Uint8 b0, Uint8 w)
{
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;
}
if(b0 > 0x7 && b0 < 0xe)
docolors(d);
}
} }
static void static void
@ -422,7 +434,7 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id)
static void static void
run(Uxn *u) run(Uxn *u)
{ {
uxn_eval(u, 0x0100); uxn_eval(u, PAGE_PROGRAM);
redraw(u); redraw(u);
while(1) { while(1) {
SDL_Event event; SDL_Event event;