Basic MBC interface?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Basic MBC interface?
by on (#66736)
I've got a gameboy cartridge connector attached to an arduino and I'm having some problems. I can get the game's name from 0x0134 and read up to 0x4000, but I can't switch banks or read RAM.

I think my problem is that I'm not understanding the documents about the MBCs. They are all from the point of view of a gameboy and I don't know what addresses are gameboy specific ports.

On some MBC1 games, if I read from 0x4000 I get garbage. If I write anything to 0x2000 and then read 0x4000, I get data from 0x#C000. The most significant part of the address changes from game to game.

I know it's not easy to debug from that. So, if someone could give me non-gameboy specific instructions I could at least rule some things out.

Thanks a lot.

by on (#66741)
For the purposes of GB bankswitching, nothing is internal to the gameboy. They are all addresses in the cartridge ROM area of the memory map. (0000-7FFF)

by on (#66747)
Are you aware of MBC1's "Mode" setting at $6000?

If Mode is 0, $0000 shifted left 5 places combines with what you write to $2000 for the ROM Bank that appears at $4000 - $7FFF. If Mode is 1, just $2000 is used for ROM Bank and $4000 selects a Cartridge RAM Bank.

Hope that helps. Oh one more thing, MBC1 cannot select Bank 0 to appear at $4000-$7FFF. If you try, it will effectively be changed to show Bank 1 the second bank in rom.

by on (#66754)
Dwedit wrote:
For the purposes of GB bankswitching, nothing is internal to the gameboy. They are all addresses in the cartridge ROM area of the memory map. (0000-7FFF)

Ok, that's good to know. One document showed a gameboy memory map and I got frightened.


MottZilla are you referring to this?
Quote:
The MBC1 defaults to 16Mbit ROM/8KByte RAM mode
on power up. Writing a value (XXXXXXXS - X = Don't
care, S = Memory model select) into 6000-7FFF area
will select the memory model to use. S = 0 selects
16/8 mode. S = 1 selects 4/32 mode.


I tried writing all 256 values to 0x2000 after setting 4/32 mode, but I never read different data. On a 128K game I should read new data multiple times right? Assuming they didn't repeat things at different addresses.

Maybe I just swapped some address lines or something.

by on (#66755)
Well, 4 mbit would be 512kb. Gives you 32 banks. 16 mbit would be 2048kb and gives you 128 banks. I'm not sure if any MBC1 game is really that big.

I would definitely double check your wiring. Although if MBC3/MBC5 carts read back fine I'm not sure.

by on (#66758)
Well I never get new data much less multiple.
I never said I got MBC3/5 working. I just detailed how MBC1 wasn't working. :P

EDIT: The wiring looks fine.

What else could be wrong? Timing?

by on (#66774)
I found a Donkey Kong Land III cart to play with. My cart reader detects it as this:

Code:
DONKEYKONGLAND
Cart Type: 3 : ROM+MBC1+RAM+BATT
ROM Size: 4 : 512KByte
RAM Size: 2 : 8KByte


I have played and saved multiple games to it. So the RAM isn't blank.

I've written 0x01 to 0x6000; 0x00 to 0x4000 and 0x0A to 0x0000.
I set WR=1, RD=0, CS=0 then I read from 0xA000 to 0xBFFF. With pull up resistors I get all 0xFF. Without I get long strings of the same few numbers.
This same process works perfectly for addresses 0x0000-0x3FFF.

What am I missing?

by on (#66777)
I'm not sure that you are missing anything from the GB MBC register angle. Perhaps your error is related to something else.

by on (#66786)
Nothing to see here. Now move along.

by on (#66789)
I deleted the post because I realized I was being stupid, you were trying to read SRAM, not ROM.

by on (#66790)
Well I'm sorry I brought your post back from the dead then. I'll go remove it.

I bet if I could bankswitch ROM I'd be a lot closer to reading RAM. Any thoughts?

by on (#66793)
Pull up a copy of Pandocs or something, that has lots of nice information about the GB's mappers.

Looks like the sequence for reading the SRAM is:

Ram Enable: write 0A to 0000

And that's probably all you need to do to enable the SRAM.
I don't think you need to do 6000 = 01 or 4000 = 00, because you aren't switching the 8K ram page to something else, so you'd just see mirrors of the same ram regardless of what page is selected. But selecting page 0 shouldn't hurt either.

But that's also exactly what you did. So I have no clue why it's not working. What clock speed are you accessing the RAM at?

by on (#66796)
Oooh pretty document! More coherent that what I've been reading.

The clock speed of the arduino board is 16MHz but I don't have a way to count cycles as it's in pseudo-C.
I scattered in some 1 micro second delays and put two 10 microsecond delays in the write loop. I know that's probably orders of magnitude more time than it needs but I wanted to be sure. You can't run too slowly can you?

by on (#66805)
I got it to work! I was trying to be crafty and have my shift register's clock and WR on the same GPIO. I split them up and it started working.

Thanks for input everyone. It helped narrow down where to look for problems.

by on (#66826)
Glad to hear you got it working. And also that it wasn't a MBC register issue.

by on (#66827)
Thanks.
I wish it had been a MBC problem. Then I would have been more justified in bothering you guys.
It still needs some work. Pokemon Blue is my only game with multiple RAM banks and I can't switch them out.