... | ... |
@@ -20,15 +20,7 @@ static Uint8 blending[5][16] = { |
20 | 20 |
{1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; |
21 | 21 |
|
22 | 22 |
void |
23 |
-clear(Ppu *p) |
|
24 |
-{ |
|
25 |
- int i, sz = p->height * p->width; |
|
26 |
- for(i = 0; i < sz; ++i) |
|
27 |
- p->pixels[i] = 0x00; |
|
28 |
-} |
|
29 |
- |
|
30 |
-void |
|
31 |
-putpixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color) |
|
23 |
+ppu_pixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color) |
|
32 | 24 |
{ |
33 | 25 |
Uint8 *pixel = &p->pixels[y * p->width + x], shift = layer * 2; |
34 | 26 |
if(x < p->width && y < p->height) |
... | ... |
@@ -36,14 +28,14 @@ putpixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color) |
36 | 28 |
} |
37 | 29 |
|
38 | 30 |
void |
39 |
-puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) |
|
31 |
+ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) |
|
40 | 32 |
{ |
41 | 33 |
Uint16 v, h; |
42 | 34 |
for(v = 0; v < 8; v++) |
43 | 35 |
for(h = 0; h < 8; h++) { |
44 | 36 |
Uint8 ch1 = (sprite[v] >> (7 - h)) & 0x1; |
45 | 37 |
if(ch1 || blending[4][color]) |
46 |
- putpixel(p, |
|
38 |
+ ppu_pixel(p, |
|
47 | 39 |
layer, |
48 | 40 |
x + (flipx ? 7 - h : h), |
49 | 41 |
y + (flipy ? 7 - v : v), |
... | ... |
@@ -52,7 +44,7 @@ puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint |
52 | 44 |
} |
53 | 45 |
|
54 | 46 |
void |
55 |
-putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) |
|
47 |
+ppu_2bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) |
|
56 | 48 |
{ |
57 | 49 |
Uint16 v, h; |
58 | 50 |
for(v = 0; v < 8; v++) |
... | ... |
@@ -61,7 +53,7 @@ putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint |
61 | 53 |
Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1); |
62 | 54 |
Uint8 ch = ch1 + ch2 * 2; |
63 | 55 |
if(ch || blending[4][color]) |
64 |
- putpixel(p, |
|
56 |
+ ppu_pixel(p, |
|
65 | 57 |
layer, |
66 | 58 |
x + (flipx ? 7 - h : h), |
67 | 59 |
y + (flipy ? 7 - v : v), |
... | ... |
@@ -72,7 +64,7 @@ putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint |
72 | 64 |
/* output */ |
73 | 65 |
|
74 | 66 |
int |
75 |
-initppu(Ppu *p, Uint8 hor, Uint8 ver) |
|
67 |
+ppu_init(Ppu *p, Uint8 hor, Uint8 ver) |
|
76 | 68 |
{ |
77 | 69 |
p->hor = hor; |
78 | 70 |
p->ver = ver; |
... | ... |
@@ -22,7 +22,7 @@ typedef struct Ppu { |
22 | 22 |
Uint8 *pixels; |
23 | 23 |
} Ppu; |
24 | 24 |
|
25 |
-int initppu(Ppu *p, Uint8 hor, Uint8 ver); |
|
26 |
-void putpixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); |
|
27 |
-void puticn(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
|
28 |
-void putchr(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
|
25 |
+int ppu_init(Ppu *p, Uint8 hor, Uint8 ver); |
|
26 |
+void ppu_pixel(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 color); |
|
27 |
+void ppu_1bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
|
28 |
+void ppu_2bpp(Ppu *p, Uint8 layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
... | ... |
@@ -84,24 +84,24 @@ inspect(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) |
84 | 84 |
Uint8 i, x, y, b; |
85 | 85 |
for(i = 0; i < 0x20; ++i) { /* stack */ |
86 | 86 |
x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i]; |
87 |
- puticn(p, 1, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0); |
|
88 |
- puticn(p, 1, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0); |
|
87 |
+ ppu_1bpp(p, 1, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0); |
|
88 |
+ ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0); |
|
89 | 89 |
} |
90 | 90 |
/* return pointer */ |
91 |
- puticn(p, 1, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0); |
|
92 |
- puticn(p, 1, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0); |
|
91 |
+ ppu_1bpp(p, 1, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0); |
|
92 |
+ ppu_1bpp(p, 1, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0); |
|
93 | 93 |
for(i = 0; i < 0x20; ++i) { /* memory */ |
94 | 94 |
x = ((i % 8) * 3 + 1) * 8, y = 0x38 + (i / 8 + 1) * 8, b = memory[i]; |
95 |
- puticn(p, 1, x, y, font[(b >> 4) & 0xf], 3, 0, 0); |
|
96 |
- puticn(p, 1, x + 8, y, font[b & 0xf], 3, 0, 0); |
|
95 |
+ ppu_1bpp(p, 1, x, y, font[(b >> 4) & 0xf], 3, 0, 0); |
|
96 |
+ ppu_1bpp(p, 1, x + 8, y, font[b & 0xf], 3, 0, 0); |
|
97 | 97 |
} |
98 | 98 |
for(x = 0; x < 0x10; ++x) { /* guides */ |
99 |
- putpixel(p, 1, x, p->height / 2, 2); |
|
100 |
- putpixel(p, 1, p->width - x, p->height / 2, 2); |
|
101 |
- putpixel(p, 1, p->width / 2, p->height - x, 2); |
|
102 |
- putpixel(p, 1, p->width / 2, x, 2); |
|
103 |
- putpixel(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2); |
|
104 |
- putpixel(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2); |
|
99 |
+ ppu_pixel(p, 1, x, p->height / 2, 2); |
|
100 |
+ ppu_pixel(p, 1, p->width - x, p->height / 2, 2); |
|
101 |
+ ppu_pixel(p, 1, p->width / 2, p->height - x, 2); |
|
102 |
+ ppu_pixel(p, 1, p->width / 2, x, 2); |
|
103 |
+ ppu_pixel(p, 1, p->width / 2 - 0x10 / 2 + x, p->height / 2, 2); |
|
104 |
+ ppu_pixel(p, 1, p->width / 2, p->height / 2 - 0x10 / 2 + x, 2); |
|
105 | 105 |
} |
106 | 106 |
} |
107 | 107 |
|
... | ... |
@@ -168,7 +168,7 @@ static int |
168 | 168 |
init(void) |
169 | 169 |
{ |
170 | 170 |
SDL_AudioSpec as; |
171 |
- if(!initppu(&ppu, 64, 40)) |
|
171 |
+ if(!ppu_init(&ppu, 64, 40)) |
|
172 | 172 |
return error("ppu", "Init failure"); |
173 | 173 |
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) |
174 | 174 |
return error("sdl", SDL_GetError()); |
... | ... |
@@ -306,13 +306,13 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) |
306 | 306 |
Uint8 layer = d->dat[0xe] >> 4 & 0x1; |
307 | 307 |
Uint8 mode = d->dat[0xe] >> 5; |
308 | 308 |
if(!mode) |
309 |
- putpixel(&ppu, layer, x, y, d->dat[0xe] & 0x3); |
|
309 |
+ ppu_pixel(&ppu, layer, x, y, d->dat[0xe] & 0x3); |
|
310 | 310 |
else { |
311 | 311 |
Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; |
312 | 312 |
if(mode-- & 0x1) |
313 |
- puticn(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); |
|
313 |
+ ppu_1bpp(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); |
|
314 | 314 |
else |
315 |
- putchr(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); |
|
315 |
+ ppu_2bpp(&ppu, layer, x, y, addr, d->dat[0xe] & 0xf, mode & 0x2, mode & 0x4); |
|
316 | 316 |
} |
317 | 317 |
reqdraw = 1; |
318 | 318 |
} else if(w && b0 == 0xf) { |
... | ... |
@@ -321,9 +321,9 @@ screen_talk(Device *d, Uint8 b0, Uint8 w) |
321 | 321 |
Uint8 layer = d->dat[0xf] >> 0x6 & 0x1; |
322 | 322 |
Uint8 *addr = &d->mem[mempeek16(d->dat, 0xc)]; |
323 | 323 |
if(d->dat[0xf] >> 0x7 & 0x1) |
324 |
- putchr(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); |
|
324 |
+ ppu_2bpp(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); |
|
325 | 325 |
else |
326 |
- puticn(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); |
|
326 |
+ ppu_1bpp(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] >> 0x4 & 0x1, d->dat[0xf] >> 0x5 & 0x1); |
|
327 | 327 |
reqdraw = 1; |
328 | 328 |
} |
329 | 329 |
} |