diff --git a/src/devices/screen.c b/src/devices/screen.c index 01b2b68..1050be4 100644 --- a/src/devices/screen.c +++ b/src/devices/screen.c @@ -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 screen_palette(Uint8 *addr) { @@ -111,7 +145,7 @@ screen_resize(Uint16 width, Uint16 height) } void -screen_redraw(void) +screen_redraw(Uxn *u) { Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg; Uint32 palette[16], *pixels = uxn_screen.pixels; @@ -129,40 +163,8 @@ screen_redraw(void) } uxn_screen.x1 = uxn_screen.y1 = 0xffff; 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; 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]); + if(u->dev[0x0e]) + screen_debugger(u); } Uint8 diff --git a/src/devices/screen.h b/src/devices/screen.h index 2989faf..5599dbb 100644 --- a/src/devices/screen.h +++ b/src/devices/screen.h @@ -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_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); +void screen_redraw(Uxn *u); Uint8 screen_dei(Uxn *u, Uint8 addr); void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port); diff --git a/src/uxn11.c b/src/uxn11.c index 3bae085..a923264 100644 --- a/src/uxn11.c +++ b/src/uxn11.c @@ -29,7 +29,6 @@ WITH REGARD TO THIS SOFTWARE. static XImage *ximage; static Display *display; -static Visual *visual; static Window window; #define WIDTH (64 * 8) @@ -81,12 +80,14 @@ emu_resize(int width, int height) return 1; } -static int -emu_start(Uxn *u, char *rom) +static void +emu_restart(Uxn *u, char *rom, int soft) { - (void)u; - (void)rom; - return 1; + screen_resize(WIDTH, HEIGHT); + screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0); + screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0); + system_reboot(u, rom, soft); + /* set window title */ } static void @@ -141,9 +142,10 @@ emu_event(Uxn *u) XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0); if(sym == XK_F2) u->dev[0x0e] = !u->dev[0x0e]; - if(sym == XK_F4) - if(!emu_start(u, "boot.rom")) - emu_start(u, boot_rom); + else if(sym == XK_F4) + emu_restart(u, boot_rom, 0); + else if(sym == XK_F5) + emu_restart(u, boot_rom, 1); controller_down(u, &u->dev[0x80], get_button(sym)); controller_key(u, &u->dev[0x80], sym < 0x80 ? sym : (Uint8)buf[0]); } break; @@ -193,6 +195,7 @@ emu_run(Uxn *u, char *rom) /* display */ Atom wmDelete; + static Visual *visual; display = XOpenDisplay(NULL); 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); @@ -230,9 +233,7 @@ emu_run(Uxn *u, char *rom) } if(uxn_screen.x2) { int x1 = uxn_screen.x1, y1 = uxn_screen.y1, x2 = uxn_screen.x2, y2 = uxn_screen.y2; - screen_redraw(); - if(u->dev[0x0e]) - screen_debugger(u); + screen_redraw(u); 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) { XDestroyImage(ximage); + close(0); + free(u->ram); return u->dev[0x0f] & 0x7f; }