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,825 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 hayesmaker
|
|
3
|
+
// See LICENSE in the project root for full license information.
|
|
4
|
+
/**
|
|
5
|
+
* agent-cli.mjs — deterministic "load → run → inspect" runner for LLM agents and scripts.
|
|
6
|
+
*
|
|
7
|
+
* Unlike the streaming headless CLI, everything here is driven by *emulated* frames
|
|
8
|
+
* (one PAL frame ≈ 20 ms per `debugger_update`), never wall-clock time, so the same
|
|
9
|
+
* command produces the same result every run.
|
|
10
|
+
*
|
|
11
|
+
* See `bin/agent.mjs --help` and docs/AGENT_CLI.md.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import fs from 'node:fs/promises';
|
|
15
|
+
import { readFileSync } from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
import { spawn } from 'node:child_process';
|
|
18
|
+
import { C64WASM } from './c64-wasm.mjs';
|
|
19
|
+
import { C64_KEY } from './c64-key-map.mjs';
|
|
20
|
+
import { encodePng } from './png.mjs';
|
|
21
|
+
|
|
22
|
+
export const FRAME_WIDTH = 384;
|
|
23
|
+
export const FRAME_HEIGHT = 272;
|
|
24
|
+
export const FRAME_MS = 20; // one PAL frame
|
|
25
|
+
const BOOT_MAX_FRAMES = 300;
|
|
26
|
+
const DRIVE_BOOT_FRAMES = 100; // 2 s for the 1541 to boot after being enabled
|
|
27
|
+
const DEFAULT_TAP_FRAMES = 3;
|
|
28
|
+
const KBD_BUF_LEN = 0x00c6;
|
|
29
|
+
const KBD_BUF = 0x0277;
|
|
30
|
+
const KBD_BUF_MAX = 10;
|
|
31
|
+
|
|
32
|
+
export const HELP = `c64-agent — run a C64 program headlessly and report what happened.
|
|
33
|
+
|
|
34
|
+
Usage:
|
|
35
|
+
c64-agent [file.prg|.crt|.d64|.c64] [options]
|
|
36
|
+
|
|
37
|
+
Time is counted in emulated PAL frames (50 per second), so runs are deterministic.
|
|
38
|
+
|
|
39
|
+
Run control:
|
|
40
|
+
--frames <n> Frames to run after loading [default: 100]
|
|
41
|
+
--no-run Load a .prg/.d64 but do not type RUN
|
|
42
|
+
--sys <addr> Start a .prg with SYS <addr> instead of RUN
|
|
43
|
+
--break <addr> Stop when the PC reaches <addr> (repeatable)
|
|
44
|
+
--until-text <str> Stop when <str> appears on screen (exit 3 if it never does)
|
|
45
|
+
--poke <addr>=<v>[,v] Write bytes after loading, before running (repeatable)
|
|
46
|
+
--symbols <file> KickAssembler .sym or VICE label file. Addresses may then be
|
|
47
|
+
labels (--break game_loop, --dump score:4) and the report
|
|
48
|
+
shows the PC as label+offset
|
|
49
|
+
|
|
50
|
+
Input (scheduled on frame numbers, counted from 0 after load):
|
|
51
|
+
--type <text> Type text into the keyboard buffer at frame 0 (\\n = RETURN)
|
|
52
|
+
--at <frame>:<action> Schedule an action (repeatable). Actions:
|
|
53
|
+
type=<text> queue text into the KERNAL keyboard buffer
|
|
54
|
+
press=<KEY>[+KEY] hold keys for ${DEFAULT_TAP_FRAMES} frames (matrix scan — works in games)
|
|
55
|
+
hold=<KEY>[+KEY] press and keep held release=<KEY>[+KEY] let go
|
|
56
|
+
joy1=<dirs>|joy2=<dirs> set joystick state, e.g. joy2=up+fire, joy2=none
|
|
57
|
+
screenshot=<path> save a PNG at this frame
|
|
58
|
+
poke=<addr>=<v>[,v] write memory at this frame
|
|
59
|
+
|
|
60
|
+
Output:
|
|
61
|
+
--screenshot <path> PNG of the final frame
|
|
62
|
+
--every <n> --shots-dir <dir> PNG every n frames (frame-00050.png …)
|
|
63
|
+
--scale <n> Integer upscale for PNGs [default: 1]
|
|
64
|
+
--video <path> Record .mp4/.gif/.webm of the run (needs ffmpeg on PATH)
|
|
65
|
+
--screen Print the text screen (decoded screen RAM)
|
|
66
|
+
--dump <a>-<b>|<a>:<len> Hex dump of CPU-visible memory (repeatable)
|
|
67
|
+
--vic Print VIC-II registers $D000-$D02E
|
|
68
|
+
--no-regs Omit CPU registers from the report
|
|
69
|
+
--save-snapshot <path> Save a native .c64 snapshot at the end
|
|
70
|
+
--json Print the report as JSON
|
|
71
|
+
--wasm <path> Path to c64.wasm [default: bundled]
|
|
72
|
+
--help Show this help
|
|
73
|
+
|
|
74
|
+
Addresses are hex ($c000, 0xc000, c000), #49152 for decimal, or a label with --symbols.
|
|
75
|
+
Quote "$…" in shells.
|
|
76
|
+
Key names: A-Z, 0-9, SPACE, RETURN, F1 F3 F5 F7, RUN_STOP, SHIFT_LEFT, CTRL, COMMODORE,
|
|
77
|
+
CURSOR_UP_DOWN, CURSOR_LEFT_RIGHT, CLEAR_HOME, INS_DEL, … (see C64_KEY).
|
|
78
|
+
|
|
79
|
+
Exit codes: 0 ok · 1 error · 3 --until-text not reached.
|
|
80
|
+
|
|
81
|
+
Examples:
|
|
82
|
+
c64-agent game.prg --frames 250 --screenshot shot.png --screen
|
|
83
|
+
c64-agent game.prg --at 100:joy2=right+fire --at 150:joy2=none --frames 200 --json
|
|
84
|
+
c64-agent test.prg --until-text "PASS" --frames 3000 --dump '$c000:32'
|
|
85
|
+
`;
|
|
86
|
+
|
|
87
|
+
// ── parsing helpers ──────────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Parse a symbol file into Map<name, address>.
|
|
91
|
+
* Supports KickAssembler .sym (`.label name=$0810`, `.const`, `.namespace x { … }`),
|
|
92
|
+
* VICE label files (`al C:0810 .name`) and plain `name = $0810` lines.
|
|
93
|
+
*/
|
|
94
|
+
export function parseSymbols(text) {
|
|
95
|
+
const syms = new Map();
|
|
96
|
+
const ns = [];
|
|
97
|
+
for (const raw of String(text).split(/\r?\n/)) {
|
|
98
|
+
const line = raw.replace(/\/\/.*$/, '').trim();
|
|
99
|
+
if (!line) continue;
|
|
100
|
+
const nsOpen = line.match(/^\.namespace\s+([\w@]+)\s*\{/);
|
|
101
|
+
if (nsOpen) {
|
|
102
|
+
ns.push(nsOpen[1]);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (line === '}') {
|
|
106
|
+
ns.pop();
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
let m = line.match(/^al\s+(?:C:)?([0-9a-f]+)\s+\.?([\w@.]+)/i);
|
|
110
|
+
if (m) {
|
|
111
|
+
syms.set(m[2], Number.parseInt(m[1], 16));
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
m = line.match(/^(?:\.(?:label|const|var)\s+)?([A-Za-z_@][\w@.]*)\s*=\s*\$([0-9a-f]+)\b/i);
|
|
115
|
+
if (m) {
|
|
116
|
+
const v = Number.parseInt(m[2], 16);
|
|
117
|
+
if (v > 0xffff) continue;
|
|
118
|
+
const name = ns.length ? `${ns.join('.')}.${m[1]}` : m[1];
|
|
119
|
+
syms.set(name, v);
|
|
120
|
+
if (ns.length && !syms.has(m[1])) syms.set(m[1], v);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return syms;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** "label" or "label+n" for the nearest symbol at or below addr (within 256 bytes). */
|
|
127
|
+
export function nearestSymbol(syms, addr) {
|
|
128
|
+
if (!syms || !syms.size) return null;
|
|
129
|
+
let best = null;
|
|
130
|
+
let bestAddr = -1;
|
|
131
|
+
for (const [name, a] of syms) {
|
|
132
|
+
if (a <= addr && a > bestAddr && addr - a < 256) {
|
|
133
|
+
best = name;
|
|
134
|
+
bestAddr = a;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (best === null) return null;
|
|
138
|
+
return addr === bestAddr ? best : `${best}+${addr - bestAddr}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Parse an address: $hex, 0xhex, bare hex, #decimal, or a label (`name`, `name+3`). */
|
|
142
|
+
export function parseAddr(str, symbols = null) {
|
|
143
|
+
const s = String(str).trim();
|
|
144
|
+
if (symbols) {
|
|
145
|
+
const sym = s.match(/^([A-Za-z_@][\w@.]*)(?:\+(\d+))?$/);
|
|
146
|
+
if (sym && symbols.has(sym[1])) return (symbols.get(sym[1]) + Number(sym[2] ?? 0)) & 0xffff;
|
|
147
|
+
}
|
|
148
|
+
let n;
|
|
149
|
+
if (s.startsWith('#')) n = Number.parseInt(s.slice(1), 10);
|
|
150
|
+
else if (s.startsWith('$')) n = Number.parseInt(s.slice(1), 16);
|
|
151
|
+
else if (/^0x/i.test(s)) n = Number.parseInt(s.slice(2), 16);
|
|
152
|
+
else n = Number.parseInt(s, 16);
|
|
153
|
+
if (!/^(#\d+|\$[0-9a-f]+|0x[0-9a-f]+|[0-9a-f]+)$/i.test(s) || !Number.isFinite(n)) {
|
|
154
|
+
throw new Error(`Invalid address${symbols ? ' or unknown symbol' : ''}: ${str}`);
|
|
155
|
+
}
|
|
156
|
+
if (n < 0 || n > 0xffff) throw new Error(`Address out of range: ${str}`);
|
|
157
|
+
return n;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function parseByte(str) {
|
|
161
|
+
const v = parseAddr(str);
|
|
162
|
+
if (v > 0xff) throw new Error(`Byte out of range: ${str}`);
|
|
163
|
+
return v;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Parse `a-b` (inclusive), `a:len` (len decimal unless $/0x) or `a` (256 bytes). */
|
|
167
|
+
export function parseRange(str, symbols = null) {
|
|
168
|
+
const s = String(str);
|
|
169
|
+
if (s.includes(':')) {
|
|
170
|
+
const [a, len] = s.split(':');
|
|
171
|
+
const start = parseAddr(a, symbols);
|
|
172
|
+
const n = parseAddr(len.startsWith('$') || /^0x/i.test(len) ? len : `#${len}`);
|
|
173
|
+
if (n < 1) throw new Error(`Invalid length: ${str}`);
|
|
174
|
+
return { start, end: Math.min(0xffff, start + n - 1) };
|
|
175
|
+
}
|
|
176
|
+
if (s.includes('-')) {
|
|
177
|
+
const [a, b] = s.split('-');
|
|
178
|
+
const start = parseAddr(a, symbols);
|
|
179
|
+
const end = parseAddr(b, symbols);
|
|
180
|
+
if (end < start) throw new Error(`Invalid range: ${str}`);
|
|
181
|
+
return { start, end };
|
|
182
|
+
}
|
|
183
|
+
const start = parseAddr(s, symbols);
|
|
184
|
+
return { start, end: Math.min(0xffff, start + 255) };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function parsePoke(str, symbols = null) {
|
|
188
|
+
const eq = String(str).indexOf('=');
|
|
189
|
+
if (eq < 0) throw new Error(`Invalid poke (expected addr=value): ${str}`);
|
|
190
|
+
const addr = parseAddr(str.slice(0, eq), symbols);
|
|
191
|
+
const values = str
|
|
192
|
+
.slice(eq + 1)
|
|
193
|
+
.split(',')
|
|
194
|
+
.map((v) => parseByte(v));
|
|
195
|
+
return { addr, values };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const KEY_ALIASES = {
|
|
199
|
+
ENTER: 'RETURN',
|
|
200
|
+
RET: 'RETURN',
|
|
201
|
+
SHIFT: 'SHIFT_LEFT',
|
|
202
|
+
LSHIFT: 'SHIFT_LEFT',
|
|
203
|
+
RSHIFT: 'SHIFT_RIGHT',
|
|
204
|
+
RUNSTOP: 'RUN_STOP',
|
|
205
|
+
STOP: 'RUN_STOP',
|
|
206
|
+
CBM: 'COMMODORE',
|
|
207
|
+
C64: 'COMMODORE',
|
|
208
|
+
HOME: 'CLEAR_HOME',
|
|
209
|
+
DEL: 'INS_DEL',
|
|
210
|
+
DOWN: 'CURSOR_UP_DOWN',
|
|
211
|
+
RIGHT: 'CURSOR_LEFT_RIGHT',
|
|
212
|
+
};
|
|
213
|
+
const DIGIT_NAMES = [
|
|
214
|
+
'ZERO',
|
|
215
|
+
'ONE',
|
|
216
|
+
'TWO',
|
|
217
|
+
'THREE',
|
|
218
|
+
'FOUR',
|
|
219
|
+
'FIVE',
|
|
220
|
+
'SIX',
|
|
221
|
+
'SEVEN',
|
|
222
|
+
'EIGHT',
|
|
223
|
+
'NINE',
|
|
224
|
+
];
|
|
225
|
+
|
|
226
|
+
export function parseKeyName(name) {
|
|
227
|
+
let k = String(name).trim().toUpperCase();
|
|
228
|
+
if (/^[0-9]$/.test(k)) k = DIGIT_NAMES[Number(k)];
|
|
229
|
+
k = KEY_ALIASES[k] ?? k;
|
|
230
|
+
if (!(k in C64_KEY)) throw new Error(`Unknown C64 key: ${name}`);
|
|
231
|
+
return C64_KEY[k];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const JOY_BITS = { up: 0x01, down: 0x02, left: 0x04, right: 0x08, fire: 0x10 };
|
|
235
|
+
|
|
236
|
+
export function parseJoy(str) {
|
|
237
|
+
const s = String(str).trim().toLowerCase();
|
|
238
|
+
if (s === '' || s === 'none' || s === '0') return 0;
|
|
239
|
+
let bits = 0;
|
|
240
|
+
for (const part of s.split('+')) {
|
|
241
|
+
if (!(part in JOY_BITS)) throw new Error(`Unknown joystick input: ${part}`);
|
|
242
|
+
bits |= JOY_BITS[part];
|
|
243
|
+
}
|
|
244
|
+
return bits;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Convert user text to PETSCII bytes for the keyboard buffer. `\n` (real or escaped) → RETURN. */
|
|
248
|
+
export function textToPetscii(text) {
|
|
249
|
+
const norm = String(text).replace(/\\n/g, '\n').replace(/\r\n?/g, '\n').toUpperCase();
|
|
250
|
+
const out = [];
|
|
251
|
+
for (const ch of norm) {
|
|
252
|
+
const c = ch.charCodeAt(0);
|
|
253
|
+
if (ch === '\n') out.push(13);
|
|
254
|
+
else if (c >= 0x20 && c < 0x60) out.push(c);
|
|
255
|
+
else throw new Error(`Cannot type character ${JSON.stringify(ch)} via the keyboard buffer`);
|
|
256
|
+
}
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function parseAction(spec, symbols = null) {
|
|
261
|
+
const s = String(spec);
|
|
262
|
+
const colon = s.indexOf(':');
|
|
263
|
+
if (colon < 0) throw new Error(`Invalid --at (expected frame:action): ${spec}`);
|
|
264
|
+
const frame = Number(s.slice(0, colon));
|
|
265
|
+
if (!Number.isInteger(frame) || frame < 0) throw new Error(`Invalid frame in --at: ${spec}`);
|
|
266
|
+
const body = s.slice(colon + 1);
|
|
267
|
+
const eq = body.indexOf('=');
|
|
268
|
+
if (eq < 0) throw new Error(`Invalid action (expected name=value): ${body}`);
|
|
269
|
+
const name = body.slice(0, eq).trim().toLowerCase();
|
|
270
|
+
const value = body.slice(eq + 1);
|
|
271
|
+
switch (name) {
|
|
272
|
+
case 'type':
|
|
273
|
+
return { frame, kind: 'type', bytes: textToPetscii(value) };
|
|
274
|
+
case 'press':
|
|
275
|
+
case 'hold':
|
|
276
|
+
case 'release':
|
|
277
|
+
return { frame, kind: name, keys: value.split('+').map(parseKeyName) };
|
|
278
|
+
case 'joy1':
|
|
279
|
+
case 'joy2':
|
|
280
|
+
return { frame, kind: 'joy', port: name === 'joy1' ? 1 : 2, bits: parseJoy(value) };
|
|
281
|
+
case 'screenshot':
|
|
282
|
+
return { frame, kind: 'screenshot', path: value };
|
|
283
|
+
case 'poke':
|
|
284
|
+
return { frame, kind: 'poke', ...parsePoke(value, symbols) };
|
|
285
|
+
default:
|
|
286
|
+
throw new Error(`Unknown action: ${name}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** @param {string[]} argv @param {(p: string) => string} [readText] */
|
|
291
|
+
export function parseArgs(argv, readText = (p) => readFileSync(p, 'utf8')) {
|
|
292
|
+
// Load symbols first so every address argument can name a label, wherever it appears.
|
|
293
|
+
const symIdx = argv.indexOf('--symbols');
|
|
294
|
+
let symbols = null;
|
|
295
|
+
if (symIdx >= 0) {
|
|
296
|
+
if (symIdx + 1 >= argv.length) throw new Error('--symbols needs a value');
|
|
297
|
+
symbols = parseSymbols(readText(argv[symIdx + 1]));
|
|
298
|
+
}
|
|
299
|
+
const o = {
|
|
300
|
+
symbols,
|
|
301
|
+
file: null,
|
|
302
|
+
wasm: null,
|
|
303
|
+
frames: 100,
|
|
304
|
+
run: true,
|
|
305
|
+
sys: null,
|
|
306
|
+
breaks: [],
|
|
307
|
+
untilText: null,
|
|
308
|
+
pokes: [],
|
|
309
|
+
actions: [],
|
|
310
|
+
screenshot: null,
|
|
311
|
+
every: 0,
|
|
312
|
+
shotsDir: null,
|
|
313
|
+
scale: 1,
|
|
314
|
+
video: null,
|
|
315
|
+
screen: false,
|
|
316
|
+
dumps: [],
|
|
317
|
+
vic: false,
|
|
318
|
+
regs: true,
|
|
319
|
+
saveSnapshot: null,
|
|
320
|
+
json: false,
|
|
321
|
+
help: false,
|
|
322
|
+
};
|
|
323
|
+
const need = (i, flag) => {
|
|
324
|
+
if (i >= argv.length) throw new Error(`${flag} needs a value`);
|
|
325
|
+
return argv[i];
|
|
326
|
+
};
|
|
327
|
+
for (let i = 0; i < argv.length; i++) {
|
|
328
|
+
const a = argv[i];
|
|
329
|
+
switch (a) {
|
|
330
|
+
case '--help':
|
|
331
|
+
case '-h':
|
|
332
|
+
o.help = true;
|
|
333
|
+
break;
|
|
334
|
+
case '--wasm':
|
|
335
|
+
o.wasm = need(++i, a);
|
|
336
|
+
break;
|
|
337
|
+
case '--symbols':
|
|
338
|
+
i++; // already loaded above
|
|
339
|
+
break;
|
|
340
|
+
case '--frames':
|
|
341
|
+
case '-n':
|
|
342
|
+
o.frames = Number(need(++i, a));
|
|
343
|
+
if (!Number.isInteger(o.frames) || o.frames < 0) throw new Error('--frames must be >= 0');
|
|
344
|
+
break;
|
|
345
|
+
case '--no-run':
|
|
346
|
+
o.run = false;
|
|
347
|
+
break;
|
|
348
|
+
case '--sys':
|
|
349
|
+
o.sys = parseAddr(need(++i, a), symbols);
|
|
350
|
+
break;
|
|
351
|
+
case '--break':
|
|
352
|
+
o.breaks.push(parseAddr(need(++i, a), symbols));
|
|
353
|
+
break;
|
|
354
|
+
case '--until-text':
|
|
355
|
+
o.untilText = need(++i, a).toUpperCase();
|
|
356
|
+
break;
|
|
357
|
+
case '--poke':
|
|
358
|
+
o.pokes.push(parsePoke(need(++i, a), symbols));
|
|
359
|
+
break;
|
|
360
|
+
case '--type':
|
|
361
|
+
o.actions.push({ frame: 0, kind: 'type', bytes: textToPetscii(need(++i, a)) });
|
|
362
|
+
break;
|
|
363
|
+
case '--at':
|
|
364
|
+
o.actions.push(parseAction(need(++i, a), symbols));
|
|
365
|
+
break;
|
|
366
|
+
case '--screenshot':
|
|
367
|
+
o.screenshot = need(++i, a);
|
|
368
|
+
break;
|
|
369
|
+
case '--every':
|
|
370
|
+
o.every = Number(need(++i, a));
|
|
371
|
+
break;
|
|
372
|
+
case '--shots-dir':
|
|
373
|
+
o.shotsDir = need(++i, a);
|
|
374
|
+
break;
|
|
375
|
+
case '--scale':
|
|
376
|
+
o.scale = Number(need(++i, a));
|
|
377
|
+
break;
|
|
378
|
+
case '--video':
|
|
379
|
+
o.video = need(++i, a);
|
|
380
|
+
break;
|
|
381
|
+
case '--screen':
|
|
382
|
+
o.screen = true;
|
|
383
|
+
break;
|
|
384
|
+
case '--dump':
|
|
385
|
+
o.dumps.push(parseRange(need(++i, a), symbols));
|
|
386
|
+
break;
|
|
387
|
+
case '--vic':
|
|
388
|
+
o.vic = true;
|
|
389
|
+
break;
|
|
390
|
+
case '--no-regs':
|
|
391
|
+
o.regs = false;
|
|
392
|
+
break;
|
|
393
|
+
case '--save-snapshot':
|
|
394
|
+
o.saveSnapshot = need(++i, a);
|
|
395
|
+
break;
|
|
396
|
+
case '--json':
|
|
397
|
+
o.json = true;
|
|
398
|
+
break;
|
|
399
|
+
default:
|
|
400
|
+
if (a.startsWith('-')) throw new Error(`Unknown option: ${a}`);
|
|
401
|
+
if (o.file) throw new Error(`Unexpected extra argument: ${a}`);
|
|
402
|
+
o.file = a;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (o.every && !o.shotsDir) o.shotsDir = '.';
|
|
406
|
+
return o;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function inferType(file) {
|
|
410
|
+
const l = file.toLowerCase();
|
|
411
|
+
if (l.endsWith('.prg')) return 'prg';
|
|
412
|
+
if (l.endsWith('.crt')) return 'crt';
|
|
413
|
+
if (l.endsWith('.d64')) return 'd64';
|
|
414
|
+
if (l.endsWith('.c64') || l.endsWith('.snapshot') || l.endsWith('.s64')) return 'snapshot';
|
|
415
|
+
throw new Error(`Unsupported file type: ${file} (expected .prg, .crt, .d64 or .c64)`);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// ── inspection helpers ───────────────────────────────────────────────────────
|
|
419
|
+
|
|
420
|
+
/** Screen code → printable char. Graphics glyphs become '#'. */
|
|
421
|
+
export function screenCodeToChar(code, lowercase) {
|
|
422
|
+
const c = code & 0x7f;
|
|
423
|
+
if (c === 0) return '@';
|
|
424
|
+
if (c < 27) return String.fromCharCode((lowercase ? 96 : 64) + c);
|
|
425
|
+
if (c < 32) return '[£]↑←'[c - 27];
|
|
426
|
+
if (c < 64) return String.fromCharCode(c);
|
|
427
|
+
if (lowercase && c >= 65 && c <= 90) return String.fromCharCode(c);
|
|
428
|
+
if (c === 96) return ' ';
|
|
429
|
+
return '#';
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export function readScreenInfo(x) {
|
|
433
|
+
const d011 = x.c64_vicReadRegister(0x11);
|
|
434
|
+
const d016 = x.c64_vicReadRegister(0x16);
|
|
435
|
+
const d018 = x.c64_vicReadRegister(0x18);
|
|
436
|
+
const bank = 3 - (x.c64_cpuReadNS(0xdd00) & 3);
|
|
437
|
+
const screenBase = bank * 0x4000 + ((d018 >> 4) & 0x0f) * 0x400;
|
|
438
|
+
const bitmap = (d011 & 0x20) !== 0;
|
|
439
|
+
const mode =
|
|
440
|
+
(bitmap ? 'bitmap' : (d011 & 0x40) !== 0 ? 'ecm-text' : 'text') +
|
|
441
|
+
((d016 & 0x10) !== 0 ? '-multicolor' : '');
|
|
442
|
+
return { screenBase, bank, mode, lowercase: (d018 & 0x02) !== 0, displayOn: (d011 & 0x10) !== 0 };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export function readScreenText(x, info = readScreenInfo(x)) {
|
|
446
|
+
const lines = [];
|
|
447
|
+
for (let r = 0; r < 25; r++) {
|
|
448
|
+
let line = '';
|
|
449
|
+
for (let c = 0; c < 40; c++) {
|
|
450
|
+
line += screenCodeToChar(x.c64_ramRead(info.screenBase + r * 40 + c), info.lowercase);
|
|
451
|
+
}
|
|
452
|
+
lines.push(line.trimEnd());
|
|
453
|
+
}
|
|
454
|
+
while (lines.length && lines[lines.length - 1] === '') lines.pop();
|
|
455
|
+
return lines.join('\n');
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export function readRegs(x) {
|
|
459
|
+
const flags = {
|
|
460
|
+
N: x.c64_getFlagN(),
|
|
461
|
+
V: x.c64_getFlagV(),
|
|
462
|
+
B: x.c64_getFlagB(),
|
|
463
|
+
D: x.c64_getFlagD(),
|
|
464
|
+
I: x.c64_getFlagI(),
|
|
465
|
+
Z: x.c64_getFlagZ(),
|
|
466
|
+
C: x.c64_getFlagC(),
|
|
467
|
+
};
|
|
468
|
+
const p =
|
|
469
|
+
(flags.N ? 0x80 : 0) |
|
|
470
|
+
(flags.V ? 0x40 : 0) |
|
|
471
|
+
0x20 |
|
|
472
|
+
(flags.B ? 0x10 : 0) |
|
|
473
|
+
(flags.D ? 0x08 : 0) |
|
|
474
|
+
(flags.I ? 0x04 : 0) |
|
|
475
|
+
(flags.Z ? 0x02 : 0) |
|
|
476
|
+
(flags.C ? 0x01 : 0);
|
|
477
|
+
const flagStr = Object.entries(flags)
|
|
478
|
+
.map(([k, v]) => (v ? k : k.toLowerCase()))
|
|
479
|
+
.join('');
|
|
480
|
+
return {
|
|
481
|
+
pc: x.c64_getPC() & 0xffff,
|
|
482
|
+
a: x.c64_getRegA() & 0xff,
|
|
483
|
+
x: x.c64_getRegX() & 0xff,
|
|
484
|
+
y: x.c64_getRegY() & 0xff,
|
|
485
|
+
sp: x.c64_getSP() & 0xff,
|
|
486
|
+
p,
|
|
487
|
+
flags: flagStr,
|
|
488
|
+
rasterY: x.c64_getRasterY(),
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const hex = (n, w = 2) => n.toString(16).padStart(w, '0');
|
|
493
|
+
|
|
494
|
+
export function hexDump(x, start, end) {
|
|
495
|
+
const lines = [];
|
|
496
|
+
const bytes = [];
|
|
497
|
+
for (let a = start; a <= end; a += 16) {
|
|
498
|
+
const row = [];
|
|
499
|
+
for (let b = a; b <= Math.min(end, a + 15); b++) row.push(x.c64_cpuReadNS(b) & 0xff);
|
|
500
|
+
bytes.push(...row);
|
|
501
|
+
const ascii = row.map((v) => (v >= 0x20 && v < 0x7f ? String.fromCharCode(v) : '.')).join('');
|
|
502
|
+
lines.push(
|
|
503
|
+
`${hex(a, 4)}: ${row
|
|
504
|
+
.map((v) => hex(v))
|
|
505
|
+
.join(' ')
|
|
506
|
+
.padEnd(47)} ${ascii}`,
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
return { start, end, bytes, text: lines.join('\n') };
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
export function readVic(x) {
|
|
513
|
+
const regs = [];
|
|
514
|
+
for (let r = 0; r <= 0x2e; r++) regs.push(x.c64_vicReadRegister(r) & 0xff);
|
|
515
|
+
return regs;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// ── runner ───────────────────────────────────────────────────────────────────
|
|
519
|
+
|
|
520
|
+
async function loadWasm(wasmPath) {
|
|
521
|
+
const bin = await fs.readFile(wasmPath);
|
|
522
|
+
const ab = bin.buffer.slice(bin.byteOffset, bin.byteOffset + bin.byteLength);
|
|
523
|
+
const w = new C64WASM();
|
|
524
|
+
await w.instantiate(ab);
|
|
525
|
+
const x = w.exports;
|
|
526
|
+
x.c64_init();
|
|
527
|
+
x.sid_setSampleRate(44100);
|
|
528
|
+
x.debugger_set_speed(100);
|
|
529
|
+
x.debugger_play();
|
|
530
|
+
return w;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function startVideo(file) {
|
|
534
|
+
const ext = path.extname(file).toLowerCase();
|
|
535
|
+
const codec =
|
|
536
|
+
ext === '.gif'
|
|
537
|
+
? ['-vf', 'fps=25,split[a][b];[a]palettegen[p];[b][p]paletteuse']
|
|
538
|
+
: ext === '.webm'
|
|
539
|
+
? ['-c:v', 'libvpx-vp9', '-b:v', '1M']
|
|
540
|
+
: ['-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-preset', 'veryfast'];
|
|
541
|
+
const args = [
|
|
542
|
+
'-y',
|
|
543
|
+
'-loglevel',
|
|
544
|
+
'error',
|
|
545
|
+
'-f',
|
|
546
|
+
'rawvideo',
|
|
547
|
+
'-pix_fmt',
|
|
548
|
+
'rgba',
|
|
549
|
+
'-s',
|
|
550
|
+
`${FRAME_WIDTH}x${FRAME_HEIGHT}`,
|
|
551
|
+
'-framerate',
|
|
552
|
+
String(1000 / FRAME_MS),
|
|
553
|
+
'-i',
|
|
554
|
+
'-',
|
|
555
|
+
...codec,
|
|
556
|
+
file,
|
|
557
|
+
];
|
|
558
|
+
const proc = spawn('ffmpeg', args, { stdio: ['pipe', 'ignore', 'inherit'] });
|
|
559
|
+
const done = new Promise((resolve, reject) => {
|
|
560
|
+
proc.on('error', (e) =>
|
|
561
|
+
reject(new Error(`ffmpeg failed to start (is it on PATH?): ${e.message}`)),
|
|
562
|
+
);
|
|
563
|
+
proc.on('close', (code) =>
|
|
564
|
+
code === 0 ? resolve() : reject(new Error(`ffmpeg exited ${code}`)),
|
|
565
|
+
);
|
|
566
|
+
});
|
|
567
|
+
return {
|
|
568
|
+
async write(buf) {
|
|
569
|
+
if (!proc.stdin.write(buf)) await new Promise((r) => proc.stdin.once('drain', r));
|
|
570
|
+
},
|
|
571
|
+
async close() {
|
|
572
|
+
proc.stdin.end();
|
|
573
|
+
await done;
|
|
574
|
+
},
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Run the agent CLI.
|
|
580
|
+
* @param {{ argv?: string[], log?: (msg: string) => void }} options
|
|
581
|
+
* @returns {Promise<{ exitCode: number, report?: object, output: string }>}
|
|
582
|
+
*/
|
|
583
|
+
export async function runAgent(options = {}) {
|
|
584
|
+
const argv = options.argv ?? process.argv.slice(2);
|
|
585
|
+
const log = options.log ?? ((m) => process.stderr.write(`[c64-agent] ${m}\n`));
|
|
586
|
+
|
|
587
|
+
let o;
|
|
588
|
+
try {
|
|
589
|
+
o = parseArgs(argv);
|
|
590
|
+
} catch (e) {
|
|
591
|
+
return { exitCode: 1, output: `c64-agent: error: ${e.message} (see --help)` };
|
|
592
|
+
}
|
|
593
|
+
if (o.help) return { exitCode: 0, output: HELP };
|
|
594
|
+
|
|
595
|
+
const wasmPath = path.resolve(
|
|
596
|
+
o.wasm ?? new URL('../../public/c64.wasm', import.meta.url).pathname,
|
|
597
|
+
);
|
|
598
|
+
const w = await loadWasm(wasmPath);
|
|
599
|
+
const x = w.exports;
|
|
600
|
+
const warnings = [];
|
|
601
|
+
const shots = [];
|
|
602
|
+
|
|
603
|
+
const grabFrame = () => {
|
|
604
|
+
const ptr = x.c64_getPixelBuffer();
|
|
605
|
+
w.updateHeapViews();
|
|
606
|
+
return w.heap.heapU8.subarray(ptr, ptr + FRAME_WIDTH * FRAME_HEIGHT * 4);
|
|
607
|
+
};
|
|
608
|
+
const saveShot = async (file) => {
|
|
609
|
+
const abs = path.resolve(file);
|
|
610
|
+
await fs.mkdir(path.dirname(abs), { recursive: true });
|
|
611
|
+
await fs.writeFile(abs, encodePng(grabFrame(), FRAME_WIDTH, FRAME_HEIGHT, { scale: o.scale }));
|
|
612
|
+
shots.push(abs);
|
|
613
|
+
};
|
|
614
|
+
const step = () => x.debugger_update(FRAME_MS);
|
|
615
|
+
|
|
616
|
+
// Boot to the READY prompt (c64_init fast-boots; this is a safety net).
|
|
617
|
+
const bootToReady = () => {
|
|
618
|
+
for (let f = 0; f < BOOT_MAX_FRAMES; f++) {
|
|
619
|
+
if (readScreenText(x).includes('READY.')) return;
|
|
620
|
+
step();
|
|
621
|
+
}
|
|
622
|
+
warnings.push('BASIC READY prompt not detected after boot');
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// ── load ──
|
|
626
|
+
const typeQueue = [];
|
|
627
|
+
let type = null;
|
|
628
|
+
let loadAddress = null;
|
|
629
|
+
if (o.file) {
|
|
630
|
+
type = inferType(o.file);
|
|
631
|
+
const data = new Uint8Array(await fs.readFile(o.file));
|
|
632
|
+
if (type === 'prg' || type === 'd64') bootToReady();
|
|
633
|
+
const ptr = w.allocAndWrite(data);
|
|
634
|
+
if (type === 'prg') {
|
|
635
|
+
if (data.length < 3) throw new Error('PRG file too short');
|
|
636
|
+
loadAddress = data[0] | (data[1] << 8);
|
|
637
|
+
x.c64_loadPRG(ptr, data.length, 1);
|
|
638
|
+
if (o.run) {
|
|
639
|
+
if (o.sys !== null) typeQueue.push(...textToPetscii(`SYS${o.sys}\n`));
|
|
640
|
+
else if (loadAddress === 0x0801) typeQueue.push(...textToPetscii('RUN\n'));
|
|
641
|
+
else {
|
|
642
|
+
warnings.push(
|
|
643
|
+
`PRG loads at $${hex(loadAddress, 4)}, not $0801 — not auto-started. Use --sys <addr>.`,
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
} else if (type === 'crt') {
|
|
648
|
+
x.c64_loadCartridge(ptr, data.length);
|
|
649
|
+
} else if (type === 'd64') {
|
|
650
|
+
x.c64_setDriveEnabled(1);
|
|
651
|
+
x.c64_insertDisk(ptr, data.length);
|
|
652
|
+
// The emulated 1541 must finish its own ROM boot before it answers on the
|
|
653
|
+
// serial bus; a LOAD sent earlier hangs at "SEARCHING FOR *".
|
|
654
|
+
for (let f = 0; f < DRIVE_BOOT_FRAMES; f++) step();
|
|
655
|
+
typeQueue.push(...textToPetscii(o.run ? 'LOAD"*",8,1\nRUN\n' : 'LOAD"*",8,1\n'));
|
|
656
|
+
} else if (type === 'snapshot') {
|
|
657
|
+
x.c64_reset();
|
|
658
|
+
x.c64_loadSnapshot(ptr, data.length);
|
|
659
|
+
}
|
|
660
|
+
log(
|
|
661
|
+
`loaded ${path.basename(o.file)} (${type}${loadAddress !== null ? ` @ $${hex(loadAddress, 4)}` : ''})`,
|
|
662
|
+
);
|
|
663
|
+
} else {
|
|
664
|
+
bootToReady();
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
for (const p of o.pokes) p.values.forEach((v, i) => x.c64_cpuWrite(p.addr + i, v));
|
|
668
|
+
for (const b of o.breaks) x.breakpoints_pcAdd(b);
|
|
669
|
+
|
|
670
|
+
// ── schedule ──
|
|
671
|
+
const schedule = new Map();
|
|
672
|
+
for (const act of o.actions) {
|
|
673
|
+
if (!schedule.has(act.frame)) schedule.set(act.frame, []);
|
|
674
|
+
schedule.get(act.frame).push(act);
|
|
675
|
+
if (act.frame >= o.frames)
|
|
676
|
+
warnings.push(`--at frame ${act.frame} is beyond --frames ${o.frames}`);
|
|
677
|
+
}
|
|
678
|
+
const joyState = { 1: 0, 2: 0 };
|
|
679
|
+
const setJoy = (port, bits) => {
|
|
680
|
+
const p = port - 1;
|
|
681
|
+
if (joyState[port]) x.c64_joystick_release(p, joyState[port]);
|
|
682
|
+
if (bits) x.c64_joystick_push(p, bits);
|
|
683
|
+
joyState[port] = bits;
|
|
684
|
+
};
|
|
685
|
+
const releases = new Map(); // frame → keys[]
|
|
686
|
+
|
|
687
|
+
const video = o.video ? startVideo(path.resolve(o.video)) : null;
|
|
688
|
+
|
|
689
|
+
let frame = 0;
|
|
690
|
+
let stopReason = 'frames';
|
|
691
|
+
try {
|
|
692
|
+
for (; frame < o.frames; frame++) {
|
|
693
|
+
for (const act of schedule.get(frame) ?? []) {
|
|
694
|
+
if (act.kind === 'type') typeQueue.push(...act.bytes);
|
|
695
|
+
else if (act.kind === 'press' || act.kind === 'hold') {
|
|
696
|
+
act.keys.forEach((k) => x.keyboard_keyPressed(k));
|
|
697
|
+
if (act.kind === 'press') {
|
|
698
|
+
const at = frame + DEFAULT_TAP_FRAMES;
|
|
699
|
+
releases.set(at, [...(releases.get(at) ?? []), ...act.keys]);
|
|
700
|
+
}
|
|
701
|
+
} else if (act.kind === 'release') act.keys.forEach((k) => x.keyboard_keyReleased(k));
|
|
702
|
+
else if (act.kind === 'joy') setJoy(act.port, act.bits);
|
|
703
|
+
else if (act.kind === 'poke') act.values.forEach((v, i) => x.c64_cpuWrite(act.addr + i, v));
|
|
704
|
+
else if (act.kind === 'screenshot') await saveShot(act.path);
|
|
705
|
+
}
|
|
706
|
+
for (const k of releases.get(frame) ?? []) x.keyboard_keyReleased(k);
|
|
707
|
+
releases.delete(frame);
|
|
708
|
+
|
|
709
|
+
// Feed the KERNAL keyboard buffer whenever it has drained.
|
|
710
|
+
if (typeQueue.length && x.c64_cpuReadNS(KBD_BUF_LEN) === 0) {
|
|
711
|
+
const chunk = typeQueue.splice(0, KBD_BUF_MAX);
|
|
712
|
+
chunk.forEach((v, i) => x.c64_cpuWrite(KBD_BUF + i, v));
|
|
713
|
+
x.c64_cpuWrite(KBD_BUF_LEN, chunk.length);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
step();
|
|
717
|
+
|
|
718
|
+
if (video) await video.write(grabFrame());
|
|
719
|
+
if (o.every > 0 && (frame + 1) % o.every === 0) {
|
|
720
|
+
await saveShot(path.join(o.shotsDir, `frame-${String(frame + 1).padStart(5, '0')}.png`));
|
|
721
|
+
}
|
|
722
|
+
if (!x.debugger_isRunning()) {
|
|
723
|
+
const pc = x.c64_getPC() & 0xffff;
|
|
724
|
+
stopReason = o.breaks.includes(pc) ? 'breakpoint' : 'paused';
|
|
725
|
+
frame++;
|
|
726
|
+
break;
|
|
727
|
+
}
|
|
728
|
+
if (o.untilText && readScreenText(x).includes(o.untilText)) {
|
|
729
|
+
stopReason = 'until-text';
|
|
730
|
+
frame++;
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
} finally {
|
|
735
|
+
if (video) await video.close();
|
|
736
|
+
}
|
|
737
|
+
if (o.untilText && stopReason === 'frames') stopReason = 'until-text-timeout';
|
|
738
|
+
if (typeQueue.length)
|
|
739
|
+
warnings.push(
|
|
740
|
+
`${typeQueue.length} typed chars never consumed (program not reading keyboard buffer?)`,
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
// ── report ──
|
|
744
|
+
if (o.screenshot) await saveShot(o.screenshot);
|
|
745
|
+
if (o.saveSnapshot) {
|
|
746
|
+
const ptr = x.c64_getSnapshot();
|
|
747
|
+
const size = x.c64_getSnapshotSize();
|
|
748
|
+
w.updateHeapViews();
|
|
749
|
+
await fs.writeFile(path.resolve(o.saveSnapshot), w.heap.heapU8.slice(ptr, ptr + size));
|
|
750
|
+
}
|
|
751
|
+
const screenInfo = readScreenInfo(x);
|
|
752
|
+
const regs = o.regs ? readRegs(x) : undefined;
|
|
753
|
+
if (regs && o.symbols) regs.pcLabel = nearestSymbol(o.symbols, regs.pc);
|
|
754
|
+
const report = {
|
|
755
|
+
file: o.file ? path.resolve(o.file) : null,
|
|
756
|
+
type,
|
|
757
|
+
loadAddress,
|
|
758
|
+
framesRun: frame,
|
|
759
|
+
seconds: +((frame * FRAME_MS) / 1000).toFixed(2),
|
|
760
|
+
stopReason,
|
|
761
|
+
regs,
|
|
762
|
+
video: o.video ? path.resolve(o.video) : undefined,
|
|
763
|
+
screenshots: shots,
|
|
764
|
+
screenMode: screenInfo,
|
|
765
|
+
screen: o.screen || o.untilText ? readScreenText(x, screenInfo) : undefined,
|
|
766
|
+
dumps: o.dumps.length ? o.dumps.map((d) => hexDump(x, d.start, d.end)) : undefined,
|
|
767
|
+
vic: o.vic ? readVic(x) : undefined,
|
|
768
|
+
snapshot: o.saveSnapshot ? path.resolve(o.saveSnapshot) : undefined,
|
|
769
|
+
warnings,
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
const exitCode = stopReason === 'until-text-timeout' ? 3 : 0;
|
|
773
|
+
return { exitCode, report, output: o.json ? jsonReport(report) : textReport(report) };
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
function jsonReport(r) {
|
|
777
|
+
const copy = { ...r };
|
|
778
|
+
if (copy.dumps) copy.dumps = copy.dumps.map(({ start, end, bytes }) => ({ start, end, bytes }));
|
|
779
|
+
return JSON.stringify(copy, null, 2);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
export function textReport(r) {
|
|
783
|
+
const out = [];
|
|
784
|
+
out.push(
|
|
785
|
+
`stop: ${r.stopReason} after ${r.framesRun} frames (${r.seconds}s)` +
|
|
786
|
+
(r.file
|
|
787
|
+
? ` · ${path.basename(r.file)} [${r.type}${r.loadAddress !== null ? ` $${hex(r.loadAddress, 4)}` : ''}]`
|
|
788
|
+
: ''),
|
|
789
|
+
);
|
|
790
|
+
if (r.regs) {
|
|
791
|
+
const g = r.regs;
|
|
792
|
+
out.push(
|
|
793
|
+
`regs: PC=$${hex(g.pc, 4)}${g.pcLabel ? ` (${g.pcLabel})` : ''} A=$${hex(g.a)} X=$${hex(g.x)} Y=$${hex(g.y)} SP=$${hex(g.sp)} P=${g.flags} raster=${g.rasterY}`,
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
const m = r.screenMode;
|
|
797
|
+
out.push(
|
|
798
|
+
`video: ${m.mode}, screen $${hex(m.screenBase, 4)} (bank ${m.bank})${m.lowercase ? ', lowercase charset' : ''}${m.displayOn ? '' : ', DISPLAY OFF'}`,
|
|
799
|
+
);
|
|
800
|
+
if (r.screenshots.length) out.push(`screenshots: ${r.screenshots.join(', ')}`);
|
|
801
|
+
if (r.video) out.push(`video file: ${r.video}`);
|
|
802
|
+
if (r.snapshot) out.push(`snapshot: ${r.snapshot}`);
|
|
803
|
+
if (r.screen !== undefined) {
|
|
804
|
+
out.push('screen:');
|
|
805
|
+
out.push('┌' + '─'.repeat(40) + '┐');
|
|
806
|
+
for (const line of r.screen.split('\n')) out.push('│' + line.padEnd(40) + '│');
|
|
807
|
+
out.push('└' + '─'.repeat(40) + '┘');
|
|
808
|
+
}
|
|
809
|
+
if (r.dumps)
|
|
810
|
+
for (const d of r.dumps) out.push(`dump $${hex(d.start, 4)}-$${hex(d.end, 4)}:\n${d.text}`);
|
|
811
|
+
if (r.vic) {
|
|
812
|
+
const v = r.vic;
|
|
813
|
+
out.push('vic:');
|
|
814
|
+
for (let i = 0; i < v.length; i += 16) {
|
|
815
|
+
out.push(
|
|
816
|
+
` d0${hex(i)}: ${v
|
|
817
|
+
.slice(i, i + 16)
|
|
818
|
+
.map((b) => hex(b))
|
|
819
|
+
.join(' ')}`,
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
for (const w of r.warnings) out.push(`warning: ${w}`);
|
|
824
|
+
return out.join('\n');
|
|
825
|
+
}
|