From efd99f16e01ac5e45d6ee002ceb9e08c104c3cfd Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:12:26 -0300 Subject: [PATCH] fix: mirror SRAM SRAM is mirrored in 64K chunks TODO: According to GBATEK SRAM chips are 32K and mirrored --- src/Bus.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bus.zig b/src/Bus.zig index d0a3af4..f97f040 100644 --- a/src/Bus.zig +++ b/src/Bus.zig @@ -137,7 +137,7 @@ pub fn read8(self: *const Self, addr: u32) u8 { 0x0800_0000...0x09FF_FFFF => self.pak.get8(addr - 0x0800_0000), 0x0A00_0000...0x0BFF_FFFF => self.pak.get8(addr - 0x0A00_0000), 0x0C00_0000...0x0DFF_FFFF => self.pak.get8(addr - 0x0C00_0000), - 0x0E00_0000...0x0E00_FFFF => self.pak.sram.get8(addr - 0x0E00_0000), + 0x0E00_0000...0x0EFF_FFFF => self.pak.sram.get8(addr & 0xFFFF), else => undRead("Tried to read from 0x{X:0>2}", .{addr}), }; @@ -152,7 +152,7 @@ pub fn write8(self: *Self, addr: u32, byte: u8) void { 0x0400_0410 => log.info("Wrote 0x{X:0>2} to 0x{X:0>8}. Ignored", .{ byte, addr }), // External Memory (Game Pak) - 0x0E00_0000...0x0E00_FFFF => self.pak.sram.set8(addr - 0x0E00_0000, byte), + 0x0E00_0000...0x0E00_FFFF => self.pak.sram.set8(addr & 0xFFFF, byte), else => undWrite("Tried to write 0x{X:0>2} to 0x{X:0>8}", .{ byte, addr }), } }