c64-ready 0.5.1 → 0.6.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.
Files changed (117) hide show
  1. package/README.md +332 -96
  2. package/bin/headless.mjs +7 -3
  3. package/bin/serve.mjs +162 -0
  4. package/dist/assets/CHANGELOG-C1nvP1iO.js +96 -0
  5. package/dist/assets/index-Cioamf6E.js +394 -0
  6. package/dist/assets/marked.esm-BOXuzyNF.js +37 -0
  7. package/dist/assets/purify.es-y41lKIN9.js +2 -0
  8. package/dist/audio-worklet-processor.js +83 -0
  9. package/dist/c64-ready/c64-ready.gif +0 -0
  10. package/dist/c64-ready/index.html +58 -0
  11. package/dist/c64.wasm +0 -0
  12. package/dist/games/cartridges/legend-of-wilf.crt +0 -0
  13. package/dist/index.html +38 -0
  14. package/dist/led-off.svg +20 -0
  15. package/dist/led-on.svg +27 -0
  16. package/dist/vite.svg +15 -0
  17. package/dist-ts/emulator/c64-emulator.d.ts +107 -0
  18. package/dist-ts/emulator/c64-emulator.d.ts.map +1 -0
  19. package/dist-ts/emulator/c64-emulator.js +13 -1
  20. package/dist-ts/emulator/c64-emulator.js.map +1 -0
  21. package/dist-ts/emulator/c64-wasm.d.ts +42 -0
  22. package/dist-ts/emulator/c64-wasm.d.ts.map +1 -0
  23. package/dist-ts/emulator/c64-wasm.js +1 -0
  24. package/dist-ts/emulator/c64-wasm.js.map +1 -0
  25. package/dist-ts/emulator/constants.d.ts +14 -0
  26. package/dist-ts/emulator/constants.d.ts.map +1 -0
  27. package/dist-ts/emulator/constants.js +1 -0
  28. package/dist-ts/emulator/constants.js.map +1 -0
  29. package/dist-ts/emulator/input.d.ts +33 -0
  30. package/dist-ts/emulator/input.d.ts.map +1 -0
  31. package/dist-ts/emulator/input.js +26 -5
  32. package/dist-ts/emulator/input.js.map +1 -0
  33. package/dist-ts/emulator/memory.d.ts +2 -0
  34. package/dist-ts/emulator/memory.d.ts.map +1 -0
  35. package/dist-ts/emulator/memory.js +9 -0
  36. package/dist-ts/emulator/memory.js.map +1 -0
  37. package/dist-ts/headless/audio-capture.d.ts +13 -0
  38. package/dist-ts/headless/audio-capture.d.ts.map +1 -0
  39. package/dist-ts/headless/audio-capture.js +24 -0
  40. package/dist-ts/headless/audio-capture.js.map +1 -0
  41. package/dist-ts/headless/c64-headless.d.ts +36 -0
  42. package/dist-ts/headless/c64-headless.d.ts.map +1 -0
  43. package/dist-ts/headless/c64-headless.js +87 -0
  44. package/dist-ts/headless/c64-headless.js.map +1 -0
  45. package/dist-ts/headless/ffmpeg-runner.d.ts +18 -0
  46. package/dist-ts/headless/ffmpeg-runner.d.ts.map +1 -0
  47. package/dist-ts/headless/ffmpeg-runner.js +67 -0
  48. package/dist-ts/headless/ffmpeg-runner.js.map +1 -0
  49. package/dist-ts/headless/frame-capture.d.ts +13 -0
  50. package/dist-ts/headless/frame-capture.d.ts.map +1 -0
  51. package/dist-ts/headless/frame-capture.js +24 -0
  52. package/dist-ts/headless/frame-capture.js.map +1 -0
  53. package/dist-ts/headless/input-bridge.d.ts +21 -0
  54. package/dist-ts/headless/input-bridge.d.ts.map +1 -0
  55. package/dist-ts/headless/input-bridge.js +41 -0
  56. package/dist-ts/headless/input-bridge.js.map +1 -0
  57. package/dist-ts/src/counter.js +9 -0
  58. package/dist-ts/src/emulator/c64-emulator.js +308 -0
  59. package/dist-ts/src/emulator/c64-emulator.test.js +104 -0
  60. package/dist-ts/src/emulator/c64-wasm.js +149 -0
  61. package/dist-ts/src/emulator/c64-wasm.test.js +65 -0
  62. package/dist-ts/src/emulator/constants.js +9 -0
  63. package/dist-ts/src/emulator/input.js +62 -0
  64. package/dist-ts/src/emulator/input.test.js +53 -0
  65. package/dist-ts/src/emulator/memory.js +1 -0
  66. package/dist-ts/src/headless/audio-capture.js +23 -0
  67. package/dist-ts/src/headless/c64-headless.js +85 -0
  68. package/dist-ts/src/headless/ffmpeg-runner.js +33 -0
  69. package/dist-ts/src/headless/frame-capture.js +23 -0
  70. package/dist-ts/src/headless/headless.cli.test.js +46 -0
  71. package/dist-ts/src/headless/input-bridge.js +37 -0
  72. package/dist-ts/src/main.js +57 -0
  73. package/dist-ts/src/player/audio-engine.js +175 -0
  74. package/dist-ts/src/player/audio-engine.test.js +284 -0
  75. package/dist-ts/src/player/c64-player.js +105 -0
  76. package/dist-ts/src/player/c64-player.test.js +165 -0
  77. package/dist-ts/src/player/canvas-renderer.js +148 -0
  78. package/dist-ts/src/player/canvas-renderer.test.js +135 -0
  79. package/dist-ts/src/player/input-handler.js +13 -0
  80. package/dist-ts/src/player/ui-controller.js +575 -0
  81. package/dist-ts/src/player/ui-controller.test.js +67 -0
  82. package/dist-ts/src/types/emulator.js +1 -0
  83. package/dist-ts/src/types/index.js +4 -0
  84. package/dist-ts/tools/run-wrapper.js +36 -0
  85. package/dist-ts/types/emulator.d.ts +128 -0
  86. package/dist-ts/types/emulator.d.ts.map +1 -0
  87. package/dist-ts/types/emulator.js +2 -0
  88. package/dist-ts/types/emulator.js.map +1 -0
  89. package/dist-ts/types/index.d.ts +51 -0
  90. package/dist-ts/types/index.d.ts.map +1 -0
  91. package/dist-ts/types/index.js +5 -0
  92. package/dist-ts/types/index.js.map +1 -0
  93. package/package.json +40 -6
  94. package/public/audio-worklet-processor.js +83 -0
  95. package/public/led-off.svg +20 -0
  96. package/public/led-on.svg +27 -0
  97. package/src/counter.ts +9 -0
  98. package/src/emulator/c64-emulator.ts +357 -0
  99. package/src/emulator/c64-wasm.ts +180 -0
  100. package/src/emulator/constants.ts +22 -0
  101. package/src/emulator/input.ts +105 -0
  102. package/src/emulator/memory.ts +9 -0
  103. package/src/headless/headless-cli.mjs +105 -19
  104. package/src/headless/input-bridge.ts +13 -4
  105. package/src/headless/input-server.mjs +76 -0
  106. package/src/main.ts +80 -0
  107. package/src/player/audio-engine.ts +216 -0
  108. package/src/player/c64-player.ts +222 -0
  109. package/src/player/canvas-renderer.ts +139 -0
  110. package/src/player/input-handler.ts +116 -0
  111. package/src/player/styles/canvas-renderer.css +41 -0
  112. package/src/player/styles/ui-controller.css +286 -0
  113. package/src/player/ui-controller.ts +485 -0
  114. package/src/style.css +96 -0
  115. package/src/types/emulator.ts +167 -0
  116. package/src/types/index.ts +62 -0
  117. package/src/typescript.svg +1 -0
