Skip to content

Rachael's SPC700 in C, with its APU - #104

Merged
skerkewitz-agent[bot] merged 1 commit into
developfrom
rachael-spc700
Nov 30, 2026
Merged

skerkewitz-agent[bot] merged 1 commit into
developfrom
rachael-spc700

Conversation

@skerkewitz-agent

Copy link
Copy Markdown
Contributor

What

This is step 1 of "Krautrecker's songs on the desktop and the web": an SPC700 in C for Rachael, with the APU around it. The step comes from the decision that the desktop plays Krautrecker's songs by running its driver on Rachael, not the preview's WAVs (ADR-6G3QXFJ0). The library doesn't use it yet; step 2 connects it through the ports.

How

  • lib/rachael/spc700.c is a port of dampf.emu.Spc700: all 256 opcodes, cycle by cycle, through a bus of three function pointers (read, write, idle). The structure follows the Java version function for function.
  • lib/rachael/apu.c puts it on Rachael's audio RAM (sdevkit__sound.aram), as dampf.emu.Apu does:
    • the I/O registers at $F0-$FF;
    • the three timers;
    • the four ports;
    • $F3 writes going to her DSP (sdevkit__dsp_write), and reads of $F3 returning the register as last written.
  • What apu.c does differently from the Java APU:
    • There is no boot ROM: the kit will write the audio RAM itself and jump (sdevkit__apu_jump, with the registers the boot ROM leaves).
    • A read of the boot ROM's area is counted, not thrown.
  • The declarations are in rachael.h. The desktop and web builds compile both files, unused for now.

Verified

  • ./gradlew build: 1300 tests, 0 failed, including the desktop and web builds of every example, now with these two files.
  • New RachaelSpc700Test, which compiles the C with cc -Wall -Wextra -Werror:
    • Against dampf's SPC700, in every build: 200 random states per opcode (51,200 tests). Registers, flags, memory and every bus cycle are the same. To check that this comparison catches mistakes, I broke ADC's half-carry on purpose: 26 opcodes failed. Then I restored it.
    • Against the SingleStepTests suite, with -PcpuTests=1000: 161,095 of 161,095 pass, every cycle included.
    • The APU: timer 0 counts at its target (port 0 changes between 1,900 and 2,200 cycles), the DSP takes $F2/$F3 and reads back, CONTROL $30 clears the ports from the CPU, and a read at $FFC0 with the boot ROM mapped is counted.
  • Not tried here: Windows (MSVC). The Windows release zip in CI compiles Rachael too.

What follows

  • Generated code and the game: dampf's output is unchanged; nothing changes for the game.
  • Documents: step 1 marked built in docs/roadmap.md; docs/testing.md; the rachael/ row of lib/README.md.
  • Book pages stale at the release: none.

Open

Step 2: the library talks to Rachael through the ports, and the SPC700's time has to line up with the desktop's frames.

🤖 Generated with Claude Code

lib/rachael/spc700.c ports dampf's SPC700 (all 256 opcodes, cycle by
cycle); apu.c puts it on Rachael's audio RAM with the I/O registers, the
timers and the ports of dampf.emu.Apu, without the boot ROM. Not used by
the library yet: that is step 2.

RachaelSpc700Test runs it against dampf's SPC700 on 200 random states per
opcode in every build, against the SingleStepTests suite with -PcpuTests,
and runs small APU programs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@skerkewitz-agent
skerkewitz-agent Bot merged commit b391bc6 into develop Nov 30, 2026
1 check passed
@skerkewitz-agent
skerkewitz-agent Bot deleted the rachael-spc700 branch November 30, 2026 20:10
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