... | ... |
@@ -19,6 +19,12 @@ 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 Uint16 |
|
23 |
+ppu_row(Ppu *p, Uint16 x, Uint16 y) |
|
24 |
+{ |
|
25 |
+ return (y % 8) + ((x / 8 + y / 8 * p->width / 8) * 16); |
|
26 |
+} |
|
27 |
+ |
|
22 | 28 |
static void |
23 | 29 |
ppu_clear(Ppu *p) |
24 | 30 |
{ |
... | ... |
@@ -34,12 +40,12 @@ ppu_clear(Ppu *p) |
34 | 40 |
Uint8 |
35 | 41 |
ppu_read(Ppu *p, Uint16 x, Uint16 y) |
36 | 42 |
{ |
37 |
- int ch1, ch2, r = (y % 8) + ((x / 8 + y / 8 * p->width / 8) * 16); |
|
38 |
- ch1 = (p->fg[r] >> (7 - x % 8)) & 1; |
|
39 |
- ch2 = (p->fg[r + 8] >> (7 - x % 8)) & 1; |
|
43 |
+ Uint16 ch1, ch2, row = ppu_row(p, x, y); |
|
44 |
+ ch1 = (p->fg[row] >> (7 - x % 8)) & 1; |
|
45 |
+ ch2 = (p->fg[row + 8] >> (7 - x % 8)) & 1; |
|
40 | 46 |
if(!ch1 && !ch2) { |
41 |
- ch1 = (p->bg[r] >> (7 - x % 8)) & 1; |
|
42 |
- ch2 = (p->bg[r + 8] >> (7 - x % 8)) & 1; |
|
47 |
+ ch1 = (p->bg[row] >> (7 - x % 8)) & 1; |
|
48 |
+ ch2 = (p->bg[row + 8] >> (7 - x % 8)) & 1; |
|
43 | 49 |
} |
44 | 50 |
return ch1 + (ch2 << 1); |
45 | 51 |
} |
... | ... |
@@ -47,17 +53,17 @@ ppu_read(Ppu *p, Uint16 x, Uint16 y) |
47 | 53 |
void |
48 | 54 |
ppu_write(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color) |
49 | 55 |
{ |
50 |
- int row = (y % 8) + ((x / 8 + y / 8 * p->width / 8) * 16), col = x % 8; |
|
56 |
+ Uint16 row = ppu_row(p, x, y), col = 7 - (x % 8); |
|
51 | 57 |
if(x >= p->width || y >= p->height) |
52 | 58 |
return; |
53 | 59 |
if(color == 0 || color == 2) |
54 |
- layer[row] &= ~(1UL << (7 - col)); |
|
60 |
+ layer[row] &= ~(1UL << col); |
|
55 | 61 |
else |
56 |
- layer[row] |= 1UL << (7 - col); |
|
62 |
+ layer[row] |= 1UL << col; |
|
57 | 63 |
if(color == 0 || color == 1) |
58 |
- layer[row + 8] &= ~(1UL << (7 - col)); |
|
64 |
+ layer[row + 8] &= ~(1UL << col); |
|
59 | 65 |
else |
60 |
- layer[row + 8] |= 1UL << (7 - col); |
|
66 |
+ layer[row + 8] |= 1UL << col; |
|
61 | 67 |
} |
62 | 68 |
|
63 | 69 |
void |