fix(memory): ignore CPU and DMA writes to the Game Pak ROM windows

Stores to 0x08-0x0c returned ReadOnly and stopped the machine. Hardware ignores
them, and a second game's boot code stores to a ROM mirror. Emulated writes now
pay their bus cost and change nothing. The 0x0d window stays a diagnostic until
EEPROM is modeled there, and host writes stay strict.

Tests that used a ROM store as their failing write now cross an ignored ROM
word into the 0x0d window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HhfHfHEuzv2AUTd6erW1gU
This commit is contained in:
0xrsydn 2026-10-14 08:26:03 +07:00
commit 258fbff2fa
25 changed files with 86 additions and 74 deletions

View file

@ -987,7 +987,7 @@ impl Memory {
}
return Ok(());
}
if address < BIOS_SIZE as u32 {
if address < BIOS_SIZE as u32 || matches!(address >> 24, 0x08..=0x0d) {
// Only validated CPU/DMA writes reach here. Pay the bus cost but
// never modify the mapped ROM image or drive BIOS read history.
return Ok(());
@ -1123,8 +1123,11 @@ impl Memory {
Ok(0) // I/O does not use a RAM index.
}
0x08..=0x0d => {
// Game Pak ROM ignores emulated writes; host setup stays strict.
// The 0x0d window stays diagnostic until EEPROM is modeled there.
let ignored = access == WriteAccess::Emulated && address >> 24 != 0x0d;
for offset in 0..N as u32 {
if !self.cartridge_state().mapped(address + offset) {
if !ignored && !self.cartridge_state().mapped(address + offset) {
return Err(MemoryError::ReadOnly(address + offset));
}
}