punesemu / puNES

Qt-based Nintendo Entertaiment System emulator and NSF/NSF2/NSFe Music Player (Linux, FreeBSD, OpenBSD and Windows)
GNU General Public License v2.0
663 stars 42 forks source link

Bug: NES Metroid (US) Release Illegal Opcode Error #36

Open jcdenton2k opened 8 years ago

jcdenton2k commented 8 years ago

This happens with (at least) the USA release of Metroid for NES. Go to password screen then enter 'ENGAGE RIDLEY MOTHER FUCKER' and the emulator will spit out an illegal opcode error and restart the game.

On actual hardware it is REPORTED but not yet 100% verified that it can cause physical damage to the hardware itself. Obviously this shouldn't be emulated but I was hoping that there could be a way to identify this 'illegal opcode' and put in a workaround for this one case.

punesemu commented 8 years ago

When the emulator intercepts an illegal opcode, do not restart the rom (he never did), print only a message but continues to run regulary. Is there any video showing how it behaves on a real console?

jcdenton2k commented 7 years ago

This is one of the best videos I could find: https://www.youtube.com/watch?v=x3UyVylP7AI

It causes suitless-Samus to be stuck on the first screen with garbled graphics without a scrolling screen.

Thanks to Sirocyl @ RetroFresh Discord server for the following technical info:

[10:57 AM] Sirocyl: Allow me to clarify this, since I've studied it at length and extensively [10:57 AM] Sirocyl: It will not brick hardware, and it will not damage any consoles, virtual or otherwise. [10:58 AM] Sirocyl: What is going on here, is really simple to figure out when you know how Metroid passwords and the data in them work [10:59 AM] Sirocyl: the Metroid password data uses a 'nybble', or four bits, of data to store the level ID. [11:00 AM] Sirocyl: That gives sixteen distinct values, only five of which are valid levels. [11:06 AM] Sirocyl: There's only five levels; ENGAGE RIDLEY MOTHER FUCKER works as a valid code, and tells the system to load "Level 11". At the pointer for level 11, is garbage data and code. Some of these contain invalid/"illegal" 6502 opcodes. [11:07 AM] Sirocyl: The NES handles them as gracefully as any 6502 would; it either gets stuck in a loop, or halts. [11:08 AM] Sirocyl: The VC emulator traps on illegal instructions and illegal memory accesses. The reason for this, seems to be so that while developing VC, undefined behavior could be caught in the debugger and a programmer could see that this game does something different. [11:10 AM] Sirocyl: Without a debugger connected on the 3DS's "HIO" port, which does not exist physically on retail units and is disabled by hardware configuration burned into OTPROM, the VC emulator just appears to freeze. [11:10 AM] Sirocyl: Later versions of the 3DS system software had removed some latent debugging functions and stubbed them out to return an error, when called, instead of "wait busy" for debug hardware. [11:11 AM] Sirocyl: It's that "waiting busy" that made the OS freeze when the VC NES crashed.