Skeetendo

’Cause all games were better on the GBC

You are not logged in.

#1 2011-01-13 20:59:53

Sawakita
Administrator
Registered: 2010-10-16
Post 76/364

How to get additional (and certainly unused) RAM

Generally speaking, finding some safe WRAM (C000-DFFF) to be used in a hack can be tricky, because you can't be 100% sure that it's unused or because it takes ages to find unused RAM locations. This thread is born because there are some things I would like conferms about.
MBC3 comes along with a total of 32KB of WRAM. So could we use the switchable WRAM banks (8 banks in total)?

PART 1: FIND
First of all this option can only be used on a GBC-cartridge (offset $143 == $80), by writing bank's ID in register $FF70, right? This register is unaccessible in any other case (id est offset $143 != $80), so for example in Pokemon R/B you can only access WRAM fixed bank0 ($C000-$CFFF) and bank1 ($D000-$DFFF), for a total of 8KB of WRAM. But in GSC I suppose that all the 8 banks, furnished along with MBC3, are accessible, allowing the access, overall, of 32KB of WRAM.
So, leaving aside the problems related to DMG-to-CGB conversion, would it be sufficient just editing the byte at $143 (from $00 to $80), to obtain 24KB of new WRAM?


PART 2: SAVE
MBC3 has 4 SRAM banks, that can be switched following this procedure:

- load $A0 in $0000 to enable SRAM,
- load $00-$03 in $4000

