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

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
LightStruk
Posts: 42
Joined: Sat May 04, 2013 6:44 am

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

Post by LightStruk » Sat Dec 08, 2018 8:32 pm

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?

lidnariq
Posts: 9494
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

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

Post by lidnariq » Sat Dec 08, 2018 9:08 pm

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".

User avatar
koitsu
Posts: 4218
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

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

Post by koitsu » Sat Dec 08, 2018 9:45 pm

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.

User avatar
LightStruk
Posts: 42
Joined: Sat May 04, 2013 6:44 am

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

Post by LightStruk » Sun Dec 09, 2018 1:22 pm

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:
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.

NewRisingSun
Posts: 1198
Joined: Thu May 19, 2005 11:30 am

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

Post by NewRisingSun » Mon Dec 10, 2018 10:23 am

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.

Post Reply