package/README.md CHANGED
@@ -113,157 +113,393 @@ All options can be set in `.env` or passed inline. See `docker/.env.example` for
113
113
  docker compose down
114
114
  ```
115
115
 
116
- ## Deployment
116
+ ## Headless Input API
117
117
 
118
- The project deploys to GitHub Pages automatically via GitHub Actions.
118
+ When the headless emulator is started with `--input` (or `INPUT_ENABLED=1` in Docker), it opens a **WebSocket server** on port `9001` (configurable via `--ws-port` / `WS_PORT`).
119
119
 
120
- On every push to `master`:
121
- 1. Tests run (`npm test`)
122
- 2. If tests pass, a production build is created (`npm run build`)
123
- 3. The `dist/` output is deployed to GitHub Pages
120
+ Any client — browser, Node script, or bot — can connect and send JSON messages to control the emulator in real-time.
124
121
 
122
+ ### Connection & handshake
125
123
 
126
- ## Work in Progress:
127
- - Proof of Concept Implementation:
128
- - [x] WASM module loading and initialization
129
- - [x] Emulator control and state management
130
- - [x] Canvas-based rendering
131
- - [x] Node-based headless rendering
132
- - [x] Framework agnostic integration (e.g., Vanilla HTML+JS, React, Vue, Angular etc)
133
- - Additional features:
134
- - [x] Audio output
135
- - [x] Input handling (keyboard)
136
- - [x] Loading and running .crt cartridge roms
137
- - [x] Display settings
138
- - [x] Docker headless streaming (RTMP / HTTP-FLV via Node Media Server)
139
- - [ ] Gamepad support
140
- - [ ] Touch controls
124
+ On connect the server immediately sends a `hello` frame:
141
125
 
142
- ## Changelog & Releases
126
+ ```json
127
+ {
128
+ "type": "hello",
129
+ "protocol": "c64-input",
130
+ "version": 1,
131
+ "joystickBitmask": { "up": 1, "down": 2, "left": 4, "right": 8, "fire": 16 }
132
+ }
133
+ ```
143
134
 
144
- This repository includes an automated changelog generator and a simple release workflow to help keep releases and the in-app version in sync.
135
+ ### Wire protocol (client → server)
145
136
 
146
- - `tools/generate_changelog.js` builds `CHANGELOG.md` from git history and GitHub Release notes. In CI the generator opens a Pull Request with the updated `CHANGELOG.md` for review instead of committing directly to `master`.
147
- - The CI workflow that runs the generator is `.github/workflows/generate_changelog.yml`. It runs on pushes to `master` and when a release is published.
148
- - The wiki publisher (`.github/workflows/publish_wiki.yml`) runs on pushes to `master` and publishes `PROJECT_OVERVIEW.md` to the repository wiki.
149
- Recommended release workflow (simple git flow)
137
+ **Joystick** — the emulator holds the direction for exactly as long as the client holds it.
138
+ A `release` **must** be sent explicitly when the physical (or virtual) button is lifted.
139
+ Never infer release from a timer — if the release message is not sent the direction will stick indefinitely.
150
140
 
151
- If you prefer the standard git-based release flow (no `gh` CLI required), follow these steps:
141
+ ```json
142
+ { "type": "joystick", "action": "push", "joystickPort": 2, "direction": "up" }
143
+ { "type": "joystick", "action": "release", "joystickPort": 2, "direction": "up" }
152
144
 