When you save your game, for example in pokemon Red, the program loads some chunk of data from WRAM to SRAM1 (SRAM0 is usually dedicated to temporary data storing, like monsters graphics, when decompressing). I'm not sure about a thing: are all SRAM banks stored in the battery when you turn off the device? I mean, if you write a byte in SRAM3 during gameplay, then turn off the GB, and then turn it on again, will that byte still hold that value or do I have to follow a certain procedure to have that bank stored in the battery? It's sufficient that you write in SRAM to have data permanently stored in battery (since you're actually writing on an external RAM) right?


A last thought: how many WRAM banks does GSC actually use? Since we have a Gold RAM map and no specifications are there, when listing $D000-$DFFF locations, I guess GSC just uses bank 0 and 1, doesn't it?

Well, I think that's all. I hope everything is correct and clearly explained: if it isn't, please, feel free to to ask clarification, or to point out corrections.

Offline

#2 2011-01-13 21:29:06

130/700

Re: How to get additional (and certainly unused) RAM

Sawakita wrote:
PART 1: FIND

First of all this option can only be used on a GBC-cartridge (offset $143 == $80), by writing bank's ID in register $FF70, right? This register is unaccessible in any other case (id est offset $143 != $80), so for example in Pokemon R/B you can only access WRAM fixed bank0 ($C000-$CFFF) and bank1 ($D000-$DFFF), for a total of 8KB of WRAM.

That option can only be used when emulating a Game Boy Color. E.g., Gold in DMG mode would not be able to access WRAM banks 2–7. There is really no such thing as a “GBC cartridge,” as all Game Boy cartridges are identical in terms of the Game Boys they can be used in. Emulators typically check the header byte to determine CGB mode or not, but this is not how a Game Boy actually behaves.

Sawakita wrote:

So, leaving aside the problems related to DMG-to-CGB conversion, would it be sufficient just editing the byte at $143 (from $00 to $80), to obtain 24KB of new WRAM?

The important thing is that the game is run in Game Boy Color mode. So it would have to be $C0. Also, you should add an error message like Crystal’s when playing in DMG mode if you restrict your hack to CGB features; otherwise a year down the road someone might have hard‐to‐diagnose problems when playing your hack (in SGB mode or somesuch).

Sawakita wrote:
PART 2: SAVE

MBC3 has 4 SRAM banks, that can be switched following this procedure:

- load $A0 in $0000 to enable SRAM,
- load $00-$03 in $4000

When you save your game, for example in pokemon Red, the program loads some chunk of data from WRAM to SRAM1 (SRAM0 is usually dedicated to temporary data storing, like monsters graphics, when decompressing). I'm not sure about a thing: are all SRAM banks stored in the battery when you turn off the device? I mean, if you write a byte in SRAM3 during gameplay, then turn off the GB, and then turn it on again, will that byte still hold that value or do I have to follow a certain procedure to have that bank stored in the battery? It's sufficient that you write in SRAM to have data permanently stored in battery (since you're actually writing on an external RAM) right?

I think it is correct that all you need to do is enable external RAM, write to external RAM, and disable external RAM.

Sawakita wrote:

A last thought: how many WRAM banks does GSC actually use? Since we have a Gold RAM map and no specifications are there, when listing $D000-$DFFF locations, I guess GSC just uses bank 0 and 1, doesn't it?

I suspect it just uses 0 and 1, because it has backwards‐compatibility with DMG. To be sure you should check the ROM and make sure there are no writes to $FF70.

#3 2011-01-13 22:11:45

Tauwasser
Member
Registered: 2010-10-16
Post 77/448

Re: How to get additional (and certainly unused) RAM

IIMarckus wrote:

Emulators typically check the header byte to determine CGB mode or not, but this is not how a Game Boy actually behaves.

Yes it is how a real CGB behaves! It will read the header bytes, determine what type of cartridge it is and init a lockout register (0xFF4C if memory serves) to disable color functionality.

However, this has nothing to do at all with RAM banks! Banking is solely dependent on the MBC used, not on the Game Boy, because all SRAM is obviously on the cart. Therefore, yes, you can access banks 0x00―0x03 in DMG mode just fine, because Gold is using MBC3, which can access these. To access 0x00―0x07, you will have to use MBC5, therefore losing the RTC functionality! I hope this clears some issues up!

IIMarckus wrote:
Sawakita wrote:

So, leaving aside the problems related to DMG-to-CGB conversion, would it be sufficient just editing the byte at $143 (from $00 to $80), to obtain 24KB of new WRAM?

The important thing is that the game is run in Game Boy Color mode.

Yes, that's the important thing. The header information is secondary. A DMG does not check this byte, since it does not perform any lockout. Therefore, yes, it is sufficient to change it to 0x80 DMG/CGB or just 0xC0 CGB only add a lockout routine to make sure it does not start up on a DMG.

Sawakita wrote:
PART 2: SAVE

MBC3 has 4 SRAM banks, that can be switched following this procedure:

- load $A0 in $0000 to enable SRAM,
 - load $00-$03 in $4000

Notice how this should be 0x0A that is stored in 0x0000―0x1FFF range, not 0xA0. Also, some MBC3 games still do a MBC1-style mode select via writing 0x00 to 0x6000―0x7FFF range ― I say "mode select" as opposed to code that latches the clock via a 0x00 write followed by a 0x01 write. I doubt this has any effect though, since it would be detrimental to what the MBC3 really is. One would have to test on hardware to be sure, tho...

The rest of your observation is correct. I think you did not get the idea, however. SRAM is just a piece of memory. While the gameboy is running, it is powered (and therefore saves what's written to it). When the game boy is turned off, the battery is powering it. There is really never a dedicated "write to SRAM" functionality beyond the fail-safe write 0x0000―0x1FFF. This is a fail-safe so when the gameboy is powered off, some residue current does not alter SRAM.

IIMarckus wrote:

I suspect it just uses 0 and 1, because it has backwards‐compatibility with DMG. To be sure you should check the ROM and make sure there are no writes to $FF70.

This is correct. It would have been detrimental to design routines twice ― once with more WRAM support, once without it. However, I think Crystal does make use of more banks, e.g. for temporary decompression of tilesets.

cYa,

Tauwasser

Offline

#4 2011-01-13 22:44:35

131/700

Re: How to get additional (and certainly unused) RAM

Tauwasser wrote:
IIMarckus wrote:

Emulators typically check the header byte to determine CGB mode or not, but this is not how a Game Boy actually behaves.

Yes it is how a real CGB behaves! It will read the header bytes, determine what type of cartridge it is and init a lockout register (0xFF4C if memory serves) to disable color functionality.

My mistake. I was thinking of the other bytes in the header, most of which (like 0x147–0x14A) are useless to a Game Boy but are used by an emulator to guess which hardware the cart uses.

Tauwasser wrote:

However, this has nothing to do at all with RAM banks! Banking is solely dependent on the MBC used, not on the Game Boy, because all SRAM is obviously on the cart.

I was talking about WRAM here, which is CGB‐dependent. Yes, external RAM banking is on the cart and hence depends on the MBC.

#5 2011-01-13 23:09:09

Tauwasser
Member
Registered: 2010-10-16
Post 78/448

Re: How to get additional (and certainly unused) RAM

Ah, I misread that part ;) So yes, WRAM is work ram of the game boy you're using, while SRAM is ram on the cart of whatever game.
After reading through the first post once, I thought the whole point was to get more SRAM, hence my confusion :(

cYa,

Tauwasser

Offline

#6 2011-01-13 23:13:53

Sawakita
Administrator
Registered: 2010-10-16
Post 77/364

Re: How to get additional (and certainly unused) RAM

IIMarckus wrote:

The important thing is that the game is run in Game Boy Color mode. So it would have to be $C0. Also, you should add an error message like Crystal’s when playing in DMG mode if you restrict your hack to CGB features; otherwise a year down the road someone might have hard‐to‐diagnose problems when playing your hack (in SGB mode or somesuch).

So, a boot-screen, that explains the thing, and locks the game should be fine, I guess. (I wasn't aware of Crystal's: so Gold/Silver runs on DMG, but Crystal doesn't?)

Tauwasser wrote:

However, this has nothing to do at all with RAM banks! Banking is solely dependent on the MBC used, not on the Game Boy, because all SRAM is obviously on the cart. Therefore, yes, you can access banks 0x00―0x03 in DMG mode just fine, because Gold is using MBC3, which can access these. To access 0x00―0x07, you will have to use MBC5, therefore losing the RTC functionality! I hope this clears some issues up!

That's bad news: so it means there's no way you can have both '0-7 internal WRAM banks' and 'RTC'.
Anyway you can use, just for instance, SRAM3 as additional RAM (although it never turns off), while SRAM1 is used as bank for saving stuff from $C000-$DFFF, and you could use SRAM2 to save data from SRAM3. This should be a solution.
Afterall 8 empty KB are probably way more than I'll ever use. Also, if I'm not wrong, SRAM0 is only used for a small part ($A000-$A497), so it also provides lots of unused RAM.

Tauwasser wrote:
Sawakita wrote:
PART 2: SAVE

MBC3 has 4 SRAM banks, that can be switched following this procedure:

- load $A0 in $0000 to enable SRAM,
 - load $00-$03 in $4000

Notice how this should be 0x0A that is stored in 0x0000―0x1FFF range, not 0xA0.

As usual I like to spread typos all over my posts. :P

Tauwasser wrote:

The rest of your observation is correct. I think you did not get the idea, however. SRAM is just a piece of memory. While the gameboy is running, it is powered (and therefore saves what's written to it). When the game boy is turned off, the battery is powering it. There is really never a dedicated "write to SRAM" functionality beyond the fail-safe write 0x0000―0x1FFF. This is a fail-safe so when the gameboy is powered off, some residue current does not alter SRAM.

Thanks for clarification.

Tauwasser wrote:
IIMarckus wrote:

I suspect it just uses 0 and 1, because it has backwards‐compatibility with DMG. To be sure you should check the ROM and make sure there are no writes to $FF70.

This is correct. It would have been detrimental to design routines twice ― once with more WRAM support, once without it. However, I think Crystal does make use of more banks, e.g. for temporary decompression of tilesets.

cYa,

Tauwasser

When you say "more banks" you mean external RAM banks, not internal (since you previously said that MBC3 doesn't support internal-working-RAM banks), right?
Something like Blue does when decompressing graphics: it uses SRAM0 temporarily.

Offline

#7 2011-01-13 23:41:30

132/700

Re: How to get additional (and certainly unused) RAM

Sawakita wrote:
IIMarckus wrote:

The important thing is that the game is run in Game Boy Color mode. So it would have to be $C0. Also, you should add an error message like Crystal’s when playing in DMG mode if you restrict your hack to CGB features; otherwise a year down the road someone might have hard‐to‐diagnose problems when playing your hack (in SGB mode or somesuch).

So, a boot-screen, that explains the thing, and locks the game should be fine, I guess. (I wasn't aware of Crystal's: so Gold/Silver runs on DMG, but Crystal doesn't?)

Correct. I think it was a Nintendo requirement that CGB‐only games displayed an error on DMG variants.

Sawakita wrote:
Tauwasser wrote:

However, this has nothing to do at all with RAM banks! Banking is solely dependent on the MBC used, not on the Game Boy, because all SRAM is obviously on the cart. Therefore, yes, you can access banks 0x00―0x03 in DMG mode just fine, because Gold is using MBC3, which can access these. To access 0x00―0x07, you will have to use MBC5, therefore losing the RTC functionality! I hope this clears some issues up!

That's bad news: so it means there's no way you can have both '0-7 internal WRAM banks' and 'RTC'.

Incorrect. Again: WRAM banks 2–7 are accessible with any MBC, as long as you’re in CGB mode. Tauwasser was saying that MBC3 is limited to external RAM banks 0–3, and that you can add four more external RAM banks (at the cost of RTC functionality) by moving to MBC5.

Sawakita wrote:
Tauwasser wrote:
IIMarckus wrote:

I suspect it just uses 0 and 1, because it has backwards‐compatibility with DMG. To be sure you should check the ROM and make sure there are no writes to $FF70.

This is correct. It would have been detrimental to design routines twice ― once with more WRAM support, once without it. However, I think Crystal does make use of more banks, e.g. for temporary decompression of tilesets.

cYa,

Tauwasser

When you say "more banks" you mean external RAM banks, not internal (since you previously said that MBC3 doesn't support internal-working-RAM banks), right?

No, he means WRAM banks. I think you misinterpreted this for the same reason the last point was misinterpreted. WRAM banks 2–7 are available to any MBC (or even games with no MBC) as long as you are in CGB mode, because WRAM is dependent on the Game Boy and not the cart. SRAM, a.k.a. external RAM, is on the cart (hence the name) and so the number of external RAM banks available depends on which MBC you use.

#8 2011-01-14 11:26:41

Sawakita
Administrator
Registered: 2010-10-16
Post 78/364

Re: How to get additional (and certainly unused) RAM

Ah, okay, now I understand.
So now I just have to choose between using SRAM2-3 as additional RAM, or use WRAM bank 2-7, thus precluding use on DGM... I guess WRAM access is faster, since you just have to write register FF70, instead of "enable SRAM, choose bank, disable SRAM" (7 bytes vs. 14 bytes, more or less).
I doubt anyone would try to play a hack on an actual DMG, and almost every emulator just are set on Automatic (allowing always full CGB functions) by default.

Offline

Board footer

Powered by FluxBB