Skip to content

Commit

Permalink
Fix ROM/RAM Banking for MBC1, Pass mooneye ram_256kb.gb
Browse files Browse the repository at this point in the history
  • Loading branch information
r41k0u committed Jan 8, 2024
1 parent 15af8c4 commit 3462e2b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 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/ram_64kb.gb", "rb")) == NULL)
if ((gameROM = fopen("../tests/mbc1/ram_256kb.gb", "rb")) == NULL)
printf("game rom file not opened");

// Set the Boot ROM
Expand Down
6 changes: 3 additions & 3 deletions src/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool MemoryMap::writeMemory(Word address, Byte value)
externalRam[address - 0xA000] = value;
break;
case MBC1:
if (enableRAM && ((ramBankNumber * 0x2000) < ramSize))
if (enableRAM && romRAMModeSelect && ((ramBankNumber * 0x2000) < ramSize))
externalRam[address - 0xA000 + (ramBankNumber * 0x2000)] = value;
else if (enableRAM)
externalRam[address - 0xA000] = value;
Expand Down Expand Up @@ -280,7 +280,7 @@ Byte MemoryMap::readMemory(Word address)
case MBC0:
return romBank0[address];
case MBC1:
if ((romBankNumber & 0x60) && ((romBankNumber * 0x4000) < romSize) && !(romBankNumber & 0x1F))
if (romRAMModeSelect && (romBankNumber & 0x60) && ((romBankNumber * 0x4000) < romSize) && !(romBankNumber & 0x1F))
return romBank1[address + (((romBankNumber & 0x60) - 1) * 0x4000)];
else
return romBank0[address];
Expand Down Expand Up @@ -320,7 +320,7 @@ Byte MemoryMap::readMemory(Word address)
return externalRam[address - 0xA000];
case MBC1:
if (enableRAM) {
if ((ramBankNumber * 0x2000) < ramSize)
if (romRAMModeSelect && ((ramBankNumber * 0x2000) < ramSize))
return externalRam[address - 0xA000 + (ramBankNumber * 0x2000)];
else
return externalRam[address - 0xA000];
Expand Down

0 comments on commit 3462e2b

Please sign in to comment.