c64-ready 1.1.0 → 2.0.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 +17 -12
- package/dist/assets/index-B3vw_7xz.js +169 -0
- package/dist/index.html +1 -1
- package/dist-ts/emulator/c64-emulator.d.ts +5 -2
- package/dist-ts/emulator/c64-emulator.d.ts.map +1 -1
- package/dist-ts/emulator/c64-emulator.js +24 -12
- package/dist-ts/emulator/c64-emulator.js.map +1 -1
- package/dist-ts/emulator/c64-wasm.d.ts +1 -1
- package/dist-ts/emulator/constants.d.ts +3 -1
- package/dist-ts/emulator/constants.d.ts.map +1 -1
- package/dist-ts/emulator/constants.js +2 -0
- package/dist-ts/emulator/constants.js.map +1 -1
- package/dist-ts/emulator/input.d.ts +26 -3
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +287 -10
- 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/audio-engine.d.ts +73 -0
- package/dist-ts/player/audio-engine.d.ts.map +1 -0
- package/dist-ts/{src/player → player}/audio-engine.js +7 -2
- package/dist-ts/player/audio-engine.js.map +1 -0
- package/dist-ts/player/c64-player.d.ts +69 -0
- package/dist-ts/player/c64-player.d.ts.map +1 -0
- package/dist-ts/player/c64-player.js +416 -0
- package/dist-ts/player/c64-player.js.map +1 -0
- package/dist-ts/player/canvas-renderer.d.ts +21 -0
- package/dist-ts/player/canvas-renderer.d.ts.map +1 -0
- package/dist-ts/{src/player → player}/canvas-renderer.js +55 -44
- package/dist-ts/player/canvas-renderer.js.map +1 -0
- package/dist-ts/player/index.d.ts +10 -0
- package/dist-ts/player/index.d.ts.map +1 -0
- package/dist-ts/player/index.js +6 -0
- package/dist-ts/player/index.js.map +1 -0
- package/dist-ts/player/input-handler.d.ts +21 -0
- package/dist-ts/player/input-handler.d.ts.map +1 -0
- package/dist-ts/player/input-handler.js +122 -0
- package/dist-ts/player/input-handler.js.map +1 -0
- package/dist-ts/player/load-formats.d.ts +15 -0
- package/dist-ts/player/load-formats.d.ts.map +1 -0
- package/dist-ts/player/load-formats.js +38 -0
- package/dist-ts/player/load-formats.js.map +1 -0
- package/dist-ts/player/ui-controller.d.ts +44 -0
- package/dist-ts/player/ui-controller.d.ts.map +1 -0
- package/dist-ts/player/ui-controller.js +844 -0
- package/dist-ts/player/ui-controller.js.map +1 -0
- package/dist-ts/types/emulator.d.ts +2 -2
- package/dist-ts/types/emulator.d.ts.map +1 -1
- package/package.json +31 -3
- package/src/emulator/c64-emulator.ts +15 -5
- package/src/emulator/constants.ts +5 -1
- package/src/emulator/input.ts +131 -39
- package/src/headless/webrtc-server.mjs +73 -8
- package/src/player/audio-engine.ts +13 -2
- package/src/player/c64-player.ts +128 -58
- package/src/player/canvas-renderer.ts +57 -5
- package/src/player/index.ts +7 -0
- package/src/player/ui-controller.ts +34 -14
- package/src/types/emulator.ts +1 -1
- package/dist/assets/CHANGELOG-0a7A8Ekq.js +0 -391
- package/dist/assets/index-BESofQoh.js +0 -627
- package/dist-ts/emulator/c64-emulator.test.js +0 -104
- package/dist-ts/emulator/c64-wasm.test.js +0 -65
- package/dist-ts/emulator/input.test.js +0 -53
- package/dist-ts/src/counter.js +0 -9
- package/dist-ts/src/emulator/c64-emulator.js +0 -308
- package/dist-ts/src/emulator/c64-emulator.test.js +0 -104
- package/dist-ts/src/emulator/c64-wasm.js +0 -149
- package/dist-ts/src/emulator/c64-wasm.test.js +0 -65
- package/dist-ts/src/emulator/constants.js +0 -9
- package/dist-ts/src/emulator/input.js +0 -62
- package/dist-ts/src/emulator/input.test.js +0 -53
- package/dist-ts/src/emulator/memory.js +0 -1
- package/dist-ts/src/headless/audio-capture.js +0 -23
- package/dist-ts/src/headless/c64-headless.js +0 -85
- package/dist-ts/src/headless/ffmpeg-runner.js +0 -33
- package/dist-ts/src/headless/frame-capture.js +0 -23
- package/dist-ts/src/headless/headless.cli.test.js +0 -46
- package/dist-ts/src/headless/input-bridge.js +0 -37
- package/dist-ts/src/main.js +0 -57
- package/dist-ts/src/player/audio-engine.test.js +0 -284
- package/dist-ts/src/player/c64-player.js +0 -105
- package/dist-ts/src/player/c64-player.test.js +0 -165
- package/dist-ts/src/player/canvas-renderer.test.js +0 -135
- package/dist-ts/src/player/input-handler.js +0 -13
- package/dist-ts/src/player/ui-controller.js +0 -575
- package/dist-ts/src/player/ui-controller.test.js +0 -67
- package/dist-ts/src/types/emulator.js +0 -1
- package/dist-ts/src/types/index.js +0 -4
- package/dist-ts/tools/run-wrapper.js +0 -36
- /package/dist/assets/{marked.esm-BOXuzyNF.js → marked.esm--kBm026b.js} +0 -0
- /package/dist/assets/{purify.es-y41lKIN9.js → purify.es-BcoGFDcJ.js} +0 -0
|
@@ -0,0 +1,844 @@
|
|
|
1
|
+
const css = `
|
|
2
|
+
.c64-help-btn,.c64-hamburger,.c64-unmute-btn{position:fixed;top:12px;width:36px;height:36px;border-radius:6px;border:2px solid #444;background:#111;color:#ddd;cursor:pointer;display:flex;align-items:center;justify-content:center;z-index:1000}.c64-help-btn{right:12px;border-radius:50%;color:#7b71d5;font-family:monospace;font-size:18px;font-weight:bold}.c64-hamburger{left:12px;font-family:monospace}.c64-unmute-btn{left:56px;color:#f44;z-index:1010}.c64-unmute-btn.hidden{opacity:0;pointer-events:none}.c64-help-overlay,.c64-menu-overlay{position:fixed;inset:0;background:rgba(0,0,0,.7);display:flex;align-items:center;justify-content:center;z-index:1001;opacity:0;transition:opacity .25s ease;pointer-events:none}.c64-help-overlay.visible,.c64-menu-overlay.visible{opacity:1;pointer-events:auto}.c64-help-dialog,.c64-menu-panel{background:#1a1a2e;border:2px solid #555;border-radius:6px;padding:24px 32px;max-width:760px;width:90%;font-family:monospace;color:#ccc;position:relative}.c64-changelog-dialog{max-height:70vh;overflow:auto}.c64-help-dialog h2{margin:0 0 8px;font-size:16px;color:#7b71d5;letter-spacing:1px}.c64-help-dialog p{margin:0 0 16px;font-size:13px;line-height:1.5;color:#aaa}.c64-help-dialog a{color:#a8a8ff;text-decoration:none}.c64-help-controls,.c64-help-special{margin:0 0 12px;padding:0;list-style:none;font-size:13px}.c64-help-controls li,.c64-help-special li{display:flex;justify-content:space-between;padding:4px 0;border-bottom:1px solid #2a2a3e}.c64-help-key{background:#2a2a3e;border:1px solid #444;border-radius:3px;padding:1px 8px;font-size:12px;color:#ddd}.c64-help-close{position:absolute;top:10px;right:14px;background:none;border:none;color:#888;font-size:20px;cursor:pointer}.c64-version{display:flex;justify-content:end;font-size:12px;color:#999;margin-top:36px}.c64-menu-overlay{align-items:flex-start;justify-content:flex-start;padding:48px 24px;background:rgba(0,0,0,.5);z-index:1002}.c64-menu-panel{min-width:320px;max-width:520px;padding:16px;background:#0f0f1a;border-color:#333}.c64-menu-header{display:flex;align-items:center;justify-content:space-between}.c64-settings-tabs,.c64-menu-actions,.c64-system-actions,.c64-radio-row,.c64-gamepad-list{display:flex;gap:8px;flex-wrap:wrap}.c64-settings-tab,.c64-btn,.c64-mute-btn{background:#222;border:1px solid #444;color:#ddd;padding:6px 10px;border-radius:4px;cursor:pointer}.c64-settings-tab.active,.c64-gamepad-btn.active{border-color:#7b71d5;color:#fff;background:#25253d}.c64-select{background:#171729;color:#ddd;border:1px solid #444;border-radius:4px;padding:4px 8px;font-family:monospace}.c64-form-row,.c64-audio-row,.c64-cart-preview{display:flex;align-items:center;gap:10px;margin-bottom:10px}.c64-section-label,.c64-audio-section label{display:block;margin:0 0 8px;font-size:13px;color:#aaa}.c64-section-hint,.c64-volume-label,.c64-cart-type{font-size:11px;color:#888}.c64-dragarea{border:2px dashed #2a2a3e;border-radius:6px;padding:12px;margin-top:12px;text-align:center;color:#aaa}.c64-dragarea.dragover{border-color:#7b71d5;color:#fff}.c64-file-input{display:none}.c64-volume-slider{flex:1}.c64-cart-filename{font-size:13px;color:#ccc;word-break:break-all}.c64-checkbox-row{display:inline-flex;gap:8px;align-items:center;color:#ccc;font-size:13px}
|
|
3
|
+
`;
|
|
4
|
+
function resolveAssetUrl(baseUrl, path) {
|
|
5
|
+
const base = baseUrl ?? '/';
|
|
6
|
+
return `${base.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
|
|
7
|
+
}
|
|
8
|
+
const CONTROLS = [
|
|
9
|
+
['Move Up', '↑'],
|
|
10
|
+
['Move Down', '↓'],
|
|
11
|
+
['Move Left', '←'],
|
|
12
|
+
['Move Right', '→'],
|
|
13
|
+
['Fire', 'Z or Left Ctrl'],
|
|
14
|
+
];
|
|
15
|
+
const SPECIAL_KEYS = [
|
|
16
|
+
['Run/Stop', 'Esc'],
|
|
17
|
+
['Restore', '(currently unsupported)'],
|
|
18
|
+
['Insert/Delete', 'Backspace or Delete'],
|
|
19
|
+
['Clear/Home', 'Home'],
|
|
20
|
+
['Commodore', 'Ctrl or Caps Lock'],
|
|
21
|
+
['Control', 'Tab'],
|
|
22
|
+
['Arrow Left glyph', '`'],
|
|
23
|
+
['Arrow Up glyph', '^ or ~'],
|
|
24
|
+
['Pound', '\\'],
|
|
25
|
+
['Colon / Semicolon', ': ; [ ]'],
|
|
26
|
+
['Slash', '/ ?'],
|
|
27
|
+
['Comma / Period', ', . < >'],
|
|
28
|
+
['C64 function keys', 'F1-F8'],
|
|
29
|
+
];
|
|
30
|
+
import { LOAD_FORMAT_OPTIONS, getAcceptForLoadTypeSelection, getLoadTypeLabel, inferLoadTypeFromFilename, resolveLoadTypeSelection, } from './load-formats.js';
|
|
31
|
+
const CRT_PRELOAD_CHECKS_STORAGE_KEY = 'c64-disable-crt-preload-checks';
|
|
32
|
+
function formatSnapshotFilename(now = new Date()) {
|
|
33
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
34
|
+
return `snapshot-${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}.c64`;
|
|
35
|
+
}
|
|
36
|
+
export default class UIController {
|
|
37
|
+
helpOverlay = null;
|
|
38
|
+
settingsOverlay = null;
|
|
39
|
+
fileInput = null;
|
|
40
|
+
player = null;
|
|
41
|
+
options;
|
|
42
|
+
// Save previous overflow styles so we can restore them when exiting full/stretch
|
|
43
|
+
savedHtmlOverflow = null;
|
|
44
|
+
savedBodyOverflow = null;
|
|
45
|
+
connectedGamepads = new Map();
|
|
46
|
+
handleControllerConnected = (event) => {
|
|
47
|
+
const detail = event.detail;
|
|
48
|
+
if (typeof detail?.index !== 'number')
|
|
49
|
+
return;
|
|
50
|
+
this.connectedGamepads.set(detail.index, {
|
|
51
|
+
index: detail.index,
|
|
52
|
+
name: detail.name ?? `Gamepad ${detail.index}`,
|
|
53
|
+
});
|
|
54
|
+
this.renderGamepadButtons();
|
|
55
|
+
};
|
|
56
|
+
handleControllerDisconnected = (event) => {
|
|
57
|
+
const detail = event.detail;
|
|
58
|
+
if (typeof detail?.index !== 'number')
|
|
59
|
+
return;
|
|
60
|
+
this.connectedGamepads.delete(detail.index);
|
|
61
|
+
this.renderGamepadButtons();
|
|
62
|
+
};
|
|
63
|
+
constructor(options = {}) {
|
|
64
|
+
this.options = options;
|
|
65
|
+
}
|
|
66
|
+
init(player) {
|
|
67
|
+
this.player = player ?? null;
|
|
68
|
+
this.syncConnectedGamepads();
|
|
69
|
+
this.injectCSS();
|
|
70
|
+
this.createButton();
|
|
71
|
+
this.createDialog();
|
|
72
|
+
this.createHamburger();
|
|
73
|
+
this.createMenu();
|
|
74
|
+
this.createUnmuteButton();
|
|
75
|
+
window.addEventListener('c64-controller-connected', this.handleControllerConnected);
|
|
76
|
+
window.addEventListener('c64-controller-disconnected', this.handleControllerDisconnected);
|
|
77
|
+
}
|
|
78
|
+
syncConnectedGamepads() {
|
|
79
|
+
this.connectedGamepads.clear();
|
|
80
|
+
const gamepads = navigator.getGamepads?.() ?? [];
|
|
81
|
+
for (const gamepad of gamepads) {
|
|
82
|
+
if (!gamepad)
|
|
83
|
+
continue;
|
|
84
|
+
this.connectedGamepads.set(gamepad.index, {
|
|
85
|
+
index: gamepad.index,
|
|
86
|
+
name: gamepad.id,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
getConnectedGamepads() {
|
|
91
|
+
return Array.from(this.connectedGamepads.values()).sort((a, b) => a.index - b.index);
|
|
92
|
+
}
|
|
93
|
+
getGamepadLabel(gamepad) {
|
|
94
|
+
const shortenedName = gamepad.name.replace(/\s*\([^)]*\)\s*$/u, '').trim();
|
|
95
|
+
const name = shortenedName || gamepad.name.trim() || `Gamepad ${gamepad.index}`;
|
|
96
|
+
return `${gamepad.index}: ${name}`;
|
|
97
|
+
}
|
|
98
|
+
renderGamepadButtons() {
|
|
99
|
+
const container = document.getElementById('c64-gamepad-list');
|
|
100
|
+
const emptyState = document.getElementById('c64-gamepad-empty');
|
|
101
|
+
if (!container || !emptyState)
|
|
102
|
+
return;
|
|
103
|
+
const gamepads = this.getConnectedGamepads();
|
|
104
|
+
const activeIndex = this.player?.getActiveGamepadIndex() ?? -1;
|
|
105
|
+
container.replaceChildren(...gamepads.map((gamepad) => {
|
|
106
|
+
const button = document.createElement('button');
|
|
107
|
+
const active = gamepad.index === activeIndex;
|
|
108
|
+
button.type = 'button';
|
|
109
|
+
button.className = `c64-btn c64-gamepad-btn${active ? ' active' : ''}`;
|
|
110
|
+
button.textContent = this.getGamepadLabel(gamepad);
|
|
111
|
+
button.setAttribute('aria-pressed', active ? 'true' : 'false');
|
|
112
|
+
button.addEventListener('click', () => {
|
|
113
|
+
if (!this.player)
|
|
114
|
+
return;
|
|
115
|
+
this.player.setActiveGamepadIndex(gamepad.index);
|
|
116
|
+
this.renderGamepadButtons();
|
|
117
|
+
});
|
|
118
|
+
return button;
|
|
119
|
+
}));
|
|
120
|
+
emptyState.hidden = gamepads.length > 0;
|
|
121
|
+
}
|
|
122
|
+
downloadSnapshot(snapshot) {
|
|
123
|
+
const snapshotCopy = new Uint8Array(snapshot.byteLength);
|
|
124
|
+
snapshotCopy.set(snapshot);
|
|
125
|
+
const blob = new Blob([snapshotCopy], { type: 'application/bin' });
|
|
126
|
+
const url = URL.createObjectURL(blob);
|
|
127
|
+
const link = document.createElement('a');
|
|
128
|
+
link.href = url;
|
|
129
|
+
link.download = formatSnapshotFilename();
|
|
130
|
+
document.body.appendChild(link);
|
|
131
|
+
link.click();
|
|
132
|
+
link.remove();
|
|
133
|
+
URL.revokeObjectURL(url);
|
|
134
|
+
}
|
|
135
|
+
injectCSS() {
|
|
136
|
+
if (document.querySelector('style[data-c64-help]'))
|
|
137
|
+
return;
|
|
138
|
+
const style = document.createElement('style');
|
|
139
|
+
style.setAttribute('data-c64-help', '');
|
|
140
|
+
style.textContent = css;
|
|
141
|
+
document.head.appendChild(style);
|
|
142
|
+
}
|
|
143
|
+
getVersionLabel() {
|
|
144
|
+
const version = this.options.appVersion ?? '0.0.0';
|
|
145
|
+
const gitHash = this.options.gitHash;
|
|
146
|
+
return `v${version}${gitHash ? ` (build: ${gitHash})` : ''}`;
|
|
147
|
+
}
|
|
148
|
+
createButton() {
|
|
149
|
+
const btn = document.createElement('button');
|
|
150
|
+
btn.className = 'c64-help-btn';
|
|
151
|
+
btn.textContent = '?';
|
|
152
|
+
btn.title = 'Help';
|
|
153
|
+
btn.addEventListener('click', () => this.open());
|
|
154
|
+
document.body.appendChild(btn);
|
|
155
|
+
}
|
|
156
|
+
createDialog() {
|
|
157
|
+
const overlay = document.createElement('div');
|
|
158
|
+
overlay.className = 'c64-help-overlay';
|
|
159
|
+
overlay.addEventListener('click', (e) => {
|
|
160
|
+
if (e.target === overlay)
|
|
161
|
+
this.close();
|
|
162
|
+
});
|
|
163
|
+
const controlItems = CONTROLS.map(([action, key]) => `<li><span>${action}</span><span class="c64-help-key">${key}</span></li>`).join('');
|
|
164
|
+
const specialItems = SPECIAL_KEYS.map(([action, key]) => `<li><span>${action}</span><span class="c64-help-key">${key}</span></li>`).join('');
|
|
165
|
+
overlay.innerHTML = `
|
|
166
|
+
<div class="c64-help-dialog">
|
|
167
|
+
<button class="c64-help-close">×</button>
|
|
168
|
+
<h2>C64 READY</h2>
|
|
169
|
+
<p>A Commodore 64 emulator running in the browser via WebAssembly.</p>
|
|
170
|
+
<p><a href="https://github.com/hayesmaker/c64-ready" target="_blank" rel="noopener">Source code on GitHub</a> · <a href="#" id="c64-view-changelog">View changelog</a></p>
|
|
171
|
+
<h2>CONTROLS</h2>
|
|
172
|
+
<ul class="c64-help-controls">${controlItems}</ul>
|
|
173
|
+
<h2>SPECIAL KEYS</h2>
|
|
174
|
+
<ul class="c64-help-special">${specialItems}</ul>
|
|
175
|
+
<div class="c64-version">${this.getVersionLabel()}</div>
|
|
176
|
+
</div>
|
|
177
|
+
`;
|
|
178
|
+
overlay.querySelector('.c64-help-close').addEventListener('click', () => this.close());
|
|
179
|
+
document.body.appendChild(overlay);
|
|
180
|
+
this.helpOverlay = overlay;
|
|
181
|
+
// Create changelog modal container (hidden by default)
|
|
182
|
+
const changelogOverlay = document.createElement('div');
|
|
183
|
+
changelogOverlay.className = 'c64-help-overlay';
|
|
184
|
+
changelogOverlay.style.zIndex = '1003';
|
|
185
|
+
changelogOverlay.innerHTML = `
|
|
186
|
+
<div class="c64-help-dialog c64-changelog-dialog">
|
|
187
|
+
<button class="c64-help-close">×</button>
|
|
188
|
+
<h2>CHANGELOG</h2>
|
|
189
|
+
<div id="c64-changelog-content">Loading...</div>
|
|
190
|
+
</div>
|
|
191
|
+
`;
|
|
192
|
+
changelogOverlay
|
|
193
|
+
.querySelector('.c64-help-close')
|
|
194
|
+
.addEventListener('click', () => changelogOverlay.classList.remove('visible'));
|
|
195
|
+
document.body.appendChild(changelogOverlay);
|
|
196
|
+
// Wire the changelog link
|
|
197
|
+
const changelogLink = overlay.querySelector('#c64-view-changelog');
|
|
198
|
+
if (changelogLink) {
|
|
199
|
+
changelogLink.addEventListener('click', (ev) => {
|
|
200
|
+
ev.preventDefault();
|
|
201
|
+
// Load changelog content (bundled via raw import if available)
|
|
202
|
+
this.loadAndShowChangelog(changelogOverlay);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async loadAndShowChangelog(container) {
|
|
207
|
+
container.classList.add('visible');
|
|
208
|
+
try {
|
|
209
|
+
const res = await fetch(this.options.changelogUrl ?? resolveAssetUrl(this.options.assetBaseUrl, 'CHANGELOG.md'), {
|
|
210
|
+
cache: 'no-store',
|
|
211
|
+
});
|
|
212
|
+
if (!res.ok)
|
|
213
|
+
throw new Error(`HTTP ${res.status}`);
|
|
214
|
+
const raw = await res.text();
|
|
215
|
+
// Filter: keep headers, blank lines, and only feat:/fix: bullet lines
|
|
216
|
+
const filtered = raw
|
|
217
|
+
.split('\n')
|
|
218
|
+
.filter((line) => {
|
|
219
|
+
const trimmed = line.trim();
|
|
220
|
+
// Keep headings, blank lines, and non-list-item lines (e.g. intro text)
|
|
221
|
+
if (!trimmed.startsWith('- '))
|
|
222
|
+
return true;
|
|
223
|
+
// Keep only feat: and fix: entries
|
|
224
|
+
return /^- (feat|fix)[:(]/.test(trimmed);
|
|
225
|
+
})
|
|
226
|
+
.join('\n');
|
|
227
|
+
const [{ marked }, DOMPurify] = await Promise.all([import('marked'), import('dompurify')]);
|
|
228
|
+
const html = DOMPurify.default.sanitize(marked.parse(filtered));
|
|
229
|
+
const el = container.querySelector('#c64-changelog-content');
|
|
230
|
+
el.innerHTML = html;
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
const el = container.querySelector('#c64-changelog-content');
|
|
234
|
+
el.innerHTML = '<p>No changelog found.</p>';
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
createHamburger() {
|
|
238
|
+
const btn = document.createElement('button');
|
|
239
|
+
btn.className = 'c64-hamburger';
|
|
240
|
+
btn.innerHTML = '☰';
|
|
241
|
+
btn.title = 'Menu';
|
|
242
|
+
btn.addEventListener('click', () => this.toggleMenu());
|
|
243
|
+
document.body.appendChild(btn);
|
|
244
|
+
}
|
|
245
|
+
createMenu() {
|
|
246
|
+
const overlay = document.createElement('div');
|
|
247
|
+
overlay.className = 'c64-menu-overlay';
|
|
248
|
+
overlay.addEventListener('click', (e) => {
|
|
249
|
+
if (e.target === overlay)
|
|
250
|
+
this.closeMenu();
|
|
251
|
+
});
|
|
252
|
+
const sections = [
|
|
253
|
+
{ id: 'load', label: 'Load' },
|
|
254
|
+
{ id: 'input', label: 'Input' },
|
|
255
|
+
{ id: 'display', label: 'Display' },
|
|
256
|
+
{ id: 'audio', label: 'Audio' },
|
|
257
|
+
{ id: 'system', label: 'System' },
|
|
258
|
+
];
|
|
259
|
+
const loadTypeOptions = LOAD_FORMAT_OPTIONS.map((format) => `<option value="${format.type}">${format.label}</option>`).join('');
|
|
260
|
+
const panel = document.createElement('div');
|
|
261
|
+
panel.className = 'c64-menu-panel';
|
|
262
|
+
panel.innerHTML = `
|
|
263
|
+
<div class="c64-menu-header">
|
|
264
|
+
<h2>Settings</h2>
|
|
265
|
+
<button class="c64-menu-close">×</button>
|
|
266
|
+
</div>
|
|
267
|
+
<div class="c64-menu-body">
|
|
268
|
+
<div class="c64-settings-tabs" role="tablist" aria-label="Settings sections">
|
|
269
|
+
${sections
|
|
270
|
+
.map((section, i) => `<button class="c64-settings-tab${i === 0 ? ' active' : ''}" data-settings-tab="${section.id}" role="tab" aria-selected="${i === 0 ? 'true' : 'false'}">${section.label}</button>`)
|
|
271
|
+
.join('')}
|
|
272
|
+
</div>
|
|
273
|
+
|
|
274
|
+
<div class="c64-settings-sections">
|
|
275
|
+
<section class="c64-settings-section" data-settings-section="load">
|
|
276
|
+
<label class="c64-section-label">Load Game</label>
|
|
277
|
+
<div class="c64-form-row">
|
|
278
|
+
<label for="c64-load-format">Format</label>
|
|
279
|
+
<select id="c64-load-format" class="c64-select">
|
|
280
|
+
<option value="auto">Auto detect (recommended)</option>
|
|
281
|
+
${loadTypeOptions}
|
|
282
|
+
</select>
|
|
283
|
+
</div>
|
|
284
|
+
<div class="c64-dragarea" id="c64-dragarea">
|
|
285
|
+
<span id="c64-dragarea-copy">Drop a game file here or</span>
|
|
286
|
+
<button class="c64-btn" id="c64-browse">Browse</button>
|
|
287
|
+
</div>
|
|
288
|
+
<input class="c64-file-input" id="c64-file-input" type="file" />
|
|
289
|
+
<div class="c64-cart-preview" id="c64-cart-preview" hidden>
|
|
290
|
+
<div class="c64-cart-icon" id="c64-cart-icon" aria-hidden="true">
|
|
291
|
+
<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>
|
|
292
|
+
</div>
|
|
293
|
+
<div>
|
|
294
|
+
<div class="c64-cart-filename" id="c64-cart-filename"></div>
|
|
295
|
+
<div class="c64-cart-type" id="c64-cart-type"></div>
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
<div class="c64-menu-actions">
|
|
299
|
+
<button class="c64-btn" id="c64-load-btn">Load</button>
|
|
300
|
+
<button class="c64-btn" id="c64-close-menu">Close</button>
|
|
301
|
+
</div>
|
|
302
|
+
<div class="c64-tools-section">
|
|
303
|
+
<label class="c64-section-label">Tools</label>
|
|
304
|
+
<div class="c64-form-row">
|
|
305
|
+
<select id="c64-tool-select" class="c64-select c64-tool-select" disabled>
|
|
306
|
+
<option value="">No tools found</option>
|
|
307
|
+
</select>
|
|
308
|
+
<button class="c64-btn" id="c64-load-tool-btn" disabled>Load Tool</button>
|
|
309
|
+
</div>
|
|
310
|
+
<div class="c64-section-hint" id="c64-tools-status">Loading tools…</div>
|
|
311
|
+
</div>
|
|
312
|
+
</section>
|
|
313
|
+
|
|
314
|
+
<section class="c64-settings-section" data-settings-section="input" hidden>
|
|
315
|
+
<label class="c64-section-label">Input Port</label>
|
|
316
|
+
<div class="c64-radio-row">
|
|
317
|
+
<label><input type="radio" name="c64-joy-port" value="1" /> Port 1</label>
|
|
318
|
+
<label><input type="radio" name="c64-joy-port" value="2" checked /> Port 2</label>
|
|
319
|
+
</div>
|
|
320
|
+
<label class="c64-section-label">Input Mode</label>
|
|
321
|
+
<div class="c64-radio-row c64-radio-row-wrap">
|
|
322
|
+
<label><input type="radio" name="c64-input-mode" value="joystick" /> Joystick</label>
|
|
323
|
+
<label><input type="radio" name="c64-input-mode" value="keyboard" /> Keyboard</label>
|
|
324
|
+
<label><input type="radio" name="c64-input-mode" value="mixed" checked /> Mixed</label>
|
|
325
|
+
</div>
|
|
326
|
+
<div id="c64-input-mode-hint" class="c64-section-hint">Arrows + Z + Ctrl = joystick & all other keys → C64 keyboard</div>
|
|
327
|
+
<label class="c64-section-label">Gamepads</label>
|
|
328
|
+
<div id="c64-gamepad-list" class="c64-gamepad-list"></div>
|
|
329
|
+
<div id="c64-gamepad-empty" class="c64-section-hint">To use a gamepad, connect it to your computer and press any button.</div>
|
|
330
|
+
</section>
|
|
331
|
+
|
|
332
|
+
<section class="c64-settings-section" data-settings-section="display" hidden>
|
|
333
|
+
<label class="c64-section-label">Display Mode</label>
|
|
334
|
+
<div class="c64-radio-row">
|
|
335
|
+
<label><input type="radio" name="c64-display-mode" value="standard" checked /> Standard</label>
|
|
336
|
+
<label><input type="radio" name="c64-display-mode" value="full" /> Full</label>
|
|
337
|
+
<label><input type="radio" name="c64-display-mode" value="stretch" /> Stretch</label>
|
|
338
|
+
</div>
|
|
339
|
+
</section>
|
|
340
|
+
|
|
341
|
+
<section class="c64-settings-section" data-settings-section="audio" hidden>
|
|
342
|
+
<div id="c64-audio-section-anchor"></div>
|
|
343
|
+
</section>
|
|
344
|
+
|
|
345
|
+
<section class="c64-settings-section" data-settings-section="system" hidden>
|
|
346
|
+
<label class="c64-section-label">System Actions</label>
|
|
347
|
+
<div class="c64-system-actions">
|
|
348
|
+
<button class="c64-btn" id="c64-save-snapshot-btn">Save Snapshot</button>
|
|
349
|
+
<button class="c64-btn" id="c64-detach-btn">Detach Cartridge</button>
|
|
350
|
+
<button class="c64-btn" id="c64-reset-btn">Hard Reset</button>
|
|
351
|
+
<button class="c64-btn" id="c64-reboot-btn">Reboot Emulator</button>
|
|
352
|
+
</div>
|
|
353
|
+
<label class="c64-checkbox-row" for="c64-disable-crt-preload-checks">
|
|
354
|
+
<input type="checkbox" id="c64-disable-crt-preload-checks" />
|
|
355
|
+
Disable crt preload checks
|
|
356
|
+
</label>
|
|
357
|
+
<div class="c64-section-hint">Allows any .crt file and skips compatibility prechecks.</div>
|
|
358
|
+
</section>
|
|
359
|
+
</div>
|
|
360
|
+
</div>
|
|
361
|
+
`;
|
|
362
|
+
panel.querySelector('.c64-menu-close').addEventListener('click', () => this.closeMenu());
|
|
363
|
+
panel.querySelector('#c64-close-menu').addEventListener('click', () => this.closeMenu());
|
|
364
|
+
overlay.appendChild(panel);
|
|
365
|
+
document.body.appendChild(overlay);
|
|
366
|
+
// The settings overlay is the overlay we just created
|
|
367
|
+
this.settingsOverlay = overlay;
|
|
368
|
+
const tabButtons = panel.querySelectorAll('[data-settings-tab]');
|
|
369
|
+
const sectionEls = panel.querySelectorAll('[data-settings-section]');
|
|
370
|
+
const activateSection = (sectionId) => {
|
|
371
|
+
tabButtons.forEach((tab) => {
|
|
372
|
+
const active = tab.getAttribute('data-settings-tab') === sectionId;
|
|
373
|
+
tab.classList.toggle('active', active);
|
|
374
|
+
tab.setAttribute('aria-selected', active ? 'true' : 'false');
|
|
375
|
+
});
|
|
376
|
+
sectionEls.forEach((section) => {
|
|
377
|
+
section.hidden = section.getAttribute('data-settings-section') !== sectionId;
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
tabButtons.forEach((tab) => {
|
|
381
|
+
tab.addEventListener('click', () => {
|
|
382
|
+
const sectionId = tab.getAttribute('data-settings-tab');
|
|
383
|
+
if (sectionId)
|
|
384
|
+
activateSection(sectionId);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
// wire up file input and drag/drop
|
|
388
|
+
this.fileInput = panel.querySelector('#c64-file-input');
|
|
389
|
+
const dragarea = panel.querySelector('#c64-dragarea');
|
|
390
|
+
const dragareaCopy = panel.querySelector('#c64-dragarea-copy');
|
|
391
|
+
const browse = panel.querySelector('#c64-browse');
|
|
392
|
+
const loadTypeSelect = panel.querySelector('#c64-load-format');
|
|
393
|
+
const toolSelect = panel.querySelector('#c64-tool-select');
|
|
394
|
+
const loadToolBtn = panel.querySelector('#c64-load-tool-btn');
|
|
395
|
+
const toolsStatus = panel.querySelector('#c64-tools-status');
|
|
396
|
+
const preview = panel.querySelector('#c64-cart-preview');
|
|
397
|
+
const previewName = panel.querySelector('#c64-cart-filename');
|
|
398
|
+
const previewType = panel.querySelector('#c64-cart-type');
|
|
399
|
+
const updateLoadChooser = () => {
|
|
400
|
+
const selection = loadTypeSelect.value ?? 'auto';
|
|
401
|
+
this.fileInput.accept = getAcceptForLoadTypeSelection(selection);
|
|
402
|
+
if (selection === 'auto') {
|
|
403
|
+
dragareaCopy.textContent = 'Drop a game file here or';
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
dragareaCopy.textContent = `Drop a ${getLoadTypeLabel(selection)} file here or`;
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
updateLoadChooser();
|
|
410
|
+
loadTypeSelect.addEventListener('change', updateLoadChooser);
|
|
411
|
+
const handleFile = (file) => {
|
|
412
|
+
const selection = loadTypeSelect.value ?? 'auto';
|
|
413
|
+
const loadType = resolveLoadTypeSelection(selection, file.name);
|
|
414
|
+
preview.hidden = false;
|
|
415
|
+
previewName.textContent = file.name;
|
|
416
|
+
previewType.textContent = getLoadTypeLabel(loadType);
|
|
417
|
+
// dispatch event for main code to pick up
|
|
418
|
+
const ev = new CustomEvent('c64-load-file', { detail: { file, type: loadType } });
|
|
419
|
+
window.dispatchEvent(ev);
|
|
420
|
+
};
|
|
421
|
+
dragarea.addEventListener('dragover', (e) => {
|
|
422
|
+
e.preventDefault();
|
|
423
|
+
dragarea.classList.add('dragover');
|
|
424
|
+
});
|
|
425
|
+
dragarea.addEventListener('dragleave', () => {
|
|
426
|
+
dragarea.classList.remove('dragover');
|
|
427
|
+
});
|
|
428
|
+
dragarea.addEventListener('drop', (e) => {
|
|
429
|
+
e.preventDefault();
|
|
430
|
+
dragarea.classList.remove('dragover');
|
|
431
|
+
const f = e.dataTransfer?.files?.[0];
|
|
432
|
+
if (f)
|
|
433
|
+
handleFile(f);
|
|
434
|
+
});
|
|
435
|
+
browse.addEventListener('click', () => this.fileInput?.click());
|
|
436
|
+
this.fileInput.addEventListener('change', () => {
|
|
437
|
+
const f = this.fileInput?.files?.[0];
|
|
438
|
+
if (f)
|
|
439
|
+
handleFile(f);
|
|
440
|
+
});
|
|
441
|
+
panel.querySelector('#c64-load-btn').addEventListener('click', () => {
|
|
442
|
+
// If a file is selected in preview, keep it; otherwise open file picker
|
|
443
|
+
const f = this.fileInput?.files?.[0];
|
|
444
|
+
if (f)
|
|
445
|
+
handleFile(f);
|
|
446
|
+
else
|
|
447
|
+
this.fileInput?.click();
|
|
448
|
+
});
|
|
449
|
+
let toolItems = [];
|
|
450
|
+
const renderToolSelect = () => {
|
|
451
|
+
toolSelect.innerHTML = '';
|
|
452
|
+
if (toolItems.length === 0) {
|
|
453
|
+
const opt = document.createElement('option');
|
|
454
|
+
opt.value = '';
|
|
455
|
+
opt.textContent = 'No tools found';
|
|
456
|
+
toolSelect.appendChild(opt);
|
|
457
|
+
toolSelect.disabled = true;
|
|
458
|
+
loadToolBtn.disabled = true;
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
toolItems.forEach((tool, i) => {
|
|
462
|
+
const opt = document.createElement('option');
|
|
463
|
+
opt.value = String(i);
|
|
464
|
+
opt.textContent = tool.name;
|
|
465
|
+
toolSelect.appendChild(opt);
|
|
466
|
+
});
|
|
467
|
+
toolSelect.disabled = false;
|
|
468
|
+
loadToolBtn.disabled = false;
|
|
469
|
+
};
|
|
470
|
+
const parseManifest = (raw) => {
|
|
471
|
+
const entries = Array.isArray(raw)
|
|
472
|
+
? raw
|
|
473
|
+
: raw && typeof raw === 'object' && Array.isArray(raw.tools)
|
|
474
|
+
? raw.tools
|
|
475
|
+
: [];
|
|
476
|
+
return entries
|
|
477
|
+
.map((entry) => {
|
|
478
|
+
const path = typeof entry === 'string'
|
|
479
|
+
? entry
|
|
480
|
+
: entry && typeof entry === 'object'
|
|
481
|
+
? entry.path
|
|
482
|
+
: undefined;
|
|
483
|
+
if (!path || typeof path !== 'string')
|
|
484
|
+
return null;
|
|
485
|
+
const filename = path.split('/').pop() ?? path;
|
|
486
|
+
const type = inferLoadTypeFromFilename(filename);
|
|
487
|
+
if (!type)
|
|
488
|
+
return null;
|
|
489
|
+
const encodedPath = path
|
|
490
|
+
.split('/')
|
|
491
|
+
.map((part) => encodeURIComponent(part))
|
|
492
|
+
.join('/');
|
|
493
|
+
const normalizedPath = encodedPath.replace(/^\/+/, '');
|
|
494
|
+
const url = resolveAssetUrl(this.options.assetBaseUrl, `tools/${normalizedPath}`);
|
|
495
|
+
return { name: filename, url, type };
|
|
496
|
+
})
|
|
497
|
+
.filter((v) => !!v);
|
|
498
|
+
};
|
|
499
|
+
const loadToolsManifest = async () => {
|
|
500
|
+
try {
|
|
501
|
+
const url = resolveAssetUrl(this.options.assetBaseUrl, 'tools/tools.json');
|
|
502
|
+
const res = await fetch(url, { cache: 'no-store' });
|
|
503
|
+
if (!res.ok)
|
|
504
|
+
throw new Error(`HTTP ${res.status}`);
|
|
505
|
+
const raw = await res.json();
|
|
506
|
+
toolItems = parseManifest(raw);
|
|
507
|
+
renderToolSelect();
|
|
508
|
+
toolsStatus.textContent =
|
|
509
|
+
toolItems.length > 0
|
|
510
|
+
? `Found ${toolItems.length} tool${toolItems.length === 1 ? '' : 's'} in /public/tools`
|
|
511
|
+
: 'No compatible tools found in manifest';
|
|
512
|
+
}
|
|
513
|
+
catch (err) {
|
|
514
|
+
toolItems = [];
|
|
515
|
+
renderToolSelect();
|
|
516
|
+
toolsStatus.textContent = `Unable to load tools manifest: ${String(err?.message ?? err)}`;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
loadToolBtn.addEventListener('click', () => {
|
|
520
|
+
const idx = Number(toolSelect.value);
|
|
521
|
+
if (!Number.isFinite(idx))
|
|
522
|
+
return;
|
|
523
|
+
const tool = toolItems[idx];
|
|
524
|
+
if (!tool)
|
|
525
|
+
return;
|
|
526
|
+
window.dispatchEvent(new CustomEvent('c64-load-tool', { detail: tool }));
|
|
527
|
+
});
|
|
528
|
+
loadToolsManifest().catch(() => { });
|
|
529
|
+
const section = panel.querySelector('[data-settings-section="system"]');
|
|
530
|
+
// Detach cartridge / hard reset controls
|
|
531
|
+
const saveSnapshotBtn = section?.querySelector('#c64-save-snapshot-btn');
|
|
532
|
+
const detachBtn = section?.querySelector('#c64-detach-btn');
|
|
533
|
+
const resetBtn = section?.querySelector('#c64-reset-btn');
|
|
534
|
+
const rebootBtn = section?.querySelector('#c64-reboot-btn');
|
|
535
|
+
const disableChecksToggle = section?.querySelector('#c64-disable-crt-preload-checks');
|
|
536
|
+
const disableCrtPreloadChecks = window.localStorage.getItem(CRT_PRELOAD_CHECKS_STORAGE_KEY) === '1';
|
|
537
|
+
this.player?.setCrtPreloadChecksDisabled(disableCrtPreloadChecks);
|
|
538
|
+
if (disableChecksToggle) {
|
|
539
|
+
disableChecksToggle.checked = disableCrtPreloadChecks;
|
|
540
|
+
disableChecksToggle.addEventListener('change', () => {
|
|
541
|
+
const disabled = disableChecksToggle.checked;
|
|
542
|
+
window.localStorage.setItem(CRT_PRELOAD_CHECKS_STORAGE_KEY, disabled ? '1' : '0');
|
|
543
|
+
this.player?.setCrtPreloadChecksDisabled(disabled);
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
if (saveSnapshotBtn) {
|
|
547
|
+
saveSnapshotBtn.addEventListener('click', () => {
|
|
548
|
+
if (!this.player || typeof this.player.getSnapshot !== 'function')
|
|
549
|
+
return;
|
|
550
|
+
const statusEl = document.getElementById('status');
|
|
551
|
+
try {
|
|
552
|
+
this.downloadSnapshot(this.player.getSnapshot());
|
|
553
|
+
if (statusEl) {
|
|
554
|
+
statusEl.textContent = 'Snapshot saved';
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
if (statusEl) {
|
|
559
|
+
statusEl.textContent = `Snapshot save failed: ${String(err?.message ?? err)}`;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
if (detachBtn) {
|
|
565
|
+
detachBtn.addEventListener('click', () => {
|
|
566
|
+
if (!this.player)
|
|
567
|
+
return;
|
|
568
|
+
if (!confirm('Detach cartridge?'))
|
|
569
|
+
return;
|
|
570
|
+
this.player.detachCartridge();
|
|
571
|
+
// Provide immediate UI feedback
|
|
572
|
+
const statusEl = document.getElementById('status');
|
|
573
|
+
if (statusEl) {
|
|
574
|
+
statusEl.textContent = 'Cartridge detached';
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
if (resetBtn) {
|
|
579
|
+
resetBtn.addEventListener('click', () => {
|
|
580
|
+
if (!this.player)
|
|
581
|
+
return;
|
|
582
|
+
if (!confirm('Perform hard reset? This will restart the emulator.'))
|
|
583
|
+
return;
|
|
584
|
+
this.player.hardReset();
|
|
585
|
+
const statusEl = document.getElementById('status');
|
|
586
|
+
if (statusEl) {
|
|
587
|
+
statusEl.textContent = 'Hard reset performed';
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
if (rebootBtn) {
|
|
592
|
+
rebootBtn.addEventListener('click', async () => {
|
|
593
|
+
if (!this.player)
|
|
594
|
+
return;
|
|
595
|
+
if (!confirm('Perform full reboot? This re-instantiates the emulator with no game loaded.'))
|
|
596
|
+
return;
|
|
597
|
+
const statusEl = document.getElementById('status');
|
|
598
|
+
if (statusEl) {
|
|
599
|
+
statusEl.textContent = 'Rebooting emulator...';
|
|
600
|
+
}
|
|
601
|
+
try {
|
|
602
|
+
await this.player.reboot();
|
|
603
|
+
if (statusEl) {
|
|
604
|
+
statusEl.textContent = 'Emulator rebooted (no game loaded)';
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
catch (err) {
|
|
608
|
+
if (statusEl) {
|
|
609
|
+
statusEl.textContent = `Reboot failed: ${String(err?.message ?? err)}`;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
// ── Audio section ─────────────────────────────────────────────────────
|
|
615
|
+
const audioContainer = panel.querySelector('#c64-audio-section-anchor');
|
|
616
|
+
this.createAudioSection(audioContainer);
|
|
617
|
+
// ── Input section wiring ───────────────────────────────────────────────
|
|
618
|
+
const joyRadios = panel.querySelectorAll('input[name="c64-joy-port"]');
|
|
619
|
+
const setJoyPort = (port) => {
|
|
620
|
+
// Dispatch a global event so main app or player can pick it up
|
|
621
|
+
window.dispatchEvent(new CustomEvent('c64-set-keyboard-joy-port', { detail: { port } }));
|
|
622
|
+
// If a player instance exists, try to set the input handler directly via the public API
|
|
623
|
+
if (this.player && typeof this.player.setKeyboardJoystickPort === 'function') {
|
|
624
|
+
try {
|
|
625
|
+
this.player.setKeyboardJoystickPort(port);
|
|
626
|
+
}
|
|
627
|
+
catch {
|
|
628
|
+
// ignore errors from consumer implementations
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
joyRadios.forEach((r) => {
|
|
633
|
+
r.addEventListener('change', () => {
|
|
634
|
+
if (r.checked)
|
|
635
|
+
setJoyPort(Number(r.value));
|
|
636
|
+
});
|
|
637
|
+
});
|
|
638
|
+
// ── Input mode wiring ──────────────────────────────────────────────────
|
|
639
|
+
const inputModeHints = {
|
|
640
|
+
joystick: 'Arrows + Ctrl = joystick only',
|
|
641
|
+
keyboard: 'All keys → C64 keyboard matrix',
|
|
642
|
+
mixed: 'Arrows + Z + Ctrl = joystick & all other keys → C64 keyboard',
|
|
643
|
+
};
|
|
644
|
+
const inputModeRadios = panel.querySelectorAll('input[name="c64-input-mode"]');
|
|
645
|
+
const hintEl = panel.querySelector('#c64-input-mode-hint');
|
|
646
|
+
const applyInputMode = (mode) => {
|
|
647
|
+
if (hintEl)
|
|
648
|
+
hintEl.innerHTML = inputModeHints[mode] ?? '';
|
|
649
|
+
window.dispatchEvent(new CustomEvent('c64-set-input-mode', { detail: { mode } }));
|
|
650
|
+
if (this.player && typeof this.player.setInputMode === 'function') {
|
|
651
|
+
try {
|
|
652
|
+
this.player.setInputMode(mode);
|
|
653
|
+
}
|
|
654
|
+
catch {
|
|
655
|
+
// ignore
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
inputModeRadios.forEach((r) => {
|
|
660
|
+
r.addEventListener('change', () => {
|
|
661
|
+
if (r.checked)
|
|
662
|
+
applyInputMode(r.value);
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
this.renderGamepadButtons();
|
|
666
|
+
// ── Display section wiring ─────────────────────────────────────────────
|
|
667
|
+
const displayRadios = panel.querySelectorAll('input[name="c64-display-mode"]');
|
|
668
|
+
const canvas = document.getElementById('c64-screen');
|
|
669
|
+
const applyDisplayMode = (mode) => {
|
|
670
|
+
if (!canvas)
|
|
671
|
+
return;
|
|
672
|
+
// Reset to defaults first
|
|
673
|
+
canvas.style.width = '';
|
|
674
|
+
canvas.style.height = '';
|
|
675
|
+
canvas.style.objectFit = '';
|
|
676
|
+
canvas.removeAttribute('data-display-mode');
|
|
677
|
+
if (mode === 'standard') {
|
|
678
|
+
// Use the default CSS size (no change)
|
|
679
|
+
canvas.style.width = '';
|
|
680
|
+
canvas.style.height = '';
|
|
681
|
+
// Restore the default border from CSS
|
|
682
|
+
canvas.style.border = '';
|
|
683
|
+
// Restore any previously-saved page overflow styles so scrollbars reappear
|
|
684
|
+
if (this.savedHtmlOverflow !== null) {
|
|
685
|
+
document.documentElement.style.overflow = this.savedHtmlOverflow;
|
|
686
|
+
this.savedHtmlOverflow = null;
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
document.documentElement.style.overflow = '';
|
|
690
|
+
}
|
|
691
|
+
if (this.savedBodyOverflow !== null) {
|
|
692
|
+
document.body.style.overflow = this.savedBodyOverflow;
|
|
693
|
+
this.savedBodyOverflow = null;
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
document.body.style.overflow = '';
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
else if (mode === 'full') {
|
|
700
|
+
// Maintain aspect ratio, make canvas fill the full height of the browser
|
|
701
|
+
canvas.style.height = '100vh';
|
|
702
|
+
canvas.style.width = 'auto';
|
|
703
|
+
canvas.style.objectFit = 'contain';
|
|
704
|
+
// Remove canvas border in full-screen-like modes
|
|
705
|
+
canvas.style.border = 'none';
|
|
706
|
+
// Hide page scrollbars (prevent overflow when canvas touches edges)
|
|
707
|
+
if (this.savedHtmlOverflow === null)
|
|
708
|
+
this.savedHtmlOverflow = document.documentElement.style.overflow;
|
|
709
|
+
if (this.savedBodyOverflow === null)
|
|
710
|
+
this.savedBodyOverflow = document.body.style.overflow;
|
|
711
|
+
document.documentElement.style.overflow = 'hidden';
|
|
712
|
+
document.body.style.overflow = 'hidden';
|
|
713
|
+
}
|
|
714
|
+
else if (mode === 'stretch') {
|
|
715
|
+
// Stretch to full width and height (may alter aspect ratio)
|
|
716
|
+
canvas.style.width = '100vw';
|
|
717
|
+
canvas.style.height = '100vh';
|
|
718
|
+
canvas.style.objectFit = 'fill';
|
|
719
|
+
// Remove canvas border in full-screen-like modes
|
|
720
|
+
canvas.style.border = 'none';
|
|
721
|
+
// Hide page scrollbars (prevent overflow when canvas touches edges)
|
|
722
|
+
if (this.savedHtmlOverflow === null)
|
|
723
|
+
this.savedHtmlOverflow = document.documentElement.style.overflow;
|
|
724
|
+
if (this.savedBodyOverflow === null)
|
|
725
|
+
this.savedBodyOverflow = document.body.style.overflow;
|
|
726
|
+
document.documentElement.style.overflow = 'hidden';
|
|
727
|
+
document.body.style.overflow = 'hidden';
|
|
728
|
+
}
|
|
729
|
+
canvas.setAttribute('data-display-mode', mode);
|
|
730
|
+
window.dispatchEvent(new CustomEvent('c64-display-mode-changed', { detail: { mode } }));
|
|
731
|
+
};
|
|
732
|
+
displayRadios.forEach((r) => {
|
|
733
|
+
r.addEventListener('change', () => {
|
|
734
|
+
if (r.checked)
|
|
735
|
+
applyDisplayMode(r.value);
|
|
736
|
+
});
|
|
737
|
+
});
|
|
738
|
+
window.addEventListener('c64-close-dialog', () => {
|
|
739
|
+
this.closeMenu();
|
|
740
|
+
});
|
|
741
|
+
// Close settings when a load completes or errors so the user sees the result
|
|
742
|
+
// window.addEventListener('c64-load-success', () => {
|
|
743
|
+
// this.settingsOverlay?.classList.remove('visible');
|
|
744
|
+
// });
|
|
745
|
+
window.addEventListener('c64-load-error', () => {
|
|
746
|
+
this.settingsOverlay?.classList.remove('visible');
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
/** Floating unmute button — shown when autoplay is blocked by the browser */
|
|
750
|
+
createUnmuteButton() {
|
|
751
|
+
const btn = document.createElement('button');
|
|
752
|
+
btn.className = 'c64-unmute-btn hidden';
|
|
753
|
+
btn.innerHTML = '🔇'; // 🔇 muted icon — audio is OFF when this button shows
|
|
754
|
+
btn.title = 'Click to enable audio';
|
|
755
|
+
btn.addEventListener('click', async () => {
|
|
756
|
+
if (this.player) {
|
|
757
|
+
await this.player.audio.resume();
|
|
758
|
+
if (!this.player.audio.suspended) {
|
|
759
|
+
btn.classList.add('hidden');
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
document.body.appendChild(btn);
|
|
764
|
+
// Show the button when audio is suspended (autoplay blocked)
|
|
765
|
+
window.addEventListener('c64-audio-suspended', () => {
|
|
766
|
+
btn.classList.remove('hidden');
|
|
767
|
+
});
|
|
768
|
+
// Listen for audio state changes dispatched by C64Player
|
|
769
|
+
window.addEventListener('c64-audio-state', ((e) => {
|
|
770
|
+
const state = e.detail;
|
|
771
|
+
if (!state.suspended) {
|
|
772
|
+
btn.classList.add('hidden');
|
|
773
|
+
}
|
|
774
|
+
// Sync the menu controls
|
|
775
|
+
this.syncAudioControls(state);
|
|
776
|
+
}));
|
|
777
|
+
}
|
|
778
|
+
/** Audio controls inside the settings menu (mute toggle + volume slider) */
|
|
779
|
+
createAudioSection(container) {
|
|
780
|
+
const section = document.createElement('div');
|
|
781
|
+
section.className = 'c64-audio-section';
|
|
782
|
+
section.innerHTML = `
|
|
783
|
+
<label>Audio</label>
|
|
784
|
+
<div class="c64-audio-row">
|
|
785
|
+
<button class="c64-mute-btn" id="c64-mute-btn" title="Toggle mute">🔈</button>
|
|
786
|
+
<input type="range" class="c64-volume-slider" id="c64-volume-slider" min="0" max="100" value="75" />
|
|
787
|
+
<span class="c64-volume-label" id="c64-volume-label">75%</span>
|
|
788
|
+
</div>
|
|
789
|
+
`;
|
|
790
|
+
container.appendChild(section);
|
|
791
|
+
const muteBtn = section.querySelector('#c64-mute-btn');
|
|
792
|
+
const slider = section.querySelector('#c64-volume-slider');
|
|
793
|
+
const label = section.querySelector('#c64-volume-label');
|
|
794
|
+
muteBtn.addEventListener('click', () => {
|
|
795
|
+
if (!this.player)
|
|
796
|
+
return;
|
|
797
|
+
this.player.audio.toggleMute();
|
|
798
|
+
// If audio was suspended, also resume on this gesture
|
|
799
|
+
if (this.player.audio.suspended) {
|
|
800
|
+
this.player.audio.resume();
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
slider.addEventListener('input', () => {
|
|
804
|
+
if (!this.player)
|
|
805
|
+
return;
|
|
806
|
+
const v = Number(slider.value) / 100;
|
|
807
|
+
this.player.audio.setVolume(v);
|
|
808
|
+
label.textContent = `${slider.value}%`;
|
|
809
|
+
// If audio was suspended, also resume on this gesture
|
|
810
|
+
if (this.player.audio.suspended) {
|
|
811
|
+
this.player.audio.resume();
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
/** Sync menu audio controls with current audio state */
|
|
816
|
+
syncAudioControls(state) {
|
|
817
|
+
const muteBtn = document.getElementById('c64-mute-btn');
|
|
818
|
+
const slider = document.getElementById('c64-volume-slider');
|
|
819
|
+
const label = document.getElementById('c64-volume-label');
|
|
820
|
+
if (muteBtn) {
|
|
821
|
+
muteBtn.innerHTML = state.muted ? '🔇' : '🔈'; // 🔇 vs 🔈
|
|
822
|
+
muteBtn.classList.toggle('muted', state.muted);
|
|
823
|
+
}
|
|
824
|
+
if (slider) {
|
|
825
|
+
slider.value = String(Math.round(state.volume * 100));
|
|
826
|
+
}
|
|
827
|
+
if (label) {
|
|
828
|
+
label.textContent = `${Math.round(state.volume * 100)}%`;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
toggleMenu() {
|
|
832
|
+
this.settingsOverlay?.classList.toggle('visible');
|
|
833
|
+
}
|
|
834
|
+
closeMenu() {
|
|
835
|
+
this.settingsOverlay?.classList.remove('visible');
|
|
836
|
+
}
|
|
837
|
+
open() {
|
|
838
|
+
this.helpOverlay?.classList.add('visible');
|
|
839
|
+
}
|
|
840
|
+
close() {
|
|
841
|
+
this.helpOverlay?.classList.remove('visible');
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
//# sourceMappingURL=ui-controller.js.map
|