uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 253be6f50c2f685ca9cd59188e61c18c7c104b1f
parent 92e44e43147e693b2737f030df5503c56a09665d
Author: neauoire <aliceffekt@gmail.com>
Date:   Wed, 29 Sep 2021 20:05:26 -0700

Minor cleanup

Diffstat:
Msrc/devices/ppu.c | 26++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/devices/ppu.c b/src/devices/ppu.c @@ -19,6 +19,12 @@ static Uint8 blending[5][16] = { {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}, {1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0}}; +static Uint16 +ppu_row(Ppu *p, Uint16 x, Uint16 y) +{ + return (y % 8) + ((x / 8 + y / 8 * p->width / 8) * 16); +} + static void ppu_clear(Ppu *p) { @@ -34,12 +40,12 @@ ppu_clear(Ppu *p) Uint8 ppu_read(Ppu *p, Uint16 x, Uint16 y) { - int ch1, ch2, r = (y % 8) + ((x / 8 + y / 8 * p->width / 8) * 16); - ch1 = (p->fg[r] >> (7 - x % 8)) & 1; - ch2 = (p->fg[r + 8] >> (7 - x % 8)) & 1; + Uint16 ch1, ch2, row = ppu_row(p, x, y); + ch1 = (p->fg[row] >> (7 - x % 8)) & 1; + ch2 = (p->fg[row + 8] >> (7 - x % 8)) & 1; if(!ch1 && !ch2) { - ch1 = (p->bg[r] >> (7 - x % 8)) & 1; - ch2 = (p->bg[r + 8] >> (7 - x % 8)) & 1; + ch1 = (p->bg[row] >> (7 - x % 8)) & 1; + ch2 = (p->bg[row + 8] >> (7 - x % 8)) & 1; } return ch1 + (ch2 << 1); } @@ -47,17 +53,17 @@ ppu_read(Ppu *p, Uint16 x, Uint16 y) void ppu_write(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color) { - int row = (y % 8) + ((x / 8 + y / 8 * p->width / 8) * 16), col = x % 8; + Uint16 row = ppu_row(p, x, y), col = 7 - (x % 8); if(x >= p->width || y >= p->height) return; if(color == 0 || color == 2) - layer[row] &= ~(1UL << (7 - col)); + layer[row] &= ~(1UL << col); else - layer[row] |= 1UL << (7 - col); + layer[row] |= 1UL << col; if(color == 0 || color == 1) - layer[row + 8] &= ~(1UL << (7 - col)); + layer[row + 8] &= ~(1UL << col); else - layer[row + 8] |= 1UL << (7 - col); + layer[row + 8] |= 1UL << col; } void