Conversation
The save state engine only enters by hijacking an S-CPU NMI or IRQ vector fetch. Sections that run with NMI disabled (NMITIMEN bit 7 clear) and no IRQ source, such as title screens polling for Start via auto-joypad read, never fetch a vector, so a save or load request can never trigger. The latched request instead fires at the next vector fetch once gameplay re-enables NMI, capturing or restoring a random later moment. Add a timer to the savestate engine: when a request stays armed for ~48.8 ms (2^20 MCLK ticks) without a hijack, assert ss_nmi_force, which ORs into P65_NMI_N and injects one edge-triggered NMI regardless of NMITIMEN. The existing vector-fetch hijack then steals that NMI and runs the helper, so the game's own handler never executes. The force drops as soon as ss_busy rises, and NMI edge detection keeps it single-shot. When no request is armed the term is a no-op, so existing timing is unchanged. Consoles in 6502 emulation mode (NMI vector $FFFA, not hijacked) stay out of scope; the helper is native mode only. Addresses MiSTer-devel#484.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The save state engine only enters by hijacking an S-CPU NMI or IRQ vector fetch (native-mode
$00FFEA/$00FFEE). Sections that run with NMI disabled (NMITIMEN bit 7 clear) and no IRQ source never fetch a vector, so a save or load request can never trigger. Title screens polling for Start via auto-joypad read are the common case.Worse, the latched request is uncancelable: it fires at the next vector fetch once gameplay re-enables NMI, capturing or restoring a random later moment instead of the screen the user asked for.
Affected games include those tracked in #484 (Earth Defense Force, Super Ninja Kid, Operation Logic Bomb). The current workaround is a per-game ROM byte-patch to force NMI enable, which is not a general fix.
Change
Add a timer to the savestate engine (
rtl/savestates.sv): when a request stays armed for ~48.8 ms (2^20 MCLK ticks, matching the siblingnmi_cycle_cntidiom) without a hijack, assert a newss_nmi_force. This ORs intoP65_NMI_Ninrtl/CPU.vhd, injecting one NMI regardless of NMITIMEN. The existing vector-fetch hijack then steals that NMI and runs the helper, so the game's own handler never executes.ss_busyrises; NMI edge detection keeps it single-shot (no storm, no re-fire after the helper's RTI).savestates.sv -> main.v -> SNES.vhd -> CPU.vhd, following the existingSS_*port style, with:= '0'defaults on the VHDL ports.Scope
Consoles in 6502 emulation mode (NMI vector
$FFFA, not hijacked) stay out of scope; the helper is native mode only, and commercial games are in native mode wherever a save makes sense.Validation
Verilog testbench on
savestates.sv(iverilog):ss_nmi_forcerises after the timer on a quiet bus, the resulting$00FFEAfetch starts the walk, the force drops oncess_busyrises, and it stays low on the normal prompt-latency path (natural saves untouched).Addresses #484.