153
- 1) Update the version and create a tag locally (npm will update package.json and create a tag):
145
+ { "type": "joystick", "action": "push", "joystickPort": 2, "fire": true }
146
+ { "type": "joystick", "action": "release", "joystickPort": 2, "fire": true }
147
+ ```
154
148
 
155
- ```zsh
156
- # bump the patch version (or use minor/major)
157
- npm version patch -m "chore(release): %s"
149
+ **Keyboard** — use the C64 key code (integer):
150
+
151
+ ```json
152
+ { "type": "key", "action": "down", "key": 65 }
153
+ { "type": "key", "action": "up", "key": 65 }
154
+ ```
155
+
156
+ ### Client example — Node.js
157
+
158
+ A minimal Node.js client that connects, waits for the handshake, then mirrors `keydown` / `keyup`-style events from the calling code as explicit `push` / `release` pairs:
159
+
160
+ ```js
161
+ import { WebSocket } from 'ws'; // npm install ws
162
+
163
+ const ws = new WebSocket('ws://localhost:9001');
164
+ let ready = false;
165
+
166
+ // --- helpers ---------------------------------------------------------
167
+
168
+ function joystickPush(port, direction, fire) {
169
+ if (!ready) return;
170
+ ws.send(JSON.stringify({ type: 'joystick', action: 'push', joystickPort: port, direction, fire }));
171
+ }
172
+
173
+ function joystickRelease(port, direction, fire) {
174
+ if (!ready) return;
175
+ ws.send(JSON.stringify({ type: 'joystick', action: 'release', joystickPort: port, direction, fire }));
176
+ }
177
+
178
+ // --- lifecycle -------------------------------------------------------
179
+
180
+ ws.on('open', () => console.log('connected'));
181
+
182
+ ws.on('message', (data) => {
183
+ const msg = JSON.parse(data);
184
+ if (msg.type !== 'hello') return;
185
+ console.log('server ready, protocol version', msg.version);
186
+ ready = true;
187
+ });
188
+
189
+ ws.on('close', () => console.log('disconnected'));
190
+ ws.on('error', (err) => console.error('ws error:', err.message));
191
+
192
+ // --- usage -----------------------------------------------------------
193
+ // Drive push/release from your own input events, e.g.:
194
+ //
195
+ // gamepad 'buttondown' event fires → joystickPush(2, 'up')
196
+ // gamepad 'buttonup' event fires → joystickRelease(2, 'up')
197
+ //
198
+ // Example: a simple readline-driven test sequence
199
+ import readline from 'readline';
200
+
201
+ const rl = readline.createInterface({ input: process.stdin });
202
+ rl.on('line', (line) => {
203
+ const [action, direction] = line.trim().split(' ');
204
+ if (action === 'push') joystickPush(2, direction);
205
+ if (action === 'release') joystickRelease(2, direction);
206
+ if (action === 'quit') ws.close();
207
+ });
158
208
  ```
