SWI 0x1E — SoundChannelClear¶
- Entry:
0x00001824(THUMB; SWI table stores0x00001825) - Status: verified (hardware-checked 2026-07-08: cycle counts and return registers measured on real GBA; struct layouts remain from static analysis)
Summary¶
Silences and resets all sound voices: clears the status byte of the 12 PCM mixer
channels and turns off the 4 CGB/PSG channels through the driver's PSG-off helper.
Used to stop all currently playing sounds immediately (e.g. before starting new
music or on a hard sound reset). Operates on the global SoundArea at [0x03007FF0]
and is guarded by the identity word.
Parameters¶
| Reg | In | Meaning |
|---|---|---|
| — | — | Operates on the global SoundArea at [0x03007FF0]; no explicit args |
Returns¶
| Reg | Out | Meaning |
|---|---|---|
| — | — | All PCM and PSG voices cleared |
Clobbered registers¶
r0–r7.
Hardware audit (2026-07-08, canary r4–r12 + CPSR snapshot): caller-visible clobbers: r0 = pointer into the sound area, r1 = 0, r3 = 0x170 leftover. r2, r4–r12, r13, and CPSR (flags and mode) came back bit-identical on every tested path. r11/r12 are explained by the SWI dispatcher (it pushes {r11, r12, lr} — see 10_irq_boot_and_iwram.md) and CPSR by the SPSR restore on return; r2 and r4–r10 must be preserved or restored by the routine itself — where a static note above claims r2 is destroyed, the hardware disagrees at the caller level. Raw data: results/clobber_audit_pass2.csv.
Algorithm¶
- Load SoundArea via
[0x03007FF0]; if identity word ≠0x68736d53, return. Otherwise bump the identity word (busy lock). - Clear the status byte of each of the 12 PCM channels at
SoundArea + 0x50 + i*0x40(i = 0..11), writing 0 (channel inactive/free). - If the CGB/PSG channel array pointer (SoundArea+0x1C) is non-null, iterate the 4
PSG channels (each 0x40 bytes) and call the internal PSG-oscillator-off helper
(
0x13C2, reached with the CGB-function pointer from SoundArea+0x2C) for each, then clear the trailing status byte. - Restore the identity word and return.
Edge cases & known bugs¶
- No-op if the SoundArea identity word is wrong.
- Only resets voice status; it does not zero the PCM mix buffers (the next SoundDriverMain simply mixes nothing for silenced voices).
Cycle count¶
Hardware-measured net CPU cycles (worker-ROM harness, TM0/TM1 cascade at F/1,
13-cycle baseline subtracted; identical across 3 runs — see
02_hardware_verification_checklist.md § Measurement setup).
244 cycles (no active channels).
Open questions (need hardware verification)¶
- Exact contract of the PSG-off helper (
0x13C2) and the CGB channel struct. - Whether the PSG hardware registers (
SOUND1CNT..SOUND4CNT) are written directly by the helper or only the software channel state is cleared.
GBATEK cross-reference¶
Matches GBATEK's SoundChannelClear; adds the concrete 12-PCM-channel stride (0x40,
base +0x50) and the 4-PSG-channel cleanup path.