The Commodore PET emulator behind PET Project's play page.
This is an adaptation of Thomas Skibo's JavaScript PET 2001 emulator
(skibo/skibo.github.io,
6502/pet2001, vendored at commit 6759471ee31fb97ed8f75b9c7ed88f5f77226411), BSD-2-Clause.
Skibo notes that Norbert Landsteiner maintains a much-extended version at
masswerk.at/pet — if you want a full-featured
in-browser PET, use that one. This repo stays minimal on purpose: it boots a
ROM 4.0 / 32K / 40-column PET, loads a .prg from a URL, types RUN, and
plays the CB2 sound. That's all the play page needs.
js/petloader.js— DOM-free.prgloading, READY-detection, RUN injectionjs/cb2audio.js— VIA CB2 shift-register bit stream → Web Audio. The downsampler runs on the main thread and posts finished PCM to an AudioWorklet (js/cb2worklet.js, loaded at runtime viaaddModule); browsers without AudioWorklet fall back to the deprecatedScriptProcessorNodejs/petplayer.js— mounts canvas + keyboard, boots, drives the above. Keys are held on the PET matrix from keydown to keyup (reusing petkeys.js's mapping tables), so a held game key doesn't stutter on the OS repeat delay. The canvas is focusable and takes focus on boot; key handling is gated on it holding focus, so the host page keeps its own keyboard when it isn't playingindex.html— bare harness:?prg=<url>boots a programtest/— headless Node tests (node --test)- Seven patches to the vendored core, each marked
// pet2001web:, across five files — bus accessors and an audio-sink setter (pet2001.js), an IO getter (pet2001hw.js), a per-cycle CB2 hook and its call site (pet2001io.js), the green-phosphor recolor (pet2001video.js, two sites) and a ROM 4 set regenerated from VICE's 4032 images (pet2001roms.js— see ROMs below)
js/pet2001roms.js embeds Commodore PET ROM images (BASIC 1/2/4, editor,
character generator). The ROM 1 and 2 images and both character generators
are upstream's. The ROM 4 set is regenerated from VICE's PET 4032 images —
basic-4.901465-23-20-21, edit-4-40-n-60Hz.901499-01 and
kernal-4.901465-22 — by tools/make-petrom4.mjs, because upstream's ROM-4
editor stores a raw keyboard matrix index at $97 where the 4032 editor
stores the decoded PETSCII that the demos read. That makes the emulated
ROM-4 machine ROM-identical to the pet4032 the demos are built against.
These are Commodore's historical firmware, not ours and not BSD-licensed — see
LICENSE. The PET-Project repo
itself contains no ROM images.
python3 -m http.server 8080
# then open http://localhost:8080/?prg=<url-of-a-.prg>
node --test