c64-ready 1.0.0 → 1.1.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 +70 -62
- package/bin/headless.mjs +1 -1
- package/dist/assets/{CHANGELOG-CPlXKLCV.js → CHANGELOG-0a7A8Ekq.js} +113 -1
- package/dist/assets/index-BESofQoh.js +627 -0
- package/dist/games/cartridges/goat-beat.crt +0 -0
- package/dist/index.html +1 -1
- package/dist-ts/emulator/c64-emulator.d.ts +3 -0
- package/dist-ts/emulator/c64-emulator.d.ts.map +1 -1
- package/dist-ts/emulator/c64-emulator.js +36 -4
- package/dist-ts/emulator/c64-emulator.js.map +1 -1
- package/dist-ts/emulator/crt-info.d.ts +61 -0
- package/dist-ts/emulator/crt-info.d.ts.map +1 -0
- package/dist-ts/emulator/crt-info.js +190 -0
- package/dist-ts/emulator/crt-info.js.map +1 -0
- package/dist-ts/emulator/input.d.ts +96 -0
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +549 -4
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/headless/c64-headless.d.ts +1 -0
- package/dist-ts/headless/c64-headless.d.ts.map +1 -1
- package/dist-ts/headless/c64-headless.js +5 -0
- package/dist-ts/headless/c64-headless.js.map +1 -1
- package/dist-ts/types/emulator.d.ts +2 -1
- package/dist-ts/types/emulator.d.ts.map +1 -1
- package/package.json +1 -1
- package/public/games/cartridges/goat-beat.crt +0 -0
- package/src/emulator/c64-emulator.ts +37 -7
- package/src/emulator/crt-info.ts +35 -23
- package/src/emulator/input.ts +239 -19
- package/src/headless/c64-headless.ts +5 -0
- package/src/headless/headless-cli.mjs +462 -249
- package/src/headless/input-server.mjs +649 -278
- package/src/headless/webrtc-server.mjs +218 -71
- package/src/main.ts +30 -4
- package/src/player/c64-player.ts +121 -40
- package/src/player/input-handler.ts +8 -0
- package/src/player/styles/ui-controller.css +103 -21
- package/src/player/ui-controller.ts +186 -23
- package/src/types/emulator.ts +1 -1
- package/dist/assets/index-Ckbi7gQo.js +0 -535
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emulator.d.ts","sourceRoot":"","sources":["../../src/types/emulator.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC;IAG3B,iBAAiB,IAAI,IAAI,CAAC;IAC1B,QAAQ,IAAI,IAAI,CAAC;IACjB,SAAS,IAAI,IAAI,CAAC;IAClB,QAAQ,IAAI,IAAI,CAAC;IACjB,UAAU,IAAI,IAAI,CAAC;IAGnB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,YAAY,IAAI,MAAM,CAAC;IAGvB,kBAAkB,IAAI,MAAM,CAAC;IAC7B,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnE,cAAc,IAAI,MAAM,CAAC;IACzB,cAAc,IAAI,MAAM,CAAC;IACzB,eAAe,IAAI,MAAM,CAAC;IAG1B,kBAAkB,IAAI,MAAM,CAAC;IAC7B,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACzC,cAAc,IAAI,MAAM,CAAC;IACzB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3C,4BAA4B,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACpD,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAG3C,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IA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E,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClE,sBAAsB,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,4BAA4B,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/D,wBAAwB,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAG1C,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,IAAI,MAAM,CAAC;IACpB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACjC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7C,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,gBAAgB,IAAI,MAAM,CAAC;CAC5B"}
|
package/package.json
CHANGED
|
Binary file
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { C64WASM } from './c64-wasm';
|
|
15
|
+
import { getUnsupportedCrtReason, parseCrtInfo } from './crt-info';
|
|
15
16
|
import type { C64Config, FrameBuffer, AudioBuffer, GameLoadOptions, InputEvent } from '../types';
|
|
16
17
|
import type { JoystickPort, JoystickInput } from './constants';
|
|
17
18
|
|
|
@@ -21,17 +22,20 @@ const DEFAULT_SAMPLE_RATE = 44100;
|
|
|
21
22
|
|
|
22
23
|
export class C64Emulator {
|
|
23
24
|
private wasm: C64WASM;
|
|
25
|
+
private readonly wasmUrl: string;
|
|
24
26
|
private config: C64Config;
|
|
25
27
|
private running: boolean = false;
|
|
26
28
|
private frameCount: number = 0;
|
|
29
|
+
private crtPreloadChecksEnabled: boolean = true;
|
|
27
30
|
|
|
28
31
|
/** Called every tick with the latest video frame */
|
|
29
32
|
onFrame?: (frame: FrameBuffer) => void;
|
|
30
33
|
/** Called every tick with the latest audio samples */
|
|
31
34
|
onAudio?: (audio: AudioBuffer) => void;
|
|
32
35
|
|
|
33
|
-
private constructor(wasm: C64WASM, config: Partial<C64Config> = {}) {
|
|
36
|
+
private constructor(wasm: C64WASM, wasmUrl: string, config: Partial<C64Config> = {}) {
|
|
34
37
|
this.wasm = wasm;
|
|
38
|
+
this.wasmUrl = wasmUrl;
|
|
35
39
|
this.config = {
|
|
36
40
|
videoWidth: FRAME_WIDTH,
|
|
37
41
|
videoHeight: FRAME_HEIGHT,
|
|
@@ -57,7 +61,7 @@ export class C64Emulator {
|
|
|
57
61
|
config: Partial<C64Config> = {},
|
|
58
62
|
): Promise<C64Emulator> {
|
|
59
63
|
const wasm = await C64WASM.load(wasmUrl);
|
|
60
|
-
const emulator = new C64Emulator(wasm, config);
|
|
64
|
+
const emulator = new C64Emulator(wasm, wasmUrl, config);
|
|
61
65
|
emulator.init();
|
|
62
66
|
return emulator;
|
|
63
67
|
}
|
|
@@ -99,6 +103,24 @@ export class C64Emulator {
|
|
|
99
103
|
this.frameCount = 0;
|
|
100
104
|
}
|
|
101
105
|
|
|
106
|
+
async reboot(): Promise<void> {
|
|
107
|
+
const wasRunning = this.running;
|
|
108
|
+
const nextWasm = await C64WASM.load(this.wasmUrl);
|
|
109
|
+
|
|
110
|
+
this.running = false;
|
|
111
|
+
this.wasm = nextWasm;
|
|
112
|
+
this.frameCount = 0;
|
|
113
|
+
this.init();
|
|
114
|
+
|
|
115
|
+
if (wasRunning) {
|
|
116
|
+
this.start();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setCrtPreloadChecksEnabled(enabled: boolean): void {
|
|
121
|
+
this.crtPreloadChecksEnabled = enabled;
|
|
122
|
+
}
|
|
123
|
+
|
|
102
124
|
// ---------------------------------------------------------------------------
|
|
103
125
|
// Frame loop — call once per animation frame (requestAnimationFrame)
|
|
104
126
|
// ---------------------------------------------------------------------------
|
|
@@ -150,6 +172,16 @@ export class C64Emulator {
|
|
|
150
172
|
x.c64_insertDisk(ptr, options.data.length);
|
|
151
173
|
break;
|
|
152
174
|
case 'crt':
|
|
175
|
+
if (this.crtPreloadChecksEnabled) {
|
|
176
|
+
const info = parseCrtInfo(options.data);
|
|
177
|
+
if (!info) {
|
|
178
|
+
throw new Error('Invalid CRT file format');
|
|
179
|
+
}
|
|
180
|
+
const unsupportedReason = getUnsupportedCrtReason(info);
|
|
181
|
+
if (unsupportedReason) {
|
|
182
|
+
throw new Error(unsupportedReason);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
153
185
|
x.c64_loadCartridge(ptr, options.data.length);
|
|
154
186
|
break;
|
|
155
187
|
case 'snapshot':
|
|
@@ -286,17 +318,15 @@ export class C64Emulator {
|
|
|
286
318
|
getSnapshot(): Uint8Array {
|
|
287
319
|
const x = this.wasm.exports;
|
|
288
320
|
if (!x || !this.wasm.heap) throw new Error('WASM not ready');
|
|
321
|
+
const ptr = x.c64_getSnapshot();
|
|
289
322
|
const size = x.c64_getSnapshotSize();
|
|
290
|
-
|
|
291
|
-
x.c64_getSnapshot(ptr);
|
|
292
|
-
const snap = this.wasm.heap.heapU8.slice(ptr, ptr + size);
|
|
293
|
-
x.free(ptr);
|
|
294
|
-
return snap;
|
|
323
|
+
return this.wasm.heap.heapU8.slice(ptr, ptr + size);
|
|
295
324
|
}
|
|
296
325
|
|
|
297
326
|
private loadSnapshotData(ptr: number, len: number): void {
|
|
298
327
|
const x = this.wasm.exports;
|
|
299
328
|
if (!x) throw new Error('WASM not ready');
|
|
329
|
+
x.c64_reset();
|
|
300
330
|
x.c64_loadSnapshot(ptr, len);
|
|
301
331
|
this.frameCount = 0;
|
|
302
332
|
}
|
package/src/emulator/crt-info.ts
CHANGED
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
|
|
30
30
|
/** Subset of well-known hardware type names (matches VICE source). */
|
|
31
31
|
export const CRT_HW_TYPES: Record<number, string> = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
0: 'Normal cartridge',
|
|
33
|
+
1: 'Action Replay',
|
|
34
|
+
2: 'KCS Power Cartridge',
|
|
35
|
+
3: 'Final Cartridge III',
|
|
36
|
+
4: 'Simons BASIC',
|
|
37
|
+
5: 'Ocean type 1',
|
|
38
|
+
6: 'Expert Cartridge',
|
|
39
|
+
7: 'Fun Play, Power Play',
|
|
40
|
+
8: 'Super Games',
|
|
41
|
+
9: 'Atomic Power',
|
|
42
42
|
10: 'Epyx Fastload',
|
|
43
43
|
11: 'Westermann Learning',
|
|
44
44
|
12: 'Rex Utility',
|
|
@@ -131,12 +131,25 @@ export interface CrtInfo {
|
|
|
131
131
|
totalRomBytes: number;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
export function isUltimaxCrt(info: CrtInfo): boolean {
|
|
135
|
+
return info.exrom === 1 && info.game === 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getUnsupportedCrtReason(info: CrtInfo): string | null {
|
|
139
|
+
if (isUltimaxCrt(info) && info.hwType === 0) {
|
|
140
|
+
return 'Unsupported CRT: Ultimax/MAX cartridges are not supported by this emulator.';
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
134
145
|
function readU32BE(buf: Uint8Array, offset: number): number {
|
|
135
|
-
return (
|
|
146
|
+
return (
|
|
147
|
+
((buf[offset] << 24) | (buf[offset + 1] << 16) | (buf[offset + 2] << 8) | buf[offset + 3]) >>> 0
|
|
148
|
+
);
|
|
136
149
|
}
|
|
137
150
|
|
|
138
151
|
function readU16BE(buf: Uint8Array, offset: number): number {
|
|
139
|
-
return ((
|
|
152
|
+
return ((buf[offset] << 8) | buf[offset + 1]) >>> 0;
|
|
140
153
|
}
|
|
141
154
|
|
|
142
155
|
/**
|
|
@@ -155,9 +168,9 @@ export function parseCrtInfo(data: Uint8Array, filename?: string): CrtInfo | nul
|
|
|
155
168
|
if (!magic.startsWith('C64 CARTRIDGE')) return null;
|
|
156
169
|
|
|
157
170
|
const headerLen = readU32BE(data, 0x10); // typically 0x40
|
|
158
|
-
const hwType
|
|
159
|
-
const exrom
|
|
160
|
-
const game
|
|
171
|
+
const hwType = readU16BE(data, 0x16);
|
|
172
|
+
const exrom = data[0x18];
|
|
173
|
+
const game = data[0x19];
|
|
161
174
|
|
|
162
175
|
// Cart name: null-terminated ASCII at 0x20, up to 32 bytes
|
|
163
176
|
let cartName = '';
|
|
@@ -172,13 +185,13 @@ export function parseCrtInfo(data: Uint8Array, filename?: string): CrtInfo | nul
|
|
|
172
185
|
// exrom=1 game=0 → Ultimax
|
|
173
186
|
// exrom=1 game=1 → inactive (pass-through)
|
|
174
187
|
let bankConfig: string;
|
|
175
|
-
if
|
|
188
|
+
if (exrom === 0 && game === 0) bankConfig = '16K (ROML+ROMH)';
|
|
176
189
|
else if (exrom === 0 && game === 1) bankConfig = '8K (ROML only)';
|
|
177
190
|
else if (exrom === 1 && game === 0) bankConfig = 'Ultimax';
|
|
178
|
-
else
|
|
191
|
+
else bankConfig = 'inactive (pass-through)';
|
|
179
192
|
|
|
180
193
|
// Walk CHIP packets to count them and sum up actual ROM data bytes
|
|
181
|
-
let chipCount
|
|
194
|
+
let chipCount = 0;
|
|
182
195
|
let totalRomBytes = 0;
|
|
183
196
|
let offset = Math.max(headerLen, 0x40);
|
|
184
197
|
|
|
@@ -189,16 +202,16 @@ export function parseCrtInfo(data: Uint8Array, filename?: string): CrtInfo | nul
|
|
|
189
202
|
const packetLen = readU32BE(data, offset + 4);
|
|
190
203
|
if (packetLen < 16) break; // malformed packet
|
|
191
204
|
|
|
192
|
-
const dataSize = readU16BE(data, offset +
|
|
205
|
+
const dataSize = readU16BE(data, offset + 0x0e);
|
|
193
206
|
chipCount++;
|
|
194
207
|
totalRomBytes += dataSize;
|
|
195
208
|
offset += packetLen;
|
|
196
209
|
}
|
|
197
210
|
|
|
198
|
-
const hwName
|
|
211
|
+
const hwName = CRT_HW_TYPES[hwType] ?? `Unknown(${hwType})`;
|
|
199
212
|
const fileLabel = filename ? ` "${filename}"` : '';
|
|
200
|
-
const namePart
|
|
201
|
-
const kbActual
|
|
213
|
+
const namePart = cartName ? ` name="${cartName}"` : '';
|
|
214
|
+
const kbActual = (totalRomBytes / 1024).toFixed(0);
|
|
202
215
|
|
|
203
216
|
const line =
|
|
204
217
|
`[C64 cart]${fileLabel} loading: hwType=${hwType}(${hwName})` +
|
|
@@ -207,4 +220,3 @@ export function parseCrtInfo(data: Uint8Array, filename?: string): CrtInfo | nul
|
|
|
207
220
|
|
|
208
221
|
return { line, hwType, hwName, exrom, game, bankConfig, cartName, chipCount, totalRomBytes };
|
|
209
222
|
}
|
|
210
|
-
|
package/src/emulator/input.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import type {C64Emulator} from './c64-emulator';
|
|
2
|
+
import {JOYSTICK_DIRECTION, JOYSTICK_FIRE_1, JOYSTICK_PORT_2, type JoystickInput} from './constants'
|
|
3
|
+
import type {JoystickPort} from './constants';
|
|
4
4
|
|
|
5
5
|
export const KEY_TO_JOYSTICK = {
|
|
6
6
|
ArrowUp: JOYSTICK_DIRECTION.UP,
|
|
@@ -132,9 +132,9 @@ export function domKeyToC64Actions(
|
|
|
132
132
|
const isDown = eventType === 'keydown';
|
|
133
133
|
const actions: C64KeyAction[] = [];
|
|
134
134
|
|
|
135
|
-
const press = (idx: number) => actions.push({
|
|
136
|
-
const release = (idx: number) => actions.push({
|
|
137
|
-
const main = (idx: number) => actions.push({
|
|
135
|
+
const press = (idx: number) => actions.push({key: idx, action: 'press'});
|
|
136
|
+
const release = (idx: number) => actions.push({key: idx, action: 'release'});
|
|
137
|
+
const main = (idx: number) => actions.push({key: idx, action: isDown ? 'press' : 'release'});
|
|
138
138
|
|
|
139
139
|
// Handle host shift state first for plain alpha/numeric keys
|
|
140
140
|
if (isDown) {
|
|
@@ -474,7 +474,6 @@ export function domKeyToC64Actions(
|
|
|
474
474
|
default:
|
|
475
475
|
break;
|
|
476
476
|
}
|
|
477
|
-
|
|
478
477
|
return actions;
|
|
479
478
|
}
|
|
480
479
|
|
|
@@ -484,8 +483,12 @@ export class EmulatorInput {
|
|
|
484
483
|
private readonly emulator: C64Emulator;
|
|
485
484
|
private readonly target: EventTarget;
|
|
486
485
|
// Which joystick port keyboard events map to (1 or 2). Default is port 2.
|
|
487
|
-
private
|
|
486
|
+
private joystickPort: JoystickPort;
|
|
488
487
|
private inputMode: InputMode = 'mixed';
|
|
488
|
+
private updateFrame: number = -1;
|
|
489
|
+
private gamepadIndex: number = -1;
|
|
490
|
+
private gamepadPresses: Array<boolean> = [];
|
|
491
|
+
private gamepadAxes: Array<boolean> = [false, false, false, false];
|
|
489
492
|
private readonly pressedControls = new Set<MappedControl>();
|
|
490
493
|
private readonly keyDownHandler = (event: KeyboardEvent): void => {
|
|
491
494
|
this.handleKeyDown(event);
|
|
@@ -493,6 +496,12 @@ export class EmulatorInput {
|
|
|
493
496
|
private readonly keyUpHandler = (event: KeyboardEvent): void => {
|
|
494
497
|
this.handleKeyUp(event);
|
|
495
498
|
};
|
|
499
|
+
private readonly gamepadConnectedHandler = (event: Event): void => {
|
|
500
|
+
this.handleGamepadConnected(event as GamepadEvent);
|
|
501
|
+
};
|
|
502
|
+
private readonly gamepadDisconnectedHandler = (event: Event): void => {
|
|
503
|
+
this.handleGamepadDisconnected(event as GamepadEvent);
|
|
504
|
+
};
|
|
496
505
|
|
|
497
506
|
constructor(
|
|
498
507
|
emulator: C64Emulator,
|
|
@@ -501,18 +510,207 @@ export class EmulatorInput {
|
|
|
501
510
|
) {
|
|
502
511
|
this.emulator = emulator;
|
|
503
512
|
this.target = target;
|
|
504
|
-
this.
|
|
513
|
+
this.joystickPort = defaultPort;
|
|
505
514
|
}
|
|
506
515
|
|
|
507
516
|
attach(): void {
|
|
517
|
+
this.target.addEventListener('gamepadconnected', this.gamepadConnectedHandler as EventListener);
|
|
518
|
+
this.target.addEventListener('gamepaddisconnected', this.gamepadDisconnectedHandler as EventListener);
|
|
508
519
|
this.target.addEventListener('keydown', this.keyDownHandler as EventListener);
|
|
509
520
|
this.target.addEventListener('keyup', this.keyUpHandler as EventListener);
|
|
510
521
|
}
|
|
511
522
|
|
|
512
523
|
detach(): void {
|
|
524
|
+
this.target.removeEventListener('gamepadconnected', this.gamepadConnectedHandler as EventListener);
|
|
525
|
+
this.target.removeEventListener('gamepaddisconnected', this.gamepadDisconnectedHandler as EventListener);
|
|
513
526
|
this.target.removeEventListener('keydown', this.keyDownHandler as EventListener);
|
|
514
527
|
this.target.removeEventListener('keyup', this.keyUpHandler as EventListener);
|
|
515
528
|
this.releaseAll();
|
|
529
|
+
this.releaseAllGamepadButtons();
|
|
530
|
+
this.cancelUpdate();
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
private step(): void {
|
|
534
|
+
const gamepads = navigator.getGamepads();
|
|
535
|
+
if (!gamepads) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
const gp = gamepads[this.gamepadIndex];
|
|
539
|
+
if (!gp) {
|
|
540
|
+
this.cancelUpdate();
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
if (gp.buttons) {
|
|
544
|
+
for (let b = 0; b < gp.buttons.length; b++) {
|
|
545
|
+
if (gp.buttons[b].pressed) {
|
|
546
|
+
this.gamepadPresses[b] = true;
|
|
547
|
+
// console.log('Buttons Pressed', b, gp.buttons[b]);
|
|
548
|
+
switch (b) {
|
|
549
|
+
case 0:
|
|
550
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_FIRE_1);
|
|
551
|
+
break;
|
|
552
|
+
case 14:
|
|
553
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.LEFT);
|
|
554
|
+
break;
|
|
555
|
+
case 15:
|
|
556
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.RIGHT);
|
|
557
|
+
break;
|
|
558
|
+
case 12:
|
|
559
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.UP);
|
|
560
|
+
break;
|
|
561
|
+
case 13:
|
|
562
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.DOWN);
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
// this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.UP);
|
|
566
|
+
} else if (!gp.buttons[b].pressed && this.gamepadPresses[b] === true) {
|
|
567
|
+
this.gamepadPresses[b] = false;
|
|
568
|
+
switch (b) {
|
|
569
|
+
case 0:
|
|
570
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_FIRE_1);
|
|
571
|
+
break;
|
|
572
|
+
case 14:
|
|
573
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.LEFT);
|
|
574
|
+
break;
|
|
575
|
+
case 15:
|
|
576
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.RIGHT);
|
|
577
|
+
break;
|
|
578
|
+
case 12:
|
|
579
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.UP);
|
|
580
|
+
break;
|
|
581
|
+
case 13:
|
|
582
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.DOWN);
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
// this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.UP);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
if (gp.axes[0] <= -0.5) {
|
|
591
|
+
this.gamepadAxes[0] = true;
|
|
592
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.LEFT);
|
|
593
|
+
} else if (this.gamepadAxes[0] === true) {
|
|
594
|
+
this.gamepadAxes[0] = false;
|
|
595
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.LEFT);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
if (gp.axes[0] >= 0.5) {
|
|
599
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.RIGHT);
|
|
600
|
+
this.gamepadAxes[1] = true;
|
|
601
|
+
} else if (this.gamepadAxes[1] === true) {
|
|
602
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.RIGHT);
|
|
603
|
+
this.gamepadAxes[1] = false;
|
|
604
|
+
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
if (gp.axes[1] <= -0.5) {
|
|
608
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.UP);
|
|
609
|
+
this.gamepadAxes[2] = true
|
|
610
|
+
} else if (this.gamepadAxes[2] === true) {
|
|
611
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.UP);
|
|
612
|
+
this.gamepadAxes[2] = false
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (gp.axes[1] >= 0.5) {
|
|
616
|
+
this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.DOWN);
|
|
617
|
+
this.gamepadAxes[3] = true;
|
|
618
|
+
} else if (this.gamepadAxes[3] === true) {
|
|
619
|
+
this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.DOWN);
|
|
620
|
+
this.gamepadAxes[3] = false;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
this.updateFrame = requestAnimationFrame(this.step.bind(this));
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
private cancelUpdate(): void {
|
|
627
|
+
cancelAnimationFrame(this.updateFrame);
|
|
628
|
+
this.updateFrame = -1;
|
|
629
|
+
this.gamepadIndex = -1;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
private releaseAllGamepadButtons(): void {
|
|
633
|
+
if (!this.gamepadPresses.some(Boolean)) return;
|
|
634
|
+
|
|
635
|
+
const buttonToInput: Partial<Record<number, JoystickInput>> = {
|
|
636
|
+
0: JOYSTICK_FIRE_1,
|
|
637
|
+
12: JOYSTICK_DIRECTION.UP,
|
|
638
|
+
13: JOYSTICK_DIRECTION.DOWN,
|
|
639
|
+
14: JOYSTICK_DIRECTION.LEFT,
|
|
640
|
+
15: JOYSTICK_DIRECTION.RIGHT,
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
for (const [button, input] of Object.entries(buttonToInput)) {
|
|
644
|
+
if (!input) continue;
|
|
645
|
+
if (this.gamepadPresses[Number(button)] === true) {
|
|
646
|
+
this.emulator.joystickRelease(this.joystickPort, input);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
this.gamepadPresses = [];
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
private findConnectedGamepadIndex(excludeIndex?: number): number {
|
|
654
|
+
const gamepads = navigator.getGamepads?.() ?? [];
|
|
655
|
+
for (const gamepad of gamepads) {
|
|
656
|
+
if (!gamepad) continue;
|
|
657
|
+
if (gamepad.index === excludeIndex) continue;
|
|
658
|
+
return gamepad.index;
|
|
659
|
+
}
|
|
660
|
+
return -1;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
private handleGamepadDisconnected(event: GamepadEvent): void {
|
|
664
|
+
console.log(
|
|
665
|
+
"Gamepad disconnected from index %d: %s",
|
|
666
|
+
event.gamepad.index,
|
|
667
|
+
event.gamepad.id,
|
|
668
|
+
);
|
|
669
|
+
const wasActive = this.gamepadIndex === event.gamepad.index;
|
|
670
|
+
if (wasActive) {
|
|
671
|
+
this.releaseAllGamepadButtons();
|
|
672
|
+
const fallbackIndex = this.findConnectedGamepadIndex(event.gamepad.index);
|
|
673
|
+
if (fallbackIndex >= 0) {
|
|
674
|
+
this.gamepadIndex = fallbackIndex;
|
|
675
|
+
if (this.updateFrame < 0) {
|
|
676
|
+
this.step();
|
|
677
|
+
}
|
|
678
|
+
} else {
|
|
679
|
+
this.cancelUpdate();
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const gamepadDisconnected = new CustomEvent('c64-controller-disconnected', {
|
|
684
|
+
detail: {
|
|
685
|
+
name: event.gamepad.id,
|
|
686
|
+
index: event.gamepad.index,
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
this.target.dispatchEvent(gamepadDisconnected);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
private handleGamepadConnected(event: GamepadEvent): void {
|
|
693
|
+
console.log(
|
|
694
|
+
"Gamepad connected at index %d: %s. %d buttons, %d axes.",
|
|
695
|
+
event.gamepad.index,
|
|
696
|
+
event.gamepad.id,
|
|
697
|
+
event.gamepad.buttons.length,
|
|
698
|
+
event.gamepad.axes.length,
|
|
699
|
+
);
|
|
700
|
+
if (this.gamepadIndex < 0) {
|
|
701
|
+
this.gamepadIndex = event.gamepad.index;
|
|
702
|
+
}
|
|
703
|
+
const gamepadConnected = new CustomEvent('c64-controller-connected', {
|
|
704
|
+
detail: {
|
|
705
|
+
name: event.gamepad.id,
|
|
706
|
+
index: event.gamepad.index,
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
this.target.dispatchEvent(gamepadConnected);
|
|
711
|
+
if (this.updateFrame < 0) {
|
|
712
|
+
this.step();
|
|
713
|
+
}
|
|
516
714
|
}
|
|
517
715
|
|
|
518
716
|
private handleKeyDown(event: KeyboardEvent): void {
|
|
@@ -534,10 +732,10 @@ export class EmulatorInput {
|
|
|
534
732
|
// all other keys route to the C64 keyboard matrix.
|
|
535
733
|
if (event.code in MIXED_JOYSTICK_KEYS) {
|
|
536
734
|
// Joystick path
|
|
537
|
-
const dir = MIXED_JOYSTICK_KEYS[event.code];
|
|
735
|
+
const dir = MIXED_JOYSTICK_KEYS[event.code] as JoystickInput;
|
|
538
736
|
this.emulator.joystickPush(
|
|
539
|
-
this.
|
|
540
|
-
dir
|
|
737
|
+
this.joystickPort,
|
|
738
|
+
dir,
|
|
541
739
|
);
|
|
542
740
|
event.preventDefault();
|
|
543
741
|
} else {
|
|
@@ -561,7 +759,7 @@ export class EmulatorInput {
|
|
|
561
759
|
return;
|
|
562
760
|
}
|
|
563
761
|
this.pressedControls.add(control);
|
|
564
|
-
this.emulator.joystickPush(this.
|
|
762
|
+
this.emulator.joystickPush(this.joystickPort, KEY_TO_JOYSTICK[control]);
|
|
565
763
|
event.preventDefault();
|
|
566
764
|
}
|
|
567
765
|
|
|
@@ -582,8 +780,8 @@ export class EmulatorInput {
|
|
|
582
780
|
if (event.code in MIXED_JOYSTICK_KEYS) {
|
|
583
781
|
const dir = MIXED_JOYSTICK_KEYS[event.code];
|
|
584
782
|
this.emulator.joystickRelease(
|
|
585
|
-
this.
|
|
586
|
-
dir as
|
|
783
|
+
this.joystickPort,
|
|
784
|
+
dir as JoystickInput,
|
|
587
785
|
);
|
|
588
786
|
event.preventDefault();
|
|
589
787
|
} else {
|
|
@@ -605,7 +803,7 @@ export class EmulatorInput {
|
|
|
605
803
|
return;
|
|
606
804
|
}
|
|
607
805
|
this.pressedControls.delete(control);
|
|
608
|
-
this.emulator.joystickRelease(this.
|
|
806
|
+
this.emulator.joystickRelease(this.joystickPort, KEY_TO_JOYSTICK[control]);
|
|
609
807
|
event.preventDefault();
|
|
610
808
|
}
|
|
611
809
|
|
|
@@ -618,26 +816,48 @@ export class EmulatorInput {
|
|
|
618
816
|
|
|
619
817
|
private releaseAll(): void {
|
|
620
818
|
for (const control of this.pressedControls) {
|
|
621
|
-
this.emulator.joystickRelease(this.
|
|
819
|
+
this.emulator.joystickRelease(this.joystickPort, KEY_TO_JOYSTICK[control]);
|
|
622
820
|
}
|
|
623
821
|
this.pressedControls.clear();
|
|
624
822
|
}
|
|
625
823
|
|
|
626
824
|
/** Set which joystick port keyboard controls should target (1 or 2). */
|
|
627
825
|
setKeyboardPort(port: JoystickPort): void {
|
|
628
|
-
if (this.
|
|
826
|
+
if (this.joystickPort === port) return;
|
|
629
827
|
this.releaseAll();
|
|
630
|
-
this.
|
|
828
|
+
this.releaseAllGamepadButtons();
|
|
829
|
+
this.joystickPort = port;
|
|
631
830
|
}
|
|
632
831
|
|
|
633
832
|
/** Set the input mode. Releases any held joystick buttons on mode change. */
|
|
634
833
|
setInputMode(mode: InputMode): void {
|
|
635
834
|
if (this.inputMode === mode) return;
|
|
636
835
|
this.releaseAll();
|
|
836
|
+
this.releaseAllGamepadButtons();
|
|
637
837
|
this.inputMode = mode;
|
|
638
838
|
}
|
|
639
839
|
|
|
640
840
|
getInputMode(): InputMode {
|
|
641
841
|
return this.inputMode;
|
|
642
842
|
}
|
|
843
|
+
|
|
844
|
+
setActiveGamepadIndex(index: number): void {
|
|
845
|
+
if (this.gamepadIndex === index) return;
|
|
846
|
+
|
|
847
|
+
const gamepads = navigator.getGamepads?.() ?? [];
|
|
848
|
+
const nextGamepad = gamepads[index];
|
|
849
|
+
if (!nextGamepad) {
|
|
850
|
+
throw new Error(`Gamepad ${index} is not connected`);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
this.releaseAllGamepadButtons();
|
|
854
|
+
this.gamepadIndex = index;
|
|
855
|
+
if (this.updateFrame < 0) {
|
|
856
|
+
this.step();
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
getActiveGamepadIndex(): number {
|
|
861
|
+
return this.gamepadIndex;
|
|
862
|
+
}
|
|
643
863
|
}
|
|
@@ -42,6 +42,11 @@ export class C64Headless {
|
|
|
42
42
|
this.emulator.loadGame(options);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
async reboot(): Promise<void> {
|
|
46
|
+
if (!this.emulator) throw new Error('Emulator not initialised — call init() first');
|
|
47
|
+
await this.emulator.reboot();
|
|
48
|
+
}
|
|
49
|
+
|
|
45
50
|
/**
|
|
46
51
|
* Run a single emulation tick/frame and return the captured latest frame/audio.
|
|
47
52
|
* This will start the emulator if it was not running, and restore the previous
|