c64-ready 2.4.0 → 3.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 +32 -0
- package/bin/admin.mjs +7 -1
- package/bin/headless.mjs +1 -1
- package/dist/assets/BeachHead-CuSwFD4k.js +1 -0
- package/dist/assets/ChuckieEgg-CPqBnAOF.js +1 -0
- package/dist/assets/ForbiddenForest-DsQ9jsc8.js +1 -0
- package/dist/assets/Galaga-Cutc3p9s.js +1 -0
- package/dist/assets/Gribbly-DdZ_hHFt.js +1 -0
- package/dist/assets/Hercules-vZYKm7GG.js +1 -0
- package/dist/assets/LegendOfWilf-CxSMOjsj.js +1 -0
- package/dist/assets/MariosCementFactory-z0IZ0q30.js +1 -0
- package/dist/assets/MoleAttack-buC6ChYy.js +1 -0
- package/dist/assets/MunchyWorm-D2Zv7i0Q.js +1 -0
- package/dist/assets/ParkPatrol-CVj7hyoB.js +1 -0
- package/dist/assets/PottyPigeon-0SYpIUBa.js +1 -0
- package/dist/assets/RainbowIslands-BjfmJB8z.js +1 -0
- package/dist/assets/Stix-BU-qUCeC.js +1 -0
- package/dist/assets/Tilt-C5KtKisF.js +1 -0
- package/dist/assets/UpNDown-CATRO7Mz.js +1 -0
- package/dist/assets/Uridium-DanS2KoH.js +1 -0
- package/dist/assets/VegetablesDeluxe-C41ViimS.js +1 -0
- package/dist/assets/index-B8DSjPqI.js +243 -0
- package/dist/assets/src-DX0rJQsE.js +1 -0
- package/dist/assets/src-_trgwTvp.js +2 -0
- package/dist/assets/string-utils-CMVABfx0.js +1 -0
- package/dist/index.html +1 -1
- package/dist-ts/emulator/c64-keys.d.ts +69 -0
- package/dist-ts/emulator/c64-keys.d.ts.map +1 -0
- package/dist-ts/emulator/c64-keys.js +69 -0
- package/dist-ts/emulator/c64-keys.js.map +1 -0
- package/dist-ts/emulator/gamepad-mapping.d.ts +64 -0
- package/dist-ts/emulator/gamepad-mapping.d.ts.map +1 -0
- package/dist-ts/emulator/gamepad-mapping.js +154 -0
- package/dist-ts/emulator/gamepad-mapping.js.map +1 -0
- package/dist-ts/emulator/input.d.ts +24 -75
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +93 -214
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/player/c64-player.d.ts +25 -0
- package/dist-ts/player/c64-player.d.ts.map +1 -1
- package/dist-ts/player/c64-player.js +77 -1
- package/dist-ts/player/c64-player.js.map +1 -1
- package/dist-ts/player/cheevos-dev.d.ts +65 -0
- package/dist-ts/player/cheevos-dev.d.ts.map +1 -0
- package/dist-ts/player/cheevos-dev.js +237 -0
- package/dist-ts/player/cheevos-dev.js.map +1 -0
- package/dist-ts/player/cheevos-tracker-panel.d.ts +21 -0
- package/dist-ts/player/cheevos-tracker-panel.d.ts.map +1 -0
- package/dist-ts/player/cheevos-tracker-panel.js +242 -0
- package/dist-ts/player/cheevos-tracker-panel.js.map +1 -0
- package/dist-ts/player/index.d.ts +3 -0
- package/dist-ts/player/index.d.ts.map +1 -1
- package/dist-ts/player/index.js +2 -0
- package/dist-ts/player/index.js.map +1 -1
- package/dist-ts/player/input-handler.d.ts +12 -1
- package/dist-ts/player/input-handler.d.ts.map +1 -1
- package/dist-ts/player/input-handler.js +46 -1
- package/dist-ts/player/input-handler.js.map +1 -1
- package/dist-ts/player/local-rom-store.d.ts +23 -0
- package/dist-ts/player/local-rom-store.d.ts.map +1 -0
- package/dist-ts/player/local-rom-store.js +87 -0
- package/dist-ts/player/local-rom-store.js.map +1 -0
- package/dist-ts/player/startup-params.d.ts +7 -0
- package/dist-ts/player/startup-params.d.ts.map +1 -0
- package/dist-ts/player/startup-params.js +47 -0
- package/dist-ts/player/startup-params.js.map +1 -0
- package/dist-ts/player/ui-controller.d.ts +22 -0
- package/dist-ts/player/ui-controller.d.ts.map +1 -1
- package/dist-ts/player/ui-controller.js +666 -1
- package/dist-ts/player/ui-controller.js.map +1 -1
- package/package.json +2 -1
- package/src/emulator/c64-keys.ts +68 -0
- package/src/emulator/gamepad-mapping.ts +212 -0
- package/src/emulator/input.ts +106 -209
- package/src/headless/headless-cli.mjs +10 -4
- package/src/headless/input-server.mjs +92 -17
- package/src/headless/webrtc-server.mjs +344 -22
- package/src/main.ts +177 -12
- package/src/player/c64-player.ts +96 -1
- package/src/player/cheevos-dev.ts +340 -0
- package/src/player/cheevos-tracker-panel.ts +309 -0
- package/src/player/index.ts +19 -0
- package/src/player/input-handler.ts +63 -1
- package/src/player/local-rom-store.ts +126 -0
- package/src/player/startup-params.ts +40 -0
- package/src/player/ui-controller.ts +741 -0
- package/src/types/c64-cheevos.d.ts +6 -0
- package/dist/assets/index-Dxuihfdi.js +0 -177
- /package/dist/assets/{marked.esm--kBm026b.js → marked.esm-fTuuvbcB.js} +0 -0
- /package/dist/assets/{purify.es-BcoGFDcJ.js → purify.es-CRM-GE0Y.js} +0 -0
package/src/main.ts
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { C64Player } from './player/c64-player';
|
|
2
2
|
import CanvasRenderer from './player/canvas-renderer';
|
|
3
3
|
import UIController from './player/ui-controller';
|
|
4
|
+
import CheevosDevController, { parseCheevosSetJson } from './player/cheevos-dev';
|
|
5
|
+
import type { CheevosDevSet } from './player/cheevos-dev';
|
|
6
|
+
import CheevosTrackerPanel from './player/cheevos-tracker-panel';
|
|
4
7
|
import { inferLoadTypeFromFilename, isSupportedLoadType } from './player/load-formats';
|
|
8
|
+
import {
|
|
9
|
+
getCheevosRomPath,
|
|
10
|
+
getCheevosRomType,
|
|
11
|
+
getStoredCheevosRom,
|
|
12
|
+
} from './player/local-rom-store';
|
|
13
|
+
import {
|
|
14
|
+
resolveGameFromParam,
|
|
15
|
+
resolveUrlFromParam,
|
|
16
|
+
shouldDisableDefaultGameForCheevos,
|
|
17
|
+
} from './player/startup-params';
|
|
5
18
|
|
|
6
19
|
const status = document.getElementById('status')!;
|
|
7
20
|
const renderer = new CanvasRenderer('c64-screen');
|
|
8
21
|
const base = import.meta.env.BASE_URL;
|
|
9
22
|
const params = new URLSearchParams(window.location.search);
|
|
10
23
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (!value) return `${baseUrl}games/cartridges/legend-of-wilf.crt`;
|
|
15
|
-
if (value.toLowerCase() === 'null') return '';
|
|
16
|
-
if (/^https?:\/\//i.test(value)) return value;
|
|
17
|
-
if (value.startsWith('/')) return value;
|
|
18
|
-
return `${baseUrl}${value.replace(/^\/+/, '')}`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const gameUrl = resolveGameFromParam(params.get('game'), base);
|
|
24
|
+
const gameUrl = resolveGameFromParam(params.get('game'), base, {
|
|
25
|
+
disableDefault: shouldDisableDefaultGameForCheevos(params),
|
|
26
|
+
});
|
|
22
27
|
const gameType = inferLoadTypeFromFilename(gameUrl || '') ?? 'crt';
|
|
23
28
|
|
|
24
29
|
// Create player and keep in outer scope so UI can trigger file loads
|
|
@@ -30,18 +35,22 @@ const player = new C64Player({
|
|
|
30
35
|
audio: { assetBaseUrl: base },
|
|
31
36
|
onProgress: (pct, label) => renderer.setProgress(pct, label),
|
|
32
37
|
});
|
|
38
|
+
const cheevosDev = new CheevosDevController(player);
|
|
39
|
+
const cheevosTrackerPanel = new CheevosTrackerPanel();
|
|
40
|
+
cheevosTrackerPanel.init();
|
|
33
41
|
|
|
34
42
|
// Initialise UI with reference to the player (for audio controls)
|
|
35
43
|
new UIController({ assetBaseUrl: base }).init(player);
|
|
36
44
|
|
|
37
45
|
player
|
|
38
46
|
.start()
|
|
39
|
-
.then(() => {
|
|
47
|
+
.then(async () => {
|
|
40
48
|
if (!gameUrl) {
|
|
41
49
|
status.textContent = 'Autoload disabled (?game=null)';
|
|
42
50
|
status.style.color = '#9ecbff';
|
|
43
51
|
}
|
|
44
52
|
renderer.hideLoader();
|
|
53
|
+
await enableCheevosFromParams();
|
|
45
54
|
})
|
|
46
55
|
.catch((err) => {
|
|
47
56
|
console.error(err);
|
|
@@ -122,6 +131,61 @@ window.addEventListener('c64-load-tool', async (e: Event) => {
|
|
|
122
131
|
}
|
|
123
132
|
});
|
|
124
133
|
|
|
134
|
+
window.addEventListener('c64-cheevos-enable', async (e: Event) => {
|
|
135
|
+
const detail = (e as CustomEvent<{ detectorId?: string; jsonText?: string }>).detail;
|
|
136
|
+
const detectorId = detail?.detectorId?.trim() ?? '';
|
|
137
|
+
if (!detectorId) return;
|
|
138
|
+
try {
|
|
139
|
+
if (detail?.jsonText?.trim()) {
|
|
140
|
+
const cheevosSet = parseCheevosSetJson(detail.jsonText);
|
|
141
|
+
await cheevosDev.enable(detectorId, cheevosSet);
|
|
142
|
+
await loadCheevosRomFromSet(cheevosSet);
|
|
143
|
+
} else {
|
|
144
|
+
await cheevosDev.enable(detectorId);
|
|
145
|
+
}
|
|
146
|
+
} catch (err) {
|
|
147
|
+
const msg = normalizeErrorMessage(String((err as Error)?.message ?? err));
|
|
148
|
+
window.dispatchEvent(
|
|
149
|
+
new CustomEvent('c64-cheevos-error', { detail: { detectorId, error: msg } }),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
window.addEventListener('c64-cheevos-rom-file', async (e: Event) => {
|
|
155
|
+
const detail = (e as CustomEvent<{ file?: File; type?: string; romPath?: string }>).detail;
|
|
156
|
+
const file = detail?.file;
|
|
157
|
+
if (!file) return;
|
|
158
|
+
const loadType = isSupportedLoadType(detail?.type) ? detail.type : undefined;
|
|
159
|
+
try {
|
|
160
|
+
status.textContent = `Loading cheevos ROM: ${detail?.romPath ?? file.name}`;
|
|
161
|
+
status.style.color = '#9ecbff';
|
|
162
|
+
renderer.showLoader();
|
|
163
|
+
await player.loadFile(file, loadType);
|
|
164
|
+
renderer.hideLoader();
|
|
165
|
+
} catch (err) {
|
|
166
|
+
console.error(err);
|
|
167
|
+
renderer.setError('LOAD ERROR');
|
|
168
|
+
status.textContent = `Cheevos ROM load error: ${normalizeErrorMessage(String(err))}`;
|
|
169
|
+
status.style.color = '#f44';
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
window.addEventListener('c64-cheevos-disable', () => {
|
|
174
|
+
cheevosDev.disable();
|
|
175
|
+
status.textContent = 'Cheevos dev tracking disabled';
|
|
176
|
+
status.style.color = '#9ecbff';
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
window.addEventListener('c64-cheevos-clear-popped', (e: Event) => {
|
|
180
|
+
const detail = (e as CustomEvent<{ detectorId?: string }>).detail;
|
|
181
|
+
cheevosDev.clearPopped(detail?.detectorId);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
window.addEventListener('c64-cheevos-clear-scores', (e: Event) => {
|
|
185
|
+
const detail = (e as CustomEvent<{ detectorId?: string }>).detail;
|
|
186
|
+
cheevosDev.clearScores(detail?.detectorId);
|
|
187
|
+
});
|
|
188
|
+
|
|
125
189
|
// Global listener for load errors dispatched by C64Player
|
|
126
190
|
window.addEventListener('c64-load-error', (e: Event) => {
|
|
127
191
|
const detail = (e as CustomEvent).detail as
|
|
@@ -144,6 +208,45 @@ window.addEventListener('c64-load-info', (e: Event) => {
|
|
|
144
208
|
console.info('C64 load info event:', detail);
|
|
145
209
|
});
|
|
146
210
|
|
|
211
|
+
window.addEventListener('c64-cheevos-status', (e: Event) => {
|
|
212
|
+
const detail = (e as CustomEvent<{ detectorId?: string; status?: string; cheevosCount?: number }>)
|
|
213
|
+
.detail;
|
|
214
|
+
if (detail?.status !== 'enabled') return;
|
|
215
|
+
status.textContent = `Cheevos tracking enabled: ${detail.detectorId ?? 'unknown'} (${detail.cheevosCount ?? 0} achievements)`;
|
|
216
|
+
status.style.color = '#9ecbff';
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
window.addEventListener('c64-cheevos-error', (e: Event) => {
|
|
220
|
+
const detail = (e as CustomEvent<{ detectorId?: string; error?: string }>).detail;
|
|
221
|
+
status.textContent = `Cheevos error${detail?.detectorId ? ` (${detail.detectorId})` : ''}: ${detail?.error ?? 'Unknown error'}`;
|
|
222
|
+
status.style.color = '#f44';
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
window.addEventListener('c64-cheevos-score', (e: Event) => {
|
|
226
|
+
const detail = (e as CustomEvent<{ detectorId?: string; score?: { score?: number } }>).detail;
|
|
227
|
+
status.textContent = `Cheevos score captured${detail?.detectorId ? ` for ${detail.detectorId}` : ''}: ${detail?.score?.score ?? 0}`;
|
|
228
|
+
status.style.color = '#9ecbff';
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
window.addEventListener('c64-cheevos-event', (e: Event) => {
|
|
232
|
+
const detail = (
|
|
233
|
+
e as CustomEvent<{
|
|
234
|
+
detectorId?: string;
|
|
235
|
+
type?: string;
|
|
236
|
+
payload?: { title?: string; message?: string; score?: number };
|
|
237
|
+
}>
|
|
238
|
+
).detail;
|
|
239
|
+
if (!detail?.type) return;
|
|
240
|
+
if (detail.type === 'cheevo') {
|
|
241
|
+
status.textContent = `${detail.payload?.title ?? 'Achievement'}: ${detail.payload?.message ?? 'Unlocked'}`;
|
|
242
|
+
} else if (detail.type === 'gameOver') {
|
|
243
|
+
status.textContent = `Game over${detail.detectorId ? ` (${detail.detectorId})` : ''}: ${detail.payload?.score ?? 0}`;
|
|
244
|
+
} else {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
status.style.color = '#9ecbff';
|
|
248
|
+
});
|
|
249
|
+
|
|
147
250
|
window.addEventListener('c64-reboot', () => {
|
|
148
251
|
status.textContent = 'Emulator rebooted. Load a cartridge to continue.';
|
|
149
252
|
status.style.color = '#9ecbff';
|
|
@@ -157,3 +260,65 @@ function normalizeErrorMessage(msg: string): string {
|
|
|
157
260
|
}
|
|
158
261
|
return out || 'Unknown load error';
|
|
159
262
|
}
|
|
263
|
+
|
|
264
|
+
async function enableCheevosFromParams(): Promise<void> {
|
|
265
|
+
const detectorId = params.get('cheevos')?.trim();
|
|
266
|
+
if (!detectorId) return;
|
|
267
|
+
|
|
268
|
+
const cheevosSetUrl = resolveUrlFromParam(params.get('cheevosSet'), base);
|
|
269
|
+
try {
|
|
270
|
+
if (cheevosSetUrl) {
|
|
271
|
+
const res = await fetch(cheevosSetUrl, { cache: 'no-store' });
|
|
272
|
+
if (!res.ok) throw new Error(`Failed to fetch cheevos set: ${res.status}`);
|
|
273
|
+
const jsonText = await res.text();
|
|
274
|
+
window.dispatchEvent(
|
|
275
|
+
new CustomEvent('c64-cheevos-json-loaded', {
|
|
276
|
+
detail: { jsonText, source: cheevosSetUrl },
|
|
277
|
+
}),
|
|
278
|
+
);
|
|
279
|
+
const cheevosSet = parseCheevosSetJson(jsonText);
|
|
280
|
+
await cheevosDev.enable(detectorId, cheevosSet);
|
|
281
|
+
await loadCheevosRomFromSet(cheevosSet);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
await cheevosDev.enable(detectorId);
|
|
285
|
+
} catch (err) {
|
|
286
|
+
const msg = normalizeErrorMessage(String((err as Error)?.message ?? err));
|
|
287
|
+
window.dispatchEvent(
|
|
288
|
+
new CustomEvent('c64-cheevos-error', { detail: { detectorId, error: msg } }),
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async function loadCheevosRomFromSet(cheevosSet: CheevosDevSet): Promise<void> {
|
|
294
|
+
const romPath = getCheevosRomPath(cheevosSet);
|
|
295
|
+
if (!romPath) return;
|
|
296
|
+
|
|
297
|
+
const type = getCheevosRomType(cheevosSet);
|
|
298
|
+
try {
|
|
299
|
+
const rom = await getStoredCheevosRom(romPath, type);
|
|
300
|
+
if (!rom) {
|
|
301
|
+
requestCheevosRomFile(romPath, type, 'Choose local ROM file');
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
status.textContent = `Loading cheevos ROM: ${romPath}`;
|
|
305
|
+
status.style.color = '#9ecbff';
|
|
306
|
+
renderer.showLoader();
|
|
307
|
+
await player.loadFile(rom.file, rom.type);
|
|
308
|
+
renderer.hideLoader();
|
|
309
|
+
} catch (err) {
|
|
310
|
+
requestCheevosRomFile(
|
|
311
|
+
romPath,
|
|
312
|
+
type,
|
|
313
|
+
`Unable to auto-load ROM (${normalizeErrorMessage(String((err as Error)?.message ?? err))})`,
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function requestCheevosRomFile(romPath: string, type: string | undefined, reason: string): void {
|
|
319
|
+
window.dispatchEvent(
|
|
320
|
+
new CustomEvent('c64-cheevos-rom-needed', { detail: { romPath, type, reason } }),
|
|
321
|
+
);
|
|
322
|
+
status.textContent = `${reason}: ${romPath}`;
|
|
323
|
+
status.style.color = '#f9c74f';
|
|
324
|
+
}
|
package/src/player/c64-player.ts
CHANGED
|
@@ -3,6 +3,12 @@ import { getUnsupportedCrtReason, parseCrtInfo } from '../emulator/crt-info';
|
|
|
3
3
|
import type { GameLoadOptions } from '../types';
|
|
4
4
|
import type { JoystickPort } from '../emulator/constants';
|
|
5
5
|
import type { InputMode, KeyboardJoystickMap } from '../emulator/input';
|
|
6
|
+
import {
|
|
7
|
+
resolveGamepadMapping,
|
|
8
|
+
type GamepadMapping,
|
|
9
|
+
type GamepadState,
|
|
10
|
+
type ResolvedGamepadMapping,
|
|
11
|
+
} from '../emulator/gamepad-mapping';
|
|
6
12
|
import type CanvasRenderer from './canvas-renderer';
|
|
7
13
|
import { AudioEngine, type AudioEngineOptions } from './audio-engine';
|
|
8
14
|
import InputHandler from './input-handler';
|
|
@@ -17,6 +23,9 @@ const PRG_AUTORUN_DELAY_MS = 650;
|
|
|
17
23
|
const DISK_AUTOLOAD_DELAY_MS = 1500;
|
|
18
24
|
const DISK_AUTOLOAD_RETURN_DELAY_MS = 250;
|
|
19
25
|
const PRG_AUTORUN_BUFFER_TIMEOUT_MS = 2000;
|
|
26
|
+
const NORMAL_DEBUG_SPEED = 100;
|
|
27
|
+
const FAST_FORWARD_STEP = 100;
|
|
28
|
+
const MAX_DEBUG_SPEED = 300;
|
|
20
29
|
|
|
21
30
|
export interface C64PlayerOptions {
|
|
22
31
|
wasmUrl: string;
|
|
@@ -32,11 +41,14 @@ export interface C64PlayerOptions {
|
|
|
32
41
|
export class C64Player {
|
|
33
42
|
private emulator: C64Emulator | null = null;
|
|
34
43
|
private inputHandler: InputHandler | null = null;
|
|
44
|
+
// Kept here so a mapping set before start() (or across restarts) still applies
|
|
45
|
+
private gamepadMapping: GamepadMapping | null = null;
|
|
35
46
|
private disableCrtPreloadChecks: boolean = false;
|
|
36
47
|
private destroyed: boolean = false;
|
|
37
48
|
private diskSessionActive: boolean = false;
|
|
38
49
|
private startupLoadInProgress: boolean = false;
|
|
39
50
|
private startupDiskAutoloadPending: boolean = false;
|
|
51
|
+
private debugSpeed: number = NORMAL_DEBUG_SPEED;
|
|
40
52
|
readonly audio: AudioEngine;
|
|
41
53
|
private readonly options: Required<Pick<C64PlayerOptions, 'wasmUrl' | 'gameUrl' | 'gameType'>> &
|
|
42
54
|
C64PlayerOptions;
|
|
@@ -53,6 +65,7 @@ export class C64Player {
|
|
|
53
65
|
onProgress?.(10, 'INITIALISING WASM...');
|
|
54
66
|
this.emulator = await C64Emulator.load(wasmUrl);
|
|
55
67
|
this.emulator.setCrtPreloadChecksEnabled(!this.disableCrtPreloadChecks);
|
|
68
|
+
this.applyDebugSpeed();
|
|
56
69
|
this.attachInputAndRenderer(this.emulator, renderer);
|
|
57
70
|
let shouldAutoRunPrgAfterStart = false;
|
|
58
71
|
|
|
@@ -250,6 +263,7 @@ export class C64Player {
|
|
|
250
263
|
this.diskSessionActive = false;
|
|
251
264
|
this.startupDiskAutoloadPending = false;
|
|
252
265
|
this.emulator.setSampleRate(this.audio.sampleRate);
|
|
266
|
+
this.applyDebugSpeed();
|
|
253
267
|
this.audio.setSidBufferReader(() => this.emulator?.getSidBuffer() ?? null);
|
|
254
268
|
window.dispatchEvent(new CustomEvent('c64-reboot', { detail: {} }));
|
|
255
269
|
window.dispatchEvent(new CustomEvent('c64-close-menu'));
|
|
@@ -300,6 +314,33 @@ export class C64Player {
|
|
|
300
314
|
this.inputHandler?.setInputMode(mode);
|
|
301
315
|
}
|
|
302
316
|
|
|
317
|
+
/** Set emulator speed in 100% increments, clamped from normal speed through 10x. */
|
|
318
|
+
setFastForwardSpeed(speed: number): number {
|
|
319
|
+
const nextSpeed = clampDebugSpeed(speed);
|
|
320
|
+
if (nextSpeed === this.debugSpeed) return this.debugSpeed;
|
|
321
|
+
|
|
322
|
+
this.debugSpeed = nextSpeed;
|
|
323
|
+
this.applyDebugSpeed();
|
|
324
|
+
this.notifyDebugSpeedChanged();
|
|
325
|
+
return this.debugSpeed;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
incrementFastForwardSpeed(): number {
|
|
329
|
+
return this.setFastForwardSpeed(this.debugSpeed + FAST_FORWARD_STEP);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
decrementFastForwardSpeed(): number {
|
|
333
|
+
return this.setFastForwardSpeed(this.debugSpeed - FAST_FORWARD_STEP);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
resetFastForwardSpeed(): number {
|
|
337
|
+
return this.setFastForwardSpeed(NORMAL_DEBUG_SPEED);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
getFastForwardSpeed(): number {
|
|
341
|
+
return this.debugSpeed;
|
|
342
|
+
}
|
|
343
|
+
|
|
303
344
|
setActiveGamepadIndex(index: number): void {
|
|
304
345
|
this.inputHandler?.setActiveGamepadIndex(index);
|
|
305
346
|
}
|
|
@@ -308,6 +349,29 @@ export class C64Player {
|
|
|
308
349
|
return this.inputHandler?.getActiveGamepadIndex() ?? -1;
|
|
309
350
|
}
|
|
310
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Remaps the gamepad for the current game: the stick mode ('8way' | '4way' | '2way') and the
|
|
354
|
+
* joystick input or C64 key (C64_KEY) for each direction and for A, B, X, Y, LB, RB, LT, RT.
|
|
355
|
+
* Unlisted controls keep their defaults; null restores all defaults. Start stays RUN/STOP.
|
|
356
|
+
* Can be called before start().
|
|
357
|
+
*/
|
|
358
|
+
setGamepadMapping(mapping: GamepadMapping | null): void {
|
|
359
|
+
this.gamepadMapping = mapping;
|
|
360
|
+
this.inputHandler?.setGamepadMapping(mapping);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
getGamepadMapping(): ResolvedGamepadMapping {
|
|
364
|
+
return this.inputHandler?.getGamepadMapping() ?? resolveGamepadMapping(this.gamepadMapping);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Feeds a virtual gamepad, such as on-screen touch controls: the controls held on it go through
|
|
369
|
+
* the same mapping as a physical gamepad.
|
|
370
|
+
*/
|
|
371
|
+
setVirtualGamepadState(state: GamepadState): void {
|
|
372
|
+
this.inputHandler?.setVirtualGamepadState(state);
|
|
373
|
+
}
|
|
374
|
+
|
|
311
375
|
getSnapshot(): Uint8Array<ArrayBufferLike> {
|
|
312
376
|
if (!this.emulator) {
|
|
313
377
|
throw new Error('Emulator not initialised');
|
|
@@ -327,6 +391,10 @@ export class C64Player {
|
|
|
327
391
|
return this.emulator?.cpuReadNS(addr) ?? 0;
|
|
328
392
|
}
|
|
329
393
|
|
|
394
|
+
cpuWrite(addr: number, v: number): void {
|
|
395
|
+
this.emulator?.cpuWrite(addr, v);
|
|
396
|
+
}
|
|
397
|
+
|
|
330
398
|
setVoiceEnabled(voice: number, enabled: boolean): void {
|
|
331
399
|
this.emulator?.setVoiceEnabled(voice, enabled);
|
|
332
400
|
}
|
|
@@ -472,11 +540,32 @@ export class C64Player {
|
|
|
472
540
|
|
|
473
541
|
private attachInputAndRenderer(emulator: C64Emulator, renderer: CanvasRenderer): void {
|
|
474
542
|
this.inputHandler?.detach();
|
|
475
|
-
this.inputHandler = new InputHandler(emulator
|
|
543
|
+
this.inputHandler = new InputHandler(emulator, window, {
|
|
544
|
+
onFastForwardIncrease: () => this.incrementFastForwardSpeed(),
|
|
545
|
+
onFastForwardDecrease: () => this.decrementFastForwardSpeed(),
|
|
546
|
+
onFastForwardReset: () => this.resetFastForwardSpeed(),
|
|
547
|
+
});
|
|
476
548
|
this.inputHandler.attach();
|
|
549
|
+
this.inputHandler.setGamepadMapping(this.gamepadMapping);
|
|
477
550
|
renderer.attachTo(emulator);
|
|
478
551
|
}
|
|
479
552
|
|
|
553
|
+
private applyDebugSpeed(): void {
|
|
554
|
+
this.emulator?.setDebugSpeed(this.debugSpeed);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
private notifyDebugSpeedChanged(): void {
|
|
558
|
+
const message =
|
|
559
|
+
this.debugSpeed === NORMAL_DEBUG_SPEED
|
|
560
|
+
? 'Fast-forward: normal speed'
|
|
561
|
+
: `Fast-forward: ${this.debugSpeed / NORMAL_DEBUG_SPEED}x`;
|
|
562
|
+
window.dispatchEvent(
|
|
563
|
+
new CustomEvent('c64-load-info', {
|
|
564
|
+
detail: { mode: 'info', source: 'keyboard', message },
|
|
565
|
+
}),
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
|
|
480
569
|
private handleCrtPreloadChecks(
|
|
481
570
|
data: Uint8Array<ArrayBufferLike>,
|
|
482
571
|
source: string,
|
|
@@ -543,6 +632,12 @@ function waitMs(ms: number): Promise<void> {
|
|
|
543
632
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
544
633
|
}
|
|
545
634
|
|
|
635
|
+
function clampDebugSpeed(speed: number): number {
|
|
636
|
+
if (!Number.isFinite(speed)) return NORMAL_DEBUG_SPEED;
|
|
637
|
+
const steppedSpeed = Math.round(speed / FAST_FORWARD_STEP) * FAST_FORWARD_STEP;
|
|
638
|
+
return Math.max(NORMAL_DEBUG_SPEED, Math.min(MAX_DEBUG_SPEED, steppedSpeed));
|
|
639
|
+
}
|
|
640
|
+
|
|
546
641
|
function normaliseKeyboardBufferText(text: string): number[] {
|
|
547
642
|
const bytes: number[] = [];
|
|
548
643
|
const normalised = text.toUpperCase().replace(/\r\n/g, '\n');
|