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.
Files changed (105) hide show
  1. package/README.md +52 -1
  2. package/bin/admin.mjs +7 -1
  3. package/bin/agent.mjs +18 -0
  4. package/bin/headless.mjs +1 -1
  5. package/dist/assets/BeachHead-CuSwFD4k.js +1 -0
  6. package/dist/assets/ChuckieEgg-CPqBnAOF.js +1 -0
  7. package/dist/assets/ForbiddenForest-DsQ9jsc8.js +1 -0
  8. package/dist/assets/Galaga-Cutc3p9s.js +1 -0
  9. package/dist/assets/Gribbly-DdZ_hHFt.js +1 -0
  10. package/dist/assets/Hercules-vZYKm7GG.js +1 -0
  11. package/dist/assets/LegendOfWilf-CxSMOjsj.js +1 -0
  12. package/dist/assets/MariosCementFactory-z0IZ0q30.js +1 -0
  13. package/dist/assets/MoleAttack-buC6ChYy.js +1 -0
  14. package/dist/assets/MunchyWorm-D2Zv7i0Q.js +1 -0
  15. package/dist/assets/ParkPatrol-CVj7hyoB.js +1 -0
  16. package/dist/assets/PottyPigeon-0SYpIUBa.js +1 -0
  17. package/dist/assets/RainbowIslands-BjfmJB8z.js +1 -0
  18. package/dist/assets/Stix-BU-qUCeC.js +1 -0
  19. package/dist/assets/Tilt-C5KtKisF.js +1 -0
  20. package/dist/assets/UpNDown-CATRO7Mz.js +1 -0
  21. package/dist/assets/Uridium-DanS2KoH.js +1 -0
  22. package/dist/assets/VegetablesDeluxe-C41ViimS.js +1 -0
  23. package/dist/assets/index-B8DSjPqI.js +243 -0
  24. package/dist/assets/src-DX0rJQsE.js +1 -0
  25. package/dist/assets/src-_trgwTvp.js +2 -0
  26. package/dist/assets/string-utils-CMVABfx0.js +1 -0
  27. package/dist/index.html +1 -1
  28. package/dist-ts/emulator/c64-emulator.d.ts +2 -2
  29. package/dist-ts/emulator/c64-emulator.js +2 -2
  30. package/dist-ts/emulator/c64-keys.d.ts +69 -0
  31. package/dist-ts/emulator/c64-keys.d.ts.map +1 -0
  32. package/dist-ts/emulator/c64-keys.js +69 -0
  33. package/dist-ts/emulator/c64-keys.js.map +1 -0
  34. package/dist-ts/emulator/c64-wasm.d.ts +1 -1
  35. package/dist-ts/emulator/gamepad-mapping.d.ts +64 -0
  36. package/dist-ts/emulator/gamepad-mapping.d.ts.map +1 -0
  37. package/dist-ts/emulator/gamepad-mapping.js +154 -0
  38. package/dist-ts/emulator/gamepad-mapping.js.map +1 -0
  39. package/dist-ts/emulator/input.d.ts +27 -78
  40. package/dist-ts/emulator/input.d.ts.map +1 -1
  41. package/dist-ts/emulator/input.js +94 -215
  42. package/dist-ts/emulator/input.js.map +1 -1
  43. package/dist-ts/headless/audio-capture.d.ts +1 -1
  44. package/dist-ts/headless/c64-headless.d.ts +2 -2
  45. package/dist-ts/headless/c64-headless.js +4 -4
  46. package/dist-ts/headless/frame-capture.d.ts +1 -1
  47. package/dist-ts/headless/input-bridge.d.ts +1 -1
  48. package/dist-ts/player/c64-player.d.ts +21 -5
  49. package/dist-ts/player/c64-player.d.ts.map +1 -1
  50. package/dist-ts/player/c64-player.js +32 -5
  51. package/dist-ts/player/c64-player.js.map +1 -1
  52. package/dist-ts/player/canvas-renderer.d.ts +2 -2
  53. package/dist-ts/player/cheevos-dev.d.ts +65 -0
  54. package/dist-ts/player/cheevos-dev.d.ts.map +1 -0
  55. package/dist-ts/player/cheevos-dev.js +237 -0
  56. package/dist-ts/player/cheevos-dev.js.map +1 -0
  57. package/dist-ts/player/cheevos-tracker-panel.d.ts +21 -0
  58. package/dist-ts/player/cheevos-tracker-panel.d.ts.map +1 -0
  59. package/dist-ts/player/cheevos-tracker-panel.js +242 -0
  60. package/dist-ts/player/cheevos-tracker-panel.js.map +1 -0
  61. package/dist-ts/player/index.d.ts +10 -7
  62. package/dist-ts/player/index.d.ts.map +1 -1
  63. package/dist-ts/player/index.js +6 -4
  64. package/dist-ts/player/index.js.map +1 -1
  65. package/dist-ts/player/input-handler.d.ts +7 -3
  66. package/dist-ts/player/input-handler.d.ts.map +1 -1
  67. package/dist-ts/player/input-handler.js +24 -1
  68. package/dist-ts/player/input-handler.js.map +1 -1
  69. package/dist-ts/player/load-formats.d.ts +1 -1
  70. package/dist-ts/player/local-rom-store.d.ts +23 -0
  71. package/dist-ts/player/local-rom-store.d.ts.map +1 -0
  72. package/dist-ts/player/local-rom-store.js +87 -0
  73. package/dist-ts/player/local-rom-store.js.map +1 -0
  74. package/dist-ts/player/startup-params.d.ts +7 -0
  75. package/dist-ts/player/startup-params.d.ts.map +1 -0
  76. package/dist-ts/player/startup-params.js +47 -0
  77. package/dist-ts/player/startup-params.js.map +1 -0
  78. package/dist-ts/player/ui-controller.d.ts +23 -1
  79. package/dist-ts/player/ui-controller.d.ts.map +1 -1
  80. package/dist-ts/player/ui-controller.js +665 -1
  81. package/dist-ts/player/ui-controller.js.map +1 -1
  82. package/package.json +11 -4
  83. package/src/emulator/c64-keys.ts +68 -0
  84. package/src/emulator/gamepad-mapping.ts +212 -0
  85. package/src/emulator/input.ts +106 -209
  86. package/src/headless/agent-cli.mjs +825 -0
  87. package/src/headless/headless-cli.mjs +10 -4
  88. package/src/headless/input-server.mjs +92 -17
  89. package/src/headless/png.mjs +72 -0
  90. package/src/headless/webrtc-server.mjs +458 -34
  91. package/src/main.ts +197 -12
  92. package/src/player/c64-player.ts +58 -1
  93. package/src/player/cheevos-dev.ts +340 -0
  94. package/src/player/cheevos-tracker-panel.ts +309 -0
  95. package/src/player/index.ts +19 -0
  96. package/src/player/input-handler.ts +32 -0
  97. package/src/player/local-rom-store.ts +126 -0
  98. package/src/player/startup-params.ts +40 -0
  99. package/src/player/ui-controller.ts +751 -0
  100. package/src/player/ultimate-bridge.ts +161 -0
  101. package/src/player/ultimate-panel.ts +315 -0
  102. package/src/types/c64-cheevos.d.ts +6 -0
  103. package/dist/assets/index-BAsZcXuS.js +0 -178
  104. /package/dist/assets/{marked.esm--kBm026b.js → marked.esm-fTuuvbcB.js} +0 -0
  105. /package/dist/assets/{purify.es-BcoGFDcJ.js → purify.es-CRM-GE0Y.js} +0 -0
