This works by having an 'undraw' flag that gets set when the view is
toggled off by pressing F2 again, which causes the inspector to be
redrawn with foreground colour 0 (transparent).
---
src/devices/ppu.c | 29 ++++++++++++++++-------------
src/devices/ppu.h | 2 +-
src/uxnemu.c | 16 +++++++++++++---
3 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/src/devices/ppu.c b/src/devices/ppu.c
index 86c6cb5..ab24ed0 100644
--- a/src/devices/ppu.c
+++ b/src/devices/ppu.c
@@ -114,30 +114,33 @@ ppu_2bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui
}
void
-ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory)
+ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory, Uint8 clear)
{
+ Uint8 c = 0xff;
+ if (clear) c = 0x00;
+
Uint8 i, x, y, b;
for(i = 0; i < 0x20; ++i) {
x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i];
/* working stack */
- ppu_1bpp(p, 1, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0);
- ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0);
+ ppu_1bpp(p, 1, x, y, font[(b >> 4) & 0xf], (1 + (wptr == i) * 0x7) & c, 0, 0);
+ ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], (1 + (wptr == i) * 0x7) & c, 0, 0);
y = 0x28 + (i / 8 + 1) * 8;
b = memory[i];
/* return stack */
- ppu_1bpp(p, 1, x, y, font[(b >> 4) & 0xf], 3, 0, 0);
- ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], 3, 0, 0);
+ ppu_1bpp(p, 1, x, y, font[(b >> 4) & 0xf], 3 & c, 0, 0);
+ ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], 3 & c, 0, 0);
}
/* return pointer */
- ppu_1bpp(p, 1, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0);
- ppu_1bpp(p, 1, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0);
+ ppu_1bpp(p, 1, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2 & c, 0, 0);
+ ppu_1bpp(p, 1, 0x10, y + 0x10, font[rptr & 0xf], 0x2 & c, 0, 0);
/* guides */
for(x = 0; x < 0x10; ++x) {
- ppu_write(p, 1, x, p->height / 2, 2);
- ppu_write(p, 1, p->width - x, p->height / 2, 2);
- ppu_write(p, 1, p->width / 2, p->height - x, 2);
- ppu_write(p, 1, p->width / 2, x, 2);
- ppu_write(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2);
- ppu_write(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2);
+ ppu_write(p, 1, x, p->height / 2, 2 & c);
+ ppu_write(p, 1, p->width - x, p->height / 2, 2 & c);
+ ppu_write(p, 1, p->width / 2, p->height - x, 2 & c);
+ ppu_write(p, 1, p->width / 2, x, 2 & c);
+ ppu_write(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2 & c);
+ ppu_write(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2 & c);
}
}
diff --git a/src/devices/ppu.h b/src/devices/ppu.h
index 93a8110..43ec847 100644
--- a/src/devices/ppu.h
+++ b/src/devices/ppu.h
@@ -29,4 +29,4 @@ void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color);
void ppu_frame(Ppu *p);
void ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
void ppu_2bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);
-void ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory);
+void ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory, Uint8 clear);
diff --git a/src/uxnemu.c b/src/uxnemu.c
index 6717ab9..ea196a3 100644
--- a/src/uxnemu.c
+++ b/src/uxnemu.c
@@ -38,6 +38,7 @@ static Ppu ppu;
static Apu apu[POLYPHONY];
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
static Uint8 zoom = 1;
+static Uint8 undraw_inspect = 0;
static Uint32 *ppu_screen, stdin_event, audio0_event, palette[16];
static int
@@ -168,8 +169,14 @@ static void
redraw(Uxn *u)
{
Uint16 x, y;
- if(devsystem->dat[0xe])
- ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat);
+
+ if (devsystem->dat[0xe])
+ ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat, 0);
+ if (undraw_inspect) {
+ ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat, 1);
+ undraw_inspect = 0;
+ }
+
for(y = 0; y < ppu.height; ++y)
for(x = 0; x < ppu.width; ++x)
ppu_screen[x + y * ppu.width] = palette[ppu_read(&ppu, x, y)];
@@ -273,7 +280,10 @@ doctrl(SDL_Event *event, int z)
case SDLK_LEFT: flag = 0x40; break;
case SDLK_RIGHT: flag = 0x80; break;
case SDLK_F1: if(z) set_zoom(zoom > 2 ? 1 : zoom + 1); break;
- case SDLK_F2: if(z) devsystem->dat[0xe] = !devsystem->dat[0xe]; break;
+ case SDLK_F2:
+ if(z) devsystem->dat[0xe] = !devsystem->dat[0xe];
+ if (!devsystem->dat[0xe]) undraw_inspect = 1;
+ break;
case SDLK_F3: if(z) capture_screen(); break;
}
/* clang-format on */
--
2.20.1