Back to documentation

Tetorica Playground — For AI

Use these type definitions and working examples when generating JavaScript for the Tetorica browser Playground.

Type definitions

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.

Execution contract

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.