@henols/c64-re-tools 2.6.0-rc.9 → 2.7.0-rc.1
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 +1 -1
- package/skills/c64-assembler/SKILL.md +7 -7
- package/skills/c64-assembler/scripts/assembler.ts +4 -3
- package/skills/c64-basic/SKILL.md +1 -1
- package/skills/c64-development/SKILL.md +7 -7
- package/skills/c64-disk/SKILL.md +13 -13
- package/skills/c64-docs/SKILL.md +25 -10
- package/skills/c64-docs/references/page-types.md +11 -11
- package/skills/c64-docs/references/style.md +21 -0
- package/skills/c64-docs/scripts/docs.ts +78 -18
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +117 -31
- package/skills/c64-docs/scripts/lib/source-map.ts +14 -0
- package/skills/c64-knowledge/SKILL.md +15 -14
- package/skills/c64-knowledge/scripts/knowledge.ts +17 -10
- package/skills/c64-memory-map/SKILL.md +1 -1
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +5 -4
- package/skills/c64-provenance/scripts/lib/compare.ts +1 -1
- package/skills/c64-reverse-engineering/SKILL.md +26 -11
- package/skills/c64-source/SKILL.md +18 -15
- package/skills/c64-source/scripts/lib/export.ts +20 -8
- package/skills/c64-source/scripts/lib/loader.ts +51 -28
- package/skills/c64-source/scripts/lib/source.ts +27 -20
- package/skills/c64-source/scripts/source.ts +68 -53
- package/skills/c64-static-analysis/SKILL.md +24 -22
- package/skills/c64-static-analysis/scripts/lib/findings.ts +11 -11
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +4 -4
- package/skills/c64-static-analysis/scripts/lib/macros.ts +3 -1
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -27
- package/skills/c64-testing/SKILL.md +32 -24
- package/skills/c64-testing/references/recording-format.md +15 -9
- package/skills/c64-testing/references/scenario-format.md +9 -7
- package/skills/c64-testing/scripts/lib/recording.ts +214 -49
- package/skills/c64-testing/scripts/lib/replay.ts +45 -19
- package/skills/c64-testing/scripts/lib/runs.ts +7 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +31 -31
- package/skills/c64-testing/scripts/testing.ts +37 -16
- package/skills/c64-unpacker/SKILL.md +16 -14
- package/skills/c64-unpacker/scripts/lib/stages.ts +18 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +38 -6
- package/src/build-name.ts +9 -4
- package/src/c64.ts +1 -1
- package/src/host/main.ts +2 -2
- package/src/host/server.ts +3 -1
- package/src/host/tools/index.ts +1 -1
- package/src/host/vice/process.ts +34 -17
- package/src/host/vice/session.ts +55 -27
- package/src/host-client/steps.ts +4 -1
- package/src/host-client/tools.ts +1 -1
- package/src/knowledge/evidence.ts +66 -0
- package/src/knowledge/history.ts +5 -5
- package/src/knowledge/import.ts +12 -5
- package/src/knowledge/program.ts +81 -33
- package/src/knowledge/read.ts +3 -3
- package/src/knowledge/schema.ts +7 -7
- package/src/knowledge/separate.ts +2 -2
- package/src/knowledge/start-screen.ts +2 -0
- package/src/knowledge/text.ts +28 -3
- package/src/knowledge/write.ts +7 -7
- package/src/mcp/tools/debug.ts +23 -21
- package/src/mcp/tools/memory.ts +12 -9
- package/src/native/c64run.ts +7 -4
- package/src/native/{ghidra → decompiler}/analyze.ts +17 -17
- package/src/native/{ghidra → decompiler}/language/c64rt_6510.slaspec +1 -1
- package/src/native/{ghidra → decompiler}/walk.ts +6 -6
- package/src/native/types.ts +25 -25
- package/src/opcodes.ts +1 -1
- package/src/project.ts +1 -1
- package/src/reference-pages.ts +64 -0
- package/src/script.ts +2 -2
- package/tools/c64run.c +151 -5
- /package/src/native/{ghidra → decompiler}/c64rt-wasm.ts +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.cspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.ldefs +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.pspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.sla +0 -0
- /package/src/native/{ghidra → decompiler}/pcode.ts +0 -0
- /package/src/native/{ghidra → decompiler}/wasm.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Functional-equivalence scenarios: a small JSON scenario of ordered
|
|
2
|
-
// steps runs on the
|
|
2
|
+
// steps runs on the reference and then on the rebuild in one VICE session.
|
|
3
3
|
// Observations name semantic symbols that resolve per side, comparisons are
|
|
4
4
|
// explicit, and the result is PASS, FAIL or INCONCLUSIVE.
|
|
5
5
|
|
|
@@ -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, type ActionStep, type ActionStepKind, type Location } from "#src/host-client/steps.ts";
|
|
10
|
+
import { ACTION_STEP_KINDS, aStep, 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";
|
|
@@ -19,8 +19,8 @@ import { DEFAULT_SPACE } from "#src/knowledge/schema.ts";
|
|
|
19
19
|
import { programImage } from "#src/knowledge/program.ts";
|
|
20
20
|
import { listed } from "#src/script.ts";
|
|
21
21
|
|
|
22
|
-
export type Side = "
|
|
23
|
-
export const SIDES: Side[] = ["
|
|
22
|
+
export type Side = "reference" | "rebuild";
|
|
23
|
+
export const SIDES: Side[] = ["reference", "rebuild"];
|
|
24
24
|
|
|
25
25
|
/** A "$xxxx" address or a symbol name that each side resolves on its own. */
|
|
26
26
|
export type { Location };
|
|
@@ -67,7 +67,7 @@ export interface Subject {
|
|
|
67
67
|
export interface Scenario {
|
|
68
68
|
name: string;
|
|
69
69
|
videoStandard?: "pal" | "ntsc";
|
|
70
|
-
|
|
70
|
+
reference: Subject;
|
|
71
71
|
rebuild: Subject;
|
|
72
72
|
steps: Step[];
|
|
73
73
|
}
|
|
@@ -77,7 +77,7 @@ export type Outcome = "PASS" | "FAIL" | "INCONCLUSIVE";
|
|
|
77
77
|
/** A byte of a memory item that differs: its address, and its value on each side as two hex digits. */
|
|
78
78
|
export interface DifferingByte {
|
|
79
79
|
address: string;
|
|
80
|
-
|
|
80
|
+
reference: string;
|
|
81
81
|
rebuild: string;
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -89,7 +89,7 @@ export interface DifferingByte {
|
|
|
89
89
|
export interface Difference {
|
|
90
90
|
checkpoint: string;
|
|
91
91
|
what: string;
|
|
92
|
-
|
|
92
|
+
reference?: unknown;
|
|
93
93
|
rebuild?: unknown;
|
|
94
94
|
bytes?: { count: number; listed: DifferingByte[]; rest?: string };
|
|
95
95
|
}
|
|
@@ -110,8 +110,8 @@ export interface ScenarioResult {
|
|
|
110
110
|
const STEP_KINDS = ["reset", "load", "autostart", "snapshot", "normalize", ...ACTION_STEP_KINDS, "observe"];
|
|
111
111
|
|
|
112
112
|
/** The keys of a scenario file: all but videoStandard are required. */
|
|
113
|
-
const SCENARIO_KEYS = ["name", "
|
|
114
|
-
const SCENARIO_FIELDS = "A scenario file has name,
|
|
113
|
+
const SCENARIO_KEYS = ["name", "reference", "rebuild", "steps", "videoStandard"];
|
|
114
|
+
const SCENARIO_FIELDS = "A scenario file has name, reference, rebuild and steps, and optionally videoStandard";
|
|
115
115
|
|
|
116
116
|
/** The keys each kind of step can have. */
|
|
117
117
|
const STEP_KEYS: Record<string, readonly string[]> = {
|
|
@@ -154,12 +154,12 @@ 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 ${STEP_KINDS.join(", ")}`);
|
|
157
|
+
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${STEP_KINDS.join(", ")}${typeof step.screen === "string" ? `. A scenario compares the screen in an observe step: {"observe": "${step.screen}", "screen": {}}` : ""}`);
|
|
158
158
|
const kind = kinds[0]!;
|
|
159
159
|
refuseOldStep(kind, step, at, fail);
|
|
160
160
|
const allowed = [...(STEP_KEYS[kind] ?? [kind]), ...(kind === "observe" ? [] : ["side"])];
|
|
161
|
-
for (const key of Object.keys(step)) if (!allowed.includes(key)) fail(`${at} has the key ${key}, which
|
|
162
|
-
if (step.side !== undefined && !(SIDES as unknown[]).includes(step.side)) fail(`${at}: side must be
|
|
161
|
+
for (const key of Object.keys(step)) if (!allowed.includes(key)) fail(`${at} has the key ${key}, which ${aStep(kind)} does not have`);
|
|
162
|
+
if (step.side !== undefined && !(SIDES as unknown[]).includes(step.side)) fail(`${at}: side must be reference or rebuild`);
|
|
163
163
|
if ((ACTION_STEP_KINDS as readonly string[]).includes(kind)) {
|
|
164
164
|
// The step with its defaults filled in, as the shared schema of the action steps gives it.
|
|
165
165
|
scenario.steps[index] = { ...checkActionStep(kind as ActionStepKind, { [kind]: step[kind] }, at, fail), ...(step.side === undefined ? {} : { side: step.side as Side }) } as Step;
|
|
@@ -255,7 +255,7 @@ function checkObserve(step: Record<string, unknown>, at: string, fail: (message:
|
|
|
255
255
|
isInteger(rectangle.height, 1, 4096);
|
|
256
256
|
if (!ok) fail(`${at}: a screen.mask rectangle needs whole numbers x and y from 0, and width and height from 1`);
|
|
257
257
|
}
|
|
258
|
-
// The emulator refuses such a compare too, but only after the
|
|
258
|
+
// The emulator refuses such a compare too, but only after the reference side ran.
|
|
259
259
|
if (maskCoversFrame(screen.mask as Array<{ x: number; y: number; width: number; height: number }>, videoStandard)) fail(`${at}: screen.mask covers the whole screen, so nothing is compared`);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
@@ -464,7 +464,7 @@ async function runStep(client: ViceSessionClient, scenario: Scenario, side: Side
|
|
|
464
464
|
if (step.sprites !== undefined) observation.sprites = (await client.sprites(step.sprites)).sprites.map(formatSprite);
|
|
465
465
|
if (step.screen !== undefined) {
|
|
466
466
|
const baseline = baselineName(checkpoint, step.observe);
|
|
467
|
-
if (side === "
|
|
467
|
+
if (side === "reference") {
|
|
468
468
|
const shot = await client.screenCapture(baseline);
|
|
469
469
|
if (files) observation.png = shot.png;
|
|
470
470
|
} else {
|
|
@@ -506,7 +506,7 @@ function differingBytes(item: MemoryItem, other: MemoryItem): DifferingByte[] {
|
|
|
506
506
|
const hex = (byte: number) => byte.toString(16).padStart(2, "0");
|
|
507
507
|
const skipped = new Set(item.excluded.map((excluded) => excluded.offset));
|
|
508
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),
|
|
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), reference: hex(byte), rebuild: hex(other.bytes[offset]!) }] : []));
|
|
510
510
|
}
|
|
511
511
|
|
|
512
512
|
/** The most differing bytes of one memory item that a result lists when no --max-listed is given. */
|
|
@@ -517,10 +517,10 @@ export const DEFAULT_LISTED_BYTES = 50;
|
|
|
517
517
|
* under the scenario's rules. A memory item lists at most `max` differing
|
|
518
518
|
* bytes; `rest` tells where the others are.
|
|
519
519
|
*/
|
|
520
|
-
export function compare(
|
|
520
|
+
export function compare(reference: Map<string, Observation>, rebuild: Map<string, Observation>, options: { max?: number; rest?: string } = {}): Difference[] {
|
|
521
521
|
const differences: Difference[] = [];
|
|
522
522
|
const max = options.max ?? DEFAULT_LISTED_BYTES;
|
|
523
|
-
for (const [checkpoint, left] of
|
|
523
|
+
for (const [checkpoint, left] of reference) {
|
|
524
524
|
const right = rebuild.get(checkpoint)!;
|
|
525
525
|
left.memory.forEach((item, index) => {
|
|
526
526
|
const bytes = differingBytes(item, right.memory[index]!);
|
|
@@ -528,12 +528,12 @@ export function compare(original: Map<string, Observation>, rebuild: Map<string,
|
|
|
528
528
|
});
|
|
529
529
|
for (const [name, value] of Object.entries(left.registers)) {
|
|
530
530
|
const other = right.registers[name as ObservedRegister];
|
|
531
|
-
if (JSON.stringify(other) !== JSON.stringify(value)) differences.push({ checkpoint, what: `register ${name}`,
|
|
531
|
+
if (JSON.stringify(other) !== JSON.stringify(value)) differences.push({ checkpoint, what: `register ${name}`, reference: value, rebuild: other });
|
|
532
532
|
}
|
|
533
533
|
const screenDiffers = right.screen !== undefined && !right.screen.match;
|
|
534
|
-
if (screenDiffers) differences.push({ checkpoint, what: "screen",
|
|
535
|
-
if (left.vicii !== undefined && JSON.stringify(left.vicii) !== JSON.stringify(right.vicii)) differences.push({ checkpoint, what: "VIC-II state",
|
|
536
|
-
if (left.sprites !== undefined && JSON.stringify(left.sprites) !== JSON.stringify(right.sprites)) differences.push({ checkpoint, what: "sprites",
|
|
534
|
+
if (screenDiffers) differences.push({ checkpoint, what: "screen", reference: "baseline", rebuild: right.screen });
|
|
535
|
+
if (left.vicii !== undefined && JSON.stringify(left.vicii) !== JSON.stringify(right.vicii)) differences.push({ checkpoint, what: "VIC-II state", reference: left.vicii, rebuild: right.vicii });
|
|
536
|
+
if (left.sprites !== undefined && JSON.stringify(left.sprites) !== JSON.stringify(right.sprites)) differences.push({ checkpoint, what: "sprites", reference: left.sprites, rebuild: right.sprites });
|
|
537
537
|
}
|
|
538
538
|
return differences;
|
|
539
539
|
}
|
|
@@ -543,18 +543,18 @@ export function compare(original: Map<string, Observation>, rebuild: Map<string,
|
|
|
543
543
|
* screens and the difference image, and memory.json with each differing
|
|
544
544
|
* memory item: all its bytes on each side, and each byte that differs.
|
|
545
545
|
*/
|
|
546
|
-
function writeFailFiles(out: string,
|
|
546
|
+
function writeFailFiles(out: string, reference: Map<string, Observation>, rebuild: Map<string, Observation>, differences: Difference[]): Written[] {
|
|
547
547
|
const files: Written[] = [];
|
|
548
548
|
const write = (name: string, bytes: Uint8Array) => {
|
|
549
549
|
files.push(writeReported(`${out}/${name}`, bytes, { what: "--out" }));
|
|
550
550
|
};
|
|
551
|
-
const memory: Array<{ checkpoint: string; what: string; address: string;
|
|
551
|
+
const memory: Array<{ checkpoint: string; what: string; address: string; reference: string; rebuild: string; bytes: DifferingByte[] }> = [];
|
|
552
552
|
for (const difference of differences) {
|
|
553
|
-
const left =
|
|
553
|
+
const left = reference.get(difference.checkpoint)!;
|
|
554
554
|
const right = rebuild.get(difference.checkpoint)!;
|
|
555
555
|
const name = difference.checkpoint.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
556
556
|
if (difference.what === "screen") {
|
|
557
|
-
if (left.png !== undefined) write(`${name}-
|
|
557
|
+
if (left.png !== undefined) write(`${name}-reference.png`, Buffer.from(left.png, "base64"));
|
|
558
558
|
if (right.png !== undefined) write(`${name}-rebuild.png`, Buffer.from(right.png, "base64"));
|
|
559
559
|
if (right.diffPng !== undefined) write(`${name}-diff.png`, Buffer.from(right.diffPng, "base64"));
|
|
560
560
|
}
|
|
@@ -563,14 +563,14 @@ function writeFailFiles(out: string, original: Map<string, Observation>, rebuild
|
|
|
563
563
|
const item = left.memory[index]!;
|
|
564
564
|
const other = right.memory[index]!;
|
|
565
565
|
const show = (bytes: number[]) => Buffer.from(bytes).toString("hex");
|
|
566
|
-
memory.push({ checkpoint: difference.checkpoint, what: difference.what, address: formatC64Address(item.address),
|
|
566
|
+
memory.push({ checkpoint: difference.checkpoint, what: difference.what, address: formatC64Address(item.address), reference: show(item.bytes), rebuild: show(other.bytes), bytes: differingBytes(item, other) });
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
if (memory.length > 0) write("memory.json", Buffer.from(`${JSON.stringify(memory, null, 2)}\n`));
|
|
570
570
|
return files;
|
|
571
571
|
}
|
|
572
572
|
|
|
573
|
-
/** Runs the scenario on the
|
|
573
|
+
/** Runs the scenario on the reference, then on the rebuild, in one VICE session. With out, a FAIL leaves files there. */
|
|
574
574
|
export async function runScenario(client: ViceSessionClient, scenario: Scenario, options: { out?: string; names?: Map<Side, Map<string, number>>; max?: number } = {}): Promise<ScenarioResult> {
|
|
575
575
|
const checkpoints = scenario.steps.flatMap((step) => ("observe" in step ? [step.observe] : []));
|
|
576
576
|
const observed = new Map<Side, Map<string, Observation>>();
|
|
@@ -587,11 +587,11 @@ export async function runScenario(client: ViceSessionClient, scenario: Scenario,
|
|
|
587
587
|
throw error;
|
|
588
588
|
}
|
|
589
589
|
}
|
|
590
|
-
const
|
|
590
|
+
const reference = observed.get("reference")!;
|
|
591
591
|
const rebuild = observed.get("rebuild")!;
|
|
592
|
-
const differences = compare(
|
|
593
|
-
const excluded = [...
|
|
594
|
-
const files = differences.length > 0 && options.out !== undefined ? writeFailFiles(options.out,
|
|
592
|
+
const differences = compare(reference, rebuild, { ...(options.max === undefined ? {} : { max: options.max }), rest: options.out === undefined ? "a larger --max-listed, or --out <dir> for memory.json with every byte" : `${options.out}/memory.json` });
|
|
593
|
+
const excluded = [...reference].flatMap(([checkpoint, observation]) => observation.memory.flatMap((item) => item.excluded.map((excluded) => ({ checkpoint, address: excluded.address, reason: excluded.reason }))));
|
|
594
|
+
const files = differences.length > 0 && options.out !== undefined ? writeFailFiles(options.out, reference, rebuild, differences) : [];
|
|
595
595
|
return {
|
|
596
596
|
result: differences.length === 0 ? "PASS" : "FAIL",
|
|
597
597
|
scenario: scenario.name,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The c64-testing script. test runs a scenario on the
|
|
1
|
+
// The c64-testing script. test runs a scenario on the reference and the
|
|
2
2
|
// rebuild in one emulator; run runs steps on one side and writes what they
|
|
3
3
|
// ask for; record and replay play a session in the replay core (c64run) and
|
|
4
4
|
// compare the rebuild with it; diff shows what changed between two states;
|
|
@@ -13,7 +13,10 @@ import { ViceSessionClient } from "#src/host-client/vice-session.ts";
|
|
|
13
13
|
import { C64RunSession, PAL_FRAME_CYCLES } from "#src/native/c64run.ts";
|
|
14
14
|
import { localToolContext } from "#src/native/local.ts";
|
|
15
15
|
import { Workspace } from "#src/native/staging.ts";
|
|
16
|
+
import { openForRead } from "#src/knowledge/database.ts";
|
|
17
|
+
import { changedEvidence } from "#src/knowledge/evidence.ts";
|
|
16
18
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
19
|
+
import { LOCAL_DIRECTORY, PROJECT_DIRECTORY, projectRelative, projectRoot } from "#src/project.ts";
|
|
17
20
|
import { OPTIONS, reply, runScript, UsageError, type Call, type CommandSpec, type Reply } from "#src/script.ts";
|
|
18
21
|
import { diffFiles } from "./lib/diff-files.ts";
|
|
19
22
|
import { CANCELLED, play } from "./lib/play.ts";
|
|
@@ -27,9 +30,9 @@ const DEFAULT_HTTP_PORT = 6465;
|
|
|
27
30
|
|
|
28
31
|
/** Behavior that only a person can judge. */
|
|
29
32
|
const ALWAYS = [
|
|
30
|
-
"The controls respond as fast as in the
|
|
33
|
+
"The controls respond as fast as in the reference.",
|
|
31
34
|
"The animation is smooth and has no glitches.",
|
|
32
|
-
"The music and the sound effects sound the same as in the
|
|
35
|
+
"The music and the sound effects sound the same as in the reference.",
|
|
33
36
|
"The game flow and the level changes work from start to end.",
|
|
34
37
|
"Nothing unexpected happens outside the tested scenarios.",
|
|
35
38
|
];
|
|
@@ -78,7 +81,10 @@ async function recordCommand(call: Call): Promise<Reply> {
|
|
|
78
81
|
const context = localToolContext();
|
|
79
82
|
const core = await C64RunSession.open(context);
|
|
80
83
|
const workspace = Workspace.create(context.supervisor, "c64-re-tools-record-");
|
|
84
|
+
let db: ReturnType<typeof openForRead>;
|
|
81
85
|
try {
|
|
86
|
+
// The knowledge is read before the session: a record into the folder of an earlier recording can change files that it gives as evidence.
|
|
87
|
+
db = openForRead();
|
|
82
88
|
const person = playing
|
|
83
89
|
? (session: C64RunSession, restore: () => Promise<string | undefined>) => {
|
|
84
90
|
const ready = (url: string) =>
|
|
@@ -104,11 +110,26 @@ async function recordCommand(call: Call): Promise<Reply> {
|
|
|
104
110
|
writeReported(`${out}/${RECORDING_FILES.reads}`, outcome.reads, { what: "--out" }),
|
|
105
111
|
writeReported(`${out}/${RECORDING_FILES.coverage}`, outcome.coverage, { what: "--out" }),
|
|
106
112
|
];
|
|
113
|
+
// A recording in the local folder is a work file: git ignores it, so it is no test. A record file there is not kept either.
|
|
114
|
+
const local = (path: string) => projectRelative(path).startsWith(`${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/`);
|
|
115
|
+
const keep = local(out)
|
|
116
|
+
? `Git ignores ${out}. To keep the recording as a test and to add its coverage to the project knowledge, record again with --out tests/recordings/<name>.`
|
|
117
|
+
: `Commit ${out} with the scenarios. Add ${out}/${RECORDING_FILES.coverage} to the project knowledge as coverage.`;
|
|
118
|
+
const recordFile = local(call.subject(0)) ? ` Git also ignores the record file ${call.subject(0)}. To record again later, keep a copy in a folder that git keeps, for example tests/record/.` : "";
|
|
119
|
+
const written = new Set(Object.values(RECORDING_FILES).map((name) => projectRelative(`${out}/${name}`)));
|
|
120
|
+
const evidence = changedEvidence(db, projectRoot(), (file) => written.has(file));
|
|
121
|
+
const map = projectRelative(`${out}/${RECORDING_FILES.coverage}`);
|
|
122
|
+
const cited = [
|
|
123
|
+
...(evidence.length === 0 ? [] : [" The project knowledge gives the files in evidence as evidence of earlier revisions, and this record changed them."]),
|
|
124
|
+
...(evidence.some((change) => change.file === map) ? [` Put the new ${RECORDING_FILES.coverage} into the project knowledge as coverage: it replaces the map of the earlier recording.`] : []),
|
|
125
|
+
...(evidence.some((change) => change.file !== map) ? [` For a file other than ${RECORDING_FILES.coverage}, examine the facts of its revisions against the new recording.`] : []),
|
|
126
|
+
].join("");
|
|
107
127
|
return reply(
|
|
108
|
-
{ result: "PASS", recorded: true, out, ...summary, files },
|
|
109
|
-
{ hint:
|
|
128
|
+
{ result: "PASS", recorded: true, out, ...summary, files, ...(evidence.length === 0 ? {} : { evidence }) },
|
|
129
|
+
{ hint: `${keep}${recordFile}${cited} ${summary.coverageFrom === null ? "The coverage did not start: the map is empty." : "The map has no marks for the code that ran before coverageFrom."} To make sure that the recording replays, run nextAction.`, nextAction: call.next("replay", out) },
|
|
110
130
|
);
|
|
111
131
|
} finally {
|
|
132
|
+
db?.close();
|
|
112
133
|
await core.close();
|
|
113
134
|
workspace.remove();
|
|
114
135
|
}
|
|
@@ -119,7 +140,7 @@ function checklist(call: Call): { text: string } {
|
|
|
119
140
|
for (const path of call.subjects) {
|
|
120
141
|
const scenario: Scenario = readScenario(path);
|
|
121
142
|
lines.push(`## ${scenario.name}`, "");
|
|
122
|
-
for (const step of scenario.steps) if ("observe" in step) lines.push(`- [ ] At "${step.observe}", the rebuild looks and behaves as the
|
|
143
|
+
for (const step of scenario.steps) if ("observe" in step) lines.push(`- [ ] At "${step.observe}", the rebuild looks and behaves as the reference.`);
|
|
123
144
|
lines.push("");
|
|
124
145
|
}
|
|
125
146
|
lines.push("## Application", "");
|
|
@@ -133,7 +154,7 @@ const STATE_ITEM = "a name or a $ address, with :size for more than one byte, fo
|
|
|
133
154
|
const COMMANDS: CommandSpec[] = [
|
|
134
155
|
{
|
|
135
156
|
name: "test",
|
|
136
|
-
summary: "Runs a scenario on the
|
|
157
|
+
summary: "Runs a scenario on the reference and then on the rebuild in one emulator. result is PASS, FAIL with the differences, or INCONCLUSIVE with the reason.",
|
|
137
158
|
subjects: [{ name: "<scenario.json>", help: "a scenario file, relative to the project folder. See references/scenario-format.md" }],
|
|
138
159
|
options: {
|
|
139
160
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", help: "with a FAIL, write both screens, the difference image and memory.json into this folder: each differing memory item with all its bytes, and each byte that differs" },
|
|
@@ -156,7 +177,7 @@ const COMMANDS: CommandSpec[] = [
|
|
|
156
177
|
},
|
|
157
178
|
{
|
|
158
179
|
name: "record",
|
|
159
|
-
summary: "Plays the steps of a record file on the
|
|
180
|
+
summary: "Plays the steps of a record file on the reference, and writes the session as a recording folder: recording.json, reads.txt and coverage.bin. result is FAIL when the session did not complete.",
|
|
160
181
|
subjects: [{ name: "<record.json>", help: "a record file, relative to the project folder. See references/recording-format.md" }],
|
|
161
182
|
options: {
|
|
162
183
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", required: true, help: "the recording folder, for example tests/recordings/<name>" },
|
|
@@ -168,25 +189,25 @@ const COMMANDS: CommandSpec[] = [
|
|
|
168
189
|
},
|
|
169
190
|
{
|
|
170
191
|
name: "replay",
|
|
171
|
-
summary: "Replays a recording on the
|
|
192
|
+
summary: "Replays a recording on the reference, which must end with the recorded state, and with --rebuild on the rebuild, which must have the state of the reference at each checkpoint. result is PASS, FAIL or INCONCLUSIVE.",
|
|
172
193
|
subjects: [{ name: "<recording>", help: "a folder that record wrote, relative to the project folder" }],
|
|
173
194
|
options: {
|
|
174
195
|
checkpoint: { kind: "text", value: "<routine>", help: "the name or $ address of a routine: each entry is a checkpoint. Without it, the comparison of the record file" },
|
|
175
196
|
state: { kind: "text", value: "<item>", multiple: true, help: `the state to compare at each checkpoint: ${STATE_ITEM}` },
|
|
176
|
-
pin: { kind: "text", value: "<item>", multiple: true, help: `random state in RAM, in the form of --state: at each checkpoint the rebuild gets the
|
|
177
|
-
rebuild: { kind: "path", value: "<prg>", help: "the rebuild to compare with the
|
|
197
|
+
pin: { kind: "text", value: "<item>", multiple: true, help: `random state in RAM, in the form of --state: at each checkpoint the rebuild gets the reference's values there` },
|
|
198
|
+
rebuild: { kind: "path", value: "<prg>", help: "the rebuild to compare with the reference" },
|
|
178
199
|
symbols: { ...OPTIONS.symbols, help: "the names of the rebuild: the symbol file of its build (default: the symbols of the recording)" },
|
|
179
200
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", help: "with a FAIL, write the RAM of both sides at the first different checkpoint into this folder" },
|
|
180
201
|
},
|
|
181
|
-
notes: "A recording without names takes the names of the knowledge for the
|
|
202
|
+
notes: "A recording without names takes the names of the knowledge for the reference. A $ address is an address of the reference: on the rebuild it moves with the name before it.",
|
|
182
203
|
run: async (call) => {
|
|
183
204
|
const [checkpoint, rebuild, symbols, out] = [call.string("checkpoint"), call.string("rebuild"), call.string("symbols"), call.string("out")];
|
|
184
205
|
const result = await replay({ folder: call.subject(0), state: call.strings("state"), pin: call.strings("pin"), ...(checkpoint === undefined ? {} : { checkpoint }), ...(rebuild === undefined ? {} : { rebuild }), ...(symbols === undefined ? {} : { symbols }), ...(out === undefined ? {} : { out }) });
|
|
185
206
|
if (result.result === "INCONCLUSIVE") return reply(result, { hint: INCONCLUSIVE_HINT });
|
|
186
207
|
if (result.result !== "FAIL") return result;
|
|
187
|
-
const [
|
|
188
|
-
if (
|
|
189
|
-
return reply(result, { hint: "files holds the RAM of each side at the first different checkpoint. Run nextAction to compare them. Then examine the first different state item in the emulator.", nextAction: call.next("diff",
|
|
208
|
+
const [reference, rebuilt] = result.files ?? [];
|
|
209
|
+
if (reference !== undefined && rebuilt !== undefined) {
|
|
210
|
+
return reply(result, { hint: "files holds the RAM of each side at the first different checkpoint. Run nextAction to compare them. Then examine the first different state item in the emulator.", nextAction: call.next("diff", reference.out, rebuilt.out) });
|
|
190
211
|
}
|
|
191
212
|
if (result.firstDifference === undefined) return reply(result, { hint: "reason tells how many checkpoints the rebuild came to. Examine the rebuild in the emulator after its last checkpoint." });
|
|
192
213
|
return reply(result, { hint: `A difference in a random value with the same input often shows a missing --pin.${out === undefined ? " Give --out to get the RAM of each side at the first different checkpoint." : ""}` });
|
|
@@ -222,7 +243,7 @@ const COMMANDS: CommandSpec[] = [
|
|
|
222
243
|
|
|
223
244
|
await runScript({
|
|
224
245
|
name: "testing",
|
|
225
|
-
summary: "Tests a rebuild against the
|
|
246
|
+
summary: "Tests a rebuild against the reference: scenarios in an emulator, runs, recorded play sessions, state differences, and a checklist for a human tester.",
|
|
226
247
|
names: knowledgeNames,
|
|
227
248
|
commands: COMMANDS,
|
|
228
249
|
});
|
|
@@ -13,7 +13,7 @@ node <skill>/scripts/unpacker.ts <command>
|
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
`<skill>` is the base directory of this skill. Run the script with `node`. You can run it from any directory.
|
|
16
|
-
Each command in this skill, for example `inspect
|
|
16
|
+
Each command in this skill, for example `inspect releases/game.prg`, goes in the place of `<command>`.
|
|
17
17
|
Each command prints one JSON envelope on stdout. See the section "JSON output".
|
|
18
18
|
To get the command list, run the script with no arguments.
|
|
19
19
|
|
|
@@ -23,16 +23,16 @@ To get the command list, run the script with no arguments.
|
|
|
23
23
|
|
|
24
24
|
| Goal | Command |
|
|
25
25
|
|---|---|
|
|
26
|
-
| Find evidence of packing in the file, without a run | `inspect
|
|
27
|
-
| Find the code that the program wrote and then executed | `trace
|
|
28
|
-
| Run a program that is not a BASIC program at `$0801` | `trace
|
|
29
|
-
| Give input to an intro or a menu before the evidence starts | `trace
|
|
30
|
-
| Find each stage and the entry of the unpacked program | `stages
|
|
31
|
-
| Capture the unpacked program at its entry | `capture
|
|
32
|
-
| Capture again without the bytes of a cracktro | `capture
|
|
33
|
-
| Capture only one known range of the program | `capture
|
|
34
|
-
| Capture each part of a multi-load program | `loads
|
|
35
|
-
| Capture each part and the RAM of the disk drive | `loads
|
|
26
|
+
| Find evidence of packing in the file, without a run | `inspect releases/game.prg` |
|
|
27
|
+
| Find the code that the program wrote and then executed | `trace releases/game.prg` |
|
|
28
|
+
| Run a program that is not a BASIC program at `$0801` | `trace releases/game.prg --entry '$c000'` |
|
|
29
|
+
| Give input to an intro or a menu before the evidence starts | `trace releases/game.prg --steps .c64-re-tools/local/input.json` |
|
|
30
|
+
| Find each stage and the entry of the unpacked program | `stages releases/game.prg` |
|
|
31
|
+
| Capture the unpacked program at its entry | `capture releases/game.prg --until '$c000' --out .c64-re-tools/local/capture` |
|
|
32
|
+
| Capture again without the bytes of a cracktro | `capture releases/game.prg --until '$c000' --out .c64-re-tools/local/capture --exclude '$a000-$a9ff'` |
|
|
33
|
+
| Capture only one known range of the program | `capture releases/game.prg --until '$c000' --out .c64-re-tools/local/capture --range '$c000-$cfff'` |
|
|
34
|
+
| Capture each part of a multi-load program | `loads releases/game.d64 --steps .c64-re-tools/local/parts.json --out .c64-re-tools/local/parts` |
|
|
35
|
+
| Capture each part and the RAM of the disk drive | `loads releases/game.d64 --steps .c64-re-tools/local/parts.json --out .c64-re-tools/local/parts --drive` |
|
|
36
36
|
|
|
37
37
|
---
|
|
38
38
|
|
|
@@ -75,7 +75,7 @@ The script refuses a step in an old form. The message gives the step to write.
|
|
|
75
75
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
76
76
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
77
77
|
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
78
|
-
- A path that a command only reads can go into another project of the group, for example `../v1/
|
|
78
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/releases/game.prg`. The command writes only in its own project.
|
|
79
79
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
80
80
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
81
81
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -195,7 +195,7 @@ Traps:
|
|
|
195
195
|
|
|
196
196
|
- `captured`: true when the CPU got to `--until`. `pc` is that address.
|
|
197
197
|
- `files`: each file that the command wrote, as `{out, bytes, sha256}`. `removed` names the segment files of an earlier capture that the new `image.json` does not list.
|
|
198
|
-
- `segments` and `excluded`: the ranges of the segment files, and the ranges that `--exclude` removed.
|
|
198
|
+
- `segments` and `excluded`: the ranges of the segment files, and the ranges that `--exclude` removed. `loaded: true` marks a segment with the bytes that the program loaded.
|
|
199
199
|
- `stages`: the count of stages.
|
|
200
200
|
- `differsFromReset`: the count of bytes that are not as a clean C64 has them at READY.
|
|
201
201
|
|
|
@@ -214,6 +214,8 @@ A segment is a block that a stage wrote, also a small block. These blocks are no
|
|
|
214
214
|
|
|
215
215
|
The block with the capture entry is always a segment. Segments do not overlap.
|
|
216
216
|
|
|
217
|
+
If no stage wrote the capture entry, the program runs as it loaded. Then the range of the PRG is a segment with `loaded: true`. The blocks that touch this range are in the same segment. An example is a memory dump that starts with `SYS`.
|
|
218
|
+
|
|
217
219
|
A capture into a folder with an earlier capture removes only the segment files that the new `image.json` does not list. It keeps all other files.
|
|
218
220
|
|
|
219
221
|
On `PASS`, `hint` tells you to disassemble the code at `pc`, and then to put `<out>/image.json` into the project knowledge.
|
|
@@ -221,7 +223,7 @@ On `PASS`, `hint` tells you to disassemble the code at `pc`, and then to put `<o
|
|
|
221
223
|
Traps:
|
|
222
224
|
|
|
223
225
|
- The capture stops at the first arrival at `--until` after the steps. To capture a later arrival, add a `runUntil` step to an address after the first arrival.
|
|
224
|
-
- `captured: false`: the program did not get to `--until` in `--timeout-frames`. The reason tells where it stopped. Find a better address, or give more frames. If it stopped in a key wait, give `--steps` with a `type` step.
|
|
226
|
+
- `captured: false`: the program did not get to `--until` in `--timeout-frames`. The reason tells where it stopped. Find a better address, or give more frames. If it stopped in a key wait, give `--steps` with a `type` step. If the CPU got to `--until` in a step, the reason names that step.
|
|
225
227
|
|
|
226
228
|
### `loads <program>`
|
|
227
229
|
|
|
@@ -107,9 +107,16 @@ export const FIRST_SEGMENT_ADDRESS = 0x0400;
|
|
|
107
107
|
* a segment. A block that an intermediate stage wrote inside a leftover, for
|
|
108
108
|
* example a variable of the loader, is a leftover too. The filter comes before
|
|
109
109
|
* the join: a join first would drop the program with a leftover. `writtenBy` is
|
|
110
|
-
* the last stage that wrote into the range.
|
|
110
|
+
* the last stage that wrote into the range. When no written block holds the
|
|
111
|
+
* entry, the code there is as the program loaded it: `loaded`, the range of
|
|
112
|
+
* the PRG, is then a segment too (`loaded: true`), joined with the blocks that
|
|
113
|
+
* it overlaps or touches.
|
|
111
114
|
*/
|
|
112
|
-
export function captureSegments(
|
|
115
|
+
export function captureSegments(
|
|
116
|
+
stages: ReadonlyArray<{ entry: number; wrote: readonly AddressRange[] }>,
|
|
117
|
+
entry: number,
|
|
118
|
+
loaded?: AddressRange,
|
|
119
|
+
): Array<AddressRange & ({ writtenBy: number } | { loaded: true })> {
|
|
113
120
|
const last = stages.length - 1;
|
|
114
121
|
const replaced = (from: number, address: number) => stages.slice(from).some((stage) => inRanges(stage.wrote, address));
|
|
115
122
|
const leftover = (block: AddressRange, writer: number) =>
|
|
@@ -129,7 +136,15 @@ export function captureSegments(stages: ReadonlyArray<{ entry: number; wrote: re
|
|
|
129
136
|
previous.writtenBy = Math.max(previous.writtenBy, block.writtenBy);
|
|
130
137
|
} else segments.push({ ...block });
|
|
131
138
|
}
|
|
132
|
-
return segments;
|
|
139
|
+
if (loaded === undefined || !contains(loaded, entry) || segments.some((segment) => contains(segment, entry))) return segments;
|
|
140
|
+
const joined = { start: loaded.start, end: loaded.end, loaded: true as const };
|
|
141
|
+
const apart = segments.filter((segment) => {
|
|
142
|
+
if (segment.end + 1 < joined.start || segment.start > joined.end + 1) return true;
|
|
143
|
+
joined.start = Math.min(joined.start, segment.start);
|
|
144
|
+
joined.end = Math.max(joined.end, segment.end);
|
|
145
|
+
return false;
|
|
146
|
+
});
|
|
147
|
+
return [...apart, joined].sort((a, b) => a.start - b.start);
|
|
133
148
|
}
|
|
134
149
|
|
|
135
150
|
/** The segments without the bytes of `holes`: a segment that a hole cuts gives its parts, each with the fields of the segment. */
|
|
@@ -15,6 +15,7 @@ import { readPrg } from "#src/host-client/image.ts";
|
|
|
15
15
|
import { writeReported, type Written } from "#src/host-client/transfer.ts";
|
|
16
16
|
import { ViceSessionClient } from "#src/host-client/vice-session.ts";
|
|
17
17
|
import { knowledgeAt, knowledgeNames } from "#src/knowledge/names.ts";
|
|
18
|
+
import { PAL_FRAME_CYCLES } from "#src/native/c64run.ts";
|
|
18
19
|
import { listed, OPTIONS, reply, runScript, UsageError, type Call, type CommandSpec, type OptionSpec } from "#src/script.ts";
|
|
19
20
|
import { basicStart, inspect, readMemoryMap, underRom, writtenThenExecuted } from "./lib/evidence.ts";
|
|
20
21
|
import { loads, readLoadSteps } from "./lib/loads.ts";
|
|
@@ -197,6 +198,8 @@ interface Followed {
|
|
|
197
198
|
failed?: string;
|
|
198
199
|
/** What stopped the CPU before the frames ran: a JAM or a point of the program. */
|
|
199
200
|
halted?: { stopReason: string; pc: number };
|
|
201
|
+
/** The first step (1 = the first) in which the CPU executed `until`, before the run waited for it. */
|
|
202
|
+
untilRan?: number;
|
|
200
203
|
}
|
|
201
204
|
|
|
202
205
|
type RunUntilStep = Extract<ActionStep, { runUntil: unknown }>;
|
|
@@ -250,9 +253,16 @@ async function follow(
|
|
|
250
253
|
const atTarget = (pc: number) => stopAt !== undefined && pc === stopAt;
|
|
251
254
|
// The current stage: its memory map since it started, chunk by chunk, its own code, and the written code it calls.
|
|
252
255
|
let stage = { map: new Uint8Array(0x10000), own: new Set<number>(), called: [] as AddressRange[] };
|
|
256
|
+
// A step that runs frames can pass until: the run then waits for it in vain.
|
|
257
|
+
let running = 0;
|
|
258
|
+
let untilRan: number | undefined;
|
|
259
|
+
const noteUntil = (map: Uint8Array) => {
|
|
260
|
+
if (options.until !== undefined && running > 0 && untilRan === undefined && (map[options.until]! & EXECUTE) !== 0) untilRan = running;
|
|
261
|
+
};
|
|
253
262
|
const startStage = async (next: number, last: Uint8Array) => {
|
|
254
263
|
mergeMaps(stage.map, last);
|
|
255
264
|
await markIoRam(stage.map);
|
|
265
|
+
noteUntil(stage.map);
|
|
256
266
|
found.push({ entry, firstFrame, frames: total - firstFrame, wrote: stageWrote(stage.map), next });
|
|
257
267
|
entry = next;
|
|
258
268
|
firstFrame = total;
|
|
@@ -426,8 +436,11 @@ async function follow(
|
|
|
426
436
|
stopAt = undefined;
|
|
427
437
|
}
|
|
428
438
|
};
|
|
439
|
+
// Stage 0 starts at the program, whatever the first step is: RUN and the BASIC line before it are no part of it.
|
|
440
|
+
await client.memmap({ action: "clear" });
|
|
429
441
|
// The steps run first and in the tracked time: a frames step and a runUntil step to an address. The others act between two chunks.
|
|
430
442
|
for (const [index, step] of options.steps.entries()) {
|
|
443
|
+
running = index + 1;
|
|
431
444
|
if ("frames" in step) await track(step.frames);
|
|
432
445
|
else if (trackedRunUntil(step)) {
|
|
433
446
|
if (!(await trackTo(knowledgeAt()(step.runUntil.target.address), step.runUntil.timeoutFrames))) {
|
|
@@ -435,8 +448,21 @@ async function follow(
|
|
|
435
448
|
const why = halted === undefined ? "" : ` ${stoppedEarly(halted.stopReason, halted.pc, total, step.runUntil.timeoutFrames)}`;
|
|
436
449
|
return { stages: found, frames: total, reached: false, failed: `Step ${index + 1} did not reach its target in ${step.runUntil.timeoutFrames} frames. It is at ${formatC64Address(pc)}.${why}` };
|
|
437
450
|
}
|
|
438
|
-
} else
|
|
451
|
+
} else {
|
|
452
|
+
// A press or a runUntil to memory or the raster runs frames outside the chunks. The stopwatch of the session gives them,
|
|
453
|
+
// also for a run that a point stops early. What the step wrote and ran is in the stage before the next chunk clears the memory map.
|
|
454
|
+
await client.timing("start");
|
|
455
|
+
const notReached = await runActionStep(client, step, knowledgeAt());
|
|
456
|
+
const timed = await client.timing("read");
|
|
457
|
+
total += Math.round(Number("cycles" in timed ? timed.cycles : 0) / PAL_FRAME_CYCLES);
|
|
458
|
+
mergeMaps(stage.map, await readCoverage(client));
|
|
459
|
+
if (notReached !== undefined && "runUntil" in step) {
|
|
460
|
+
return { stages: found, frames: total, reached: false, failed: `Step ${index + 1} did not reach its target in ${step.runUntil.timeoutFrames} frames. It stopped by ${notReached.stopReason} at ${formatC64Address(notReached.pc)}.` };
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
noteUntil(stage.map);
|
|
439
464
|
}
|
|
465
|
+
running = 0;
|
|
440
466
|
const left = Math.max(0, options.frames - total);
|
|
441
467
|
let reached = false;
|
|
442
468
|
if (options.until === undefined) await track(left);
|
|
@@ -445,7 +471,7 @@ async function follow(
|
|
|
445
471
|
mergeMaps(stage.map, await readCoverage(client));
|
|
446
472
|
await markIoRam(stage.map);
|
|
447
473
|
found.push({ entry, firstFrame, frames: total - firstFrame, wrote: stageWrote(stage.map) });
|
|
448
|
-
return { stages: found, frames: total, reached, ...(halted === undefined ? {} : { halted }) };
|
|
474
|
+
return { stages: found, frames: total, reached, ...(halted === undefined ? {} : { halted }), ...(untilRan === undefined ? {} : { untilRan }) };
|
|
449
475
|
}
|
|
450
476
|
|
|
451
477
|
const showRange = (range: { start: number; end: number }) => ({ start: formatC64Address(range.start), end: formatC64Address(range.end) });
|
|
@@ -490,6 +516,11 @@ async function stages(program: string, options: { frames: number; entry?: number
|
|
|
490
516
|
}
|
|
491
517
|
}
|
|
492
518
|
|
|
519
|
+
/** Why a capture can wait for --until in vain: a step ran over it. */
|
|
520
|
+
function passedInStep(until: number, step: number): string {
|
|
521
|
+
return `The CPU executed ${formatC64Address(until)} in step ${step}, before the wait for --until started. A press step runs frames. Make the steps stop before the program gets to that address, or give an --until address that the program gets to later.`;
|
|
522
|
+
}
|
|
523
|
+
|
|
493
524
|
async function capture(
|
|
494
525
|
program: string,
|
|
495
526
|
options: { until: number; out: string; range?: AddressRange; exclude: AddressRange[]; timeoutFrames: number; entry?: number; steps: ActionStep[]; minStage: number },
|
|
@@ -504,7 +535,7 @@ async function capture(
|
|
|
504
535
|
return {
|
|
505
536
|
output: {
|
|
506
537
|
captured: false,
|
|
507
|
-
reason: `The program did not get to ${formatC64Address(options.until)} in ${options.timeoutFrames} frames. It is at ${formatC64Address(registers.pc)}.${followed.halted === undefined ? "" : ` ${stoppedEarly(followed.halted.stopReason, followed.halted.pc, followed.frames, options.timeoutFrames)}`}`,
|
|
538
|
+
reason: `The program did not get to ${formatC64Address(options.until)} in ${options.timeoutFrames} frames. It is at ${formatC64Address(registers.pc)}.${followed.halted === undefined ? "" : ` ${stoppedEarly(followed.halted.stopReason, followed.halted.pc, followed.frames, options.timeoutFrames)}`}${followed.untilRan === undefined ? "" : ` ${passedInStep(options.until, followed.untilRan)}`}`,
|
|
508
539
|
...(followed.halted === undefined ? {} : { stopReason: followed.halted.stopReason }),
|
|
509
540
|
stages: showStages(followed.stages),
|
|
510
541
|
},
|
|
@@ -515,7 +546,8 @@ async function capture(
|
|
|
515
546
|
const memory = await readRam(client, 0x0000, 0x10000);
|
|
516
547
|
const state = await machineState(client);
|
|
517
548
|
// The segments: what the stages wrote, without loader leftovers, with no overlap.
|
|
518
|
-
const
|
|
549
|
+
const load = bytes[0]! | (bytes[1]! << 8);
|
|
550
|
+
const found = options.range !== undefined ? [options.range] : captureSegments(followed.stages, registers.pc, { start: load, end: Math.min(0xffff, load + bytes.length - 3) });
|
|
519
551
|
const segments = withoutRanges(found, options.exclude);
|
|
520
552
|
const file = (path: string) => `${options.out}/${path}`;
|
|
521
553
|
const written: Written[] = [];
|
|
@@ -533,7 +565,7 @@ async function capture(
|
|
|
533
565
|
`${JSON.stringify(
|
|
534
566
|
{
|
|
535
567
|
entry: formatC64Address(registers.pc),
|
|
536
|
-
segments: segments.map((segment, index) => ({ ...showRange(segment), ...("writtenBy" in segment ? { writtenBy: segment.writtenBy } : {}), file: files[index] })),
|
|
568
|
+
segments: segments.map((segment, index) => ({ ...showRange(segment), ...("writtenBy" in segment ? { writtenBy: segment.writtenBy } : {}), ...("loaded" in segment ? { loaded: true } : {}), file: files[index] })),
|
|
537
569
|
...(options.exclude.length === 0 ? {} : { excluded: options.exclude.map(showRange) }),
|
|
538
570
|
vectors,
|
|
539
571
|
stages: showStages(followed.stages),
|
|
@@ -556,7 +588,7 @@ async function capture(
|
|
|
556
588
|
out: options.out,
|
|
557
589
|
files: written,
|
|
558
590
|
...(removed.length === 0 ? {} : { removed }),
|
|
559
|
-
segments: segments.map(showRange),
|
|
591
|
+
segments: segments.map((segment) => ({ ...showRange(segment), ...("loaded" in segment ? { loaded: true } : {}) })),
|
|
560
592
|
...(options.exclude.length === 0 ? {} : { excluded: options.exclude.map(showRange) }),
|
|
561
593
|
stages: followed.stages.length,
|
|
562
594
|
differsFromReset: entry.differsFromReset,
|
package/src/build-name.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// A release build is release_<label>. A build of config.asm is clean when each
|
|
3
3
|
// switch has its default, else custom_ with each switch that differs: its
|
|
4
4
|
// name when it is on, no_<name> when it is off. A build of an entry other
|
|
5
|
-
// than main.asm adds the entry, for example clean_loader.
|
|
5
|
+
// than main.asm adds the entry, for example clean_loader. The loader of the
|
|
6
|
+
// packed form alone is only its copier, so its build is clean_copier: the loader
|
|
7
|
+
// program, which generate packs, keeps clean_loader. A source without
|
|
6
8
|
// config.asm and without a release keeps the name of its entry. The symbols
|
|
7
9
|
// of a build go into symbols/ next to the program, so the program folder
|
|
8
10
|
// holds only programs.
|
|
@@ -31,9 +33,12 @@ export function configValues(text: string): Map<string, 0 | 1> {
|
|
|
31
33
|
/** What a build is made of: a release, or the values of config.asm with the default of each switch (0 when the defaults do not have it). */
|
|
32
34
|
export type BuildKind = { release: string } | { values: ReadonlyMap<string, number>; defaults: ReadonlyMap<string, number> };
|
|
33
35
|
|
|
34
|
-
/** The
|
|
35
|
-
export
|
|
36
|
-
|
|
36
|
+
/** The line of a generated loader.asm of the packed form. Its build alone is only the copier, not the loader program. */
|
|
37
|
+
export const COPIER_LINE = "; A build of this file alone is only the copier: its build name has copier in place of loader.";
|
|
38
|
+
|
|
39
|
+
/** The name of a build of `entry`, without an extension. `source` is the text of the entry: COPIER_LINE in it gives the name copier. */
|
|
40
|
+
export function buildName(entry: string, kind: BuildKind | undefined, source?: string): string {
|
|
41
|
+
const base = source?.split(/\r?\n/).includes(COPIER_LINE) ? "copier" : basename(entry, extname(entry));
|
|
37
42
|
if (kind === undefined) return base;
|
|
38
43
|
let type: string;
|
|
39
44
|
if ("release" in kind) type = `release_${kind.release}`;
|
package/src/c64.ts
CHANGED
|
@@ -511,7 +511,7 @@ const BRANCHES = new Set([0x10, 0x30, 0x50, 0x70, 0x90, 0xb0, 0xd0, 0xf0]);
|
|
|
511
511
|
const NO_FALL = new Set([0x00, 0x40, 0x4c, 0x60, 0x6c]);
|
|
512
512
|
|
|
513
513
|
/**
|
|
514
|
-
* The coverage flow starts split for
|
|
514
|
+
* The coverage flow starts split for the decompiler. A start is a code start, a
|
|
515
515
|
* place in a routine, when it follows an executed JSR, or when an executed
|
|
516
516
|
* branch or JMP from outside its own flow reaches it (the loop of a routine
|
|
517
517
|
* that jumps back to its own start does not count). Any other start, for
|
package/src/host/main.ts
CHANGED
|
@@ -121,8 +121,8 @@ async function main(): Promise<number> {
|
|
|
121
121
|
log,
|
|
122
122
|
flaws,
|
|
123
123
|
// c1541 lists the disk, so an autostart index selects a program.
|
|
124
|
-
directory: async (imageType, image) => {
|
|
125
|
-
const { result } = await inspect({ action: "directory", imageType }, image, { supervisor, signal
|
|
124
|
+
directory: async (imageType, image, signal) => {
|
|
125
|
+
const { result } = await inspect({ action: "directory", imageType }, image, { supervisor, signal, log });
|
|
126
126
|
return result.action === "directory" ? result.entries : [];
|
|
127
127
|
},
|
|
128
128
|
}),
|