Make screen debugger private

This commit is contained in:
neauoire 2023-08-16 13:22:41 -07:00
parent 7dac87dcba
commit 867701b5dc
3 changed files with 53 additions and 49 deletions

View File

@ -65,6 +65,40 @@ screen_blit(Uint8 *layer, Uint8 *ram, Uint16 addr, int x1, int y1, int color, in
} }
} }
/* clang-format off */
static 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 */
static 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);
}
static 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]);
}
void void
screen_palette(Uint8 *addr) screen_palette(Uint8 *addr)
{ {
@ -111,7 +145,7 @@ screen_resize(Uint16 width, Uint16 height)
} }
void void
screen_redraw(void) screen_redraw(Uxn *u)
{ {
Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg; Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg;
Uint32 palette[16], *pixels = uxn_screen.pixels; Uint32 palette[16], *pixels = uxn_screen.pixels;
@ -129,40 +163,8 @@ screen_redraw(void)
} }
uxn_screen.x1 = uxn_screen.y1 = 0xffff; uxn_screen.x1 = uxn_screen.y1 = 0xffff;
uxn_screen.x2 = uxn_screen.y2 = 0; uxn_screen.x2 = uxn_screen.y2 = 0;
} if(u->dev[0x0e])
screen_debugger(u);
/* 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 Uint8

View File

@ -26,8 +26,7 @@ void screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color);
void screen_palette(Uint8 *addr); void screen_palette(Uint8 *addr);
void screen_resize(Uint16 width, Uint16 height); void screen_resize(Uint16 width, Uint16 height);
void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2); void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2);
void screen_redraw(void); void screen_redraw(Uxn *u);
void screen_debugger(Uxn *u);
Uint8 screen_dei(Uxn *u, Uint8 addr); Uint8 screen_dei(Uxn *u, Uint8 addr);
void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port); void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port);

View File

@ -29,7 +29,6 @@ WITH REGARD TO THIS SOFTWARE.
static XImage *ximage; static XImage *ximage;
static Display *display; static Display *display;
static Visual *visual;
static Window window; static Window window;
#define WIDTH (64 * 8) #define WIDTH (64 * 8)
@ -81,12 +80,14 @@ emu_resize(int width, int height)
return 1; return 1;
} }
static int static void
emu_start(Uxn *u, char *rom) emu_restart(Uxn *u, char *rom, int soft)
{ {
(void)u; screen_resize(WIDTH, HEIGHT);
(void)rom; screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
return 1; screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
system_reboot(u, rom, soft);
/* set window title */
} }
static void static void
@ -141,9 +142,10 @@ emu_event(Uxn *u)
XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
if(sym == XK_F2) if(sym == XK_F2)
u->dev[0x0e] = !u->dev[0x0e]; u->dev[0x0e] = !u->dev[0x0e];
if(sym == XK_F4) else if(sym == XK_F4)
if(!emu_start(u, "boot.rom")) emu_restart(u, boot_rom, 0);
emu_start(u, boot_rom); else if(sym == XK_F5)
emu_restart(u, boot_rom, 1);
controller_down(u, &u->dev[0x80], get_button(sym)); controller_down(u, &u->dev[0x80], get_button(sym));
controller_key(u, &u->dev[0x80], sym < 0x80 ? sym : (Uint8)buf[0]); controller_key(u, &u->dev[0x80], sym < 0x80 ? sym : (Uint8)buf[0]);
} break; } break;
@ -193,6 +195,7 @@ emu_run(Uxn *u, char *rom)
/* display */ /* display */
Atom wmDelete; Atom wmDelete;
static Visual *visual;
display = XOpenDisplay(NULL); display = XOpenDisplay(NULL);
visual = DefaultVisual(display, 0); visual = DefaultVisual(display, 0);
window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width * SCALE + PAD * 2, uxn_screen.height * SCALE + PAD * 2, 1, 0, 0); window = XCreateSimpleWindow(display, RootWindow(display, 0), 0, 0, uxn_screen.width * SCALE + PAD * 2, uxn_screen.height * SCALE + PAD * 2, 1, 0, 0);
@ -230,9 +233,7 @@ emu_run(Uxn *u, char *rom)
} }
if(uxn_screen.x2) { if(uxn_screen.x2) {
int x1 = uxn_screen.x1, y1 = uxn_screen.y1, x2 = uxn_screen.x2, y2 = uxn_screen.y2; int x1 = uxn_screen.x1, y1 = uxn_screen.y1, x2 = uxn_screen.x2, y2 = uxn_screen.y2;
screen_redraw(); screen_redraw(u);
if(u->dev[0x0e])
screen_debugger(u);
XPutImage(display, window, DefaultGC(display, 0), ximage, x1, y1, x1 + PAD, y1 + PAD, x2 - x1, y2 - y1); XPutImage(display, window, DefaultGC(display, 0), ximage, x1, y1, x1 + PAD, y1 + PAD, x2 - x1, y2 - y1);
} }
} }
@ -243,6 +244,8 @@ static int
emu_end(Uxn *u) emu_end(Uxn *u)
{ {
XDestroyImage(ximage); XDestroyImage(ximage);
close(0);
free(u->ram);
return u->dev[0x0f] & 0x7f; return u->dev[0x0f] & 0x7f;
} }