c64-ready 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -1
- package/bin/agent.mjs +18 -0
- package/package.json +10 -4
- package/src/headless/agent-cli.mjs +825 -0
- package/src/headless/png.mjs +72 -0
- package/src/headless/webrtc-server.mjs +115 -13
- package/src/main.ts +20 -0
- package/src/player/c64-player.ts +22 -1
- package/src/player/ui-controller.ts +11 -0
- package/src/player/ultimate-bridge.ts +161 -0
- package/src/player/ultimate-panel.ts +315 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import type { C64Player } from './c64-player';
|
|
2
|
+
import { inferLoadTypeFromFilename } from './load-formats';
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_BRIDGE_URL,
|
|
5
|
+
ULTIMATE_BRIDGE_PACKAGE_URL,
|
|
6
|
+
getSavedUltimateSettings,
|
|
7
|
+
getUltimateInfo,
|
|
8
|
+
isUltimateFileType,
|
|
9
|
+
isValidUltimateIp,
|
|
10
|
+
launchOnUltimate,
|
|
11
|
+
powerOffUltimate,
|
|
12
|
+
rebootUltimate,
|
|
13
|
+
saveUltimateSettings,
|
|
14
|
+
type UltimateDeviceInfo,
|
|
15
|
+
type UltimateFileType,
|
|
16
|
+
type UltimateSettings,
|
|
17
|
+
} from './ultimate-bridge';
|
|
18
|
+
|
|
19
|
+
type StatusMode = 'info' | 'ok' | 'error';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Settings section for playing games on a real Ultimate 64 / C64 Ultimate / Ultimate II+
|
|
23
|
+
* through the C64Cade Ultimate Bridge npm package running on the user's machine.
|
|
24
|
+
*/
|
|
25
|
+
export default class UltimatePanel {
|
|
26
|
+
private deviceInfo: UltimateDeviceInfo | null = null;
|
|
27
|
+
private busy = false;
|
|
28
|
+
private els!: {
|
|
29
|
+
bridgeUrl: HTMLInputElement;
|
|
30
|
+
ip: HTMLInputElement;
|
|
31
|
+
password: HTMLInputElement;
|
|
32
|
+
connectBtn: HTMLButtonElement;
|
|
33
|
+
device: HTMLElement;
|
|
34
|
+
currentGame: HTMLElement;
|
|
35
|
+
sendCurrentBtn: HTMLButtonElement;
|
|
36
|
+
sendFileBtn: HTMLButtonElement;
|
|
37
|
+
fileInput: HTMLInputElement;
|
|
38
|
+
rebootBtn: HTMLButtonElement;
|
|
39
|
+
powerOffBtn: HTMLButtonElement;
|
|
40
|
+
status: HTMLElement;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
private readonly container: HTMLElement;
|
|
44
|
+
private readonly getPlayer: () => C64Player | null;
|
|
45
|
+
|
|
46
|
+
constructor(container: HTMLElement, getPlayer: () => C64Player | null) {
|
|
47
|
+
this.container = container;
|
|
48
|
+
this.getPlayer = getPlayer;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
init(): void {
|
|
52
|
+
this.render();
|
|
53
|
+
this.bind();
|
|
54
|
+
this.updateCurrentGame();
|
|
55
|
+
this.updateControls();
|
|
56
|
+
if (isValidUltimateIp(this.settings().ip)) void this.connect({ silent: true });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private render(): void {
|
|
60
|
+
const saved = getSavedUltimateSettings();
|
|
61
|
+
|
|
62
|
+
this.container.innerHTML = `
|
|
63
|
+
<label class="c64-section-label">Ultimate Player</label>
|
|
64
|
+
<div class="c64-section-hint">
|
|
65
|
+
Play games on a real Ultimate 64, C64 Ultimate or Ultimate II+. Run the
|
|
66
|
+
<a href="${ULTIMATE_BRIDGE_PACKAGE_URL}" target="_blank" rel="noopener noreferrer">C64Cade Ultimate Bridge</a>
|
|
67
|
+
on this computer first: <code>npx @c64cade/ultimate-bridge</code>
|
|
68
|
+
</div>
|
|
69
|
+
<div class="c64-form-row">
|
|
70
|
+
<label for="c64-ultimate-bridge-url">Bridge URL</label>
|
|
71
|
+
<input id="c64-ultimate-bridge-url" class="c64-text-input" type="url" placeholder="${DEFAULT_BRIDGE_URL}" />
|
|
72
|
+
</div>
|
|
73
|
+
<div class="c64-form-row">
|
|
74
|
+
<label for="c64-ultimate-ip">Ultimate IP</label>
|
|
75
|
+
<input id="c64-ultimate-ip" class="c64-text-input" type="text" inputmode="decimal" placeholder="192.168.0.10" />
|
|
76
|
+
</div>
|
|
77
|
+
<div class="c64-form-row">
|
|
78
|
+
<label for="c64-ultimate-password">Password</label>
|
|
79
|
+
<input id="c64-ultimate-password" class="c64-text-input" type="password" autocomplete="off" placeholder="(optional)" />
|
|
80
|
+
</div>
|
|
81
|
+
<div class="c64-menu-actions">
|
|
82
|
+
<button class="c64-btn" id="c64-ultimate-connect" type="button">Connect</button>
|
|
83
|
+
<span class="c64-inline-status" id="c64-ultimate-device">Not connected</span>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<div class="c64-tools-section">
|
|
87
|
+
<label class="c64-section-label">Launch on Ultimate</label>
|
|
88
|
+
<div class="c64-form-row">
|
|
89
|
+
<button class="c64-btn" id="c64-ultimate-send-current" type="button">Send Current Game</button>
|
|
90
|
+
<span class="c64-inline-status" id="c64-ultimate-current-game"></span>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="c64-form-row">
|
|
93
|
+
<button class="c64-btn" id="c64-ultimate-send-file" type="button">Send File…</button>
|
|
94
|
+
<span class="c64-inline-status">.prg, .crt or .d64</span>
|
|
95
|
+
<input id="c64-ultimate-file" class="c64-file-input" type="file" accept=".prg,.crt,.d64" />
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
<div class="c64-tools-section">
|
|
100
|
+
<label class="c64-section-label">Device</label>
|
|
101
|
+
<div class="c64-system-actions">
|
|
102
|
+
<button class="c64-btn" id="c64-ultimate-reboot" type="button">Reboot Ultimate</button>
|
|
103
|
+
<button class="c64-btn" id="c64-ultimate-poweroff" type="button">Power Off</button>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
<div class="c64-cheat-status" id="c64-ultimate-status" role="status"></div>
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
const q = <T extends Element>(sel: string) => this.container.querySelector(sel) as T;
|
|
110
|
+
this.els = {
|
|
111
|
+
bridgeUrl: q('#c64-ultimate-bridge-url'),
|
|
112
|
+
ip: q('#c64-ultimate-ip'),
|
|
113
|
+
password: q('#c64-ultimate-password'),
|
|
114
|
+
connectBtn: q('#c64-ultimate-connect'),
|
|
115
|
+
device: q('#c64-ultimate-device'),
|
|
116
|
+
currentGame: q('#c64-ultimate-current-game'),
|
|
117
|
+
sendCurrentBtn: q('#c64-ultimate-send-current'),
|
|
118
|
+
sendFileBtn: q('#c64-ultimate-send-file'),
|
|
119
|
+
fileInput: q('#c64-ultimate-file'),
|
|
120
|
+
rebootBtn: q('#c64-ultimate-reboot'),
|
|
121
|
+
powerOffBtn: q('#c64-ultimate-poweroff'),
|
|
122
|
+
status: q('#c64-ultimate-status'),
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
this.els.bridgeUrl.value = saved.bridgeUrl === DEFAULT_BRIDGE_URL ? '' : saved.bridgeUrl;
|
|
126
|
+
this.els.ip.value = saved.ip;
|
|
127
|
+
this.els.password.value = saved.password;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private bind(): void {
|
|
131
|
+
[this.els.bridgeUrl, this.els.ip, this.els.password].forEach((input) => {
|
|
132
|
+
// Save as the user types so a reload or closed tab never loses the IP
|
|
133
|
+
input.addEventListener('input', () => this.saveFields());
|
|
134
|
+
input.addEventListener('change', () => {
|
|
135
|
+
this.saveFields();
|
|
136
|
+
this.deviceInfo = null;
|
|
137
|
+
this.updateControls();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
this.els.connectBtn.addEventListener('click', () => void this.connect());
|
|
142
|
+
this.els.sendCurrentBtn.addEventListener('click', () => void this.sendCurrentGame());
|
|
143
|
+
this.els.sendFileBtn.addEventListener('click', () => this.els.fileInput.click());
|
|
144
|
+
this.els.fileInput.addEventListener('change', () => {
|
|
145
|
+
const file = this.els.fileInput.files?.[0];
|
|
146
|
+
this.els.fileInput.value = '';
|
|
147
|
+
if (file) void this.sendFile(file);
|
|
148
|
+
});
|
|
149
|
+
this.els.rebootBtn.addEventListener('click', () => void this.reboot());
|
|
150
|
+
this.els.powerOffBtn.addEventListener('click', () => void this.powerOff());
|
|
151
|
+
|
|
152
|
+
const onGameChanged = () => {
|
|
153
|
+
this.updateCurrentGame();
|
|
154
|
+
this.updateControls();
|
|
155
|
+
};
|
|
156
|
+
window.addEventListener('c64-load-success', onGameChanged);
|
|
157
|
+
window.addEventListener('c64-detach', onGameChanged);
|
|
158
|
+
window.addEventListener('c64-reboot', onGameChanged);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private settings(): UltimateSettings {
|
|
162
|
+
return {
|
|
163
|
+
bridgeUrl: this.els.bridgeUrl.value.trim() || DEFAULT_BRIDGE_URL,
|
|
164
|
+
ip: this.els.ip.value.trim(),
|
|
165
|
+
password: this.els.password.value,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private saveFields(): void {
|
|
170
|
+
saveUltimateSettings({
|
|
171
|
+
bridgeUrl: this.els.bridgeUrl.value.trim(),
|
|
172
|
+
ip: this.els.ip.value.trim(),
|
|
173
|
+
password: this.els.password.value,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private async connect({ silent = false } = {}): Promise<void> {
|
|
178
|
+
await this.run(
|
|
179
|
+
silent ? '' : 'Connecting to Ultimate…',
|
|
180
|
+
async () => {
|
|
181
|
+
this.saveFields();
|
|
182
|
+
const settings = this.settings();
|
|
183
|
+
if (!isValidUltimateIp(settings.ip)) {
|
|
184
|
+
throw new Error("Enter your Ultimate's IPv4 address, e.g. 192.168.0.10.");
|
|
185
|
+
}
|
|
186
|
+
this.deviceInfo = null;
|
|
187
|
+
this.deviceInfo = await getUltimateInfo(settings);
|
|
188
|
+
return silent ? '' : `Connected to ${this.describeDevice()}`;
|
|
189
|
+
},
|
|
190
|
+
{ silentErrors: silent },
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private async sendCurrentGame(): Promise<void> {
|
|
195
|
+
const game = this.currentGame();
|
|
196
|
+
if (!game) return;
|
|
197
|
+
if (!isUltimateFileType(game.type)) {
|
|
198
|
+
this.setStatus(
|
|
199
|
+
`Ultimate can't launch ${game.type} files — only .prg, .crt and .d64.`,
|
|
200
|
+
'error',
|
|
201
|
+
);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
await this.launch(game.name, game.type, game.data);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private async sendFile(file: File): Promise<void> {
|
|
208
|
+
const type = inferLoadTypeFromFilename(file.name);
|
|
209
|
+
if (!isUltimateFileType(type)) {
|
|
210
|
+
this.setStatus(`${file.name} isn't a .prg, .crt or .d64 file.`, 'error');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
await this.launch(file.name, type, new Uint8Array(await file.arrayBuffer()));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private async launch(
|
|
217
|
+
filename: string,
|
|
218
|
+
fileType: UltimateFileType,
|
|
219
|
+
data: Uint8Array<ArrayBufferLike>,
|
|
220
|
+
): Promise<void> {
|
|
221
|
+
await this.run(`Sending ${filename} to Ultimate…`, async () => {
|
|
222
|
+
await launchOnUltimate(this.settings(), { filename, fileType, data });
|
|
223
|
+
return `Launched ${filename} on ${this.describeDevice()}`;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async reboot(): Promise<void> {
|
|
228
|
+
if (!confirm('Reboot the Ultimate? Anything running on it will be lost.')) return;
|
|
229
|
+
await this.run('Rebooting Ultimate…', async () => {
|
|
230
|
+
await rebootUltimate(this.settings());
|
|
231
|
+
return 'Ultimate rebooted';
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private async powerOff(): Promise<void> {
|
|
236
|
+
if (!confirm('Power off the Ultimate? You will need to switch it back on by hand.')) return;
|
|
237
|
+
await this.run('Powering off Ultimate…', async () => {
|
|
238
|
+
await powerOffUltimate(this.settings());
|
|
239
|
+
this.deviceInfo = null;
|
|
240
|
+
return 'Ultimate powered off';
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Runs a bridge request with the buttons disabled, reporting progress and errors. */
|
|
245
|
+
private async run(
|
|
246
|
+
pending: string,
|
|
247
|
+
task: () => Promise<string>,
|
|
248
|
+
{ silentErrors = false } = {},
|
|
249
|
+
): Promise<void> {
|
|
250
|
+
if (this.busy) return;
|
|
251
|
+
this.busy = true;
|
|
252
|
+
if (pending) this.setStatus(pending);
|
|
253
|
+
this.updateControls();
|
|
254
|
+
try {
|
|
255
|
+
const done = await task();
|
|
256
|
+
if (done) this.setStatus(done, 'ok');
|
|
257
|
+
else if (pending) this.setStatus('');
|
|
258
|
+
} catch (err) {
|
|
259
|
+
if (silentErrors) this.setStatus('');
|
|
260
|
+
else this.setStatus(errorText(err), 'error');
|
|
261
|
+
} finally {
|
|
262
|
+
this.busy = false;
|
|
263
|
+
this.updateControls();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private describeDevice(): string {
|
|
268
|
+
const product = this.deviceInfo?.product || 'Ultimate';
|
|
269
|
+
const ip = this.settings().ip;
|
|
270
|
+
return ip ? `${product} at ${ip}` : product;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private currentGame() {
|
|
274
|
+
return this.getPlayer()?.getCurrentGame?.() ?? null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private updateCurrentGame(): void {
|
|
278
|
+
const game = this.currentGame();
|
|
279
|
+
this.els.currentGame.textContent = game ? game.name : 'No game loaded';
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private updateControls(): void {
|
|
283
|
+
if (this.deviceInfo) {
|
|
284
|
+
const info = this.deviceInfo;
|
|
285
|
+
const versions = [
|
|
286
|
+
info.firmware_version && `firmware ${info.firmware_version}`,
|
|
287
|
+
info.fpga_version && `FPGA ${info.fpga_version}`,
|
|
288
|
+
].filter(Boolean);
|
|
289
|
+
this.els.device.textContent = `● ${this.describeDevice()}${versions.length ? ` (${versions.join(', ')})` : ''}`;
|
|
290
|
+
this.els.device.dataset.connected = 'true';
|
|
291
|
+
} else {
|
|
292
|
+
this.els.device.textContent = 'Not connected';
|
|
293
|
+
delete this.els.device.dataset.connected;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const connected = !!this.deviceInfo;
|
|
297
|
+
const game = this.currentGame();
|
|
298
|
+
this.els.connectBtn.disabled = this.busy;
|
|
299
|
+
this.els.connectBtn.textContent = connected ? 'Reconnect' : 'Connect';
|
|
300
|
+
this.els.sendCurrentBtn.disabled = this.busy || !connected || !game;
|
|
301
|
+
this.els.sendFileBtn.disabled = this.busy || !connected;
|
|
302
|
+
this.els.rebootBtn.disabled = this.busy || !connected;
|
|
303
|
+
this.els.powerOffBtn.disabled = this.busy || !connected;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private setStatus(message: string, mode: StatusMode = 'info'): void {
|
|
307
|
+
this.els.status.textContent = message;
|
|
308
|
+
this.els.status.hidden = !message;
|
|
309
|
+
this.els.status.dataset.mode = mode;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function errorText(err: unknown): string {
|
|
314
|
+
return err instanceof Error ? err.message : String(err);
|
|
315
|
+
}
|