Skip to content

Commit

Permalink
Fix ROM/RAM Banking for MBC1, Pass mooneye ram_64kb.gb
Browse files Browse the repository at this point in the history
  • Loading branch information
r41k0u committed Jan 8, 2024
1 parent 685e929 commit 15af8c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/gameBoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ GBE::GBE()
printf("boot rom file not opened");

// Open the Game ROM
if ((gameROM = fopen("../tests/mbc1/bits_ramg.gb", "rb")) == NULL)
if ((gameROM = fopen("../tests/mbc1/ram_64kb.gb", "rb")) == NULL)
printf("game rom file not opened");

// Set the Boot ROM
Expand Down
6 changes: 4 additions & 2 deletions src/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ bool MemoryMap::writeMemory(Word address, Byte value)
externalRam[address - 0xA000] = value;
break;
case MBC1:
if (enableRAM)
if (enableRAM && ((ramBankNumber * 0x2000) < ramSize))
externalRam[address - 0xA000 + (ramBankNumber * 0x2000)] = value;
else if (enableRAM)
externalRam[address - 0xA000] = value;
break;
default:
externalRam[address - 0xA000] = value;
Expand Down Expand Up @@ -318,7 +320,7 @@ Byte MemoryMap::readMemory(Word address)
return externalRam[address - 0xA000];
case MBC1:
if (enableRAM) {
if (ramBankNumber * 0x2000 < ramSize)
if ((ramBankNumber * 0x2000) < ramSize)
return externalRam[address - 0xA000 + (ramBankNumber * 0x2000)];
else
return externalRam[address - 0xA000];
Expand Down

0 comments on commit 15af8c4

Please sign in to comment.