commit 867701b
neauoire
·
2023-08-16 20:22:41 +0000 UTC
parent 7dac87d
Make screen debugger private
3 files changed,
+53,
-49
+37,
-35
1@@ -65,6 +65,40 @@ screen_blit(Uint8 *layer, Uint8 *ram, Uint16 addr, int x1, int y1, int color, in
2 }
3 }
4
5+/* clang-format off */
6+
7+static Uint8 icons[] = {
8+ 0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10,
9+ 0x10, 0x00, 0x7c, 0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe, 0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02,
10+ 0x82, 0x7c, 0x00, 0x0c, 0x14, 0x24, 0x44, 0x84, 0xfe, 0x04, 0x00, 0xfe, 0x80, 0x80, 0x7c,
11+ 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02,
12+ 0x1e, 0x02, 0x02, 0x02, 0x00, 0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82,
13+ 0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e, 0x00, 0xfc,
14+ 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00,
15+ 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c,
16+ 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80};
17+
18+/* clang-format on */
19+
20+static void
21+draw_byte(Uint8 v, Uint16 x, Uint16 y, Uint8 color)
22+{
23+ screen_blit(uxn_screen.fg, icons, v >> 4 << 3, x, y, color, 0, 0, 0);
24+ screen_blit(uxn_screen.fg, icons, (v & 0xf) << 3, x + 8, y, color, 0, 0, 0);
25+}
26+
27+static void
28+screen_debugger(Uxn *u)
29+{
30+ int i;
31+ for(i = 0; i < u->wst.ptr; i++)
32+ draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2);
33+ for(i = 0; i < u->rst.ptr; i++)
34+ draw_byte(u->rst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x10, 0x3);
35+ for(i = 0; i < 0x40; i++)
36+ draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
37+}
38+
39 void
40 screen_palette(Uint8 *addr)
41 {
42@@ -111,7 +145,7 @@ screen_resize(Uint16 width, Uint16 height)
43 }
44
45 void
46-screen_redraw(void)
47+screen_redraw(Uxn *u)
48 {
49 Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg;
50 Uint32 palette[16], *pixels = uxn_screen.pixels;
51@@ -129,40 +163,8 @@ screen_redraw(void)
52 }
53 uxn_screen.x1 = uxn_screen.y1 = 0xffff;
54 uxn_screen.x2 = uxn_screen.y2 = 0;
55-}
56-
57-/* clang-format off */
58-
59-Uint8 icons[] = {
60- 0x00, 0x7c, 0x82, 0x82, 0x82, 0x82, 0x82, 0x7c, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10,
61- 0x10, 0x00, 0x7c, 0x82, 0x02, 0x7c, 0x80, 0x80, 0xfe, 0x00, 0x7c, 0x82, 0x02, 0x1c, 0x02,
62- 0x82, 0x7c, 0x00, 0x0c, 0x14, 0x24, 0x44, 0x84, 0xfe, 0x04, 0x00, 0xfe, 0x80, 0x80, 0x7c,
63- 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x80, 0xfc, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02,
64- 0x1e, 0x02, 0x02, 0x02, 0x00, 0x7c, 0x82, 0x82, 0x7c, 0x82, 0x82, 0x7c, 0x00, 0x7c, 0x82,
65- 0x82, 0x7e, 0x02, 0x82, 0x7c, 0x00, 0x7c, 0x82, 0x02, 0x7e, 0x82, 0x82, 0x7e, 0x00, 0xfc,
66- 0x82, 0x82, 0xfc, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0x80, 0x80, 0x82, 0x7c, 0x00,
67- 0xfc, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfc, 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x82, 0x7c,
68- 0x00, 0x7c, 0x82, 0x80, 0xf0, 0x80, 0x80, 0x80};
69-
70-/* clang-format on */
71-
72-void
73-draw_byte(Uint8 v, Uint16 x, Uint16 y, Uint8 color)
74-{
75- screen_blit(uxn_screen.fg, icons, v >> 4 << 3, x, y, color, 0, 0, 0);
76- screen_blit(uxn_screen.fg, icons, (v & 0xf) << 3, x + 8, y, color, 0, 0, 0);
77-}
78-
79-void
80-screen_debugger(Uxn *u)
81-{
82- int i;
83- for(i = 0; i < u->wst.ptr; i++)
84- draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2);
85- for(i = 0; i < u->rst.ptr; i++)
86- draw_byte(u->rst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x10, 0x3);
87- for(i = 0; i < 0x40; i++)
88- draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
89+ if(u->dev[0x0e])
90+ screen_debugger(u);
91 }
92
93 Uint8
+1,
-2
1@@ -26,8 +26,7 @@ void screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color);
2 void screen_palette(Uint8 *addr);
3 void screen_resize(Uint16 width, Uint16 height);
4 void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2);
5-void screen_redraw(void);
6-void screen_debugger(Uxn *u);
7+void screen_redraw(Uxn *u);
8
9 Uint8 screen_dei(Uxn *u, Uint8 addr);
10 void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port);
+15,
-12
1@@ -29,7 +29,6 @@ WITH REGARD TO THIS SOFTWARE.
2
3 static XImage *ximage;
4 static Display *display;
5-static Visual *visual;
6 static Window window;
7
8 #define WIDTH (64 * 8)
9@@ -81,12 +80,14 @@ emu_resize(int width, int height)
10 return 1;
11 }
12
13-static int
14-emu_start(Uxn *u, char *rom)
15+static void
16+emu_restart(Uxn *u, char *rom, int soft)
17 {
18- (void)u;
19- (void)rom;
20- return 1;
21+ screen_resize(WIDTH, HEIGHT);
22+ screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
23+ screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
24+ system_reboot(u, rom, soft);
25+ /* set window title */
26 }
27
28 static void
29@@ -141,9 +142,10 @@ emu_event(Uxn *u)
30 XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
31 if(sym == XK_F2)
32 u->dev[0x0e] = !u->dev[0x0e];
33- if(sym == XK_F4)
34- if(!emu_start(u, "boot.rom"))
35- emu_start(u, boot_rom);
36+ else if(sym == XK_F4)
37+ emu_restart(u, boot_rom, 0);
38+ else if(sym == XK_F5)
39+ emu_restart(u, boot_rom, 1);
40 controller_down(u, &u->dev[0x80], get_button(sym));
41 controller_key(u, &u->dev[0x80], sym < 0x80 ? sym : (Uint8)buf[0]);
42 } break;
43@@ -193,6 +195,7 @@ emu_run(Uxn *u, char *rom)
44
45 /* display */
46 Atom wmDelete;
47+ static Visual *visual;
48 display = XOpenDisplay(NULL);
49 visual = DefaultVisual(display, 0);
50 window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width * SCALE + PAD * 2, uxn_screen.height * SCALE + PAD * 2, 1, 0, 0);
51@@ -230,9 +233,7 @@ emu_run(Uxn *u, char *rom)
52 }
53 if(uxn_screen.x2) {
54 int x1 = uxn_screen.x1, y1 = uxn_screen.y1, x2 = uxn_screen.x2, y2 = uxn_screen.y2;
55- screen_redraw();
56- if(u->dev[0x0e])
57- screen_debugger(u);
58+ screen_redraw(u);
59 XPutImage(display, window, DefaultGC(display, 0), ximage, x1, y1, x1 + PAD, y1 + PAD, x2 - x1, y2 - y1);
60 }
61 }
62@@ -243,6 +244,8 @@ static int
63 emu_end(Uxn *u)
64 {
65 XDestroyImage(ximage);
66+ close(0);
67+ free(u->ram);
68 return u->dev[0x0f] & 0x7f;
69 }
70