This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Difference between RAM and cartridge SRAM?

Difference between RAM and cartridge SRAM?
by on (#242669)
Hi!

I'd like to apologize in advance for posting such a n00b question, but I'm having some trouble understanding the difference between the RAM (0000h-07FFh) and SRAM (6000h-7FFFh).

Code:
CPU Memory Map (16bit buswidth, 0-FFFFh)

  0000h-07FFh   Internal 2K Work RAM (mirrored to 800h-1FFFh)
  2000h-2007h   Internal PPU Registers (mirrored to 2008h-3FFFh)
  4000h-4017h   Internal APU Registers
  4018h-5FFFh   Cartridge Expansion Area almost 8K
  6000h-7FFFh   Cartridge SRAM Area 8K
  8000h-FFFFh   Cartridge PRG-ROM Area 32K

http://problemkaputt.de/everynes.htm#memorymaps


For example, if I were to declare a pointer in the SRAM area, would I be able to freely utilize that space?
Re: Difference between RAM and cartridge SRAM?
by on (#242670)
The only differences are as follows:
  • The RAM at $0000-$1FFF is always there, but there's only 2KB of it, a quarter of it is used for special purposes (Zero-Page and the Stack), and all of its contents are lost when you turn off the console.
  • RAM at $6000-$7FFF is not guaranteed to exist - only certain cartridges have it, and a subset of those can have that RAM connected to a Battery so its contents can be preserved over long periods of time.
If you want to declare a pointer, you'll need to put it within $0000-$00FF because, with the sole exception of JMP, all of the 6502's various Indirect addressing modes are only capable of using pointers stored in the Zero Page.
Re: Difference between RAM and cartridge SRAM?
by on (#242672)
wonder wrote:
For example, if I were to declare a pointer in the SRAM area, would I be able to freely utilize that space?

Assuming you meant pointer to the SRAM area, yes. Labels and pointers that refer to this will work the same as labels and pointers to the other areas of RAM.

As an aside, sometimes this on-cart RAM will also be called WRAM, I think meaning "work RAM". I don't know the origin of this term, but it's the term that specifically distinguishes this RAM as belonging to a cartridge and not being an internal part of the NES.

SRAM seems like a less common term for it, because it means "static RAM" which is a type of RAM chip, but the other RAM inside the NES is also an SRAM chip. That's also kinda why they operate the same as each other, just at a different address: they're the same kind of RAM. SRAM distinguishes it from other types of RAM that work differently, like DRAM (dynamic RAM) or flash memory.

So it's true that a cartridge may contain SRAM, but if you want a term for "RAM inside the cartridge", WRAM is a term that describes that more directly.


Edit: though I just noticed the source you linked by nocash uses "Work RAM" do describe the internal RAM? That actually confuses me... if that's not an error I could be wrong about the meaning of WRAM, but how I described it just above is how I've seen it consistently applied here (e.g. our wiki). Maybe nothing short of mentioning that it belongs to the cartridge is sufficient after all...

PRG-RAM is another alternative here.
Re: Difference between RAM and cartridge SRAM?
by on (#242673)
rainwarrior wrote:
Edit: though I just noticed the source you linked by nocash uses "Work RAM" do describe the internal RAM? That actually confuses me... if that's not an error I could be wrong about the meaning of WRAM, but how I described it just above is how I've seen it consistently applied here
Nintendo of America used "WRAM" to refer to both cart and console RAM, unfortunately. (e.g. SKROM resist, top right corner of component side, and NES-CPU-07 mainboard, bottom left corner)
Re: Difference between RAM and cartridge SRAM?
by on (#242674)
rainwarrior wrote:
So it's true that a cartridge may contain SRAM, but if you want a term for "RAM inside the cartridge", WRAM is a term that describes that more directly.

Don't count on that.
To me, SRAM implies specifically low-power consumption, with capability for battery backing, usually externally, in the cartridge.
And WRAM would be more general pupose work ram for temporary data, often without battery, usually internally, in the console.
But yes, depending on the context, the terms can be swapped or mean the same thing in some situations.
Although, strictly speaking, SRAM means hardware/technology, and WRAM means usage/purpose.
Re: Difference between RAM and cartridge SRAM?
by on (#242676)
Hrm, so on the NES board, WRAM (work RAM) is for the CPU, distinguished from VRAM (video RAM) for the GPU (PPU).

Maybe I should start preferring "PRG-RAM". I dunno.
Re: Difference between RAM and cartridge SRAM?
by on (#242680)
For comparison, the Game Boy homebrew scene distinguishes "WRAM" and "VRAM" in the console from "SRAM" in the cartridge, despite that all three are static.
Re: Difference between RAM and cartridge SRAM?
by on (#242688)
I parse the S in SRAM as "save", not static, in a game context.
Re: Difference between RAM and cartridge SRAM?
by on (#242689)
SRAM - Save RAM
WRAM - Work RAM , so if the cart has RAM and it is not battery backed up its just extra RAM then its WRAM not SRAM
VRAM - Video RAM
IRAM - Internal RAM
Re: Difference between RAM and cartridge SRAM?
by on (#242690)
I don't know where and when the terms were coined, or if there's an official definition, but to me, "SRAM" in this context was always "save RAM", referring specifically to battery backed (W)RAM. This may or may not be a mutation of the term that has come about over time due to people misunderstanding the abbreviation (not unlike "LOL" or "CIB"). Of course on the technical side of things, battery backed RAM needs to be static RAM in order for that to work.

Another related and often used term I tend to see is NVRAM (non-volatile RAM) which I believe is used generically for any kind of RAM that is able to retain its data after the system is switched off, which could be via a battery, but I have also seen it used specifically for RAM circuits that are able to do so without an external power source. But that would, by definition, exclude static RAM. :)
Re: Difference between RAM and cartridge SRAM?
by on (#242692)
Some NVRAMs contain an SRAM and a battery on the same package. Others are ferroelectric RAM (FeRAM), as used in Sonic the Hedgehog 3. One drawback of FeRAM is limited read endurance in continuous use, especially in early devices, making it less useful than SRAM as supplementary work RAM. This is probably why Game Boy games never used FeRAM during its commercial life, as games such as Super Mario Land 2 and Wario Land used SRAM not used by the save feature as extra work RAM. But the read limit became less important after the Genesis and Super NES made 64 KiB of work RAM standard.
Re: Difference between RAM and cartridge SRAM?
by on (#242704)
I've always been confused with weird acronyms like SRAM in the context of cartridge RAM. I've been told it means static RAM, but why would the type of RAM used matter in this context? You don't say what type of memory other areas use (except for when it does matter, like for EEPROM etc). Save RAM makes more sense because it tells you what usage it has, but in that case I wouldn't use an acronym that can easily be confused with static RAM. And this thread shows clearly that I'm not the only one confused.

The term WRAM is also common for cartridge RAM, but it really just means work RAM which is just any general purpose RAM available to the programmer (so not video RAM etc), and the internal RAM is also sometimes called work RAM as been said already. If you only use it to distinguish it from battery backed RAM it makes sense though, but battery backed WRAM is also used, and besides it can still be used as normal work RAM no matter if it has a battery or not.

The wiki most commonly seems to use PRG RAM as it fits in well with PRG ROM, CHR ROM and CHR RAM, although it's a bit confusing since the initial meaning of PRG vs CHR is kind of lost. It's more like CPU memory vs PPU memory than simply about program and CHR data.

External RAM is another alternative, but in the context of GBA for example that just means external to the CPU chip and internal to the console.

Personally I mostly use PRG RAM, or I explicitly say "cartridge RAM" or sometimes even "save RAM" if it's battery backed and the context requires it.
Re: Difference between RAM and cartridge SRAM?
by on (#242706)
Pokun wrote:
but battery backed WRAM is also used, and besides it can still be used as normal work RAM no matter if it has a battery or not.

Important difference is though, that most mappers with battery backed RAM also often include a way to protect writes to the RAM, since unintended writes while turning off power to the console could potentially corrupt battery backed RAM. For cartridge RAM only used as "WRAM", that corruption wouldn't matter.

So if you want to use the cartridge RAM for both saves and extra work RAM, you need to either restrict usages to specific situations where you open the mapper for writes, or simple accept a higher risk of corrupted saves.

I'm not sure what actual licensed games historically did in these situations.
Re: Difference between RAM and cartridge SRAM?
by on (#242712)
here
Re: Difference between RAM and cartridge SRAM?
by on (#242713)
aquasnake wrote:
here


but cc65's devkit here name sram as " [c run] stack ram" actually, $700-$7FF, not general save ram(or static ram)
Re: Difference between RAM and cartridge SRAM?
by on (#242714)
$700-$7FF is just regular NES RAM same as the rest of it, using it for a stack in the compiled C code is a CC65 specific thing.
Re: Difference between RAM and cartridge SRAM?
by on (#242717)
Yes, the 6502 is hardwired to always use page 1 ($0100 to $01FF) for the hardware stack.
Re: Difference between RAM and cartridge SRAM?
by on (#242720)
It's not even a cc65 specific thing. You can put cc65's software stack anywhere in RAM, and it doesn't need to take up a whole page either. It's not really relevant to this discussion about hardware RAM layout though.


The hardware stack at $100-$1FF is relevant, though that's not what aquasnake brought up.
Re: Difference between RAM and cartridge SRAM?
by on (#242739)
Also, since page 0 and page 1 are mapped to the internal RAM on the NES they can also still be used as normal RAM. They are not magical in any way except that they can be used by zero page addressing and the hardware stack respectively. Of course any usage of page 1 should be carefully controlled so that it doesn't clash with the stack.

Sumez wrote:
Pokun wrote:
but battery backed WRAM is also used, and besides it can still be used as normal work RAM no matter if it has a battery or not.

Important difference is though, that most mappers with battery backed RAM also often include a way to protect writes to the RAM, since unintended writes while turning off power to the console could potentially corrupt battery backed RAM. For cartridge RAM only used as "WRAM", that corruption wouldn't matter.

So if you want to use the cartridge RAM for both saves and extra work RAM, you need to either restrict usages to specific situations where you open the mapper for writes, or simple accept a higher risk of corrupted saves.

I'm not sure what actual licensed games historically did in these situations.
Good point.

Ever since I learned that mappers like both MMC1 and MMC3 has write protection of the cartridge RAM, I've been wondering why games like Dragon Quest always reminds you of holding RESET when turning off power. Isn't the write protection enough?
Re: Difference between RAM and cartridge SRAM?
by on (#242742)
I think the write protect registers are mostly just protection against software bugs, but the chaos of power-off had other ways to corrupt it.

I think later games have diodes on the board that help protect against the power-off problem. Like StarTropics doesn't give you any special power-off instructions, it just warns you not to switch off during the brief moment while the game is in-progress of a save.
Re: Difference between RAM and cartridge SRAM?
by on (#242746)
Pokun wrote:
Ever since I learned that mappers like both MMC1 and MMC3 has write protection of the cartridge RAM, I've been wondering why games like Dragon Quest always reminds you of holding RESET when turning off power. Isn't the write protection enough?

That write protection exists only in MMC1B or newer. Apart from that, I don't know if that protection flag is enough, if neccessary one could combine it with additional "analog" protections, like checking if VCC is higher than 3V.
Re: Difference between RAM and cartridge SRAM?
by on (#242754)
SRAM is a memory chip that is faster and requires less power than DRAM. More costly than DRAM, SRAM is generally used by the computer as cache memory. ... DRAM is a memory chip that can hold more data than an SRAM chip, although it is slower and needs more power
Re: Difference between RAM and cartridge SRAM?
by on (#242756)
rainwarrior wrote:
I think the write protect registers are mostly just protection against software bugs, but the chaos of power-off had other ways to corrupt it.

I think later games have diodes on the board that help protect against the power-off problem. Like StarTropics doesn't give you any special power-off instructions, it just warns you not to switch off during the brief moment while the game is in-progress of a save.
nocash wrote:
Pokun wrote:
Ever since I learned that mappers like both MMC1 and MMC3 has write protection of the cartridge RAM, I've been wondering why games like Dragon Quest always reminds you of holding RESET when turning off power. Isn't the write protection enough?

That write protection exists only in MMC1B or newer. Apart from that, I don't know if that protection flag is enough, if neccessary one could combine it with additional "analog" protections, like checking if VCC is higher than 3V.
I see, so the flag might not be reliable as the voltage drops.

On the SNES they say it didn't have the hold-RESET requirement, but it sounds like protecting the cartridge memory is a job for the cartridge and have nothing to do with the console. Actraiser is the only SNES game that I remember to actually have the Dragon Quest-style "please hold RESET when turning off the system" kind of message when saving and quitting (it's an Enix game after all).
Re: Difference between RAM and cartridge SRAM?
by on (#242759)
I always assumed that MMC1 write protection was for the power-on state, rather than power-off. Since you can never predict when the user will cut the power, you'd have to disable the RAM all the time to keep it safe. Which seems totally useless.

tepples wrote:
Others are ferroelectric RAM (FeRAM), as used in Sonic the Hedgehog 3.

Kind of interesting that they used it once in a fairly big release, then seemingly never used it again in any game carts (AFAIK). It must have been 256 bytes or something small. I remember in 2005 or so I briefly considered using FRAM in my Squeedo design before I understood it had read endurance. I'm not 100% sure but I want to say the price difference was something like $1.50 for 32kB SRAM, VS $10 for 8kB FRAM. Neat stuff, but too expensive, using Flash+SRAM made more sense than EPROM+FRAM.

There was another technology that's not in any game carts (AFAIK), but there were some chips that were a drop-in replacement for SRAM, but it was a combined SRAM and Flash. It would restore the SRAM contents on power-on, and save the SRAM contents automatically when the chip loses power. Seems to have died out and/or been a boutique part though.