159
209
 
160
- 2) Push the commit and tags to GitHub:
210
+ Run it and type `push up` / `release up` to move the joystick while the emulator is streaming.
211
+
212
+ ### Client example — Browser
213
+
214
+ The browser's built-in `WebSocket` works the same way — useful for a frontend that streams video via flv.js and sends keyboard/joystick input back:
215
+
216
+ ```js
217
+ const ws = new WebSocket('ws://localhost:9001');
218
+
219
+ ws.addEventListener('message', (evt) => {
220
+ const msg = JSON.parse(evt.data);
221
+ if (msg.type !== 'hello') return;
222
+ console.log('c64-input server ready');
223
+ });
224
+
225
+ // Map keyboard events → C64 key codes and send them
226
+ document.addEventListener('keydown', (evt) => {
227
+ ws.send(JSON.stringify({ type: 'key', action: 'down', key: evt.keyCode }));
228
+ });
229
+ document.addEventListener('keyup', (evt) => {
230
+ ws.send(JSON.stringify({ type: 'key', action: 'up', key: evt.keyCode }));
231
+ });
232
+ ```
233
+
234
+ ### Using `InputBridge` helpers (TypeScript / ESM)
235
+
236
+ `InputBridge` ships static encoder helpers so you don't have to hand-roll JSON strings:
237
+
238
+ ```ts
239
+ import { InputBridge } from 'c64-ready/src/headless/input-bridge';
240
+
241
+ // Encode a joystick push and release
242
+ const push = InputBridge.encodeJoystick(2, 'push', 'right');
243
+ const release = InputBridge.encodeJoystick(2, 'release', 'right');
244
+
245
+ // Encode fire button
246
+ const firePush = InputBridge.encodeJoystick(2, 'push', undefined, true);
247
+ const fireRelease = InputBridge.encodeJoystick(2, 'release', undefined, true);
248
+
249
+ // Encode a keypress
250
+ const keyDown = InputBridge.encodeKeypress(65, 'down'); // 'A'
251
+ const keyUp = InputBridge.encodeKeypress(65, 'up');
252
+
253
+ // Send push on button-down, release on button-up — never infer release from a timer
254
+ gamepad.on('buttondown', (btn) => ws.send(InputBridge.encodeJoystick(2, 'push', btn.direction)));
255
+ gamepad.on('buttonup', (btn) => ws.send(InputBridge.encodeJoystick(2, 'release', btn.direction)));
256
+ ```
257
+
258
+ ### Docker — enabling input
259
+
260
+ Expose the WebSocket port and set `INPUT_ENABLED=1` in `docker/.env` (or inline):
161
261
 
162
262
  ```zsh
163
- git push origin master
164
- git push --tags
263
+ INPUT_ENABLED=1 WS_PORT=9001 docker compose up
165
264
  ```
166
265
 
167
- 3) Create a GitHub Release from the tag using the GitHub web UI:
266
+ Then connect your client to `ws://localhost:9001`.
168
267
 
169
- - Go to your repository → Releases → Draft a new release
170
- - Select the tag you just pushed, add release notes, and publish the release
268
+ ## Using c64-ready as an npm package
171
269
 
