MBC1 Bank Switching with unusual instructions

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
Gabrias
Posts: 2
Joined: Sat Dec 28, 2019 8:26 pm

MBC1 Bank Switching with unusual instructions

Post by Gabrias »

Hi,
While developing a MBC1 logic for CPLD/FPGA for a flashcart i have encountered an error (game freezes) during the execution of Donkey Kong Land 2 and 3, specifically at the time i press SELECT to change the characters.
After inspecting the code with the help of the BGB debugger, i have found that after pressing SELECT it enters on a routine that executes some reset bit instructions on a couple of ROM addresses ( res 0,(hl) ), addresses 5A1A and 5A29 in the case of the DKL 2.

It seems an unusual way to change ROM banks, but since the res bit,(hl) instruction reads the byte at HL, reset the bit and write it back, and the address is in the range 4000-5FFF, the upper ROM bank bits (with bank sel equal to zero) will change.

Does anyone have any information about this?
In my MBC1 implementation, when i try to isolate the problem, preventing the ROM bank switching when writing to those specific addresses the freeze doesnt happen, but it does bring other apparent random graphic glitches, so i guess those bank switches are supposed to happen.

Appreciate any insight on this.
Thank you.
Gabrias
Posts: 2
Joined: Sat Dec 28, 2019 8:26 pm

Re: MBC1 Bank Switching with unusual instructions

Post by Gabrias »

For future reference, i solved the issue.

Donkey Kong Land 2 and Donkey Kong Land 3 do use the reset bit instruction in an unusual way on addresses in the range 4000-5FFF, but since the ROM size is not larger than 512KB, the bits 5 and 6 of the ROM BANK register of the MBC1 dont matter.
All i had to do to circumvent the problem was to implement that logic on my fpga code to ignore the 5 and 6 bits for a ROM of size 512KB or smaller when also using a MBC1.

Thanks.
Post Reply