c64-ready 0.10.0 → 0.11.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 +5 -2
- package/dist/assets/CHANGELOG-CPMeNyjb.js +261 -0
- package/dist/assets/index-CeQto0sd.js +499 -0
- package/dist/c64-ready/c64-ready.gif +0 -0
- package/dist/fonts/Commodore Angled v1.2.ttf +0 -0
- package/dist/fonts/Commodore Rounded v1.2.ttf +0 -0
- package/dist/fonts/Commodore-64-v6.3.TTF +0 -0
- package/dist/fonts/READ ME!.txt +127 -0
- package/dist/fonts/button-commodore-64-font.gif +0 -0
- package/dist/games/cartridges/bubble-bobble.crt +0 -0
- package/dist/games/cartridges/ghosts-n-goblins.crt +0 -0
- package/dist/games/snapshots/LVLLVL%BAAL.c64 +0 -0
- package/dist/games/snapshots/VICE2-4%APOLLO18.vsf +0 -0
- package/dist/games/snapshots/VICE3.10%ELEVATOR.vsf +0 -0
- package/dist/index.html +1 -1
- package/dist/tools/Keyboard-Test.prg +0 -0
- package/package.json +1 -1
- package/src/emulator/c64-emulator.ts +10 -2
- package/src/headless/headless-cli.mjs +74 -18
- package/src/headless/input-server.mjs +95 -3
- package/src/main.ts +34 -2
- package/src/player/c64-player.ts +108 -9
- package/src/player/load-formats.ts +58 -0
- package/src/player/styles/ui-controller.css +69 -2
- package/src/player/ui-controller.ts +140 -47
- package/src/types/emulator.ts +2 -1
- package/dist/assets/CHANGELOG-C1nvP1iO.js +0 -96
- package/dist/assets/index-Cioamf6E.js +0 -394
package/src/player/c64-player.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { C64Emulator } from '../emulator/c64-emulator';
|
|
2
|
+
import { domKeyToC64Actions } from '../emulator/input';
|
|
2
3
|
import { parseCrtInfo } from '../emulator/crt-info';
|
|
3
4
|
import type { GameLoadOptions } from '../types';
|
|
4
5
|
import type { JoystickPort } from '../emulator/constants';
|
|
@@ -6,6 +7,7 @@ import type { InputMode } from '../emulator/input';
|
|
|
6
7
|
import type CanvasRenderer from './canvas-renderer';
|
|
7
8
|
import { AudioEngine } from './audio-engine';
|
|
8
9
|
import InputHandler from './input-handler';
|
|
10
|
+
import { getLoadTypeLabel, inferLoadTypeFromFilename } from './load-formats';
|
|
9
11
|
|
|
10
12
|
export type ProgressCallback = (percent: number, label: string) => void;
|
|
11
13
|
|
|
@@ -38,7 +40,9 @@ export class C64Player {
|
|
|
38
40
|
this.inputHandler.attach();
|
|
39
41
|
renderer.attachTo(this.emulator);
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
if (gameUrl && gameUrl !== 'null') {
|
|
44
|
+
await this.loadGame(gameUrl, gameType, onProgress);
|
|
45
|
+
}
|
|
42
46
|
|
|
43
47
|
this.emulator.start();
|
|
44
48
|
|
|
@@ -118,7 +122,7 @@ export class C64Player {
|
|
|
118
122
|
data = new Uint8Array(await response.arrayBuffer());
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
onProgress?.(90,
|
|
125
|
+
onProgress?.(90, `INSERTING ${formatLoadProgressLabel(type)}...`);
|
|
122
126
|
// Basic validation for cartridge files — some malformed .crt files can
|
|
123
127
|
// silently fail inside the WASM loader; catch common format problems here
|
|
124
128
|
if (type === 'crt' && !isValidCRT(data)) {
|
|
@@ -132,8 +136,13 @@ export class C64Player {
|
|
|
132
136
|
const info = parseCrtInfo(data, filename);
|
|
133
137
|
if (info) console.log(info.line);
|
|
134
138
|
}
|
|
139
|
+
this.assertSnapshotFormatSupported(data, type, url);
|
|
140
|
+
this.emitSnapshotLoadInfo(type, url);
|
|
135
141
|
try {
|
|
136
142
|
this.emulator.loadGame({ type, data });
|
|
143
|
+
if (type === 'prg') {
|
|
144
|
+
await this.autoRunPrgIfRunning();
|
|
145
|
+
}
|
|
137
146
|
onProgress?.(100, 'READY!');
|
|
138
147
|
// Notify UI that load succeeded
|
|
139
148
|
window.dispatchEvent(new CustomEvent('c64-load-success', { detail: { url, type } }));
|
|
@@ -149,36 +158,42 @@ export class C64Player {
|
|
|
149
158
|
}
|
|
150
159
|
|
|
151
160
|
// Load a game from a File/Blob provided by the user (drag & drop / file input)
|
|
152
|
-
async loadFile(file: File, type
|
|
161
|
+
async loadFile(file: File, type?: GameLoadOptions['type']): Promise<void> {
|
|
153
162
|
if (!this.emulator) throw new Error('Emulator not initialised — call start() first');
|
|
154
163
|
const onProgress = this.options.onProgress;
|
|
164
|
+
const resolvedType = type ?? inferLoadTypeFromFilename(file.name) ?? 'crt';
|
|
155
165
|
try {
|
|
156
166
|
onProgress?.(20, `READING FILE ${file.name}...`);
|
|
157
167
|
const ab = await file.arrayBuffer();
|
|
158
168
|
const data = new Uint8Array(ab);
|
|
159
|
-
onProgress?.(90,
|
|
160
|
-
if (
|
|
169
|
+
onProgress?.(90, `INSERTING ${formatLoadProgressLabel(resolvedType)}...`);
|
|
170
|
+
if (resolvedType === 'crt' && !isValidCRT(data)) {
|
|
161
171
|
onProgress?.(0, 'INVALID CRT');
|
|
162
172
|
const err = new Error('Invalid CRT file format');
|
|
163
173
|
console.error(err);
|
|
164
174
|
throw err;
|
|
165
175
|
}
|
|
166
|
-
if (
|
|
176
|
+
if (resolvedType === 'crt') {
|
|
167
177
|
const info = parseCrtInfo(data, file.name);
|
|
168
178
|
if (info) console.log(info.line);
|
|
169
179
|
}
|
|
180
|
+
this.assertSnapshotFormatSupported(data, resolvedType, file.name);
|
|
181
|
+
this.emitSnapshotLoadInfo(resolvedType, file.name);
|
|
170
182
|
try {
|
|
171
|
-
this.emulator.loadGame({ type, data });
|
|
183
|
+
this.emulator.loadGame({ type: resolvedType, data });
|
|
184
|
+
if (resolvedType === 'prg') {
|
|
185
|
+
await this.autoRunPrgIfRunning();
|
|
186
|
+
}
|
|
172
187
|
onProgress?.(100, 'READY!');
|
|
173
188
|
window.dispatchEvent(
|
|
174
|
-
new CustomEvent('c64-close-dialog', { detail: { file: file.name, type } }),
|
|
189
|
+
new CustomEvent('c64-close-dialog', { detail: { file: file.name, type: resolvedType } }),
|
|
175
190
|
);
|
|
176
191
|
} catch (err) {
|
|
177
192
|
onProgress?.(0, 'FAILED');
|
|
178
193
|
console.error('Failed to insert cartridge from file:', err);
|
|
179
194
|
window.dispatchEvent(
|
|
180
195
|
new CustomEvent('c64-load-error', {
|
|
181
|
-
detail: { error: String(err), file: file.name, type },
|
|
196
|
+
detail: { error: String(err), file: file.name, type: resolvedType },
|
|
182
197
|
}),
|
|
183
198
|
);
|
|
184
199
|
throw err;
|
|
@@ -232,9 +247,93 @@ export class C64Player {
|
|
|
232
247
|
setInputMode(mode: InputMode): void {
|
|
233
248
|
this.inputHandler?.setInputMode(mode);
|
|
234
249
|
}
|
|
250
|
+
|
|
251
|
+
private async autoRunPrgIfRunning(): Promise<void> {
|
|
252
|
+
if (!this.emulator || !this.emulator.isRunning()) return;
|
|
253
|
+
await waitMs(120);
|
|
254
|
+
await this.typeCommand('run\n');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private async typeCommand(command: string): Promise<void> {
|
|
258
|
+
if (!this.emulator) return;
|
|
259
|
+
|
|
260
|
+
for (const char of command) {
|
|
261
|
+
const domKey = char === '\n' ? 'enter' : char;
|
|
262
|
+
|
|
263
|
+
const down = domKeyToC64Actions(domKey, false, 'keydown');
|
|
264
|
+
for (const act of down) {
|
|
265
|
+
if (act.action === 'press') this.emulator.keyDown(act.key);
|
|
266
|
+
else this.emulator.keyUp(act.key);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
await waitMs(22);
|
|
270
|
+
|
|
271
|
+
const up = domKeyToC64Actions(domKey, false, 'keyup');
|
|
272
|
+
for (const act of up) {
|
|
273
|
+
if (act.action === 'press') this.emulator.keyDown(act.key);
|
|
274
|
+
else this.emulator.keyUp(act.key);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
await waitMs(22);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private emitSnapshotLoadInfo(type: GameLoadOptions['type'], source: string): void {
|
|
282
|
+
if (type !== 'snapshot') return;
|
|
283
|
+
|
|
284
|
+
const mode = 'native';
|
|
285
|
+
const message = `Loading native LVL snapshot (${source})`;
|
|
286
|
+
|
|
287
|
+
console.info(`[snapshot] mode=${mode} source=${source}`);
|
|
288
|
+
window.dispatchEvent(new CustomEvent('c64-load-info', { detail: { mode, source, message } }));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private assertSnapshotFormatSupported(
|
|
292
|
+
data: Uint8Array,
|
|
293
|
+
type: GameLoadOptions['type'],
|
|
294
|
+
source: string,
|
|
295
|
+
): void {
|
|
296
|
+
if (type !== 'snapshot') return;
|
|
297
|
+
if (!hasViceSnapshotMagic(data)) return;
|
|
298
|
+
|
|
299
|
+
const err = new Error(
|
|
300
|
+
`Unsupported snapshot format for ${source}. VICE .vsf snapshots are disabled for now; use LVLLVL/native snapshots (.c64, .snapshot, .s64).`,
|
|
301
|
+
);
|
|
302
|
+
console.error(err);
|
|
303
|
+
window.dispatchEvent(
|
|
304
|
+
new CustomEvent('c64-load-info', {
|
|
305
|
+
detail: {
|
|
306
|
+
mode: 'warning',
|
|
307
|
+
source,
|
|
308
|
+
message: 'Snapshot must be LVLLVL/native format (.c64, .snapshot, .s64).',
|
|
309
|
+
},
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
312
|
+
throw err;
|
|
313
|
+
}
|
|
235
314
|
}
|
|
236
315
|
|
|
237
316
|
// CRT format validator — delegates to parseCrtInfo so magic-check logic lives in one place.
|
|
238
317
|
function isValidCRT(data: Uint8Array): boolean {
|
|
239
318
|
return parseCrtInfo(data) !== null;
|
|
240
319
|
}
|
|
320
|
+
|
|
321
|
+
function formatLoadProgressLabel(type: GameLoadOptions['type']): string {
|
|
322
|
+
const label = getLoadTypeLabel(type);
|
|
323
|
+
const suffixStart = label.indexOf(' (');
|
|
324
|
+
const plain = suffixStart > 0 ? label.slice(0, suffixStart) : label;
|
|
325
|
+
return plain.toUpperCase();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function waitMs(ms: number): Promise<void> {
|
|
329
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function hasViceSnapshotMagic(data: Uint8Array): boolean {
|
|
333
|
+
const magic = 'VICE Snapshot File\x1a';
|
|
334
|
+
if (data.length < magic.length) return false;
|
|
335
|
+
for (let i = 0; i < magic.length; i++) {
|
|
336
|
+
if (data[i] !== magic.charCodeAt(i)) return false;
|
|
337
|
+
}
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { GameLoadOptions } from '../types';
|
|
2
|
+
|
|
3
|
+
export type LoadType = GameLoadOptions['type'];
|
|
4
|
+
export type LoadTypeSelection = LoadType | 'auto';
|
|
5
|
+
|
|
6
|
+
export interface LoadFormatOption {
|
|
7
|
+
type: LoadType;
|
|
8
|
+
label: string;
|
|
9
|
+
extensions: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const LOAD_FORMAT_OPTIONS: LoadFormatOption[] = [
|
|
13
|
+
{ type: 'crt', label: 'Cartridge (.crt)', extensions: ['.crt'] },
|
|
14
|
+
{ type: 'prg', label: 'Program (.prg)', extensions: ['.prg'] },
|
|
15
|
+
{ type: 'd64', label: 'Disk image (.d64)', extensions: ['.d64'] },
|
|
16
|
+
{
|
|
17
|
+
type: 'snapshot',
|
|
18
|
+
label: 'Snapshot (.snapshot, .c64, .s64)',
|
|
19
|
+
extensions: ['.snapshot', '.c64', '.s64'],
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const LOAD_TYPE_SET = new Set<LoadType>(LOAD_FORMAT_OPTIONS.map((f) => f.type));
|
|
24
|
+
|
|
25
|
+
export function isSupportedLoadType(value: unknown): value is LoadType {
|
|
26
|
+
return typeof value === 'string' && LOAD_TYPE_SET.has(value as LoadType);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function inferLoadTypeFromFilename(filename: string): LoadType | null {
|
|
30
|
+
const lower = filename.toLowerCase();
|
|
31
|
+
for (const format of LOAD_FORMAT_OPTIONS) {
|
|
32
|
+
if (format.extensions.some((ext) => lower.endsWith(ext))) {
|
|
33
|
+
return format.type;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function resolveLoadTypeSelection(
|
|
40
|
+
selection: LoadTypeSelection,
|
|
41
|
+
filename: string,
|
|
42
|
+
fallback: LoadType = 'crt',
|
|
43
|
+
): LoadType {
|
|
44
|
+
if (selection !== 'auto') return selection;
|
|
45
|
+
return inferLoadTypeFromFilename(filename) ?? fallback;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getAcceptForLoadTypeSelection(selection: LoadTypeSelection): string {
|
|
49
|
+
const exts =
|
|
50
|
+
selection === 'auto'
|
|
51
|
+
? LOAD_FORMAT_OPTIONS.flatMap((f) => f.extensions)
|
|
52
|
+
: LOAD_FORMAT_OPTIONS.find((f) => f.type === selection)?.extensions ?? [];
|
|
53
|
+
return exts.join(',');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getLoadTypeLabel(type: LoadType): string {
|
|
57
|
+
return LOAD_FORMAT_OPTIONS.find((f) => f.type === type)?.label ?? type.toUpperCase();
|
|
58
|
+
}
|
|
@@ -262,6 +262,64 @@
|
|
|
262
262
|
}
|
|
263
263
|
.c64-menu-header { display:flex; align-items:center; justify-content:space-between; }
|
|
264
264
|
.c64-menu-close { background:none; border:none; color:#888; font-size:20px; cursor:pointer; }
|
|
265
|
+
.c64-settings-tabs {
|
|
266
|
+
display: flex;
|
|
267
|
+
gap: 8px;
|
|
268
|
+
flex-wrap: wrap;
|
|
269
|
+
margin-bottom: 12px;
|
|
270
|
+
}
|
|
271
|
+
.c64-settings-tab {
|
|
272
|
+
background: #171729;
|
|
273
|
+
border: 1px solid #353552;
|
|
274
|
+
color: #c5c5df;
|
|
275
|
+
padding: 6px 10px;
|
|
276
|
+
border-radius: 4px;
|
|
277
|
+
cursor: pointer;
|
|
278
|
+
font-size: 12px;
|
|
279
|
+
}
|
|
280
|
+
.c64-settings-tab.active {
|
|
281
|
+
border-color: #7b71d5;
|
|
282
|
+
color: #fff;
|
|
283
|
+
background: #25253d;
|
|
284
|
+
}
|
|
285
|
+
.c64-settings-section {
|
|
286
|
+
padding-top: 2px;
|
|
287
|
+
}
|
|
288
|
+
.c64-section-label {
|
|
289
|
+
display: block;
|
|
290
|
+
margin: 0 0 8px;
|
|
291
|
+
font-size: 13px;
|
|
292
|
+
color: #aaa;
|
|
293
|
+
}
|
|
294
|
+
.c64-form-row {
|
|
295
|
+
display: flex;
|
|
296
|
+
align-items: center;
|
|
297
|
+
gap: 10px;
|
|
298
|
+
margin-bottom: 10px;
|
|
299
|
+
}
|
|
300
|
+
.c64-select {
|
|
301
|
+
background: #171729;
|
|
302
|
+
color: #ddd;
|
|
303
|
+
border: 1px solid #444;
|
|
304
|
+
border-radius: 4px;
|
|
305
|
+
padding: 4px 8px;
|
|
306
|
+
font-family: monospace;
|
|
307
|
+
}
|
|
308
|
+
.c64-radio-row {
|
|
309
|
+
margin-top: 8px;
|
|
310
|
+
display: flex;
|
|
311
|
+
gap: 12px;
|
|
312
|
+
align-items: center;
|
|
313
|
+
}
|
|
314
|
+
.c64-radio-row-wrap {
|
|
315
|
+
flex-wrap: wrap;
|
|
316
|
+
}
|
|
317
|
+
.c64-section-hint {
|
|
318
|
+
margin-top: 6px;
|
|
319
|
+
font-size: 11px;
|
|
320
|
+
color: #888;
|
|
321
|
+
line-height: 1.4;
|
|
322
|
+
}
|
|
265
323
|
.c64-dragarea {
|
|
266
324
|
border: 2px dashed #2a2a3e;
|
|
267
325
|
border-radius: 6px;
|
|
@@ -271,16 +329,25 @@
|
|
|
271
329
|
color: #aaa;
|
|
272
330
|
background: linear-gradient(180deg, rgba(255,255,255,0.01), transparent);
|
|
273
331
|
}
|
|
332
|
+
.c64-dragarea button {
|
|
333
|
+
margin-left: 6px;
|
|
334
|
+
}
|
|
274
335
|
.c64-dragarea.dragover { border-color: #7b71d5; color: #fff; }
|
|
275
336
|
.c64-cart-preview { display:flex; gap:12px; align-items:center; margin-top:12px; }
|
|
276
337
|
.c64-cart-icon { width:56px; height:40px; background:#222; border:1px solid #333; display:flex; align-items:center; justify-content:center; border-radius:4px; }
|
|
277
338
|
.c64-cart-filename { font-size:13px; color:#ccc; word-break:break-all; }
|
|
339
|
+
.c64-cart-type { font-size: 11px; color: #888; margin-top: 2px; }
|
|
278
340
|
.c64-file-input { display:none; }
|
|
279
341
|
.c64-menu-actions {
|
|
280
342
|
margin-top:12px;
|
|
281
343
|
display:flex;
|
|
282
|
-
flex-
|
|
344
|
+
flex-wrap: wrap;
|
|
283
345
|
gap:8px;
|
|
284
346
|
}
|
|
347
|
+
.c64-system-actions {
|
|
348
|
+
margin-top: 4px;
|
|
349
|
+
display: flex;
|
|
350
|
+
gap: 8px;
|
|
351
|
+
flex-wrap: wrap;
|
|
352
|
+
}
|
|
285
353
|
.c64-btn { background:#222; border:1px solid #444; color:#ddd; padding:6px 10px; border-radius:4px; cursor:pointer; }
|
|
286
|
-
|
|
@@ -11,6 +11,13 @@ const CONTROLS = [
|
|
|
11
11
|
|
|
12
12
|
import type { C64Player } from './c64-player';
|
|
13
13
|
import type { JoystickPort } from '../emulator/constants';
|
|
14
|
+
import {
|
|
15
|
+
LOAD_FORMAT_OPTIONS,
|
|
16
|
+
getAcceptForLoadTypeSelection,
|
|
17
|
+
getLoadTypeLabel,
|
|
18
|
+
resolveLoadTypeSelection,
|
|
19
|
+
type LoadTypeSelection,
|
|
20
|
+
} from './load-formats';
|
|
14
21
|
|
|
15
22
|
export default class UIController {
|
|
16
23
|
private helpOverlay: HTMLElement | null = null;
|
|
@@ -149,6 +156,18 @@ export default class UIController {
|
|
|
149
156
|
if (e.target === overlay) this.closeMenu();
|
|
150
157
|
});
|
|
151
158
|
|
|
159
|
+
const sections = [
|
|
160
|
+
{ id: 'load', label: 'Load' },
|
|
161
|
+
{ id: 'input', label: 'Input' },
|
|
162
|
+
{ id: 'display', label: 'Display' },
|
|
163
|
+
{ id: 'audio', label: 'Audio' },
|
|
164
|
+
{ id: 'system', label: 'System' },
|
|
165
|
+
] as const;
|
|
166
|
+
|
|
167
|
+
const loadTypeOptions = LOAD_FORMAT_OPTIONS.map(
|
|
168
|
+
(format) => `<option value="${format.type}">${format.label}</option>`,
|
|
169
|
+
).join('');
|
|
170
|
+
|
|
152
171
|
const panel = document.createElement('div');
|
|
153
172
|
panel.className = 'c64-menu-panel';
|
|
154
173
|
panel.innerHTML = `
|
|
@@ -157,51 +176,83 @@ export default class UIController {
|
|
|
157
176
|
<button class="c64-menu-close">×</button>
|
|
158
177
|
</div>
|
|
159
178
|
<div class="c64-menu-body">
|
|
160
|
-
<
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
<label><input type="radio" name="c64-input-mode" value="keyboard" /> Keyboard</label>
|
|
170
|
-
<label><input type="radio" name="c64-input-mode" value="mixed" /> Mixed</label>
|
|
171
|
-
</div>
|
|
172
|
-
<div style="height:4px"></div>
|
|
173
|
-
<div id="c64-input-mode-hint" style="font-size:11px;color:#888;line-height:1.4">
|
|
174
|
-
Arrows + Ctrl = joystick
|
|
175
|
-
</div>
|
|
176
|
-
<div style="height:8px"></div>
|
|
177
|
-
<label style="font-size:13px;color:#aaa">Display</label>
|
|
178
|
-
<div style="margin-top:8px; display:flex; gap:12px; align-items:center;">
|
|
179
|
-
<label><input type="radio" name="c64-display-mode" value="standard" checked /> Standard</label>
|
|
180
|
-
<label><input type="radio" name="c64-display-mode" value="full" /> Full</label>
|
|
181
|
-
<label><input type="radio" name="c64-display-mode" value="stretch" /> Stretch</label>
|
|
182
|
-
</div>
|
|
183
|
-
<div style="height:8px"></div>
|
|
184
|
-
<label style="font-size:13px;color:#aaa">Load cartridge (.crt)</label>
|
|
185
|
-
<div class="c64-dragarea" id="c64-dragarea">Drop a .crt file here or <button class="c64-btn" id="c64-browse">Browse</button></div>
|
|
186
|
-
<input class="c64-file-input" id="c64-file-input" type="file" accept=".crt" />
|
|
187
|
-
<div class="c64-cart-preview" id="c64-cart-preview" style="display:none">
|
|
188
|
-
<div class="c64-cart-icon" id="c64-cart-icon" aria-hidden="true">
|
|
189
|
-
<!-- simple C64 cart SVG -->
|
|
190
|
-
<svg width="48" height="32" viewBox="0 0 48 32" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="4" width="44" height="24" rx="3" fill="#222" stroke="#555"/><rect x="6" y="8" width="36" height="12" fill="#2b2b3d"/></svg>
|
|
191
|
-
</div>
|
|
192
|
-
<div class="c64-cart-filename" id="c64-cart-filename"></div>
|
|
193
|
-
</div>
|
|
194
|
-
<div class="c64-menu-actions">
|
|
195
|
-
<div>
|
|
196
|
-
<button class="c64-btn" id="c64-load-btn">Load</button>
|
|
197
|
-
<button class="c64-btn" id="c64-close-menu">Close</button>
|
|
198
|
-
</div>
|
|
199
|
-
<div style="margin-top:12px; display:flex; gap:8px;">
|
|
200
|
-
<button class="c64-btn" id="c64-detach-btn">Detach Cartridge</button>
|
|
201
|
-
<button class="c64-btn" id="c64-reset-btn">Hard Reset</button>
|
|
202
|
-
</div>
|
|
179
|
+
<div class="c64-settings-tabs" role="tablist" aria-label="Settings sections">
|
|
180
|
+
${sections
|
|
181
|
+
.map(
|
|
182
|
+
(section, i) =>
|
|
183
|
+
`<button class="c64-settings-tab${i === 0 ? ' active' : ''}" data-settings-tab="${section.id}" role="tab" aria-selected="${
|
|
184
|
+
i === 0 ? 'true' : 'false'
|
|
185
|
+
}">${section.label}</button>`,
|
|
186
|
+
)
|
|
187
|
+
.join('')}
|
|
203
188
|
</div>
|
|
204
189
|
|
|
190
|
+
<div class="c64-settings-sections">
|
|
191
|
+
<section class="c64-settings-section" data-settings-section="load">
|
|
192
|
+
<label class="c64-section-label">Load Game</label>
|
|
193
|
+
<div class="c64-form-row">
|
|
194
|
+
<label for="c64-load-format">Format</label>
|
|
195
|
+
<select id="c64-load-format" class="c64-select">
|
|
196
|
+
<option value="auto">Auto detect (recommended)</option>
|
|
197
|
+
${loadTypeOptions}
|
|
198
|
+
</select>
|
|
199
|
+
</div>
|
|
200
|
+
<div class="c64-dragarea" id="c64-dragarea">
|
|
201
|
+
<span id="c64-dragarea-copy">Drop a game file here or</span>
|
|
202
|
+
<button class="c64-btn" id="c64-browse">Browse</button>
|
|
203
|
+
</div>
|
|
204
|
+
<input class="c64-file-input" id="c64-file-input" type="file" />
|
|
205
|
+
<div class="c64-cart-preview" id="c64-cart-preview" hidden>
|
|
206
|
+
<div class="c64-cart-icon" id="c64-cart-icon" aria-hidden="true">
|
|
207
|
+
<svg width="48" height="32" viewBox="0 0 48 32" xmlns="http://www.w3.org/2000/svg"><rect x="2" y="4" width="44" height="24" rx="3" fill="#222" stroke="#555"/><rect x="6" y="8" width="36" height="12" fill="#2b2b3d"/></svg>
|
|
208
|
+
</div>
|
|
209
|
+
<div>
|
|
210
|
+
<div class="c64-cart-filename" id="c64-cart-filename"></div>
|
|
211
|
+
<div class="c64-cart-type" id="c64-cart-type"></div>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
<div class="c64-menu-actions">
|
|
215
|
+
<button class="c64-btn" id="c64-load-btn">Load</button>
|
|
216
|
+
<button class="c64-btn" id="c64-close-menu">Close</button>
|
|
217
|
+
</div>
|
|
218
|
+
</section>
|
|
219
|
+
|
|
220
|
+
<section class="c64-settings-section" data-settings-section="input" hidden>
|
|
221
|
+
<label class="c64-section-label">Input Port</label>
|
|
222
|
+
<div class="c64-radio-row">
|
|
223
|
+
<label><input type="radio" name="c64-joy-port" value="1" /> Port 1</label>
|
|
224
|
+
<label><input type="radio" name="c64-joy-port" value="2" checked /> Port 2</label>
|
|
225
|
+
</div>
|
|
226
|
+
<label class="c64-section-label">Input Mode</label>
|
|
227
|
+
<div class="c64-radio-row c64-radio-row-wrap">
|
|
228
|
+
<label><input type="radio" name="c64-input-mode" value="joystick" checked /> Joystick</label>
|
|
229
|
+
<label><input type="radio" name="c64-input-mode" value="keyboard" /> Keyboard</label>
|
|
230
|
+
<label><input type="radio" name="c64-input-mode" value="mixed" /> Mixed</label>
|
|
231
|
+
</div>
|
|
232
|
+
<div id="c64-input-mode-hint" class="c64-section-hint">Arrows + Ctrl = joystick</div>
|
|
233
|
+
</section>
|
|
234
|
+
|
|
235
|
+
<section class="c64-settings-section" data-settings-section="display" hidden>
|
|
236
|
+
<label class="c64-section-label">Display Mode</label>
|
|
237
|
+
<div class="c64-radio-row">
|
|
238
|
+
<label><input type="radio" name="c64-display-mode" value="standard" checked /> Standard</label>
|
|
239
|
+
<label><input type="radio" name="c64-display-mode" value="full" /> Full</label>
|
|
240
|
+
<label><input type="radio" name="c64-display-mode" value="stretch" /> Stretch</label>
|
|
241
|
+
</div>
|
|
242
|
+
</section>
|
|
243
|
+
|
|
244
|
+
<section class="c64-settings-section" data-settings-section="audio" hidden>
|
|
245
|
+
<div id="c64-audio-section-anchor"></div>
|
|
246
|
+
</section>
|
|
247
|
+
|
|
248
|
+
<section class="c64-settings-section" data-settings-section="system" hidden>
|
|
249
|
+
<label class="c64-section-label">System Actions</label>
|
|
250
|
+
<div class="c64-system-actions">
|
|
251
|
+
<button class="c64-btn" id="c64-detach-btn">Detach Cartridge</button>
|
|
252
|
+
<button class="c64-btn" id="c64-reset-btn">Hard Reset</button>
|
|
253
|
+
</div>
|
|
254
|
+
</section>
|
|
255
|
+
</div>
|
|
205
256
|
</div>
|
|
206
257
|
`;
|
|
207
258
|
|
|
@@ -213,18 +264,59 @@ export default class UIController {
|
|
|
213
264
|
// The settings overlay is the overlay we just created
|
|
214
265
|
this.settingsOverlay = overlay;
|
|
215
266
|
|
|
267
|
+
const tabButtons = panel.querySelectorAll('[data-settings-tab]') as NodeListOf<HTMLButtonElement>;
|
|
268
|
+
const sectionEls = panel.querySelectorAll(
|
|
269
|
+
'[data-settings-section]'
|
|
270
|
+
) as NodeListOf<HTMLElement>;
|
|
271
|
+
|
|
272
|
+
const activateSection = (sectionId: string) => {
|
|
273
|
+
tabButtons.forEach((tab) => {
|
|
274
|
+
const active = tab.dataset.settingsTab === sectionId;
|
|
275
|
+
tab.classList.toggle('active', active);
|
|
276
|
+
tab.setAttribute('aria-selected', active ? 'true' : 'false');
|
|
277
|
+
});
|
|
278
|
+
sectionEls.forEach((section) => {
|
|
279
|
+
section.hidden = section.dataset.settingsSection !== sectionId;
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
tabButtons.forEach((tab) => {
|
|
284
|
+
tab.addEventListener('click', () => {
|
|
285
|
+
const sectionId = tab.dataset.settingsTab;
|
|
286
|
+
if (sectionId) activateSection(sectionId);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
216
290
|
// wire up file input and drag/drop
|
|
217
291
|
this.fileInput = panel.querySelector('#c64-file-input') as HTMLInputElement;
|
|
218
292
|
const dragarea = panel.querySelector('#c64-dragarea') as HTMLElement;
|
|
293
|
+
const dragareaCopy = panel.querySelector('#c64-dragarea-copy') as HTMLElement;
|
|
219
294
|
const browse = panel.querySelector('#c64-browse') as HTMLButtonElement;
|
|
295
|
+
const loadTypeSelect = panel.querySelector('#c64-load-format') as HTMLSelectElement;
|
|
220
296
|
const preview = panel.querySelector('#c64-cart-preview') as HTMLElement;
|
|
221
297
|
const previewName = panel.querySelector('#c64-cart-filename') as HTMLElement;
|
|
298
|
+
const previewType = panel.querySelector('#c64-cart-type') as HTMLElement;
|
|
299
|
+
|
|
300
|
+
const updateLoadChooser = () => {
|
|
301
|
+
const selection = (loadTypeSelect.value as LoadTypeSelection) ?? 'auto';
|
|
302
|
+
this.fileInput!.accept = getAcceptForLoadTypeSelection(selection);
|
|
303
|
+
if (selection === 'auto') {
|
|
304
|
+
dragareaCopy.textContent = 'Drop a game file here or';
|
|
305
|
+
} else {
|
|
306
|
+
dragareaCopy.textContent = `Drop a ${getLoadTypeLabel(selection)} file here or`;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
updateLoadChooser();
|
|
310
|
+
loadTypeSelect.addEventListener('change', updateLoadChooser);
|
|
222
311
|
|
|
223
312
|
const handleFile = (file: File) => {
|
|
224
|
-
|
|
313
|
+
const selection = (loadTypeSelect.value as LoadTypeSelection) ?? 'auto';
|
|
314
|
+
const loadType = resolveLoadTypeSelection(selection, file.name);
|
|
315
|
+
preview.hidden = false;
|
|
225
316
|
previewName.textContent = file.name;
|
|
317
|
+
previewType.textContent = getLoadTypeLabel(loadType);
|
|
226
318
|
// dispatch event for main code to pick up
|
|
227
|
-
const ev = new CustomEvent('c64-load-file', { detail: { file } });
|
|
319
|
+
const ev = new CustomEvent('c64-load-file', { detail: { file, type: loadType } });
|
|
228
320
|
window.dispatchEvent(ev);
|
|
229
321
|
};
|
|
230
322
|
|
|
@@ -255,7 +347,7 @@ export default class UIController {
|
|
|
255
347
|
else this.fileInput?.click();
|
|
256
348
|
});
|
|
257
349
|
|
|
258
|
-
const section =
|
|
350
|
+
const section = panel.querySelector('[data-settings-section="system"]');
|
|
259
351
|
// Detach cartridge / hard reset controls
|
|
260
352
|
const detachBtn = section?.querySelector('#c64-detach-btn') as HTMLButtonElement | null;
|
|
261
353
|
const resetBtn = section?.querySelector('#c64-reset-btn') as HTMLButtonElement | null;
|
|
@@ -284,7 +376,8 @@ export default class UIController {
|
|
|
284
376
|
}
|
|
285
377
|
|
|
286
378
|
// ── Audio section ─────────────────────────────────────────────────────
|
|
287
|
-
|
|
379
|
+
const audioContainer = panel.querySelector('#c64-audio-section-anchor') as HTMLElement;
|
|
380
|
+
this.createAudioSection(audioContainer);
|
|
288
381
|
|
|
289
382
|
// ── Input section wiring ───────────────────────────────────────────────
|
|
290
383
|
const joyRadios = panel.querySelectorAll(
|
package/src/types/emulator.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface WASMExports {
|
|
|
51
51
|
c64_insertDisk(ptr: number, len: number): void;
|
|
52
52
|
|
|
53
53
|
// Loading
|
|
54
|
-
c64_loadPRG(ptr: number, len: number): void;
|
|
54
|
+
c64_loadPRG(ptr: number, len: number, inject?: number): void;
|
|
55
55
|
c64_loadCartridge(ptr: number, len: number): void;
|
|
56
56
|
c64_removeCartridge(): void;
|
|
57
57
|
|
|
@@ -81,6 +81,7 @@ export interface WASMExports {
|
|
|
81
81
|
c64_setRegX(v: number): void;
|
|
82
82
|
c64_setRegY(v: number): void;
|
|
83
83
|
c64_setRegA(v: number): void;
|
|
84
|
+
c64_setSP?(v: number): void;
|
|
84
85
|
c64_getCycleCount(): number;
|
|
85
86
|
|
|
86
87
|
// CPU flags
|