Skip to content

test(nr-3wg): pin that a taken same-page branch delays NMI as NESdev says - #3339

Merged
rmstdope merged 4 commits into
mainfrom
nr-3wg-branch-delays-nmi
Oct 4, 2026
Merged

rmstdope merged 4 commits into
mainfrom
nr-3wg-branch-delays-nmi

Conversation

@rmstdope

@rmstdope rmstdope commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Bead: nr-3wg (Tekken 2 attract-mode fight diverges from Mesen2 from frame ~1320).

Finding

The difference is Mesen2's, not NESER's. Tekken 2 uses its vblank idle counter $22 as an RNG. At frame 27, vblank's NMI first appears in the second cycle of the wait loop's taken, same-page BEQ. NESdev (CPU interrupts, Branch instructions and interrupts) says that kind of branch is not polled before its third cycle, so the NMI waits one instruction. NESER does exactly that. Mesen2's BranchRelative applies the rule to IRQ only, so its NMI timing drifts by a cycle each time this happens. By frame 1306, $22 differs ($B1 vs $AF) when the fight code reads it.

Experiment: NESER with Mesen2's rule matches Mesen2 at all 12 checkpoints to 3600 (0 px). Without it, 1500–3600 differ. The navigator chose to keep the NESdev behaviour and record the difference, as the bead's acceptance allows. The full evidence is in the bead's notes.

Change

Test only. test_taken_branch_without_page_cross_delays_nmi_like_a_two_cycle_instruction sweeps the vblank arrival over 0–30 dots and asserts that a taken same-page BEQ polls NMI where a 2-cycle NOP does. It also asserts that the sweep includes an NMI first seen in the second cycle (a 3-cycle LDA zp takes it). It passes as is, and fails with Mesen2's rule applied ("vblank 3 dots ahead (NOP: false, BEQ: true)"), so the decision cannot be undone by accident.

Validation

  • ./scripts/gate-full.sh: passed.
  • No emulator behaviour changes, so there is nothing to recheck by hand.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BVAhbPCxrs1fRqHCgG2Cd5

rmstdope and others added 2 commits October 4, 2026 14:13
…says

Tekken 2's attract-mode fight differs from Mesen2 from frame 1307 because
Mesen2 lets an NMI detected in a taken branch's second cycle through,
where NESdev's CPU interrupts page says the branch does not poll again.
The navigator chose the specification; this test keeps it that way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVAhbPCxrs1fRqHCgG2Cd5
… instruction

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVAhbPCxrs1fRqHCgG2Cd5
@rmstdope

rmstdope commented Oct 4, 2026

Copy link
Copy Markdown
Owner Author

Review (cold read, reviewed_head: 109e3dab754d568587f9cf3faee41d238f2e5c5d): reviewed before merge under the producer's review practice, by an agent given the diff and the bead, not the producer's reasoning. A bug bead has no plan, so the diff was read against the bead's bug claim and its reproduction test.

The reviewer confirmed the test passes as is and fails under Mesen2's IRQ-only rule (verified in a throwaway copy). It also confirmed the guard means the test cannot pass without checking anything, the result is deterministic, and the test follows the file's conventions.

  1. src/nes/cpu/cpu/tests.rs, helper nmi_taken_after_one_instruction: the zero_flag parameter is dead. Every call passes true. Either remove it or use it for a not-taken BEQ case. Not blocking.

Answer: 1, fixed in the next commit. The parameter is now used: a not-taken BEQ (zero_flag = false) must poll NMI where a NOP does, at every point in the sweep. The test still passes. This adds one assertion inside the same test, so no follow-up review was requested.

rmstdope and others added 2 commits October 4, 2026 15:13
…ference nr-046 had recorded

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVAhbPCxrs1fRqHCgG2Cd5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVAhbPCxrs1fRqHCgG2Cd5
@rmstdope
rmstdope merged commit 7c9bd67 into main Oct 4, 2026
12 checks passed
@rmstdope
rmstdope deleted the nr-3wg-branch-delays-nmi branch October 4, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant