raydempsey wrote:
How do I set bit 1 of byte 6 in the header?
If you're hacking an existing ROM, use an hex editor. If you're assembling from source, look for the iNEs header and change the bit. Some programmers include the iNES header as a binary file (in which case you'd also need an hex editor), others have it defined in editable form in the source code. It varies.
Quote:
Is the only information saved from $6000 - $7FFF ?
Yes, but since it's RAM you can put anything you want in there. This was Nintendo's standard solution for saving games: a battery backed 8KB RAM chip mapped at $6000-$7FFF (right before the start of ROM, which is at $8000). In a ROM, all you need to do is use the header to specify that this area of memory should be preserved (i.e. it's free), but a real cart that doesn't already have SRAM must be significantly modified in order to support a game that expects this memory to be present.
Another important thing you have to consider when saving games is that data corruption does happen. This makes it important that you implement some for of error detection, to verify that the saved data is present and valid. The presence of saved data is often signaled by a few signature bytes, a sequence of specific values that isn't likely to appear at random. For example, a 4-byte signature has a chance of 1 in 18,446,744,073,709,551,616 of being created by accident, so that should be pretty safe. As for the validity of the saved data, a common approach is to checksum the data (when saving, add all bytes together, ignoring the carry, and save the resulting byte - when loading, add them all again and compare against the saved checksum). This is clearly not 100% safe, because the errors could coincidentally nullify themselves and still generate the same checksum, but that's somewhat unlikely.
BTW, the 8KB of extra RAM doesn't have to be used exclusively for saving, it can also be used as regular RAM. This means that by adding this memory to your game you not only get to save games, but you also bump the amount of RAM you have available from 2KB to 10KB.
raydempsey wrote:
.inesprg 1 ; 1x 16KB PRG code
.ineschr 1 ; 1x 8KB CHR data
.inesmap 0 ; mapper 0 = NROM, no bank swapping
.inesmir 1 ; background mirroring
I see you're using NESASM. I looked at the documentation and couldn't find anything related to enabling battery-backed SRAM. Apparently there are only these 4 directives controlling the iNES header, which sucks. Honestly I wouldn't be surprised if NESASM didn't support this, it isn't a very good or particularly well planned program. You can always run the final ROM through an hex editor, but that would be a pin in the ass to do every time. I suggest you start to assemble the ROM without a header and use an external 16-byte binary file containing your header, and use
copy /b header.bin + rom.bin rom.nes (if you're running windows) to generate the final ROM.
Movax12 wrote:
You could always use a password system instead.
That is indeed a good option if the amount of data you have to save isn't that large.