ppu_palette: rewrite for more readability

This commit is contained in:
Sigrid Solveig Haflínudóttir 2021-12-25 22:42:34 +01:00
parent 8d4e7d54e1
commit 69cfef46be
1 changed files with 7 additions and 6 deletions

View File

@ -40,13 +40,14 @@ static Uint8 font[][8] = {
void void
ppu_palette(Ppu *p, Uint8 *addr) ppu_palette(Ppu *p, Uint8 *addr)
{ {
int i; int i, shift;
for(i = 0; i < 4; ++i) { for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) {
Uint8 Uint8
r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f, r = (addr[0 + i / 2] >> shift) & 0x0f,
g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f, g = (addr[2 + i / 2] >> shift) & 0x0f,
b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; b = (addr[4 + i / 2] >> shift) & 0x0f;
p->palette[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b; p->palette[i] = 0x0f000000 | r << 16 | g << 8 | b;
p->palette[i] |= p->palette[i] << 4;
} }
p->fg.changed = p->bg.changed = 1; p->fg.changed = p->bg.changed = 1;
} }