| ... | ... |
@@ -19,23 +19,16 @@ 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 |
- Uint32 row, bound = p->height * p->width / 2; |
|
| 26 |
- for(row = 0; row < bound; ++row) |
|
| 27 |
- p->pixels[row] = 0; |
|
| 28 |
-} |
|
| 29 |
- |
|
| 30 |
-Uint8 |
|
| 22 |
+void |
|
| 31 | 23 |
ppu_set_size(Ppu *p, Uint16 width, Uint16 height) |
| 32 | 24 |
{
|
| 33 |
- ppu_clear(p); |
|
| 25 |
+ Uint8 *pixels; |
|
| 26 |
+ if(!(pixels = realloc(p->pixels, width * height / 2))) |
|
| 27 |
+ return; |
|
| 28 |
+ memset(pixels, 0, width * height / 2); |
|
| 29 |
+ p->pixels = pixels; |
|
| 34 | 30 |
p->width = width; |
| 35 | 31 |
p->height = height; |
| 36 |
- p->pixels = realloc(p->pixels, p->width * p->height * sizeof(Uint8) / 2); |
|
| 37 |
- ppu_clear(p); |
|
| 38 |
- return !!p->pixels; |
|
| 39 | 32 |
} |
| 40 | 33 |
|
| 41 | 34 |
Uint8 |
| ... | ... |
@@ -1,5 +1,6 @@ |
| 1 | 1 |
#include <stdio.h> |
| 2 | 2 |
#include <stdlib.h> |
| 3 |
+#include <string.h> |
|
| 3 | 4 |
|
| 4 | 5 |
/* |
| 5 | 6 |
Copyright (c) 2021 Devine Lu Linvega |
| ... | ... |
@@ -22,7 +23,7 @@ typedef struct Ppu {
|
| 22 | 23 |
Uint16 width, height; |
| 23 | 24 |
} Ppu; |
| 24 | 25 |
|
| 25 |
-Uint8 ppu_set_size(Ppu *p, Uint16 width, Uint16 height); |
|
| 26 |
+void ppu_set_size(Ppu *p, Uint16 width, Uint16 height); |
|
| 26 | 27 |
Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y); |
| 27 | 28 |
void ppu_write(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); |
| 28 | 29 |
void ppu_frame(Ppu *p); |