0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-16 11:15:06 +00:00

Do not overdraw

This commit is contained in:
neauoire 2021-09-30 19:35:22 -07:00
parent 765724d2af
commit 243c5866ac

View file

@ -41,26 +41,31 @@ 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)
{ {
Uint32 row = (x + y * p->width) / 0x2; if(x < p->width && y < p->height) {
Uint8 shift = !(x & 0x1) << 2; Uint32 row = (x + y * p->width) / 0x2;
Uint8 pix = p->pixels[row] >> shift; Uint8 shift = !(x & 0x1) << 2;
if(pix & 0x0c) Uint8 pix = p->pixels[row] >> shift;
pix = pix >> 2; if(pix & 0x0c)
return pix & 0x3; pix = pix >> 2;
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)
{ {
Uint32 row = (x + y * p->width) / 0x2; if(x < p->width && y < p->height) {
Uint8 shift = (!(x & 0x1) << 2) + (layer << 1); Uint32 row = (x + y * p->width) / 0x2;
Uint8 pix = p->pixels[row]; Uint8 shift = (!(x & 0x1) << 2) + (layer << 1);
Uint8 mask = ~(0x3 << shift); Uint8 pix = p->pixels[row];
Uint8 pixnew = (pix & mask) + (color << shift); Uint8 mask = ~(0x3 << shift);
if(x < p->width && y < p->height) Uint8 pixnew = (pix & mask) + (color << shift);
p->pixels[row] = pixnew; if(x < p->width && y < p->height)
if(pix != pixnew) p->pixels[row] = pixnew;
p->reqdraw = 1; if(pix != pixnew)
p->reqdraw = 1;
}
} }
void void