← All SNES demos

Backtracking Solver

Algorithms & Data

Queens drop onto the board as the search descends. Abandoned rows flash red and disappear together when a dead end jumps back to a still-viable choice.

Self-running — no controller input required.

Verify fidelity checks the recorded result against 0x7336.

Source backtrack.cbacktrack.h in wbniv/llvm-mos-65816

What you see

Queens drop onto the board as the search descends. Abandoned rows flash red and disappear together when a dead end jumps back to a still-viable choice.

The defect this ROM exposed

The first native 65816 run revealed that the SNES longjmp implementation did not reconstruct page-1 hardware stack state at all. The assembly entered 16-bit accumulator mode, but encoded and #$00ff as an 8-bit immediate because the assembler chose operand width from the literal. The CPU consumed the next opcode as the second immediate byte, so the stack reconstruction and return-address path were skipped or decoded as unrelated instructions.

The repair uses the assembler's explicit 16-bit immediate modifier in platforms/snes/setjmp.S. It is a runtime/assembler contract repair, not a change to the 8-queens algorithm: a correct nonlocal return must restore the page-1 stack, saved registers, and return address before execution resumes.

What is checked

Each recursion level owns a setjmp choice point. A longjmp can discard several hardware and software stack frames at once; the gate folds solution boards, visit counts, unwind depths, and the full event trace into 0x7336. A wrong stack reconstruction changes both the visible jumps and the host comparison. The repaired ROM agrees across the published emulator checks; the retained investigation records the original instruction-decoding failure.

Compiler stress-test #116. The downloadable ROM and browser player use the same verified artifact.