Page 1 of 1

nes emulattion - where can i get ram data from

Posted: Sat Aug 23, 2008 10:53 pm
by bruce_lee
hi there,
i am in the process of completing the cpu side of a nes emulator i am programming.
The current problem i have is that the ram is loaded with no data - i understand that when loading the rom file the nes gets the program rom from the 10th element in the rom file, and the vrom comes after that. But where can i get the RAM data from??
any help would greatly be appreicated
many thanks

Posted: Sun Aug 24, 2008 6:24 am
by BitWise
The RAM contains random values at power on. The code in the ROM should initialise it.

Posted: Sun Aug 24, 2008 11:46 am
by bruce_lee
hi there, thanks for your reply,
can you elaborate on this for me please? , i understand that the rom data is retrieved at startup (assuming this is programmable rom we are talking about),
which part of the rom gets stored in the ram? at what offset? and how large? assuming we are using the fread function in C:

startup()
{
fseek(FILE_PTR,0x10,SEEK_SET);
fread(rom,sixteen_kb,numROM,FILE_PTR);

//which part of rom gets stored in ram?
}

any help you can give would be greatly appreciated
many thanks

Posted: Sun Aug 24, 2008 1:02 pm
by leeeeee
Quote:
which part of the rom gets stored in the ram?
None of it, the RAM contents are irrelevant at startup.

Posted: Sun Aug 24, 2008 5:35 pm
by kc5tja
If the NES is architected like most other computers, the program code stored in the ROM is wholly responsible for configuring the I/O and RAM variables it needs to function. Thus, you needn't concern yourself with the contents of RAM -- the game ROMs should take care of that for you.

Posted: Sun Aug 24, 2008 10:03 pm
by leegoukko
There are NES carts which contain RAM chips as well and is accessed via bank switching. I don't remember mapper number.

Posted: Mon Aug 25, 2008 7:25 am
by tomaitheous
http://nesdevwiki.org/index.php/NESdevWiki

The rom header will indicate if the game (not just the mapper) supports additional SRAM (mapped to $6000-$7fff). Be careful, some older iNES formats have incorrect headers. You can tell by search for 4 different identifiers in the second half of the $10 byte header. Look at Mednafen's source to see (I don't remember off hand what they were). If the RAM is battery backed, then I'm not entirely sure how to treat the ram when the rom is first ran/encountered. Probably just clear it out. Most(all?) games with battery backed SRAM do a CRC check on power/reset. Dragon Warrior reinitializes SRAM on CRC fail for example.

Also, not all games use VROM. Some games use VRAM (CHR RAM) with MMC and other mappers.