c64-ready 2.5.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -1
- package/bin/admin.mjs +7 -1
- package/bin/agent.mjs +18 -0
- package/bin/headless.mjs +1 -1
- package/dist/assets/BeachHead-CuSwFD4k.js +1 -0
- package/dist/assets/ChuckieEgg-CPqBnAOF.js +1 -0
- package/dist/assets/ForbiddenForest-DsQ9jsc8.js +1 -0
- package/dist/assets/Galaga-Cutc3p9s.js +1 -0
- package/dist/assets/Gribbly-DdZ_hHFt.js +1 -0
- package/dist/assets/Hercules-vZYKm7GG.js +1 -0
- package/dist/assets/LegendOfWilf-CxSMOjsj.js +1 -0
- package/dist/assets/MariosCementFactory-z0IZ0q30.js +1 -0
- package/dist/assets/MoleAttack-buC6ChYy.js +1 -0
- package/dist/assets/MunchyWorm-D2Zv7i0Q.js +1 -0
- package/dist/assets/ParkPatrol-CVj7hyoB.js +1 -0
- package/dist/assets/PottyPigeon-0SYpIUBa.js +1 -0
- package/dist/assets/RainbowIslands-BjfmJB8z.js +1 -0
- package/dist/assets/Stix-BU-qUCeC.js +1 -0
- package/dist/assets/Tilt-C5KtKisF.js +1 -0
- package/dist/assets/UpNDown-CATRO7Mz.js +1 -0
- package/dist/assets/Uridium-DanS2KoH.js +1 -0
- package/dist/assets/VegetablesDeluxe-C41ViimS.js +1 -0
- package/dist/assets/index-B8DSjPqI.js +243 -0
- package/dist/assets/src-DX0rJQsE.js +1 -0
- package/dist/assets/src-_trgwTvp.js +2 -0
- package/dist/assets/string-utils-CMVABfx0.js +1 -0
- package/dist/index.html +1 -1
- package/dist-ts/emulator/c64-emulator.d.ts +2 -2
- package/dist-ts/emulator/c64-emulator.js +2 -2
- package/dist-ts/emulator/c64-keys.d.ts +69 -0
- package/dist-ts/emulator/c64-keys.d.ts.map +1 -0
- package/dist-ts/emulator/c64-keys.js +69 -0
- package/dist-ts/emulator/c64-keys.js.map +1 -0
- package/dist-ts/emulator/c64-wasm.d.ts +1 -1
- package/dist-ts/emulator/gamepad-mapping.d.ts +64 -0
- package/dist-ts/emulator/gamepad-mapping.d.ts.map +1 -0
- package/dist-ts/emulator/gamepad-mapping.js +154 -0
- package/dist-ts/emulator/gamepad-mapping.js.map +1 -0
- package/dist-ts/emulator/input.d.ts +27 -78
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +94 -215
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/headless/audio-capture.d.ts +1 -1
- package/dist-ts/headless/c64-headless.d.ts +2 -2
- package/dist-ts/headless/c64-headless.js +4 -4
- package/dist-ts/headless/frame-capture.d.ts +1 -1
- package/dist-ts/headless/input-bridge.d.ts +1 -1
- package/dist-ts/player/c64-player.d.ts +21 -5
- package/dist-ts/player/c64-player.d.ts.map +1 -1
- package/dist-ts/player/c64-player.js +32 -5
- package/dist-ts/player/c64-player.js.map +1 -1
- package/dist-ts/player/canvas-renderer.d.ts +2 -2
- package/dist-ts/player/cheevos-dev.d.ts +65 -0
- package/dist-ts/player/cheevos-dev.d.ts.map +1 -0
- package/dist-ts/player/cheevos-dev.js +237 -0
- package/dist-ts/player/cheevos-dev.js.map +1 -0
- package/dist-ts/player/cheevos-tracker-panel.d.ts +21 -0
- package/dist-ts/player/cheevos-tracker-panel.d.ts.map +1 -0
- package/dist-ts/player/cheevos-tracker-panel.js +242 -0
- package/dist-ts/player/cheevos-tracker-panel.js.map +1 -0
- package/dist-ts/player/index.d.ts +10 -7
- package/dist-ts/player/index.d.ts.map +1 -1
- package/dist-ts/player/index.js +6 -4
- package/dist-ts/player/index.js.map +1 -1
- package/dist-ts/player/input-handler.d.ts +7 -3
- package/dist-ts/player/input-handler.d.ts.map +1 -1
- package/dist-ts/player/input-handler.js +24 -1
- package/dist-ts/player/input-handler.js.map +1 -1
- package/dist-ts/player/load-formats.d.ts +1 -1
- package/dist-ts/player/local-rom-store.d.ts +23 -0
- package/dist-ts/player/local-rom-store.d.ts.map +1 -0
- package/dist-ts/player/local-rom-store.js +87 -0
- package/dist-ts/player/local-rom-store.js.map +1 -0
- package/dist-ts/player/startup-params.d.ts +7 -0
- package/dist-ts/player/startup-params.d.ts.map +1 -0
- package/dist-ts/player/startup-params.js +47 -0
- package/dist-ts/player/startup-params.js.map +1 -0
- package/dist-ts/player/ui-controller.d.ts +23 -1
- package/dist-ts/player/ui-controller.d.ts.map +1 -1
- package/dist-ts/player/ui-controller.js +665 -1
- package/dist-ts/player/ui-controller.js.map +1 -1
- package/package.json +11 -4
- package/src/emulator/c64-keys.ts +68 -0
- package/src/emulator/gamepad-mapping.ts +212 -0
- package/src/emulator/input.ts +106 -209
- package/src/headless/agent-cli.mjs +825 -0
- package/src/headless/headless-cli.mjs +10 -4
- package/src/headless/input-server.mjs +92 -17
- package/src/headless/png.mjs +72 -0
- package/src/headless/webrtc-server.mjs +458 -34
- package/src/main.ts +197 -12
- package/src/player/c64-player.ts +58 -1
- package/src/player/cheevos-dev.ts +340 -0
- package/src/player/cheevos-tracker-panel.ts +309 -0
- package/src/player/index.ts +19 -0
- package/src/player/input-handler.ts +32 -0
- package/src/player/local-rom-store.ts +126 -0
- package/src/player/startup-params.ts +40 -0
- package/src/player/ui-controller.ts +751 -0
- package/src/player/ultimate-bridge.ts +161 -0
- package/src/player/ultimate-panel.ts +315 -0
- package/src/types/c64-cheevos.d.ts +6 -0
- package/dist/assets/index-BAsZcXuS.js +0 -178
- /package/dist/assets/{marked.esm--kBm026b.js → marked.esm-fTuuvbcB.js} +0 -0
- /package/dist/assets/{purify.es-BcoGFDcJ.js → purify.es-CRM-GE0Y.js} +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client for the `@c64cade/ultimate-bridge` npm bridge. Browsers can't call an Ultimate's
|
|
3
|
+
* REST API directly, so requests go to the bridge running on the user's machine, which
|
|
4
|
+
* forwards them to the device. The protocol matches C64Cade's own client.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_BRIDGE_URL = 'http://localhost:6464';
|
|
8
|
+
export const ULTIMATE_BRIDGE_PACKAGE_URL = 'https://www.npmjs.com/package/@c64cade/ultimate-bridge';
|
|
9
|
+
export const ULTIMATE_FILE_TYPES = ['prg', 'crt', 'd64'] as const;
|
|
10
|
+
export const DEFAULT_D64_AUTOLOAD_COMMAND = 'LOAD"*",8,1\nRUN';
|
|
11
|
+
|
|
12
|
+
const BRIDGE_URL_STORAGE_KEY = 'c64-ultimate-bridge-url';
|
|
13
|
+
const IP_STORAGE_KEY = 'c64-ultimate-ip';
|
|
14
|
+
const PASSWORD_STORAGE_KEY = 'c64-ultimate-password';
|
|
15
|
+
|
|
16
|
+
export type UltimateFileType = (typeof ULTIMATE_FILE_TYPES)[number];
|
|
17
|
+
|
|
18
|
+
export interface UltimateSettings {
|
|
19
|
+
bridgeUrl: string;
|
|
20
|
+
ip: string;
|
|
21
|
+
password: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface UltimateDeviceInfo {
|
|
25
|
+
product?: string;
|
|
26
|
+
firmware_version?: string;
|
|
27
|
+
fpga_version?: string;
|
|
28
|
+
core_version?: string;
|
|
29
|
+
hostname?: string;
|
|
30
|
+
unique_id?: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface UltimateLaunchOptions {
|
|
35
|
+
fileType: UltimateFileType;
|
|
36
|
+
filename: string;
|
|
37
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
38
|
+
joyPort?: number;
|
|
39
|
+
autoLoadCommand?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getSavedUltimateSettings(): UltimateSettings {
|
|
43
|
+
return {
|
|
44
|
+
bridgeUrl: readStorage(BRIDGE_URL_STORAGE_KEY) || DEFAULT_BRIDGE_URL,
|
|
45
|
+
ip: readStorage(IP_STORAGE_KEY),
|
|
46
|
+
password: readStorage(PASSWORD_STORAGE_KEY),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function saveUltimateSettings(settings: Partial<UltimateSettings>): void {
|
|
51
|
+
if (settings.bridgeUrl !== undefined)
|
|
52
|
+
writeStorage(BRIDGE_URL_STORAGE_KEY, settings.bridgeUrl || DEFAULT_BRIDGE_URL);
|
|
53
|
+
if (settings.ip !== undefined) writeStorage(IP_STORAGE_KEY, settings.ip);
|
|
54
|
+
if (settings.password !== undefined) writeStorage(PASSWORD_STORAGE_KEY, settings.password);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isUltimateFileType(value: unknown): value is UltimateFileType {
|
|
58
|
+
return typeof value === 'string' && (ULTIMATE_FILE_TYPES as readonly string[]).includes(value);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function isValidUltimateIp(ip: string): boolean {
|
|
62
|
+
const value = ip.trim();
|
|
63
|
+
return (
|
|
64
|
+
/^(?:\d{1,3}\.){3}\d{1,3}$/.test(value) &&
|
|
65
|
+
value.split('.').every((octet) => Number(octet) <= 255)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function getUltimateInfo(settings: UltimateSettings): Promise<UltimateDeviceInfo> {
|
|
70
|
+
const { bridgeUrl, ip, password } = settings;
|
|
71
|
+
return (await postToBridge(bridgeUrl, '/ultimate/info', { ip, password })) as UltimateDeviceInfo;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function launchOnUltimate(
|
|
75
|
+
settings: UltimateSettings,
|
|
76
|
+
options: UltimateLaunchOptions,
|
|
77
|
+
): Promise<void> {
|
|
78
|
+
const { bridgeUrl, ip, password } = settings;
|
|
79
|
+
await postToBridge(bridgeUrl, '/ultimate/launch', {
|
|
80
|
+
ip,
|
|
81
|
+
password,
|
|
82
|
+
fileType: options.fileType,
|
|
83
|
+
filename: options.filename,
|
|
84
|
+
fileBase64: bytesToBase64(options.data),
|
|
85
|
+
autoLoadCommand: options.autoLoadCommand ?? DEFAULT_D64_AUTOLOAD_COMMAND,
|
|
86
|
+
joyPort: options.joyPort ?? 2,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function rebootUltimate(settings: UltimateSettings): Promise<void> {
|
|
91
|
+
const { bridgeUrl, ip, password } = settings;
|
|
92
|
+
await postToBridge(bridgeUrl, '/ultimate/reboot', { ip, password });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function powerOffUltimate(settings: UltimateSettings): Promise<void> {
|
|
96
|
+
const { bridgeUrl, ip, password } = settings;
|
|
97
|
+
await postToBridge(bridgeUrl, '/ultimate/poweroff', { ip, password, timeoutMs: 1500 }, 2500);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function bytesToBase64(bytes: Uint8Array<ArrayBufferLike>): string {
|
|
101
|
+
let binary = '';
|
|
102
|
+
const chunkSize = 0x8000;
|
|
103
|
+
for (let index = 0; index < bytes.length; index += chunkSize) {
|
|
104
|
+
binary += String.fromCharCode(...bytes.subarray(index, index + chunkSize));
|
|
105
|
+
}
|
|
106
|
+
return btoa(binary);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function postToBridge(
|
|
110
|
+
bridgeUrl: string,
|
|
111
|
+
path: string,
|
|
112
|
+
body: Record<string, unknown>,
|
|
113
|
+
timeoutMs?: number,
|
|
114
|
+
): Promise<unknown> {
|
|
115
|
+
const baseUrl = (bridgeUrl || DEFAULT_BRIDGE_URL).replace(/\/$/, '');
|
|
116
|
+
const controller = timeoutMs ? new AbortController() : null;
|
|
117
|
+
const timer = controller ? window.setTimeout(() => controller.abort(), timeoutMs) : null;
|
|
118
|
+
|
|
119
|
+
let response: Response;
|
|
120
|
+
try {
|
|
121
|
+
response = await fetch(`${baseUrl}${path}`, {
|
|
122
|
+
method: 'POST',
|
|
123
|
+
headers: { 'Content-Type': 'application/json' },
|
|
124
|
+
body: JSON.stringify(body),
|
|
125
|
+
signal: controller?.signal,
|
|
126
|
+
});
|
|
127
|
+
} catch (err) {
|
|
128
|
+
// fetch only rejects when the bridge itself can't be reached; Ultimate errors come back as JSON.
|
|
129
|
+
if ((err as Error)?.name === 'AbortError')
|
|
130
|
+
throw new Error(`The Ultimate bridge at ${baseUrl} did not respond in time.`, {
|
|
131
|
+
cause: err,
|
|
132
|
+
});
|
|
133
|
+
throw new Error(
|
|
134
|
+
`Could not reach the Ultimate bridge at ${baseUrl}. Start it with: npx @c64cade/ultimate-bridge`,
|
|
135
|
+
{ cause: err },
|
|
136
|
+
);
|
|
137
|
+
} finally {
|
|
138
|
+
if (timer !== null) window.clearTimeout(timer);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const data = (await response.json().catch(() => null)) as { error?: string } | null;
|
|
142
|
+
if (!response.ok) throw new Error(data?.error || `Bridge request failed: ${response.status}`);
|
|
143
|
+
return data;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function readStorage(key: string): string {
|
|
147
|
+
try {
|
|
148
|
+
return window.localStorage.getItem(key) ?? '';
|
|
149
|
+
} catch {
|
|
150
|
+
return '';
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function writeStorage(key: string, value: string): void {
|
|
155
|
+
try {
|
|
156
|
+
if (value) window.localStorage.setItem(key, value);
|
|
157
|
+
else window.localStorage.removeItem(key);
|
|
158
|
+
} catch {
|
|
159
|
+
// storage unavailable (private mode etc.)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -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
|
+
}
|