... | ... |
@@ -41,13 +41,12 @@ readpixel(Uint8 *sprite, Uint8 h, Uint8 v) |
41 | 41 |
void |
42 | 42 |
clear(Ppu *p) |
43 | 43 |
{ |
44 |
- int i, sz = p->height * p->width; |
|
45 |
- for(i = 0; i < sz; ++i) { |
|
44 |
+ int i, sz = p->height * p->width, rows = sz / 4; |
|
45 |
+ for(i = 0; i < sz; ++i) |
|
46 | 46 |
p->output[i] = p->colors[0]; |
47 |
+ for(i = 0; i < rows; i++) { |
|
47 | 48 |
p->fg[i] = 0; |
48 | 49 |
p->bg[i] = 0; |
49 |
- p->fg[sz + i] = 0; |
|
50 |
- p->bg[sz + i] = 0; |
|
51 | 50 |
} |
52 | 51 |
} |
53 | 52 |
|
... | ... |
@@ -160,9 +159,9 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver, Uint8 pad) |
160 | 159 |
p->height = (8 * p->ver + p->pad * 2); |
161 | 160 |
if(!(p->output = malloc(p->width * p->height * sizeof(Uint32)))) |
162 | 161 |
return 0; |
163 |
- if(!(p->bg = malloc(p->width * p->height * sizeof(Uint8) * 2))) |
|
162 |
+ if(!(p->bg = malloc(p->width * p->height * sizeof(Uint8) / 4))) |
|
164 | 163 |
return 0; |
165 |
- if(!(p->fg = malloc(p->width * p->height * sizeof(Uint8) * 2))) |
|
164 |
+ if(!(p->fg = malloc(p->width * p->height * sizeof(Uint8) / 4))) |
|
166 | 165 |
return 0; |
167 | 166 |
clear(p); |
168 | 167 |
return 1; |