From 250e338d07f97043f32880607ce120804bfee46e Mon Sep 17 00:00:00 2001 From: neauoire Date: Fri, 24 Dec 2021 09:46:21 -0800 Subject: [PATCH] Redraw is now part of the PPU --- src/devices/ppu.c | 10 ++++++++++ src/devices/ppu.h | 1 + src/uxnemu.c | 6 +----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/devices/ppu.c b/src/devices/ppu.c index 859e31a..69be827 100644 --- a/src/devices/ppu.c +++ b/src/devices/ppu.c @@ -75,6 +75,16 @@ ppu_clear(Ppu *p, Uint8 mask) p->pixels[i] &= mask; } +void +ppu_redraw(Ppu *p, Uint32 *screen) +{ + Uint16 x, y; + for(y = 0; y < p->height; ++y) + for(x = 0; x < p->width; ++x) + screen[x + y * p->width] = p->palette[ppu_read(p, x, y)]; + p->reqdraw = 0; +} + Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y) { diff --git a/src/devices/ppu.h b/src/devices/ppu.h index 15a2a2c..e30b05c 100644 --- a/src/devices/ppu.h +++ b/src/devices/ppu.h @@ -29,6 +29,7 @@ typedef struct Ppu { void ppu_palette(Ppu *p, Uint8 *addr); void ppu_resize(Ppu *p, Uint16 width, Uint16 height); void ppu_clear(Ppu *p, Uint8 layer); +void ppu_redraw(Ppu *p, Uint32 *screen); Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y); void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); void ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); diff --git a/src/uxnemu.c b/src/uxnemu.c index 101f523..d79c695 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -152,18 +152,14 @@ capture_screen(void) 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); - for(y = 0; y < ppu.height; ++y) - for(x = 0; x < ppu.width; ++x) - ppu_screen[x + y * ppu.width] = ppu.palette[ppu_read(&ppu, x, y)]; + ppu_redraw(&ppu, ppu_screen); if(SDL_UpdateTexture(gTexture, &gRect, ppu_screen, ppu.width * sizeof(Uint32)) != 0) error("SDL_UpdateTexture", SDL_GetError()); SDL_RenderClear(gRenderer); SDL_RenderCopy(gRenderer, gTexture, NULL, NULL); SDL_RenderPresent(gRenderer); - ppu.reqdraw = 0; } static void