c64-ready 0.5.1 → 0.6.1

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 +164 -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/emulator/memory.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ // This file was removed from the active source tree because it appears to be
2
+ // unused in the codebase. It has been archived here to preserve history
3
+ // and avoid accidental deletion. If you later decide to restore it,
4
+ // move it back into `src/emulator/` and re-export any required symbols.
5
+ //
6
+ // Search results showed no imports/usages of `src/emulator/memory.ts`.
7
+ // Keeping a small stub export so TypeScript treats this as a module.
8
+ export {};
9
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/emulator/memory.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wEAAwE;AACxE,oEAAoE;AACpE,wEAAwE;AACxE,EAAE;AACF,uEAAuE;AACvE,qEAAqE"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Audio capture for headless operation
3
+ */
4
+ import type { AudioBuffer } from '../types';
5
+ export declare class AudioCapture {
6
+ private latestAudio;
7
+ private audioQueue;
8
+ capture(audio: AudioBuffer): void;
9
+ getLatest(): Float32Array | null;
10
+ getQueued(): Float32Array[];
11
+ clearQueue(): void;
12
+ }
13
+ //# sourceMappingURL=audio-capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audio-capture.d.ts","sourceRoot":"","sources":["../../src/headless/audio-capture.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,UAAU,CAAsB;IAExC,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAMjC,SAAS,IAAI,YAAY,GAAG,IAAI;IAIhC,SAAS,IAAI,YAAY,EAAE;IAM3B,UAAU,IAAI,IAAI;CAGnB"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Audio capture for headless operation
3
+ */
4
+ export class AudioCapture {
5
+ latestAudio = null;
6
+ audioQueue = [];
7
+ capture(audio) {
8
+ // Copy samples so the caller owns them
9
+ this.latestAudio = audio.samples.slice();
10
+ this.audioQueue.push(this.latestAudio);
11
+ }
12
+ getLatest() {
13
+ return this.latestAudio;
14
+ }
15
+ getQueued() {
16
+ const q = this.audioQueue;
17
+ this.audioQueue = [];
18
+ return q;
19
+ }
20
+ clearQueue() {
21
+ this.audioQueue = [];
22
+ }
23
+ }
24
+ //# sourceMappingURL=audio-capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audio-capture.js","sourceRoot":"","sources":["../../src/headless/audio-capture.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,OAAO,YAAY;IACf,WAAW,GAAwB,IAAI,CAAC;IACxC,UAAU,GAAmB,EAAE,CAAC;IAExC,OAAO,CAAC,KAAkB;QACxB,uCAAuC;QACvC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,SAAS;QACP,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,UAAU;QACR,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Headless C64 emulator for server-side streaming / testing
3
+ * Minimal MVP implementation: load WASM, wire frame/audio capture and input bridge,
4
+ * expose step/run methods for consuming frames and audio in Node environments.
5
+ */
6
+ import { InputBridge } from './input-bridge';
7
+ import type { GameLoadOptions, C64Config } from '../types';
8
+ export declare class C64Headless {
9
+ private wasmUrl;
10
+ private config?;
11
+ private emulator;
12
+ private frameCapture;
13
+ private audioCapture;
14
+ readonly inputBridge: InputBridge;
15
+ constructor(wasmUrl?: string, config?: Partial<C64Config>);
16
+ /** Load and initialise the WASM emulator */
17
+ init(): Promise<void>;
18
+ loadGame(options: GameLoadOptions): Promise<void>;
19
+ /**
20
+ * Run a single emulation tick/frame and return the captured latest frame/audio.
21
+ * This will start the emulator if it was not running, and restore the previous
22
+ * running state afterwards.
23
+ */
24
+ stepAndCapture(dTime?: number): {
25
+ frame: Uint8Array | null;
26
+ audio: Float32Array | null;
27
+ };
28
+ /**
29
+ * Continuous run loop for streaming. Calls onFrame / onAudio for every tick
30
+ * until the emulator is paused via stop().
31
+ */
32
+ runLoop(onFrame?: (data: Uint8Array) => void, onAudio?: (data: Float32Array) => void): Promise<void>;
33
+ feedInput(json: string): void;
34
+ stop(): void;
35
+ }
36
+ //# sourceMappingURL=c64-headless.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c64-headless.d.ts","sourceRoot":"","sources":["../../src/headless/c64-headless.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,eAAe,EAA4B,SAAS,EAAc,MAAM,UAAU,CAAC;AAEjG,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,CAAqB;IACpC,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,YAAY,CAAsB;IAC1C,QAAQ,CAAC,WAAW,cAAqB;gBAE7B,OAAO,GAAE,MAAiC,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC;IAUnF,4CAA4C;IACtC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAQrB,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvD;;;;OAIG;IACH,cAAc,CAAC,KAAK,GAAE,MAAU,GAAG;QAAE,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;KAAE;IAiB3F;;;OAGG;IACG,OAAO,CACX,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,EACpC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,GACrC,OAAO,CAAC,IAAI,CAAC;IAuBhB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI7B,IAAI,IAAI,IAAI;CAGb"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Headless C64 emulator for server-side streaming / testing
3
+ * Minimal MVP implementation: load WASM, wire frame/audio capture and input bridge,
4
+ * expose step/run methods for consuming frames and audio in Node environments.
5
+ */
6
+ import { C64Emulator } from '../emulator/c64-emulator';
7
+ import { FrameCapture } from './frame-capture';
8
+ import { AudioCapture } from './audio-capture';
9
+ import { InputBridge } from './input-bridge';
10
+ export class C64Headless {
11
+ wasmUrl;
12
+ config;
13
+ emulator = null;
14
+ frameCapture = new FrameCapture();
15
+ audioCapture = new AudioCapture();
16
+ inputBridge = new InputBridge();
17
+ constructor(wasmUrl = '/src/emulator/c64.wasm', config) {
18
+ this.wasmUrl = wasmUrl;
19
+ this.config = config;
20
+ // Forward remote input into the emulator when available
21
+ this.inputBridge.onInput = (ev) => {
22
+ this.emulator?.handleInput(ev);
23
+ };
24
+ }
25
+ /** Load and initialise the WASM emulator */
26
+ async init() {
27
+ this.emulator = await C64Emulator.load(this.wasmUrl, this.config ?? {});
28
+ // Wire capture callbacks
29
+ this.emulator.onFrame = (frame) => this.frameCapture.capture(frame);
30
+ this.emulator.onAudio = (audio) => this.audioCapture.capture(audio);
31
+ }
32
+ async loadGame(options) {
33
+ if (!this.emulator)
34
+ throw new Error('Emulator not initialised — call init() first');
35
+ this.emulator.loadGame(options);
36
+ }
37
+ /**
38
+ * Run a single emulation tick/frame and return the captured latest frame/audio.
39
+ * This will start the emulator if it was not running, and restore the previous
40
+ * running state afterwards.
41
+ */
42
+ stepAndCapture(dTime = 0) {
43
+ if (!this.emulator)
44
+ throw new Error('Emulator not initialised — call init() first');
45
+ const wasRunning = this.emulator.isRunning();
46
+ if (!wasRunning)
47
+ this.emulator.start();
48
+ // Tick once (dTime in ms). If 0, emulator.tick will clamp to ~60fps like browser.
49
+ this.emulator.tick(dTime);
50
+ const frame = this.frameCapture.getLatest();
51
+ const audio = this.audioCapture.getLatest();
52
+ if (!wasRunning)
53
+ this.emulator.pause();
54
+ return { frame, audio };
55
+ }
56
+ /**
57
+ * Continuous run loop for streaming. Calls onFrame / onAudio for every tick
58
+ * until the emulator is paused via stop().
59
+ */
60
+ async runLoop(onFrame, onAudio) {
61
+ if (!this.emulator)
62
+ throw new Error('Emulator not initialised — call init() first');
63
+ this.emulator.start();
64
+ while (this.emulator.isRunning()) {
65
+ this.emulator.tick(0);
66
+ const frame = this.frameCapture.getLatest();
67
+ const audio = this.audioCapture.getLatest();
68
+ if (frame && onFrame)
69
+ onFrame(frame);
70
+ if (audio && onAudio)
71
+ onAudio(audio);
72
+ // yield to node event loop
73
+ // Use setImmediate which is available in Node; fall back to a timeout if not present
74
+ await new Promise((resolve) => typeof globalThis
75
+ .setImmediate === 'function'
76
+ ? globalThis.setImmediate(resolve)
77
+ : setTimeout(resolve, 0));
78
+ }
79
+ }
80
+ feedInput(json) {
81
+ this.inputBridge.receiveRemoteInput(json);
82
+ }
83
+ stop() {
84
+ this.emulator?.pause();
85
+ }
86
+ }
87
+ //# sourceMappingURL=c64-headless.js.map
@@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,YAAY,CAAC,SAAS,EAAE,CAAC;YAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC;YAC5C,IAAI,KAAK,IAAI,OAAO;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,KAAK,IAAI,OAAO;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC;YACrC,2BAA2B;YAC3B,qFAAqF;YACrF,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAClC,OAAQ,UAAqE;iBAC1E,YAAY,KAAK,UAAU;gBAC5B,CAAC,CAAE,UAAqE,CAAC,YAAa,CAClF,OAAO,CACR;gBACH,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAC3B,CAAC;QACJ,CAAC;IACH,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI;QACF,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Minimal FFmpeg runner stub for headless MVP.
3
+ *
4
+ * This file provides a very small wrapper around child_process.spawn to demonstrate
5
+ * how frames/audio could be piped to an ffmpeg process. For the MVP we expose a
6
+ * start/stop API but do not implement the full piping logic — this keeps the
7
+ * library safe to run in browser builds while remaining useful in Node.
8
+ */
9
+ export declare class FFmpegRunner {
10
+ private proc;
11
+ /**
12
+ * Start ffmpeg with the provided args. Returns true if spawn succeeded.
13
+ * In browser builds this will be a no-op and return false.
14
+ */
15
+ start(args: string[]): boolean;
16
+ stop(): void;
17
+ }
18
+ //# sourceMappingURL=ffmpeg-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffmpeg-runner.d.ts","sourceRoot":"","sources":["../../src/headless/ffmpeg-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAA6B;IAEzC;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO;IAiD9B,IAAI,IAAI,IAAI;CAMb"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Minimal FFmpeg runner stub for headless MVP.
3
+ *
4
+ * This file provides a very small wrapper around child_process.spawn to demonstrate
5
+ * how frames/audio could be piped to an ffmpeg process. For the MVP we expose a
6
+ * start/stop API but do not implement the full piping logic — this keeps the
7
+ * library safe to run in browser builds while remaining useful in Node.
8
+ */
9
+ import { spawn } from 'child_process';
10
+ export class FFmpegRunner {
11
+ proc = null;
12
+ /**
13
+ * Start ffmpeg with the provided args. Returns true if spawn succeeded.
14
+ * In browser builds this will be a no-op and return false.
15
+ */
16
+ start(args) {
17
+ try {
18
+ // Use Node's spawn import directly. This module is only used in
19
+ // headless Node.js environments and should not be bundled into
20
+ // browser builds.
21
+ // If the user passed an RTMP (or similar) output URL, ensure we include
22
+ // streaming-friendly encoder options unless the caller already provided
23
+ // them. We look for a URL like rtmp:// and, if found, insert a sensible
24
+ // default encoder config for low-latency live streaming.
25
+ let finalArgs = args.slice();
26
+ const outputIndex = finalArgs.findIndex((a) => a.startsWith('rtmp://'));
27
+ if (outputIndex !== -1) {
28
+ const hasPreset = finalArgs.some((a) => a === '-preset' || a === '-tune' || a === '-g' || a === '-c:v');
29
+ if (!hasPreset) {
30
+ // Insert before the output position
31
+ const streamOpts = [
32
+ '-c:v',
33
+ 'libx264',
34
+ '-preset',
35
+ 'ultrafast',
36
+ '-tune',
37
+ 'zerolatency',
38
+ '-pix_fmt',
39
+ 'yuv420p',
40
+ '-g',
41
+ '50',
42
+ ];
43
+ finalArgs = finalArgs
44
+ .slice(0, outputIndex)
45
+ .concat(streamOpts)
46
+ .concat(finalArgs.slice(outputIndex));
47
+ }
48
+ }
49
+ // Spawn ffmpeg and show its stdout/stderr to aid debugging in Node.
50
+ // Use a pipe for stdin so callers can write frames to ffmpeg if needed.
51
+ this.proc = spawn('ffmpeg', finalArgs, { stdio: ['pipe', 'inherit', 'inherit'] });
52
+ return this.proc != null;
53
+ }
54
+ catch (_err) {
55
+ // ignore spawn errors (ffmpeg missing or not available in environment)
56
+ console.debug('[ffmpeg-runner] spawn failed', String(_err));
57
+ return false;
58
+ }
59
+ }
60
+ stop() {
61
+ if (this.proc && typeof this.proc.kill === 'function') {
62
+ this.proc.kill('SIGINT');
63
+ }
64
+ this.proc = null;
65
+ }
66
+ }
67
+ //# sourceMappingURL=ffmpeg-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ffmpeg-runner.js","sourceRoot":"","sources":["../../src/headless/ffmpeg-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAC;AAEzD,MAAM,OAAO,YAAY;IACf,IAAI,GAAwB,IAAI,CAAC;IAEzC;;;OAGG;IACH,KAAK,CAAC,IAAc;QAClB,IAAI,CAAC;YACH,gEAAgE;YAChE,+DAA+D;YAC/D,kBAAkB;YAElB,wEAAwE;YACxE,wEAAwE;YACxE,wEAAwE;YACxE,yDAAyD;YACzD,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAC7B,MAAM,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;YAExE,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;gBACvB,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,MAAM,CACtE,CAAC;gBACF,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,oCAAoC;oBACpC,MAAM,UAAU,GAAG;wBACjB,MAAM;wBACN,SAAS;wBACT,SAAS;wBACT,WAAW;wBACX,OAAO;wBACP,aAAa;wBACb,UAAU;wBACV,SAAS;wBACT,IAAI;wBACJ,IAAI;qBACL,CAAC;oBACF,SAAS,GAAG,SAAS;yBAClB,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC;yBACrB,MAAM,CAAC,UAAU,CAAC;yBAClB,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;gBAC1C,CAAC;YACH,CAAC;YAED,oEAAoE;YACpE,wEAAwE;YACxE,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;YAClF,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;QAC3B,CAAC;QAAC,OAAO,IAAI,EAAE,CAAC;YACd,uEAAuE;YACvE,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YAC5D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,IAAI;QACF,IAAI,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACtD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Frame capture for headless operation
3
+ */
4
+ import type { FrameBuffer } from '../types';
5
+ export declare class FrameCapture {
6
+ private latestFrame;
7
+ private frameQueue;
8
+ capture(frame: FrameBuffer): void;
9
+ getLatest(): Uint8Array | null;
10
+ getQueued(): Uint8Array[];
11
+ clearQueue(): void;
12
+ }
13
+ //# sourceMappingURL=frame-capture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame-capture.d.ts","sourceRoot":"","sources":["../../src/headless/frame-capture.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,UAAU,CAAoB;IAEtC,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAMjC,SAAS,IAAI,UAAU,GAAG,IAAI;IAI9B,SAAS,IAAI,UAAU,EAAE;IAMzB,UAAU,IAAI,IAAI;CAGnB"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Frame capture for headless operation
3
+ */
4
+ export class FrameCapture {
5
+ latestFrame = null;
6
+ frameQueue = [];
7
+ capture(frame) {
8
+ // Store latest frame (copy to ensure consumer owns the buffer)
9
+ this.latestFrame = frame.data.slice();
10
+ this.frameQueue.push(this.latestFrame);
11
+ }
12
+ getLatest() {
13
+ return this.latestFrame;
14
+ }
15
+ getQueued() {
16
+ const q = this.frameQueue;
17
+ this.frameQueue = [];
18
+ return q;
19
+ }
20
+ clearQueue() {
21
+ this.frameQueue = [];
22
+ }
23
+ }
24
+ //# sourceMappingURL=frame-capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame-capture.js","sourceRoot":"","sources":["../../src/headless/frame-capture.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,OAAO,YAAY;IACf,WAAW,GAAsB,IAAI,CAAC;IACtC,UAAU,GAAiB,EAAE,CAAC;IAEtC,OAAO,CAAC,KAAkB;QACxB,+DAA+D;QAC/D,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QACtC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,SAAS;QACP,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,OAAO,CAAC,CAAC;IACX,CAAC;IAED,UAAU;QACR,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Remote input bridge (WebSocket → emulator)
3
+ * Allows remote players to control the emulator
4
+ */
5
+ import type { InputEvent } from '../types';
6
+ export declare class InputBridge {
7
+ onInput?: (event: InputEvent) => void;
8
+ /**
9
+ * Called when a remote input arrives (e.g., from WebSocket)
10
+ */
11
+ receiveRemoteInput(jsonString: string): void;
12
+ /**
13
+ * Encode a keypress for transmission
14
+ */
15
+ static encodeKeypress(key: string | number, action?: 'down' | 'up'): string;
16
+ /**
17
+ * Encode a joystick event for transmission
18
+ */
19
+ static encodeJoystick(port: 1 | 2, action: 'push' | 'release', direction?: string, fire?: boolean): string;
20
+ }
21
+ //# sourceMappingURL=input-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-bridge.d.ts","sourceRoot":"","sources":["../../src/headless/input-bridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,qBAAa,WAAW;IACtB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IAEtC;;OAEG;IACH,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAa5C;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,GAAE,MAAM,GAAG,IAAa,GAAG,MAAM;IAInF;;OAEG;IACH,MAAM,CAAC,cAAc,CACnB,IAAI,EAAE,CAAC,GAAG,CAAC,EACX,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,SAAS,CAAC,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,OAAO,GACb,MAAM;CASV"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Remote input bridge (WebSocket → emulator)
3
+ * Allows remote players to control the emulator
4
+ */
5
+ export class InputBridge {
6
+ onInput;
7
+ /**
8
+ * Called when a remote input arrives (e.g., from WebSocket)
9
+ */
10
+ receiveRemoteInput(jsonString) {
11
+ try {
12
+ const event = JSON.parse(jsonString);
13
+ if (this.onInput) {
14
+ this.onInput(event);
15
+ }
16
+ }
17
+ catch (err) {
18
+ // Keep minimal dependency on console in headless mode
19
+ console.error('Failed to parse input:', err);
20
+ }
21
+ }
22
+ /**
23
+ * Encode a keypress for transmission
24
+ */
25
+ static encodeKeypress(key, action = 'down') {
26
+ return JSON.stringify({ type: 'key', key, action });
27
+ }
28
+ /**
29
+ * Encode a joystick event for transmission
30
+ */
31
+ static encodeJoystick(port, action, direction, fire) {
32
+ return JSON.stringify({
33
+ type: 'joystick',
34
+ joystickPort: port,
35
+ action,
36
+ direction,
37
+ fire,
38
+ });
39
+ }
40
+ }
41
+ //# sourceMappingURL=input-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-bridge.js","sourceRoot":"","sources":["../../src/headless/input-bridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,OAAO,WAAW;IACtB,OAAO,CAA+B;IAEtC;;OAEG;IACH,kBAAkB,CAAC,UAAkB;QACnC,IAAI,CAAC;YACH,MAAM,KAAK,GAAe,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACjD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACjB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,sDAAsD;YAEtD,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,GAAoB,EAAE,SAAwB,MAAM;QACxE,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,cAAc,CACnB,IAAW,EACX,MAA0B,EAC1B,SAAkB,EAClB,IAAc;QAEd,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,IAAI,EAAE,UAAU;YAChB,YAAY,EAAE,IAAI;YAClB,MAAM;YACN,SAAS;YACT,IAAI;SACL,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ export function setupCounter(element) {
2
+ let counter = 0;
3
+ const setCounter = (count) => {
4
+ counter = count;
5
+ element.innerHTML = `count is ${counter}`;
6
+ };
7
+ element.addEventListener('click', () => setCounter(counter + 1));
8
+ setCounter(0);
9
+ }