commit 3d5e7f7e4875a5fd8b7fd0dea7c6a0c1a9d80598
parent 51770be781a095a31a1dddf3ed8977c90b0439ba
Author: neauoire <aliceffekt@gmail.com>
Date: Wed, 28 Apr 2021 13:17:11 -0700
Fixed PPU
Diffstat:
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/ppu.c b/src/ppu.c
@@ -41,13 +41,12 @@ readpixel(Uint8 *sprite, Uint8 h, Uint8 v)
void
clear(Ppu *p)
{
- int i, sz = p->height * p->width;
- for(i = 0; i < sz; ++i) {
+ int i, sz = p->height * p->width, rows = sz / 4;
+ for(i = 0; i < sz; ++i)
p->output[i] = p->colors[0];
+ for(i = 0; i < rows; i++) {
p->fg[i] = 0;
p->bg[i] = 0;
- p->fg[sz + i] = 0;
- p->bg[sz + i] = 0;
}
}
@@ -160,9 +159,9 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad)
p->height = (8 * p->ver + p->pad * 2);
if(!(p->output = malloc(p->width * p->height * sizeof(Uint32))))
return 0;
- if(!(p->bg = malloc(p->width * p->height * sizeof(Uint8) * 2)))
+ if(!(p->bg = malloc(p->width * p->height * sizeof(Uint8) / 4)))
return 0;
- if(!(p->fg = malloc(p->width * p->height * sizeof(Uint8) * 2)))
+ if(!(p->fg = malloc(p->width * p->height * sizeof(Uint8) / 4)))
return 0;
clear(p);
return 1;