Redraw is now part of the PPU

This commit is contained in:
neauoire 2021-12-24 09:46:21 -08:00
parent 0794070adf
commit 250e338d07
3 changed files with 12 additions and 5 deletions

View File

@ -75,6 +75,16 @@ ppu_clear(Ppu *p, Uint8 mask)
p->pixels[i] &= 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 Uint8
ppu_read(Ppu *p, Uint16 x, Uint16 y) ppu_read(Ppu *p, Uint16 x, Uint16 y)
{ {

View File

@ -29,6 +29,7 @@ typedef struct Ppu {
void ppu_palette(Ppu *p, Uint8 *addr); void ppu_palette(Ppu *p, Uint8 *addr);
void ppu_resize(Ppu *p, Uint16 width, Uint16 height); void ppu_resize(Ppu *p, Uint16 width, Uint16 height);
void ppu_clear(Ppu *p, Uint8 layer); void ppu_clear(Ppu *p, Uint8 layer);
void ppu_redraw(Ppu *p, Uint32 *screen);
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y); Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y);
void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); 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); void ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);

View File

@ -152,18 +152,14 @@ capture_screen(void)
static void static void
redraw(Uxn *u) redraw(Uxn *u)
{ {
Uint16 x, y;
if(devsystem->dat[0xe]) if(devsystem->dat[0xe])
ppu_debug(&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) ppu_redraw(&ppu, ppu_screen);
for(x = 0; x < ppu.width; ++x)
ppu_screen[x + y * ppu.width] = ppu.palette[ppu_read(&ppu, x, y)];
if(SDL_UpdateTexture(gTexture, &gRect, ppu_screen, ppu.width * sizeof(Uint32)) != 0) if(SDL_UpdateTexture(gTexture, &gRect, ppu_screen, ppu.width * sizeof(Uint32)) != 0)
error("SDL_UpdateTexture", SDL_GetError()); error("SDL_UpdateTexture", SDL_GetError());
SDL_RenderClear(gRenderer); SDL_RenderClear(gRenderer);
SDL_RenderCopy(gRenderer, gTexture, NULL, NULL); SDL_RenderCopy(gRenderer, gTexture, NULL, NULL);
SDL_RenderPresent(gRenderer); SDL_RenderPresent(gRenderer);
ppu.reqdraw = 0;
} }
static void static void