PRG-RAM power-up state - NINA-001 / Impossible Mission 2

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
PRG-RAM power-up state - NINA-001 / Impossible Mission 2
by on (#230050)
Is anyone familiar with the behavior of Impossible Mission 2 on real hardware?

I just wrote a NINA-001 implementation for my emulator, and while testing the only NINA-001 game, I noticed that the starting map was different in my emulator compared to Nintendulator and puNES, but I don't know which behavior is correct.

Stepping through the game in the debugger, I noticed that it reads from uninitialized PRG-RAM! I haven't been initializing PRG-RAM, since I figured that its power-on state would be unreliable and random.

Without initializing PRG-RAM, my emulator starts the game with the number 4 highlighted in the lower-left. (Is that the current level?) Nintendulator and puNES start the game with number 7 highlighted. There are videos of the game on other platforms, and some seem to start with 1 highlighted, and others with 7 highlighted.

If I initialize PRG-RAM ($6000-$7FFF) to 0, then I get 7 highlighted, like the other emulators. If I initialize to 0xFF, then I get number 1 highlighted, like this C64 longplay. On real hardware with the original cartridge, is the starting number random or fixed, and if it is fixed, what does it start with?
Re: PRG-RAM power-up state - NINA-001 / Impossible Mission 2
by on (#230053)
Real world SRAMs tend to power on with some particular value, but that value depends on the specific vendor, process, and location within the die. All bits will power up with some probability of 1 or 0; for many of the bits this is sufficiently tilted to be reliably 1 or 0.

It could even be the case—who knows?—that AVE used multiple different models of SRAM during manufacture with entirely different behaviors and that all behaviors are "correct".
Re: PRG-RAM power-up state - NINA-001 / Impossible Mission 2
by on (#230059)
This sounds almost identical to subjects discussed in the past, only that this is about PRG-RAM region and not RAM/ZP region -- but in both cases the behaviour is the same.

The "major" thread on this subject is here -- viewtopic.php?f=3&t=10845 -- but there have been others. Dig around on the forum/search and you'll find others.

There is no "infallible" way to solve this in an emulator. It's recommended you do what Mesen and FCEUX do: let the user choose (in Preferences) what to initialise the RAM values as: all zeros, all ones, or random values. I advocate all zeros, but that will break some games; if you default to the opposite (all ones or random), that breaks other games. You can't do anything about it, and it's not your fault.

Also, I'm going to update this wiki page to note that this game does said thing. That page will interest you, I'm sure.
Re: PRG-RAM power-up state - NINA-001 / Impossible Mission 2
by on (#230102)
If the walkthrough on GameFAQs is to be believed, then we can deduce that Impossible Mission 2 relies on PRG-RAM being somewhat random on initialization:
Quote:
You begin the game on an elevator on a random tower. This game is completely random, and I will do my best to offer my solutions to each room as I get to them.
Re: PRG-RAM power-up state - NINA-001 / Impossible Mission 2
by on (#230173)
I have removed Impossible Mission 2 and Apple Town Story from the Game bugs wiki page. It is clear that these games read from uninitialized RAM to obtain a seed for random number generation, and doing so is not a game bug. I have instead added them to the respective section of the Tricky-to-emulate games page.