c64-ready 2.5.0 → 3.2.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 +52 -1
- package/bin/admin.mjs +7 -1
- package/bin/agent.mjs +18 -0
- 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-emulator.d.ts +2 -2
- package/dist-ts/emulator/c64-emulator.js +2 -2
- 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/c64-wasm.d.ts +1 -1
- 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 +27 -78
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +94 -215
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/headless/audio-capture.d.ts +1 -1
- package/dist-ts/headless/c64-headless.d.ts +2 -2
- package/dist-ts/headless/c64-headless.js +4 -4
- package/dist-ts/headless/frame-capture.d.ts +1 -1
- package/dist-ts/headless/input-bridge.d.ts +1 -1
- package/dist-ts/player/c64-player.d.ts +21 -5
- package/dist-ts/player/c64-player.d.ts.map +1 -1
- package/dist-ts/player/c64-player.js +32 -5
- package/dist-ts/player/c64-player.js.map +1 -1
- package/dist-ts/player/canvas-renderer.d.ts +2 -2
- 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 +10 -7
- package/dist-ts/player/index.d.ts.map +1 -1
- package/dist-ts/player/index.js +6 -4
- package/dist-ts/player/index.js.map +1 -1
- package/dist-ts/player/input-handler.d.ts +7 -3
- package/dist-ts/player/input-handler.d.ts.map +1 -1
- package/dist-ts/player/input-handler.js +24 -1
- package/dist-ts/player/input-handler.js.map +1 -1
- package/dist-ts/player/load-formats.d.ts +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 +23 -1
- package/dist-ts/player/ui-controller.d.ts.map +1 -1
- package/dist-ts/player/ui-controller.js +665 -1
- package/dist-ts/player/ui-controller.js.map +1 -1
- package/package.json +11 -4
- 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/agent-cli.mjs +825 -0
- package/src/headless/headless-cli.mjs +10 -4
- package/src/headless/input-server.mjs +92 -17
- package/src/headless/png.mjs +72 -0
- package/src/headless/webrtc-server.mjs +458 -34
- package/src/main.ts +197 -12
- package/src/player/c64-player.ts +58 -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 +32 -0
- package/src/player/local-rom-store.ts +126 -0
- package/src/player/startup-params.ts +40 -0
- package/src/player/ui-controller.ts +751 -0
- package/src/player/ultimate-bridge.ts +161 -0
- package/src/player/ultimate-panel.ts +315 -0
- package/src/types/c64-cheevos.d.ts +6 -0
- package/dist/assets/index-BAsZcXuS.js +0 -178
- /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
|
|
@@ -129,21 +193,80 @@ window.addEventListener('c64-load-error', (e: Event) => {
|
|
|
129
193
|
| undefined;
|
|
130
194
|
const msg = normalizeErrorMessage(detail?.error ?? 'Unknown load error');
|
|
131
195
|
console.error('C64 load error event:', detail);
|
|
196
|
+
loadWarningShown = false;
|
|
132
197
|
renderer.setError('LOAD ERROR');
|
|
133
198
|
status.textContent = `Load error: ${msg}`;
|
|
134
199
|
status.style.color = '#f44';
|
|
135
200
|
});
|
|
136
201
|
|
|
202
|
+
// Set while a load-time warning is on screen so the success message doesn't hide it
|
|
203
|
+
let loadWarningShown = false;
|
|
204
|
+
|
|
205
|
+
window.addEventListener('c64-load-success', (e: Event) => {
|
|
206
|
+
const detail = (e as CustomEvent<{ name?: string }>).detail;
|
|
207
|
+
if (loadWarningShown) {
|
|
208
|
+
loadWarningShown = false;
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
status.textContent = `Loaded: ${detail?.name ?? 'game'}`;
|
|
212
|
+
status.style.color = '#9ecbff';
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
window.addEventListener('c64-detach', () => {
|
|
216
|
+
status.textContent = 'Cartridge detached (no game loaded)';
|
|
217
|
+
status.style.color = '#9ecbff';
|
|
218
|
+
});
|
|
219
|
+
|
|
137
220
|
window.addEventListener('c64-load-info', (e: Event) => {
|
|
138
221
|
const detail = (e as CustomEvent).detail as
|
|
139
222
|
| { mode?: string; source?: string; message?: string }
|
|
140
223
|
| undefined;
|
|
141
224
|
if (!detail?.message) return;
|
|
225
|
+
loadWarningShown = detail.mode === 'warning';
|
|
142
226
|
status.textContent = detail.message;
|
|
143
227
|
status.style.color = detail.mode === 'warning' ? '#f9c74f' : '#9ecbff';
|
|
144
228
|
console.info('C64 load info event:', detail);
|
|
145
229
|
});
|
|
146
230
|
|
|
231
|
+
window.addEventListener('c64-cheevos-status', (e: Event) => {
|
|
232
|
+
const detail = (e as CustomEvent<{ detectorId?: string; status?: string; cheevosCount?: number }>)
|
|
233
|
+
.detail;
|
|
234
|
+
if (detail?.status !== 'enabled') return;
|
|
235
|
+
status.textContent = `Cheevos tracking enabled: ${detail.detectorId ?? 'unknown'} (${detail.cheevosCount ?? 0} achievements)`;
|
|
236
|
+
status.style.color = '#9ecbff';
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
window.addEventListener('c64-cheevos-error', (e: Event) => {
|
|
240
|
+
const detail = (e as CustomEvent<{ detectorId?: string; error?: string }>).detail;
|
|
241
|
+
status.textContent = `Cheevos error${detail?.detectorId ? ` (${detail.detectorId})` : ''}: ${detail?.error ?? 'Unknown error'}`;
|
|
242
|
+
status.style.color = '#f44';
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
window.addEventListener('c64-cheevos-score', (e: Event) => {
|
|
246
|
+
const detail = (e as CustomEvent<{ detectorId?: string; score?: { score?: number } }>).detail;
|
|
247
|
+
status.textContent = `Cheevos score captured${detail?.detectorId ? ` for ${detail.detectorId}` : ''}: ${detail?.score?.score ?? 0}`;
|
|
248
|
+
status.style.color = '#9ecbff';
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
window.addEventListener('c64-cheevos-event', (e: Event) => {
|
|
252
|
+
const detail = (
|
|
253
|
+
e as CustomEvent<{
|
|
254
|
+
detectorId?: string;
|
|
255
|
+
type?: string;
|
|
256
|
+
payload?: { title?: string; message?: string; score?: number };
|
|
257
|
+
}>
|
|
258
|
+
).detail;
|
|
259
|
+
if (!detail?.type) return;
|
|
260
|
+
if (detail.type === 'cheevo') {
|
|
261
|
+
status.textContent = `${detail.payload?.title ?? 'Achievement'}: ${detail.payload?.message ?? 'Unlocked'}`;
|
|
262
|
+
} else if (detail.type === 'gameOver') {
|
|
263
|
+
status.textContent = `Game over${detail.detectorId ? ` (${detail.detectorId})` : ''}: ${detail.payload?.score ?? 0}`;
|
|
264
|
+
} else {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
status.style.color = '#9ecbff';
|
|
268
|
+
});
|
|
269
|
+
|
|
147
270
|
window.addEventListener('c64-reboot', () => {
|
|
148
271
|
status.textContent = 'Emulator rebooted. Load a cartridge to continue.';
|
|
149
272
|
status.style.color = '#9ecbff';
|
|
@@ -157,3 +280,65 @@ function normalizeErrorMessage(msg: string): string {
|
|
|
157
280
|
}
|
|
158
281
|
return out || 'Unknown load error';
|
|
159
282
|
}
|
|
283
|
+
|
|
284
|
+
async function enableCheevosFromParams(): Promise<void> {
|
|
285
|
+
const detectorId = params.get('cheevos')?.trim();
|
|
286
|
+
if (!detectorId) return;
|
|
287
|
+
|
|
288
|
+
const cheevosSetUrl = resolveUrlFromParam(params.get('cheevosSet'), base);
|
|
289
|
+
try {
|
|
290
|
+
if (cheevosSetUrl) {
|
|
291
|
+
const res = await fetch(cheevosSetUrl, { cache: 'no-store' });
|
|
292
|
+
if (!res.ok) throw new Error(`Failed to fetch cheevos set: ${res.status}`);
|
|
293
|
+
const jsonText = await res.text();
|
|
294
|
+
window.dispatchEvent(
|
|
295
|
+
new CustomEvent('c64-cheevos-json-loaded', {
|
|
296
|
+
detail: { jsonText, source: cheevosSetUrl },
|
|
297
|
+
}),
|
|
298
|
+
);
|
|
299
|
+
const cheevosSet = parseCheevosSetJson(jsonText);
|
|
300
|
+
await cheevosDev.enable(detectorId, cheevosSet);
|
|
301
|
+
await loadCheevosRomFromSet(cheevosSet);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
await cheevosDev.enable(detectorId);
|
|
305
|
+
} catch (err) {
|
|
306
|
+
const msg = normalizeErrorMessage(String((err as Error)?.message ?? err));
|
|
307
|
+
window.dispatchEvent(
|
|
308
|
+
new CustomEvent('c64-cheevos-error', { detail: { detectorId, error: msg } }),
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async function loadCheevosRomFromSet(cheevosSet: CheevosDevSet): Promise<void> {
|
|
314
|
+
const romPath = getCheevosRomPath(cheevosSet);
|
|
315
|
+
if (!romPath) return;
|
|
316
|
+
|
|
317
|
+
const type = getCheevosRomType(cheevosSet);
|
|
318
|
+
try {
|
|
319
|
+
const rom = await getStoredCheevosRom(romPath, type);
|
|
320
|
+
if (!rom) {
|
|
321
|
+
requestCheevosRomFile(romPath, type, 'Choose local ROM file');
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
status.textContent = `Loading cheevos ROM: ${romPath}`;
|
|
325
|
+
status.style.color = '#9ecbff';
|
|
326
|
+
renderer.showLoader();
|
|
327
|
+
await player.loadFile(rom.file, rom.type);
|
|
328
|
+
renderer.hideLoader();
|
|
329
|
+
} catch (err) {
|
|
330
|
+
requestCheevosRomFile(
|
|
331
|
+
romPath,
|
|
332
|
+
type,
|
|
333
|
+
`Unable to auto-load ROM (${normalizeErrorMessage(String((err as Error)?.message ?? err))})`,
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function requestCheevosRomFile(romPath: string, type: string | undefined, reason: string): void {
|
|
339
|
+
window.dispatchEvent(
|
|
340
|
+
new CustomEvent('c64-cheevos-rom-needed', { detail: { romPath, type, reason } }),
|
|
341
|
+
);
|
|
342
|
+
status.textContent = `${reason}: ${romPath}`;
|
|
343
|
+
status.style.color = '#f9c74f';
|
|
344
|
+
}
|
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';
|
|
@@ -32,15 +38,24 @@ export interface C64PlayerOptions {
|
|
|
32
38
|
audio?: AudioEngineOptions;
|
|
33
39
|
}
|
|
34
40
|
|
|
41
|
+
export interface LoadedGame {
|
|
42
|
+
name: string;
|
|
43
|
+
type: GameLoadOptions['type'];
|
|
44
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
45
|
+
}
|
|
46
|
+
|
|
35
47
|
export class C64Player {
|
|
36
48
|
private emulator: C64Emulator | null = null;
|
|
37
49
|
private inputHandler: InputHandler | null = null;
|
|
50
|
+
// Kept here so a mapping set before start() (or across restarts) still applies
|
|
51
|
+
private gamepadMapping: GamepadMapping | null = null;
|
|
38
52
|
private disableCrtPreloadChecks: boolean = false;
|
|
39
53
|
private destroyed: boolean = false;
|
|
40
54
|
private diskSessionActive: boolean = false;
|
|
41
55
|
private startupLoadInProgress: boolean = false;
|
|
42
56
|
private startupDiskAutoloadPending: boolean = false;
|
|
43
57
|
private debugSpeed: number = NORMAL_DEBUG_SPEED;
|
|
58
|
+
private currentGame: LoadedGame | null = null;
|
|
44
59
|
readonly audio: AudioEngine;
|
|
45
60
|
private readonly options: Required<Pick<C64PlayerOptions, 'wasmUrl' | 'gameUrl' | 'gameType'>> &
|
|
46
61
|
C64PlayerOptions;
|
|
@@ -219,6 +234,11 @@ export class C64Player {
|
|
|
219
234
|
await this.loadGame(url, resolvedType, onProgress);
|
|
220
235
|
}
|
|
221
236
|
|
|
237
|
+
/** The most recently loaded game, or null after a detach/reboot. */
|
|
238
|
+
getCurrentGame(): LoadedGame | null {
|
|
239
|
+
return this.currentGame;
|
|
240
|
+
}
|
|
241
|
+
|
|
222
242
|
// Expose cartridge / reset controls for UI
|
|
223
243
|
detachCartridge(): void {
|
|
224
244
|
if (!this.emulator) return;
|
|
@@ -226,6 +246,7 @@ export class C64Player {
|
|
|
226
246
|
this.emulator.removeCartridge();
|
|
227
247
|
this.diskSessionActive = false;
|
|
228
248
|
this.startupDiskAutoloadPending = false;
|
|
249
|
+
this.currentGame = null;
|
|
229
250
|
window.dispatchEvent(new CustomEvent('c64-detach', { detail: {} }));
|
|
230
251
|
window.dispatchEvent(new CustomEvent('c64-close-menu'));
|
|
231
252
|
} catch (e) {
|
|
@@ -254,6 +275,7 @@ export class C64Player {
|
|
|
254
275
|
this.emulator.start();
|
|
255
276
|
this.diskSessionActive = false;
|
|
256
277
|
this.startupDiskAutoloadPending = false;
|
|
278
|
+
this.currentGame = null;
|
|
257
279
|
this.emulator.setSampleRate(this.audio.sampleRate);
|
|
258
280
|
this.applyDebugSpeed();
|
|
259
281
|
this.audio.setSidBufferReader(() => this.emulator?.getSidBuffer() ?? null);
|
|
@@ -341,6 +363,29 @@ export class C64Player {
|
|
|
341
363
|
return this.inputHandler?.getActiveGamepadIndex() ?? -1;
|
|
342
364
|
}
|
|
343
365
|
|
|
366
|
+
/**
|
|
367
|
+
* Remaps the gamepad for the current game: the stick mode ('8way' | '4way' | '2way') and the
|
|
368
|
+
* joystick input or C64 key (C64_KEY) for each direction and for A, B, X, Y, LB, RB, LT, RT.
|
|
369
|
+
* Unlisted controls keep their defaults; null restores all defaults. Start stays RUN/STOP.
|
|
370
|
+
* Can be called before start().
|
|
371
|
+
*/
|
|
372
|
+
setGamepadMapping(mapping: GamepadMapping | null): void {
|
|
373
|
+
this.gamepadMapping = mapping;
|
|
374
|
+
this.inputHandler?.setGamepadMapping(mapping);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
getGamepadMapping(): ResolvedGamepadMapping {
|
|
378
|
+
return this.inputHandler?.getGamepadMapping() ?? resolveGamepadMapping(this.gamepadMapping);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Feeds a virtual gamepad, such as on-screen touch controls: the controls held on it go through
|
|
383
|
+
* the same mapping as a physical gamepad.
|
|
384
|
+
*/
|
|
385
|
+
setVirtualGamepadState(state: GamepadState): void {
|
|
386
|
+
this.inputHandler?.setVirtualGamepadState(state);
|
|
387
|
+
}
|
|
388
|
+
|
|
344
389
|
getSnapshot(): Uint8Array<ArrayBufferLike> {
|
|
345
390
|
if (!this.emulator) {
|
|
346
391
|
throw new Error('Emulator not initialised');
|
|
@@ -360,6 +405,10 @@ export class C64Player {
|
|
|
360
405
|
return this.emulator?.cpuReadNS(addr) ?? 0;
|
|
361
406
|
}
|
|
362
407
|
|
|
408
|
+
cpuWrite(addr: number, v: number): void {
|
|
409
|
+
this.emulator?.cpuWrite(addr, v);
|
|
410
|
+
}
|
|
411
|
+
|
|
363
412
|
setVoiceEnabled(voice: number, enabled: boolean): void {
|
|
364
413
|
this.emulator?.setVoiceEnabled(voice, enabled);
|
|
365
414
|
}
|
|
@@ -453,9 +502,11 @@ export class C64Player {
|
|
|
453
502
|
} else {
|
|
454
503
|
this.diskSessionActive = false;
|
|
455
504
|
}
|
|
505
|
+
const name = getSourceName(source);
|
|
506
|
+
this.currentGame = { name, type, data };
|
|
456
507
|
onProgress?.(100, 'READY!');
|
|
457
508
|
window.dispatchEvent(
|
|
458
|
-
new CustomEvent('c64-load-success', { detail: { ...eventDetail, type } }),
|
|
509
|
+
new CustomEvent('c64-load-success', { detail: { ...eventDetail, name, type } }),
|
|
459
510
|
);
|
|
460
511
|
} catch (err) {
|
|
461
512
|
onProgress?.(0, 'FAILED');
|
|
@@ -511,6 +562,7 @@ export class C64Player {
|
|
|
511
562
|
onFastForwardReset: () => this.resetFastForwardSpeed(),
|
|
512
563
|
});
|
|
513
564
|
this.inputHandler.attach();
|
|
565
|
+
this.inputHandler.setGamepadMapping(this.gamepadMapping);
|
|
514
566
|
renderer.attachTo(emulator);
|
|
515
567
|
}
|
|
516
568
|
|
|
@@ -658,3 +710,8 @@ function hasViceSnapshotMagic(data: Uint8Array<ArrayBufferLike>): boolean {
|
|
|
658
710
|
}
|
|
659
711
|
return true;
|
|
660
712
|
}
|
|
713
|
+
|
|
714
|
+
function getSourceName(source: string): string {
|
|
715
|
+
const path = source.split(/[?#]/)[0];
|
|
716
|
+
return path.split('/').filter(Boolean).pop() || source;
|
|
717
|
+
}
|