172
- What happens next
270
+ `c64-ready` can be installed as a dependency and used in three ways:
173
271
 
174
- - Publishing a release will trigger the changelog workflow in CI. The generator will create or update `CHANGELOG.md` and open a Pull Request with the changelog changes for review. Merge that PR to update `master` with the changelog.
175
- - The wiki publisher workflow runs on pushes to `master` and will publish `PROJECT_OVERVIEW.md` to the wiki when the changelog PR (or any other commit) is merged.
272
+ | Use-case | How |
273
+ |---|---|
274
+ | Run the browser player locally | `npx c64-ready` (zero config) |
275
+ | TypeScript / Node API | `import` from sub-path exports |
276
+ | Vite browser app | Copy or re-use `src/player/*` with your own Vite project |
176
277
 
177
- About tokens / authentication
278
+ ### Prerequisites
178
279
 
179
- - You do not need to provide secrets for GitHub Actions to run in CI: Actions injects an automatic `GITHUB_TOKEN` into workflow runs, and the workflows here use that token to create branches/PRs and push changes back to the same repository.
180
- - If you run `tools/generate_changelog.js` locally and want it to push branches or create a PR from your machine, that script will use your local git credentials (SSH keys or credential helper); you do not have to set `GITHUB_TOKEN` locally unless you specifically want the script to authenticate via token.
280
+ The TypeScript compiled outputs (`dist-ts/`) must be present in the package. They are
281
+ generated by `npm run package:build` (`npm run build && npm run headless:build`) before
282
+ publishing. A published release on npm will always contain them.
181
283
 
182
- Quick local tools
284
+ ### Running the browser player
183
285
 
184
- - Generate the changelog locally (writes `CHANGELOG.md` but will not create a PR unless CI runs the script with its `GITHUB_TOKEN`):
286
+ After installing the package globally, or via `npx`, the `c64-ready` command starts a
287
+ lightweight static HTTP server that serves the pre-built browser player:
185
288
 
186
289
  ```zsh
187
- node tools/generate_changelog.js
290
+ # Run without installing (npx caches the package automatically)
291
+ npx c64-ready
292
+
293
+ # Or install globally and run
294
+ npm install -g c64-ready
295
+ c64-ready
188
296
  ```
189
297
 
190
- Verify the in-app version
298
+ Open the URL printed to the terminal in any modern browser:
191
299
 
192
- - After bumping the version, rebuild the site so the new version is embedded in the app:
300
+ ```
301
+ C64 Ready player is running.
302
+
303
+ ➜ Local: http://localhost:5173/c64-ready/
304
+ ```
305
+
306
+ **Options:**
307
+
308
+ | Flag | Default | Description |
309
+ |------|---------|-------------|
310
+ | `--port <n>` | `5173` | HTTP port to listen on |
311
+ | `--host` | localhost | Bind to `0.0.0.0` so the player is reachable on the local network |
312
+ | `--help` | | Print usage |
193
313
 
194
314
  ```zsh
195
- npm run build
315
+ # Different port, accessible on the LAN
316
+ c64-ready --port 8080 --host
196
317
  ```
197
318
 
198
- - Open the built site (or run the dev server) and check the Help dialog — the version (and short git hash when available) appears at the bottom.
319
+ > **Note:** `c64-ready` serves the compiled `dist/` directory. If you are working from a
320
+ > cloned repo rather than a published package, run `npm run build` first.
199
321
 
200
- ## Docs & Wiki publishing
322
+ ### TypeScript / Node.js API
201
323
 
202
- This repository now keeps human-facing documentation in a `docs/` folder at the repository root (except for `AGENTS.md` and `README.md`, which remain in root).
324
+ After installing as a local dependency:
325
+
326
+ ```zsh
327
+ npm install c64-ready
328
+ ```
203
329
 
204
- - `docs/` contains user and developer docs that should be published to the repository wiki.
205
- - The helper script `scripts/publish_wiki.sh` will prepare a wiki clone, copy `docs/*.md` plus the canonical `CHANGELOG.md` (from the repo root) into the wiki clone, update `Home.md` with links, and commit the changes so you can review before pushing.
330
+ The following sub-path exports are available:
206
331
 
