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;
} }
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 #pragma mark - Devices
static void static void
system_talk(Device *d, Uint8 b0, Uint8 w) system_talk(Device *d, Uint8 b0, Uint8 w)
{ {
if(!w) { if(!w) { /* read */
d->dat[0x2] = d->u->wst.ptr; switch(b0) {
d->dat[0x3] = d->u->rst.ptr; case 0x2: d->dat[0x2] = d->u->wst.ptr; break;
} else if(b0 == 0xe) { case 0x3: d->dat[0x3] = d->u->rst.ptr; break;
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");
} }
} else if(b0 == 0xf) } else { /* write */
d->u->ram.ptr = 0x0000; 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,32 +268,44 @@ doctrl(Uxn *u, SDL_Event *event, int z)
} else } else
devctrl->dat[2] &= ~flag; 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 #pragma mark - Devices
static void static void
system_talk(Device *d, Uint8 b0, Uint8 w) system_talk(Device *d, Uint8 b0, Uint8 w)
{ {
if(!w) { if(!w) { /* read */
d->dat[0x2] = d->u->wst.ptr; switch(b0) {
d->dat[0x3] = d->u->rst.ptr; case 0x2: d->dat[0x2] = d->u->wst.ptr; break;
} else if(b0 > 0x7 && b0 < 0xe) { case 0x3: d->dat[0x3] = d->u->rst.ptr; break;
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) { } else { /* write */
pal[i].r = pal[i / 4].r; switch(b0) {
pal[i].g = pal[i / 4].g; case 0x2: d->u->wst.ptr = d->dat[0x2]; break;
pal[i].b = pal[i / 4].b; 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); if(b0 > 0x7 && b0 < 0xe)
reqdraw = 1; docolors(d);
} else if(b0 == 0xf) }
d->u->ram.ptr = 0x0000;
} }
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;