From 3590215d33a3f9b3b307fd5de64a2f33f1199f05 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:11:52 -0300 Subject: [PATCH] feat(ppu): implement Mode 4 Implementation is not tested. Pending on LDM and STM so that I can run beeg.gba --- src/ppu.zig | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ppu.zig b/src/ppu.zig index 3a59544..f41c0de 100644 --- a/src/ppu.zig +++ b/src/ppu.zig @@ -44,12 +44,29 @@ pub const Ppu = struct { switch (bg_mode) { 0x3 => { - // Mode 3 const start = buf_pitch * @as(usize, scanline); const end = start + buf_pitch; std.mem.copy(u8, self.frame_buf[start..end], self.vram.buf[start..end]); }, + 0x4 => { + const frame_select = io.dispcnt.frame_select.read(); + + const fb_start = buf_pitch * @as(usize, scanline); + const vram_start = width * @as(usize, scanline); + + 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); + } + }, else => std.debug.panic("[PPU] TODO: Implement BG Mode {}", .{bg_mode}), } }