207
- To prepare a wiki update locally (no push):
208
- ```bash
209
- # clone the wiki and stage the docs in the wiki clone (script prints the clone path)
210
- ./scripts/publish_wiki.sh git@github.com:YOUR_USER/c64-ready.wiki.git
332
+ #### Shared types — `c64-ready`
211
333
 
212
- # Inspect the prepared wiki clone (the script prints where it wrote files)
213
- cd /tmp/<the-script-printed-path>/wiki
214
- git status
215
- git show --name-only
334
+ ```ts
335
+ import type { C64Config, FrameBuffer, AudioBuffer, InputEvent, GameLoadOptions } from 'c64-ready';
216
336
  ```
217
337
 
218
- To publish the changes to the GitHub wiki (requires push access):
219
- ```bash
220
- cd /tmp/<the-script-printed-path>/wiki
221
- git push origin HEAD
338
+ #### Low-level emulator — `c64-ready/emulator`
339
+
340
+ `C64Emulator` is the single class all higher-level consumers build on. It owns the WASM
341
+ lifecycle and fires `onFrame` / `onAudio` callbacks each tick.
342
+
343
+ ```ts
344
+ import { C64Emulator } from 'c64-ready/emulator';
345
+
346
+ // Load and initialise the WASM binary
347
+ const emulator = await C64Emulator.load('/path/to/c64.wasm');
348
+
349
+ // React to each rendered frame (RGBA pixels, 384 × 272)
350
+ emulator.onFrame = (frame) => {
351
+ console.log(`frame ${frame.timestamp}: ${frame.width}×${frame.height}`);
352
+ };
353
+
354
+ // Load a cartridge (.crt file bytes)
355
+ const crtBytes = new Uint8Array(await fetch('/games/mygame.crt').then(r => r.arrayBuffer()));
356
+ emulator.loadGame({ type: 'crt', data: crtBytes });
357
+
358
+ // Start the emulation loop
359
+ emulator.start();
222
360
  ```
223
361
 
224
- Note: the script does not push to the wiki remote automatically to avoid accidental publishing. It also appends links to `Home.md` only if they are not already present.
362
+ #### Headless emulator — `c64-ready/headless`
225
363
 
226
- ## Release helper (`tools/release.sh`)
364
+ `C64Headless` wraps `C64Emulator` for server-side use (Node.js / Deno). It wires up
365
+ `FrameCapture`, `AudioCapture`, and `InputBridge` out of the box.
227
366
 
228
- This project includes a small release helper script `./tools/release.sh` that wraps `npm version` and git push steps. The script now supports a safe `--dry-run` mode that reports the version that WOULD be created without modifying files, and a `--preid` option for prereleases.
367
+ ```ts
368
+ import { C64Headless } from 'c64-ready/headless';
229
369
 
230
- Examples
370
+ const headless = new C64Headless('/path/to/c64.wasm');
371
+ await headless.init();
231
372
 
232
- - Dry-run a minor bump (no changes made):
233
- ```bash
234
- ./tools/release.sh minor --dry-run
235
- # -> prints predicted new version (e.g. 0.4.0) and does not edit package.json
373
+ // Optional: load a game
374
+ const data = new Uint8Array(fs.readFileSync('/path/to/game.crt'));
375
+ await headless.loadGame({ type: 'crt', data });
376
+
377
+ // Step the emulator and capture frames
378
+ const { frame, audio } = headless.stepAndCapture(20); // 20 ms step
379
+ if (frame) {
380
+ // frame is a Uint8Array of raw RGBA pixels (384 × 272)
381
+ }
382
+
383
+ // Forward remote input from an external source (e.g. WebSocket message)
384
+ headless.inputBridge.receiveRemoteInput(
385
+ JSON.stringify({ type: 'joystick', action: 'push', joystickPort: 2, direction: 'up' })
386
+ );
236
387
  ```
237
388
 
238
- - Create the version commit and tag locally but do not push:
239
- ```bash
240
- ./tools/release.sh minor --no-push
241
- # creates the commit and tag (npm version) locally so you can inspect before pushing
389
+ #### Remote input encoding — `c64-ready/input-bridge`
390
+
391
+ `InputBridge` provides static helpers so you don't hand-roll input JSON:
392
+
393
+ ```ts
394
+ import { InputBridge } from 'c64-ready/input-bridge';
395
+
396
+ // Joystick
397
+ const push = InputBridge.encodeJoystick(2, 'push', 'right');
398
+ const release = InputBridge.encodeJoystick(2, 'release', 'right');
399
+ const fire = InputBridge.encodeJoystick(2, 'push', undefined, true);
400
+
401
+ // Keyboard (C64 key code)
402
+ const keyDown = InputBridge.encodeKeypress(65, 'down'); // key code 65 = 'A'
403
+ const keyUp = InputBridge.encodeKeypress(65, 'up');
404
+
405
+ // Send via WebSocket — push on button-down, release on button-up
406
+ gamepad.on('buttondown', (btn) => ws.send(InputBridge.encodeJoystick(2, 'push', btn.direction)));
407
+ gamepad.on('buttonup', (btn) => ws.send(InputBridge.encodeJoystick(2, 'release', btn.direction)));
242
408
  ```
