Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If a SNES has 128k memory and in assembly you can reference $FF:FFFF addresses, how does this work?

Am I misunderstanding something here? 128kB is way smaller than 0xFFFFFF bytes.

like image 505
VJC1288 Avatar asked Sep 23 '13 22:09

VJC1288


2 Answers

Okay, old question, but this just popped up in Google and I can totally answer this.

The confusion here lies in the difference between RAM, ROM, and the SNES's total address space. While it's true that the SNES only has 128K of RAM, that's just volatile memory and doesn't take into account ROM space. Working RAM is mapped to banks 7E and 7F, each 64K. VRAM is another 32K of volatile memory, but it's inaccessible within the standard address space and needs to be written to via special registers.

The most common ROM mappings (referred to as LoROM and HiROM within the community) map either 32K banks in the upper half of the address space in each bank or full 64K banks. "LoROM" maps 32K banks (00:8000-00:FFFF, 01:8000-01:FFFF, ..., 3F:8000-3F:FFFF, mirrored at 80:8000-BF:FFFF) while HiROM maps 64K banks (C0:0000-C0:FFFF, C1:0000:C1-FFFF, ... FF:0000-FF:FFFF). As mentioned earlier, working RAM maps to 64K banks 7E and 7F. I'm not all that familiar with how SRAM works but that maps to 70:0000 iirc and is mirrored in several additional banks in the 7X region.

Edit: As a further note, ROM of course is read only. It's where your program data (read: the game, its instructions and its assets) is stored. Anything that needs to be modified (compressed data that needs to be decompressed, level data, enemies, player stats, tilemaps for whatever displays on the various backgrounds, etc) gets transferred to RAM (7E/7F) for processing. ROM is what comes printed on the chips in your cartridges, while RAM is simply filled with garbage data every time the system gets turned on; it's fairly standard practice to use a simple loop to zero out RAM during a game's initialization steps.

Hope that clears things up!

like image 54
Gideon Avatar answered Nov 09 '22 03:11

Gideon


The fact that the address space of the SNES is much bigger than the actual number of addresses isn't a problem. On a 64-bit machine, pointers are large enough to address 1.844674407×1019 bytes, which is about 10 billion GB. I've never seen any computer with this much RAM, but that's not a problem. Some addresses just don't refer to any addresses in memory.

Hope this helps!

like image 28
templatetypedef Avatar answered Nov 09 '22 01:11

templatetypedef