| ... | ... |
@@ -91,7 +91,7 @@ void |
| 91 | 91 |
ppu_write(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
| 92 | 92 |
{
|
| 93 | 93 |
if(x < p->width && y < p->height) {
|
| 94 |
- Uint32 i = (x + y * p->width); |
|
| 94 |
+ Uint32 i = x + y * p->width; |
|
| 95 | 95 |
Uint8 prev = layer->pixels[i]; |
| 96 | 96 |
if(color != prev) {
|
| 97 | 97 |
layer->pixels[i] = color; |
| ... | ... |
@@ -101,30 +101,14 @@ ppu_write(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
| 101 | 101 |
} |
| 102 | 102 |
|
| 103 | 103 |
void |
| 104 |
-ppu_1bpp(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) |
|
| 104 |
+ppu_blit(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp) |
|
| 105 | 105 |
{
|
| 106 | 106 |
Uint16 v, h; |
| 107 | 107 |
for(v = 0; v < 8; ++v) |
| 108 | 108 |
for(h = 0; h < 8; ++h) {
|
| 109 |
- Uint8 ch1 = (sprite[v] >> (7 - h)) & 0x1; |
|
| 110 |
- if(ch1 || blending[4][color]) |
|
| 111 |
- ppu_write(p, |
|
| 112 |
- layer, |
|
| 113 |
- x + (flipx ? 7 - h : h), |
|
| 114 |
- y + (flipy ? 7 - v : v), |
|
| 115 |
- blending[ch1][color]); |
|
| 116 |
- } |
|
| 117 |
-} |
|
| 118 |
- |
|
| 119 |
-void |
|
| 120 |
-ppu_2bpp(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy) |
|
| 121 |
-{
|
|
| 122 |
- Uint16 v, h; |
|
| 123 |
- for(v = 0; v < 8; ++v) |
|
| 124 |
- for(h = 0; h < 8; ++h) {
|
|
| 125 |
- Uint8 ch1 = ((sprite[v] >> (7 - h)) & 0x1); |
|
| 126 |
- Uint8 ch2 = ((sprite[v + 8] >> (7 - h)) & 0x1); |
|
| 127 |
- Uint8 ch = ch1 + ch2 * 2; |
|
| 109 |
+ Uint8 ch = (sprite[v + 0] >> (7 - h)) & 0x1; |
|
| 110 |
+ if(twobpp) |
|
| 111 |
+ ch |= ((sprite[v + 8] >> (7 - h)) & 0x1) << 1; |
|
| 128 | 112 |
if(ch || blending[4][color]) |
| 129 | 113 |
ppu_write(p, |
| 130 | 114 |
layer, |
| ... | ... |
@@ -141,17 +125,17 @@ ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory) |
| 141 | 125 |
for(i = 0; i < 0x20; ++i) {
|
| 142 | 126 |
x = ((i % 8) * 3 + 1) * 8, y = (i / 8 + 1) * 8, b = stack[i]; |
| 143 | 127 |
/* working stack */ |
| 144 |
- ppu_1bpp(p, &p->fg, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0); |
|
| 145 |
- ppu_1bpp(p, &p->fg, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0); |
|
| 128 |
+ ppu_blit(p, &p->fg, x, y, font[(b >> 4) & 0xf], 1 + (wptr == i) * 0x7, 0, 0, 0); |
|
| 129 |
+ ppu_blit(p, &p->fg, x + 8, y, font[b & 0xf], 1 + (wptr == i) * 0x7, 0, 0, 0); |
|
| 146 | 130 |
y = 0x28 + (i / 8 + 1) * 8; |
| 147 | 131 |
b = memory[i]; |
| 148 | 132 |
/* return stack */ |
| 149 |
- ppu_1bpp(p, &p->fg, x, y, font[(b >> 4) & 0xf], 3, 0, 0); |
|
| 150 |
- ppu_1bpp(p, &p->fg, x + 8, y, font[b & 0xf], 3, 0, 0); |
|
| 133 |
+ ppu_blit(p, &p->fg, x, y, font[(b >> 4) & 0xf], 3, 0, 0, 0); |
|
| 134 |
+ ppu_blit(p, &p->fg, x + 8, y, font[b & 0xf], 3, 0, 0, 0); |
|
| 151 | 135 |
} |
| 152 | 136 |
/* return pointer */ |
| 153 |
- ppu_1bpp(p, &p->fg, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0); |
|
| 154 |
- ppu_1bpp(p, &p->fg, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0); |
|
| 137 |
+ ppu_blit(p, &p->fg, 0x8, y + 0x10, font[(rptr >> 4) & 0xf], 0x2, 0, 0, 0); |
|
| 138 |
+ ppu_blit(p, &p->fg, 0x10, y + 0x10, font[rptr & 0xf], 0x2, 0, 0, 0); |
|
| 155 | 139 |
/* guides */ |
| 156 | 140 |
for(x = 0; x < 0x10; ++x) {
|
| 157 | 141 |
ppu_write(p, &p->fg, x, p->height / 2, 2); |
| ... | ... |
@@ -37,6 +37,5 @@ void ppu_clear(Ppu *p, Layer *layer); |
| 37 | 37 |
void ppu_redraw(Ppu *p, Uint32 *screen); |
| 38 | 38 |
|
| 39 | 39 |
void ppu_write(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color); |
| 40 |
-void ppu_1bpp(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
|
| 41 |
-void ppu_2bpp(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy); |
|
| 40 |
+void ppu_blit(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp); |
|
| 42 | 41 |
void ppu_debug(Ppu *p, Uint8 *stack, Uint8 wptr, Uint8 rptr, Uint8 *memory); |
| ... | ... |
@@ -299,15 +299,11 @@ screen_deo(Device *d, Uint8 port) |
| 299 | 299 |
case 0xf: {
|
| 300 | 300 |
Uint16 x = peek16(d->dat, 0x8); |
| 301 | 301 |
Uint16 y = peek16(d->dat, 0xa); |
| 302 |
- Uint8 layer = d->dat[0xf] & 0x40; |
|
| 302 |
+ Layer *layer = (d->dat[0xf] & 0x40) ? &ppu.fg : &ppu.bg; |
|
| 303 | 303 |
Uint8 *addr = &d->mem[peek16(d->dat, 0xc)]; |
| 304 |
- if(d->dat[0xf] & 0x80) {
|
|
| 305 |
- ppu_2bpp(&ppu, layer ? &ppu.fg : &ppu.bg, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20); |
|
| 306 |
- if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 16); /* auto addr+16 */ |
|
| 307 |
- } else {
|
|
| 308 |
- ppu_1bpp(&ppu, layer ? &ppu.fg : &ppu.bg, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20); |
|
| 309 |
- if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8); /* auto addr+8 */ |
|
| 310 |
- } |
|
| 304 |
+ Uint8 twobpp = !!(d->dat[0xf] & 0x80); |
|
| 305 |
+ ppu_blit(&ppu, layer, x, y, addr, d->dat[0xf] & 0xf, d->dat[0xf] & 0x10, d->dat[0xf] & 0x20, twobpp); |
|
| 306 |
+ if(d->dat[0x6] & 0x04) poke16(d->dat, 0xc, peek16(d->dat, 0xc) + 8 + twobpp*8); /* auto addr+8 / auto addr+16 */ |
|
| 311 | 307 |
if(d->dat[0x6] & 0x01) poke16(d->dat, 0x8, x + 8); /* auto x+8 */ |
| 312 | 308 |
if(d->dat[0x6] & 0x02) poke16(d->dat, 0xa, y + 8); /* auto y+8 */ |
| 313 | 309 |
break; |