fix: mirror SRAM

SRAM is mirrored in 64K chunks
TODO: According to GBATEK SRAM chips are 32K and mirrored
This commit is contained in:
Rekai Nyangadzayi Musuka 2022-03-13 05:53:26 -03:00
parent 017ec407f5
commit 025f295c08
1 changed files with 2 additions and 2 deletions

View File

@ -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 }),
}
}