Browse code

Better on-screen stack debugging

neauoire authored on 31/10/2023 18:17:33
Showing 2 changed files
... ...
@@ -13,21 +13,21 @@ WITH REGARD TO THIS SOFTWARE.
13 13
 
14 14
 #define FLIP       { s = ins & 0x40 ? &u->wst : &u->rst; }
15 15
 #define JUMP(x)    { if(m2) pc = (x); else pc += (Sint8)(x); }
16
-#define POKE(x, y) { if(m2) { POKE2(ram + x, y) } else ram[(x)] = (y); }
17
-#define PEEK(o, x) { if(m2) { o = PEEK2(ram + x); } else o = ram[(x)]; }
18
-#define DEVR(o, p) { if(m2) { o = ((emu_dei(u, p) << 8) + emu_dei(u, p + 1)); } else o = emu_dei(u, p); }
16
+#define POKE(x, y) { if(m2) { tp = &ram[x]; POKE2(tp, y) } else ram[(x)] = (y); }
17
+#define PEEK(o, x) { if(m2) { tp = &ram[x]; o = PEEK2(tp); } else o = ram[(x)]; }
18
+#define DEVR(o, p) { if(m2) { o = (emu_dei(u, p) << 8) | emu_dei(u, p + 1); } else o = emu_dei(u, p); }
19 19
 #define DEVW(p, y) { if(m2) { emu_deo(u, p, y >> 8); emu_deo(u, p + 1, y); } else emu_deo(u, p, y); }
20 20
 #define PUSH1(y)   { s->dat[s->ptr++] = (y); }
21
-#define PUSH2(y)   { t = (y); s->dat[s->ptr++] = t >> 0x8; s->dat[s->ptr++] = t & 0xff; }
21
+#define PUSH2(y)   { t = (y); s->dat[s->ptr++] = t >> 0x8; s->dat[s->ptr++] = t; }
22 22
 #define PUSHx(y)   { if(m2) { PUSH2(y) } else PUSH1(y) }
23 23
 #define POP1(o)    { o = s->dat[--*sp]; }
24
-#define POP2(o)    { o = s->dat[--*sp] | s->dat[--*sp] << 0x8; }
24
+#define POP2(o)    { o = s->dat[--*sp] | (s->dat[--*sp] << 0x8); }
25 25
 #define POPx(o)    { if(m2) { POP2(o) } else POP1(o) }
26 26
 
27 27
 int
28 28
 uxn_eval(Uxn *u, Uint16 pc)
29 29
 {
30
-	Uint8 ksp, *sp, *ram = u->ram;
30
+	Uint8 ksp, *sp, *tp, *ram = u->ram;
31 31
 	Uint16 a, b, c, t;
32 32
 	if(!pc || u->dev[0x0f]) return 0;
33 33
 	for(;;) {
... ...
@@ -76,15 +76,17 @@ static Uint8 icons[] = {
76 76
 	0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e, 0x00, 0xfc, 
77 77
 	0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00, 
78 78
 	0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c,
79
-	0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80};
79
+	0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80 };
80
+static Uint8 arrow[] = {
81
+	0x00, 0x00, 0x00, 0xfe, 0x7c, 0x38, 0x10, 0x00 };
80 82
 
81 83
 /* clang-format on */
82 84
 
83 85
 static void
84
-draw_byte(Uint8 v, Uint16 x, Uint16 y, Uint8 color)
86
+draw_byte(Uint8 b, Uint16 x, Uint16 y, Uint8 color)
85 87
 {
86
-	screen_blit(uxn_screen.fg, icons, v >> 4 << 3, x, y, color, 0, 0, 0);
87
-	screen_blit(uxn_screen.fg, icons, (v & 0xf) << 3, x + 8, y, color, 0, 0, 0);
88
+	screen_blit(uxn_screen.fg, icons, (b >> 4) << 3, x, y, color, 0, 0, 0);
89
+	screen_blit(uxn_screen.fg, icons, (b & 0xf) << 3, x + 8, y, color, 0, 0, 0);
88 90
 	screen_change(x, y, x + 0x10, y + 0x8);
89 91
 }
90 92
 
... ...
@@ -92,11 +94,22 @@ static void
92 94
 screen_debugger(Uxn *u)
93 95
 {
94 96
 	int i;
95
-	for(i = 0; i < u->wst.ptr; i++)
96
-		draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2);
97
-	for(i = 0; i < u->rst.ptr; i++)
98
-		draw_byte(u->rst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x10, 0x3);
99
-	for(i = 0; i < 0x40; i++)
97
+	for(i = 0; i < 0x08; i++) {
98
+		Uint8 pos = u->wst.ptr - 4 + i;
99
+		Uint8 color = i > 4 ? 0x01 : !pos ? 0xc :
100
+			i == 4                        ? 0x8 :
101
+                                            0x2;
102
+		draw_byte(u->wst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x18, color);
103
+	}
104
+	for(i = 0; i < 0x08; i++) {
105
+		Uint8 pos = u->rst.ptr - 4 + i;
106
+		Uint8 color = i > 4 ? 0x01 : !pos ? 0xc :
107
+			i == 4                        ? 0x8 :
108
+                                            0x2;
109
+		draw_byte(u->rst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x10, color);
110
+	}
111
+	screen_blit(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 0, 0, 0);
112
+	for(i = 0; i < 0x20; i++)
100 113
 		draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
101 114
 }
102 115