From 2a3d0c8b0d5d39310d067848befde4d609d571b9 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:21 -0300 Subject: [PATCH] chore: properly write to VOFS and HOFS in 32-bit bus --- src/bus/io.zig | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/bus/io.zig b/src/bus/io.zig index 4bef89c..c9b0722 100644 --- a/src/bus/io.zig +++ b/src/bus/io.zig @@ -142,14 +142,22 @@ pub fn read32(bus: *const Bus, addr: u32) u32 { pub fn write32(bus: *Bus, addr: u32, word: u32) void { switch (addr) { 0x0400_0000 => bus.ppu.dispcnt.raw = @truncate(u16, word), - 0x0400_0010 => bus.ppu.bg[0].hofs.raw = @truncate(u16, word), // TODO: Don't write out every HOFS / VOFS? - 0x0400_0012 => bus.ppu.bg[0].vofs.raw = @truncate(u16, word), - 0x0400_0014 => bus.ppu.bg[1].hofs.raw = @truncate(u16, word), - 0x0400_0016 => bus.ppu.bg[1].vofs.raw = @truncate(u16, word), - 0x0400_0018 => bus.ppu.bg[2].hofs.raw = @truncate(u16, word), - 0x0400_001A => bus.ppu.bg[2].vofs.raw = @truncate(u16, word), - 0x0400_001C => bus.ppu.bg[3].hofs.raw = @truncate(u16, word), - 0x0400_001E => bus.ppu.bg[3].vofs.raw = @truncate(u16, word), + 0x0400_0010 => { + bus.ppu.bg[0].hofs.raw = @truncate(u16, word); + bus.ppu.bg[0].vofs.raw = @truncate(u16, word >> 16); + }, + 0x0400_0014 => { + bus.ppu.bg[1].hofs.raw = @truncate(u16, word); + bus.ppu.bg[1].vofs.raw = @truncate(u16, word >> 16); + }, + 0x0400_0018 => { + bus.ppu.bg[2].hofs.raw = @truncate(u16, word); + bus.ppu.bg[2].vofs.raw = @truncate(u16, word >> 16); + }, + 0x0400_001C => { + bus.ppu.bg[3].hofs.raw = @truncate(u16, word); + bus.ppu.bg[3].vofs.raw = @truncate(u16, word >> 16); + }, 0x0400_0200 => bus.io.ie.raw = @truncate(u16, word), 0x0400_0208 => bus.io.ime = word & 1 == 1, else => std.debug.panic("[I/O:32] tried to write 0x{X:} to 0x{X:}", .{ word, addr }),