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:
1 parent
aff8391e55
commit
7f30c3f450
34 files changed
+3961
-74
No files matched your search
+18
-1
@@ -11,6 +11,8 @@ import { renderPokedexScreen, renderPokedexTab } from "./ui/pokedex";
|
||||
import {
|
||||
RESERVED_KEYS,
|
||||
TEXT_SCALES,
|
||||
VOLUMES,
|
||||
type Volume,
|
||||
applyTextScale,
|
||||
buttonKeys,
|
||||
defaultPreferences,
|
||||
@@ -93,7 +95,12 @@ function showWorld(world: GameWorld) {
|
||||
get("town-map-view").hidden = !world.townMap;
|
||||
if (world.townMap)
|
||||
drawTownMap(get<HTMLCanvasElement>("town-map-canvas"), world);
|
||||
const dialogue = world.dialogue;
|
||||
// While a script waits for its sound, the last page stays in the box.
|
||||
const dialogue =
|
||||
world.dialogue ??
|
||||
(world.waitingPage !== undefined
|
||||
? { pages: [world.waitingPage], index: 0, holdTicks: 0 }
|
||||
: undefined);
|
||||
showPicture(world);
|
||||
// A page without text is a button wait while a picture is shown.
|
||||
const pictureWait = Boolean(
|
||||
@@ -1696,6 +1703,7 @@ const input = new InputController((button, pressed) =>
|
||||
let preferences = loadPreferences();
|
||||
let keys = keyMap(preferences);
|
||||
applyTextScale(preferences.textScale);
|
||||
runtime.setVolume(preferences.volume);
|
||||
const controls = bindControls(
|
||||
root,
|
||||
input,
|
||||
@@ -2021,6 +2029,7 @@ function setPreferences(next: Preferences, status = "") {
|
||||
keys = keyMap(preferences);
|
||||
savePreferences(preferences);
|
||||
applyTextScale(preferences.textScale);
|
||||
runtime.setVolume(preferences.volume);
|
||||
get("game-screen").setAttribute("aria-label", `Game screen. ${controlsSummary()}`);
|
||||
showSettings();
|
||||
get("settings-status").textContent = status;
|
||||
@@ -2028,6 +2037,8 @@ function setPreferences(next: Preferences, status = "") {
|
||||
function showSettings() {
|
||||
for (const radio of document.querySelectorAll<HTMLInputElement>('input[name="text-scale"]'))
|
||||
radio.checked = Number(radio.value) === preferences.textScale;
|
||||
for (const radio of document.querySelectorAll<HTMLInputElement>('input[name="volume"]'))
|
||||
radio.checked = Number(radio.value) === preferences.volume;
|
||||
get("key-table").replaceChildren(
|
||||
...BUTTON_ORDER.map((button) => {
|
||||
const row = document.createElement("tr"),
|
||||
@@ -2112,6 +2123,12 @@ for (const radio of document.querySelectorAll<HTMLInputElement>('input[name="tex
|
||||
if (TEXT_SCALES.includes(scale))
|
||||
setPreferences({ ...preferences, textScale: scale }, `Text size: ${radio.parentElement?.textContent?.trim()}.`);
|
||||
});
|
||||
for (const radio of document.querySelectorAll<HTMLInputElement>('input[name="volume"]'))
|
||||
radio.addEventListener("change", () => {
|
||||
const volume = Number(radio.value) as Volume;
|
||||
if (VOLUMES.includes(volume))
|
||||
setPreferences({ ...preferences, volume }, `Sound: ${radio.parentElement?.textContent?.trim()}.`);
|
||||
});
|
||||
get("reset-keys").addEventListener("click", () =>
|
||||
setPreferences({ ...preferences, keys: defaultPreferences().keys }, "Controls reset to the defaults."),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user