Tetorica Playground — For AI
Use these type definitions and working examples when generating JavaScript for the Tetorica browser Playground.
Type definitions
- Common Playground API
- YM2612 / Mega Drive selection
- Mega CD selection (also 32X and 32X Nuked)
- YM2608 / PC-98 selection
- YM2203 / PC-98 selection
- YM2610 / Neo Geo selection
- Game Boy mode
- Game Gear mode
- Master System mode
- DX7 mode
Read the common API and the one chip-selection file that matches the target Playground.
Game Boy mode uses gameboy.pulse, gameboy.wave and gameboy.noise, also through pg.gameboy. Use beat(), sleep() and liveLoop() for timing. Global play(), fm and OPN shortcuts are available in OPN modes.
Game Gear and Master System modes use the primary psg with PSG1, PSG2 and PSG3 for three tone channels, plus psg.noise(). Use psg.tone() / psg.off() and beat() / sleep(); these modes have no global play() or fm. Game Gear adds psg.setStereo(mask): bits 0..3 route tone 1–3 and noise to the right, bits 4..7 to the left, and 0xff enables both sides. Master System mixes the same PSG voices in mono and omits setStereo(); the optional YM2413 FM expansion is outside this mode.
The primary PSG is also available as pg.psg, in livePrepare(), and from await useSoundChip('segapsg'), without dispose(). Use await createSoundChip('segapsg') for an independent disposable PSG with stereo routing.
Mega CD mode combines Genesis FM and PSG with one RF5C164: eight PCM voices sharing 64 KiB RAM, without 32X PWM. await useSoundChip('rf5c164') borrows the primary instrument without dispose(); createSoundChip() adds an independent device. await inputAudio({title}) opens a file/microphone dialog and returns {name, source, sampleRate, channels: Float32Array[]} or null on Cancel. Crop and prepare the recording before pcm.loadSample() and keyboard events. Playback speed controls pitch; specify the sample's root note rather than assuming pitch detection.
Working examples
The canonical example source is playground_examples.js. The following links load representative examples into the Playground. Loading an example does not run it automatically.
- Open these source files from Playground FILES → examples to run them.
- Live Loop — tempo, notes, and named loops
- Ambient Choir Sample — sample loading, FX, and live state
- Noise Ocean — generated noise and parameter control
- FM API Beep — direct YM2612 setup
- PSG Scale — SN76489-compatible tone API
- Mega CD starter — FM and a short PCM bass with attack/release
- Mega CD sampler — choose or record audio, then play an eight-voice PCM keyboard
- Parallel FX — branched effect routing
- Game Boy mode pulse — primary APU and a named melody loop
- Game Gear starter — Sega PSG melody, noise rhythm, and stereo routing
- Game Gear stereo — route physical tone channels to the left or right speaker
- Master System starter — Sega PSG melody and noise rhythm in mono
Execution contract
- Generate JavaScript, not TypeScript.
- Top-level
awaitis supported. - Playground APIs are available as globals and through
pg. - Use stable, unique names for independent
liveLoop()andlivePrepare()state. - Project files are read with
file(); relative paths resolve from the running file. - Network APIs and external package installation are unavailable during user-code execution.
Suggested prompt context
You are writing JavaScript for the Tetorica Playground.
Use only APIs declared in the linked common and selected-chip .d.ts files.
Follow the canonical working examples.
Return JavaScript that can be pasted into the Playground and run directly.