@@ -6,7 +6,11 @@ const css = `
6
6
  .c64-settings-tabs{display:flex;gap:8px;flex-wrap:wrap;margin:0 0 18px;padding:0;border:0;background:transparent}.c64-settings-tab{background:#2a2a3e;border:1px solid #444;border-radius:3px;color:#ddd;font:inherit;font-size:12px;padding:4px 10px;cursor:pointer}.c64-settings-tab.active{background:#3a335f;border-color:#7b71d5;color:#fff}
7
7
  .c64-section-label{display:block;margin:0 0 8px;color:#7b71d5;font-size:13px;letter-spacing:1px;text-transform:uppercase}.c64-form-row,.c64-radio-row,.c64-system-actions,.c64-menu-actions{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin:0 0 12px}.c64-form-row label{color:#aaa;font-size:13px}
8
8
  .c64-select,.c64-file-input{background:#111827;border:1px solid #444;border-radius:3px;color:#ddd;font:inherit;font-size:13px;padding:5px 8px}.c64-btn{background:#2a2a3e;border:1px solid #444;border-radius:3px;color:#ddd;font:inherit;font-size:12px;padding:5px 10px;cursor:pointer}.c64-btn:hover:not(:disabled){border-color:#7b71d5;color:#fff}.c64-btn:disabled,.c64-select:disabled{opacity:.55;cursor:not-allowed}
9
+ .c64-btn.active{background:#3a335f;border-color:#7b71d5;color:#fff}
9
10
  .c64-dragarea{border:1px dashed #555;border-radius:6px;background:#111827;color:#aaa;padding:18px;margin:0 0 12px;text-align:center}.c64-dragarea.dragover{border-color:#7b71d5;background:#1f1b38;color:#fff}.c64-cart-preview,.c64-tools-section{background:#151527;border:1px solid #2a2a3e;border-radius:6px;padding:12px;margin:12px 0}.c64-section-hint{color:#888;font-size:12px;line-height:1.4;margin:4px 0 12px}.c64-checkbox-row{display:flex;align-items:center;gap:8px;color:#ccc;font-size:13px;margin:14px 0 4px}
11
+ .c64-text-input,.c64-textarea{background:#111827;border:1px solid #444;border-radius:3px;color:#ddd;font:inherit;font-size:13px;padding:5px 8px}.c64-text-input{min-width:180px}.c64-textarea{box-sizing:border-box;width:100%;min-height:120px;resize:vertical}.c64-cheevos-json-file{display:none}.c64-inline-status{color:#888;font-size:12px}
12
+ .c64-cheat-list{display:grid;gap:12px;margin:0 0 12px}.c64-cheat-card{background:#151527;border:1px solid #2a2a3e;border-radius:6px;padding:12px}.c64-cheat-card-header{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:0 0 10px;color:#ddd;font-size:13px}.c64-cheat-remove{background:none;border:0;color:#ff9a9a;cursor:pointer;font:inherit;font-size:12px}.c64-cheat-grid{display:grid;grid-template-columns:max-content minmax(0,1fr);gap:8px 10px;align-items:center}.c64-cheat-input{background:#111827;border:1px solid #444;border-radius:3px;color:#ddd;font:inherit;font-size:13px;min-width:0;padding:5px 8px}.c64-cheat-error{color:#ff9a9a;font-size:12px;margin:8px 0 0}.c64-cheat-status{color:#aaa;font-size:12px;line-height:1.4;margin:8px 0 0}.c64-cheat-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}@media (max-width:600px){.c64-cheat-grid{grid-template-columns:1fr}.c64-cheat-grid label{margin-top:4px}}
13
+ .c64-cheat-status[data-mode=ok]{color:#8fd694}.c64-cheat-status[data-mode=error]{color:#f77}#c64-ultimate-device[data-connected]{color:#8fd694}.c64-settings-section .c64-section-hint a{color:#a8a8ff;text-decoration:none}
10
14
  `;
11
15
 
