Conceptualizing PRG-RAM

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
Dr. Floppy
Posts: 47
Joined: Mon May 09, 2011 7:02 pm

Conceptualizing PRG-RAM

Post by Dr. Floppy »

This is probably an extremely n00bish question, but here goes: I can't seem to figure out how to properly conceptualize PRG-RAM. Specifically, where does it go in the traditional iNES file format?

$00000000-0000000F = iNES header
$00000010-0004000F = PRG-ROM
$00040010-0008000F = CHR-ROM / end of file

I know CHR-RAM is plucked from PRG-ROM and assigned to the appropriate place in PPU-RAM. This leads me to believe that PRG-RAM is merely data taken from PRG-ROM and mapped to the CPU's SRAM block at $6000.

But that doesn't explain the multiple banks of PRG-RAM data found in certain mappers, or their seemingly hardwired nature. For example, MMC5 allows for up to eight 8kB banks of PRG-RAM data, mappable to anywhere from $6000 to $DFFF. This sounds like PRG-RAM is special data distinct from the PRG-ROM proper... which brings us back around to where the hell it goes in the iNES setup?

...unless PRG-RAM is basically additional storage space, where PRG-ROM data can be written and maintained until the power goes off. This would allow one to copy eight 8kB banks of PRG-ROM data over to eight respective banks of PRG-RAM (at startup) and swap them in during gameplay to effectively increase total CPU ROMspace to 40kB.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Some games, such as The Legend of Zelda, do indeed copy code or data to PRG RAM to have it available no matter which bank is switched into $8000-$BFFF. But it's also used to extend the NES's built in 2 KiB to a total of 10 KiB with more memory for the state of an entire map, including the ability to modify or destroy map cells (e.g. Mario breaking blocks or collecting coins). Or when used with a battery, it can save the player's progress across a power cycle.
User avatar
infiniteneslives
Posts: 2102
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Post by infiniteneslives »

Yeah the WRAM (PRG-RAM) is not part of the .nes file. Most games don't have battery backing so like you're thinking, there is no data stored there when power is removed. The ines format only has a bit to signify that the WRAM is available to the game/rom but nothing stored there in an off state. It's just more RAM for the game to use while it's running. And trash after power down and at start up.

With Battery backed games the WRAM has a battery to maintain save data. But that data is not required for operation, only for saves. If you were to remove the battery the game would still work, you'd just never be able to save things after turning the console off. So the ines file format doesn't store because it's not really part of the rom. You can have images of the WRAM for emulators and in that case it's just a dump of the 8KB image in a .sav file. It's completely separate from the ines file format.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Post by 3gengames »

Racermate store data in CHR-RAM I believe.
Karatorian
Posts: 76
Joined: Sun Sep 30, 2007 9:54 pm
Location: Corneria
Contact:

Post by Karatorian »

At first blush, it's tempting to think that an INES format ROM image is a digital representation of an entire cart. It's intuitive, but it's not so. Other than the header, they actually only contain the contents of the ROM chips. Therefore, any RAM (regardless of type) on the cart is only represented by flags in the header. The contents of that RAM is not stored in the INES file. Which makes sense, because it's a ROM image.

In fact, unless the RAM is battery backed, it's contents are undefined. (Which means probably zero in an emu and essentially random on real hardware). Therefore it doesn't make any sense to store it at all. If it is battery backed, it's generally stored in SAV files, which are usually raw memory dumps, but may be compressed by some emus.

I think you'd have a better understanding of all this all fits together if you looked at it from the perspective of the NES memory map, rather than starting from the INES format. Due to the partial decoding of some parts of it, it can be a little complex, but once you get a feel for it, it all makes a lot more sense.

Basically, PRG RAM is similar to the 2K of internal RAM in the NES. It's just at a different address and there's (generally) more of it. You use it in essentially the same way. Battery backup and bank switching can complicate matters, but for the most part, it's used the same way.
Post Reply