Optimized ppu_redraw

This commit is contained in:
neauoire 2021-12-24 10:10:55 -08:00
parent cc6f2c8b29
commit 0a040824b7
2 changed files with 8 additions and 14 deletions

View File

@ -12,8 +12,6 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
/* byte: p0-bg | p0-fg | p1-bg | p1-fg */
static Uint8 blending[5][16] = {
{0, 0, 0, 0, 1, 0, 1, 1, 2, 2, 0, 2, 3, 3, 3, 0},
{0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3},
@ -58,10 +56,10 @@ ppu_palette(Ppu *p, Uint8 *addr)
void
ppu_resize(Ppu *p, Uint16 width, Uint16 height)
{
Uint8 *bg, *fg;
if(!(bg = realloc(p->bg, width * height)))
return;
if(!(fg = realloc(p->fg, width * height)))
Uint8
*bg = realloc(p->bg, width * height),
*fg = realloc(p->fg, width * height);
if(!bg || !fg)
return;
p->bg = bg;
p->fg = fg;
@ -82,13 +80,9 @@ ppu_clear(Ppu *p, Uint8 *layer)
void
ppu_redraw(Ppu *p, Uint32 *screen)
{
Uint16 x, y;
for(y = 0; y < p->height; ++y)
for(x = 0; x < p->width; ++x) {
Uint32 row = (x + y * p->width);
Uint8 color = p->fg[row] ? p->fg[row] : p->bg[row];
screen[x + y * p->width] = p->palette[color];
}
Uint32 i, size = p->width * p->height;
for(i = 0; i < size; ++i)
screen[i] = p->palette[p->fg[i] ? p->fg[i] : p->bg[i]];
p->reqdraw = 0;
}

View File

@ -30,7 +30,7 @@ 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);
void ppu_2bpp(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy);