@henols/c64-re-tools 2.5.1-rc.2 → 2.6.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/skills/c64-assembler/SKILL.md +26 -12
- package/skills/c64-assembler/scripts/assembler.ts +25 -13
- package/skills/c64-development/SKILL.md +2 -2
- package/skills/c64-docs/SKILL.md +4 -4
- package/skills/c64-docs/scripts/docs.ts +7 -7
- package/skills/c64-docs/scripts/lib/reference.ts +3 -3
- package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
- package/skills/c64-knowledge/SKILL.md +29 -20
- package/skills/c64-knowledge/scripts/knowledge.ts +33 -39
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +11 -10
- package/skills/c64-provenance/scripts/lib/library.ts +16 -16
- package/skills/c64-provenance/scripts/provenance.ts +33 -23
- package/skills/c64-reverse-engineering/SKILL.md +16 -10
- package/skills/c64-source/SKILL.md +60 -42
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +26 -7
- package/skills/c64-source/scripts/lib/source.ts +21 -24
- package/skills/c64-source/scripts/lib/stage.ts +6 -5
- package/skills/c64-source/scripts/source.ts +213 -106
- package/skills/c64-static-analysis/SKILL.md +7 -5
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
- package/skills/c64-testing/SKILL.md +5 -2
- package/skills/c64-testing/references/recording-format.md +18 -3
- package/skills/c64-testing/references/scenario-format.md +7 -6
- package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
- package/skills/c64-testing/scripts/lib/play.ts +39 -41
- package/skills/c64-testing/scripts/lib/recording.ts +46 -37
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/runs.ts +2 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
- package/skills/c64-unpacker/SKILL.md +4 -1
- package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/skills/emulator/SKILL.md +7 -12
- package/src/build-name.ts +50 -0
- package/src/c64-keys.ts +98 -0
- package/src/c64.ts +20 -0
- package/src/cli/main.ts +3 -29
- package/src/host/main.ts +1 -1
- package/src/host/tools/index.ts +1 -6
- package/src/host/vice/session.ts +88 -9
- package/src/host-client/steps.ts +17 -17
- package/src/host-client/tools.ts +2 -7
- package/src/host-client/vice-session.ts +7 -1
- package/src/knowledge/program.ts +44 -1
- package/src/knowledge/read.ts +28 -8
- package/src/knowledge/schema.ts +33 -9
- package/src/knowledge/start-screen.ts +4 -0
- package/src/knowledge/text.ts +4 -2
- package/src/knowledge/write.ts +59 -25
- package/src/mcp/inputs.ts +12 -0
- package/src/mcp/server.ts +1 -1
- package/src/mcp/tools/input.ts +38 -5
- package/src/mcp/tools/machine.ts +3 -42
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/acme.ts +1 -1
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +3 -3
- package/src/native/dxa.ts +12 -1
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +4 -4
- package/src/native/types.ts +2 -2
- package/src/platform.ts +30 -1
- package/src/project.ts +17 -4
- package/src/protocol/tools.ts +1 -45
- package/src/protocol/vice.ts +47 -0
- package/src/script.ts +1 -1
- package/src/vsf.ts +98 -0
- package/tools/c64run.c +9 -12
- package/tools/install-container.sh +1 -2
- package/src/cli/status.ts +0 -127
- package/src/host/tools/status.ts +0 -47
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/src/native/status.ts +0 -135
- package/tools/install-ghidra.sh +0 -40
|
@@ -29,7 +29,8 @@ To get the command list, run the script with no arguments.
|
|
|
29
29
|
| Get C-like code of a routine | `analyze --entry '$080d' --decompile '$0818'` |
|
|
30
30
|
| Get each instruction as JSON | `analyze --entry '$080d' --out-instructions .c64-re-tools/local/instructions.json` |
|
|
31
31
|
| Analyze drive code or a cartridge bank | `analyze --space drive8` |
|
|
32
|
-
|
|
|
32
|
+
| Write the macro candidates to the project knowledge | `analyze --apply-macros` |
|
|
33
|
+
| Write only the correct macro candidates | `analyze --apply-macros --skip '$1e64' --skip '$2010'` |
|
|
33
34
|
| Get more items in each list | `analyze --max-listed 500` |
|
|
34
35
|
|
|
35
36
|
---
|
|
@@ -86,7 +87,8 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
86
87
|
| `--max-listed <n>` | `analyze` | List at most `n` items in each list. `0` lists no items. The counts stay complete. The default is 50. |
|
|
87
88
|
| `--out-listing <file>` | `analyze` | DXA only. Write the disassembly listing to this project file. There is no default. |
|
|
88
89
|
| `--out-instructions <file>` | `analyze` | Ghidra only. Write each instruction to this project file as JSON. There is no default. |
|
|
89
|
-
| `--
|
|
90
|
+
| `--apply-macros` | `analyze` | Write the macro candidates and their macros to the project knowledge as one revision of the LLM. Off by default. |
|
|
91
|
+
| `--skip <address>` | `analyze` | With `--apply-macros`: the start of a macro candidate that is not correct. The run does not write it. Give one `--skip` for each such candidate. |
|
|
90
92
|
|
|
91
93
|
---
|
|
92
94
|
|
|
@@ -127,7 +129,7 @@ The `hint` gives each of these cases:
|
|
|
127
129
|
|
|
128
130
|
- `conflicts` is not empty. Find the correct answer in the emulator. Then correct the project knowledge.
|
|
129
131
|
- `coverageConflicts` is not empty. Classify each range as code in the project knowledge, or as `dual-use` when its bytes are also data. For many ranges, write all classifications in one batch of changes.
|
|
130
|
-
-
|
|
132
|
+
- `idioms.candidates.macros` has candidates, and the run had no `--apply-macros`. Examine the candidates. To write the correct candidates to the project knowledge, run the analysis again with `--apply-macros`. Give `--skip` with the start of each candidate that is not correct. Then generate the source again.
|
|
131
133
|
- A list is cut. Give a larger `--max-listed`. The project knowledge has all `labels` and `functions` as analyzer names.
|
|
132
134
|
|
|
133
135
|
There is no `nextAction`.
|
|
@@ -140,7 +142,7 @@ The script does not record the candidates. Examine each candidate and decide.
|
|
|
140
142
|
- `selfModified`: opcodes that the program wrote and then executed. The write and the execution must be in one coverage file. A coverage file does not record the order. Thus a candidate can also be code that ran first, and that the program then wrote over. To prevent this, save one coverage file for each part of the program, for example the intro, the game, or a loader that copies code. Clear the memory map between the parts.
|
|
141
143
|
- `pointers`: code that makes an address from immediates. A `vector` or a `zero-page pointer` candidate stores a low byte (`low`) and a high byte (`high`) to a vector or to a zero-page pair. A `sprite pointer` candidate stores an immediate (`at`) to a sprite pointer of the screen at `$0400` in VIC bank 0. For each correct candidate, record a low and a high operand expression to its `target` in the project knowledge. Then a rebuild can move the target.
|
|
142
144
|
- `pitfalls`: code that a C64 runs in a different way than it reads. For `raster-bit-8`, the instruction at `at` reads `$D011`, and the instruction at `store` writes the value back. The write can move the raster interrupt to line 256 or later. On PAL, past line 311, the interrupt never comes. Where the code must not keep bit 7, add a comment and test the program.
|
|
143
|
-
- `macros`: runs of instructions that one macro line can replace, for example `+inc16 ptr`. Each candidate has `macro`, `start`, `end`, `args` and `text`. The macros are `inc16`, `dec16`, `add16_8`, `add16`, `sub16`, `set16`, `mov16` and `wait_line`. An arg is a name of the user or the LLM, or a platform name of a ROM that the program uses. `known` counts the uses that the project knowledge has. `leftOut` counts the candidates with a label inside, or with a patch or
|
|
145
|
+
- `macros`: runs of instructions that one macro line can replace, for example `+inc16 ptr`. Each candidate has `macro`, `start`, `end`, `args` and `text`. The macros are `inc16`, `dec16`, `add16_8`, `add16`, `sub16`, `set16`, `mov16` and `wait_line`. An arg is a name of the user or the LLM, or a platform name of a ROM that the program uses. `known` counts the uses that the project knowledge has. `leftOut` counts the candidates with a label inside, or with a patch over them, or with another use of the project knowledge over them. With `--apply-macros`, `revision` gives the revision of the writes, and `writes` counts them. The writes hold the macros that the project knowledge does not have, with their bodies, and the uses. Do not write these macros yourself. `otherMacros` names each macro that the project knowledge has with another body. The writes do not have the uses of that macro. `skipped` counts the candidates that `--skip` left out. `notCandidates` lists each `--skip` address that starts no candidate.
|
|
144
146
|
|
|
145
147
|
#### Which facts the analysis replaces
|
|
146
148
|
|
|
@@ -165,7 +167,7 @@ The script does not record the candidates. Examine each candidate and decide.
|
|
|
165
167
|
- `coverageGaps` has starts. Normally its count is 0. Each start is not in `--out-instructions` and not in the generated source. Examine the code at the start. Overlapped instructions and self-modified code can cause a gap. A start in a `dual-use` region is a known overlap, for example a BIT skip, and is not in the list.
|
|
166
168
|
- `coverageSeeds.used` is smaller than `coverageSeeds.entryPoints`. The analysis did not use all entry points of the coverage. Give the important entry points with `--entry`, or record them as routines in the project knowledge. These come first.
|
|
167
169
|
- `romOnlyUsed` is smaller than `romOnlyRanges`. The analysis did not keep all RAM under ROM as data. Classify the RAM under ROM that is not code as data in the project knowledge.
|
|
168
|
-
- `notDecompiled` has a reason
|
|
170
|
+
- `notDecompiled` has a routine. The `reason` tells why the decompiler did not decompile it. Read the instructions of that routine in the file of `--out-instructions`.
|
|
169
171
|
|
|
170
172
|
#### Failures
|
|
171
173
|
|
|
@@ -4,15 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import type { DatabaseSync } from "node:sqlite";
|
|
6
6
|
|
|
7
|
-
import { COVERAGE, coverageEntries, coverageSeedKinds, executedStarts } from "#src/c64.ts";
|
|
7
|
+
import { COVERAGE, coverageEntries, coverageSeedKinds, executedStarts, romOnlyRanges } from "#src/c64.ts";
|
|
8
8
|
|
|
9
|
-
export { coverageEntries, coverageSeedKinds, executedStarts };
|
|
10
|
-
import { FULL_COVERAGE } from "#src/host-client/coverage.ts";
|
|
9
|
+
export { coverageEntries, coverageSeedKinds, executedStarts, romOnlyRanges };
|
|
11
10
|
import { listRegions, type RegionRow } from "#src/knowledge/read.ts";
|
|
12
11
|
import { CODE_REGION_TYPES, DEFAULT_SPACE, isAnalyzer, isSemantic, type Space } from "#src/knowledge/schema.ts";
|
|
13
12
|
|
|
14
|
-
const FULL_MAP = FULL_COVERAGE;
|
|
15
|
-
|
|
16
13
|
/** The byte at an address of the analyzed image, or undefined outside it. */
|
|
17
14
|
export type ImageByte = (address: number) => number | undefined;
|
|
18
15
|
|
|
@@ -22,26 +19,6 @@ export function imageReader(bytes: Uint8Array, kind: "prg" | "flat64k"): ImageBy
|
|
|
22
19
|
return (address) => (address >= load && address - load + 2 < bytes.length ? bytes[address - load + 2] : undefined);
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
const ROM_ACCESS = COVERAGE.romRead | COVERAGE.romExecute;
|
|
26
|
-
const RAM_USE = COVERAGE.ramRead | COVERAGE.ramExecute;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The image bytes under ROM that the runs never used: the CPU read or ran the
|
|
30
|
-
* ROM there, and never read or ran the RAM. A JSR $FFE4 or an IRQ
|
|
31
|
-
* vector at $FFFE then leads into ROM, not into the leftover RAM bytes of a
|
|
32
|
-
* flat image, so the ranges are data for the analysis run.
|
|
33
|
-
*/
|
|
34
|
-
export function romOnlyRanges(map: Uint8Array, image: ImageByte): Array<{ start: number; end: number }> {
|
|
35
|
-
const ranges: Array<{ start: number; end: number }> = [];
|
|
36
|
-
for (let address = 0; address < FULL_MAP; address++) {
|
|
37
|
-
if ((map[address]! & ROM_ACCESS) === 0 || (map[address]! & RAM_USE) !== 0 || image(address) === undefined) continue;
|
|
38
|
-
const last = ranges.at(-1);
|
|
39
|
-
if (last !== undefined && last.end === address - 1) last.end = address;
|
|
40
|
-
else ranges.push({ start: address, end: address });
|
|
41
|
-
}
|
|
42
|
-
return ranges;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
22
|
/** Entry points from semantic knowledge beyond routines: the start of each code region, and each entry of a JMP table with its target. */
|
|
46
23
|
export function codeEntries(db: DatabaseSync | undefined, image: ImageByte, space: Space = DEFAULT_SPACE): number[] {
|
|
47
24
|
const entries: number[] = [];
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// with a coverage file, whether the instruction ran.
|
|
4
4
|
|
|
5
5
|
import { COVERAGE, formatC64Address } from "#src/c64.ts";
|
|
6
|
+
import { OPCODES, type Mode as OpcodeMode } from "#src/opcodes.ts";
|
|
6
7
|
import type { GhidraInstruction } from "#src/native/types.ts";
|
|
7
8
|
|
|
8
9
|
export type Mode =
|
|
@@ -20,26 +21,27 @@ export type Mode =
|
|
|
20
21
|
| "(indirect),y"
|
|
21
22
|
| "relative";
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
const
|
|
24
|
+
/** ASL, ROL, LSR and ROR of the accumulator: the implied forms that work on A. */
|
|
25
|
+
const ACCUMULATOR = new Set([0x0a, 0x2a, 0x4a, 0x6a]);
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
const MODES: Record<OpcodeMode, Mode> = {
|
|
28
|
+
imp: "implied",
|
|
29
|
+
imm: "immediate",
|
|
30
|
+
zp: "zeropage",
|
|
31
|
+
zpx: "zeropage,x",
|
|
32
|
+
zpy: "zeropage,y",
|
|
33
|
+
abs: "absolute",
|
|
34
|
+
abx: "absolute,x",
|
|
35
|
+
aby: "absolute,y",
|
|
36
|
+
ind: "(indirect)",
|
|
37
|
+
izx: "(indirect,x)",
|
|
38
|
+
izy: "(indirect),y",
|
|
39
|
+
rel: "relative",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** The addressing mode of an opcode. */
|
|
43
|
+
export function modeOf(opcode: number): Mode {
|
|
44
|
+
return ACCUMULATOR.has(opcode) ? "accumulator" : MODES[OPCODES[opcode]!.mode];
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
/** The operand in 6502 syntax, from the instruction bytes; empty for implied. */
|
|
@@ -90,7 +92,7 @@ export interface ListedInstruction {
|
|
|
90
92
|
export function instructionList(instructions: GhidraInstruction[], coverage?: Uint8Array): ListedInstruction[] {
|
|
91
93
|
return instructions.map((instruction) => {
|
|
92
94
|
const bytes = Buffer.from(instruction.bytes, "hex");
|
|
93
|
-
const mode = modeOf(bytes[0]
|
|
95
|
+
const mode = modeOf(bytes[0]!);
|
|
94
96
|
const [target] = instruction.flows;
|
|
95
97
|
return {
|
|
96
98
|
address: formatC64Address(instruction.address),
|
|
@@ -13,7 +13,8 @@ import { analyze as analyzeWithGhidra } from "#src/native/ghidra/analyze.ts";
|
|
|
13
13
|
import { localToolContext } from "#src/native/local.ts";
|
|
14
14
|
import { GHIDRA_LIMITS } from "#src/native/types.ts";
|
|
15
15
|
import { openForRead, withWrite } from "#src/knowledge/database.ts";
|
|
16
|
-
import { analyzedBytes, programCoverage, requireProgram } from "#src/knowledge/program.ts";
|
|
16
|
+
import { analyzedBytes, operandImages, programCoverage, requireProgram } from "#src/knowledge/program.ts";
|
|
17
|
+
import { applyBatch, type BatchOperation } from "#src/knowledge/write.ts";
|
|
17
18
|
import { importFindings, runProvenance, type ImportConflict, type ImportContext, type ImportResult, type NormalizedFindings } from "#src/knowledge/import.ts";
|
|
18
19
|
import { currentRevision, listMacros, listMacroUses, listPatches, listReferences, listRegions, listSymbols } from "#src/knowledge/read.ts";
|
|
19
20
|
import { DEFAULT_SPACE, SEMANTIC_ORIGINS, type Analyzer } from "#src/knowledge/schema.ts";
|
|
@@ -32,14 +33,15 @@ const ALL_NAMES = "a larger --max-listed. The project knowledge has all of them
|
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* The result with a hint for what the agent does next: conflicts to examine,
|
|
35
|
-
* analyzer data over executed code to classify, and
|
|
36
|
+
* analyzer data over executed code to classify, and macro candidates to write.
|
|
36
37
|
* The envelope adds the sentence for a cut list.
|
|
37
38
|
*/
|
|
38
|
-
function withHint(body: Record<string, unknown>, conflicts: number, coverageConflicts: number,
|
|
39
|
+
function withHint(body: Record<string, unknown>, conflicts: number, coverageConflicts: number, macros: { candidates: number; applied: boolean; revision: string | null | undefined }) {
|
|
39
40
|
const hints: string[] = [];
|
|
40
41
|
if (conflicts > 0) hints.push("The analysis and the project knowledge disagree at each place in conflicts. Find the correct answer in the emulator. Then correct the project knowledge.");
|
|
41
42
|
if (coverageConflicts > 0) hints.push("The coverage shows executed code in each range of coverageConflicts. Classify each range as code, or as dual-use when its bytes are also data, in the project knowledge.");
|
|
42
|
-
if (
|
|
43
|
+
if (typeof macros.revision === "string") hints.push("The project knowledge has the macro candidates now. Generate the source again.");
|
|
44
|
+
else if (!macros.applied && macros.candidates > 0) hints.push("Examine idioms.candidates.macros. To write them to the project knowledge, run the analysis again with --apply-macros.");
|
|
43
45
|
if (hints.length === 0) return body;
|
|
44
46
|
return reply(body, { hint: hints.join(" ") });
|
|
45
47
|
}
|
|
@@ -73,11 +75,11 @@ function showMacro(candidate: MacroCandidate) {
|
|
|
73
75
|
* the ROMs that the program uses, as c64-source names them. A candidate is left out when
|
|
74
76
|
* a name or a reference target is inside it, or a patch or a use overlaps it:
|
|
75
77
|
* c64-source would write its instructions. The same use in the knowledge is
|
|
76
|
-
* known.
|
|
77
|
-
*
|
|
78
|
-
* another body leaves its candidates out of the
|
|
78
|
+
* known. The writes are the candidates with the macros they need, without the
|
|
79
|
+
* candidates that start at an address of `skip`. A macro of the catalogue that
|
|
80
|
+
* the knowledge has with another body leaves its candidates out of the writes.
|
|
79
81
|
*/
|
|
80
|
-
function macroCandidates(space: string, byteAt: ImageByte,
|
|
82
|
+
function macroCandidates(space: string, byteAt: ImageByte, romUse: RomUse, skip: ReadonlySet<number>) {
|
|
81
83
|
const db = openForRead();
|
|
82
84
|
try {
|
|
83
85
|
// The platform names that c64-source uses: a name of a ROM that the program does not use is no arg.
|
|
@@ -98,45 +100,27 @@ function macroCandidates(space: string, byteAt: ImageByte, batchPath: string | u
|
|
|
98
100
|
else if ([...named].some((address) => address > candidate.start && address <= candidate.end) || patches.some((patch) => overlaps(patch, candidate)) || uses.some((use) => overlaps(use, candidate))) leftOut++;
|
|
99
101
|
else candidates.push(candidate);
|
|
100
102
|
}
|
|
101
|
-
|
|
102
|
-
// A macro of the catalogue goes into the batch unless the knowledge has it; with another body, its uses stay out.
|
|
103
|
+
// A macro of the catalogue goes into the writes unless the knowledge has it; with another body, its uses stay out.
|
|
103
104
|
const macros = new Map(listMacros(db, undefined, space).map((macro) => [macro.name, macro]));
|
|
104
|
-
const
|
|
105
|
-
const batched: MacroCandidate[] = [];
|
|
105
|
+
const writes: BatchOperation[] = [];
|
|
106
106
|
const other = new Set<string>();
|
|
107
|
-
|
|
107
|
+
const chosen = candidates.filter((candidate) => !skip.has(candidate.start));
|
|
108
|
+
for (const idiom of CATALOGUE.filter((item) => chosen.some((candidate) => candidate.macro === item.name))) {
|
|
108
109
|
const existing = macros.get(idiom.name);
|
|
109
|
-
if (existing === undefined)
|
|
110
|
+
if (existing === undefined) writes.push({ op: "macro", space, name: idiom.name, params: [...idiom.params], body: idiom.body, comment: idiom.comment });
|
|
110
111
|
else if (existing.params.join(",") !== idiom.params.join(",") || existing.body !== idiom.body) other.add(idiom.name);
|
|
111
112
|
}
|
|
112
|
-
for (const candidate of
|
|
113
|
+
for (const candidate of chosen) {
|
|
113
114
|
if (other.has(candidate.macro)) continue;
|
|
114
|
-
|
|
115
|
-
batch.push({ op: "use", start: formatC64Address(candidate.start), end: formatC64Address(candidate.end), macro: candidate.macro, args: candidate.args, ...(space === DEFAULT_SPACE ? {} : { space }) });
|
|
115
|
+
writes.push({ op: "use", space, start: candidate.start, end: candidate.end, macro: candidate.macro, args: candidate.args });
|
|
116
116
|
}
|
|
117
|
-
const
|
|
118
|
-
return {
|
|
119
|
-
candidates,
|
|
120
|
-
known,
|
|
121
|
-
leftOut,
|
|
122
|
-
batch: {
|
|
123
|
-
...written,
|
|
124
|
-
writes: batch.length,
|
|
125
|
-
...(other.size === 0 ? {} : { otherMacros: [...other].map((name) => `The knowledge has another macro ${name}: its candidates are not in the batch.`) }),
|
|
126
|
-
},
|
|
127
|
-
};
|
|
117
|
+
const notCandidates = [...skip].filter((address) => !candidates.some((candidate) => candidate.start === address)).sort((a, b) => a - b);
|
|
118
|
+
return { candidates, known, leftOut, writes, skipped: candidates.length - chosen.length, notCandidates, otherMacros: [...other].map((name) => `The knowledge has another macro ${name}: its candidates are not written.`) };
|
|
128
119
|
} finally {
|
|
129
120
|
db?.close();
|
|
130
121
|
}
|
|
131
122
|
}
|
|
132
123
|
|
|
133
|
-
/** A decompiler that did not start gets the remedy: Ghidra ships no native decompiler for macOS. */
|
|
134
|
-
function withRemedy(reason: string): string {
|
|
135
|
-
return reason.startsWith("the Ghidra decompiler did not start")
|
|
136
|
-
? `${reason} On macOS, build the native decompiler once: in <Ghidra>/support/gradle run ./gradlew buildNatives.`
|
|
137
|
-
: reason;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
124
|
/** One conflict: what the knowledge has, and what the analyzer found, under the analyzer's name. */
|
|
141
125
|
function showConflict(conflict: ImportConflict, analyzer: Analyzer): Record<string, unknown> {
|
|
142
126
|
if (conflict.category === "code-evidence") {
|
|
@@ -194,7 +178,9 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
194
178
|
const analyzer = call.string("analyzer") as "dxa" | "ghidra";
|
|
195
179
|
const listingPath = call.string("out-listing");
|
|
196
180
|
const instructionsPath = call.string("out-instructions");
|
|
197
|
-
const
|
|
181
|
+
const applyMacros = call.flag("apply-macros");
|
|
182
|
+
const skip = new Set(call.addresses("skip"));
|
|
183
|
+
if (skip.size > 0 && !applyMacros) throw new UsageError("--skip works only with --apply-macros: it names a macro candidate that the run does not write");
|
|
198
184
|
if (analyzer === "dxa" && decompile.length > 0) throw new UsageError("--decompile works only with --analyzer ghidra");
|
|
199
185
|
if (analyzer === "ghidra" && listingPath !== undefined) throw new UsageError("--out-listing works only with --analyzer dxa");
|
|
200
186
|
if (analyzer === "dxa" && instructionsPath !== undefined) throw new UsageError("--out-instructions works only with --analyzer ghidra");
|
|
@@ -241,7 +227,10 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
241
227
|
const idiomsResult = () => {
|
|
242
228
|
const imported = withWrite((db) => importFindings(db, { ...idioms.findings, space }, { description: "Idioms in the program" }));
|
|
243
229
|
// The macro candidates read the code regions after both imports.
|
|
244
|
-
const macros = macroCandidates(space, byteAt,
|
|
230
|
+
const macros = macroCandidates(space, byteAt, romUseOfProgram(coverage, program.state), skip);
|
|
231
|
+
// With --apply-macros, the candidates and their macros are a third revision of the LLM.
|
|
232
|
+
const platformNamed = new Map(platformNames().map((entry) => [entry.name, entry.address]));
|
|
233
|
+
const written = applyMacros && macros.writes.length > 0 ? withWrite((db) => applyBatch(db, { origin: "llm", description: "Macro candidates in the program", image: operandImages(db, platformNamed) }, macros.writes)) : undefined;
|
|
245
234
|
// Platform pitfalls are C64 facts: drive code and banks get none. Pitfalls and pointers read the code regions after both imports.
|
|
246
235
|
const codeDb = openForRead();
|
|
247
236
|
const code = listRegions(codeDb, undefined, "code", undefined, space);
|
|
@@ -264,10 +253,13 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
264
253
|
pointers: listed(pointers, max, showPointer, "a larger --max-listed"),
|
|
265
254
|
pitfalls: listed(pitfalls, max, showPitfall, "a larger --max-listed"),
|
|
266
255
|
macros: {
|
|
267
|
-
...listed(macros.candidates, max, showMacro, "a larger --max-listed
|
|
256
|
+
...listed(macros.candidates, max, showMacro, "a larger --max-listed"),
|
|
268
257
|
...(macros.known === 0 ? {} : { known: macros.known }),
|
|
269
258
|
...(macros.leftOut === 0 ? {} : { leftOut: macros.leftOut }),
|
|
270
|
-
...(
|
|
259
|
+
...(written === undefined ? {} : { revision: written.revision, writes: macros.writes.length }),
|
|
260
|
+
...(macros.skipped === 0 ? {} : { skipped: macros.skipped }),
|
|
261
|
+
...(macros.notCandidates.length === 0 ? {} : { notCandidates: macros.notCandidates.map(formatC64Address) }),
|
|
262
|
+
...(macros.otherMacros.length === 0 ? {} : { otherMacros: macros.otherMacros }),
|
|
271
263
|
},
|
|
272
264
|
},
|
|
273
265
|
},
|
|
@@ -315,7 +307,7 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
315
307
|
labels: listed(result.labels, max, (label) => ({ address: formatC64Address(label.address), name: label.name }), ALL_NAMES),
|
|
316
308
|
...(written === undefined ? {} : { listing: written }),
|
|
317
309
|
};
|
|
318
|
-
return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, found.idioms.candidates.macros.
|
|
310
|
+
return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision });
|
|
319
311
|
}
|
|
320
312
|
|
|
321
313
|
const { result } = await analyzeWithGhidra({ imageKind, ...seeds, codeStarts, decompile }, bytes, localToolContext());
|
|
@@ -347,9 +339,9 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
347
339
|
decompilations: result.decompilations.map((item) => ({ entry: formatC64Address(item.entry), text: item.text, ...(item.truncated ? { truncated: true } : {}) })),
|
|
348
340
|
...((result.notDecompiled ?? []).length === 0
|
|
349
341
|
? {}
|
|
350
|
-
: { notDecompiled: result.notDecompiled!.map((item) => ({ entry: formatC64Address(item.entry), reason:
|
|
342
|
+
: { notDecompiled: result.notDecompiled!.map((item) => ({ entry: formatC64Address(item.entry), reason: item.reason })) }),
|
|
351
343
|
};
|
|
352
|
-
return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, found.idioms.candidates.macros.
|
|
344
|
+
return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision });
|
|
353
345
|
}
|
|
354
346
|
|
|
355
347
|
await runScript({
|
|
@@ -368,7 +360,8 @@ await runScript({
|
|
|
368
360
|
"max-listed": { ...OPTIONS["max-listed"], help: "list at most n labels, functions or candidates (default 50, 0 for none). The counts are always given, and the knowledge has all labels and functions" },
|
|
369
361
|
"out-listing": { kind: "path", output: "file", value: "<file>", help: "dxa: write the disassembly listing to this project file" },
|
|
370
362
|
"out-instructions": { kind: "path", output: "file", value: "<file>", help: "ghidra: write every instruction (address, bytes, mnemonic, mode, operand, target, executed) to this project file as JSON" },
|
|
371
|
-
"
|
|
363
|
+
"apply-macros": { kind: "flag", help: "write the macro candidates (the macros and their uses) to the project knowledge as one revision of the LLM" },
|
|
364
|
+
skip: { kind: "address", value: "<address>", multiple: true, help: "with --apply-macros: the start of a macro candidate that is not correct. The run does not write it" },
|
|
372
365
|
},
|
|
373
366
|
notes: "The program and the coverage come from the project knowledge: put them into the project knowledge first. The executed code of the coverage gives entry points. Routine symbols in the knowledge are entry points too. Ghidra needs at least one entry point. DXA finds the SYS of a BASIC start by itself.",
|
|
374
367
|
run: analyze,
|
|
@@ -30,7 +30,7 @@ To get the command list, run the script with no arguments.
|
|
|
30
30
|
| Record a play session of a person on the original | `record tests/record/start.json --out tests/recordings/play1 --play --joystick 1` |
|
|
31
31
|
| Record a session from steps only | `record tests/record/rooms.json --out tests/recordings/rooms` |
|
|
32
32
|
| Make sure that a recording replays on the original | `replay tests/recordings/rooms` |
|
|
33
|
-
| Compare the rebuild with a recording | `replay tests/recordings/rooms --checkpoint main_loop --state room --state lives --pin random_ptr:2 --rebuild build/
|
|
33
|
+
| Compare the rebuild with a recording | `replay tests/recordings/rooms --checkpoint main_loop --state room --state lives --pin random_ptr:2 --rebuild build/clean.prg --symbols build/symbols/clean.json --out .c64-re-tools/local/results/rooms` |
|
|
34
34
|
| Find what changed between two snapshot files | `diff .c64-re-tools/local/runs/rooms/before.vsf .c64-re-tools/local/runs/rooms/after.vsf` |
|
|
35
35
|
| Find what changed between two observations of runs | `diff .c64-re-tools/local/runs/rooms/results.json:room0 .c64-re-tools/local/runs/rooms/results.json:room3` |
|
|
36
36
|
| Find what changed between two memory files of runs | `diff .c64-re-tools/local/runs/a/all.bin .c64-re-tools/local/runs/b/all.bin --gap 4` |
|
|
@@ -42,6 +42,7 @@ To get the command list, run the script with no arguments.
|
|
|
42
42
|
- The original gets its names from the project knowledge. Give `"symbols": "knowledge"` for the original.
|
|
43
43
|
- The rebuild gets its names from the symbol file of its build. Build the rebuild with a symbol file that has all symbols, also the constants that the source does not use.
|
|
44
44
|
- You write the scenario file, the run file and the record file. Their formats are in the files of the section "Reference".
|
|
45
|
+
- A file in `tests/` is a scenario or a run file with expected values. Give a scenario to `test` and a run file to `run`. `test` refuses a run file.
|
|
45
46
|
- `<recording>` is the `--out` folder of `record`.
|
|
46
47
|
- `--checkpoint` is a routine that the program executes one time in each pass of its game logic, for example the main loop. Do not use an interrupt handler. Get the name from the project knowledge.
|
|
47
48
|
- `--state` and `--pin` take a name or a `$` address, with `:size` for more than one byte, for example `room:2`. Use the names that the project knowledge has at the time of the replay.
|
|
@@ -233,6 +234,8 @@ The script first replays the recording on the original. The original must end th
|
|
|
233
234
|
`--checkpoint` and `--state` go together. `--pin` needs both of them. `--symbols` needs `--rebuild`. Give at most 16 `--state` and `--pin` items. Without `--checkpoint`, the script uses the comparison of the record file.
|
|
234
235
|
A `$` address is an address of the original. On the rebuild, it moves with the name before it.
|
|
235
236
|
|
|
237
|
+
A rebuild can be a loader with a start screen that RUN starts. If the symbols of the rebuild have `loader_start_screen_wait` and `loader_start_screen_continue`, the script runs the rebuild to the wait. Then it sets the PC to `loader_start_screen_continue`. The cycles before the wait do not count.
|
|
238
|
+
|
|
236
239
|
`body` holds `result`, `side`, `firstDifference`, `reason` and `files`. The section "Replay" of `references/recording-format.md` gives each field.
|
|
237
240
|
|
|
238
241
|
Do this for each result:
|
|
@@ -248,7 +251,7 @@ Do this for each result:
|
|
|
248
251
|
|
|
249
252
|
Traps:
|
|
250
253
|
|
|
251
|
-
- `idleReads` counts the input reads of the rebuild that the recording had no value for. On the original, such a read makes the result INCONCLUSIVE.
|
|
254
|
+
- `idleReads` counts the input reads of the rebuild that the recording had no value for. On the original, such a read makes the result INCONCLUSIVE. The rebuild can read input where the original does not, for example in its loader before the start screen. Such reads do not change a PASS of the rebuild.
|
|
252
255
|
- The script refuses a recording of version 2.0 with `invalid-input`. Record the session again.
|
|
253
256
|
|
|
254
257
|
---
|
|
@@ -37,7 +37,7 @@ A record file is one JSON object in a project file.
|
|
|
37
37
|
The steps have the form of the steps of a scenario. Two steps behave differently:
|
|
38
38
|
|
|
39
39
|
- `type` puts at most 10 keys into the keyboard queue of the KERNAL. It is an event: a replay does it again.
|
|
40
|
-
- `press` pushes keys of the keyboard matrix. It is input.
|
|
40
|
+
- `press` pushes keys of the keyboard matrix. It is input.
|
|
41
41
|
|
|
42
42
|
A record file has no `raster` target and no `condition`. `write` and `runUntil` have only the space `c64`.
|
|
43
43
|
|
|
@@ -45,19 +45,33 @@ A record file has no `raster` target and no `condition`. `write` and `runUntil`
|
|
|
45
45
|
|---|---|
|
|
46
46
|
| `{ "frames": 300 }` | Run 300 frames (19656 cycles each). |
|
|
47
47
|
| `{ "joystick": { "port": 2, "direction": "left", "fire": true } }` | Set a joystick. It stays in this state until the next joystick step. |
|
|
48
|
-
| `{ "press": "RUN\n" }` | Press
|
|
48
|
+
| `{ "press": { "keys": "RUN\n" } }` | Press the keys of the keyboard matrix. Each tap holds its keys for 3 frames, then releases them for 3 frames. `frames` sets a different number, from 1 to 3000. |
|
|
49
49
|
| `{ "type": { "mode": "text", "text": "RUN\n" } }` | Put at most 10 keys into the keyboard queue of the KERNAL, after the keys that wait there. |
|
|
50
50
|
| `{ "write": { "address": "next_room", "data": "01" } }` | Write bytes into RAM. |
|
|
51
51
|
| `{ "registers": { "pc": "change_room", "a": 16 } }` | Set registers at the next instruction. `pc` continues the program at that address. |
|
|
52
52
|
| `{ "runUntil": { "target": { "kind": "address", "address": "main_loop" }, "timeoutFrames": 300 } }` | Run until the CPU gets to an address. |
|
|
53
53
|
| `{ "runUntil": { "target": { "kind": "memory", "address": "room", "operator": "eq", "value": 2 }, "timeoutFrames": 600 } }` | Run until a byte compares true with `value`. The script reads the byte at the end of each frame. |
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
Each character of `keys` is one tap. a to z press the same keys as A to Z. `\n` presses RETURN. A character with SHIFT, for example `!`, also presses the left SHIFT.
|
|
56
|
+
|
|
57
|
+
The program runs while a `press` step taps its keys. An event in these frames is past when the next step starts. After a `press` step, run until an address that the program gets to later. For example, after F1 starts a game, run until the main loop of the game, not until the routine that starts the game.
|
|
58
|
+
|
|
59
|
+
A key without a character has its name in braces, in upper or lower case. `{STOP}` is RUN/STOP, and `{CBM}` is the Commodore key. The names are:
|
|
60
|
+
|
|
61
|
+
- `{F1}` to `{F8}`, `{RETURN}`, `{SPACE}`, `{DEL}`, `{INST}`, `{HOME}`, `{CLR}`
|
|
62
|
+
- `{STOP}`, `{RUN}`, `{RESTORE}`, `{CTRL}`, `{CBM}`, `{LSHIFT}`, `{RSHIFT}`
|
|
63
|
+
- `{UP}`, `{DOWN}`, `{LEFT}`, `{RIGHT}`, `{POUND}`, `{UPARROW}`, `{LEFTARROW}`
|
|
64
|
+
|
|
65
|
+
`{F2}`, `{F4}`, `{F6}`, `{F8}`, `{RUN}`, `{CLR}`, `{INST}`, `{UP}` and `{LEFT}` also press the left SHIFT.
|
|
66
|
+
|
|
67
|
+
To hold keys together in one tap, join them with `+` in braces. For example, `{ "press": { "keys": "{LSHIFT+CBM}" } }` holds the left SHIFT and the Commodore key together. One tap holds at most 4 keys. RESTORE counts as a key.
|
|
56
68
|
|
|
57
69
|
The keyboard queue of the KERNAL holds 10 keys. If the keys of a `type` step and the keys that wait in the queue do not fit, the session stops. A program that reads the keyboard hardware does not see the keys of a `type` step. Use `press` for that program.
|
|
58
70
|
|
|
59
71
|
`joystick`, `press` and `frames` steps are input and time. The recording keeps their effect in the reads, so a replay does not do these steps again.
|
|
60
72
|
|
|
73
|
+
RESTORE starts an NMI and is not a read. The recording keeps each RESTORE of a `press` step as an event of that step. The replay presses RESTORE again at the same read of the program.
|
|
74
|
+
|
|
61
75
|
`type`, `write`, `registers` and `runUntil` steps are events. The recording keeps a point in the program for each event. The point is the next read at the input site with the most reads. That site is not in ROM. A replay does the event again at the same read. An event that comes directly after another event runs at once after that event.
|
|
62
76
|
|
|
63
77
|
## Play
|
|
@@ -126,5 +140,6 @@ The body of the envelope of `replay` has these fields:
|
|
|
126
140
|
- `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 `original` and `rebuild` values as hex.
|
|
127
141
|
- `reason`: why the result is FAIL or INCONCLUSIVE.
|
|
128
142
|
- `movedSites`: the number of sites at a different address in the rebuild.
|
|
143
|
+
- `startScreen`: `skipped` when the rebuild went past the wait of its start screen.
|
|
129
144
|
- `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.
|
|
130
145
|
- `files`: with `--out`, the RAM of each side at the first different checkpoint, `original-<n>.bin` and `rebuild-<n>.bin`.
|
|
@@ -8,7 +8,7 @@ A scenario is one JSON object in a project file.
|
|
|
8
8
|
{
|
|
9
9
|
"name": "player moves left",
|
|
10
10
|
"original": { "program": "original/game.prg", "symbols": "knowledge" },
|
|
11
|
-
"rebuild": { "program": "build/
|
|
11
|
+
"rebuild": { "program": "build/clean.prg", "symbols": "build/symbols/clean.json" },
|
|
12
12
|
"steps": [
|
|
13
13
|
{ "frames": 150 },
|
|
14
14
|
{ "load": true },
|
|
@@ -46,8 +46,9 @@ Before the first step of each side, the script does a hard reset. The CPU stops
|
|
|
46
46
|
| `{ "write": { "address": "seed", "data": "0102" } }` | Write 1 to 4096 bytes into memory. Optional: `space` (`c64` or `drive8`, default `c64`) and `view` (`cpu` or `ram`, default `cpu`). |
|
|
47
47
|
| `{ "registers": { "pc": "start", "a": 0, "flags": { "i": true } } }` | Set registers: `pc`, `a`, `x`, `y`, `sp` and `flags` (`n`, `v`, `b`, `d`, `i`, `z`, `c`). Only `pc` can be a name. |
|
|
48
48
|
| `{ "joystick": { "port": 2, "direction": "left", "fire": true } }` | Set a joystick. `fire` is `false` by default. The joystick stays in this state until the next joystick step. |
|
|
49
|
-
| `{ "type": { "mode": "text", "text": "RUN\n" } }` | Put at most 1024 keys into the keyboard queue of the KERNAL. A program that reads the keyboard hardware does not see them. |
|
|
49
|
+
| `{ "type": { "mode": "text", "text": "RUN\n" } }` | Put at most 1024 keys into the keyboard queue of the KERNAL. A program that reads the keyboard hardware does not see them. Use `press` for that program. |
|
|
50
50
|
| `{ "type": { "mode": "petscii", "bytes": [147] } }` | Put PETSCII codes from 1 to 255 into the keyboard queue of the KERNAL. Use it for keys that mode `text` does not have. |
|
|
51
|
+
| `{ "press": { "keys": "{F1}" } }` | Press keys of the keyboard matrix and RESTORE. A program that reads the keyboard hardware sees them. Each tap holds its keys for 3 frames, then releases them for 3 frames. Optional: `frames` from 1 to 3000. The keys are the same as the keys of a `press` step of a record file. |
|
|
51
52
|
| `{ "runUntil": { "target": { "kind": "address", "address": "main_loop" }, "timeoutFrames": 600 } }` | Run until the CPU gets to an address. |
|
|
52
53
|
| `{ "runUntil": { "target": { "kind": "memory", "address": "game_state", "operator": "eq", "value": 2 }, "timeoutFrames": 600 } }` | Run until a write to the byte makes the comparison with `value` true. `operator` is `eq`, `ne`, `lt`, `lte`, `gt` or `gte`. The run does not stop for a byte that is already true at the start. It also does not stop for a register that the hardware changes, for example `$d012`. For a raster line, use a `raster` target. |
|
|
53
54
|
| `{ "runUntil": { "target": { "kind": "raster", "line": 250 }, "timeoutFrames": 5 } }` | Run until the raster beam gets to a line (0 to 311 for PAL, 0 to 262 for NTSC). Optional: `cycle` from 0 to 64. |
|
|
@@ -62,8 +63,6 @@ A `condition` has the `kind` `register`, `memory` or `raster`. A `register` cond
|
|
|
62
63
|
|
|
63
64
|
`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.
|
|
64
65
|
|
|
65
|
-
A scenario has no `press` step. Only a record file has `press` for keys of the keyboard matrix.
|
|
66
|
-
|
|
67
66
|
Each step except `observe` can have `"side": "original"` 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 original. An `observe` step has no `side`, because it compares both sides.
|
|
68
67
|
|
|
69
68
|
Each side finds a name in its own symbols.
|
|
@@ -74,13 +73,15 @@ An `observe` step has a checkpoint name. A scenario can have each name only one
|
|
|
74
73
|
|
|
75
74
|
| Key | What the script compares |
|
|
76
75
|
|---|---|
|
|
77
|
-
| `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) and `exclude`. The view `ram` reads the RAM under the ROMs and the I/O area. |
|
|
76
|
+
| `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. |
|
|
78
77
|
| `registers` | A list of register names: `pc`, `a`, `x`, `y`, `sp`, `flags`. |
|
|
79
78
|
| `screen` | The screen of the rebuild against the screen of the original. `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. |
|
|
80
79
|
| `vicii` | The VIC-II state: mode, screen address, scroll and colors. |
|
|
81
80
|
| `sprites` | A list of sprite numbers from 0 to 7. The script compares their position, color and flags. |
|
|
82
81
|
|
|
83
|
-
A `tolerance` is the largest permitted difference for each byte. A `mask` has at most 64 rectangles. A `mask` must not cover all of the screen: PAL is 384×272 pixels and NTSC is 384×247 pixels. A scenario can observe the screen at most at 64 checkpoints.
|
|
82
|
+
A `tolerance` is the largest permitted difference for each byte. A screen `mask` has at most 64 rectangles. A `mask` must not cover all of the screen: PAL is 384×272 pixels and NTSC is 384×247 pixels. A scenario can observe the screen at most at 64 checkpoints.
|
|
83
|
+
|
|
84
|
+
The `mask` of a memory object gives the bits that the comparison uses, as hex. It is one byte for all bytes of the range, for example `0f`, or one byte for each byte of the range. The comparison applies the mask first and then the `tolerance`. The colour RAM at $d800 has only 4 bits, and its other 4 bits are not stable. Thus observe the colour RAM with the mask `0f`.
|
|
84
85
|
|
|
85
86
|
`exclude` is a list of bytes in the observed range that the comparison does not include. Each has `address` and a `reason`, for example `{ "address": "$d01e", "reason": "latched sprite collision, not writable" }`. The result lists each excluded byte with its `address` and `reason`.
|
|
86
87
|
|
|
@@ -10,8 +10,9 @@ import { isObject } from "#src/host-client/steps.ts";
|
|
|
10
10
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
11
11
|
import { readProjectFile, writeReported } from "#src/host-client/transfer.ts";
|
|
12
12
|
import { readMemoryInParts, ViceSessionClient } from "#src/host-client/vice-session.ts";
|
|
13
|
-
import { checkSnapshotFile
|
|
13
|
+
import { checkSnapshotFile } from "#src/media.ts";
|
|
14
14
|
import { listed, UsageError } from "#src/script.ts";
|
|
15
|
+
import { snapshotModule } from "#src/vsf.ts";
|
|
15
16
|
import { diffStates, type ChangedRange, type MachineState } from "./diff.ts";
|
|
16
17
|
|
|
17
18
|
type Kind = "snapshot" | "memory" | "observation";
|
|
@@ -58,29 +59,14 @@ function cpuValues(registers: Record<string, unknown>): Record<string, number |
|
|
|
58
59
|
return values;
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
/** The size of the header of a module in a VICE snapshot file: the name (16 bytes), the version (2 bytes) and the size (4 bytes). */
|
|
62
|
-
const MODULE_HEADER = 22;
|
|
63
|
-
const VSF_VERSION = "VICE Version\x1a";
|
|
64
|
-
|
|
65
62
|
/**
|
|
66
63
|
* The data of the C64MEM module of a VICE snapshot file: the data and the
|
|
67
64
|
* direction register of the CPU port, the cartridge lines (2 bytes), then
|
|
68
65
|
* the 64 KiB of RAM. Undefined when the file has no such module.
|
|
69
66
|
*/
|
|
70
67
|
function c64Memory(file: Uint8Array): Buffer | undefined {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
// The magic, the version (2 bytes) and the machine name (16 bytes); a newer VICE adds its own version (8 bytes).
|
|
74
|
-
let at = VSF_SIGNATURE.length + 2 + 16;
|
|
75
|
-
if (bytes.subarray(at, at + VSF_VERSION.length).toString("latin1") === VSF_VERSION) at += VSF_VERSION.length + 8;
|
|
76
|
-
while (at + MODULE_HEADER <= bytes.length) {
|
|
77
|
-
const name = bytes.subarray(at, at + 16).toString("latin1").replace(/\0+$/, "");
|
|
78
|
-
const size = bytes.readUInt32LE(at + 18);
|
|
79
|
-
if (size < MODULE_HEADER) return undefined;
|
|
80
|
-
if (name === "C64MEM") return at + MODULE_HEADER + 4 + 0x10000 <= bytes.length ? bytes.subarray(at + MODULE_HEADER, at + MODULE_HEADER + 4 + 0x10000) : undefined;
|
|
81
|
-
at += size;
|
|
82
|
-
}
|
|
83
|
-
return undefined;
|
|
68
|
+
const data = snapshotModule(Buffer.from(file), "C64MEM")?.data;
|
|
69
|
+
return data !== undefined && data.length >= 4 + 0x10000 ? data.subarray(0, 4 + 0x10000) : undefined;
|
|
84
70
|
}
|
|
85
71
|
|
|
86
72
|
/** The 64 KiB of C64 RAM that a VICE snapshot file holds, also the RAM under the CPU port at $00/$01. Undefined when the file has no C64MEM module. */
|