commit 9fd8b17
neauoire
·
2023-08-08 17:51:12 +0000 UTC
parent cb1dcd1
Added on-screen debugger
5 files changed,
+44,
-6
+35,
-1
1@@ -24,7 +24,7 @@ static Uint8 blending[4][16] = {
2 {1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1},
3 {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
4
5-static void
6+void
7 screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2)
8 {
9 if(x1 > uxn_screen.width && x2 > x1) return;
10@@ -129,6 +129,40 @@ screen_redraw(void)
11 uxn_screen.x1 = uxn_screen.y1 = uxn_screen.x2 = uxn_screen.y2 = 0;
12 }
13
14+/* clang-format off */
15+
16+Uint8 icons[] = {
17+ 0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10,
18+ 0x10, 0x00, 0x7c, 0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe, 0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02,
19+ 0x82, 0x7c, 0x00, 0x0c, 0x14, 0x24, 0x44, 0x84, 0xfe, 0x04, 0x00, 0xfe, 0x80, 0x80, 0x7c,
20+ 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02,
21+ 0x1e, 0x02, 0x02, 0x02, 0x00, 0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82,
22+ 0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e, 0x00, 0xfc,
23+ 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00,
24+ 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c,
25+ 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80};
26+
27+/* clang-format on */
28+
29+void
30+draw_byte(Uint8 v, Uint16 x, Uint16 y, Uint8 color)
31+{
32+ screen_blit(uxn_screen.fg, icons, v >> 4 << 3, x, y, color, 0, 0, 0);
33+ screen_blit(uxn_screen.fg, icons, (v & 0xf) << 3, x + 8, y, color, 0, 0, 0);
34+}
35+
36+void
37+screen_debugger(Uxn *u)
38+{
39+ int i;
40+ for(i = 0; i < u->wst.ptr; i++)
41+ draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2);
42+ for(i = 0; i < u->rst.ptr; i++)
43+ draw_byte(u->rst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x10, 0x3);
44+ for(i = 0; i < 0x40; i++)
45+ draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
46+}
47+
48 Uint8
49 screen_dei(Uxn *u, Uint8 addr)
50 {
+2,
-0
1@@ -21,6 +21,8 @@ extern int emu_resize(int width, int height);
2
3 void screen_palette(Uint8 *addr);
4 void screen_resize(Uint16 width, Uint16 height);
5+void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2);
6 void screen_redraw(void);
7+void screen_debugger(Uxn *u);
8 Uint8 screen_dei(Uxn *u, Uint8 addr);
9 void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port);
+3,
-3
1@@ -12,7 +12,7 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 #define HALT(c) { return emu_halt(u, ins, (c), pc - 1); }
5-#define FLIP { s = (ins & 0x40) ? &u->wst : &u->rst; }
6+#define FLIP { s = ins & 0x40 ? &u->wst : &u->rst; }
7 #define JUMP(x) { if(m2) pc = (x); else pc += (Sint8)(x); }
8 #define POKE(x, y) { if(m2) { POKE2(ram + x, y) } else { ram[(x)] = (y); } }
9 #define PEEK(o, x) { if(m2) { o = PEEK2(ram + x); } else o = ram[(x)]; }
10@@ -23,7 +23,7 @@ WITH REGARD TO THIS SOFTWARE.
11 #define POP2(o) { if((tsp = *sp) <= 0x01) HALT(1) o = PEEK2(&s->dat[tsp - 2]); *sp = tsp - 2; }
12 #define POPx(o) { if(m2) { POP2(o) } else { POP1(o) } }
13 #define DEVW(p, y) { if(m2) { DEO(p, y >> 8) DEO((p + 1), y) } else { DEO(p, y) } }
14-#define DEVR(o, p) { if(m2) { o = ((DEI(p) << 8) + DEI(p + 1)); } else { o = DEI(p); } }
15+#define DEVR(o, p) { if(m2) { o = DEI(p) << 8 | DEI(p + 1); } else { o = DEI(p); } }
16
17 int
18 uxn_eval(Uxn *u, Uint16 pc)
19@@ -47,7 +47,7 @@ uxn_eval(Uxn *u, Uint16 pc)
20 case -0x2: /* JMI */ pc += PEEK2(ram + pc) + 2; break;
21 case -0x3: /* JSI */ PUSH2(pc + 2) pc += PEEK2(ram + pc) + 2; break;
22 case -0x4: /* LIT */
23- case -0x6: /* LITr */ a = ram[pc++]; PUSH1(a) break;
24+ case -0x6: /* LITr */ PUSH1(ram[pc++]) break;
25 case -0x5: /* LIT2 */
26 case -0x7: /* LIT2r */ PUSH2(PEEK2(ram + pc)) pc += 2; break;
27 /* ALU */
+1,
-1
1@@ -15,7 +15,7 @@ WITH REGARD TO THIS SOFTWARE.
2
3 #define POKE2(d, v) { (d)[0] = (v) >> 8; (d)[1] = (v); }
4 #define PEEK2(d) ((d)[0] << 8 | (d)[1])
5-#define DEO(p, value) { u->dev[p] = value; if((deo_mask[p >> 4] >> (p & 0xf)) & 0x1) emu_deo(u, p); }
6+#define DEO(p, v) { u->dev[p] = v; if((deo_mask[p >> 4] >> (p & 0xf)) & 0x1) emu_deo(u, p); }
7 #define DEI(p) ((dei_mask[(p) >> 4] >> ((p) & 0xf)) & 0x1 ? emu_dei(u, (p)) : u->dev[(p)])
8
9 /* clang-format on */
+3,
-1
1@@ -143,7 +143,7 @@ emu_event(Uxn *u)
2 char buf[7];
3 XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
4 if(sym == XK_F2)
5- system_inspect(u);
6+ u->dev[0x0e] = !u->dev[0x0e];
7 if(sym == XK_F4)
8 if(!emu_start(u, "boot.rom"))
9 emu_start(u, rom_path);
10@@ -247,6 +247,8 @@ main(int argc, char **argv)
11 if(uxn_screen.x2) {
12 int x1 = uxn_screen.x1, y1 = uxn_screen.y1, x2 = uxn_screen.x2, y2 = uxn_screen.y2;
13 screen_redraw();
14+ if(u.dev[0x0e])
15+ screen_debugger(&u);
16 XPutImage(display, window, DefaultGC(display, 0), ximage, x1, y1, x1 + PAD, y1 + PAD, x2 - x1, y2 - y1);
17 }
18 }