Play the music and sound effects from the ROM's sound engine (Closes #34)

The sound engine (audio/engine.asm, home/audio.asm) is ported on a byte
copy of its audio WRAM and a sound register model. A reference test runs
the cartridge's routines beside it and matches the WRAM and registers
after every UpdateSound for all songs, effects and cries, fades, the
danger tone and effect priority. apu.ts synthesizes the four channels in
an AudioWorklet; its output matches the reference emulator's APU by
spectrum. The world runs the engine twice per tick; Play or the first
press unlocks sound, pausing suspends it, Settings sets the volume.

Wired in: map music by map setup and special map music, script audio
commands, text fanfares, WaitSFX and cries that hold the script frozen
(the last page stays shown), battle music, cries, fainting, victory,
capture and the low HP tone, Pokémon Center healing, evolution, the
intro, the Pokédex's cries, PCs, marts, healing items, talk and menu
clicks, bumps, ledges, warps, boulders, the Bicycle and Surf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
kawaandClaude Opus 5.5 committed 2026-10-15 15:54:02 +02:00
1 parent aff8391e55
commit 7f30c3f450
34 files changed
+3961 -74

No files matched your search

+11
View File
@@ -1,3 +1,5 @@
import type { GameSound } from "../audio/sound";
import { SOUND } from "../audio/constants";
import type { RomReader } from "../rom/reader";
import type { PokemonData } from "../rom/pokemon";
import { ENGINE_FLAGS, MENU, PC, RAM } from "../rom/profile";
@@ -37,6 +39,8 @@ export interface PcHost {
numbers: Record<number, number>;
/** _PlayerDecorationMenu: true if a decoration changed. */
decorationMenu(): Gen<boolean>;
/** The sound engine, for the PC's boot, choice and shutdown sounds. */
sound?: GameSound;
}
/** PokemonCenterPC's menu items (PCPCITEM_*). */
@@ -144,6 +148,8 @@ export class PcSession {
yield* this.print(PC["PC_CheckPartyForPokemon.PokecenterPCCantUseText"]);
return;
}
// PC_PlayBootSound
this.host.sound?.playSFX(SOUND.SFX_BOOT_PC);
yield* this.print(PC.PokecenterPCTurnOnText);
const whose = this.pages(PC.PokecenterPCWhoseText);
let cursor = 0;
@@ -160,6 +166,10 @@ export class PcSession {
undefined,
cursor,
);
// PC_PlayShutdownSound when leaving; PC_PlayChoosePCSound otherwise.
const sound = this.host.sound;
if (choice < 0 || items[choice] === PCPCITEM_TURN_OFF) sound?.playSFX(SOUND.SFX_SHUT_DOWN_PC);
else sound?.playSFX(SOUND.SFX_CHOOSE_PC_OPTION);
if (choice < 0) return;
cursor = choice;
switch (items[choice]) {
@@ -187,6 +197,7 @@ export class PcSession {
/** _PlayersHousePC: returns true when a decoration changed, which makes
* the script reload the room. */
*playersHousePC(): Gen<boolean> {
this.host.sound?.playSFX(SOUND.SFX_BOOT_PC);
yield* this.print(PC.PlayersPCTurnOnText);
return yield* this.playersPC(true);
}