Better on-screen stack debugging

This commit is contained in:
neauoire 2023-10-31 11:17:33 -07:00
parent 2e32545a8b
commit 81a3dbee5e
2 changed files with 28 additions and 15 deletions

View File

@ -13,21 +13,21 @@ WITH REGARD TO THIS SOFTWARE.
#define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; } #define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; }
#define JUMP(x) { if(m2) pc = (x); else pc += (Sint8)(x); } #define JUMP(x) { if(m2) pc = (x); else pc += (Sint8)(x); }
#define POKE(x, y) { if(m2) { POKE2(ram + x, y) } else ram[(x)] = (y); } #define POKE(x, y) { if(m2) { tp = &ram[x]; POKE2(tp, y) } else ram[(x)] = (y); }
#define PEEK(o, x) { if(m2) { o = PEEK2(ram + x); } else o = ram[(x)]; } #define PEEK(o, x) { if(m2) { tp = &ram[x]; o = PEEK2(tp); } else o = ram[(x)]; }
#define DEVR(o, p) { if(m2) { o = ((emu_dei(u, p) << 8) + emu_dei(u, p + 1)); } else o = emu_dei(u, p); } #define DEVR(o, p) { if(m2) { o = (emu_dei(u, p) << 8) | emu_dei(u, p + 1); } else o = emu_dei(u, p); }
#define DEVW(p, y) { if(m2) { emu_deo(u, p, y >> 8); emu_deo(u, p + 1, y); } else emu_deo(u, p, y); } #define DEVW(p, y) { if(m2) { emu_deo(u, p, y >> 8); emu_deo(u, p + 1, y); } else emu_deo(u, p, y); }
#define PUSH1(y) { s->dat[s->ptr++] = (y); } #define PUSH1(y) { s->dat[s->ptr++] = (y); }
#define PUSH2(y) { t = (y); s->dat[s->ptr++] = t >> 0x8; s->dat[s->ptr++] = t & 0xff; } #define PUSH2(y) { t = (y); s->dat[s->ptr++] = t >> 0x8; s->dat[s->ptr++] = t; }
#define PUSHx(y) { if(m2) { PUSH2(y) } else PUSH1(y) } #define PUSHx(y) { if(m2) { PUSH2(y) } else PUSH1(y) }
#define POP1(o) { o = s->dat[--*sp]; } #define POP1(o) { o = s->dat[--*sp]; }
#define POP2(o) { o = s->dat[--*sp] | s->dat[--*sp] << 0x8; } #define POP2(o) { o = s->dat[--*sp] | (s->dat[--*sp] << 0x8); }
#define POPx(o) { if(m2) { POP2(o) } else POP1(o) } #define POPx(o) { if(m2) { POP2(o) } else POP1(o) }
int int
uxn_eval(Uxn *u, Uint16 pc) uxn_eval(Uxn *u, Uint16 pc)
{ {
Uint8 ksp, *sp, *ram = u->ram; Uint8 ksp, *sp, *tp, *ram = u->ram;
Uint16 a, b, c, t; Uint16 a, b, c, t;
if(!pc || u->dev[0x0f]) return 0; if(!pc || u->dev[0x0f]) return 0;
for(;;) { for(;;) {

View File

@ -76,15 +76,17 @@ static Uint8 icons[] = {
0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e, 0x00, 0xfc, 0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e, 0x00, 0xfc,
0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00, 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00,
0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c, 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c,
0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}; 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80 };
static Uint8 arrow[] = {
0x00, 0x00, 0x00, 0xfe, 0x7c, 0x38, 0x10, 0x00 };
/* clang-format on */ /* clang-format on */
static void static void
draw_byte(Uint8 v, Uint16 x, Uint16 y, Uint8 color) draw_byte(Uint8 b, Uint16 x, Uint16 y, Uint8 color)
{ {
screen_blit(uxn_screen.fg, icons, v >> 4 << 3, x, y, color, 0, 0, 0); screen_blit(uxn_screen.fg, icons, (b >> 4) << 3, x, y, color, 0, 0, 0);
screen_blit(uxn_screen.fg, icons, (v & 0xf) << 3, x + 8, y, color, 0, 0, 0); screen_blit(uxn_screen.fg, icons, (b & 0xf) << 3, x + 8, y, color, 0, 0, 0);
screen_change(x, y, x + 0x10, y + 0x8); screen_change(x, y, x + 0x10, y + 0x8);
} }
@ -92,11 +94,22 @@ static void
screen_debugger(Uxn *u) screen_debugger(Uxn *u)
{ {
int i; int i;
for(i = 0; i < u->wst.ptr; i++) for(i = 0; i < 0x08; i++) {
draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2); Uint8 pos = u->wst.ptr - 4 + i;
for(i = 0; i < u->rst.ptr; i++) Uint8 color = i > 4 ? 0x01 : !pos ? 0xc :
draw_byte(u->rst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x10, 0x3); i == 4 ? 0x8 :
for(i = 0; i < 0x40; i++) 0x2;
draw_byte(u->wst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x18, color);
}
for(i = 0; i < 0x08; i++) {
Uint8 pos = u->rst.ptr - 4 + i;
Uint8 color = i > 4 ? 0x01 : !pos ? 0xc :
i == 4 ? 0x8 :
0x2;
draw_byte(u->rst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x10, color);
}
screen_blit(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 0, 0, 0);
for(i = 0; i < 0x20; i++)
draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]); draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
} }