Detecting Cartridge 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
Great Hierophant
Posts: 780
Joined: Tue Nov 23, 2004 9:35 pm

Detecting Cartridge RAM

Post by Great Hierophant »

In most ordinary mappers, cartridge RAM resides at CPU $6000-$7FFF. Games which use that RAM will read from it and write to it. I understand that if you want to detect whether a game uses cartridge RAM and you cannot find an image of its PCB, the best approach would be to monitor the area at CPU $6000-$7FFF. This can be done via setting a breakpoint on accesses to that area.

There are games that may have vestigial code that writes to RAM because the development cartridge had RAM but the programmers figured out how to avoid using it on production cartridges. Extra RAM cost more money BITD. I have figured that reads from RAM are the accesses to watch out for. Execution of code from RAM should be rare in a cartridge system, but if there is execution then there must be RAM.

But even then, a read from the cartridge RAM could be a false positive. There are a few games that are known to read from RAM not because they have RAM there, but because they rely on open bus behavior. When reading from open bus, a game is not reading a definable memory value but whatever happened to be on the bus just before the read, typically the high byte of the address. Two well-known cases are Low-G-Man and Battletoads & Double Dragon. At this point you need to apply reasoning to the instances where this occurs. "Is this really RAM usage?" "Why does this game read only at a boss fight?" "Is there any rhyme or reason to the game's writes?"

Also, I have found that a game like Battle of Olympus reads from RAM when you start a new game or enter a password without having written to the RAM beforehand. The routine appears to read 64 bytes from the CPU RAM area to update the $2007 PPU register. It doesn't really seem to care what the values are because the program corrects itself by the time the next image appears.

Does anyone care to add anything to this summary?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Detecting Cartridge RAM

Post by rainwarrior »

I think you want to primarily be looking for writes to RAM, not really for reads? If there really is RAM there it must be written before it is read. (Ideally you'd be looking for a write followed by a later read from the same address.)

Looking for an initialization signature for battery RAM is a separate thing, but I would be exceedingly surprised by something that has battery backed RAM and no obvious save feature in the game. (The farthest I'd stretch this is maybe a high score table, but that's an expensive feature just for a high score.)

AFAIK both the false positive read examples you gave read without writing first, and they don't do it on startup.

Are there actually any known cases of vestigial RAM use? I've never heard of one.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Detecting Cartridge RAM

Post by tepples »

rainwarrior wrote:I would be exceedingly surprised by something that has battery backed RAM and no obvious save feature in the game. (The farthest I'd stretch this is maybe a high score table, but that's an expensive feature just for a high score.)
By Tetris DX on Game Boy Color, 8-bit games were adding a battery just for high scores.
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Detecting Cartridge RAM

Post by rainwarrior »

Sure, 10 years and 3 volts probably makes a bit of a difference there. ;) Arcade games did it all the time too, of course, but a battery was a relatively small expense for those... but even then a lot of arcade games omitted it.
User avatar
Sumez
Posts: 919
Joined: Thu Sep 15, 2016 6:29 am
Location: Denmark (PAL)

Re: Detecting Cartridge RAM

Post by Sumez »

I'm not sure what your endgame is here? You're looking at an NES ROM to figure out if it was designed to use cartridge RAM? But having access to an NES ROM would mean dumping it from an actual cartridge, and whoever dumped it should be well aware of wether the cartridge in question has a RAM chip on the PCB - which is why we have iNES headers, usually considered a part of an "NES ROM". And this is ignoring the fact that almost every NES PCB out there is already well documented.

I also imagine any games that actually rely on cartridge RAM would visibly break really fast without it.
rainwarrior wrote:Arcade games did it all the time too, of course, but a battery was a relatively small expense for those... but even then a lot of arcade games omitted it.
Aside from the Neo Geo system, pretty much no Japanese arcade games did it until the late 90s. I almost only see it in western games.
unregistered
Posts: 1318
Joined: Thu Apr 23, 2009 11:21 pm
Location: cypress, texas

Re: Detecting Cartridge RAM

Post by unregistered »

Great Hierophant wrote:In most ordinary mappers, cartridge RAM resides at CPU $6000-$7FFF. Games which use that RAM will read from it and write to it. I understand that if you want to detect whether a game uses cartridge RAM and you cannot find an image of its PCB, the best approach would be to monitor the area at CPU $6000-$7FFF. This can be done via setting a breakpoint on accesses to that area.
Monitoring memory became much easier for me after I started using Sour's Mesen emulator. Open the "Memory Tools" hex editor/viewer and you can easily view reads and writes to whatever area you are viewing because the accesses can be color coded... like red for reads and blue for writes. And you are able to order Mesen to keep the color change for however many frames you would like. You can also toggle to only color reads, or writes, or executions. You are also allowed to choose your own colors. It's so helpful!! :mrgreen: :D

edit: highlighted quote
Great Hierophant
Posts: 780
Joined: Tue Nov 23, 2004 9:35 pm

Re: Detecting Cartridge RAM

Post by Great Hierophant »

rainwarrior wrote:Sure, 10 years and 3 volts probably makes a bit of a difference there. ;) Arcade games did it all the time too, of course, but a battery was a relatively small expense for those... but even then a lot of arcade games omitted it.
I think you can chalk it down to 10 years and Tetris DX being a first-party title. Not only does Tetris DX save high scores but also player profiles. Nintendo could afford the "battery tax" better than 3rd parties.

Don't GB and GBC carts use +5v parts?

Interestingly, you might think that all Famicom Disk System games would support saving high scores, but most do not. The Disk System guaranteed you writable storage, but not all games took advantage of that feature.
Sumez wrote:I'm not sure what your endgame is here? You're looking at an NES ROM to figure out if it was designed to use cartridge RAM? But having access to an NES ROM would mean dumping it from an actual cartridge, and whoever dumped it should be well aware of wether the cartridge in question has a RAM chip on the PCB - which is why we have iNES headers, usually considered a part of an "NES ROM". And this is ignoring the fact that almost every NES PCB out there is already well documented.

I also imagine any games that actually rely on cartridge RAM would visibly break really fast without it.
I'm not interested in reinventing the wheel, I know that almost all licensed NES and most unlicensed, non-pirate NES, has been properly documented. However, I find that Famicom stuff, whether licensed or unlicensed, has not been so well-documented. However, as a learning tool, comparing what a NES game does in relation to the board it uses is helpful.

I also think it is unwise to assume that the original dumper necessarily knew what exactly was inside the cartridge, especially for difficult-to-open Famicom cartridges. The presence or absence of RAM would not matter to the dumper.
unregistered wrote:Monitoring memory became much easier for me after I started using Sour's Mesen emulator. Open the "Memory Tools" hex editor/viewer and you can easily view reads and writes to whatever area you are viewing because the accesses can be color coded... like red for reads and blue for writes. And you are able to order Mesen to keep the color change for however many frames you would like. You can also toggle to only color reads, or writes, or executions. You are also allowed to choose your own colors. It's so helpful!! :mrgreen: :D
Mesen has been my poison :) of choice!
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Detecting Cartridge RAM

Post by lidnariq »

Great Hierophant wrote:Don't GB and GBC carts use +5v parts?
Even during the NES era, it was a 3V battery and a SRAM that supported operation supplied by ≈3 to 5V.
Post Reply