MiSTer-devel / NES_MiSTer

GNU General Public License v3.0
174 stars 75 forks source link

CPU fails to stop after a KIL unofficial opcode #379

Open SBDWolf opened 5 months ago

SBDWolf commented 5 months ago

KIL/STP/JAM/HLT is a series of unofficial opcodes that are supposed to stop the CPU after their execution: https://www.masswerk.at/6502/6502_instruction_set.html#JAM

However, it would seem that on the MiSTer, the CPU will continue running after the execution of one of these opcodes. This can be tested with these test ROMs: https://github.com/threecreepio/nes-hlt-test/releases

I think this is standard 6502 behavior and not specific to the 2A03 (though I'm not 100% sure).

These are unofficial opcodes and I'm not aware of any officially licensed titles intentionally making use of these (understandably so, stopping the CPU is not very useful). However, one area where this is quite relevant is in Speedruns making use of an ACE exploit, like Super Mario Bros. 3 Any% or Castlevania Any% w/ ACE. These runs involve setups that make use of game bugs that shift the Program Counter within RAM, where a payload can be placed to warp directly to the end credits, for example. In certain cases, depending on luck or player execution, a STP opcode may be encountered. If a platform is not emulating the behavior of this opcode correctly, it may cause the ACE to work in situations where it wouldn't on original hardware.