From 69cfef46beafe0ee7cc5122ef01d88adea8e62f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Solveig=20Hafl=C3=ADnud=C3=B3ttir?= Date: Sat, 25 Dec 2021 22:42:34 +0100 Subject: [PATCH] ppu_palette: rewrite for more readability --- src/devices/ppu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/devices/ppu.c b/src/devices/ppu.c index 603ca47..9dae9d9 100644 --- a/src/devices/ppu.c +++ b/src/devices/ppu.c @@ -40,13 +40,14 @@ static Uint8 font[][8] = { void ppu_palette(Ppu *p, Uint8 *addr) { - int i; - for(i = 0; i < 4; ++i) { + int i, shift; + for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) { Uint8 - r = (*(addr + i / 2) >> (!(i % 2) << 2)) & 0x0f, - g = (*(addr + 2 + i / 2) >> (!(i % 2) << 2)) & 0x0f, - b = (*(addr + 4 + i / 2) >> (!(i % 2) << 2)) & 0x0f; - p->palette[i] = 0xff000000 | (r << 20) | (r << 16) | (g << 12) | (g << 8) | (b << 4) | b; + r = (addr[0 + i / 2] >> shift) & 0x0f, + g = (addr[2 + i / 2] >> shift) & 0x0f, + b = (addr[4 + i / 2] >> shift) & 0x0f; + p->palette[i] = 0x0f000000 | r << 16 | g << 8 | b; + p->palette[i] |= p->palette[i] << 4; } p->fg.changed = p->bg.changed = 1; }