12
16
  export interface UIControllerOptions {
@@ -48,17 +52,42 @@ const SPECIAL_KEYS = [
48
52
 
49
53
  import type { C64Player } from './c64-player';
50
54
  import type { JoystickPort } from '../emulator/constants';
55
+ import { chooseAndStoreCheevosRom, storeCheevosRomFile } from './local-rom-store';
56
+ import { toViteFsUrl } from './startup-params';
57
+ import UltimatePanel from './ultimate-panel';
51
58
  import {
52
59
  LOAD_FORMAT_OPTIONS,
53
60
  getAcceptForLoadTypeSelection,
54
61
  getLoadTypeLabel,
55
62
  inferLoadTypeFromFilename,
63
+ isSupportedLoadType,
56
64
  resolveLoadTypeSelection,
57
65
  type LoadType,
58
66
  type LoadTypeSelection,
59
67
  } from './load-formats';
60
68
 
61
69
  const CRT_PRELOAD_CHECKS_STORAGE_KEY = 'c64-disable-crt-preload-checks';
70
+ const CHEEVOS_DETECTOR_STORAGE_KEY = 'c64-cheevos-dev-detector';
71
+ const CHEEVOS_JSON_PATH_STORAGE_KEY = 'c64-cheevos-dev-json-path';
72
+ const CHEEVOS_TRACKER_VISIBLE_STORAGE_KEY = 'c64-cheevos-tracker-visible';
73
+ const CHEAT_CONFIG_STORAGE_KEY = 'c64cade.cheatMode.v1';
74
+ const CHEAT_NOTICE_MS = 1800;
75
+
76
+ type CheatAction = 'increment' | 'decrement' | 'set';
77
+ type CheatKeyBinding = { code: string; key: string; label: string };
78
+ type CheatRow = {
79
+ id: string;
80
+ address: string;
81
+ action: CheatAction;
82
+ setValue: string;
83
+ keyBinding: CheatKeyBinding | null;
84
+ };
85
+
86
+ const CHEAT_ACTIONS: Array<{ value: CheatAction; label: string }> = [
87
+ { value: 'increment', label: 'Increment' },
88
+ { value: 'decrement', label: 'Decrement' },
89
+ { value: 'set', label: 'Set' },
90
+ ];
62
91
 
63
92
  type ConnectedGamepad = {
64
93
  index: number;
@@ -70,12 +99,144 @@ function formatSnapshotFilename(now: Date = new Date()): string {
70
99
  return `snapshot-${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}.c64`;
71
100
  }
72
101
 
102
+ function createCheatRow(overrides: Partial<CheatRow> = {}): CheatRow {
103
+ return {
104
+ id: overrides.id ?? `cheat-${Date.now()}-${Math.random().toString(36).slice(2)}`,
105
+ address: typeof overrides.address === 'string' ? overrides.address : '0x004e',
106
+ action: CHEAT_ACTIONS.some((action) => action.value === overrides.action)
107
+ ? (overrides.action as CheatAction)
108
+ : 'increment',
109
+ setValue: typeof overrides.setValue === 'string' ? overrides.setValue : '0xff',
110
+ keyBinding: normaliseCheatKeyBinding(overrides.keyBinding),
111
+ };
112
+ }
113
+
114
+ function normaliseCheatRow(value: unknown): CheatRow | null {
115
+ if (!value || typeof value !== 'object') return null;
116
+ return createCheatRow(value as Partial<CheatRow>);
117
+ }
118
+
119
+ function isCheatRow(row: CheatRow | null): row is CheatRow {
120
+ return !!row;
121
+ }
122
+
123
+ function loadCheatConfig(): CheatRow[] {
124
+ const fallback = [createCheatRow()];
125
+ try {
126
+ const raw = localStorage.getItem(CHEAT_CONFIG_STORAGE_KEY);
127
+ const parsed = raw ? JSON.parse(raw) : null;
128
+ const rows = Array.isArray(parsed?.cheats)
129
+ ? (parsed.cheats as unknown[]).map(normaliseCheatRow).filter(isCheatRow)
130
+ : [normaliseCheatRow(parsed)].filter(isCheatRow);
131
+ return rows.length ? rows : fallback;
132
+ } catch (error) {
133
+ console.warn('Failed to load cheat config:', error);
134
+ return fallback;
135
+ }
136
+ }
137
+
138
+ function getNextCheatId(rows: CheatRow[]): number {
139
+ return rows.reduce((nextId, cheat) => {
140
+ const match = String(cheat.id).match(/^cheat-(\d+)$/);
141
+ return match ? Math.max(nextId, Number(match[1]) + 1) : nextId;
142
+ }, 1);
143
+ }
144
+
145
+ function parseC64Address(value: string): number | null {
146
+ const raw = value.trim().toLowerCase();
147
+ if (!raw) return null;
148
+ const hex = raw.startsWith('0x') ? raw.slice(2) : raw.startsWith('$') ? raw.slice(1) : raw;
149
+ if (!/^[0-9a-f]{1,4}$/.test(hex)) return null;
150
+ const address = Number.parseInt(hex, 16);
151
+ return Number.isInteger(address) && address >= 0 && address <= 0xffff ? address : null;
152
+ }
153
+
154
+ function parseCheatByte(value: string): number | null {
155
+ const raw = value.trim().toLowerCase();
156
+ if (!raw) return null;
157
+ const hex = raw.startsWith('0x') ? raw.slice(2) : raw.startsWith('$') ? raw.slice(1) : raw;
158
+ if (!/^[0-9a-f]{1,2}$/.test(hex)) return null;
159
+ const byte = Number.parseInt(hex, 16);
160
+ return Number.isInteger(byte) && byte >= 0 && byte <= 0xff ? byte : null;
161
+ }
162
+
163
+ function formatHexByte(value: number): string {
164
+ return `0x${(value & 0xff).toString(16).padStart(2, '0')}`;
165
+ }
166
+
167
+ function formatHexAddress(value: number): string {
168
+ return `0x${(value & 0xffff).toString(16).padStart(4, '0')}`;
169
+ }
170
+
171
+ function normaliseCheatKeyBinding(binding: unknown): CheatKeyBinding | null {
172
+ if (!binding || typeof binding !== 'object' || !('code' in binding)) return null;
173
+ const value = binding as Partial<CheatKeyBinding>;
174
+ if (!value.code) return null;
175
+ return {
176
+ code: String(value.code),
177
+ key: String(value.key || value.code),
178
+ label: String(value.label || labelForKey(value.key, value.code)),
179
+ };
180
+ }
181
+
182
+ function keyBindingFromEvent(event: KeyboardEvent): CheatKeyBinding {
183
+ return {
184
+ code: event.code || event.key,
185
+ key: event.key,
186
+ label: labelForKey(event.key, event.code),
187
+ };
188
+ }
189
+
190
+ function labelForKey(key?: string, code?: string): string {
191
+ if (code === 'ControlLeft') return 'Left Ctrl';
192
+ if (code === 'ControlRight') return 'Right Ctrl';
193
+ if (key === ' ') return 'Space';
194
+ if (key?.startsWith('Arrow')) return key.replace('Arrow', 'Arrow ');
195
+ if (/^Key[A-Z]$/.test(code || '')) return (code || '').slice(3);
196
+ if (/^Digit[0-9]$/.test(code || '')) return (code || '').slice(5);
197
+ return key || code || '';
198
+ }
199
+
200
+ function isEditableKeyTarget(target: EventTarget | null): boolean {
201
+ const element = target as HTMLElement | null;
202
+ const tagName = element?.tagName?.toLowerCase();
203
+ return (
204
+ tagName === 'input' ||
205
+ tagName === 'select' ||
206
+ tagName === 'textarea' ||
207
+ !!element?.isContentEditable
208
+ );
209
+ }
210
+
211
+ function formatRamDumpFilename(now: Date = new Date()): string {
212
+ const stamp = now
213
+ .toISOString()
214
+ .replace(/[-:]/g, '')
215
+ .replace(/\.\d{3}z$/i, 'z');
216
+ return `c64-ready-${stamp}-ram.bin`;
217
+ }
218
+
73
219
  export default class UIController {
220
+ private static activeController: UIController | null = null;
74
221
  private helpOverlay: HTMLElement | null = null;
75
222
  private settingsOverlay: HTMLElement | null = null;
76
223
  private fileInput: HTMLInputElement | null = null;
77
224
  private player: C64Player | null = null;
78
225
  private readonly options: UIControllerOptions;
226
+ private cheats: CheatRow[] = loadCheatConfig();
227
+ private recordingCheatId: string | null = null;
228
+ private nextCheatId = getNextCheatId(this.cheats);
229
+ private cheatStatus = '';
230
+ private cheatNoticeTimer: number | null = null;
231
+ private readonly handleCheatKeyDown = (event: KeyboardEvent): void => {
232
+ if (UIController.activeController !== this) return;
233
+ if (this.recordingCheatId || event.repeat || isEditableKeyTarget(event.target)) return;
234
+ const cheat = this.cheats.find((entry) => this.matchesCheatKey(event, entry));
235
+ if (!cheat) return;
236
+ event.preventDefault();
237
+ event.stopPropagation();
238
+ this.applyCheatAction(cheat);
239
+ };
79
240
  // Save previous overflow styles so we can restore them when exiting full/stretch
80
241
  private savedHtmlOverflow: string | null = null;
81
242
  private savedBodyOverflow: string | null = null;
@@ -101,6 +262,7 @@ export default class UIController {
101
262
  }
102
263
 
103
264
  init(player?: C64Player): void {
265
+ UIController.activeController = this;
104
266
  this.player = player ?? null;
105
267
  this.syncConnectedGamepads();
106
268
  this.injectCSS();
@@ -109,6 +271,7 @@ export default class UIController {
109
271
  this.createHamburger();
110
272
  this.createMenu();
111
273
  this.createUnmuteButton();
274
+ window.addEventListener('keydown', this.handleCheatKeyDown, true);
112
275
  window.addEventListener('c64-controller-connected', this.handleControllerConnected);
113
276
  window.addEventListener('c64-controller-disconnected', this.handleControllerDisconnected);
114
277
  }
@@ -177,6 +340,363 @@ export default class UIController {
177
340
  URL.revokeObjectURL(url);
178
341
  }
179
342
 
343
+ private downloadBytes(filename: string, bytes: Uint8Array): void {
344
+ const copy = new Uint8Array(bytes.byteLength);
345
+ copy.set(bytes);
346
+ const blob = new Blob([copy], { type: 'application/octet-stream' });
347
+ const url = URL.createObjectURL(blob);
348
+ const link = document.createElement('a');
349
+ link.href = url;
350
+ link.download = filename;
351
+ document.body.appendChild(link);
352
+ link.click();
353
+ link.remove();
354
+ URL.revokeObjectURL(url);
355
+ }
356
+
357
+ private promptForCheevosJsonUrl(
358
+ file: File,
359
+ detectorInput: HTMLInputElement | null,
360
+ status: HTMLElement,
361
+ ): void {
362
+ const fileWithPath = file as File & { path?: string; webkitRelativePath?: string };
363
+ const inferredPath = fileWithPath.path || fileWithPath.webkitRelativePath || '';
364
+ if (inferredPath) {
365
+ this.updateCheevosJsonUrl(inferredPath, file.name, detectorInput, status);
366
+ return;
367
+ }
368
+ const previousPath = localStorage.getItem(CHEEVOS_JSON_PATH_STORAGE_KEY) ?? '';
369
+ const path = window.prompt(
370
+ 'Optional: enter the absolute path to this cheevos JSON to update the URL for refresh.',
371
+ previousPath,
372
+ );
373
+ if (!path?.trim()) return;
374
+
375
+ this.updateCheevosJsonUrl(path, file.name, detectorInput, status);
376
+ }
377
+
378
+ private updateCheevosJsonUrl(
379
+ path: string,
380
+ filename: string,
381
+ detectorInput: HTMLInputElement | null,
382
+ status: HTMLElement,
383
+ ): void {
384
+ const cheevosSet = toViteFsUrl(path, this.options.assetBaseUrl ?? '/');
385
+ if (!cheevosSet) return;
386
+
387
+ localStorage.setItem(CHEEVOS_JSON_PATH_STORAGE_KEY, path.trim());
388
+ const searchParams = new URLSearchParams(window.location.search);
389
+ const detectorId = detectorInput?.value.trim() ?? '';
390
+ if (detectorId) searchParams.set('cheevos', detectorId);
391
+ searchParams.set('cheevosSet', cheevosSet);
392
+ if (!searchParams.has('game')) searchParams.delete('game');
393
+ const search = searchParams.toString();
394
+ window.history.replaceState(
395
+ null,
396
+ '',
397
+ `${window.location.pathname}${search ? `?${search}` : ''}${window.location.hash}`,
398
+ );
399
+ status.textContent = `Loaded JSON from ${filename}; updated URL cheevosSet=${cheevosSet}`;
400
+ }
401
+
402
+ private saveCheatConfig(): void {
403
+ localStorage.setItem(
404
+ CHEAT_CONFIG_STORAGE_KEY,
405
+ JSON.stringify({
406
+ cheats: this.cheats.map((cheat) => ({
407
+ id: cheat.id,
408
+ address: cheat.address,
409
+ action: cheat.action,
410
+ setValue: cheat.setValue,
411
+ keyBinding: cheat.keyBinding,
412
+ })),
413
+ }),
414
+ );
415
+ }
416
+
417
+ private getCheatAddressError(cheat: CheatRow): string {
418
+ if (!cheat.address.trim()) return 'Enter a C64 memory address.';
419
+ if (parseC64Address(cheat.address) === null)
420
+ return 'Use a valid address from 0x0000 to 0xffff.';
421
+ return '';
422
+ }
423
+
424
+ private getCheatSetValueError(cheat: CheatRow): string {
425
+ if (cheat.action !== 'set') return '';
426
+ if (!cheat.setValue.trim()) return 'Enter a byte value to set.';
427
+ if (parseCheatByte(cheat.setValue) === null) return 'Use a valid byte value from 0x00 to 0xff.';
428
+ return '';
429
+ }
430
+
431
+ private isCheatReady(cheat: CheatRow): boolean {
432
+ return (
433
+ !this.getCheatAddressError(cheat) &&
434
+ !this.getCheatSetValueError(cheat) &&
435
+ !!cheat.keyBinding?.code
436
+ );
437
+ }
438
+
439
+ private matchesCheatKey(event: KeyboardEvent, cheat: CheatRow): boolean {
440
+ const binding = cheat.keyBinding;
441
+ if (!binding?.code || !this.isCheatReady(cheat)) return false;
442
+ if (event.code === binding.code) return true;
443
+ return !!binding.key && event.key?.toLowerCase() === binding.key.toLowerCase();
444
+ }
445
+
446
+ private setCheatStatus(message: string): void {
447
+ this.cheatStatus = message;
448
+ const status = document.getElementById('c64-cheat-status') as HTMLElement | null;
449
+ if (status) {
450
+ status.textContent = message;
451
+ status.hidden = !message;
452
+ }
453
+
454
+ if (this.cheatNoticeTimer !== null) window.clearTimeout(this.cheatNoticeTimer);
455
+ this.cheatNoticeTimer = window.setTimeout(() => {
456
+ this.cheatNoticeTimer = null;
457
+ }, CHEAT_NOTICE_MS);
458
+ }
459
+
460
+ private applyCheatAction(cheat: CheatRow): void {
461
+ const address = parseC64Address(cheat.address);
462
+ if (address === null) {
463
+ this.setCheatStatus(this.getCheatAddressError(cheat));
464
+ return;
465
+ }
466
+
467
+ const setValue = cheat.action === 'set' ? parseCheatByte(cheat.setValue) : null;
468
+ if (cheat.action === 'set' && setValue === null) {
469
+ this.setCheatStatus(this.getCheatSetValueError(cheat));
470
+ return;
471
+ }
472
+
473
+ if (
474
+ !this.player ||
475
+ typeof this.player.cpuRead !== 'function' ||
476
+ typeof this.player.cpuWrite !== 'function'
477
+ ) {
478
+ this.setCheatStatus('Emulator memory is not ready yet.');
479
+ return;
480
+ }
481
+
482
+ const currentValue = this.player.cpuRead(address) & 0xff;
483
+ const nextValue =
484
+ cheat.action === 'set'
485
+ ? (setValue as number)
486
+ : cheat.action === 'decrement'
487
+ ? (currentValue + 0xff) & 0xff
488
+ : (currentValue + 1) & 0xff;
489
+
490
+ this.player.cpuWrite(address, nextValue);
491
+ const actionLabel =
492
+ CHEAT_ACTIONS.find((action) => action.value === cheat.action)?.label ?? 'Updated';
493
+ this.setCheatStatus(
494
+ `${actionLabel} ${formatHexAddress(address)}: ${formatHexByte(currentValue)} -> ${formatHexByte(nextValue)}`,
495
+ );
496
+ }
497
+
498
+ private addCheat(): void {
499
+ this.cheats = [
500
+ ...this.cheats,
501
+ createCheatRow({ id: `cheat-${this.nextCheatId++}`, address: '' }),
502
+ ];
503
+ this.saveCheatConfig();
504
+ this.renderCheats();
505
+ }
506
+
507
+ private removeCheat(cheatId: string): void {
508
+ if (this.cheats.length <= 1) return;
509
+ this.cheats = this.cheats.filter((cheat) => cheat.id !== cheatId);
510
+ if (this.recordingCheatId === cheatId) this.recordingCheatId = null;
511
+ this.saveCheatConfig();
512
+ this.renderCheats();
513
+ }
514
+
515
+ private renderCheats(): void {
516
+ const list = document.getElementById('c64-cheat-list');
517
+ if (!list) return;
518
+
519
+ list.replaceChildren(
520
+ ...this.cheats.map((cheat, index) => {
521
+ const card = document.createElement('article');
522
+ card.className = 'c64-cheat-card';
523
+ card.addEventListener('keydown', (event) => event.stopPropagation());
524
+ card.addEventListener('keyup', (event) => event.stopPropagation());
525
+
526
+ const header = document.createElement('div');
527
+ header.className = 'c64-cheat-card-header';
528
+ const title = document.createElement('span');
529
+ title.textContent = `Cheat ${index + 1}`;
530
+ header.appendChild(title);
531
+ if (this.cheats.length > 1) {
532
+ const remove = document.createElement('button');
533
+ remove.type = 'button';
534
+ remove.className = 'c64-cheat-remove';
535
+ remove.textContent = 'Remove';
536
+ remove.addEventListener('click', () => this.removeCheat(cheat.id));
537
+ header.appendChild(remove);
538
+ }
539
+
540
+ const grid = document.createElement('div');
541
+ grid.className = 'c64-cheat-grid';
542
+
543
+ const addressInput = document.createElement('input');
544
+ addressInput.id = `c64-cheat-address-${cheat.id}`;
545
+ addressInput.className = 'c64-cheat-input';
546
+ addressInput.type = 'text';
547
+ addressInput.inputMode = 'text';
548
+ addressInput.spellcheck = false;
549
+ addressInput.autocomplete = 'off';
550
+ addressInput.placeholder = '0x004e';
551
+ addressInput.value = cheat.address;
552
+ addressInput.addEventListener('input', () => {
553
+ cheat.address = addressInput.value;
554
+ this.saveCheatConfig();
555
+ });
556
+ grid.appendChild(this.makeLabel(addressInput.id, 'Memory address'));
557
+ grid.appendChild(addressInput);
558
+
559
+ const actionSelect = document.createElement('select');
560
+ actionSelect.id = `c64-cheat-action-${cheat.id}`;
561
+ actionSelect.className = 'c64-cheat-input';
562
+ for (const action of CHEAT_ACTIONS) {
563
+ const option = document.createElement('option');
564
+ option.value = action.value;
565
+ option.textContent = action.label;
566
+ option.selected = cheat.action === action.value;
567
+ actionSelect.appendChild(option);
568
+ }
569
+ actionSelect.addEventListener('change', () => {
570
+ cheat.action = actionSelect.value as CheatAction;
571
+ this.saveCheatConfig();
572
+ this.renderCheats();
573
+ });
574
+ grid.appendChild(this.makeLabel(actionSelect.id, 'Action'));
575
+ grid.appendChild(actionSelect);
576
+
577
+ if (cheat.action === 'set') {
578
+ const setInput = document.createElement('input');
579
+ setInput.id = `c64-cheat-set-value-${cheat.id}`;
580
+ setInput.className = 'c64-cheat-input';
581
+ setInput.type = 'text';
582
+ setInput.inputMode = 'text';
583
+ setInput.spellcheck = false;
584
+ setInput.autocomplete = 'off';
585
+ setInput.placeholder = '0xff';
586
+ setInput.value = cheat.setValue;
587
+ setInput.addEventListener('input', () => {
588
+ cheat.setValue = setInput.value;
589
+ this.saveCheatConfig();
590
+ });
591
+ grid.appendChild(this.makeLabel(setInput.id, 'Set value'));
592
+ grid.appendChild(setInput);
593
+ }
594
+
595
+ const keyButton = document.createElement('button');
596
+ keyButton.id = `c64-cheat-key-${cheat.id}`;
597
+ keyButton.type = 'button';
598
+ keyButton.className = `c64-btn${this.recordingCheatId === cheat.id ? ' active' : ''}`;
599
+ keyButton.textContent =
600
+ this.recordingCheatId === cheat.id
601
+ ? 'Press a key...'
602
+ : (cheat.keyBinding?.label ?? 'Choose key...');
603
+ keyButton.addEventListener('click', () => {
604
+ this.recordingCheatId = cheat.id;
605
+ this.renderCheats();
606
+ document.getElementById(keyButton.id)?.focus();
607
+ });
608
+ keyButton.addEventListener('keydown', (event) => {
609
+ if (this.recordingCheatId !== cheat.id) return;
610
+ event.preventDefault();
611
+ event.stopPropagation();
612
+ cheat.keyBinding = keyBindingFromEvent(event);
613
+ this.recordingCheatId = null;
614
+ this.saveCheatConfig();
615
+ this.renderCheats();
616
+ });
617
+ grid.appendChild(this.makeLabel(keyButton.id, 'Key press'));
618
+ grid.appendChild(keyButton);
619
+
620
+ const actions = document.createElement('div');
621
+ actions.className = 'c64-cheat-actions';
622
+ const apply = document.createElement('button');
623
+ apply.type = 'button';
624
+ apply.className = 'c64-btn';
625
+ apply.textContent = 'Apply Now';
626
+ apply.disabled = !this.isCheatReady(cheat);
627
+ apply.addEventListener('click', () => this.applyCheatAction(cheat));
628
+ actions.appendChild(apply);
629
+ if (this.recordingCheatId === cheat.id) {
630
+ const cancel = document.createElement('button');
631
+ cancel.type = 'button';
632
+ cancel.className = 'c64-btn';
633
+ cancel.textContent = 'Cancel Key';
634
+ cancel.addEventListener('click', () => {
635
+ this.recordingCheatId = null;
636
+ this.renderCheats();
637
+ });
638
+ actions.appendChild(cancel);
639
+ }
640
+ if (cheat.keyBinding) {
641
+ const clear = document.createElement('button');
642
+ clear.type = 'button';
643
+ clear.className = 'c64-btn';
644
+ clear.textContent = 'Clear Key';
645
+ clear.addEventListener('click', () => {
646
+ cheat.keyBinding = null;
647
+ this.saveCheatConfig();
648
+ this.renderCheats();
649
+ });
650
+ actions.appendChild(clear);
651
+ }
652
+
653
+ const error = this.getCheatAddressError(cheat) || this.getCheatSetValueError(cheat);
654
+ card.appendChild(header);
655
+ card.appendChild(grid);
656
+ card.appendChild(actions);
657
+ if (error) {
658
+ const errorEl = document.createElement('p');
659
+ errorEl.className = 'c64-cheat-error';
660
+ errorEl.textContent = error;
661
+ card.appendChild(errorEl);
662
+ }
663
+ return card;
664
+ }),
665
+ );
666
+
667
+ const status = document.getElementById('c64-cheat-status') as HTMLElement | null;
668
+ if (status) {
669
+ status.textContent = this.cheatStatus;
670
+ status.hidden = !this.cheatStatus;
671
+ }
672
+ }
673
+
674
+ private makeLabel(htmlFor: string, text: string): HTMLLabelElement {
675
+ const label = document.createElement('label');
676
+ label.htmlFor = htmlFor;
677
+ label.textContent = text;
678
+ return label;
679
+ }
680
+
681
+ private dumpC64Ram(): void {
682
+ if (!this.player || typeof this.player.ramRead !== 'function') {
683
+ this.setCheatStatus('Emulator RAM is not ready yet.');
684
+ return;
685
+ }
686
+
687
+ try {
688
+ const bytes = new Uint8Array(0x10000);
689
+ for (let address = 0; address <= 0xffff; address += 1) {
690
+ bytes[address] = this.player.ramRead(address) & 0xff;
691
+ }
692
+ const filename = formatRamDumpFilename();
693
+ this.downloadBytes(filename, bytes);
694
+ this.setCheatStatus(`Dumped 64K RAM to ${filename}`);
695
+ } catch (error) {
696
+ this.setCheatStatus(error instanceof Error ? error.message : 'Failed to dump C64 RAM.');
697
+ }
698
+ }
699
+
180
700
  private injectCSS(): void {
181
701
  if (document.querySelector('style[data-c64-help]')) return;
182
702
  const style = document.createElement('style');
@@ -314,6 +834,9 @@ export default class UIController {
314
834
  { id: 'input', label: 'Input' },
315
835
  { id: 'display', label: 'Display' },
316
836
  { id: 'audio', label: 'Audio' },
837
+ { id: 'cheevos', label: 'Cheevos' },
838
+ { id: 'cheats', label: 'Cheats' },
839
+ { id: 'ultimate', label: 'Ultimate' },
317
840
  { id: 'system', label: 'System' },
318
841
  ] as const;
319
842
 
@@ -411,6 +934,56 @@ export default class UIController {
411
934
  <div id="c64-audio-section-anchor"></div>
412
935
  </section>
413
936
 
937
+ <section class="c64-settings-section" data-settings-section="cheevos" hidden>
938
+ <label class="c64-section-label">Cheevos Dev</label>
939
+ <div class="c64-section-hint">Load a c64-cheevos detector and optional achievement set JSON for local development.</div>
940
+ <div class="c64-form-row">
941
+ <label for="c64-cheevos-detector">Detector ID</label>
942
+ <input id="c64-cheevos-detector" class="c64-text-input" type="text" placeholder="uridium" />
943
+ </div>
944
+ <div class="c64-form-row">
945
+ <button class="c64-btn" id="c64-cheevos-browse-json-btn" type="button">Load JSON File</button>
946
+ <span class="c64-inline-status" id="c64-cheevos-json-filename">No JSON file loaded</span>
947
+ <input id="c64-cheevos-json-file" class="c64-cheevos-json-file" type="file" accept="application/json,.json" />
948
+ </div>
949
+ <textarea id="c64-cheevos-json" class="c64-textarea" spellcheck="false" placeholder='{ "_id": "set1", "cheevos": [{ "_id": "zinc", "title": "Zinc", "description": "Clear level 1" }] }'></textarea>
950
+ <div class="c64-menu-actions">
951
+ <button class="c64-btn" id="c64-cheevos-enable-btn">Enable</button>
952
+ <button class="c64-btn" id="c64-cheevos-disable-btn">Disable</button>
953
+ <button class="c64-btn" id="c64-cheevos-choose-rom-btn" type="button" disabled>Choose ROM File</button>
954
+ <button class="c64-btn" id="c64-cheevos-clear-popped-btn">Clear Unlocks</button>
955
+ <button class="c64-btn" id="c64-cheevos-clear-scores-btn">Clear Scores</button>
956
+ </div>
957
+ <input id="c64-cheevos-rom-file" class="c64-cheevos-json-file" type="file" accept=".crt,.prg,.d64" />
958
+ <label class="c64-checkbox-row" for="c64-cheevos-tracker-visible">
959
+ <input type="checkbox" id="c64-cheevos-tracker-visible" />
960
+ Show tracker panel
961
+ </label>
962
+ <div class="c64-section-hint">Shows the cheevos tracker beside the emulator in Standard display mode.</div>
963
+ <div class="c64-section-hint" id="c64-cheevos-status">Cheevos dev tracking is disabled.</div>
964
+ </section>
965
+
966
+ <section class="c64-settings-section" data-settings-section="cheats" hidden>
967
+ <label class="c64-section-label">Cheat Mode</label>
968
+ <div class="c64-section-hint">Bind keys to change C64 memory bytes while the game is running. Values wrap between 0x00 and 0xff.</div>
969
+ <div class="c64-cheat-list" id="c64-cheat-list"></div>
970
+ <div class="c64-menu-actions">
971
+ <button class="c64-btn" id="c64-add-cheat-btn" type="button">Add Cheat</button>
972
+ </div>
973
+ <div class="c64-tools-section">
974
+ <label class="c64-section-label">Memory Tools</label>
975
+ <div class="c64-menu-actions">
976
+ <button class="c64-btn" id="c64-dump-ram-btn" type="button">Dump 64K RAM</button>
977
+ </div>
978
+ <div class="c64-section-hint">Downloads raw C64 RAM from $0000-$ffff as a .bin file for address inspection.</div>
979
+ <div class="c64-cheat-status" id="c64-cheat-status" hidden></div>
980
+ </div>
981
+ </section>
982
+
983
+ <section class="c64-settings-section" data-settings-section="ultimate" hidden>
984
+ <div id="c64-ultimate-section-anchor"></div>
985
+ </section>
986
+
414
987
  <section class="c64-settings-section" data-settings-section="system" hidden>
415
988
  <label class="c64-section-label">System Actions</label>
416
989
  <div class="c64-system-actions">
@@ -606,6 +1179,180 @@ export default class UIController {
606
1179
 
607
1180
  loadToolsManifest().catch(() => {});
608
1181
 
1182
+ const cheevosDetectorInput = panel.querySelector(
1183
+ '#c64-cheevos-detector',
1184
+ ) as HTMLInputElement | null;
1185
+ const cheevosJsonInput = panel.querySelector('#c64-cheevos-json') as HTMLTextAreaElement | null;
1186
+ const cheevosJsonFile = panel.querySelector(
1187
+ '#c64-cheevos-json-file',
1188
+ ) as HTMLInputElement | null;
1189
+ const cheevosBrowseJsonBtn = panel.querySelector(
1190
+ '#c64-cheevos-browse-json-btn',
1191
+ ) as HTMLButtonElement | null;
1192
+ const cheevosJsonFilename = panel.querySelector(
1193
+ '#c64-cheevos-json-filename',
1194
+ ) as HTMLElement | null;
1195
+ const cheevosStatus = panel.querySelector('#c64-cheevos-status') as HTMLElement | null;
1196
+ const cheevosTrackerVisibleInput = panel.querySelector(
1197
+ '#c64-cheevos-tracker-visible',
1198
+ ) as HTMLInputElement | null;
1199
+ const cheevosChooseRomBtn = panel.querySelector(
1200
+ '#c64-cheevos-choose-rom-btn',
1201
+ ) as HTMLButtonElement | null;
1202
+ const cheevosRomFile = panel.querySelector('#c64-cheevos-rom-file') as HTMLInputElement | null;
1203
+ let pendingCheevosRomPath = '';
1204
+ let pendingCheevosRomType: LoadType | undefined;
1205
+ const storedCheevosDetector = window.localStorage.getItem(CHEEVOS_DETECTOR_STORAGE_KEY) ?? '';
1206
+ if (cheevosDetectorInput) cheevosDetectorInput.value = storedCheevosDetector;
1207
+ const trackerVisible = window.localStorage.getItem(CHEEVOS_TRACKER_VISIBLE_STORAGE_KEY) !== '0';
1208
+ if (cheevosTrackerVisibleInput) {
1209
+ cheevosTrackerVisibleInput.checked = trackerVisible;
1210
+ window.dispatchEvent(
1211
+ new CustomEvent('c64-cheevos-tracker-toggle', { detail: { visible: trackerVisible } }),
1212
+ );
1213
+ cheevosTrackerVisibleInput.addEventListener('change', () => {
1214
+ const visible = cheevosTrackerVisibleInput.checked;
1215
+ window.localStorage.setItem(CHEEVOS_TRACKER_VISIBLE_STORAGE_KEY, visible ? '1' : '0');
1216
+ window.dispatchEvent(
1217
+ new CustomEvent('c64-cheevos-tracker-toggle', { detail: { visible } }),
1218
+ );
1219
+ });
1220
+ }
1221
+
1222
+ cheevosBrowseJsonBtn?.addEventListener('click', () => {
1223
+ cheevosJsonFile?.click();
1224
+ });
1225
+
1226
+ cheevosJsonFile?.addEventListener('change', async () => {
1227
+ const file = cheevosJsonFile.files?.[0];
1228
+ if (!file || !cheevosJsonInput || !cheevosStatus) return;
1229
+ try {
1230
+ cheevosJsonInput.value = await file.text();
1231
+ if (cheevosJsonFilename) cheevosJsonFilename.textContent = file.name;
1232
+ cheevosStatus.textContent = `Loaded JSON from ${file.name}`;
1233
+ this.promptForCheevosJsonUrl(file, cheevosDetectorInput, cheevosStatus);
1234
+ } catch (err) {
1235
+ cheevosStatus.textContent = `Unable to read JSON file: ${String((err as Error)?.message ?? err)}`;
1236
+ }
1237
+ });
1238
+
1239
+ panel.querySelector('#c64-cheevos-enable-btn')?.addEventListener('click', () => {
1240
+ const detectorId = cheevosDetectorInput?.value.trim() ?? '';
1241
+ const jsonText = cheevosJsonInput?.value.trim() ?? '';
1242
+ if (!detectorId) {
1243
+ if (cheevosStatus) cheevosStatus.textContent = 'Enter a detector ID first.';
1244
+ return;
1245
+ }
1246
+ window.localStorage.setItem(CHEEVOS_DETECTOR_STORAGE_KEY, detectorId);
1247
+ window.dispatchEvent(
1248
+ new CustomEvent('c64-cheevos-enable', { detail: { detectorId, jsonText } }),
1249
+ );
1250
+ if (cheevosStatus) cheevosStatus.textContent = `Enabling ${detectorId}...`;
1251
+ });
1252
+
1253
+ panel.querySelector('#c64-cheevos-disable-btn')?.addEventListener('click', () => {
1254
+ window.dispatchEvent(new CustomEvent('c64-cheevos-disable'));
1255
+ if (cheevosStatus) cheevosStatus.textContent = 'Cheevos dev tracking is disabled.';
1256
+ });
1257
+
1258
+ const dispatchCheevosRomFile = (file: File, romPath: string, type?: LoadType) => {
1259
+ const resolvedType = type ?? inferLoadTypeFromFilename(file.name) ?? 'crt';
1260
+ window.dispatchEvent(
1261
+ new CustomEvent('c64-cheevos-rom-file', {
1262
+ detail: { file, type: resolvedType, romPath },
1263
+ }),
1264
+ );
1265
+ if (cheevosStatus) cheevosStatus.textContent = `Loading ROM ${file.name} for ${romPath}`;
1266
+ };
1267
+
1268
+ cheevosChooseRomBtn?.addEventListener('click', async () => {
1269
+ if (!pendingCheevosRomPath) return;
1270
+ if ('showOpenFilePicker' in window) {
1271
+ try {
1272
+ const rom = await chooseAndStoreCheevosRom(pendingCheevosRomPath, pendingCheevosRomType);
1273
+ if (rom) dispatchCheevosRomFile(rom.file, rom.romPath, rom.type);
1274
+ return;
1275
+ } catch (err) {
1276
+ if ((err as DOMException)?.name === 'AbortError') return;
1277
+ if (cheevosStatus) {
1278
+ cheevosStatus.textContent = `Unable to remember ROM file: ${String((err as Error)?.message ?? err)}`;
1279
+ }
1280
+ return;
1281
+ }
1282
+ }
1283
+ cheevosRomFile?.click();
1284
+ });
1285
+
1286
+ cheevosRomFile?.addEventListener('change', async () => {
1287
+ const file = cheevosRomFile.files?.[0];
1288
+ if (!file || !pendingCheevosRomPath) return;
1289
+ try {
1290
+ await storeCheevosRomFile(pendingCheevosRomPath, file, pendingCheevosRomType);
1291
+ } catch (err) {
1292
+ if (cheevosStatus) {
1293
+ cheevosStatus.textContent = `Unable to remember ROM file: ${String((err as Error)?.message ?? err)}`;
1294
+ }
1295
+ }
1296
+ dispatchCheevosRomFile(file, pendingCheevosRomPath, pendingCheevosRomType);
1297
+ });
1298
+
1299
+ panel.querySelector('#c64-cheevos-clear-popped-btn')?.addEventListener('click', () => {
1300
+ window.dispatchEvent(
1301
+ new CustomEvent('c64-cheevos-clear-popped', {
1302
+ detail: { detectorId: cheevosDetectorInput?.value.trim() ?? '' },
1303
+ }),
1304
+ );
1305
+ if (cheevosStatus) cheevosStatus.textContent = 'Local unlocks cleared.';
1306
+ });
1307
+
1308
+ panel.querySelector('#c64-cheevos-clear-scores-btn')?.addEventListener('click', () => {
1309
+ window.dispatchEvent(
1310
+ new CustomEvent('c64-cheevos-clear-scores', {
1311
+ detail: { detectorId: cheevosDetectorInput?.value.trim() ?? '' },
1312
+ }),
1313
+ );
1314
+ if (cheevosStatus) cheevosStatus.textContent = 'Local scores cleared.';
1315
+ });
1316
+
1317
+ window.addEventListener('c64-cheevos-status', (event: Event) => {
1318
+ if (!cheevosStatus) return;
1319
+ const detail = (
1320
+ event as CustomEvent<{ detectorId?: string; status?: string; cheevosCount?: number }>
1321
+ ).detail;
1322
+ if (detail?.status === 'enabled') {
1323
+ cheevosStatus.textContent = `Tracking ${detail.detectorId ?? 'cheevos'} (${detail.cheevosCount ?? 0} achievements)`;
1324
+ }
1325
+ });
1326
+
1327
+ window.addEventListener('c64-cheevos-json-loaded', (event: Event) => {
1328
+ const detail = (event as CustomEvent<{ jsonText?: string; source?: string }>).detail;
1329
+ if (!detail?.jsonText || !cheevosJsonInput) return;
1330
+ cheevosJsonInput.value = detail.jsonText;
1331
+ if (cheevosJsonFilename) cheevosJsonFilename.textContent = detail.source ?? 'URL-loaded JSON';
1332
+ if (cheevosStatus) cheevosStatus.textContent = `Loaded JSON from ${detail.source ?? 'URL'}`;
1333
+ });
1334
+
1335
+ window.addEventListener('c64-cheevos-rom-needed', (event: Event) => {
1336
+ const detail = (event as CustomEvent<{ romPath?: string; type?: LoadType; reason?: string }>)
1337
+ .detail;
1338
+ pendingCheevosRomPath = detail?.romPath?.trim() ?? '';
1339
+ pendingCheevosRomType = isSupportedLoadType(detail?.type) ? detail.type : undefined;
1340
+ if (cheevosChooseRomBtn) cheevosChooseRomBtn.disabled = !pendingCheevosRomPath;
1341
+ if (cheevosStatus && pendingCheevosRomPath) {
1342
+ cheevosStatus.textContent = `${detail?.reason ?? 'Choose local ROM file'}: ${pendingCheevosRomPath}`;
1343
+ }
1344
+ });
1345
+
1346
+ window.addEventListener('c64-cheevos-error', (event: Event) => {
1347
+ if (!cheevosStatus) return;
1348
+ const detail = (event as CustomEvent<{ error?: string }>).detail;
1349
+ cheevosStatus.textContent = `Cheevos error: ${detail?.error ?? 'Unknown error'}`;
1350
+ });
1351
+
1352
+ panel.querySelector('#c64-add-cheat-btn')?.addEventListener('click', () => this.addCheat());
1353
+ panel.querySelector('#c64-dump-ram-btn')?.addEventListener('click', () => this.dumpC64Ram());
1354
+ this.renderCheats();
1355
+
609
1356
  const section = panel.querySelector('[data-settings-section="system"]');
610
1357
  // Detach cartridge / hard reset controls
611
1358
  const saveSnapshotBtn = section?.querySelector(
@@ -693,6 +1440,10 @@ export default class UIController {
693
1440
  const audioContainer = panel.querySelector('#c64-audio-section-anchor') as HTMLElement;
694
1441
  this.createAudioSection(audioContainer);
695
1442
 
1443
+ // ── Ultimate section ──────────────────────────────────────────────────
1444
+ const ultimateContainer = panel.querySelector('#c64-ultimate-section-anchor') as HTMLElement;
1445
+ new UltimatePanel(ultimateContainer, () => this.player).init();
1446
+
696
1447
  // ── Input section wiring ───────────────────────────────────────────────
697
1448
  const joyRadios = panel.querySelectorAll(
698
1449
  'input[name="c64-joy-port"]',