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.
- package/README.md +332 -96
- package/bin/headless.mjs +7 -3
- package/bin/serve.mjs +162 -0
- package/dist/assets/CHANGELOG-C1nvP1iO.js +96 -0
- package/dist/assets/index-Cioamf6E.js +394 -0
- package/dist/assets/marked.esm-BOXuzyNF.js +37 -0
- package/dist/assets/purify.es-y41lKIN9.js +2 -0
- package/dist/audio-worklet-processor.js +83 -0
- package/dist/c64-ready/c64-ready.gif +0 -0
- package/dist/c64-ready/index.html +58 -0
- package/dist/c64.wasm +0 -0
- package/dist/games/cartridges/legend-of-wilf.crt +0 -0
- package/dist/index.html +38 -0
- package/dist/led-off.svg +20 -0
- package/dist/led-on.svg +27 -0
- package/dist/vite.svg +15 -0
- package/dist-ts/emulator/c64-emulator.d.ts +107 -0
- package/dist-ts/emulator/c64-emulator.d.ts.map +1 -0
- package/dist-ts/emulator/c64-emulator.js +13 -1
- package/dist-ts/emulator/c64-emulator.js.map +1 -0
- package/dist-ts/emulator/c64-wasm.d.ts +42 -0
- package/dist-ts/emulator/c64-wasm.d.ts.map +1 -0
- package/dist-ts/emulator/c64-wasm.js +1 -0
- package/dist-ts/emulator/c64-wasm.js.map +1 -0
- package/dist-ts/emulator/constants.d.ts +14 -0
- package/dist-ts/emulator/constants.d.ts.map +1 -0
- package/dist-ts/emulator/constants.js +1 -0
- package/dist-ts/emulator/constants.js.map +1 -0
- package/dist-ts/emulator/input.d.ts +33 -0
- package/dist-ts/emulator/input.d.ts.map +1 -0
- package/dist-ts/emulator/input.js +26 -5
- package/dist-ts/emulator/input.js.map +1 -0
- package/dist-ts/emulator/memory.d.ts +2 -0
- package/dist-ts/emulator/memory.d.ts.map +1 -0
- package/dist-ts/emulator/memory.js +9 -0
- package/dist-ts/emulator/memory.js.map +1 -0
- package/dist-ts/headless/audio-capture.d.ts +13 -0
- package/dist-ts/headless/audio-capture.d.ts.map +1 -0
- package/dist-ts/headless/audio-capture.js +24 -0
- package/dist-ts/headless/audio-capture.js.map +1 -0
- package/dist-ts/headless/c64-headless.d.ts +36 -0
- package/dist-ts/headless/c64-headless.d.ts.map +1 -0
- package/dist-ts/headless/c64-headless.js +87 -0
- package/dist-ts/headless/c64-headless.js.map +1 -0
- package/dist-ts/headless/ffmpeg-runner.d.ts +18 -0
- package/dist-ts/headless/ffmpeg-runner.d.ts.map +1 -0
- package/dist-ts/headless/ffmpeg-runner.js +67 -0
- package/dist-ts/headless/ffmpeg-runner.js.map +1 -0
- package/dist-ts/headless/frame-capture.d.ts +13 -0
- package/dist-ts/headless/frame-capture.d.ts.map +1 -0
- package/dist-ts/headless/frame-capture.js +24 -0
- package/dist-ts/headless/frame-capture.js.map +1 -0
- package/dist-ts/headless/input-bridge.d.ts +21 -0
- package/dist-ts/headless/input-bridge.d.ts.map +1 -0
- package/dist-ts/headless/input-bridge.js +41 -0
- package/dist-ts/headless/input-bridge.js.map +1 -0
- package/dist-ts/src/counter.js +9 -0
- package/dist-ts/src/emulator/c64-emulator.js +308 -0
- package/dist-ts/src/emulator/c64-emulator.test.js +104 -0
- package/dist-ts/src/emulator/c64-wasm.js +149 -0
- package/dist-ts/src/emulator/c64-wasm.test.js +65 -0
- package/dist-ts/src/emulator/constants.js +9 -0
- package/dist-ts/src/emulator/input.js +62 -0
- package/dist-ts/src/emulator/input.test.js +53 -0
- package/dist-ts/src/emulator/memory.js +1 -0
- package/dist-ts/src/headless/audio-capture.js +23 -0
- package/dist-ts/src/headless/c64-headless.js +85 -0
- package/dist-ts/src/headless/ffmpeg-runner.js +33 -0
- package/dist-ts/src/headless/frame-capture.js +23 -0
- package/dist-ts/src/headless/headless.cli.test.js +46 -0
- package/dist-ts/src/headless/input-bridge.js +37 -0
- package/dist-ts/src/main.js +57 -0
- package/dist-ts/src/player/audio-engine.js +175 -0
- package/dist-ts/src/player/audio-engine.test.js +284 -0
- package/dist-ts/src/player/c64-player.js +105 -0
- package/dist-ts/src/player/c64-player.test.js +165 -0
- package/dist-ts/src/player/canvas-renderer.js +148 -0
- package/dist-ts/src/player/canvas-renderer.test.js +135 -0
- package/dist-ts/src/player/input-handler.js +13 -0
- package/dist-ts/src/player/ui-controller.js +575 -0
- package/dist-ts/src/player/ui-controller.test.js +67 -0
- package/dist-ts/src/types/emulator.js +1 -0
- package/dist-ts/src/types/index.js +4 -0
- package/dist-ts/tools/run-wrapper.js +36 -0
- package/dist-ts/types/emulator.d.ts +128 -0
- package/dist-ts/types/emulator.d.ts.map +1 -0
- package/dist-ts/types/emulator.js +2 -0
- package/dist-ts/types/emulator.js.map +1 -0
- package/dist-ts/types/index.d.ts +51 -0
- package/dist-ts/types/index.d.ts.map +1 -0
- package/dist-ts/types/index.js +5 -0
- package/dist-ts/types/index.js.map +1 -0
- package/package.json +40 -6
- package/public/audio-worklet-processor.js +83 -0
- package/public/led-off.svg +20 -0
- package/public/led-on.svg +27 -0
- package/src/counter.ts +9 -0
- package/src/emulator/c64-emulator.ts +357 -0
- package/src/emulator/c64-wasm.ts +180 -0
- package/src/emulator/constants.ts +22 -0
- package/src/emulator/input.ts +105 -0
- package/src/emulator/memory.ts +9 -0
- package/src/headless/headless-cli.mjs +105 -19
- package/src/headless/input-bridge.ts +13 -4
- package/src/headless/input-server.mjs +76 -0
- package/src/main.ts +80 -0
- package/src/player/audio-engine.ts +216 -0
- package/src/player/c64-player.ts +222 -0
- package/src/player/canvas-renderer.ts +139 -0
- package/src/player/input-handler.ts +116 -0
- package/src/player/styles/canvas-renderer.css +41 -0
- package/src/player/styles/ui-controller.css +286 -0
- package/src/player/ui-controller.ts +485 -0
- package/src/style.css +96 -0
- package/src/types/emulator.ts +167 -0
- package/src/types/index.ts +62 -0
- 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
|
-
##
|
|
116
|
+
## Headless Input API
|
|
117
117
|
|
|
118
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
135
|
+
### Wire protocol (client → server)
|
|
145
136
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
141
|
+
```json
|
|
142
|
+
{ "type": "joystick", "action": "push", "joystickPort": 2, "direction": "up" }
|
|
143
|
+
{ "type": "joystick", "action": "release", "joystickPort": 2, "direction": "up" }
|
|
152
144
|
|
|
153
|
-
|
|
145
|
+
{ "type": "joystick", "action": "push", "joystickPort": 2, "fire": true }
|
|
146
|
+
{ "type": "joystick", "action": "release", "joystickPort": 2, "fire": true }
|
|
147
|
+
```
|
|
154
148
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
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
|
-
|
|
164
|
-
git push --tags
|
|
263
|
+
INPUT_ENABLED=1 WS_PORT=9001 docker compose up
|
|
165
264
|
```
|
|
166
265
|
|
|
167
|
-
|
|
266
|
+
Then connect your client to `ws://localhost:9001`.
|
|
168
267
|
|
|
169
|
-
|
|
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
|
-
|
|
270
|
+
`c64-ready` can be installed as a dependency and used in three ways:
|
|
173
271
|
|
|
174
|
-
-
|
|
175
|
-
|
|
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
|
-
|
|
278
|
+
### Prerequisites
|
|
178
279
|
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
284
|
+
### Running the browser player
|
|
183
285
|
|
|
184
|
-
|
|
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
|
-
|
|
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
|
-
|
|
298
|
+
Open the URL printed to the terminal in any modern browser:
|
|
191
299
|
|
|
192
|
-
|
|
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
|
-
|
|
315
|
+
# Different port, accessible on the LAN
|
|
316
|
+
c64-ready --port 8080 --host
|
|
196
317
|
```
|
|
197
318
|
|
|
198
|
-
|
|
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
|
-
|
|
322
|
+
### TypeScript / Node.js API
|
|
201
323
|
|
|
202
|
-
|
|
324
|
+
After installing as a local dependency:
|
|
325
|
+
|
|
326
|
+
```zsh
|
|
327
|
+
npm install c64-ready
|
|
328
|
+
```
|
|
203
329
|
|
|
204
|
-
|
|
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
|
-
|
|
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
|
-
|
|
213
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
362
|
+
#### Headless emulator — `c64-ready/headless`
|
|
225
363
|
|
|
226
|
-
|
|
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
|
-
|
|
367
|
+
```ts
|
|
368
|
+
import { C64Headless } from 'c64-ready/headless';
|
|
229
369
|
|
|
230
|
-
|
|
370
|
+
const headless = new C64Headless('/path/to/c64.wasm');
|
|
371
|
+
await headless.init();
|
|
231
372
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
486
|
+
## Docs
|
|
263
487
|
|
|
264
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
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 --
|
|
74
|
+
--output rtmp://localhost:1935/live/c64 --input --ws-port 9001
|
|
71
75
|
`.trim();
|
|
72
76
|
console.log(help);
|
|
73
77
|
process.exit(0);
|