0
0
Fork 0
mirror of https://git.sr.ht/~rabbits/uxn synced 2024-11-23 22:35:11 +00:00

Minor cleanup

This commit is contained in:
neauoire 2021-09-29 20:05:26 -07:00
parent 92e44e4314
commit 253be6f50c

View file

@ -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}, {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}}; {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 static void
ppu_clear(Ppu *p) ppu_clear(Ppu *p)
{ {
@ -34,12 +40,12 @@ ppu_clear(Ppu *p)
Uint8 Uint8
ppu_read(Ppu *p, Uint16 x, Uint16 y) ppu_read(Ppu *p, Uint16 x, Uint16 y)
{ {
int ch1, ch2, r = (y % 8) + ((x / 8 + y / 8 * p->width / 8) * 16); Uint16 ch1, ch2, row = ppu_row(p, x, y);
ch1 = (p->fg[r] >> (7 - x % 8)) & 1; ch1 = (p->fg[row] >> (7 - x % 8)) & 1;
ch2 = (p->fg[r + 8] >> (7 - x % 8)) & 1; ch2 = (p->fg[row + 8] >> (7 - x % 8)) & 1;
if(!ch1 && !ch2) { if(!ch1 && !ch2) {
ch1 = (p->bg[r] >> (7 - x % 8)) & 1; ch1 = (p->bg[row] >> (7 - x % 8)) & 1;
ch2 = (p->bg[r + 8] >> (7 - x % 8)) & 1; ch2 = (p->bg[row + 8] >> (7 - x % 8)) & 1;
} }
return ch1 + (ch2 << 1); return ch1 + (ch2 << 1);
} }
@ -47,17 +53,17 @@ ppu_read(Ppu *p, Uint16 x, Uint16 y)
void void
ppu_write(Ppu *p, Uint8 *layer, Uint16 x, Uint16 y, Uint8 color) 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) if(x >= p->width || y >= p->height)
return; return;
if(color == 0 || color == 2) if(color == 0 || color == 2)
layer[row] &= ~(1UL << (7 - col)); layer[row] &= ~(1UL << col);
else else
layer[row] |= 1UL << (7 - col); layer[row] |= 1UL << col;
if(color == 0 || color == 1) if(color == 0 || color == 1)
layer[row + 8] &= ~(1UL << (7 - col)); layer[row + 8] &= ~(1UL << col);
else else
layer[row + 8] |= 1UL << (7 - col); layer[row + 8] |= 1UL << col;
} }
void void