243
409
 
244
- - Full release (commit, tag, and push to origin/master):
245
- ```bash
246
- # Run this on master with a clean working tree
247
- ./tools/release.sh minor
410
+ ### Using the player in your own Vite app
411
+
412
+ The browser player (`src/player/*`) uses Vite-specific features (`?raw` CSS imports,
413
+ `import.meta.env`) so it is **not** pre-compiled and is shipped as TypeScript source.
414
+ Copy the files you need into your own Vite project and import them directly:
415
+
416
+ ```ts
417
+ // In your Vite project (TypeScript + Vite)
418
+ import { C64Player } from './vendor/c64-ready/src/player/c64-player';
419
+ import CanvasRenderer from './vendor/c64-ready/src/player/canvas-renderer';
420
+ import { AudioEngine } from './vendor/c64-ready/src/player/audio-engine';
421
+
422
+ const renderer = new CanvasRenderer('c64-canvas');
423
+ const player = new C64Player({
424
+ wasmUrl: '/c64.wasm',
425
+ gameUrl: '/games/mygame.crt',
426
+ renderer,
427
+ });
428
+
429
+ await player.start();
248
430
  ```
249
431
 
250
- - Create a prerelease (example with `beta` identifier) — dry-run:
251
- ```bash
252
- ./tools/release.sh preminor --preid beta --dry-run
253
- # -> e.g. predicts 0.4.0-beta.0 without changing files
432
+ Also copy `public/c64.wasm` and `public/audio-worklet-processor.js` into your project's
433
+ public directory so they are served alongside your app.
434
+
435
+ ### Building before publish
436
+
437
+ To regenerate both the Vite browser bundle and the TypeScript API outputs in one step:
438
+
439
+ ```zsh
440
+ npm run package:build
441
+ # equivalent to: npm run build && npm run headless:build
254
442
  ```
255
443
 
256
- - Create a prerelease (create locally, no push):
257
- ```bash
258
- ./tools/release.sh prerelease --preid beta --no-push
259
- # creates tag like v0.3.1-beta.0 locally
444
+ This produces:
445
+ - `dist/` — Vite browser bundle (served by `c64-ready` CLI)
446
+ - `dist-ts/` — compiled JS + `.d.ts` declarations (imported by API consumers)
447
+
448
+ ## Deployment
449
+
450
+ The project deploys to GitHub Pages automatically via GitHub Actions.
451
+
452
+ On every push to `master`:
453
+ 1. Tests run (`npm test`)
454
+ 2. If tests pass, a production build is created (`npm run build`)
455
+ 3. The `dist/` output is deployed to GitHub Pages
456
+
457
+
458
+ ## Work in Progress:
459
+ - Proof of Concept Implementation:
460
+ - [x] WASM module loading and initialization
461
+ - [x] Emulator control and state management
462
+ - [x] Canvas-based rendering
463
+ - [x] Node-based headless rendering
464
+ - [x] Framework agnostic integration (e.g., Vanilla HTML+JS, React, Vue, Angular etc)
465
+ - Additional features:
466
+ - [x] Audio output
467
+ - [x] Input handling (keyboard)
468
+ - [x] Loading and running .crt cartridge roms
469
+ - [x] Display settings
470
+ - [x] Docker headless streaming (RTMP / HTTP-FLV via Node Media Server)
471
+ - [ ] Gamepad support
472
+ - [ ] Touch controls
473
+
474
+ ## Changelog & Releases
475
+
476
+ See [`docs/CHANGELOG_RELEASES.md`](docs/CHANGELOG_RELEASES.md) for the full release workflow,
477
+ changelog generator usage, `tools/release.sh` examples, and authentication notes.
478
+
479
+ Quick start — bump and push a patch release:
480
+
481
+ ```zsh
482
+ npm version patch -m "chore(release): %s"
483
+ git push origin master && git push --tags
260
484
  ```
261
485
 
262
- Notes and safety
486
+ ## Docs
263
487
 
264
- - `--dry-run` will never edit `package.json` or create git commits/tags — it only prints the predicted version and the commands the script would run.
265
- - Use `--no-push` to create the commit and tag locally for inspection, then push manually when you're ready.
266
- - The script expects a clean working tree and will prompt if you are not on `master` (unless you use `--dry-run` which skips branch checks).
488
+ Extended documentation lives in the [`docs/`](docs/) folder:
267
489
 
268
- If you want, I can add examples to the CI workflow to automatically create releases on merges to `master` using this helper.
490
+ | File | Description |
491
+ |------|-------------|
492
+ | [`AUDIO_ENGINE.md`](docs/AUDIO_ENGINE.md) | SID audio pipeline, worklet pull-model, timing rules |
493
+ | [`HEADLESS_INPUT.md`](docs/HEADLESS_INPUT.md) | Headless WebSocket input API reference |
494
+ | [`HEADLESS_RUNNING.md`](docs/HEADLESS_RUNNING.md) | Headless CLI usage, frame/timing rules, ffmpeg integration |
495
+ | [`PROJECT_OVERVIEW.md`](docs/PROJECT_OVERVIEW.md) | High-level architecture and design decisions |
496
+ | [`CHANGELOG_RELEASES.md`](docs/CHANGELOG_RELEASES.md) | Release workflow, `tools/release.sh`, changelog generator |
497
+ | [`WIKI_PUBLISHING.md`](docs/WIKI_PUBLISHING.md) | How to sync `docs/` to the GitHub wiki via `tools/publish_wiki.sh` |
498
+
499
+ The wiki is kept in sync automatically by the `.github/workflows/publish_wiki.yml` CI workflow
500
+ on every push to `master`. To publish manually:
501
+
502
+ ```bash
503
+ ./tools/publish_wiki.sh git@github.com:YOUR_USER/c64-ready.wiki.git
504
+ ```
269
505
 
package/bin/headless.mjs CHANGED
@@ -13,6 +13,8 @@
13
13
  * --output <path|url> Output file or rtmp:// URL [default: temp/c64-record-<ts>.mp4]
14
14
  * --duration <secs> Recording duration in seconds [default: 60]
15
15
  * --fps <n> Frame rate [default: 50 (PAL)]
16
+ * --input Start WebSocket input server for remote control
17
+ * --ws-port <n> WebSocket server port [default: 9001]
16
18
  * --verbose Print per-frame diagnostics
17
19
  * --help Show this help
18
20
  *
@@ -49,12 +51,14 @@ Options:
49
51
  --output <path|url> Output file path or rtmp:// stream URL
50
52
  --duration <secs> Recording duration in seconds (omit for endless streaming)
51
53
  --fps <n> Target frame rate (default: 50 for PAL)
54
+ --input Start WebSocket input server for remote control
55
+ --ws-port <n> WebSocket server port (default: 9001)
52
56
  --verbose Print per-frame diagnostics to stderr
53
57
  --help Show this help
54
58
 
55
59
  Prerequisites:
56
60
  ffmpeg must be on PATH for --record
57
- Build the JS wrapper once: npx tsc -p tsconfig.build2.json
61
+ ws npm package must be installed for --input (it is a dependency of c64-ready)
58
62
 
59
63
  Examples:
60
64
  # RTMP live stream (5 minutes)
@@ -65,9 +69,9 @@ Examples:
65
69
  c64-headless --wasm public/c64.wasm --no-game --record \\
66
70
  --output out.mp4 --duration 30
67
71
 
68
- # Load a cartridge and stream
72
+ # Stream with remote input enabled
69
73
  c64-headless --wasm public/c64.wasm --game game.crt --record \\
70
- --output rtmp://localhost:1935/live/c64 --duration 3600
74
+ --output rtmp://localhost:1935/live/c64 --input --ws-port 9001
71
75
  `.trim();
72
76
  console.log(help);
73
77
  process.exit(0);