Skip to content

A complete SPC700 in dampf's emulator, with its timers and I/O registers - #97

Merged
skerkewitz-agent[bot] merged 3 commits into
developfrom
spc700
Nov 30, 2026
Merged

skerkewitz-agent[bot] merged 3 commits into
developfrom
spc700

Conversation

@skerkewitz-agent

Copy link
Copy Markdown
Contributor

What

dampf's emulator gets a complete SPC700. Until now it ran only the 17 opcodes of the kit's 21-byte forwarding driver and stopped on any other, so Krautrecker's music driver could not run in it. This is the first step towards SNES music from Krautrecker's zips; the decision that the music driver is our own and lives in Krautrecker is ADR-6FYT4Z4T.

The examples behave exactly as before: the forwarding driver takes the same cycles.

How

  • dampf/emu/Spc700.java: all 256 opcodes, cycle by cycle. Every bus call is one cycle (a read, a write or an idle cycle) in the chip's order, dummy reads included. Those matter, because reading a timer counter clears it. The cycle sequences follow ares's; the suite confirms them.
  • dampf/emu/Apu.java uses it in place of the old subset, and adds the I/O registers a driver uses:
    • CONTROL ($F1): timers on or off, port clears, the boot ROM mapping;
    • timers 0 and 1 at 8 kHz and timer 2 at 64 kHz, with targets and 4-bit counters that a read clears;
    • the registers the boot ROM leaves at its jump: SP $EF, A, X and Y 0, the address in $00-$01.
  • The boot ROM stays behaviour, since its code is Nintendo's. A read of it while it is mapped stops with a message saying so; a driver maps it out with bit 7 of CONTROL, as Krautrecker's does.
  • The DSP is still only its registers. ENDX, ENVX and OUTX read as last written, because no sound is made here.

Verified

  • Spc700SingleStepTest against the SingleStepTests SPC700 suite (MIT): with -PcpuTests=1000, all 161,095 tests in the first 200 KB of each opcode's file pass: registers, flags, memory, and every bus cycle with its kind and address. Like the 65816 test it only runs with -PcpuTests (300 per opcode by default), so CI doesn't download the suite.
  • The first run had 246 of 256 opcodes right. The suite found three cycle orders I had wrong ([d]+Y reads, movw ya,d, sleep/stop).
  • New ApuTest: timer 0 counts at its target, writes to the registers land in the RAM too, the boot code's registers at the jump, CONTROL clears the ports, and reading the boot ROM stops.
  • ./gradlew build: 1,273 tests, 2 failed, 14 skipped. Both failures are today's random loop programs, seeds 20787012 and 20787028 ("PC vs SNES from MIR"). They fail on develop too, with the old Apu.java put back, so they are miscompiles already in dampf, not caused by this change. I'll fix them in separate pull requests; CI here will fail on them until then. Everything that runs the emulator passes, ExamplesTest included, with unchanged sound logs.

What follows

  • Generated code: unchanged. The C guide, StyleGuideTest, the game: unaffected.
  • Documents: docs/testing.md describes the SPC700 and its validation.
  • Next steps: the sound check logs what the 65816 sends (decided on 2026-11-30), then SNES music from Krautrecker's zips with effects through its driver, then the example.

🤖 Generated with Claude Code

skerkewitz-agent Bot and others added 2 commits November 30, 2026 12:26
The emulator ran the 17 opcodes of the kit's forwarding driver and stopped
on any other, so Krautrecker's music driver (ADR-6FYT4Z4T) could not run in
it. Spc700 now runs all 256 opcodes cycle by cycle, every bus cycle in the
chip's order, dummy reads included; Spc700SingleStepTest checks it against
the SingleStepTests SPC700 suite with -PcpuTests (161,095 tests pass with
-PcpuTests=1000: registers, flags, memory and every cycle).

Apu adds the I/O registers a driver uses: CONTROL ($F1: timers, port
clears, the boot ROM), timers 0-2 with their targets and counters, and the
registers the boot ROM leaves at its jump. The boot ROM stays behaviour; a
read of it stops with a message. The examples' sound logs are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Small programs uploaded through the boot protocol check what the SPC700
suite does not: timer 0 counts at its target, a register write lands in the
RAM too, the boot code jumps with SP $EF, Y 0 and the address in $00-$01,
CONTROL clears the ports from the CPU, and a read of the boot ROM stops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@skerkewitz-agent

Copy link
Copy Markdown
Contributor Author

🤖 Merged develop

Merged develop at b2f5d89 (#98, the fix for seeds 20787012 and 20787028 that failed this pull request's CI). ./gradlew build passed: 1280 tests, 0 failed.

@skerkewitz-agent
skerkewitz-agent Bot merged commit 8b26727 into develop Nov 30, 2026
1 check passed
@skerkewitz-agent
skerkewitz-agent Bot deleted the spc700 branch November 30, 2026 15:40
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