uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 3bfbbbc124c8b7d56ce93ae6475df460b907ab7b
parent e21a0ed885e4cb84654a5124e7e89219f9686b5f
Author: Devine Lu Linvega <aliceffekt@gmail.com>
Date:   Thu,  4 Nov 2021 11:42:15 -0400

Moved debugger to ppu

Diffstat:
Msrc/devices/ppu.c | 47+++++++++++++++++++++++++++++++++++++++++++++++
Msrc/devices/ppu.h | 1+
Msrc/uxnemu.c | 49+------------------------------------------------
3 files changed, 49 insertions(+), 48 deletions(-)

diff --git a/src/devices/ppu.c b/src/devices/ppu.c @@ -19,6 +19,24 @@ static Uint8 blending[5][16] = { {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}, {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; +static Uint8 font[][8] = { + {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}}; + void ppu_set_size(Ppu *p, Uint16 width, Uint16 height) { @@ -94,3 +112,32 @@ ppu_2bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Ui blending[ch][color]); } } + +void +ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) +{ + 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); + 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); + } + /* 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); + /* 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); + } +} diff --git a/src/devices/ppu.h b/src/devices/ppu.h @@ -29,3 +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); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -40,24 +40,6 @@ static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconso static Uint8 zoom = 1; static Uint32 *ppu_screen, stdin_event, audio0_event, palette[16]; -static Uint8 font[][8] = { - {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}}; - static int clamp(int val, int min, int max) { @@ -183,40 +165,11 @@ capture_screen(void) } static void -draw_inspect(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) -{ - 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); - 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); - } - /* 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); - /* 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); - } -} - -static void redraw(Uxn *u) { Uint16 x, y; if(devsystem->dat[0xe]) - draw_inspect(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); + ppu_debug(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); 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)];