... | ... |
@@ -19,6 +19,18 @@ static Uint8 blending[5][16] = { |
19 | 19 |
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}, |
20 | 20 |
{1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; |
21 | 21 |
|
22 |
+static void |
|
23 |
+ppu_clear(Ppu *p) |
|
24 |
+{ |
|
25 |
+ int x, y; |
|
26 |
+ for(y = 0; y < p->height; ++y) { |
|
27 |
+ for(x = 0; x < p->width; ++x) { |
|
28 |
+ ppu_pixel(p, p->bg, x, y, 0); |
|
29 |
+ ppu_pixel(p, p->fg, x, y, 0); |
|
30 |
+ } |
|
31 |
+ } |
|
32 |
+} |
|
33 |
+ |
|
22 | 34 |
void |
23 | 35 |
ppu_pixel(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color) |
24 | 36 |
{ |
... | ... |
@@ -78,15 +90,18 @@ ppu_init(Ppu *p, Uint8 hor, Uint8 ver) |
78 | 90 |
p->height = 8 * ver; |
79 | 91 |
p->bg = calloc(1, p->width / 4 * p->height * sizeof(Uint8)); |
80 | 92 |
p->fg = calloc(1, p->width / 4 * p->height * sizeof(Uint8)); |
93 |
+ ppu_clear(p); |
|
81 | 94 |
return p->bg && p->fg; |
82 | 95 |
} |
83 | 96 |
|
84 | 97 |
int |
85 | 98 |
ppu_resize(Ppu *p, Uint8 hor, Uint8 ver) |
86 | 99 |
{ |
100 |
+ ppu_clear(p); |
|
87 | 101 |
p->width = 8 * hor; |
88 | 102 |
p->height = 8 * ver; |
89 | 103 |
p->bg = realloc(p->bg, p->width / 4 * p->height * sizeof(Uint8)); |
90 | 104 |
p->fg = realloc(p->fg, p->width / 4 * p->height * sizeof(Uint8)); |
105 |
+ ppu_clear(p); |
|
91 | 106 |
return p->bg && p->fg; |
92 | 107 |
} |
93 | 108 |
\ No newline at end of file |
... | ... |
@@ -298,11 +298,6 @@ update_palette(Uint8 *addr) |
298 | 298 |
void |
299 | 299 |
set_size(Uint16 width, Uint16 height) |
300 | 300 |
{ |
301 |
- int i; |
|
302 |
- /* clear */ |
|
303 |
- for(i = 0; i < ppu.height * ppu.width; ++i) |
|
304 |
- ppu_screen[i] = palette[0]; |
|
305 |
- /* resize */ |
|
306 | 301 |
ppu_resize(&ppu, width / 8, height / 8); |
307 | 302 |
gRect.w = ppu.width; |
308 | 303 |
gRect.h = ppu.height; |