OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Two S-DSP programs — noise drums and hardware vibrato — hot-swapped with apuReset(). More...

#include <snes.h>
#include <snes/apu.h>
#include <snes/input.h>

Macros

#define SPC_BASE   0x0200

Functions

int main (void)
static void start_song (u8 song)
 Upload and start one of the two APU programs.

Variables

u8 current_song
 Active program: 0 = drums, 1 = cello (probe oracle).
u8 spc_cello []
u8 spc_cello_end []
u8 spc_drums []
u8 spc_drums_end []

Detailed Description

Two S-DSP programs — noise drums and hardware vibrato — hot-swapped with apuReset().

The apu module's upload path (apuWaitBoot/apuUpload/apuExecute) runs once, at boot. This example adds the missing capability: replacing the running APU program at ANY time. The method is krom (Peter Lemon)'s PlayTwoSong protocol, productized: the 65816 writes APU_RESET_MAGIC to I/O port 0 (apuReset()); the SPC700 program polls for it in its wait loops (the APU_CHECK_RESET idiom), silences the DSP, and jumps back to the IPL boot ROM — ready for the next upload.

Press A for the drum kit, B for the vibrato cello. Both APU programs are this repo's own ports of krom's demos: the drums are the DSP's white-noise generator alone (NON, the FLG noise clock, one ADSR per drum: krom's PlayNoise), the cello sings by pitch modulation (PMON: a silent voice as a hardware LFO: krom's PitchMod). No external assets beyond the cello sample already attributed.

ROM mode: LoROM (project default).

SNES Concepts
  • Cooperative APU reset: CPU→APU messaging over $2140 after boot
  • The IPL ROM is re-entrant — jump to $FFC0 with the ROM re-enabled and the full boot handshake ($AA/$BB, $CC upload) works again
  • Two independent APU programs in one ROM, uploaded on demand
  • The S-DSP noise source (NON, FLG bits 0-4) as an instrument; the ADSR envelope is the drum type
  • Pitch modulation (PMON): voice N-1's output scales voice N's pitch
  • FIR echo setup (ESA/EDL/EFB/FIR0) in each program
What to Observe
Drums start immediately. Press B: the kit cuts, the cello blooms. Press A: back to the drums. The backdrop tracks the active program (red = drums, amber = cello). Swap latency is a few frames — the SPC polls for the reset request every millisecond.
Modules Used
console, apu, input
See also
https://github.com/PeterLemon/SNES — PlayTwoSong, the original protocol demo (its songs use samples ripped from commercial games, so this port swaps between two OpenSNES-native programs instead)
drums.spc700.asm, cello.spc700.asm — the two APU programs

Macro Definition Documentation

◆ SPC_BASE

#define SPC_BASE   0x0200

Function Documentation

◆ main()

int main ( void )

< A button

< B button

◆ start_song()

void start_song ( u8 song)
static

Upload and start one of the two APU programs.

Variable Documentation

◆ current_song

u8 current_song

Active program: 0 = drums, 1 = cello (probe oracle).

◆ spc_cello

u8 spc_cello[]
extern

◆ spc_cello_end

u8 spc_cello_end[]

◆ spc_drums

u8 spc_drums[]
extern

◆ spc_drums_end

u8 spc_drums_end[]