Do not overdraw

This commit is contained in:
neauoire 2021-09-30 19:35:22 -07:00
parent 765724d2af
commit 243c5866ac
1 changed files with 20 additions and 15 deletions

View File

@ -41,6 +41,7 @@ ppu_set_size(Ppu *p, Uint16 width, Uint16 height)
Uint8 Uint8
ppu_read(Ppu *p, Uint16 x, Uint16 y) ppu_read(Ppu *p, Uint16 x, Uint16 y)
{ {
if(x < p->width && y < p->height) {
Uint32 row = (x + y * p->width) / 0x2; Uint32 row = (x + y * p->width) / 0x2;
Uint8 shift = !(x & 0x1) << 2; Uint8 shift = !(x & 0x1) << 2;
Uint8 pix = p->pixels[row] >> shift; Uint8 pix = p->pixels[row] >> shift;
@ -48,10 +49,13 @@ ppu_read(Ppu *p, Uint16 x, Uint16 y)
pix = pix >> 2; pix = pix >> 2;
return pix & 0x3; return pix & 0x3;
} }
return 0x0;
}
void void
ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color) ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color)
{ {
if(x < p->width && y < p->height) {
Uint32 row = (x + y * p->width) / 0x2; Uint32 row = (x + y * p->width) / 0x2;
Uint8 shift = (!(x & 0x1) << 2) + (layer << 1); Uint8 shift = (!(x & 0x1) << 2) + (layer << 1);
Uint8 pix = p->pixels[row]; Uint8 pix = p->pixels[row];
@ -62,6 +66,7 @@ ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color)
if(pix != pixnew) if(pix != pixnew)
p->reqdraw = 1; p->reqdraw = 1;
} }
}
void void
ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy)