Gameboy MBC-2 RAM Question

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Gameboy MBC-2 RAM Question
by on (#41569)
Documents say the MBC-2 has built in 512 x 4bits of RAM. I'm not really sure what this means other than there is a total of 256 bytes... So is it 256 bytes at $A000, or is it 512 nibbles (4bits) at $A000 with the upper 4 bits ignored? Anyone know?

by on (#41620)
I guess it should by nybbles, with the upper 4 bits ignoerd. Altough I don't know much about the gameboy :cry:

I guess the MBC2 is to the Gameboy what the MMC6 is to the NES (altough it is much more widely used).

by on (#41642)
But on NES, it was full bytes, which is part of the confusion. Currently I just emulate them with 2kbytes of RAM and the two games I know are MBC2 (Kid Icarus and Final Fantasy Adventure) both seem to be ok. FFA doesn't get in game due to incomplete emulation, but Kid Icarus doesn't seem to care and seems to run fine. Though I haven't actually tested its saving ability.

by on (#41664)
Well, if you emulate full bytes when it's nybbles, I guess there is no reason it won't work. But if you emulate nybbles when it's bytes, definitely it won't work. So I'd say emulate nybbles and see what happens.

Oh, and the .sav file my emulators give me for Final Fantasy adventure is 256 bytes long, but the bytes seems to takes all kind of values. So I guess they just re-arranged the nybbles in some way so that it makes full bytes and it doesn't waste space in the .save files. It seems to work on most of my GB emulators with the same file so there is some kind of standard.

by on (#55627)
It's 512 nybbles at $A000-A1FF--only the low 4 bits of each byte are valid. I think the high bits read as open bus. Here's the "load saved game" routine from Makaitoushi SaGa:

Code:
ROM0:04DC CD 19 05         call 0519   ; enable MBC2 battery RAM, hl = a000, de = cc00, b = 0
ROM0:04DF 2A               ldi a,(hl)
ROM0:04E0 E6 0F            and a,0f
ROM0:04E2 4F               ld c,a
ROM0:04E3 2A               ldi a,(hl)
ROM0:04E4 E6 0F            and a,0f
ROM0:04E6 CB 37            swap a
ROM0:04E8 B1               or c
ROM0:04E9 12               ld (de),a
ROM0:04EA 13               inc de
ROM0:04EB 05               dec b
ROM0:04EC 20 F1            jr nz,04df
ROM0:04EE AF               xor a
ROM0:04EF EA 00 00         ld (0000),a   ; disable MBC2 battery RAM
ROM0:04F2 D9               reti


Why is the battery RAM laid out in this silly way? Because the RAM is inside the MBC2 chip itself, and the chip only has 4 data lines! MBC2 cartridges are limited to 16 ROM banks (2 megabits/256 kilobytes) for the same reason.