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;
}
#pragma mark - Devices
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;
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]);
p == wptr ? "[%02x]" : " %02x ",
stack[p]);
}
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
@ -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, 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

View File

@ -268,16 +268,9 @@ doctrl(Uxn *u, SDL_Event *event, int z)
} else
devctrl->dat[2] &= ~flag;
}
#pragma mark - Devices
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];
int 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);
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
@ -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;