From fd5006b29d0d749261d4e111c9727395e91eb84f Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Mon, 10 Jan 2022 07:23:54 -0400 Subject: [PATCH] fix(ppu): properly access Mode 4 palette --- src/ppu.zig | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ppu.zig b/src/ppu.zig index f41c0de..ac2c72e 100644 --- a/src/ppu.zig +++ b/src/ppu.zig @@ -53,18 +53,16 @@ pub const Ppu = struct { const frame_select = io.dispcnt.frame_select.read(); const fb_start = buf_pitch * @as(usize, scanline); - const vram_start = width * @as(usize, scanline); + const vram_start = fb_start >> 1; const start = if (frame_select) 0xA000 + vram_start else vram_start; const end = start + width; for (self.vram.buf[start..end]) |byte, i| { const fb_i = i * @sizeOf(u16); - const colour = self.palette.buf[byte]; - var bgr555: u16 = colour & 0x3 | (colour & 0x1C >> 2) << 5 | @as(u16, colour >> 5) << 10; - self.frame_buf[fb_start + fb_i + 1] = @truncate(u8, bgr555 >> 8); - self.frame_buf[fb_start + fb_i] = @truncate(u8, bgr555); + self.frame_buf[fb_start + fb_i + 1] = self.palette.buf[byte + 1]; + self.frame_buf[fb_start + fb_i] = self.palette.buf[byte]; } }, else => std.debug.panic("[PPU] TODO: Implement BG Mode {}", .{bg_mode}),