Skip to content

Commit f9182ef

Browse files
committed
Add Run in BBC emulator button
Opens bbc.xania.org in a new tab with the current ENVELOPE and SOUND statements embedded as a two-line BASIC program via the embedBasic URL parameter, plus autorun so jsbeeb tokenises and RUNs immediately. Lets you A/B local Web Audio playback against real BBC behaviour with one click.
1 parent e5ac729 commit f9182ef

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ <h2>Visualisation</h2>
4646
<div class="transport">
4747
<button id="play">Play</button>
4848
<button id="stop">Stop</button>
49+
<button id="run-emulator" title="Open bbc.xania.org with the current ENVELOPE and SOUND auto-running">Run in BBC emulator ↗</button>
4950
</div>
5051
<h3>Presets</h3>
5152
<div class="presets" id="presets"></div>

src/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ document.getElementById("stop")!.addEventListener("click", () => {
231231
render(canvas, currentSamples, sound.pitch, null);
232232
});
233233

234+
document.getElementById("run-emulator")!.addEventListener("click", () => {
235+
// jsbeeb (bbc.xania.org) takes URL-encoded BASIC via embedBasic, with
236+
// &autorun to type RUN after tokenising. Two numbered lines are enough:
237+
// ENVELOPE registers the envelope, SOUND queues the note.
238+
const program = `10 ${formatBasic(env)}\n20 ${formatSound(sound.channel, sound.amplitude, sound.pitch, sound.duration)}\n`;
239+
const url = `https://bbc.xania.org/?embedBasic=${encodeURIComponent(program)}&autorun`;
240+
window.open(url, "_blank", "noopener,noreferrer");
241+
});
242+
234243
for (const btn of document.querySelectorAll<HTMLButtonElement>(".copy-btn")) {
235244
btn.addEventListener("click", async () => {
236245
const targetId = btn.dataset["copy"];

src/style.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
8282
}
8383
.field input:focus { outline: 1px solid #58a6ff; }
8484

85-
#play, #stop {
85+
#play, #stop, #run-emulator {
8686
color: white;
8787
border: none;
8888
border-radius: 4px;
@@ -95,6 +95,8 @@ code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
9595
#play:hover { background: #2ea043; }
9696
#stop { background: #6e7681; }
9797
#stop:hover { background: #8b949e; }
98+
#run-emulator { background: #1f6feb; margin-left: auto; margin-right: 0; }
99+
#run-emulator:hover { background: #388bfd; }
98100

99101
.basic-row {
100102
display: flex;

0 commit comments

Comments
 (0)