Tuesday, 30 December 2014

MBC address wraparound on the GameBoy

I discovered many games were doing out-of-bound accesses on MBC's by accessing banks that weren't in the file. Nintendo's docs simply say a "memory image" is created in unused ROM space, which is somewhat obtuse, and really not easy to understand.

After tearing my hair out for a few hours, wondering if there was a bug in our core or in the games, I realised that this really means the ROM's contents are mirrored again; that is, banks are "repeated."

The simple procedure is to modulo the bank number with the number of banks, easily derived by dividing the ROM size by the ROM bank numbers. I don't know if adjustment is needed for specific MBC's such as MBC1 which cannot address banks whose lower bits are 0 (e.g. it can't address 0x0, 0x20, 0x40, 0x60, etc.), but it all seems to work properly now.

Now if I could just figure out why Link's Awakening has bizarre scroll bugs... it's not banking related, and it only happens in specific corner cases (when SCX is > 0 and Y scroll changes is one instance)...

No comments :

Post a Comment