@henols/c64-re-tools 2.5.1-rc.2 → 2.6.0-rc.10
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/package.json +2 -2
- package/skills/c64-assembler/SKILL.md +26 -12
- package/skills/c64-assembler/scripts/assembler.ts +25 -13
- package/skills/c64-development/SKILL.md +2 -2
- package/skills/c64-docs/SKILL.md +4 -4
- package/skills/c64-docs/scripts/docs.ts +7 -7
- package/skills/c64-docs/scripts/lib/reference.ts +3 -3
- package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
- package/skills/c64-knowledge/SKILL.md +29 -20
- package/skills/c64-knowledge/scripts/knowledge.ts +33 -39
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +11 -10
- package/skills/c64-provenance/scripts/lib/library.ts +16 -16
- package/skills/c64-provenance/scripts/provenance.ts +33 -23
- package/skills/c64-reverse-engineering/SKILL.md +16 -10
- package/skills/c64-source/SKILL.md +60 -42
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +26 -7
- package/skills/c64-source/scripts/lib/source.ts +21 -24
- package/skills/c64-source/scripts/lib/stage.ts +6 -5
- package/skills/c64-source/scripts/source.ts +213 -106
- package/skills/c64-static-analysis/SKILL.md +7 -5
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
- package/skills/c64-testing/SKILL.md +5 -2
- package/skills/c64-testing/references/recording-format.md +18 -3
- package/skills/c64-testing/references/scenario-format.md +7 -6
- package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
- package/skills/c64-testing/scripts/lib/play.ts +39 -41
- package/skills/c64-testing/scripts/lib/recording.ts +46 -37
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/runs.ts +2 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
- package/skills/c64-unpacker/SKILL.md +4 -1
- package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/skills/emulator/SKILL.md +7 -12
- package/src/build-name.ts +50 -0
- package/src/c64-keys.ts +98 -0
- package/src/c64.ts +20 -0
- package/src/cli/main.ts +3 -29
- package/src/host/main.ts +1 -1
- package/src/host/tools/index.ts +1 -6
- package/src/host/vice/session.ts +88 -9
- package/src/host-client/steps.ts +17 -17
- package/src/host-client/tools.ts +2 -7
- package/src/host-client/vice-session.ts +7 -1
- package/src/knowledge/program.ts +44 -1
- package/src/knowledge/read.ts +28 -8
- package/src/knowledge/schema.ts +33 -9
- package/src/knowledge/start-screen.ts +4 -0
- package/src/knowledge/text.ts +4 -2
- package/src/knowledge/write.ts +59 -25
- package/src/mcp/inputs.ts +12 -0
- package/src/mcp/server.ts +1 -1
- package/src/mcp/tools/input.ts +38 -5
- package/src/mcp/tools/machine.ts +3 -42
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/acme.ts +1 -1
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +3 -3
- package/src/native/dxa.ts +12 -1
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +4 -4
- package/src/native/types.ts +2 -2
- package/src/platform.ts +30 -1
- package/src/project.ts +17 -4
- package/src/protocol/tools.ts +1 -45
- package/src/protocol/vice.ts +47 -0
- package/src/script.ts +1 -1
- package/src/vsf.ts +98 -0
- package/tools/c64run.c +9 -12
- package/tools/install-container.sh +1 -2
- package/src/cli/status.ts +0 -127
- package/src/host/tools/status.ts +0 -47
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/src/native/status.ts +0 -135
- package/tools/install-ghidra.sh +0 -40
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { createServer, type ServerResponse } from "node:http";
|
|
10
10
|
|
|
11
|
+
import { keyTaps, type KeyTap } from "#src/c64-keys.ts";
|
|
11
12
|
import { PAL_FRAME_CYCLES, type C64RunSession } from "#src/native/c64run.ts";
|
|
12
13
|
|
|
13
14
|
const FRAME_MS = 20;
|
|
@@ -26,50 +27,46 @@ export interface PlayOptions {
|
|
|
26
27
|
restore: () => Promise<string | undefined>;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
/** The key codes of the replay core: chips c64.h, and 11, 12 and 5e of c64run. */
|
|
30
|
-
const C64 = {
|
|
31
|
-
del: 0x01, clr: 0x02, stop: 0x03, leftArrow: 0x04, run: 0x07, csrLeft: 0x08, csrRight: 0x09, csrDown: 0x0a, csrUp: 0x0b,
|
|
32
|
-
home: 0x0c, return: 0x0d, ctrl: 0x0e, cbm: 0x0f, inst: 0x10, leftShift: 0x11, rightShift: 0x12, space: 0x20, upArrow: 0x5e, pound: 0x7e,
|
|
33
|
-
} as const;
|
|
34
|
-
const F_KEYS = [0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8];
|
|
35
30
|
const LETTERS = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"];
|
|
36
31
|
const DIGITS = [..."0123456789"];
|
|
37
|
-
const
|
|
32
|
+
const F_KEYS = [1, 2, 3, 4, 5, 6, 7, 8].map((number) => `{F${number}}`);
|
|
33
|
+
/** The matrix places of one key, as a press step names it: a character, or a name in braces. */
|
|
34
|
+
const places = (key: string) => (keyTaps(key) as KeyTap[])[0]!.keys;
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
|
-
* The key maps of the page. Each one maps a KeyboardEvent property to
|
|
41
|
-
* The symbolic map (event.key) gives the character on the PC key;
|
|
42
|
-
* map (event.code) gives the C64 key at the place of the PC key, with each SHIFT alone.
|
|
37
|
+
* The key maps of the page. Each one maps a KeyboardEvent property to the matrix places
|
|
38
|
+
* that go down together. The symbolic map (event.key) gives the character on the PC key;
|
|
39
|
+
* the positional map (event.code) gives the C64 key at the place of the PC key, with each SHIFT alone.
|
|
43
40
|
*/
|
|
44
41
|
export const KEY_MAPS = {
|
|
45
42
|
/** event.code, in both maps. */
|
|
46
|
-
both: { Tab:
|
|
43
|
+
both: { Tab: places("{CTRL}"), AltLeft: places("{CBM}") },
|
|
47
44
|
/** event.code, when the arrow keys and space are keyboard keys. */
|
|
48
|
-
arrows: { ArrowUp:
|
|
45
|
+
arrows: { ArrowUp: places("{UP}"), ArrowDown: places("{DOWN}"), ArrowLeft: places("{LEFT}"), ArrowRight: places("{RIGHT}"), Space: places(" ") },
|
|
49
46
|
/** event.code */
|
|
50
47
|
positional: {
|
|
51
|
-
...Object.fromEntries(LETTERS.map((letter) => ["Key" + letter,
|
|
52
|
-
...Object.fromEntries(DIGITS.map((digit) => ["Digit" + digit,
|
|
53
|
-
...Object.fromEntries(F_KEYS.map((key, index) => ["F" + (index + 1), key])),
|
|
54
|
-
Backquote:
|
|
55
|
-
BracketLeft:
|
|
56
|
-
Escape:
|
|
57
|
-
ShiftLeft:
|
|
58
|
-
} as Record<string, number>,
|
|
48
|
+
...Object.fromEntries(LETTERS.map((letter) => ["Key" + letter, places(letter)])),
|
|
49
|
+
...Object.fromEntries(DIGITS.map((digit) => ["Digit" + digit, places(digit)])),
|
|
50
|
+
...Object.fromEntries(F_KEYS.map((key, index) => ["F" + (index + 1), places(key)])),
|
|
51
|
+
Backquote: places("{LEFTARROW}"), Minus: places("+"), Equal: places("-"), Insert: places("{POUND}"), Home: places("{HOME}"), Backspace: places("{DEL}"),
|
|
52
|
+
BracketLeft: places("@"), BracketRight: places("*"), Delete: places("{UPARROW}"),
|
|
53
|
+
Escape: places("{STOP}"), Semicolon: places(":"), Quote: places(";"), Backslash: places("="), Enter: places("{RETURN}"),
|
|
54
|
+
ShiftLeft: places("{LSHIFT}"), ShiftRight: places("{RSHIFT}"), Comma: places(","), Period: places("."), Slash: places("/"),
|
|
55
|
+
} as Record<string, number[]>,
|
|
59
56
|
/** event.key; a-z are the C64 letters, A-Z the letters with SHIFT. */
|
|
60
57
|
symbolic: {
|
|
61
|
-
...Object.fromEntries(LETTERS.flatMap((letter) => [[letter.toLowerCase(),
|
|
62
|
-
...Object.fromEntries([...DIGITS, ..."+-.:@,*;=/!\"#$%&'()[]<>?"].map((character) => [character,
|
|
63
|
-
...Object.fromEntries(F_KEYS.map((key, index) => ["F" + (index + 1), key])),
|
|
64
|
-
"£":
|
|
65
|
-
Enter:
|
|
66
|
-
} as Record<string, number>,
|
|
58
|
+
...Object.fromEntries(LETTERS.flatMap((letter) => [[letter.toLowerCase(), places(letter)], [letter, places(`{LSHIFT+${letter}}`)]])),
|
|
59
|
+
...Object.fromEntries([...DIGITS, ..."+-.:@,*;=/!\"#$%&'()[]<>?"].map((character) => [character, places(character)])),
|
|
60
|
+
...Object.fromEntries(F_KEYS.map((key, index) => ["F" + (index + 1), places(key)])),
|
|
61
|
+
"£": places("{POUND}"), "^": places("{UPARROW}"), "`": places("{LEFTARROW}"),
|
|
62
|
+
Enter: places("{RETURN}"), Backspace: places("{DEL}"), Delete: places("{DEL}"), Insert: places("{INST}"), Home: places("{HOME}"), Escape: places("{STOP}"),
|
|
63
|
+
} as Record<string, number[]>,
|
|
67
64
|
/** event.key with SHIFT held, in the symbolic map. */
|
|
68
|
-
symbolicShift: { Home:
|
|
65
|
+
symbolicShift: { Home: places("{CLR}"), Backspace: places("{INST}"), Escape: places("{RUN}"), F1: places("{F2}"), F3: places("{F4}"), F5: places("{F6}"), F7: places("{F8}") } as Record<string, number[]>,
|
|
69
66
|
};
|
|
70
67
|
|
|
71
|
-
/** The
|
|
72
|
-
const PAGE_KEYS = new Set(Object.values(KEY_MAPS).flatMap((map) => Object.values(map)));
|
|
68
|
+
/** The matrix places that the page can send: every place of the key maps. */
|
|
69
|
+
const PAGE_KEYS = new Set(Object.values(KEY_MAPS).flatMap((map) => Object.values(map).flat()));
|
|
73
70
|
|
|
74
71
|
const PAGE = String.raw`<!doctype html>
|
|
75
72
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
@@ -100,7 +97,7 @@ const BITS = { ArrowUp: 1, ArrowDown: 2, ArrowLeft: 4, ArrowRight: 8, Space: 16
|
|
|
100
97
|
const $ = (id) => document.getElementById(id);
|
|
101
98
|
const canvas = $("screen"), context = canvas.getContext("2d"), state = $("state");
|
|
102
99
|
let palette = [], image = context.createImageData(392, 272), frames = 0, phase = "connecting", port = 2, arrows = "joystick", keyMap = "symbolic", sent = -1;
|
|
103
|
-
// The
|
|
100
|
+
// The matrix places of each PC key that is down (by event.code), and the joystick keys that are down.
|
|
104
101
|
const pressed = new Map(), stick = new Set();
|
|
105
102
|
// One request at a time, so that the core gets each key down before its key up.
|
|
106
103
|
let queue = Promise.resolve();
|
|
@@ -120,7 +117,7 @@ function show() {
|
|
|
120
117
|
else state.textContent = phase;
|
|
121
118
|
}
|
|
122
119
|
function releaseAll() {
|
|
123
|
-
for (const
|
|
120
|
+
for (const keys of pressed.values()) send("key?keys=" + keys.join(",") + "&down=0");
|
|
124
121
|
pressed.clear();
|
|
125
122
|
stick.clear();
|
|
126
123
|
}
|
|
@@ -180,19 +177,19 @@ function key(event, down) {
|
|
|
180
177
|
}
|
|
181
178
|
if (arrows === "joystick" && event.code in BITS) { event.preventDefault(); down ? stick.add(event.code) : stick.delete(event.code); return; }
|
|
182
179
|
if (!down) {
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
180
|
+
const keys = pressed.get(event.code);
|
|
181
|
+
if (keys === undefined) return;
|
|
185
182
|
event.preventDefault();
|
|
186
183
|
pressed.delete(event.code);
|
|
187
|
-
send("key?
|
|
184
|
+
send("key?keys=" + keys.join(",") + "&down=0");
|
|
188
185
|
return;
|
|
189
186
|
}
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
187
|
+
const keys = c64Key(event);
|
|
188
|
+
if (keys === undefined) return;
|
|
192
189
|
event.preventDefault();
|
|
193
190
|
if (event.repeat || phase !== "playing" || pressed.has(event.code)) return;
|
|
194
|
-
pressed.set(event.code,
|
|
195
|
-
send("key?
|
|
191
|
+
pressed.set(event.code, keys);
|
|
192
|
+
send("key?keys=" + keys.join(",") + "&down=1");
|
|
196
193
|
}
|
|
197
194
|
addEventListener("keydown", (event) => key(event, true));
|
|
198
195
|
addEventListener("keyup", (event) => key(event, false));
|
|
@@ -262,9 +259,10 @@ export async function play(core: Pick<C64RunSession, "command" | "status">, opti
|
|
|
262
259
|
if (phase === "playing") mask = Number(url.searchParams.get("mask")) & 0x1f;
|
|
263
260
|
answer(phase === "playing");
|
|
264
261
|
} else if (request.method === "POST" && url.pathname === "/key") {
|
|
265
|
-
const
|
|
266
|
-
if (!PAGE_KEYS.has(key)) return void response.writeHead(400).end();
|
|
267
|
-
|
|
262
|
+
const keys = (url.searchParams.get("keys") ?? "").split(",").map((key) => (/^\d{1,2}$/.test(key) ? Number(key) : -1));
|
|
263
|
+
if (!keys.every((key) => PAGE_KEYS.has(key))) return void response.writeHead(400).end();
|
|
264
|
+
const state = url.searchParams.get("down") === "1" ? "down" : "up";
|
|
265
|
+
if (phase === "playing") for (const key of keys) pending.push("key " + (0x80 + key).toString(16) + " " + state);
|
|
268
266
|
answer(phase === "playing");
|
|
269
267
|
} else if (request.method === "POST" && url.pathname === "/restore") {
|
|
270
268
|
if (phase === "playing") pending.push(RESTORE);
|
|
@@ -13,9 +13,11 @@ import { readFileSync, writeFileSync } from "node:fs";
|
|
|
13
13
|
|
|
14
14
|
import { isRefusal, Refusal } from "#src/errors.ts";
|
|
15
15
|
import { c64AddressOf, formatC64Address, parseC64Address } from "#src/c64.ts";
|
|
16
|
+
import { keyTaps, type KeyTap } from "#src/c64-keys.ts";
|
|
16
17
|
import { READY_FRAMES } from "#src/host-client/entry-state.ts";
|
|
17
18
|
import { ACTION_STEP_KINDS, checkActionStep, isInteger, isObject, keyboardBytes, renamedField, stepKind, type ActionStep, type Location } from "#src/host-client/steps.ts";
|
|
18
19
|
import { readProjectFile, type Written } from "#src/host-client/transfer.ts";
|
|
20
|
+
import { START_SCREEN_CONTINUE, START_SCREEN_WAIT } from "#src/knowledge/start-screen.ts";
|
|
19
21
|
import { PAL_FRAME_CYCLES, type C64RunSession, type CoreStatus } from "#src/native/c64run.ts";
|
|
20
22
|
import type { Workspace } from "#src/native/staging.ts";
|
|
21
23
|
import { namesOf, type Outcome } from "./scenario.ts";
|
|
@@ -137,20 +139,8 @@ const QUEUE_SIZE = 10;
|
|
|
137
139
|
|
|
138
140
|
const hex = (address: number) => address.toString(16).padStart(4, "0");
|
|
139
141
|
|
|
140
|
-
/** The
|
|
141
|
-
const
|
|
142
|
-
...[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 +-.:@,*;=/!\"#$%&'()[]<>?"].map((character) => [character, character.charCodeAt(0)] as [string, number]),
|
|
143
|
-
["\n", 0x0d],
|
|
144
|
-
]);
|
|
145
|
-
|
|
146
|
-
/** The key codes of a text; a-z type as A-Z, as the C64 shows them after power-on. */
|
|
147
|
-
export function keyCodes(text: string): number[] {
|
|
148
|
-
return [...text.replace(/\r\n?/g, "\n")].map((character) => {
|
|
149
|
-
const code = KEY_CODES.get(character.toUpperCase());
|
|
150
|
-
if (code === undefined) throw new Refusal("invalid-input", `press cannot press ${JSON.stringify(character)} on the C64 keyboard`);
|
|
151
|
-
return code;
|
|
152
|
-
});
|
|
153
|
-
}
|
|
142
|
+
/** The key code of the replay core for a matrix place: 80 + the place. RESTORE is ff. */
|
|
143
|
+
const coreKey = (place: number) => (0x80 + place).toString(16);
|
|
154
144
|
|
|
155
145
|
/** The joystick mask of the replay core: 1 up, 2 down, 4 left, 8 right, $10 fire. */
|
|
156
146
|
export function joystickMask(direction: Extract<ActionStep, { joystick: unknown }>["joystick"]["direction"], fire: boolean): number {
|
|
@@ -225,7 +215,7 @@ export function readRecordFile(path: string): RecordFile {
|
|
|
225
215
|
if (!Array.isArray(value.steps) || value.steps.length === 0) fail("steps must be a list with at least one step");
|
|
226
216
|
const steps = (value.steps as unknown[]).map((raw, index) => {
|
|
227
217
|
const at = `step ${index + 1}`;
|
|
228
|
-
const step = checkActionStep(stepKind(raw, ACTION_STEP_KINDS, at, fail), raw as Record<string, unknown>, at, fail
|
|
218
|
+
const step = checkActionStep(stepKind(raw, ACTION_STEP_KINDS, at, fail), raw as Record<string, unknown>, at, fail);
|
|
229
219
|
checkCoreStep(step, at, fail);
|
|
230
220
|
return step;
|
|
231
221
|
});
|
|
@@ -244,14 +234,6 @@ export function readRecordFile(path: string): RecordFile {
|
|
|
244
234
|
/** What the replay core cannot do of a step that is right for VICE: it has the C64 alone, no raster wait and no conditions. */
|
|
245
235
|
function checkCoreStep(step: ActionStep, at: string, fail: (message: string) => never): void {
|
|
246
236
|
if ("write" in step && step.write.space !== "c64") fail(`${at}: a recording has the C64 alone, not ${step.write.space}`);
|
|
247
|
-
if ("press" in step) {
|
|
248
|
-
try {
|
|
249
|
-
keyCodes(step.press);
|
|
250
|
-
} catch (error) {
|
|
251
|
-
if (isRefusal(error)) fail(`${at}: ${error.message}`);
|
|
252
|
-
throw error;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
237
|
if ("type" in step) {
|
|
256
238
|
const keys = keyboardBytes(step.type);
|
|
257
239
|
if (typeof keys !== "string" && keys.length > QUEUE_SIZE) fail(`${at}: the KERNAL keyboard queue holds ${QUEUE_SIZE} keys; give more type steps, or press for keys of the keyboard matrix`);
|
|
@@ -297,7 +279,7 @@ export function readRecording(folder: string): Recording {
|
|
|
297
279
|
const named = typeof event.step === "number" ? `${at} (step ${event.step})` : at;
|
|
298
280
|
if (event.action.restore === true && Object.keys(event.action).length === 1) return;
|
|
299
281
|
// The action with the defaults filled in, as the record file gave it.
|
|
300
|
-
event.action = checkActionStep(stepKind(event.action, ACTION_STEP_KINDS, named, where), event.action, named, where
|
|
282
|
+
event.action = checkActionStep(stepKind(event.action, ACTION_STEP_KINDS, named, where), event.action, named, where);
|
|
301
283
|
});
|
|
302
284
|
return value as unknown as Recording;
|
|
303
285
|
}
|
|
@@ -387,10 +369,10 @@ function busiestSite(answer: string): { site: number; addr: number; count: numbe
|
|
|
387
369
|
* Runs to the point of an event. `map` moves a site to the rebuild. "halted"
|
|
388
370
|
* when a sample stop came first, "not-reached" when the point did not come before `until`.
|
|
389
371
|
*/
|
|
390
|
-
async function runToKey(core: C64RunSession, key: RecordedEvent["key"], until: number, map: Map<number, number
|
|
372
|
+
async function runToKey(core: C64RunSession, key: RecordedEvent["key"], until: number, map: Map<number, number>, skipped: number): Promise<"reached" | "not-reached" | "halted"> {
|
|
391
373
|
if ("previous" in key) return (await core.status("status")).word === "halted" ? "halted" : "reached";
|
|
392
374
|
if ("tick" in key) {
|
|
393
|
-
const status = await core.status(`run ${key.tick}`);
|
|
375
|
+
const status = await core.status(`run ${key.tick + skipped}`);
|
|
394
376
|
return status.word === "halted" ? "halted" : "reached";
|
|
395
377
|
}
|
|
396
378
|
const site = parseC64Address(key.site);
|
|
@@ -509,7 +491,7 @@ export async function record(
|
|
|
509
491
|
: busiest === undefined
|
|
510
492
|
? { tick: tick + 1 }
|
|
511
493
|
: { site: formatC64Address(busiest.site), addr: formatC64Address(busiest.addr), count: busiest.count + 1 };
|
|
512
|
-
if ((await runToKey(core, key, tick + 600 * PAL_FRAME_CYCLES, new Map())) !== "reached") return "the program did not read its input again within 600 frames";
|
|
494
|
+
if ((await runToKey(core, key, tick + 600 * PAL_FRAME_CYCLES, new Map(), 0)) !== "reached") return "the program did not read its input again within 600 frames";
|
|
513
495
|
events.push({ ...(step === undefined ? {} : { step }), action, key });
|
|
514
496
|
return doAction(core, action, at);
|
|
515
497
|
};
|
|
@@ -522,11 +504,22 @@ export async function record(
|
|
|
522
504
|
masks[step.joystick.port - 1] = joystickMask(step.joystick.direction, step.joystick.fire ?? false);
|
|
523
505
|
await core.command(`joy ${masks[0]!.toString(16)} ${masks[1]!.toString(16)}`);
|
|
524
506
|
} else if ("press" in step) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
await core.
|
|
528
|
-
|
|
529
|
-
await
|
|
507
|
+
const hold = step.press.frames * PAL_FRAME_CYCLES;
|
|
508
|
+
for (const tap of keyTaps(step.press.keys) as KeyTap[]) {
|
|
509
|
+
for (const place of tap.keys) await core.command(`key ${coreKey(place)} down`);
|
|
510
|
+
// RESTORE is no read: an event at the next read of the program, with the keys of the tap down.
|
|
511
|
+
if (tap.restore) reason = await runEvent({ restore: true }, index + 1);
|
|
512
|
+
if (reason !== undefined) break;
|
|
513
|
+
tick = (await core.status("status")).tick;
|
|
514
|
+
await core.status(`run ${(tick += hold)}`);
|
|
515
|
+
for (const place of tap.keys) await core.command(`key ${coreKey(place)} up`);
|
|
516
|
+
await core.status(`run ${(tick += hold)}`);
|
|
517
|
+
// Frames ran: the next RESTORE is no event right after an event.
|
|
518
|
+
afterEvent = false;
|
|
519
|
+
}
|
|
520
|
+
if (reason !== undefined) {
|
|
521
|
+
reason = `step ${index + 1}: RESTORE: ${reason}`;
|
|
522
|
+
break;
|
|
530
523
|
}
|
|
531
524
|
} else {
|
|
532
525
|
reason = await runEvent(step, index + 1);
|
|
@@ -590,6 +583,8 @@ export interface SideRun {
|
|
|
590
583
|
end: CoreStatus;
|
|
591
584
|
/** Why the side stopped before its last checkpoint, if it did. */
|
|
592
585
|
problem?: string;
|
|
586
|
+
/** True when the rebuild went on after the wait of its start screen. */
|
|
587
|
+
startScreenSkipped?: boolean;
|
|
593
588
|
/**
|
|
594
589
|
* Input reads that the recording has no value for, which got the fixed idle value:
|
|
595
590
|
* at sites that it does not have, and after its end at a site.
|
|
@@ -620,7 +615,8 @@ export async function replaySide(
|
|
|
620
615
|
const move = original
|
|
621
616
|
? { code: same, data: same }
|
|
622
617
|
: { code: mover(namesOf(names, "code"), namesOf(subject.symbols, "code")), data: mover(namesOf(names), namesOf(subject.symbols)) };
|
|
623
|
-
const
|
|
618
|
+
const own = namesOf(subject.symbols);
|
|
619
|
+
const at = sideAddresses(own, subject.side, move);
|
|
624
620
|
const moved = original ? [] : siteMap(recording.sites, namesOf(names, "code"), namesOf(subject.symbols, "code"));
|
|
625
621
|
const map = new Map(moved);
|
|
626
622
|
const reads = workspace.path(`${subject.side}-${RECORDING_FILES.reads}`);
|
|
@@ -645,11 +641,24 @@ export async function replaySide(
|
|
|
645
641
|
await core.command(`sample ${hex(at.code(options.compare.checkpoint))} ${samples} ${rangesArgument([...options.compare.state, ...pinned], at)}${stop > 0 ? ` ${stop}` : ""}`);
|
|
646
642
|
}
|
|
647
643
|
await startProgram(core, prg, recording.load);
|
|
648
|
-
|
|
644
|
+
let limit = original ? recording.ticks : recording.ticks * REBUILD_TIME_FACTOR;
|
|
649
645
|
let problem: string | undefined;
|
|
650
|
-
for
|
|
646
|
+
// A loader with a start screen that RUN starts waits for a key or a fire button that the recording does not have:
|
|
647
|
+
// the rebuild goes on after the wait, as the check of the loader does. The cycles to the wait do not count.
|
|
648
|
+
const wait = own.get(START_SCREEN_WAIT);
|
|
649
|
+
const resume = own.get(START_SCREEN_CONTINUE);
|
|
650
|
+
let skipped = 0;
|
|
651
|
+
if (!original && !recording.load && wait !== undefined && resume !== undefined) {
|
|
652
|
+
const reached = await core.status(`run-pc ${hex(wait)} ${limit}`);
|
|
653
|
+
if (reached.word === "reached") {
|
|
654
|
+
skipped = reached.tick;
|
|
655
|
+
limit += skipped;
|
|
656
|
+
await core.status(`goto ${hex(resume)}`);
|
|
657
|
+
} else problem = `the rebuild did not come to the wait of its start screen at ${formatC64Address(wait)}`;
|
|
658
|
+
}
|
|
659
|
+
for (const event of problem === undefined ? recording.events : []) {
|
|
651
660
|
const what = event.step === undefined ? "the RESTORE of the play" : "step " + event.step;
|
|
652
|
-
const point = await runToKey(core, event.key, limit, map);
|
|
661
|
+
const point = await runToKey(core, event.key, limit, map, skipped);
|
|
653
662
|
if (point === "halted") break;
|
|
654
663
|
if (point === "not-reached") {
|
|
655
664
|
problem = "the program did not come to the point of " + what;
|
|
@@ -672,7 +681,7 @@ export async function replaySide(
|
|
|
672
681
|
await core.command("sample off");
|
|
673
682
|
lines = readFileSync(samples, "utf8").split("\n").filter((line) => line !== "");
|
|
674
683
|
}
|
|
675
|
-
return { samples: lines, end, unknown, misses, ...(problem === undefined ? {} : { problem }), ...(ram === undefined ? {} : { ram }) };
|
|
684
|
+
return { samples: lines, end, unknown, misses, ...(problem === undefined ? {} : { problem }), ...(skipped > 0 ? { startScreenSkipped: true } : {}), ...(ram === undefined ? {} : { ram }) };
|
|
676
685
|
}
|
|
677
686
|
|
|
678
687
|
export interface CheckpointDifference {
|
|
@@ -93,7 +93,7 @@ export async function replay(values: ReplayOptions): Promise<ReplayResult> {
|
|
|
93
93
|
const replayed = await side(rebuild, { compare: compare!, stop: expected.length, pins });
|
|
94
94
|
const difference = firstDifference(expected, replayed.samples, compare!.state);
|
|
95
95
|
// A read that the recording has no value for gets the idle value: it is in the result, never silent.
|
|
96
|
-
const base = { checkpoints: expected.length, movedSites, ...(replayed.unknown > 0 ? { idleReads: replayed.unknown } : {}) };
|
|
96
|
+
const base = { checkpoints: expected.length, movedSites, ...(replayed.startScreenSkipped === true ? { startScreen: "skipped" } : {}), ...(replayed.unknown > 0 ? { idleReads: replayed.unknown } : {}) };
|
|
97
97
|
if (difference === undefined && replayed.samples.length >= expected.length) return result("PASS", "rebuild", { ...base, compared: expected.length });
|
|
98
98
|
const reason =
|
|
99
99
|
difference !== undefined
|
|
@@ -9,7 +9,7 @@ import { screenText } from "#src/graphics.ts";
|
|
|
9
9
|
import { runProgram } from "#src/host-client/autostart.ts";
|
|
10
10
|
import { isRefusal, Refusal } from "#src/errors.ts";
|
|
11
11
|
import { readCoverage } from "#src/host-client/coverage.ts";
|
|
12
|
-
import { ACTION_STEP_KINDS, checkActionStep, checkLocation, checkStepNames, isInteger, isObject, refuseOldStep, renamedField, runActionStep,
|
|
12
|
+
import { ACTION_STEP_KINDS, checkActionStep, checkLocation, checkStepNames, isInteger, isObject, refuseOldStep, renamedField, runActionStep, type ActionStep, type ActionStepKind } from "#src/host-client/steps.ts";
|
|
13
13
|
import { readPrg } from "#src/host-client/image.ts";
|
|
14
14
|
import { MAX_MEMORY_READ, MAX_TRACE_FRAMES, MAX_TRACE_HITS, MAX_TRACE_POINTS, TRACE_KINDS, WireFailure, type TraceHit, type TraceKind } from "#src/host-client/tools.ts";
|
|
15
15
|
import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
|
|
@@ -131,7 +131,7 @@ function readRun(path: string): Run {
|
|
|
131
131
|
if (!isObject(step)) return fail(`${at} must be an object`);
|
|
132
132
|
const kinds = "observe" in step ? ["observe"] : "expect" in step ? ["expect"] : "trace" in step ? ["trace"] : Object.keys(step).filter((key) => (ACTION_STEP_KINDS as readonly string[]).includes(key) || (OWN_KINDS as readonly string[]).includes(key));
|
|
133
133
|
if (kinds.length > 1) return fail(`${at} has ${kinds.length} step kinds: ${kinds.join(", ")}. Give each one its own step`);
|
|
134
|
-
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...
|
|
134
|
+
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...ACTION_STEP_KINDS, ...OWN_KINDS].join(", ")}`);
|
|
135
135
|
const kind = kinds[0]!;
|
|
136
136
|
refuseOldStep(kind, step, at, fail);
|
|
137
137
|
const allowed = kind === "observe" ? OBSERVE_KEYS : kind === "expect" ? EXPECT_KEYS : kind === "trace" ? TRACE_KEYS : [kind];
|
|
@@ -7,7 +7,7 @@ import { isRefusal, Refusal } from "#src/errors.ts";
|
|
|
7
7
|
import { c64AddressOf, formatC64Address, formatSprite, formatVicii, parseC64Address } from "#src/c64.ts";
|
|
8
8
|
import { MAX_BASELINES, MAX_MASK_RECTANGLES, maskCoversFrame, WireFailure } from "#src/host-client/tools.ts";
|
|
9
9
|
import { LOAD_LIMIT_FRAMES, RUN_LIMIT_FRAMES, runProgram } from "#src/host-client/autostart.ts";
|
|
10
|
-
import { ACTION_STEP_KINDS, checkActionStep, checkLocation, isInteger, isObject, refuseOldStep, renamedField, runActionStep,
|
|
10
|
+
import { ACTION_STEP_KINDS, checkActionStep, checkLocation, isInteger, isObject, refuseOldStep, renamedField, runActionStep, type ActionStep, type ActionStepKind, type Location } from "#src/host-client/steps.ts";
|
|
11
11
|
import { applyEntryState, parseEntryState } from "#src/host-client/entry-state.ts";
|
|
12
12
|
import { readPrg } from "#src/host-client/image.ts";
|
|
13
13
|
import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
|
|
@@ -33,6 +33,8 @@ export interface MemoryObservation {
|
|
|
33
33
|
view?: "cpu" | "ram";
|
|
34
34
|
/** The largest allowed difference per byte; 0 when not given. */
|
|
35
35
|
tolerance?: number;
|
|
36
|
+
/** Hex bits that the comparison uses: one byte for each byte, or one byte per byte of the range; all bits when not given. */
|
|
37
|
+
mask?: string;
|
|
36
38
|
/** Bytes in the range that the comparison leaves out, each with the reason. */
|
|
37
39
|
exclude?: Array<{ address: Location; reason: string }>;
|
|
38
40
|
}
|
|
@@ -50,7 +52,7 @@ type StepBody =
|
|
|
50
52
|
| { autostart: true }
|
|
51
53
|
| { snapshot: string }
|
|
52
54
|
| { normalize: true }
|
|
53
|
-
|
|
|
55
|
+
| ActionStep
|
|
54
56
|
| { observe: string; memory?: Array<Location | MemoryObservation>; registers?: ObservedRegister[]; screen?: ScreenPolicy; vicii?: boolean; sprites?: number[] };
|
|
55
57
|
|
|
56
58
|
/** A step; with side, only that side does it. An observe step has no side: it compares both. */
|
|
@@ -106,8 +108,6 @@ export interface ScenarioResult {
|
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
const STEP_KINDS = ["reset", "load", "autostart", "snapshot", "normalize", ...ACTION_STEP_KINDS, "observe"];
|
|
109
|
-
/** The step kinds that a scenario runs: press is for the replay core only. */
|
|
110
|
-
const SHOWN_KINDS = ["reset", "load", "autostart", "snapshot", "normalize", ...VICE_STEP_KINDS, "observe"];
|
|
111
111
|
|
|
112
112
|
/** The keys of a scenario file: all but videoStandard are required. */
|
|
113
113
|
const SCENARIO_KEYS = ["name", "original", "rebuild", "steps", "videoStandard"];
|
|
@@ -154,7 +154,7 @@ export function readScenario(path: string): Scenario {
|
|
|
154
154
|
// An observe step names what it observes with "memory" and "registers" too.
|
|
155
155
|
const kinds = "observe" in step ? ["observe"] : Object.keys(step).filter((key) => STEP_KINDS.includes(key));
|
|
156
156
|
if (kinds.length > 1) return fail(`${at} has ${kinds.length} step kinds: ${kinds.join(", ")}. Give each one its own step`);
|
|
157
|
-
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${
|
|
157
|
+
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${STEP_KINDS.join(", ")}`);
|
|
158
158
|
const kind = kinds[0]!;
|
|
159
159
|
refuseOldStep(kind, step, at, fail);
|
|
160
160
|
const allowed = [...(STEP_KEYS[kind] ?? [kind]), ...(kind === "observe" ? [] : ["side"])];
|
|
@@ -207,7 +207,7 @@ function checkObserve(step: Record<string, unknown>, at: string, fail: (message:
|
|
|
207
207
|
checkLocation(item, `${at}: memory`, fail);
|
|
208
208
|
continue;
|
|
209
209
|
}
|
|
210
|
-
const itemFields = ["address", "size", "view", "tolerance", "exclude"];
|
|
210
|
+
const itemFields = ["address", "size", "view", "tolerance", "mask", "exclude"];
|
|
211
211
|
if (!isObject(item)) return fail(`${at}: memory must be a list of names, $ addresses or objects with address`);
|
|
212
212
|
for (const key of Object.keys(item)) if (!itemFields.includes(key)) fail(`${at}: a memory object has the field ${key}. ${renamedField(key, itemFields) ?? `It has ${itemFields.join(", ")}, and nothing else`}`);
|
|
213
213
|
if (item.view !== undefined && item.view !== "cpu" && item.view !== "ram") fail(`${at}: memory.view must be cpu or ram`);
|
|
@@ -223,6 +223,12 @@ function checkObserve(step: Record<string, unknown>, at: string, fail: (message:
|
|
|
223
223
|
checkLocation(item.address, `${at}: memory.address`, fail);
|
|
224
224
|
if (item.size !== undefined && !isInteger(item.size, 1, 0x10000)) fail(`${at}: memory.size must be a number from 1 to 65536`);
|
|
225
225
|
if (item.tolerance !== undefined && !isInteger(item.tolerance, 0, 0xff)) fail(`${at}: memory.tolerance must be a number from 0 to 255`);
|
|
226
|
+
if (item.mask !== undefined) {
|
|
227
|
+
const size = isInteger(item.size, 1, 0x10000) ? item.size : 1;
|
|
228
|
+
if (typeof item.mask !== "string" || !/^(?:[0-9a-fA-F]{2})+$/.test(item.mask) || (item.mask.length !== 2 && item.mask.length !== size * 2)) {
|
|
229
|
+
fail(`${at}: memory.mask must be hex bits, one byte for each byte (for example 0f) or one byte per byte of size`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
234
|
if (step.registers !== undefined) {
|
|
@@ -354,7 +360,7 @@ export function resolve(location: Location, symbols: Map<string, number>, side:
|
|
|
354
360
|
}
|
|
355
361
|
|
|
356
362
|
interface Observation {
|
|
357
|
-
memory: Array<{ label: string; address: number; bytes: number[]; tolerance: number; excluded: Array<{ offset: number; address: Location; reason: string }> }>;
|
|
363
|
+
memory: Array<{ label: string; address: number; bytes: number[]; tolerance: number; mask?: number[]; excluded: Array<{ offset: number; address: Location; reason: string }> }>;
|
|
358
364
|
registers: Partial<Record<ObservedRegister, unknown>>;
|
|
359
365
|
screen?: { match: boolean; mismatchingPixels: number; comparedPixels: number; mismatchRatio: number; bounds?: unknown };
|
|
360
366
|
vicii?: unknown;
|
|
@@ -444,7 +450,7 @@ async function runStep(client: ViceSessionClient, scenario: Scenario, side: Side
|
|
|
444
450
|
if (offset < 0 || offset >= size) throw new Refusal("invalid-input", `the exclude ${exclude.address} lies outside the observed ${spec.address} (${size} bytes)`);
|
|
445
451
|
return { offset, address: exclude.address, reason: exclude.reason };
|
|
446
452
|
});
|
|
447
|
-
observation.memory.push({ label: size > 1 ? `${spec.address} (${size} bytes)` : spec.address, address, bytes: [...Buffer.from(read.data, "hex")], tolerance: spec.tolerance ?? 0, excluded });
|
|
453
|
+
observation.memory.push({ label: size > 1 ? `${spec.address} (${size} bytes)` : spec.address, address, bytes: [...Buffer.from(read.data, "hex")], tolerance: spec.tolerance ?? 0, ...(spec.mask === undefined ? {} : { mask: [...Buffer.from(spec.mask, "hex")] }), excluded });
|
|
448
454
|
}
|
|
449
455
|
if (step.registers !== undefined) {
|
|
450
456
|
const registers = await client.registersGet("c64");
|
|
@@ -495,11 +501,12 @@ async function runStep(client: ViceSessionClient, scenario: Scenario, side: Side
|
|
|
495
501
|
|
|
496
502
|
type MemoryItem = Observation["memory"][number];
|
|
497
503
|
|
|
498
|
-
/** The bytes of a memory item
|
|
504
|
+
/** The bytes of a memory item whose bits of the mask differ by more than its tolerance, without the excluded bytes. */
|
|
499
505
|
function differingBytes(item: MemoryItem, other: MemoryItem): DifferingByte[] {
|
|
500
506
|
const hex = (byte: number) => byte.toString(16).padStart(2, "0");
|
|
501
507
|
const skipped = new Set(item.excluded.map((excluded) => excluded.offset));
|
|
502
|
-
|
|
508
|
+
const bits = (offset: number) => (item.mask === undefined ? 0xff : item.mask.length === 1 ? item.mask[0]! : item.mask[offset]!);
|
|
509
|
+
return item.bytes.flatMap((byte, offset) => (!skipped.has(offset) && Math.abs((byte & bits(offset)) - (other.bytes[offset]! & bits(offset))) > item.tolerance ? [{ address: formatC64Address(item.address + offset), original: hex(byte), rebuild: hex(other.bytes[offset]!) }] : []));
|
|
503
510
|
}
|
|
504
511
|
|
|
505
512
|
/** The most differing bytes of one memory item that a result lists when no --max-listed is given. */
|
|
@@ -58,13 +58,15 @@ Each step has one of these kinds:
|
|
|
58
58
|
- `{ "registers": { "pc": "start", "a": 1 } }` sets registers. Only `pc` takes a name.
|
|
59
59
|
- `{ "joystick": { "port": 2, "direction": "up", "fire": false } }` sets a joystick.
|
|
60
60
|
- `{ "type": { "mode": "text", "text": "RUN\n" } }` or `{ "type": { "mode": "petscii", "bytes": [147] } }` puts keys in the keyboard queue of the KERNAL.
|
|
61
|
+
- `{ "press": { "keys": "{F1}" } }` presses keys of the keyboard matrix. Each character is one tap. A name in braces is a key without a character, for example `{STOP}` or `{RESTORE}`. `+` in braces holds keys together, for example `{LSHIFT+CBM}`. `frames` is 1 to 3000, and 3 by default.
|
|
61
62
|
- `{ "frames": 50 }` runs 1 to 30000 frames.
|
|
62
63
|
- `{ "runUntil": { "target": { "kind": "address", "address": "main_loop" }, "timeoutFrames": 300 } }` runs until the target. The target kinds are `address`, `memory` and `raster`. `timeoutFrames` is 1 to 30000. The default is 3000.
|
|
63
64
|
- `{ "capture": "level1" }` captures a part. Only `loads` takes this step. Give each capture step a different name of 1 to 64 letters, digits, dots, underscores or hyphens.
|
|
65
|
+
- `{ "save": "at-call" }` writes the machine state to `<out>/at-call.vsf`. Only `loads` takes this step. A run of the program can start from this snapshot file, for example at the call of a routine of a loading stage. Give each save step a different name.
|
|
64
66
|
|
|
65
67
|
An address in a step can be a name. The script refuses an unknown name before the program runs. The message gives the file and the step.
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
A program that reads the keyboard matrix does not see the keys of a `type` step. Use a `press` step for that program. A wait for any key that reads all keyboard columns can end without a key.
|
|
68
70
|
|
|
69
71
|
The script refuses a step in an old form. The message gives the step to write.
|
|
70
72
|
|
|
@@ -231,6 +233,7 @@ A segment is a block of RAM from `$0400` that the program changed after the capt
|
|
|
231
233
|
|
|
232
234
|
- `loaded`: true when a capture has a segment.
|
|
233
235
|
- `captures`: one item for each capture step, with `capture`, `out`, `files`, `removed`, `pc`, `segments`, `excluded`, `differsFromReset`, `smallChanges` and `drive`.
|
|
236
|
+
- `saved`: one item for each save step, with `save`, `file` and `pc`.
|
|
234
237
|
- `smallChanges`: the count of changed bytes in blocks that are smaller than `--min-block`.
|
|
235
238
|
- `keyWait: true`: the CPU was in the KERNAL wait for a key, at READY or at an INPUT statement.
|
|
236
239
|
- `drive`: the name of the drive file, with `--drive`.
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// The loads command of c64-unpacker: one capture for each part of a
|
|
2
|
-
// multi-load program. The steps file has action steps
|
|
3
|
-
// capture writes what the C64 side changed since the previous
|
|
4
|
-
// image with its entry state, and with --drive the drive RAM as
|
|
5
|
-
// knowledge space drive8.
|
|
2
|
+
// multi-load program. The steps file has action steps, capture steps and save
|
|
3
|
+
// steps; a capture writes what the C64 side changed since the previous
|
|
4
|
+
// capture as an image with its entry state, and with --drive the drive RAM as
|
|
5
|
+
// a PRG for knowledge space drive8. A save writes the machine state as a
|
|
6
|
+
// snapshot file, which a run can start from. No tool guesses where a load
|
|
7
|
+
// ends: the steps decide.
|
|
6
8
|
|
|
7
9
|
import { type AddressRange, COVERAGE, formatC64Address } from "#src/c64.ts";
|
|
8
10
|
import { Refusal } from "#src/errors.ts";
|
|
9
11
|
import { autostartLoaded, LOAD_LIMIT_FRAMES, RUN_LIMIT_FRAMES, typeRun } from "#src/host-client/autostart.ts";
|
|
10
12
|
import { IO_RAM, markIoRamWrites, readCoverage } from "#src/host-client/coverage.ts";
|
|
11
|
-
import { ACTION_STEP_KINDS, checkActionStep, checkStepNames, isObject, runActionStep,
|
|
13
|
+
import { ACTION_STEP_KINDS, checkActionStep, checkStepNames, isObject, runActionStep, type ActionStep, type ActionStepKind } from "#src/host-client/steps.ts";
|
|
12
14
|
import { knowledgeAt } from "#src/knowledge/names.ts";
|
|
13
15
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
14
16
|
import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
|
|
@@ -17,9 +19,9 @@ import { entryStateFile, json, machineState, readRam, readyState, removeStaleFil
|
|
|
17
19
|
import { FIRST_SEGMENT_ADDRESS } from "./stages.ts";
|
|
18
20
|
|
|
19
21
|
|
|
20
|
-
export type LoadStep = ActionStep | { capture: string };
|
|
22
|
+
export type LoadStep = ActionStep | { capture: string } | { save: string };
|
|
21
23
|
|
|
22
|
-
/** A capture name: letters, digits, dots, underscores or hyphens. */
|
|
24
|
+
/** A capture or save name: letters, digits, dots, underscores or hyphens. */
|
|
23
25
|
const NAME = /^[A-Za-z0-9._-]{1,64}$/;
|
|
24
26
|
/** The drive RAM of a 1541. */
|
|
25
27
|
const DRIVE_RAM = 0x0800;
|
|
@@ -28,7 +30,7 @@ const KERNAL_LOAD = 0xffd5;
|
|
|
28
30
|
/** The KERNAL loop that waits for a key at READY. or at an INPUT statement. */
|
|
29
31
|
const KERNAL_KEY_WAIT = { start: 0xe5cd, end: 0xe5d5 };
|
|
30
32
|
|
|
31
|
-
/** Reads and checks the steps file of loads: action steps with $ addresses, and capture steps with new names. */
|
|
33
|
+
/** Reads and checks the steps file of loads: action steps with $ addresses, and capture and save steps with new names. */
|
|
32
34
|
export function readLoadSteps(path: string): LoadStep[] {
|
|
33
35
|
let value: unknown;
|
|
34
36
|
try {
|
|
@@ -42,9 +44,17 @@ export function readLoadSteps(path: string): LoadStep[] {
|
|
|
42
44
|
};
|
|
43
45
|
if (!Array.isArray(value) || value.length === 0) return fail("the steps are a JSON list with at least one step");
|
|
44
46
|
const names = new Set<string>();
|
|
47
|
+
const saves = new Set<string>();
|
|
45
48
|
value.forEach((step: unknown, index) => {
|
|
46
49
|
const at = `step ${index + 1}`;
|
|
47
50
|
if (!isObject(step)) return fail(`${at} must be an object`);
|
|
51
|
+
if ("save" in step) {
|
|
52
|
+
if (Object.keys(step).length !== 1) fail(`${at}: a save step has only save`);
|
|
53
|
+
if (typeof step.save !== "string" || !NAME.test(step.save)) fail(`${at}: save needs a name of 1 to 64 letters, digits, dots, underscores or hyphens`);
|
|
54
|
+
if (saves.has(step.save as string)) fail(`${at}: the save name ${step.save as string} is used before`);
|
|
55
|
+
saves.add(step.save as string);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
48
58
|
if ("capture" in step) {
|
|
49
59
|
if (Object.keys(step).length !== 1) fail(`${at}: a capture step has only capture`);
|
|
50
60
|
if (typeof step.capture !== "string" || !NAME.test(step.capture)) fail(`${at}: capture needs a name of 1 to 64 letters, digits, dots, underscores or hyphens`);
|
|
@@ -54,14 +64,14 @@ export function readLoadSteps(path: string): LoadStep[] {
|
|
|
54
64
|
}
|
|
55
65
|
const kinds = Object.keys(step).filter((key) => (ACTION_STEP_KINDS as readonly string[]).includes(key));
|
|
56
66
|
if (kinds.length > 1) return fail(`${at} has ${kinds.length} step kinds: ${kinds.join(", ")}. Give each one its own step`);
|
|
57
|
-
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...
|
|
67
|
+
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...ACTION_STEP_KINDS, "capture", "save"].join(", ")}`);
|
|
58
68
|
// The step with its defaults filled in, as the shared schema of the action steps gives it.
|
|
59
69
|
const checked = checkActionStep(kinds[0] as ActionStepKind, step, at, fail);
|
|
60
70
|
// Its names resolve now: an unknown name stops the call before the emulator starts.
|
|
61
71
|
checkStepNames([checked], knowledgeAt(), `--steps ${path}`, index + 1);
|
|
62
72
|
(value as unknown[])[index] = checked;
|
|
63
73
|
});
|
|
64
|
-
if (names.size === 0) fail("the steps have no capture step");
|
|
74
|
+
if (names.size === 0 && saves.size === 0) fail("the steps have no capture step and no save step");
|
|
65
75
|
return value as LoadStep[];
|
|
66
76
|
}
|
|
67
77
|
|
|
@@ -149,12 +159,23 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
const captures: Array<Record<string, unknown>> = [];
|
|
162
|
+
const saved: Array<Record<string, unknown>> = [];
|
|
152
163
|
for (const [index, step] of options.steps.entries()) {
|
|
164
|
+
if ("save" in step) {
|
|
165
|
+
// The machine state as a snapshot file: a run starts from it, for example at the call of a loading stage.
|
|
166
|
+
if ((await client.status()).state === "running") await client.execution({ action: "pause", space: "c64" });
|
|
167
|
+
await client.snapshot({ action: "save", name: "loads-save" });
|
|
168
|
+
const path = `${options.out}/${step.save}.vsf`;
|
|
169
|
+
const file = writeReported(path, await client.snapshotExport("loads-save"), { what: "--out" });
|
|
170
|
+
await client.snapshot({ action: "remove", name: "loads-save" });
|
|
171
|
+
saved.push({ save: step.save, file, pc: formatC64Address((await client.registersGet("c64")).pc) });
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
153
174
|
if (!("capture" in step)) {
|
|
154
175
|
const notReached = await runActionStep(client, step, knowledgeAt());
|
|
155
176
|
if (notReached !== undefined && "runUntil" in step) {
|
|
156
177
|
const reason = `Step ${index + 1} did not reach its target in ${step.runUntil.timeoutFrames} frames. It stopped by ${notReached.stopReason} at ${formatC64Address(notReached.pc)}.`;
|
|
157
|
-
return { output: { loaded: false, reason, captures }, failed: true };
|
|
178
|
+
return { output: { loaded: false, reason, captures, ...(saved.length === 0 ? {} : { saved }) }, failed: true };
|
|
158
179
|
}
|
|
159
180
|
continue;
|
|
160
181
|
}
|
|
@@ -226,9 +247,9 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
226
247
|
if (captures.length > 0 && captures.every((capture) => (capture.segments as unknown[]).length === 0)) {
|
|
227
248
|
const waits = captures.some((capture) => capture.keyWait === true) ? " The C64 waited for a key at READY. or at an INPUT statement, so the load ended or did not start." : "";
|
|
228
249
|
const reason = `No capture has a segment: the program changed no block of RAM from ${formatC64Address(FIRST_SEGMENT_ADDRESS)} on.${waits}`;
|
|
229
|
-
return { output: { loaded: false, reason, captures }, failed: true };
|
|
250
|
+
return { output: { loaded: false, reason, captures, ...(saved.length === 0 ? {} : { saved }) }, failed: true };
|
|
230
251
|
}
|
|
231
|
-
return { output: { loaded: true, captures }, failed: false };
|
|
252
|
+
return { output: { loaded: true, captures, ...(saved.length === 0 ? {} : { saved }) }, failed: false };
|
|
232
253
|
} finally {
|
|
233
254
|
await client.close();
|
|
234
255
|
}
|
|
@@ -642,7 +642,9 @@ function loaded(call: Call, { output, failed }: { output: Record<string, unknown
|
|
|
642
642
|
if (failed) return result;
|
|
643
643
|
const out = call.string("out")!;
|
|
644
644
|
const drive = call.flag("drive") ? ` Put the drive RAM ${out}/<name>/drive8.prg into the project knowledge in the space drive8.` : "";
|
|
645
|
-
|
|
645
|
+
const captures = (output.captures as unknown[]).length === 0 ? "" : `Put the capture ${out}/<name>/image.json of the part that you work on into the project knowledge.${drive}`;
|
|
646
|
+
const saved = output.saved === undefined ? "" : `A run of the program can start from a snapshot file ${out}/<name>.vsf.`;
|
|
647
|
+
return reply(result, { hint: [captures, saved].filter((text) => text !== "").join(" ") });
|
|
646
648
|
}
|
|
647
649
|
|
|
648
650
|
const COMMANDS: CommandSpec[] = [
|
|
@@ -702,10 +704,10 @@ const COMMANDS: CommandSpec[] = [
|
|
|
702
704
|
},
|
|
703
705
|
{
|
|
704
706
|
name: "loads",
|
|
705
|
-
summary: "Runs a multi-load program with the steps file. Each capture step {\"capture\": \"<name>\"} writes <dir>/<name>/ with image.bin, image.json, entry_state.json and a PRG for each block that the C64 side changed since the previous capture.",
|
|
707
|
+
summary: "Runs a multi-load program with the steps file. Each capture step {\"capture\": \"<name>\"} writes <dir>/<name>/ with image.bin, image.json, entry_state.json and a PRG for each block that the C64 side changed since the previous capture. Each save step {\"save\": \"<name>\"} writes the machine state to <dir>/<name>.vsf.",
|
|
706
708
|
subjects: [{ name: "<program>", help: "a PRG, or a disk, tape or cartridge image, relative to the project folder" }],
|
|
707
709
|
options: {
|
|
708
|
-
steps: { ...STEPS, required: true, help: "action steps and
|
|
710
|
+
steps: { ...STEPS, required: true, help: "action steps, capture steps and save steps (JSON)" },
|
|
709
711
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", required: true, help: "the folder for the captures, relative to the project folder" },
|
|
710
712
|
drive: { kind: "flag", help: "also write the 2 KiB drive RAM as drive8.prg, for knowledge space drive8" },
|
|
711
713
|
"min-block": { kind: "count", value: "<bytes>", min: 1, max: 0x10000, default: 64, help: "write a changed block of at least this many bytes (default 64)" },
|