@henols/c64-re-tools 2.6.0 → 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 +4 -4
- package/skills/c64-basic/SKILL.md +1 -1
- package/skills/c64-development/SKILL.md +5 -5
- package/skills/c64-disk/SKILL.md +13 -13
- package/skills/c64-docs/SKILL.md +22 -9
- 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 +64 -17
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-knowledge/SKILL.md +7 -7
- package/skills/c64-knowledge/scripts/knowledge.ts +1 -1
- 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 +20 -11
- package/skills/c64-source/SKILL.md +8 -8
- package/skills/c64-source/scripts/lib/export.ts +7 -6
- package/skills/c64-source/scripts/lib/source.ts +3 -3
- package/skills/c64-source/scripts/source.ts +17 -17
- package/skills/c64-static-analysis/SKILL.md +1 -1
- package/skills/c64-testing/SKILL.md +25 -24
- package/skills/c64-testing/references/recording-format.md +7 -7
- package/skills/c64-testing/references/scenario-format.md +5 -5
- package/skills/c64-testing/scripts/lib/recording.ts +38 -38
- package/skills/c64-testing/scripts/lib/replay.ts +26 -26
- package/skills/c64-testing/scripts/lib/scenario.ts +28 -28
- package/skills/c64-testing/scripts/testing.ts +14 -14
- package/skills/c64-unpacker/SKILL.md +12 -12
- package/src/knowledge/separate.ts +2 -2
- package/src/knowledge/write.ts +1 -1
- package/src/project.ts +1 -1
- package/src/script.ts +1 -1
- package/tools/c64run.c +1 -1
|
@@ -9,7 +9,7 @@ A record file is one JSON object in a project file.
|
|
|
9
9
|
```json
|
|
10
10
|
{
|
|
11
11
|
"name": "first rooms",
|
|
12
|
-
"program": "
|
|
12
|
+
"program": "releases/game.prg",
|
|
13
13
|
"steps": [
|
|
14
14
|
{ "frames": 300 },
|
|
15
15
|
{ "joystick": { "port": 2, "direction": "center", "fire": true } },
|
|
@@ -131,21 +131,21 @@ A site is the address of the instruction that reads. The values are hex. `<from>
|
|
|
131
131
|
|
|
132
132
|
## Replay
|
|
133
133
|
|
|
134
|
-
`replay` replays the recording on the
|
|
134
|
+
`replay` replays the recording on the reference program first. The session must end with the recorded cycles and state hash. Else the result is INCONCLUSIVE. With `--rebuild`, `replay` then replays the recording on the rebuild. At each checkpoint, the rebuild first gets the pinned values of the reference. Then the script compares the state. The cycles can be different.
|
|
135
135
|
|
|
136
136
|
A recording without names (`symbols` is `none`) takes the names of the project knowledge at the time of the replay.
|
|
137
137
|
|
|
138
|
-
For the rebuild, the script finds each name with the names of the rebuild (`--symbols`). A `$` address is an address of the
|
|
138
|
+
For the rebuild, the script finds each name with the names of the rebuild (`--symbols`). A `$` address is an address of the reference. It moves with the name before it in the reference: the script finds the same name in the rebuild and adds the same offset. Code moves with a code label, and data with any name. A site in ROM does not move. Give a state item a name, or the state moves with the code before it.
|
|
139
139
|
|
|
140
140
|
The body of the envelope of `replay` has these fields:
|
|
141
141
|
|
|
142
142
|
- `result`: PASS, FAIL or INCONCLUSIVE.
|
|
143
|
-
- `side`: `
|
|
143
|
+
- `side`: `reference` for the check of the reference only, `rebuild` with `--rebuild`.
|
|
144
144
|
- `checkpoint`: the routine of the comparison.
|
|
145
|
-
- `checkpoints` and `compared`: the checkpoints of the
|
|
146
|
-
- `firstDifference`: on a FAIL, the checkpoint (1 is the first), the cycle on each side, and each state item that is different. An item has `address`, and the `
|
|
145
|
+
- `checkpoints` and `compared`: the checkpoints of the reference, and the checkpoints of the rebuild that were the same.
|
|
146
|
+
- `firstDifference`: on a FAIL, the checkpoint (1 is the first), the cycle on each side, and each state item that is different. An item has `address`, and the `reference` and `rebuild` values as hex.
|
|
147
147
|
- `reason`: why the result is FAIL or INCONCLUSIVE.
|
|
148
148
|
- `movedSites`: the number of sites at a different address in the rebuild.
|
|
149
149
|
- `startScreen`: `skipped` when the rebuild went past the wait of its start screen.
|
|
150
150
|
- `idleReads`: the input reads of the rebuild that the recording had no value for. Such a read is at a site that the recording does not have, or after its end. Each got the fixed value `$FF` (joystick, keyboard, paddles) or `$00`. An input site that the site map did not find shows here.
|
|
151
|
-
- `files`: with `--out`, the RAM of each side at the first different checkpoint, `
|
|
151
|
+
- `files`: with `--out`, the RAM of each side at the first different checkpoint, `reference-<n>.bin` and `rebuild-<n>.bin`.
|
|
@@ -7,7 +7,7 @@ A scenario is one JSON object in a project file.
|
|
|
7
7
|
```json
|
|
8
8
|
{
|
|
9
9
|
"name": "player moves left",
|
|
10
|
-
"
|
|
10
|
+
"reference": { "program": "releases/game.prg", "symbols": "knowledge" },
|
|
11
11
|
"rebuild": { "program": "build/clean.prg", "symbols": "build/symbols/clean.json" },
|
|
12
12
|
"steps": [
|
|
13
13
|
{ "frames": 150 },
|
|
@@ -23,7 +23,7 @@ A scenario is one JSON object in a project file.
|
|
|
23
23
|
|
|
24
24
|
## Subjects
|
|
25
25
|
|
|
26
|
-
`
|
|
26
|
+
`reference` and `rebuild` each have:
|
|
27
27
|
|
|
28
28
|
- `program`: a PRG file, relative to the project folder.
|
|
29
29
|
- `symbols`: where the names come from:
|
|
@@ -65,7 +65,7 @@ A `condition` has the `kind` `register`, `memory` or `raster`. A `register` cond
|
|
|
65
65
|
|
|
66
66
|
`timeoutFrames` is from 1 to 30000, and 3000 by default. A `runUntil` that does not get to its target in `timeoutFrames` frames makes the result INCONCLUSIVE.
|
|
67
67
|
|
|
68
|
-
Each step except `observe` can have `"side": "
|
|
68
|
+
Each step except `observe` can have `"side": "reference"` or `"side": "rebuild"`. Then only that side does the step. Use it when only one side needs a step, for example a key for the intro of the reference. An `observe` step has no `side`, because it compares both sides.
|
|
69
69
|
|
|
70
70
|
Each side finds a name in its own symbols.
|
|
71
71
|
|
|
@@ -77,7 +77,7 @@ An `observe` step has a checkpoint name. A scenario can have each name only one
|
|
|
77
77
|
|---|---|
|
|
78
78
|
| `memory` | A list of names, `$` addresses, or objects. An object has `address`, `size` (1 to 65536, default 1), `view` (`cpu` or `ram`, default `cpu`), `tolerance` (0 to 255, default 0), `mask` and `exclude`. The view `ram` reads the RAM under the ROMs and the I/O area. |
|
|
79
79
|
| `registers` | A list of register names: `pc`, `a`, `x`, `y`, `sp`, `flags`. |
|
|
80
|
-
| `screen` | The screen of the rebuild against the screen of the
|
|
80
|
+
| `screen` | The screen of the rebuild against the screen of the reference. `maxMismatchRatio` (default 0) is the largest permitted part of different pixels. `mask` is a list of rectangles (`x`, `y`, `width`, `height`) that the comparison does not include. |
|
|
81
81
|
| `vicii` | The VIC-II state: mode, screen address, scroll and colors. |
|
|
82
82
|
| `sprites` | A list of sprite numbers from 0 to 7. The script compares their position, color and flags. |
|
|
83
83
|
|
|
@@ -122,7 +122,7 @@ A name in `save`, `screen`, `coverage`, `observe` and `expect` has 1 to 64 lette
|
|
|
122
122
|
|
|
123
123
|
### Expected values
|
|
124
124
|
|
|
125
|
-
An `expect` step compares the memory and the registers with the values that the step gives. It writes no file. Use it to test a program that has no
|
|
125
|
+
An `expect` step compares the memory and the registers with the values that the step gives. It writes no file. Use it to test a program that has no reference, for example a new program or a fix.
|
|
126
126
|
|
|
127
127
|
```json
|
|
128
128
|
{ "expect": "title",
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// values that its input reads got (the joystick ports, the keyboard matrix,
|
|
3
3
|
// the SID noise) and the state hash at its end. A replay gives the same values
|
|
4
4
|
// to the same reads, keyed by the site (the reading instruction) and the read
|
|
5
|
-
// index. On the
|
|
5
|
+
// index. On the reference it must end with the same hash. On a rebuild it
|
|
6
6
|
// compares the state at each entry of one routine (the checkpoints) with the
|
|
7
|
-
//
|
|
7
|
+
// reference's. Timing does not key anything, so a rebuild with other timing
|
|
8
8
|
// replays the same session. A recording needs no names: the checkpoint and the
|
|
9
9
|
// state can be chosen at replay time, with the names that the knowledge has then.
|
|
10
10
|
|
|
@@ -82,7 +82,7 @@ const COVERAGE_COMMANDS = new Map([
|
|
|
82
82
|
/**
|
|
83
83
|
* What a replay compares: the state at each entry of a routine, for example the
|
|
84
84
|
* main loop of a game. `pin` is random state in RAM (a seed, a pointer into a
|
|
85
|
-
* random table): at each checkpoint the rebuild gets the
|
|
85
|
+
* random table): at each checkpoint the rebuild gets the reference's values there.
|
|
86
86
|
*/
|
|
87
87
|
export interface Comparison {
|
|
88
88
|
checkpoint: Location;
|
|
@@ -308,7 +308,7 @@ export function readRecording(folder: string): Recording {
|
|
|
308
308
|
|
|
309
309
|
/**
|
|
310
310
|
* The addresses of one side. A name comes from the symbols of the side. A $
|
|
311
|
-
* address is an address of the
|
|
311
|
+
* address is an address of the reference: on the rebuild it moves with the
|
|
312
312
|
* name before it (code with a code label, data with any symbol).
|
|
313
313
|
*/
|
|
314
314
|
export interface SideAddresses {
|
|
@@ -330,8 +330,8 @@ function sideAddresses(symbols: Map<string, number>, side: string, move: { code:
|
|
|
330
330
|
const MAX_LABEL_DISTANCE = 4096;
|
|
331
331
|
|
|
332
332
|
/**
|
|
333
|
-
* Moves an address of the
|
|
334
|
-
*
|
|
333
|
+
* Moves an address of the reference to the rebuild: the name before it in the
|
|
334
|
+
* reference, plus the same offset from that name in the rebuild. An address
|
|
335
335
|
* without a name before it (within MAX_LABEL_DISTANCE) stays where it is.
|
|
336
336
|
*/
|
|
337
337
|
export function mover(from: Map<string, number>, to: Map<string, number>): (address: number) => number {
|
|
@@ -358,7 +358,7 @@ export function siteMap(sites: RecordedSite[], from: Map<string, number>, to: Ma
|
|
|
358
358
|
return moved;
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
-
/** Where the
|
|
361
|
+
/** Where the reference came to the entry that the loader of a rebuild jumps to. */
|
|
362
362
|
export interface EntryPoint {
|
|
363
363
|
/** The tick of the first opcode fetch at the entry. */
|
|
364
364
|
tick: number;
|
|
@@ -371,7 +371,7 @@ export interface EntryPoint {
|
|
|
371
371
|
counts: Map<string, number>;
|
|
372
372
|
/** The number of events of the recording before the entry: always the first ones. */
|
|
373
373
|
eventsBefore: number;
|
|
374
|
-
/** The number of checkpoints before the entry, which the samples of the
|
|
374
|
+
/** The number of checkpoints before the entry, which the samples of the reference leave out. */
|
|
375
375
|
samplesBefore: number;
|
|
376
376
|
}
|
|
377
377
|
|
|
@@ -538,7 +538,7 @@ export async function record(
|
|
|
538
538
|
): Promise<RecordOutcome> {
|
|
539
539
|
const prg = readProjectFile(file.program).bytes;
|
|
540
540
|
const same = (address: number) => address;
|
|
541
|
-
const at = sideAddresses(namesOf(file.symbols), "
|
|
541
|
+
const at = sideAddresses(namesOf(file.symbols), "reference", { code: same, data: same });
|
|
542
542
|
// A checkpoint and state of the record file must resolve now, so that a replay can use them.
|
|
543
543
|
if (file.compare !== undefined) {
|
|
544
544
|
at.code(file.compare.checkpoint);
|
|
@@ -662,7 +662,7 @@ export async function record(
|
|
|
662
662
|
|
|
663
663
|
/** One side of a replay. */
|
|
664
664
|
export interface ReplaySubject {
|
|
665
|
-
side: "
|
|
665
|
+
side: "reference" | "rebuild";
|
|
666
666
|
program: string;
|
|
667
667
|
symbols: string;
|
|
668
668
|
}
|
|
@@ -676,7 +676,7 @@ export interface SideRun {
|
|
|
676
676
|
problem?: string;
|
|
677
677
|
/** True when the rebuild went on after the wait of its start screen. */
|
|
678
678
|
startScreenSkipped?: boolean;
|
|
679
|
-
/** The
|
|
679
|
+
/** The reference with an `entry`: where it came to that entry, when it came to it. */
|
|
680
680
|
entryPoint?: EntryPoint;
|
|
681
681
|
/**
|
|
682
682
|
* Input reads that the recording has no value for, which got the fixed idle value:
|
|
@@ -687,7 +687,7 @@ export interface SideRun {
|
|
|
687
687
|
}
|
|
688
688
|
|
|
689
689
|
/**
|
|
690
|
-
* Replays a recording on one side. The
|
|
690
|
+
* Replays a recording on one side. The reference runs to the end of the
|
|
691
691
|
* session; a rebuild runs until `stop` checkpoints (or REBUILD_TIME_FACTOR
|
|
692
692
|
* times the cycles). With `dump`, it stops at that checkpoint (1 = the first)
|
|
693
693
|
* and gives the RAM there.
|
|
@@ -698,19 +698,19 @@ export async function replaySide(
|
|
|
698
698
|
folder: string,
|
|
699
699
|
subject: ReplaySubject,
|
|
700
700
|
workspace: Workspace,
|
|
701
|
-
options: { compare?: Comparison; stop?: number; dump?: number; pins?: string[]; entry?: number; handover?: { entry: number;
|
|
701
|
+
options: { compare?: Comparison; stop?: number; dump?: number; pins?: string[]; entry?: number; handover?: { entry: number; reference: EntryPoint } } = {},
|
|
702
702
|
): Promise<SideRun & { ram?: Uint8Array }> {
|
|
703
703
|
const prg = readProjectFile(subject.program).bytes;
|
|
704
|
-
const
|
|
705
|
-
// The names of the
|
|
704
|
+
const reference = subject.side === "reference";
|
|
705
|
+
// The names of the reference: a recording without names takes those of the knowledge.
|
|
706
706
|
const names = recording.symbols === "none" ? "knowledge" : recording.symbols;
|
|
707
707
|
const same = (address: number) => address;
|
|
708
|
-
const move =
|
|
708
|
+
const move = reference
|
|
709
709
|
? { code: same, data: same }
|
|
710
710
|
: { code: mover(namesOf(names, "code"), namesOf(subject.symbols, "code")), data: mover(namesOf(names), namesOf(subject.symbols)) };
|
|
711
711
|
const own = namesOf(subject.symbols);
|
|
712
712
|
const at = sideAddresses(own, subject.side, move);
|
|
713
|
-
const moved =
|
|
713
|
+
const moved = reference ? [] : siteMap(recording.sites, namesOf(names, "code"), namesOf(subject.symbols, "code"));
|
|
714
714
|
const map = new Map(moved);
|
|
715
715
|
const reads = workspace.path(`${subject.side}-${RECORDING_FILES.reads}`);
|
|
716
716
|
writeFileSync(reads, readProjectFile(`${folder}/${RECORDING_FILES.reads}`).bytes);
|
|
@@ -726,7 +726,7 @@ export async function replaySide(
|
|
|
726
726
|
const stop = options.dump ?? options.stop ?? 0;
|
|
727
727
|
const pinned = compare.pin ?? [];
|
|
728
728
|
if (options.pins !== undefined && pinned.length > 0) {
|
|
729
|
-
// The rebuild: each checkpoint first gets the
|
|
729
|
+
// The rebuild: each checkpoint first gets the reference's values of the random state.
|
|
730
730
|
const pinFile = workspace.path(`${subject.side}-pins.txt`);
|
|
731
731
|
writeFileSync(pinFile, options.pins.map((line) => `${line}\n`).join(""));
|
|
732
732
|
await core.command(`pin ${pinFile} ${rangesArgument(pinned, at)}`);
|
|
@@ -735,19 +735,19 @@ export async function replaySide(
|
|
|
735
735
|
await core.command(`sample ${hex(at.code(compare.checkpoint))} ${samples} ${rangesArgument([...compare.state, ...pinned], at)}${stop > 0 ? ` ${stop}` : ""}`);
|
|
736
736
|
sampling = true;
|
|
737
737
|
};
|
|
738
|
-
// A rebuild with a loader takes its checkpoints from its entry on, as the
|
|
738
|
+
// A rebuild with a loader takes its checkpoints from its entry on, as the reference leaves out those before its own.
|
|
739
739
|
if (options.compare !== undefined && options.handover === undefined) await startSampling(options.compare);
|
|
740
740
|
const targets = recording.events.flatMap((event) => ("pc" in event.key ? [at.code(event.key.pc)] : []));
|
|
741
741
|
await countAt(core, targets);
|
|
742
742
|
if (options.entry !== undefined) await core.command(`mark ${hex(options.entry)}`);
|
|
743
743
|
await startProgram(core, prg, recording.load);
|
|
744
|
-
const base =
|
|
744
|
+
const base = reference ? recording.ticks : recording.ticks * REBUILD_TIME_FACTOR;
|
|
745
745
|
let limit = base;
|
|
746
746
|
let problem: string | undefined;
|
|
747
|
-
// A tick key of the rebuild comes this many cycles later than in the
|
|
747
|
+
// A tick key of the rebuild comes this many cycles later than in the reference.
|
|
748
748
|
let skipped = 0;
|
|
749
749
|
let screenSkipped = false;
|
|
750
|
-
if (!
|
|
750
|
+
if (!reference && !recording.load) {
|
|
751
751
|
// The cycles to the wait of a start screen do not count.
|
|
752
752
|
const screen = await passStartScreen(core, own, limit);
|
|
753
753
|
if (typeof screen === "string") problem = screen;
|
|
@@ -758,7 +758,7 @@ export async function replaySide(
|
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
760
|
// A pc key counts the opcode fetches from the start, also those of the code before the entry: the unpacker of
|
|
761
|
-
// the
|
|
761
|
+
// the reference, or the loader of the rebuild. The rebuild counts again from the jump of its loader, without those of the reference.
|
|
762
762
|
const { handover } = options;
|
|
763
763
|
if (problem === undefined && handover !== undefined) {
|
|
764
764
|
const jump = own.get(LOADER_JUMP)!;
|
|
@@ -769,17 +769,17 @@ export async function replaySide(
|
|
|
769
769
|
if (reached.word !== "reached") problem = `the rebuild did not come to its entry at ${formatC64Address(handover.entry)}`;
|
|
770
770
|
else {
|
|
771
771
|
// The loader sets the entry state of the capture, but the phase of the frame and of the CIA timers at the entry
|
|
772
|
-
// depends on how the
|
|
772
|
+
// depends on how the reference started: the rebuild waits at its entry for the beam position of the reference, and
|
|
773
773
|
// gets its CIA timers and interrupt state there. A program that starts its timers without a load keeps that phase.
|
|
774
|
-
const entered = await core.status(`align ${handover.
|
|
775
|
-
// After the entry, a tick key is as far from the entry as in the
|
|
776
|
-
skipped = entered.tick - handover.
|
|
774
|
+
const entered = await core.status(`align ${handover.reference.phase}`);
|
|
775
|
+
// After the entry, a tick key is as far from the entry as in the reference.
|
|
776
|
+
skipped = entered.tick - handover.reference.tick;
|
|
777
777
|
limit = base + Math.max(0, skipped);
|
|
778
778
|
if (options.compare !== undefined) await startSampling(options.compare);
|
|
779
779
|
}
|
|
780
780
|
}
|
|
781
781
|
}
|
|
782
|
-
// The
|
|
782
|
+
// The reference with an entry: the events before the mark at the entry came.
|
|
783
783
|
let eventsBefore = 0;
|
|
784
784
|
let entryTick: number | undefined;
|
|
785
785
|
let entryPhase = "";
|
|
@@ -791,9 +791,9 @@ export async function replaySide(
|
|
|
791
791
|
const what = event.step === undefined ? "the RESTORE of the play" : "step " + event.step;
|
|
792
792
|
let key = event.key;
|
|
793
793
|
if (handover !== undefined) {
|
|
794
|
-
// The
|
|
795
|
-
if (index < handover.
|
|
796
|
-
if ("pc" in key) key = { ...key, count: key.count - (handover.
|
|
794
|
+
// The reference came to this point before its entry, where the rebuild runs its loader. Each such event is a pc key: replay checks it.
|
|
795
|
+
if (index < handover.reference.eventsBefore) continue;
|
|
796
|
+
if ("pc" in key) key = { ...key, count: key.count - (handover.reference.counts.get(key.pc) ?? 0) };
|
|
797
797
|
}
|
|
798
798
|
const point = await runToKey(core, key, limit, map, skipped, at);
|
|
799
799
|
if (point === "halted") break;
|
|
@@ -852,8 +852,8 @@ export async function replaySide(
|
|
|
852
852
|
export interface CheckpointDifference {
|
|
853
853
|
/** 1 = the first checkpoint. */
|
|
854
854
|
checkpoint: number;
|
|
855
|
-
tick: {
|
|
856
|
-
items: Array<{ address: Location;
|
|
855
|
+
tick: { reference: number; rebuild: number };
|
|
856
|
+
items: Array<{ address: Location; reference: string; rebuild: string }>;
|
|
857
857
|
}
|
|
858
858
|
|
|
859
859
|
/** The pinned values of each sample line: the fields after the state items. */
|
|
@@ -872,8 +872,8 @@ export function firstDifference(expected: string[], got: string[], state: StateI
|
|
|
872
872
|
const a = allA.slice(0, state.length);
|
|
873
873
|
const b = allB.slice(0, state.length);
|
|
874
874
|
if (a.join(" ") === b.join(" ")) continue;
|
|
875
|
-
const items = state.flatMap((item, at) => (a[at] === b[at] ? [] : [{ address: item.address,
|
|
876
|
-
return { checkpoint: index + 1, tick: {
|
|
875
|
+
const items = state.flatMap((item, at) => (a[at] === b[at] ? [] : [{ address: item.address, reference: a[at] ?? "", rebuild: b[at] ?? "" }]));
|
|
876
|
+
return { checkpoint: index + 1, tick: { reference: Number(tickA), rebuild: Number(tickB) }, items };
|
|
877
877
|
}
|
|
878
878
|
return undefined;
|
|
879
879
|
}
|
|
@@ -881,9 +881,9 @@ export function firstDifference(expected: string[], got: string[], state: StateI
|
|
|
881
881
|
export interface ReplayResult {
|
|
882
882
|
result: Outcome;
|
|
883
883
|
recording: string;
|
|
884
|
-
/** The side that the result is about: the
|
|
885
|
-
side: "
|
|
886
|
-
/** The routine of the checkpoints, and the checkpoints of the
|
|
884
|
+
/** The side that the result is about: the reference (the self-check) or the rebuild. */
|
|
885
|
+
side: "reference" | "rebuild";
|
|
886
|
+
/** The routine of the checkpoints, and the checkpoints of the reference. */
|
|
887
887
|
checkpoint?: Location;
|
|
888
888
|
checkpoints: number;
|
|
889
889
|
/** The checkpoints of the rebuild that were equal. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The replay of c64-testing: replays a recording in the replay core
|
|
2
|
-
// (c64run). First on the
|
|
2
|
+
// (c64run). First on the reference program, which must end with the recorded
|
|
3
3
|
// state hash. Then, with --rebuild, on the rebuild: it compares the state at
|
|
4
|
-
// each checkpoint with the
|
|
4
|
+
// each checkpoint with the reference's. --checkpoint and --state choose the
|
|
5
5
|
// comparison, else the record file gave it.
|
|
6
6
|
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
@@ -30,7 +30,7 @@ export interface ReplayOptions {
|
|
|
30
30
|
out?: string;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
/** Replays the recording on the
|
|
33
|
+
/** Replays the recording on the reference, and with `rebuild` on the rebuild: PASS, FAIL or INCONCLUSIVE. */
|
|
34
34
|
export async function replay(values: ReplayOptions): Promise<ReplayResult> {
|
|
35
35
|
if (values.symbols !== undefined && values.rebuild === undefined) throw new UsageError("--symbols gives the names of the rebuild, and --rebuild is missing. Give --rebuild too, or leave out --symbols.");
|
|
36
36
|
if ((values.checkpoint === undefined) !== (values.state.length === 0)) throw new UsageError("--checkpoint and --state go together. Give both of them, or neither.");
|
|
@@ -61,54 +61,54 @@ export async function replay(values: ReplayOptions): Promise<ReplayResult> {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
const sha256 = createHash("sha256").update(readProjectFile(recording.program).bytes).digest("hex");
|
|
64
|
-
if (sha256 !== recording.sha256) return result("INCONCLUSIVE", "
|
|
64
|
+
if (sha256 !== recording.sha256) return result("INCONCLUSIVE", "reference", { reason: `${recording.program} is not the program of the recording (its SHA-256 changed); record the session again` });
|
|
65
65
|
|
|
66
66
|
const context = localToolContext();
|
|
67
67
|
const core = await C64RunSession.open(context);
|
|
68
68
|
const workspace = Workspace.create(context.supervisor, "c64-re-tools-replay-");
|
|
69
69
|
try {
|
|
70
70
|
// A recording made without names takes the names that the knowledge has now.
|
|
71
|
-
const
|
|
72
|
-
const
|
|
71
|
+
const referenceSymbols = recording.symbols === "none" ? "knowledge" : recording.symbols;
|
|
72
|
+
const reference: ReplaySubject = { side: "reference", program: recording.program, symbols: referenceSymbols };
|
|
73
73
|
const side = (subject: ReplaySubject, options: Parameters<typeof replaySide>[5]) => replaySide(core, recording, folder, subject, workspace, options);
|
|
74
|
-
const rebuildSymbols = values.symbols ??
|
|
75
|
-
// A rebuild with a generated loader starts the program where its loader jumps to. The
|
|
76
|
-
let loader: { entry: number;
|
|
74
|
+
const rebuildSymbols = values.symbols ?? referenceSymbols;
|
|
75
|
+
// A rebuild with a generated loader starts the program where its loader jumps to. The reference comes to that entry by the same name.
|
|
76
|
+
let loader: { entry: number; reference: number } | undefined;
|
|
77
77
|
if (values.rebuild !== undefined && !recording.load && namesOf(rebuildSymbols).has(LOADER_JUMP)) {
|
|
78
78
|
const entry = await loaderEntry(core, recording, { side: "rebuild", program: values.rebuild, symbols: rebuildSymbols });
|
|
79
79
|
if (typeof entry === "string") return result("FAIL", "rebuild", { reason: entry });
|
|
80
|
-
loader = { entry,
|
|
80
|
+
loader = { entry, reference: mover(namesOf(rebuildSymbols, "code"), namesOf(referenceSymbols, "code"))(entry) };
|
|
81
81
|
}
|
|
82
|
-
// The self-check: the
|
|
83
|
-
const self = await side(
|
|
84
|
-
if (self.problem !== undefined) return result("INCONCLUSIVE", "
|
|
82
|
+
// The self-check: the reference ends the session with the recorded state, to the cycle.
|
|
83
|
+
const self = await side(reference, { ...(compare === undefined ? {} : { compare }), ...(loader === undefined ? {} : { entry: loader.reference }) });
|
|
84
|
+
if (self.problem !== undefined) return result("INCONCLUSIVE", "reference", { reason: `the recording does not reproduce on the reference: ${self.problem}` });
|
|
85
85
|
if (self.unknown > 0 || self.misses > 0) {
|
|
86
|
-
return result("INCONCLUSIVE", "
|
|
86
|
+
return result("INCONCLUSIVE", "reference", { reason: `the recording does not reproduce on the reference: ${self.unknown + self.misses} input reads had no recorded value; record the session again with this version of the toolkit` });
|
|
87
87
|
}
|
|
88
88
|
if (self.end.tick !== recording.ticks || self.end.hash !== recording.hash) {
|
|
89
|
-
return result("INCONCLUSIVE", "
|
|
89
|
+
return result("INCONCLUSIVE", "reference", { reason: "the recording does not reproduce on the reference: the state at its end is different; record the session again with this version of the toolkit" });
|
|
90
90
|
}
|
|
91
91
|
const expected = self.samples;
|
|
92
|
-
if (compare !== undefined && expected.length === 0) return result("INCONCLUSIVE", "
|
|
93
|
-
if (values.rebuild === undefined) return result("PASS", "
|
|
94
|
-
let handover: { entry: number;
|
|
92
|
+
if (compare !== undefined && expected.length === 0) return result("INCONCLUSIVE", "reference", { reason: `the reference never came to the checkpoint ${compare.checkpoint} in the session` });
|
|
93
|
+
if (values.rebuild === undefined) return result("PASS", "reference", { checkpoints: expected.length });
|
|
94
|
+
let handover: { entry: number; reference: NonNullable<typeof self.entryPoint> } | undefined;
|
|
95
95
|
if (loader !== undefined) {
|
|
96
96
|
const entered = self.entryPoint;
|
|
97
|
-
const at = formatC64Address(loader.
|
|
98
|
-
if (entered === undefined) return result("INCONCLUSIVE", "
|
|
97
|
+
const at = formatC64Address(loader.reference);
|
|
98
|
+
if (entered === undefined) return result("INCONCLUSIVE", "reference", { reason: `the reference never came to ${at}, where the loader of the rebuild jumps` });
|
|
99
99
|
// An event before the entry has no point in a rebuild with a loader. A runUntil to an address there does nothing, and the rebuild leaves it out.
|
|
100
100
|
const early = recording.events.slice(0, entered.eventsBefore).find((event) => !("pc" in event.key));
|
|
101
101
|
if (early !== undefined) {
|
|
102
102
|
const what = early.step === undefined ? "the RESTORE of the play" : `step ${early.step}`;
|
|
103
|
-
return result("INCONCLUSIVE", "
|
|
103
|
+
return result("INCONCLUSIVE", "reference", { reason: `${what} ran before the program came to its entry ${at}. A rebuild with a loader has no point for it. Make the steps of the record file start after the entry` });
|
|
104
104
|
}
|
|
105
|
-
handover = { entry: loader.entry,
|
|
105
|
+
handover = { entry: loader.entry, reference: entered };
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
const rebuild: ReplaySubject = { side: "rebuild", program: values.rebuild, symbols: rebuildSymbols };
|
|
109
109
|
let movedSites: number;
|
|
110
110
|
try {
|
|
111
|
-
movedSites = siteMap(recording.sites, namesOf(
|
|
111
|
+
movedSites = siteMap(recording.sites, namesOf(referenceSymbols, "code"), namesOf(rebuild.symbols, "code")).length;
|
|
112
112
|
} catch (error) {
|
|
113
113
|
throw new UsageError(`--symbols ${rebuild.symbols}: ${(error as Error).message}`);
|
|
114
114
|
}
|
|
@@ -125,9 +125,9 @@ export async function replay(values: ReplayOptions): Promise<ReplayResult> {
|
|
|
125
125
|
const failed = result("FAIL", "rebuild", { ...base, compared: (difference?.checkpoint ?? replayed.samples.length + 1) - 1, reason, ...(difference === undefined ? {} : { firstDifference: difference }) });
|
|
126
126
|
if (values.out !== undefined && difference !== undefined) {
|
|
127
127
|
const files: Written[] = [];
|
|
128
|
-
for (const subject of [
|
|
129
|
-
// The
|
|
130
|
-
const dump = difference.checkpoint + (subject.side === "
|
|
128
|
+
for (const subject of [reference, rebuild]) {
|
|
129
|
+
// The reference also stops at the checkpoints before its entry, which its samples leave out.
|
|
130
|
+
const dump = difference.checkpoint + (subject.side === "reference" ? (handover?.reference.samplesBefore ?? 0) : 0);
|
|
131
131
|
const dumped = await side(subject, { compare: compare!, dump, ...(subject.side === "rebuild" ? { pins, ...(handover === undefined ? {} : { handover }) } : {}) });
|
|
132
132
|
files.push(writeReported(`${values.out}/${subject.side}-${difference.checkpoint}.bin`, dumped.ram!, { what: "--out" }));
|
|
133
133
|
}
|
|
@@ -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
|
|
|
@@ -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[]> = {
|
|
@@ -159,7 +159,7 @@ export function readScenario(path: string): Scenario {
|
|
|
159
159
|
refuseOldStep(kind, step, at, fail);
|
|
160
160
|
const allowed = [...(STEP_KEYS[kind] ?? [kind]), ...(kind === "observe" ? [] : ["side"])];
|
|
161
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
|
|
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,
|