diff --git a/src/devices/screen.c b/src/devices/screen.c index 7c2f81c..0789045 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -24,7 +24,7 @@ static Uint8 blending[4][16] = { {1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1}, {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}}; -static void +void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2) { if(x1 > uxn_screen.width && x2 > x1) return; @@ -129,6 +129,40 @@ screen_redraw(void) uxn_screen.x1 = uxn_screen.y1 = uxn_screen.x2 = uxn_screen.y2 = 0; } +/* clang-format off */ + +Uint8 icons[] = { + 0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x00, 0x7c, 0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe, 0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02, + 0x82, 0x7c, 0x00, 0x0c, 0x14, 0x24, 0x44, 0x84, 0xfe, 0x04, 0x00, 0xfe, 0x80, 0x80, 0x7c, + 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02, + 0x1e, 0x02, 0x02, 0x02, 0x00, 0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82, + 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, + 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c, + 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80}; + +/* clang-format on */ + +void +draw_byte(Uint8 v, 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, (v & 0xf) << 3, x + 8, y, color, 0, 0, 0); +} + +void +screen_debugger(Uxn *u) +{ + int i; + for(i = 0; i < u->wst.ptr; i++) + draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2); + for(i = 0; i < u->rst.ptr; i++) + draw_byte(u->rst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x10, 0x3); + for(i = 0; i < 0x40; i++) + draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]); +} + Uint8 screen_dei(Uxn *u, Uint8 addr) { diff --git a/src/devices/screen.h b/src/devices/screen.h index 6a417a3..6620909 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -21,6 +21,8 @@ extern int emu_resize(int width, int height); void screen_palette(Uint8 *addr); void screen_resize(Uint16 width, Uint16 height); +void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2); void screen_redraw(void); +void screen_debugger(Uxn *u); Uint8 screen_dei(Uxn *u, Uint8 addr); void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port); diff --git a/src/uxn.c b/src/uxn.c index 46c0d8b..18e4ba3 100644 --- a/src/uxn.c +++ b/src/uxn.c @@ -12,7 +12,7 @@ WITH REGARD TO THIS SOFTWARE. */ #define HALT(c) { return emu_halt(u, ins, (c), pc - 1); } -#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 POKE(x, y) { if(m2) { POKE2(ram + x, y) } else { ram[(x)] = (y); } } #define PEEK(o, x) { if(m2) { o = PEEK2(ram + x); } else o = ram[(x)]; } @@ -23,7 +23,7 @@ WITH REGARD TO THIS SOFTWARE. #define POP2(o) { if((tsp = *sp) <= 0x01) HALT(1) o = PEEK2(&s->dat[tsp - 2]); *sp = tsp - 2; } #define POPx(o) { if(m2) { POP2(o) } else { POP1(o) } } #define DEVW(p, y) { if(m2) { DEO(p, y >> 8) DEO((p + 1), y) } else { DEO(p, y) } } -#define DEVR(o, p) { if(m2) { o = ((DEI(p) << 8) + DEI(p + 1)); } else { o = DEI(p); } } +#define DEVR(o, p) { if(m2) { o = DEI(p) << 8 | DEI(p + 1); } else { o = DEI(p); } } int uxn_eval(Uxn *u, Uint16 pc) @@ -47,7 +47,7 @@ uxn_eval(Uxn *u, Uint16 pc) case -0x2: /* JMI */ pc += PEEK2(ram + pc) + 2; break; case -0x3: /* JSI */ PUSH2(pc + 2) pc += PEEK2(ram + pc) + 2; break; case -0x4: /* LIT */ - case -0x6: /* LITr */ a = ram[pc++]; PUSH1(a) break; + case -0x6: /* LITr */ PUSH1(ram[pc++]) break; case -0x5: /* LIT2 */ case -0x7: /* LIT2r */ PUSH2(PEEK2(ram + pc)) pc += 2; break; /* ALU */ diff --git a/src/uxn.h b/src/uxn.h index 367b920..8bb5831 100644 --- a/src/uxn.h +++ b/src/uxn.h @@ -15,7 +15,7 @@ WITH REGARD TO THIS SOFTWARE. #define POKE2(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); } #define PEEK2(d) ((d)[0] << 8 | (d)[1]) -#define DEO(p, value) { u->dev[p] = value; if((deo_mask[p >> 4] >> (p & 0xf)) & 0x1) emu_deo(u, p); } +#define DEO(p, v) { u->dev[p] = v; if((deo_mask[p >> 4] >> (p & 0xf)) & 0x1) emu_deo(u, p); } #define DEI(p) ((dei_mask[(p) >> 4] >> ((p) & 0xf)) & 0x1 ? emu_dei(u, (p)) : u->dev[(p)]) /* clang-format on */ diff --git a/src/uxn11.c b/src/uxn11.c index ac8e618..7af02c7 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -143,7 +143,7 @@ emu_event(Uxn *u) char buf[7]; XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); if(sym == XK_F2) - system_inspect(u); + u->dev[0x0e] = !u->dev[0x0e]; if(sym == XK_F4) if(!emu_start(u, "boot.rom")) emu_start(u, rom_path); @@ -247,6 +247,8 @@ main(int argc, char **argv) if(uxn_screen.x2) { int x1 = uxn_screen.x1, y1 = uxn_screen.y1, x2 = uxn_screen.x2, y2 = uxn_screen.y2; screen_redraw(); + if(u.dev[0x0e]) + screen_debugger(&u); XPutImage(display, window, DefaultGC(display, 0), ximage, x1, y1, x1 + PAD, y1 + PAD, x2 - x1, y2 - y1); } }