feat(ppu): implement Mode 4

Implementation is not tested. Pending on LDM and STM so that I can
run beeg.gba
This commit is contained in:
Rekai Nyangadzayi Musuka 2022-01-10 02:41:48 -04:00
parent 2467b94dbd
commit 7c5d2d2389
1 changed files with 18 additions and 1 deletions

View File

@ -44,12 +44,29 @@ pub const Ppu = struct {
switch (bg_mode) { switch (bg_mode) {
0x3 => { 0x3 => {
// Mode 3
const start = buf_pitch * @as(usize, scanline); const start = buf_pitch * @as(usize, scanline);
const end = start + buf_pitch; const end = start + buf_pitch;
std.mem.copy(u8, self.frame_buf[start..end], self.vram.buf[start..end]); 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}), else => std.debug.panic("[PPU] TODO: Implement BG Mode {}", .{bg_mode}),
} }
} }