c64-ready 0.10.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -4
- package/dist/assets/CHANGELOG-CPlXKLCV.js +279 -0
- package/dist/assets/index-Ckbi7gQo.js +535 -0
- package/dist/c64-ready/c64-ready.gif +0 -0
- package/dist/fonts/Commodore Angled v1.2.ttf +0 -0
- package/dist/fonts/Commodore Rounded v1.2.ttf +0 -0
- package/dist/fonts/Commodore-64-v6.3.TTF +0 -0
- package/dist/fonts/READ ME!.txt +127 -0
- package/dist/fonts/button-commodore-64-font.gif +0 -0
- package/dist/games/cartridges/bubble-bobble.crt +0 -0
- package/dist/games/cartridges/ghosts-n-goblins.crt +0 -0
- package/dist/games/snapshots/LVLLVL%BAAL.c64 +0 -0
- package/dist/games/snapshots/VICE2-4%APOLLO18.vsf +0 -0
- package/dist/games/snapshots/VICE3.10%ELEVATOR.vsf +0 -0
- package/dist/index.html +1 -1
- package/dist/tools/Keyboard-Test.prg +0 -0
- package/dist/tools/anykey-c64.prg +0 -0
- package/dist/tools/tools.json +6 -0
- package/package.json +1 -1
- package/src/emulator/c64-emulator.ts +10 -2
- package/src/emulator/input.ts +5 -2
- package/src/headless/c64-key-map.mjs +1 -1
- package/src/headless/headless-cli.mjs +77 -20
- package/src/headless/input-server.mjs +176 -16
- package/src/headless/webrtc-server.mjs +70 -6
- package/src/main.ts +54 -2
- package/src/player/c64-player.ts +126 -9
- package/src/player/load-formats.ts +58 -0
- package/src/player/styles/ui-controller.css +93 -2
- package/src/player/ui-controller.ts +262 -48
- package/src/types/emulator.ts +2 -1
- package/dist/assets/CHANGELOG-C1nvP1iO.js +0 -96
- package/dist/assets/index-Cioamf6E.js +0 -394
package/README.md
CHANGED
|
@@ -102,8 +102,18 @@ docker compose restart headless
|
|
|
102
102
|
GAME_PATH=/app/public/games/cartridges/legend-of-wilf.crt docker compose up
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
You can also drag-and-drop
|
|
106
|
-
|
|
105
|
+
You can also drag-and-drop game files onto the player page at any time to load without
|
|
106
|
+
restarting the container. Supported browser-side formats are `.crt`, `.prg`, `.d64`,
|
|
107
|
+
and native snapshots (`.c64`, `.snapshot`, `.s64`).
|
|
108
|
+
|
|
109
|
+
Note: VICE `.vsf` snapshots are currently disabled in the browser runtime.
|
|
110
|
+
|
|
111
|
+
### Keyboard limitations (current WASM build)
|
|
112
|
+
|
|
113
|
+
- The C64 `RESTORE` key is currently not functional in this build.
|
|
114
|
+
- We verified browser key mapping for `Page Up` is received, but the underlying
|
|
115
|
+
WASM core does not appear to trigger restore behavior from key input.
|
|
116
|
+
- Treat this as a runtime limitation of the shipped binary for now.
|
|
107
117
|
|
|
108
118
|
### Environment variables
|
|
109
119
|
|
|
@@ -537,9 +547,10 @@ On every push to `master`:
|
|
|
537
547
|
- [x] Docker headless streaming (RTMP / HTTP-FLV via Node Media Server)
|
|
538
548
|
- [ ] Gamepad support
|
|
539
549
|
- [ ] Touch controls
|
|
540
|
-
- [ ]
|
|
550
|
+
- [ ] Mobile Layout
|
|
551
|
+
- [x] Loading more game formats (e.g., .d64 disk images)
|
|
541
552
|
- [ ] Performance optimizations (e.g., offscreen canvas, audio worklets)
|
|
542
|
-
- [ ]
|
|
553
|
+
- [ ] Jitter creep - frame timing optimizations for smoother rendering
|
|
543
554
|
|
|
544
555
|
## Changelog & Releases
|
|
545
556
|
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
var e=`# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
No unreleased changes.
|
|
8
|
+
|
|
9
|
+
## v0.11.0 - 2026-04-11T10:48:07+01:00
|
|
10
|
+
|
|
11
|
+
- chore(release): 0.11.0 (1f4ff40)
|
|
12
|
+
- Merge pull request #38 from hayesmaker/feature/live-settings-parity-backend (8fdb739)
|
|
13
|
+
- feat(input): support host-defined joystick port overrides (86701b2)
|
|
14
|
+
- fix(prg): make headless autorun typing deterministic (d55ca16)
|
|
15
|
+
- feat(headless): support typed load-file command and reset-only hard reset (1b575b2)
|
|
16
|
+
- Merge pull request #37 from hayesmaker/feature/add-prg-support (b883c3e)
|
|
17
|
+
- feat: added keyboard test prg and snapshots (7325ffa)
|
|
18
|
+
- revert(snapshot): disable VICE .vsf support in browser runtime (5911735)
|
|
19
|
+
- feat(runtime): add ?game override and refine VICE snapshot parsing (69a38b6)
|
|
20
|
+
- feat(snapshot): add VICE best-effort loader and runtime load diagnostics (9330bfa)
|
|
21
|
+
- feat: lvllvl snapshot support (eb2fe61)
|
|
22
|
+
- fix(d64): enable 1541 drive before disk insert (9835894)
|
|
23
|
+
- fix(prg): auto-run after load and use inject mode (373615f)
|
|
24
|
+
- feat(ui): split settings into tabs and add format-aware loading (3df4373)
|
|
25
|
+
- Merge pull request #36 from hayesmaker/chore/deploy-and-release (3e5d444)
|
|
26
|
+
|
|
27
|
+
## v0.10.0 - 2026-04-09T09:24:54+01:00
|
|
28
|
+
|
|
29
|
+
- chore(release): 0.10.0 (6716e49)
|
|
30
|
+
|
|
31
|
+
## v0.9.0 - 2026-04-09T09:24:36+01:00
|
|
32
|
+
|
|
33
|
+
- chore(release): 0.9.0 (d03b2f1)
|
|
34
|
+
- Merge pull request #35 from hayesmaker/spike/video-telemetry-diagnostics (0dbc14a)
|
|
35
|
+
- fix(webrtc): handle early trickle ICE and send explicit SDP offers (b798fe6)
|
|
36
|
+
- feat(webrtc): keep one peer per viewer session (635c77c)
|
|
37
|
+
- feat(telemetry): log sender pressure metrics under log-events (3b1bccb)
|
|
38
|
+
- feat(admin): add c64-admin commands for status and client kicks (78091a7)
|
|
39
|
+
- feat(webrtc): use monotonic clocks and sample sender queue stats (b74f8af)
|
|
40
|
+
- feat(webrtc): add output fps cap and sender drop counters (15119e6)
|
|
41
|
+
- tune(webrtc): lower bitrate defaults and drop overdue video frames (5cc58cd)
|
|
42
|
+
- chore(docs): mv doc to correct location (c726d30)
|
|
43
|
+
- docs(troubleshooting): document auto-resync controls (51d9c60)
|
|
44
|
+
- docs(troubleshooting): update video lag threshold guidance (d95fd3a)
|
|
45
|
+
- docs(troubleshooting): add c64-live input lag runbook (94d7146)
|
|
46
|
+
- fix: input latency indicator improvement (ae12360)
|
|
47
|
+
- fix: attempt to fix network latency status (bc05b7c)
|
|
48
|
+
- fix: use wall clock delta for debugger_update (05c61f7)
|
|
49
|
+
- Merge pull request #34 from hayesmaker/fix/input-flood-instrumentation (d158729)
|
|
50
|
+
- feat(latency): network latency backend (c1ea04b)
|
|
51
|
+
- chore(logs): more diagnostic logging see LOGGING.md (df80b57)
|
|
52
|
+
- chore(logs): input latency profiling (8323723)
|
|
53
|
+
- chore(logs): added write logs to file (3dada37)
|
|
54
|
+
- feat(headless): add log file output with retention (75f2ed8)
|
|
55
|
+
- perf(input-server): add input flood instrumentation (d6d802d)
|
|
56
|
+
- chore(logs): only log key events on verbose mode (d94174d)
|
|
57
|
+
- chore(logs): only log inputs on verbose running (53a6698)
|
|
58
|
+
|
|
59
|
+
## v0.8.0 - 2026-04-05T08:53:20+01:00
|
|
60
|
+
|
|
61
|
+
- Merge pull request #33 from hayesmaker/chore/release-0.8.0 (090cbc7)
|
|
62
|
+
- chore(release): 0.8.0 Skip v0.7.0 (tagged locally, never published). This is the first public release since v0.6.2 and includes all v0.7.0 work plus: - feat(cart): parseCrtInfo — cartridge type/size/CHIP logging on load - fix(input): force host claim on reconnect — fixes detach/reset - fix(webrtc): enable buttons when initial game already loaded on connect - fix(docker): bake GIT_HASH into image via build arg - feat(hello): serverVersion + serverGitHash in hello message - feat(webrtc): --max-spectators connection limit - ci(test): PR workflow for branch-protection status check (bb284e4)
|
|
63
|
+
- Merge pull request #32 from hayesmaker/feat/cart-load-logging (4173b68)
|
|
64
|
+
- test(player): fix CRT stub — bump to 0x40 bytes to satisfy parseCrtInfo parseCrtInfo requires a minimum of 0x40 bytes (full CRT header) before it considers a buffer valid. The old 16-byte stub only contained the magic string; isValidCRT now delegates to parseCrtInfo so the test was throwing 'Invalid CRT file format'. Updated stubFetchForGame() to build a proper 0x40-byte header: - 16-byte signature 'C64 CARTRIDGE ' - header-length field = 0x40 (big-endian u32 at 0x10) - hwType = 0 (Normal cartridge) at 0x16 - exrom = 1, game = 1 (inactive / pass-through) at 0x18–0x19 (393a218)
|
|
65
|
+
- fix(input): force host claim on page (re)connect — fixes detach/reset The WebRTC player page always claims host on inputWs.onopen. If a previous session's WS connection is still open (Docker restart, page reload, or any connectWebRTC() call) the server returned host-taken and the new socket never became hostClient, so detach-crt and hard-reset were silently dropped (ws !== hostClient gate). Fix — two-part: input-server.mjs: Honour force:true on a host claim message. When set, the existing host socket is gracefully evicted (host-evicted message + close()) before the new connection is granted the slot. Without force:true the old rejection behaviour is preserved (multi-player aware callers should not force). webrtc-server.mjs (embedded browser page): Always send force:true with the host claim. The headless player page is a single-player UI; there is never a legitimate reason for a second host to exist concurrently, so forcibly taking the slot on every connect/reconnect is the correct policy. (fcfa464)
|
|
66
|
+
- feat(cart): log cartridge type, size and CHIP count on load Add parseCrtInfo() to src/emulator/crt-info.ts — parses the CRT binary header (magic, hwType, EXROM/GAME bits, cart name, CHIP packets) and returns a structured object plus a ready-to-log summary line. Browser player (c64-player.ts) calls parseCrtInfo() in both loadGame() (URL path) and loadFile() (drag-and-drop / file-input path), logging to console.log before emulator.loadGame(). isValidCRT() now delegates to parseCrtInfo() to avoid duplicating the magic-check logic. Headless CLI (headless-cli.mjs) carries an inline JS port of the same parser (no build step required) and logs to console.error at both the startup --game load site and inside the load-crt WebSocket command handler. Example output: [C64 cart] "legend-of-wilf.crt" loading: hwType=32(EasyFlash) | Ultimax flags, 96K actual | 12 CHIP(s) | 98560 bytes name="EasyFlash" (87fa675)
|
|
67
|
+
- Merge pull request #31 from hayesmaker/fix/webrtc-initial-game-buttons (49c258f)
|
|
68
|
+
- fix(webrtc): enable detach/reset buttons when initial game is already loaded When a browser client connects after the server has already booted with a game loaded (via --game CLI arg), the input server sends a 'hello' message containing cartFilename. The browser page was not acting on that field to enable the detach/reset buttons or update the game badge, leaving both buttons permanently disabled until a new cart-loaded event arrived. Add a 'hello' handler that mirrors the cart-loaded UI update: set the game badge, mark load-status as loaded, and enable both buttons. (03872dc)
|
|
69
|
+
- Merge pull request #29 from hayesmaker/feat/hello-build-info (ecb1ee7)
|
|
70
|
+
- Merge pull request #28 from hayesmaker/master (d5011f0)
|
|
71
|
+
- fix(docker): bake GIT_HASH into image via build arg; fall back to .git-hash file git is not installed in node:24-slim and .git is not bind-mounted, so execSync('git rev-parse --short HEAD') silently failed in the container and serverGitHash was never sent in the hello message. Fix: - Dockerfile.headless: accept GIT_HASH build arg (default 'unknown'), write it to /app/.git-hash during the build layer so it survives into the final image without needing git at runtime. - headless-cli.mjs: check GIT_HASH env var first, then read /app/.git-hash, then fall back to execSync (local dev only). - docker-compose.yml: pass GIT_HASH build arg via args block — resolves from host shell env at build time: GIT_HASH=$(git rev-parse --short HEAD) docker compose build headless - docker/.env.example: document MAX_SPECTATORS (missing from this branch) and add a note explaining GIT_HASH is a build arg, not a runtime var. (f8b1bb7)
|
|
72
|
+
- Merge pull request #27 from hayesmaker/feat/hello-build-info (97d8b6f)
|
|
73
|
+
- feat(hello): include serverVersion and serverGitHash in hello message headless-cli.mjs reads package.json version and runs git rev-parse --short HEAD at startup (both non-fatal — omitted if unavailable). Both values are passed to createInputServer as opts.serverVersion and opts.serverGitHash and included as optional fields in the hello frame sent to every new WebSocket client: { ..., serverVersion: '0.7.0', serverGitHash: '16e86cd' } Fields are omitted from the hello when null (standalone / non-git environments) so older clients receiving the message are unaffected. (9d287ee)
|
|
74
|
+
- Merge pull request #25 from hayesmaker/feat/spectator-limit (6e836ef)
|
|
75
|
+
- Merge branch 'master' into feat/spectator-limit (16e86cd)
|
|
76
|
+
- Merge pull request #26 from hayesmaker/chore/update-readme-webrtc-streaming (35b05d2)
|
|
77
|
+
- ci(test): add PR test workflow to satisfy branch protection status check The deploy.yml workflow only runs on push to master, so branch protection status checks were waiting indefinitely for a check that never fires on pull requests. Add .github/workflows/test.yml that: - triggers on pull_request targeting master - runs the same 'test' job (npm ci + npm test) as deploy.yml - uses the same job name 'test' so the required status check in the branch protection rule is satisfied by this workflow (c20c3b2)
|
|
78
|
+
- chore(docs): README update (c212758)
|
|
79
|
+
- docs(readme): rewrite headless streaming section for WebRTC NMS (Node Media Server) has been removed. The single headless container now streams directly over WebRTC — a self-contained player page on port 9002 handles video, audio, and keyboard/joystick input with no extra software required. Changes: - Replace two-container RTMP/NMS setup with single-container WebRTC docs - Add spectator limit section (MAX_SPECTATORS, player slots) - Document FFmpeg --record as a separate capture/debug tool that can run alongside or instead of WebRTC (file recording, RTMP push) - Update env variable table to match current docker/.env.example (add WEBRTC_*, LOG_EVENTS, MAX_SPECTATORS; remove NMS_* and RTMP_URL) - Update quick-start to point to http://localhost:9002 instead of ffplay - Add drag-and-drop cartridge loading note (d8551a2)
|
|
80
|
+
- feat(webrtc): add spectator connection limit (--max-spectators, default 5) Prevent CPU overload when many users spectate simultaneously by capping the number of concurrent WebRTC peer connections. How it works: - MAX_CONNECTIONS = 2 (player slots) + maxSpectators (default 5) = 7 - Capacity is tracked as active ICE-connected peers + pending (in-flight) WS connections so a burst of simultaneous connects can't slip through. - Connections over the limit receive { type: 'capacity-full', current, max, maxSpectators } and the WS is closed immediately — no ICE negotiation, no encoder load. - A webrtc-capacity-full event is logged when --log-events is active. Browser (headless page) already stops auto-reconnecting on capacity-full. c64cade useC64WebRTC.js must also be updated (see companion commit there). New flag: --max-spectators <n> default 5 Docker support: MAX_SPECTATORS=<n> in docker/.env (entrypoint passes it through) Documented in docker/.env.example (7091d83)
|
|
81
|
+
|
|
82
|
+
## v0.7.0 - 2026-03-31T19:52:09+01:00
|
|
83
|
+
|
|
84
|
+
- chore(release): 0.7.0 Promotes v0.7.0-rc.1 + v0.7.0-rc.2 + pre-release fixes to final release. Full changelog in CHANGELOG.md. (408c855)
|
|
85
|
+
- chore: merge feat/pre-release-fixes (3657c9c)
|
|
86
|
+
- chore: merge fix/v0.7.0-rc.2-release (ac2bfe5)
|
|
87
|
+
- feat(input-server): remove P2→host promotion; increase inactivity timeout to 10 min Three changes: 1. Remove P2 auto-promotion when host leaves Previously, whenever the host slot became vacant (voluntary leave, timeout, admin kick, or grace-period expiry) P2 was automatically promoted to host. This caused confusion — P2 had no expectation of taking over and could find themselves as host unexpectedly. Removed promoteP2ToHost() entirely. P2 now stays as P2 when the host leaves; the host slot becomes open for a new player to claim. Each path that previously called promoteP2ToHost() now broadcasts p2-slot-status open:false (since no host = slot is logically unavailable for new P2 joins too). 2. Fix player panel not clearing p2-slot-status on host leave Without the promotion call, voluntary host-leave, timeout kick, and admin kick were not broadcasting a p2-slot-status update. Added broadcastAll({ type: 'p2-slot-status', open: false }) to all four host-exit paths so every connected client updates its Join button state immediately. 3. Increase default inactivity timeout from 5 to 10 minutes Applies to both host and P2 (both use HOST_TIMEOUT). Reduces accidental kicks during normal play pauses. (4965158)
|
|
88
|
+
- chore(release): 0.7.0-rc.2 Bump version and update CHANGELOG for v0.7.0-rc.2. Single fix since rc.1: - fix(webrtc): WS ping/pong keepalive to prevent idle TCP timeout (031610d) (bd926eb)
|
|
89
|
+
|
|
90
|
+
## v0.7.0-rc.2 - 2026-03-31T18:30:33+01:00
|
|
91
|
+
|
|
92
|
+
- fix(webrtc): add WS ping/pong keepalive to prevent idle TCP timeout Root cause of the ~60s stream freeze observed in production: After ICE negotiation completes the signalling WebSocket carries no further traffic. Cloud NAT, Docker bridge networking, and OS TCP stacks silently drop idle connections after ~60s — exactly matching the log evidence (ws-closed firing ~60s after webrtc-ice-connected with no prior ICE disconnect event). Fix — two-layer keepalive: Server side (webrtc-server.mjs): - setInterval every 30s: ws.ping() all connected signalling clients - Track liveness with ws._sigAlive flag, reset on pong, set on pong - If a client misses a full ping interval (60s total): ws.terminate() and log webrtc-sig-timeout under --log-events - clearInterval(pingInterval) in close() to avoid timer leak Browser side (embedded HTML): - sigPingTimer: send {type:'ping'} every 30s on sigWs - Server replies with {type:'pong'} — browser handles it as no-op - sigPingTimer cleared in sigWs.onclose and connectWebRTC() teardown - Handle {type:'pong'} in sigWs.onmessage (no-op, prevents JSON parse errors from unrecognised message type) (031610d)
|
|
93
|
+
|
|
94
|
+
## v0.7.0-rc.1 - 2026-03-31T18:13:33+01:00
|
|
95
|
+
|
|
96
|
+
- chore(release): 0.7.0-rc.1 Release candidate for v0.7.0. Key changes since v0.6.2: - fix(webrtc): ICE disconnected grace period — root cause of periodic stream freeze - fix(webrtc): browser auto-reconnect on failed/peer-closed/sigWs-close - feat(headless): --log-events structured production logging - feat(input-server): per-player P2 inactivity timer - feat(input-server): host reconnect grace period (8s) before P2 promotion - fix(webrtc): RTCPeerConnection full reconnect on cart-load - fix(webrtc): force VP8 IDR keyframe after load/reset - fix(webrtc): audio RTP resync after blocking WASM gaps - fix(docker): VERBOSE=0 correctly disables verbose - chore(docker): WebRTC-only, NMS removed (d565e79)
|
|
97
|
+
- feat(input-server): add per-player inactivity timer for P2 Previously only the host had an inactivity timeout. P2 could sit connected indefinitely without sending any input and never be kicked. Changes: - Add p2TimeoutTimer / resetP2Timeout() / clearP2Timeout() mirroring the existing host timer, using the same HOST_TIMEOUT duration (5min) - resetP2Timeout() called on every joystick/key input from P2 - resetP2Timeout() called on P2 join (open + token) - clearP2Timeout() called on: voluntary leave, revoke-p2, admin kick, ws.on('close'), promoteP2ToHost(), and server close() - Kick sends p2-timeout-kick to P2 and broadcasts player2-left reason=timeout + p2-slot-status open=true to all clients - logEv('p2-timeout') emitted under --log-events (a674b0c)
|
|
98
|
+
- fix(webrtc): don't close peer on ICE disconnected; add logEv throughout Two changes: 1. ICE 'disconnected' grace period (root cause fix) The server was calling pc.close() immediately on iceConnectionState === 'disconnected', which is a transient state that the ICE agent is supposed to recover from on its own within a few seconds. Any brief packet loss, NAT keepalive gap, or Node GC pause could trigger it, permanently killing what would have been a recoverable connection — the browser then sat on a frozen frame with no indication the peer was gone. Fix: on 'disconnected', remove from activePeers (stop pushing frames) but start a 6s grace timer. If ICE recovers to connected/completed within that window the timer is cancelled and streaming resumes. Only after the grace expires (or on 'failed'/'closed') is closePeer() called. closePeer() sends a 'peer-closed' message to the browser so it can reconnect immediately rather than waiting for a timeout. 2. Browser auto-reconnect - On ICE 'failed': scheduleRtcReconnect(1000) - On sigWs close: scheduleRtcReconnect(2000) instead of dead badge - On 'peer-closed' message from server: scheduleRtcReconnect(500) - On ICE 'disconnected': show 'unstable…' badge, wait for server grace 3. logEv throughout webrtc-server Added logEv() helper (same pattern as input-server.mjs) and wired it to every ICE state transition and peer lifecycle event. logEvents is now accepted by createWebRTCServer and passed in from headless-cli. ICE state changes are also always logged to stderr (not gated on --verbose) since they are infrequent and critical for diagnosing stream freezes. (cc80281)
|
|
99
|
+
- chore: log events for docker debug (df24c2b)
|
|
100
|
+
- feat(headless): add --log-events flag for structured event logging Adds a new --log-events CLI flag (distinct from --verbose) that emits structured [event] lines to stderr for all meaningful state transitions: - server-listening - client-connected / client-disconnected - host-joined / host-rejoined / host-left / host-disconnected - host-grace-expired / host-timeout / host-kicked / host-claim-rejected - p2-joined / p2-left / p2-disconnected / p2-kicked / p2-promoted-to-host - p2-join-rejected / invite-p2-issued / invite-p2-rejected / ports-swapped - cmd-load-crt / cmd-detach-crt / cmd-hard-reset (emulator commands) - cart-loaded / cart-detached / hard-reset outcome (in headless-cli) - drift warning when actual FPS deviates >10% from target - error (bad-message, ws-error, server-error, load-crt-failed, etc.) Format: [event] <ISO-timestamp> <tag> key=value ... Never fires per-frame; safe for production/deployed instances. Input events include a role= field (host|p2) for attribution. --verbose is unchanged and remains independent of --log-events. (0e7f24c)
|
|
101
|
+
- Merge pull request #24 from hayesmaker/feat/host-rejoin-grace (c40a23b)
|
|
102
|
+
- chore: fix lints (cc352ea)
|
|
103
|
+
- feat(input-server): add host reconnect grace period before P2 promotion When the host WebSocket closes unexpectedly (e.g. browser refresh), instead of immediately promoting P2 to host, start a grace period (default 8 s). During the grace period: - All clients receive 'host-disconnected' (new) with graceMs so they can show a 'reconnecting…' notice rather than an immediate role change. - The hello handshake sends hostTaken:false + hostPendingRejoin so that: - The refreshing host's rejoin logic can silently reclaim the slot. - P2 / spectators joining during grace suppress the host prompt. - If the original host reconnects and sends 'host' (same username) the grace timer is cancelled and 'host-rejoined' is broadcast. - If a different user claims the host slot during grace, grace is also cancelled (they get it). - If nobody claims within graceMs, expireGrace() broadcasts 'host-left' and calls promoteP2ToHost() as before. Voluntary leave, inactivity timeout, and admin kick all call clearGrace() to prevent a stale timer from firing after an intentional departure. New option: hostReconnectGraceMs (default 8000). (8436d5b)
|
|
104
|
+
- Merge pull request #23 from hayesmaker/fix/input-lag-post-cart-load (2428bf5)
|
|
105
|
+
- chore: fix lint (14b3597)
|
|
106
|
+
- test(webrtc): add tests covering post-load input lag fixes webrtc-encoder.test.ts (new): - pushSilenceForGap: correct chunk count for 1600ms / 1000ms / 200ms gaps - pushSilenceForGap: 0ms and negative gaps are no-ops - pushSilenceForGap: correct chunk size at 48000 Hz (480 samples) - pushSilenceForGap: all chunks are silence (zeros, 16-bit, mono) - resetVideoTimestamp: safe no-op, no throw - init/setFps: track kinds correct, no throw - pushAudioFrame: drains exactly 2 chunks from 882 samples at 50fps webrtc-server.test.ts (new): - createWebRTCServer: returns { close, forceKeyframe } - forceKeyframe: safe no-op with no peers (null/undefined/no-peers) - browser HTML: cart-loaded / machine-reset / cart-detached each call connectWebRTC() — regression guard against reverting to seek - browser HTML: connectWebRTC tears down old pc + sigWs + srcObject before creating fresh RTCPeerConnection - browser HTML: sync button uses connectWebRTC(), not flushToLiveEdge() - browser HTML: mute state preserved across reconnect (wasMuted check) headless.cli.test.ts: - pushSilenceForGap algorithm test: 1600ms → 160 chunks of 441 samples (31f33ac)
|
|
107
|
+
- fix(webrtc): reconnect RTCPeerConnection on cart-load to clear decoder state Root cause of persistent post-load lag: The browser's RTCPeerConnection jitter buffer and VP8 decoder accumulate state during the ~1600ms cart-load gap. No amount of currentTime seeking, srcObject manipulation, or jitterBufferTarget=0 clears this — they all operate above the decoder pipeline level. Only a full browser refresh (new RTCPeerConnection) reliably clears it, which the user confirmed. Fix: refactor browser WebRTC setup into connectWebRTC() and call it on every cart-loaded / machine-reset / cart-detached event. connectWebRTC(): - Closes the existing pc and sigWs cleanly (no badge flicker) - Nulls videoEl.srcObject to drop the stale MediaStream reference - Creates a fresh RTCPeerConnection + new signalling WebSocket - Re-negotiates SDP offer/answer with the server - Re-applies VP8 codec preference + bitrate fmtp - Restarts the drift monitor on the new pc Mute state is preserved: if the user had unmuted before the load, a 100ms polling interval re-unmutes once the new stream's ontrack fires. The sync button (⟳) also calls connectWebRTC() — giving users a manual way to hard-reset the video pipeline at any time. The input WebSocket is deliberately NOT reconnected — it is independent of the video pipeline and must stay connected to avoid losing host role. (c1301f0)
|
|
108
|
+
- fix(docker): VERBOSE=0 should disable verbose, check for '1'/'true' explicitly The entrypoint used 'if [ -n "\${VERBOSE}" ]' which treats any non-empty string as truthy — including VERBOSE=0. Change to match '1' or 'true' only, consistent with the WEBRTC_ENABLED and AUDIO checks in the same file. (be0d0b9)
|
|
109
|
+
- fix(webrtc): force VP8 IDR keyframe on cart load/reset to eliminate video freeze Root cause of post-load visual lag (separate from AV clock sync): After c64_loadCartridge() the VP8 encoder emits IDR keyframes at its normal interval (~2-3 seconds). The browser decoder cannot render any frame until it receives an IDR. So even though the server pushes live frames immediately after the load, the browser shows a frozen/blank screen for up to 2-3 seconds waiting for the next natural keyframe. This is the dominant source of perceived input lag — the player sees the pre-load game state while their inputs are landing on the new game. Fix: server-side forceKeyframe(videoTrack) createWebRTCServer() now tracks all active RTCPeerConnections in an activePeers Set (added on ICE 'connected'/'completed', removed on 'failed'/'closed'/'disconnected' and ws 'close'). forceKeyframe(videoTrack) iterates activePeers and calls sender.replaceTrack(videoTrack) on every video sender. This triggers libwebrtc to emit an IDR on the next encoded frame (within ≤20ms @ 50fps), giving the browser decoder a complete reference frame immediately after the load completes. Called after load-crt (1625ms gap), detach-crt (~110ms) and hard-reset (~110ms). Also reverts the srcObject=null flushToLiveEdge approach from the previous commit — that approach caused a blank screen while waiting for the keyframe that replaceTrack() now provides proactively. (e62a278)
|
|
110
|
+
- fix(webrtc): hard srcObject reset on cart-load/reset to flush stale video buffer The previous flushToLiveEdge() used videoEl.currentTime = bufEnd. This is ineffective because at the moment cart-loaded fires from the input server, the frame loop has just resumed and hasn't pushed any new video frames yet. The buffered range end is still the pre-load stale position — seeking to it just jumps within the stale buffered content, not to the actual live stream edge. Fix: replace currentTime seek with srcObject=null then restore on the next requestAnimationFrame. This forces the WebRTC decoder to drop its entire accumulated buffer and re-initialize from the next incoming keyframe. The browser starts playing live frames immediately rather than draining the pre-load buffer first. Also update the drift monitor: drifts >1s now trigger the same hard srcObject reset (the currentTime seek is kept for small drifts ≤1s as a lighter-weight correction for minor jitter). (9d24673)
|
|
111
|
+
- fix(webrtc): re-sync audio RTP clock after blocking WASM gaps to eliminate input lag Root cause: RTCAudioSource is a push-source — its RTP clock only advances when onData() is called. RTCVideoSource is driven by @roamhq/wrtc using the wall clock internally. During the ~1300ms blockage of c64_loadCartridge() (and ~110ms for detach/hard-reset) the frame loop is completely frozen, so no audio is pushed. The video RTP clock keeps ticking, leaving audio ~1300ms behind video when the loop resumes. The browser's AV sync logic holds video playback until the audio clock catches up — experienced as 1–30s of input lag after every cart load. The slow recovery (sometimes 30s) was because the 1300ms audio debt could only drain at real-time rate (one 10ms chunk per 441 samples). Fix: In all three blocking WASM paths (load-crt, detach-crt, hard-reset): 1. Record wall-clock time before the blocking call (gapStart). 2. Measure the actual gap (gapMs = Date.now() - gapStart). 3. Call webrtcEncoder.pushSilenceForGap(gapMs) immediately after. pushSilenceForGap() pushes (gapMs/1000 * sampleRate / chunkSize) silence chunks via RTCAudioSource.onData() in a tight loop — ~130 calls for a 1300ms gap. This advances the audio RTP clock by the exact same duration the video RTP clock advanced during the gap, so both clocks re-align before the frame loop resumes. The wall-clock video timestamp change (Date.now()-based) is kept as a no-op improvement — the timestamp field is ignored by @roamhq/wrtc 0.10.0 (RTCVideoFrame type has no timestamp field), but the comment is accurate about intent. Also applies to detach-crt (~110ms gap) and hard-reset (~110ms gap) for completeness, though those gaps are short enough that the lag was barely perceptible before. (03b5e82)
|
|
112
|
+
- fix(headless): gate video push on debugger_update return + debugger_isRunning Mirror c64.js render guard in the headless frame loop: const update = debugger_update(dTime); if (update && cd /home/ahayes/Homespace/c64-ready && git commit --amend -m 'fix(headless): gate video push on debugger_update return + debugger_isRunning Mirror c64.js render guard in the headless frame loop: const update = debugger_update(dTime); if (update && cd /home/ahayes/Homespace/c64-ready && git log --oneline -3 | catdebugger_isRunning()) { redraw(); } - Capture debugger_update() return value as frameReady (truthy = VSync completed, emulator has a new pixel buffer ready). - Call debugger_isRunning() each frame as isRunning. - Gate WebRTC pushVideoFrame() and ffmpeg writeFrame() on frameReady && isRunning — prevents pushing stale/repeated pixel data during ROM boot sequences after a cart load, which was inflating the WebRTC jitter buffer with duplicate frames and likely contributing to the post-load perceived lag. - Audio push is unconditional every frame — audio clock must stay continuous regardless of video readiness. - Fix always-true WebRTC audio condition: (audio || sidRingCount >= 0) corrected — pushAudioFrame() called directly inside the (webrtc && webrtcEncoder) block, which is the correct guard. - Remove redundant try/catch blocks around WASM calls in the frame loop, onInput, and onCommand — exports are known-good at this point.' | catdebugger_isRunning()) { redraw(); } - Capture debugger_update() return value as frameReady (truthy = VSync completed, emulator has a new pixel buffer ready). - Call debugger_isRunning() each frame as isRunning. - Gate WebRTC pushVideoFrame() and ffmpeg writeFrame() on frameReady && isRunning — prevents pushing stale/repeated pixel data during ROM boot sequences after a cart load, which was inflating the WebRTC jitter buffer with duplicate frames and likely contributing to the post-load perceived lag. - Audio push is unconditional every frame — audio clock must stay continuous regardless of video readiness. - Fix always-true WebRTC audio condition: (audio || sidRingCount >= 0) corrected — pushAudioFrame() called directly inside the (webrtc && webrtcEncoder) block, which is the correct guard. - Remove redundant try/catch blocks around WASM calls in the frame loop, onInput, and onCommand — exports are known-good at this point. (430a0c9)
|
|
113
|
+
- Merge branch 'fix/webrtc-frame-drop-live-edge' (3429f0e)
|
|
114
|
+
- docs(headless): document unresolved post-load input lag in load-crt handler Symptoms (observed, not yet fixed): - Initial game load: lag-free. - First load-crt: ~1s lag onset, clears after ~20-30s. - Subsequent loads: lag-free for a while, then periodically returns and recovers, cycling unpredictably. Investigation notes added inline at the load-crt site: - Emulator keypress latency is not the cause (<=20ms confirmed). - Lag is perceptual: browser displays stale buffered WebRTC video while live input lands on the server. - flushToLiveEdge() fires on cart-loaded but buffer partially re-accumulates over the following 20-30s. - c64_loadCartridge + c64_reset block the event loop ~1300ms inside setImmediate, starving WebRTC of frames and leaving the jitter buffer ahead of real-time when frames resume. - Periodic relapse suggests a slow buffer-drain race that re-opens on each subsequent load. - Candidates not yet ruled out: primeSidRing() extra emulation deepening video debt; jitterBufferTarget=0 not honoured under load; VP8 bitrate cap holding queued frames longer than expected after burst resumes. Also removes debug noise from previous investigation session: - Restore moved comment to its original inline position - Remove dead commented-out c64_reset() line (f361b27)
|
|
115
|
+
- feat(webrtc): add sync button to manually flush video to live edge (de57747)
|
|
116
|
+
- chore(docker): remove nms service — WebRTC-only setup NMS (Node Media Server) was used for the legacy RTMP streaming path. Now that WebRTC is the only supported mode, NMS is no longer needed. docker-compose.yml: - Remove the nms service block entirely - Remove headless depends_on nms - Simplify header comment to reflect WebRTC-only setup docker/.env.example: - Remove RTMP_URL, NMS_RTMP_HOST_PORT, NMS_HTTP_HOST_PORT - Default WEBRTC_ENABLED=1 and AUDIO=1 (sensible defaults for WebRTC mode) - Clean up comments (258e0c9)
|
|
117
|
+
- fix(webrtc): blur all UI elements on game load, reset, and detach Buttons (load, detach, reset) retain DOM focus after being clicked. While a button has focus, keydown events fire its click handler rather than reaching the document keydown listener, causing the first keypress after a game action to be swallowed or misrouted. Fix: add blurAll() helper (document.activeElement.blur()) and call it: - inputWs.onmessage on cart-loaded / machine-reset / cart-detached (server confirms the action completed — safe point to return focus) - detachBtn and resetBtn click handlers (immediate blur on click) - fileInput change handler (blur after file picker closes) (94d8641)
|
|
118
|
+
- Revert "fix(webrtc): aggressive drift monitor, hard flush on cart load, surface frame errors" (fb37716)
|
|
119
|
+
- fix(webrtc): aggressive drift monitor, hard flush on cart load, surface frame errors headless-cli.mjs: - Fix always-true condition: (audio || sidRingCount >= 0) was always true since sidRingCount is always >= 0. Corrected to (audio || webrtc). - Surface frame loop errors: outer catch(_){} was silently swallowing all exceptions including WASM traps, causing silent frame skips that could manifest as intermittent lag. Now logs via console.error when --verbose. webrtc-server.mjs (browser page): - Drift monitor: lower threshold from 300ms to 80ms (4 frames @ 50fps) and poll every 100ms instead of 200ms so drift is corrected faster during normal gameplay. - flushToLiveEdge: replace currentTime seek with srcObject=null + restore. The currentTime seek only works when buffered.length > 0, which is not guaranteed for all WebRTC stream states. The srcObject hard flush works unconditionally and is called on cart-loaded / machine-reset / cart-detached where we need a guaranteed resync to the live edge after a load blockage. (582e63a)
|
|
120
|
+
- fix(headless): c64_reset before cart load/detach; keep reset btn enabled after detach - load-crt: call c64_reset() after removeCartridge() and before c64_loadCartridge() so the machine is in a clean state before the new cart is parsed and booted. - detach-crt: call c64_reset() after removeCartridge() so the machine returns to a clean BASIC prompt rather than undefined CPU state. - webrtc-server.mjs: do not disable the reset button after cart-detached — the machine is still running (at BASIC prompt) so hard-reset remains meaningful after an eject. (8ca7a64)
|
|
121
|
+
- feat(webrtc): replace stub player page with full-featured WebRTC frontend The page at :9002 was a minimal test stub that didn't match the real c64cade frontend (ArcadeLiveView.vue / useC64WebRTC.js). Replace it with a complete self-contained player page implementing: Video: - RTCPeerConnection with VP8 preference via setCodecPreferences - jitterBufferTarget=0 applied on track arrival and after answer - Live-edge drift monitor: polls videoEl.buffered every 200ms, skips currentTime forward when >300ms behind buffer head - flushToLiveEdge() called on cart-loaded / machine-reset / cart-detached — same pattern as useC64WebRTC.js flushToLiveEdge() - Muted autoplay with click-to-unmute overlay + AudioContext RMS analyser to confirm actual SID audio signal Input: - Connects to input server on INPUT_PORT, claims host role on open - Three input modes (cycle via button): mixed (🕹+⌨), joy, kb Mixed: arrows/Z/X → joystick port 2 AND all other keys → C64 kb — matches the default mode in ArcadeLiveView.vue - Exponential backoff reconnect on WS close CRT loading: - 📂 load .crt button → file picker - Drag-and-drop .crt files onto the screen (drag-over highlight) - FileReader.readAsDataURL → base64 → load-crt WS message - Progress badge: reading… → sending… → loaded (from cart-loaded) - Error badge on cart-load-error Controls: - ⏏ detach and ↺ reset buttons (enabled after a game loads) - Game name badge derived from cart filename on cart-loaded Status badges: video, audio, input, game state all update reactively (9b115e6)
|
|
122
|
+
- fix(webrtc): fix apparent input lag — video buffer resync + monotonic timestamps The 'input lag' was not emulator lag at all. The emulator processes keypresses within one frame (<=20ms). The visible lag was the browser playing stale buffered video while the emulator ran in real-time. Root cause 1 — video buffer accumulates during cart load blockage: c64_loadCartridge() blocks the event loop for ~1300ms. During this window no video frames are sent to the browser. When frames resume, the browser's WebRTC decode pipeline plays back from its accumulated buffer rather than the live edge. The player watches video from the past while their inputs land in real-time, making controls feel unresponsive for 20-25s until the buffer drains. Fix (webrtc-server.mjs): inputWs.onmessage listens for cart-loaded, machine-reset and cart-detached events from the input server. On receipt, videoEl.srcObject is set to null then restored on the next animation frame. This forces the WebRTC decoder to drop its buffer and resync to the live incoming frames — same effect as a page refresh without losing the RTCPeerConnection. Root cause 2 — resetVideoTimestamp() caused backwards timestamp jump: After every cart load, resetVideoTimestamp() set _videoFrameCount=0. The browser receiver saw timestamps jump backwards (e.g. 50 000 000 µs → 0 µs), triggering a full re-buffer cycle of another 20-25s. The ~1300ms blockage is already invisible to the receiver (no frames sent = no timestamp gap); resetting makes it visible as a backwards jump. Fix (webrtc-encoder.mjs): resetVideoTimestamp() is now a no-op. _videoFrameCount increments monotonically across cart loads. Root cause 3 — startup cart load re-triggered ROM boot sequence: The startup path called free(ptr) + c64_reset() + debugger_set_speed() + debugger_play() after c64_loadCartridge(). c64_loadCartridge already resets and resumes the machine internally; these calls re-triggered the ROM boot sequence causing ~1s of heavy emulation on the first frames (same root cause as the lag fixed for the load-crt command path in 6f30143). Fix (headless-cli.mjs): remove those four calls from startup path. Bonus low-latency improvements (no user-visible behaviour change): - isScreencast: true on RTCVideoSource — disables temporal noise filtering in libwebrtc, reducing encoder buffering latency - SDP answer: inject x-google-min/max-bitrate=200/800 fmtp for VP8 to keep frame sizes small and encode latency low - Browser offer: setCodecPreferences to prefer VP8, matching fmtp - onPeerConnected: sender.setParameters maxBitrate=800kbps (3fe65b2)
|
|
123
|
+
- fix(headless): fix input lag and audio dropouts Input lag (headless-cli.mjs) The two-half-step approach added in the previous commit put the setImmediate yield BEFORE the sleep, meaning input that arrived during the sleep still waited until the next frame's yield — no improvement over a single debugger_update. Correct ordering: 1. debugger_update(frameMs) — full frame emulation 2. audio/video push 3. setTimeout(sleepMs) — event loop sleeps; WebSocket I/O callbacks fire here and write to WASM exports synchronously 4. setImmediate yield — drains any message that arrived right at the tail of the sleep 5. top of next iteration: debugger_update reads committed state iterStart is captured at the TOP of the loop (before emulation) so sleepMs correctly accounts for all work in the frame. Worst-case latency = 1 frame (20ms @ 50fps); average ~10ms. Audio dropouts (headless-cli.mjs) The JS-side SID ring started empty and accumulated samples at 882/frame (samplesPerFrame @ 50fps), only pulling a 4096-sample chunk from the WASM every ~4.65 frames. This caused: - Frames 0-3: always silent (ring empty, no pull yet) - Frame 8 (and every ~4.65 frames): ring ran dry (4096 - 5*882 = -314 → 568 samples left < 882 needed) Fix: add primeSidRing() — runs 2 * ~93ms of emulated pre-roll and pulls 2 × 4096-sample buffers into the ring before the frame loop. Ring starts at 8192 samples (~9.3 frames of headroom); the lowest it ever reaches is ~4290 samples (verified by trace), well above the 882 threshold. Zero silent frames in steady state. primeSidRing() is also called from resetSidRing() after every cart load / detach / hard-reset so the new game's audio starts without a gap. test: update the stale 'silence on first frame' test name/comment to reflect that the ring is now pre-primed before the frame loop. (018a6ec)
|
|
124
|
+
- fix(webrtc): fix input lag, audio stuttering, and dead live-edge code Three independent bugs addressed in one commit: 1. Input lag (headless-cli.mjs) The previous single debugger_update(frameMs) gave no yield point for the Node event loop to drain incoming WebSocket input events. Worst-case latency was one full 20ms frame (input arrives just after the update). Fix: restore the two-half-step pattern — debugger_update(halfFrameMs), setImmediate yield, debugger_update(halfFrameMs). Input events that land during the yield are processed in the second half, halving worst-case latency to 10ms @ 50fps. 2. Audio stuttering (webrtc-encoder.mjs) pushAudioFrame() was allocating two new Float32Array objects per call (merged concat + slice for leftovers) — at 50fps that is 100 heap allocs/sec of varying size, triggering frequent GC pauses and audible gaps in the audio stream. Fix: replace the dynamic queue with a pre-allocated Float32Array ring buffer (32768 samples, sized for 8× SID_BUFFER_SIZE headroom) and a pre-allocated Int16Array staging buffer. pushAudioFrame() now makes zero heap allocations per call. 3. Dead live-edge browser code (webrtc-server.mjs) The requestVideoFrameCallback + videoEl.buffered seek approach does nothing for WebRTC streams: videoEl.buffered is always empty because WebRTC video feeds through the jitter buffer, not a seekable MSE source. The seek silently no-ops every frame. Fix: replace with RTCPeerConnection.getStats() polling (every 2s) that reads jitterBufferDelay/jitterBufferEmittedCount from the inbound-rtp video report. When average jitter delay exceeds 20ms (one frame @ 50fps) the video element's playbackRate is bumped to 1.02x to drain the buffer; it snaps back to 1.0x once delay falls below 10ms. The jitterBufferTarget = 0 from the previous commit is retained as the primary mechanism; playbackRate catchup is the secondary safety net. (9fd6df8)
|
|
125
|
+
- fix(webrtc): restore missing input handlers lost during live-edge edit The jitterBufferTarget + requestVideoFrameCallback live-edge code was added correctly inside pc.ontrack, but the edit accidentally deleted: - inputWs.onclose (backoff reconnect + badge update) - inputWs.onerror (badge update) - inputBtn click listener (manual retry) - connectInput() auto-call on page load - sendInput() helper function - Input mode toggle section comment header Restore all removed code. The diff now adds only the two live-edge blocks with no other behavioural changes. (855dcda)
|
|
126
|
+
- Merge pull request #22 from hayesmaker/fix/input-lag-issue (2000c9f)
|
|
127
|
+
- fix(headless): remove substep system and redundant cart load/detach calls Merges chore/remove-substep-system into fix/input-lag-issue. - Remove half-step setImmediate approach (did not fix input lag) - Remove free(ptr)/debugger_set_speed/debugger_play after c64_loadCartridge — re-triggering ROM boot was the actual root cause of post-load input lag - Same removal for detach-crt path - Update AGENTS.md: remove substep docs, add | cat rule for git pager commands (6f30143)
|
|
128
|
+
- chore(agents): add | cat rule for git pager commands (bc1de2d)
|
|
129
|
+
- fix(headless): remove redundant calls after cart load/detach to fix input lag After c64_loadCartridge(), calling free(ptr) / debugger_set_speed(100) / debugger_play() re-triggers the ROM boot sequence, causing the emulator to run CPU-heavy frames for ~1 second after every cart load. This was the root cause of post-load input lag. Removing them is safe: c64_loadCartridge internally resets and resumes the machine. Same fix for detach-crt: removing c64_reset() / debugger_set_speed / debugger_play() after c64_removeCartridge() eliminates the same boot re-trigger on detach. Also removes the unnecessary typeof guard — c64_removeCartridge is always present. Verified stable across 4 consecutive cart loads. (db76279)
|
|
130
|
+
- chore: adding game (8557133)
|
|
131
|
+
- chore(headless): remove frame substep system The two-half-step + setImmediate yield approach was added to reduce input lag but did not actually solve the problem. Remove it entirely: - headless-cli.mjs: replace two debugger_update(halfFrameMs) calls + setImmediate yield with a single debugger_update(frameMs) per frame. Remove halfFrameMs constant and the input-lag comment block. - AGENTS.md: remove INPUT_SUBSTEPS / yield-guard / POST_RESET_GRACE documentation; restore the simple one-call-per-frame timing rule. - headless.cli.test.ts: remove the half-step assertion (toBeGreaterThanOrEqual FRAMES*2); replace with a direct toBe(FRAMES) check. (9558104)
|
|
132
|
+
- refactor(headless): replace 4-substep/grace-window frame loop with simple 2-half-step design Remove accumulated complexity that was no longer solving real problems: REMOVED: - INPUT_SUBSTEPS = 4 with per-substep yield guard (subElapsed < subStepMs) The guard was always true (debugger_update(5ms) takes ~0.4ms wall time), making it dead code that added 3 extra event-loop turns per frame. - POST_RESET_GRACE_FRAMES = 64 grace window countdown Added to handle slow boot frames suppressing yields — no longer needed since the yield is now unconditional. - markEmulatorReset() and postResetFrames counter Only served the now-removed grace window. - lastTick / useFixedDt / deltaMs useFixedDt was always true; deltaMs was computed but never used. - Double iterStart = Date.now() capture at loop top - Stale iterStart re-capture patch (was treating a symptom, not the cause) - Dead --use-fixed-dt / --use-wall-clock arg flags REPLACEMENT: exports.debugger_update(halfFrameMs); // first half (10ms @ 50fps) await new Promise(r => setImmediate(r)); // yield — input events drain here exports.debugger_update(halfFrameMs); // second half const iterStart = Date.now(); // captured AFTER emulation ... const sleepMs = max(0, frameMs - (Date.now() - iterStart)); await setTimeout(r, sleepMs); - One unconditional setImmediate yield per frame halves worst-case input latency (20ms → 10ms) without guards or counters. - iterStart captured after emulation means sleepMs is always correct even if loadCartridge blocked inside the yield — no burst spin-up. (8b042a7)
|
|
133
|
+
- fix(headless): re-capture iterStart after sub-steps to prevent burst emulation on load Root cause of variable input lag + progressive audio drift after crt loads: loadCartridge (~1300ms) fires inside a sub-step setImmediate yield. The original iterStart was captured at the top of the frame, so by the time the sub-step loop completes, iterStart is ~1300ms stale. At the bottom of the loop: sleepMs = max(0, frameMs - (Date.now() - iterStart)) = max(0, 20 - 1300+) = 0 The frame loop then spins with 0ms sleep for ~65 consecutive frames (1300ms debt / 20ms per frame), running the emulator at many times real-clock speed during that window. Two symptoms result: 1. Input lag that 'gets better after some time' — the emulator is consuming game time faster than wall clock; inputs arrive at real speed but are spread across far more emulated cycles than intended. After 65 fast frames the debt drains and normal pacing resumes. 2. Audio drifts late — the SID ring is filled at 65× normal rate during the burst; the consumer (WebRTC/ffmpeg) still drains at 1× rate, so the ring overflows and audio timestamp falls behind video. With each successive crt load the accumulated debt grows. Fix: re-capture iterStart = Date.now() immediately after the sub-step loop, before the sleep calculation. The blockage time is absorbed into the current frame's 'elapsed' cost; sleepMs is computed from when emulation actually finished, giving a correct ~20ms sleep on every frame regardless of how long a mid-yield blockage took. Also include the webrtc-encoder.mjs timestamp fix (frame-counter-driven timestamps) and the TDZ crash fix (setFps after targetFps declaration) from the previous session that were not yet committed together. (b4d99f6)
|
|
134
|
+
- fix(webrtc): drive video timestamp from frame counter, not wall clock; fix TDZ crash Root cause of progressive video lag after each crt load: RTCVideoSource.onFrame() was called with no timestamp, so the WebRTC engine used its internal wall-clock monotonic timer. The ~1300ms loadCartridge() blockage advances the wall clock but produces no frames. When frames resume, the receiver's jitter buffer sees a ~1300ms gap; each subsequent load adds another gap, causing video to drift progressively further behind audio. Audio was unaffected because RTCAudioSource drives its own clock independently. Fix: WebRTCEncoder now maintains _videoFrameCount and _videoFrameDurationUs. pushVideoFrame() passes timestamp = frameCount * frameDuration (µs) to onFrame(). The timestamp is purely emulator-time-based — the ~1300ms wall-clock blockage is invisible to the receiver; frames resume at the next sequential timestamp with no gap. - setFps(fps): sets per-frame duration in µs (called after targetFps is known) - resetVideoTimestamp(): resets counter to 0 — called from load-crt, detach-crt and hard-reset so each new game starts a fresh sequence Also fix: TDZ crash 'Cannot access targetFps before initialization' setFps(targetFps) was mistakenly placed inside the webrtc init block which runs before targetFps is declared. Moved to immediately after the targetFps const declaration where webrtcEncoder is already in scope. (6010186)
|
|
135
|
+
- fix(headless): halve load-crt blockage by dropping redundant c64_reset after loadCartridge Measured per-call costs after 500 frames of gameplay: allocAndWrite: 0 ms c64_loadCartridge: 1250 ms (parses cart + resets machine internally) c64_reset (with cart): 1250 ms ← was called after loadCartridge — redundant c64_reset (no cart): 101 ms c64_loadCartridge already performs a full machine reset internally — the explicit c64_reset() after it produces an identical CPU PC and is pure wasted event-loop blockage (~1250ms). Drop it. Also add c64_removeCartridge() before loadCartridge to ensure any previously-resident cart is cleanly ejected before the new parse begins. Total load-crt blockage: ~2500ms → ~1300ms (one loadCartridge call only). The setImmediate deferral is kept so the frame loop yields to the event loop before the blockage starts and input events can drain afterwards. Also simplify detach-crt to run synchronously inline (same as hard-reset): removeCartridge (~0ms) + c64_reset no-cart (~110ms) — no setImmediate or debugger_set_speed(0) pause needed for a ~110ms operation. (25c98dc)
|
|
136
|
+
- fix(headless): instant hard-reset — removeCartridge + c64_reset, no loadCartridge Root cause of post-reset lag: the previous hard-reset fast path still called c64_loadCartridge() after the reset, which blocks the event loop for ~1300ms (O(1) but large constant). This stalled all WebSocket I/O for ~1.4s on every reset, causing input events to pile up and be delivered in a burst afterwards. New approach: hard reset detaches the cart and resets — intentionally leaving the machine at the BASIC prompt (blank screen), matching real C64 behaviour. c64_removeCartridge() → 0 ms c64_reset() (no cart) → ~110 ms (runs inline, no setImmediate needed) Total → ~110 ms, no event-loop blockage - Remove stale currentCartBytes variable and all its write sites — it was only ever read by the old hard-reset-reload path, which no longer exists. - Remove dead commented-out debugger_set_speed(0) line from load-crt path. - Add resetSidRing() + markEmulatorReset() to the new hard-reset handler. - Update input-server.mjs comment: hard-reset onCommand is now synchronous; Promise chain still works correctly (resolves immediately on undefined). test: add input-server.test.ts covering Promise-await behaviour for load-crt, detach-crt and hard-reset; cart-load-error on rejection; non-host command rejection; cart-loading broadcast timing; P2 open-join. Add headless.cli.test.ts cases: sub-step count per frame (4×), SID silence on first frame, --no-game completion. Install @types/ws for TS support. (b9b828e)
|
|
137
|
+
- fix(headless): eliminate event-loop blocking on hard-reset and detach-crt Root cause: c64_reset() with a cartridge resident blocks the Node.js event loop for ~1.4-3 s (the WASM runs a full ROM + cart init synchronously). During this time ALL WebSocket I/O stalls — inputs queue up and are not dispatched to the WASM, causing the perceived input lag after every reset. Measured costs in a long-running instance (3000 frames of gameplay): bare c64_reset() with cart loaded → 1400-3000 ms ❌ c64_removeCartridge() → 0 ms ✅ c64_reset() with no cart → 105-114 ms ✅ c64_loadCartridge() after gameplay → 1489 ms ❌ (O(frames) cost) Fast hard-reset sequence: removeCartridge(0ms) → reset(109ms) → loadCartridge → debugger_play Total ≈ 1600ms — dominated by loadCartridge, but event loop only blocks 109ms synchronously; the rest is inside the deferred setImmediate so the frame loop continues between calls. Changes: - hard-reset and detach-crt now defer their WASM work via setImmediate and return a Promise (same pattern as load-crt). - hard-reset uses fast path: removeCartridge → reset → loadCartridge, avoiding the 3s bare c64_reset()-with-cart call. - currentCartBytes variable tracks the loaded cart bytes so hard-reset can reload without reading from disk; seeded from gamePath at startup and updated on every load-crt / cleared on detach-crt. - input-server.mjs awaits the onCommand Promise before broadcasting cart-detached / machine-reset, so clients only hear the confirmation after the WASM work is complete. (34e6e7a)
|
|
138
|
+
- chore(docker): bind-mount src/headless, src/emulator, bin into container Source edits now take effect with \`docker compose restart headless\` instead of requiring a full rebuild. No more stale-code surprises from Docker layer caching. Also document the correct build commands in AGENTS.md: - docker compose build --no-cache is separate from docker compose up - restart workflow for source changes vs rebuild for dependency changes (13dd69e)
|
|
139
|
+
- fix(headless): restore input-lag sub-step yields after cart load / reset Three bugs caused input lag to persist for ~1 second after every game load or emulator reset: 1. Whole-frame elapsed guard suppressed all remaining setImmediate yields The previous guard skipped yields when (Date.now() - iterStart) exceeded the frame budget. Because load-crt's setImmediate fires inside one of the sub-step yields, iterStart is stale when the remaining sub-steps run — so elapsedSoFar >> frameMs and ALL remaining yields are skipped for that frame. 2. ROM boot frames also over-budget — lag persists for ~1 s After a reset the C64 ROM boot sequence runs heavy code; each debugger_update(5ms) can take 10-20ms wall-clock. The whole-frame guard suppressed yields for every boot frame, pushing worst-case input latency back to one full frame (~20ms) for the entire boot period. 3. detach-crt / hard-reset lastTick reset was dead code The timing reset at the bottom of onCommand was reached for the sync reset paths, but immediately overwritten by lastTick = iterStart at the top of the next frame loop iteration. markEmulatorReset() is now the single place that resets timing state for all paths. Fixes: - Replace whole-frame elapsed guard with per-sub-step guard: skip the setImmediate only when the *just-completed* sub-step itself exceeded its own subStepMs budget. Slow earlier steps no longer suppress later ones. - Add POST_RESET_GRACE_FRAMES = 64 counter + markEmulatorReset() helper. For the 64 frames after any reset/cart-load the per-sub-step guard is bypassed entirely — every sub-step always yields regardless of how long debugger_update took. 64 frames ≈ 1.28 s @ 50 fps, covering the full ROM boot sequence. - Call markEmulatorReset() from all three reset paths (load-crt finally, detach-crt, hard-reset), replacing the scattered lastTick resets. - Decrement postResetFrames once per frame after the loop body. - Update AGENTS.md to document the corrected yield guard pattern. (ccfbbf5)
|
|
140
|
+
- chore(agents): document git workflow and update SID audio rules - Add mandatory Git workflow section: branch naming, conventional commits, no-push-unless-asked, add-tests-on-confirmation, never-commit-to-master - Replace stale SID audio rule (cached-pointer approach, which causes the looping-audio bug) with the correct two-stage JS ring buffer pattern - Update frame/timing rule to cover INPUT_SUBSTEPS sub-stepping and the budget-aware yield (skip setImmediate when already over-budget) (474266d)
|
|
141
|
+
- fix(headless): reset SID ring on cart load/reset to prevent stale audio loop - Add resetSidRing() helper that zeros sidSampleAccum, sidRingWrite/Read/Count and fills sidFrameBuf with silence - Call it on every load-crt, detach-crt and hard-reset command so the JS-side ring is flushed before the WASM SID's own write cursor resets; stale samples from the previous game can no longer bleed into the new session - Skip setImmediate sub-step yields when the frame is already over-budget (Date.now() - iterStart >= frameMs); this prevents yield overhead from compounding on catch-up frames immediately after a cart load, which was the root cause of input lag growing with each game load or reset (05dd467)
|
|
142
|
+
- WIP: audio/video in sync, input lag increases over time (5ec882f)
|
|
143
|
+
- feat(headless): added input and host api (773fdb5)
|
|
144
|
+
- feat: c64-live integration (a1cdb21)
|
|
145
|
+
- Merge pull request #21 from hayesmaker/feature/headless-web-rtc (8a9a4de)
|
|
146
|
+
- feat: webrtc implemented end to end (df5e4c5)
|
|
147
|
+
- chore: install @roamhq/wrtc (f3543bc)
|
|
148
|
+
- refactor: trust types more (66ef55c)
|
|
149
|
+
- chore: add MIT LICENSE file and SPDX headers to bin entry points (30dbb66)
|
|
150
|
+
- chore(wiki): auto-generate Home.md from doc headings, no hardcoded list - Drop TITLES map and ORDER array from workflow and publish_wiki.sh - Title is now read from the first # heading of each .md file - PROJECT_OVERVIEW pinned first, CHANGELOG pinned last, rest alphabetical - Adding a new doc to docs/ is all that's needed — no workflow edits required - Fix doc headings: PROJECT_OVERVIEW, HEADLESS_INPUT, HEADLESS_RUNNING had stale copy comments or non-ATX h1s that produced bad wiki titles (bdef473)
|
|
151
|
+
- chore(wiki): add workflow_dispatch trigger for manual runs (8db4f82)
|
|
152
|
+
- chore(wiki): publish all docs/ to wiki, clean up stale rewrite plan - Rename workflow to 'Publish docs to Wiki' - Trigger only on changes to docs/, CHANGELOG.md, or the workflow itself - Copy all docs/*.md + CHANGELOG.md to wiki on every qualifying push - Generate Home.md from scratch with ordered links to all pages - Fallback loop picks up any future docs not in the explicit order list - Remove debug/API-inspection steps from workflow - Sync tools/publish_wiki.sh to use identical logic - Remove stale docs/REWRITE_PLAN_V2..md (020962b)
|
|
153
|
+
- chore: changelogs (auto) (414199c)
|
|
154
|
+
|
|
155
|
+
## v0.6.2 - 2026-03-27T20:43:20+00:00
|
|
156
|
+
|
|
157
|
+
- chore(release): 0.6.2 (d3cc8a0)
|
|
158
|
+
- fix: serve correct mimetypes in serve mode (096516d)
|
|
159
|
+
- chore: changelogs (auto) (68698eb)
|
|
160
|
+
|
|
161
|
+
## v0.6.1 - 2026-03-27T20:36:27+00:00
|
|
162
|
+
|
|
163
|
+
- chore(release): 0.6.1 (27df16c)
|
|
164
|
+
- fix: serve path corrected for running emulator via npm (56b9f1a)
|
|
165
|
+
- chore: updated changelogs (e9c6320)
|
|
166
|
+
|
|
167
|
+
## v0.6.0 - 2026-03-27T20:21:42+00:00
|
|
168
|
+
|
|
169
|
+
- chore(release): 0.6.0 (fce6cf9)
|
|
170
|
+
- chore(release): 0.5.2 (cbf9175)
|
|
171
|
+
- feat: added input handling api to the headless runner (73eebfb)
|
|
172
|
+
- fix(headless): use correct output path relative to project (299607e)
|
|
173
|
+
- chore: add cartridges to headless npm (f8d72c9)
|
|
174
|
+
- Merge pull request #20 from hayesmaker/feature/headless-audio (ba60d4b)
|
|
175
|
+
- feat: headless player with audio working good (4203361)
|
|
176
|
+
- fix: docker env file reading (3761a76)
|
|
177
|
+
- Merge pull request #19 from hayesmaker/chore/docker-headless (da1d530)
|
|
178
|
+
- chore: Docker docs (054323d)
|
|
179
|
+
- chore: changelogs (auto) (2a3dab0)
|
|
180
|
+
- chore: dockerized headless c64 player (7bc7770)
|
|
181
|
+
- chore: cleanup source files (27925b4)
|
|
182
|
+
|
|
183
|
+
## v0.5.1 - 2026-03-23T10:09:37+00:00
|
|
184
|
+
|
|
185
|
+
- chore(release): 0.5.1 (8f3dae2)
|
|
186
|
+
- chore: update CHANGELOG.md (auto) (c9c5955)
|
|
187
|
+
- fix: detatch keyboard input when ui panels present (baa80a1)
|
|
188
|
+
- chore: fix node24 in deploy workflow (a948be5)
|
|
189
|
+
- chore: force node24 fix (25d1bc8)
|
|
190
|
+
- chore: update changelog (auto) [skip ci] (8e926b6)
|
|
191
|
+
|
|
192
|
+
## v0.5.0 - 2026-03-23T09:12:04+00:00
|
|
193
|
+
|
|
194
|
+
- chore: fix typings and UI controller behavior for joystick/display settings (e843785)
|
|
195
|
+
- Merge remote-tracking branch 'origin/master' (2f5150f)
|
|
196
|
+
- chore(release): 0.5.0 (1c67934)
|
|
197
|
+
- chore: update changelog (auto) [skip ci] (07c46ba)
|
|
198
|
+
- Merge pull request #18 from hayesmaker/feature/more-ui-controller-settings (7557af9)
|
|
199
|
+
- chore: fix lints (45d0b3d)
|
|
200
|
+
- feat: simple input and display settings (c5e60b1)
|
|
201
|
+
- chore(styles): extract inline CSS to module styles/ and import as raw (74f1d41)
|
|
202
|
+
|
|
203
|
+
## v0.4.0 - 2026-03-22T23:27:35+00:00
|
|
204
|
+
|
|
205
|
+
- chore(release): 0.4.0 (ccff6b7)
|
|
206
|
+
- Merge pull request #17 from hayesmaker/feature/headless-cli-runner (7bcd326)
|
|
207
|
+
- Merge branch 'master' into feature/headless-cli-runner (561a02b)
|
|
208
|
+
- chore: stop auto generated changelogs prs (a9822ca)
|
|
209
|
+
- chore: update changelog (auto) [skip ci] (0fefa3d)
|
|
210
|
+
- chore: update changelog (auto) [skip ci] (8a8668f)
|
|
211
|
+
- chore: update changelog (auto) [skip ci] (75373a5)
|
|
212
|
+
- chore: update changelog (auto) [skip ci] (a87a12a)
|
|
213
|
+
- Merge pull request #15 from hayesmaker/feature/headless-cli-runner (1b0b510)
|
|
214
|
+
- chore(release): generate changelog inside release commit; add --local to generator (d5687a3)
|
|
215
|
+
- Merge pull request #13 from hayesmaker/chore/update-changelog-2026-03-22T23-05-37-281Z-a1ccae7 (8f20c94)
|
|
216
|
+
- chore: update changelog (auto) [skip ci] (a1ccae7)
|
|
217
|
+
- Merge pull request #10 from hayesmaker/chore/update-changelog-2026-03-22T23-04-34-067Z-ae4bc22 (7365710)
|
|
218
|
+
- Merge pull request #11 from hayesmaker/feature/headless-cli-runner (78df809)
|
|
219
|
+
- chore: update changelog (auto) [skip ci] (ae4bc22)
|
|
220
|
+
- Merge pull request #9 from hayesmaker/chore/update-changelog-2026-03-22T18-25-45-840Z-bdf7b14 (e6e66d4)
|
|
221
|
+
- chore: release script enhancements (920a654)
|
|
222
|
+
- chore: update changelog (auto) [skip ci] (bdf7b14)
|
|
223
|
+
- Merge pull request #8 from hayesmaker/feature/headless-cli-runner (02ee198)
|
|
224
|
+
- chore: docs re-org (2efa3c0)
|
|
225
|
+
- chore(docs): keep CHANGELOG.md at repo root and update publish script (a2e1292)
|
|
226
|
+
- chore(docs): remove docs/CHANGELOG.md (keep root CHANGELOG.md) (726a914)
|
|
227
|
+
- chore(docs): move CHANGELOG.md back to repo root and restore generator output (27710f0)
|
|
228
|
+
- chore(docs): move repo root markdown into docs/ and update imports/generator (a713e07)
|
|
229
|
+
- chore(docs): add docs/ copies of repo root markdown and wiki publish helper (4089d45)
|
|
230
|
+
- chore(tests): remove tests from src; canonical tests now under test/ (5aef5d6)
|
|
231
|
+
- chore: remove duplicate cartridge in games/; use public/games as canonical asset (87bd78d)
|
|
232
|
+
- chore(headless): prefer public/games for default cartridge; remove repo-level fallback (10b5c8f)
|
|
233
|
+
- Merge pull request #6 from hayesmaker/chore/update-changelog-2026-03-21T15-22-06-743Z-5ae1fea (f887858)
|
|
234
|
+
- chore: fix lints (7242ab0)
|
|
235
|
+
- feat(headless): adds a headless c64 emulation mode (715f943)
|
|
236
|
+
- feat(headless): headless runner first commit (acb9e7f)
|
|
237
|
+
- chore: update changelog (auto) [skip ci] (5ae1fea)
|
|
238
|
+
|
|
239
|
+
## v0.3.0 - 2026-03-21T15:16:11+00:00
|
|
240
|
+
|
|
241
|
+
- chore(release): 0.3.0 (40d518c)
|
|
242
|
+
- feat: audio support (ee0f378)
|
|
243
|
+
- chore: filter changelogs from frontend (3192369)
|
|
244
|
+
- fix: changelog requests (8be31d6)
|
|
245
|
+
- chore: update changelog (auto) [skip ci] (ac19ea9)
|
|
246
|
+
- ci: trigger changelog workflow (node24) (0853680)
|
|
247
|
+
- ci: use Node 24 in changelog workflow (02065db)
|
|
248
|
+
- chore: fix changelog action (5675eda)
|
|
249
|
+
|
|
250
|
+
## v0.2.0 - 2026-03-21T13:25:25+00:00
|
|
251
|
+
|
|
252
|
+
- chore(release): 0.2.0 (991d9e7)
|
|
253
|
+
- chore: prepare release 0.2.0 (b31be4b)
|
|
254
|
+
- feat: adds cart loading support (559d866)
|
|
255
|
+
- chore: update changelog (auto) [skip ci] (9b1c57e)
|
|
256
|
+
- chore: update changelog (auto) [skip ci] (6c44232)
|
|
257
|
+
- chore: fix wiki (a6b1c9d)
|
|
258
|
+
- chore: link to overview from home wiki (bd91242)
|
|
259
|
+
- chore: attempt to fix wiki publish (30de988)
|
|
260
|
+
- chore: push plan to wiki (36e9639)
|
|
261
|
+
- chore: added wiki project overview (865c003)
|
|
262
|
+
- chore: added prettier linting and cleanup of source (c2e2199)
|
|
263
|
+
- chore: page link in banner (6cad53a)
|
|
264
|
+
- feat: power led favicon (b8b4825)
|
|
265
|
+
- chore: regenerated lockfile (fa871eb)
|
|
266
|
+
|
|
267
|
+
## v0.1.0 - 2026-03-20T23:42:38+00:00
|
|
268
|
+
|
|
269
|
+
- build: bump version to 0.1.0 (ef6ee3f)
|
|
270
|
+
- chore: ensure minimum node (2977a5e)
|
|
271
|
+
- feat: added github pages deployment (c55c362)
|
|
272
|
+
- chore: docs (2dff0bb)
|
|
273
|
+
- c64 ready (8ff3291)
|
|
274
|
+
- feat: c64-ready gif (eecdea5)
|
|
275
|
+
- feat: render ticks and readme (696b107)
|
|
276
|
+
- feat: larger canvas view (d1d8856)
|
|
277
|
+
- feat: working proof of concept initial commit (89e9a6e)
|
|
278
|
+
|
|
279
|
+
`;export{e as default};
|