From 4018f3875b28c65e7369757820a80f781c8bf530 Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 16 Feb 2022 23:23:41 -0400 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 }),