aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgbc dev <gbc@localhost>2026-09-22 19:29:28 +0200
committergbc dev <gbc@localhost>2026-09-22 19:29:28 +0200
commit69ce132b9edb355ecf77199f4b2ee5b339c39a30 (patch)
treec18f82a6c5fe67a0529548db4ed0a0c62f20a36d
parentwasm: run the emulator in a browser (diff)
downloadsl0pboy-69ce132b9edb355ecf77199f4b2ee5b339c39a30.tar.gz
sl0pboy-69ce132b9edb355ecf77199f4b2ee5b339c39a30.tar.xz
sl0pboy-69ce132b9edb355ecf77199f4b2ee5b339c39a30.zip
web: boot a demo ROM on arrival, and a deploy script for gbc.sl0p.foo
The page fetched nothing on its own, so a visitor met an empty canvas and a file picker. It now loads roms/gbos.gb on arrival - gbos being a Unix-ish microkernel for the GBC, which shows off rather more of the emulator than a title screen - with a note pointing at SELECT for its on-screen keyboard and warning that its networking rides a link cable a browser tab doesn't have. Dropping your own ROM still replaces it (and hides the blurb). web/deploy.sh builds the wasm, stages index + wasm + the demo ROM, rsyncs to /opt/sl0p/gbc and curls the three URLs back. The ROM is a build artifact of ~/dev/gbos and deliberately not vendored here; if it's missing the page falls back to "drop in a ROM" on the 404, so the deploy still works. Also fixes a save-path bug that would have bitten the first 128KB cart: String.fromCharCode(...sram) throws RangeError on a spread that big, killing the autosave. Chunked, and the whole thing is wrapped for quota errors.
-rwxr-xr-xweb/deploy.sh48
-rw-r--r--web/index.html48
2 files changed, 92 insertions, 4 deletions
diff --git a/web/deploy.sh b/web/deploy.sh
new file mode 100755
index 0000000..071f981
--- /dev/null
+++ b/web/deploy.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+# Ship the browser build to gbc.sl0p.foo.
+#
+# Static files only - no service, no restart, nginx serves the directory. The
+# box does not build anything: the wasm is compiled here and rsynced.
+#
+# ./web/deploy.sh # build + ship
+# DRY=1 ./web/deploy.sh # show what would transfer
+# HOST=root@other ./web/deploy.sh
+#
+# The demo ROM is gbos (~/dev/gbos), which is a build artifact of that repo and
+# deliberately not vendored here - point GBOS_ROM at it if it lives elsewhere.
+set -euo pipefail
+
+HOST="${HOST:-root@sl0p.foo}"
+DEST="${DEST:-/opt/sl0p/gbc}"
+GBOS_ROM="${GBOS_ROM:-$HOME/dev/gbos/gbos.gb}"
+cd "$(dirname "$0")/.."
+
+echo "==> building wasm"
+make wasm
+
+stage="$(mktemp -d)"
+trap 'rm -rf "$stage"' EXIT
+install -Dm644 web/index.html "$stage/index.html"
+install -Dm644 web/sl0pboy.wasm "$stage/sl0pboy.wasm"
+
+if [ -f "$GBOS_ROM" ]; then
+ install -Dm644 "$GBOS_ROM" "$stage/roms/gbos.gb"
+ echo "==> demo ROM: $GBOS_ROM ($(du -h "$GBOS_ROM" | cut -f1))"
+else
+ # Not fatal: the page falls back to "drop in a ROM" when the fetch 404s.
+ echo "!! no demo ROM at $GBOS_ROM - shipping without it" >&2
+fi
+
+echo "==> ${HOST}:${DEST}"
+rsync -av --delete ${DRY:+--dry-run} -e ssh "$stage/" "${HOST}:${DEST}/"
+[ -n "${DRY:-}" ] && exit 0
+
+# nginx (user http/www-data) only needs to read; keep it root-owned.
+ssh "$HOST" "chown -R root:root '$DEST' && chmod -R a+rX '$DEST'"
+
+echo "==> verify"
+for p in / /sl0pboy.wasm /roms/gbos.gb; do
+ printf ' %-18s ' "$p"
+ curl -s -o /dev/null -w '%{http_code} %{content_type} %{size_download}B\n' \
+ "https://gbc.sl0p.foo$p"
+done
diff --git a/web/index.html b/web/index.html
index 5503048..f0f314b 100644
--- a/web/index.html
+++ b/web/index.html
@@ -52,6 +52,14 @@
<kbd>←↑↓→</kbd>/<kbd>WASD</kbd> d-pad · <kbd>Z</kbd> A · <kbd>X</kbd> B ·
<kbd>Enter</kbd> start · <kbd>Space</kbd> select · <kbd>R</kbd> reset
</div>
+ <div class="keys" id="demo-note">
+ booting <b>gbos</b> — a Unix-flavored microkernel for the Game Boy Color.
+ hit <kbd>Space</kbd> (SELECT) for the on-screen keyboard, then
+ <kbd>←↑↓→</kbd> + <kbd>Z</kbd> to type at the <code>/#</code> prompt — try
+ <code>ls</code>, <code>ps</code>, <code>uptime</code>.
+ <span style="opacity:.7">(its networking rides the link cable, which a browser
+ tab doesn't have — so <code>dhcp</code> just sits there discovering.)</span>
+ </div>
<script type="module">
const $ = (id) => document.getElementById(id);
@@ -141,9 +149,21 @@ addEventListener("blur", () => { buttons = 0; gb.gbw_set_buttons(0); });
let saveKey = null, saveTimer = 0;
const readSram = () =>
new Uint8Array(memory.buffer, gb.gbw_sram_ptr(), gb.gbw_sram_size()).slice();
+// NB: chunked. String.fromCharCode(...buf) on a 128KB save (gbos) blows the
+// argument limit and throws RangeError, taking the autosave with it.
+const b64encode = (buf) => {
+ let s = "";
+ for (let i = 0; i < buf.length; i += 0x8000)
+ s += String.fromCharCode.apply(null, buf.subarray(i, i + 0x8000));
+ return btoa(s);
+};
const persist = () => {
if (!saveKey || !gb.gbw_has_battery() || !gb.gbw_sram_size()) return;
- localStorage.setItem(saveKey, btoa(String.fromCharCode(...readSram())));
+ try {
+ localStorage.setItem(saveKey, b64encode(readSram()));
+ } catch (e) {
+ console.warn("[sl0pboy] save failed (quota?)", e);
+ }
};
const restore = () => {
if (!saveKey || !gb.gbw_has_battery()) return false;
@@ -214,18 +234,38 @@ async function loadROM(file) {
canvas.focus();
}
-$("file").addEventListener("change", (e) => e.target.files[0] && loadROM(e.target.files[0]));
+// A ROM shipped with the page, booted on arrival so the site does something
+// on its own. Dropping a file just replaces it.
+const DEMO = "roms/gbos.gb";
+async function loadDemo() {
+ try {
+ const r = await fetch(DEMO);
+ if (!r.ok) throw new Error(`HTTP ${r.status}`);
+ const buf = await r.arrayBuffer();
+ await loadROM(new File([buf], DEMO.split("/").pop()));
+ } catch (e) {
+ console.warn("[sl0pboy] demo ROM unavailable:", e);
+ $("demo-note").classList.add("hide");
+ say("core ready — drop in a ROM to start");
+ }
+}
+
+// Once you bring your own game, the gbos blurb is just noise.
+const userROM = (f) => { $("demo-note").classList.add("hide"); loadROM(f); };
+
+$("file").addEventListener("change", (e) => e.target.files[0] && userROM(e.target.files[0]));
const drop = $("drop");
addEventListener("dragover", (e) => { e.preventDefault(); drop.classList.add("over"); });
addEventListener("dragleave", () => drop.classList.remove("over"));
addEventListener("drop", (e) => {
e.preventDefault(); drop.classList.remove("over");
const f = e.dataTransfer.files[0];
- if (f) loadROM(f);
+ if (f) userROM(f);
});
-say("core ready — drop in a ROM to start");
+say("core ready — fetching the demo ROM…");
draw();
+loadDemo();
</script>
</body>
</html>