Returned the on-screen debugger

This commit is contained in:
neauoire 2023-08-08 10:27:41 -07:00
parent 27ff275cea
commit 7090ab72b9
3 changed files with 48 additions and 6 deletions

View File

@ -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,41 @@ 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 + 1; i++)
draw_byte(u->wst.dat[i], i * 0x18 + 0x8, uxn_screen.height - 0x18, 0x2);
for(i = 0; i < u->rst.ptr + 1; 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, 0x2 + !!u->ram[i]);
}
}
Uint8
screen_dei(Uxn *u, Uint8 addr)
{

View File

@ -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);

View File

@ -208,8 +208,13 @@ emu_resize(int width, int height)
}
static void
emu_redraw(void)
emu_redraw(Uxn *u)
{
if(u->dev[0x0e]) {
screen_change(0, 0, uxn_screen.width, uxn_screen.height);
screen_redraw();
screen_debugger(u);
} else
screen_redraw();
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0)
system_error("SDL_UpdateTexture", SDL_GetError());
@ -362,7 +367,7 @@ handle_events(Uxn *u)
if(event.type == SDL_QUIT)
return 0;
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED)
emu_redraw();
emu_redraw(u);
else if(event.type == SDL_DROPFILE) {
screen_resize(WIDTH, HEIGHT);
emu_start(u, event.drop.file, 0);
@ -392,7 +397,7 @@ handle_events(Uxn *u)
else if(event.key.keysym.sym == SDLK_F1)
set_zoom(zoom == 3 ? 1 : zoom + 1, 1);
else if(event.key.keysym.sym == SDLK_F2)
system_inspect(u);
u->dev[0x0e] = !u->dev[0x0e];
else if(event.key.keysym.sym == SDLK_F3)
capture_screen();
else if(event.key.keysym.sym == SDLK_F4)
@ -484,7 +489,7 @@ run(Uxn *u, char *rom)
next_refresh = now + frame_interval;
uxn_eval(u, screen_vector);
if(uxn_screen.x2)
emu_redraw();
emu_redraw(u);
}
if(screen_vector || uxn_screen.x2) {
Uint64 delay_ms = (next_refresh - now) / ms_interval;