| ... | ... |
@@ -41,9 +41,8 @@ putcolors(Ppu *p, Uint8 *addr) |
| 41 | 41 |
void |
| 42 | 42 |
putpixel(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
| 43 | 43 |
{
|
| 44 |
- if(x >= p->width || y >= p->height) |
|
| 45 |
- return; |
|
| 46 |
- layer->pixels[y * p->width + x] = layer->colors[color]; |
|
| 44 |
+ if(x < p->width && y < p->height) |
|
| 45 |
+ layer->pixels[y * p->width + x] = layer->colors[color]; |
|
| 47 | 46 |
} |
| 48 | 47 |
|
| 49 | 48 |
void |
| ... | ... |
@@ -52,15 +51,13 @@ puticn(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uin |
| 52 | 51 |
Uint16 v, h; |
| 53 | 52 |
for(v = 0; v < 8; v++) |
| 54 | 53 |
for(h = 0; h < 8; h++) {
|
| 55 |
- Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); |
|
| 56 |
- Uint16 px = x + (flipx ? 7 - h : h); |
|
| 57 |
- Uint16 py = y + (flipy ? 7 - v : v); |
|
| 58 |
- if(!(ch1 || color % 0x5)) |
|
| 59 |
- continue; |
|
| 60 |
- if(px < p->width && py < p->height) {
|
|
| 61 |
- Uint8 pc = ch1 ? (color & 0x3) : (color >> 0x2); |
|
| 62 |
- layer->pixels[py * p->width + px] = layer->colors[pc]; |
|
| 63 |
- } |
|
| 54 |
+ Uint8 ch1 = (sprite[v] >> (7 - h)) & 0x1; |
|
| 55 |
+ if(ch1 == 1 || (color != 0x05 && color != 0x0a && color != 0x0f)) |
|
| 56 |
+ putpixel(p, |
|
| 57 |
+ layer, |
|
| 58 |
+ x + (flipx ? 7 - h : h), |
|
| 59 |
+ y + (flipy ? 7 - v : v), |
|
| 60 |
+ ch1 ? color % 4 : color / 4); |
|
| 64 | 61 |
} |
| 65 | 62 |
} |
| 66 | 63 |
|
| ... | ... |
@@ -72,12 +69,11 @@ putchr(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uin |
| 72 | 69 |
for(h = 0; h < 8; h++) {
|
| 73 | 70 |
Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1) * color; |
| 74 | 71 |
Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1) * color; |
| 75 |
- Uint16 px = x + (flipx ? 7 - h : h); |
|
| 76 |
- Uint16 py = y + (flipy ? 7 - v : v); |
|
| 77 |
- if(px < p->width && py < p->height) {
|
|
| 78 |
- Uint8 pc = ((ch1 + ch2 * 2) + color / 4) & 0x3; |
|
| 79 |
- layer->pixels[py * p->width + px] = layer->colors[pc]; |
|
| 80 |
- } |
|
| 72 |
+ putpixel(p, |
|
| 73 |
+ layer, |
|
| 74 |
+ x + (flipx ? 7 - h : h), |
|
| 75 |
+ y + (flipy ? 7 - v : v), |
|
| 76 |
+ ((ch1 + ch2 * 2) + color / 4) & 0x3); |
|
| 81 | 77 |
} |
| 82 | 78 |
} |
| 83 | 79 |
|
| ... | ... |
@@ -97,3 +93,12 @@ initppu(Ppu *p, Uint8 hor, Uint8 ver) |
| 97 | 93 |
clear(p); |
| 98 | 94 |
return 1; |
| 99 | 95 |
} |
| 96 |
+; |
|
| 97 |
+ p->height = 8 * p->ver; |
|
| 98 |
+ if(!(p->bg.pixels = malloc(p->width * p->height * sizeof(Uint32)))) |
|
| 99 |
+ return 0; |
|
| 100 |
+ if(!(p->fg.pixels = malloc(p->width * p->height * sizeof(Uint32)))) |
|
| 101 |
+ return 0; |
|
| 102 |
+ clear(p); |
|
| 103 |
+ return 1; |
|
| 104 |
+} |