@henols/c64-re-tools 2.8.0-rc.4 → 2.8.0-rc.6
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 +1 -1
- package/skills/c64-assembler/scripts/assembler.ts +78 -24
- package/skills/c64-docs/scripts/docs.ts +31 -10
- package/skills/c64-knowledge/SKILL.md +11 -7
- package/skills/c64-knowledge/references/batches.md +2 -1
- package/skills/c64-knowledge/references/source-knowledge.md +1 -1
- package/skills/c64-knowledge/scripts/knowledge.ts +46 -29
- package/skills/c64-packer/scripts/packer.ts +9 -2
- package/skills/c64-provenance/SKILL.md +2 -2
- package/skills/c64-provenance/scripts/lib/runtime.ts +45 -10
- package/skills/c64-provenance/scripts/provenance.ts +10 -3
- package/skills/c64-source/references/loader.md +8 -7
- package/skills/c64-source/scripts/lib/loader.ts +4 -111
- package/skills/c64-source/scripts/lib/source.ts +3 -1
- package/skills/c64-source/scripts/source.ts +49 -78
- package/skills/c64-static-analysis/SKILL.md +2 -2
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +56 -4
- package/skills/c64-static-analysis/scripts/lib/idioms.ts +92 -42
- package/skills/c64-static-analysis/scripts/static-analysis.ts +32 -21
- package/skills/c64-testing/SKILL.md +7 -0
- package/skills/c64-testing/scripts/lib/play.ts +8 -7
- package/skills/c64-testing/scripts/lib/recording.ts +278 -27
- package/skills/c64-testing/scripts/lib/replay.ts +9 -8
- package/skills/c64-testing/scripts/lib/runs.ts +5 -1
- package/skills/c64-testing/scripts/lib/scenario.ts +4 -0
- package/skills/c64-testing/scripts/testing.ts +30 -11
- package/skills/c64-unpacker/SKILL.md +13 -11
- package/skills/c64-unpacker/scripts/lib/loads.ts +10 -5
- package/skills/c64-unpacker/scripts/lib/machine.ts +163 -3
- package/skills/c64-unpacker/scripts/lib/stages.ts +13 -6
- package/skills/c64-unpacker/scripts/unpacker.ts +34 -15
- package/skills/emulator/SKILL.md +2 -2
- package/src/c64.ts +21 -0
- package/src/host/vice/adapter.ts +2 -1
- package/src/host/vice/chips.ts +6 -9
- package/src/host/vice/session.ts +2 -2
- package/src/host-client/image.ts +40 -4
- package/src/host-client/tools.ts +1 -1
- package/src/host-client/transfer.ts +48 -26
- package/src/host-client/vice-session.ts +15 -0
- package/src/knowledge/database.ts +72 -19
- package/src/knowledge/import.ts +32 -7
- package/src/knowledge/join.ts +50 -2
- package/src/knowledge/names.ts +2 -2
- package/src/knowledge/program.ts +103 -24
- package/src/knowledge/schema.ts +6 -0
- package/src/knowledge/start-screen.ts +57 -7
- package/src/knowledge/write.ts +20 -13
- package/src/loader.ts +101 -33
- package/src/mcp/output.ts +13 -12
- package/src/mcp/server.ts +33 -22
- package/src/mcp/tools/debug.ts +21 -24
- package/src/mcp/tools/media.ts +27 -27
- package/src/mcp/tools/memory.ts +13 -17
- package/src/mcp/tools/video.ts +10 -12
- package/src/native/c64run.ts +39 -1
- package/src/native/decompiler/analyze.ts +1 -1
- package/src/native/dxa.ts +2 -2
- package/src/native/types.ts +26 -7
- package/src/opcodes.ts +5 -0
- package/src/program-code.ts +4 -2
- package/src/project.ts +224 -71
- package/src/protocol/vice.ts +5 -3
- package/src/script.ts +60 -15
- package/{skills/c64-source/scripts/lib → src}/stage.ts +142 -11
- package/tools/c64run.c +18 -5
package/package.json
CHANGED
|
@@ -136,7 +136,7 @@ Assembles the source and writes the program to `--out`, or to `build/<name>.prg`
|
|
|
136
136
|
- `different`, with `differences` and `firstDifference`. `firstDifference` gives `address`, and the byte of the build (`built`) and of the reference (`reference`), each as `$` and two hex digits. It is the first different byte outside the leftovers that the build leaves out. When all different bytes are in these leftovers, the segment has no `firstDifference`.
|
|
137
137
|
- `not covered`, with `uncovered`: the build does not hold all bytes of the segment.
|
|
138
138
|
- A segment in `compare.segments` can also have `leftovers`. These are the leftovers that the build leaves out, where a byte is different or not in the build. Each item has `start`, `end`, `file` (the leftover file, relative to the source root) and `differences`. `differences` and `uncovered` of the segment also count these bytes.
|
|
139
|
-
- `loader`: only with `--switch`, the entry `main.asm` and a `loader.asm` in the source root. It is the loader program of these switch values, with `out`, `bytes` and `sha256`. `symbolsFile` is its symbols file. `packed` gives `packedBytes` and `unpackedBytes` of the packed form. `verified` is always `false`, because no check of the loader program runs. When the script cannot make the loader program, `loader` holds only `written`, which is `false`, and `reason`.
|
|
139
|
+
- `loader`: only with `--switch`, the entry `main.asm` and a `loader.asm` in the source root. It is the loader program of these switch values, with `out`, `bytes` and `sha256`. `symbolsFile` is its symbols file. `packed` gives `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, `stage` gives the `space` of the stage, and `packedBytes` and `unpackedBytes` of the loader program with the start screen. `verified` is always `false`, because no check of the loader program runs. When the script cannot make the loader program, `loader` holds only `written`, which is `false`, and `reason`.
|
|
140
140
|
|
|
141
141
|
Do as the result tells:
|
|
142
142
|
|
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
// values. A generated source with loader.asm then also gets its loader
|
|
6
6
|
// program with the same values: the build of loader.asm in the plain form,
|
|
7
7
|
// and in the packed form the pack of the build of main.asm with the build of
|
|
8
|
-
// loader.asm, the copier, as generate packs it.
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// loader.asm, the copier, as generate packs it. A start screen of a captured
|
|
9
|
+
// stage then wraps that pack in the show stage, with the bytes of the stage
|
|
10
|
+
// from start_screen_stage.asm of the source, as generate wraps it. No check
|
|
11
|
+
// of that loader runs. When the knowledge or the builds do not permit the
|
|
12
|
+
// loader, the build writes the program of main.asm and no loader program,
|
|
13
|
+
// and tells why.
|
|
11
14
|
|
|
12
15
|
import { posix } from "node:path";
|
|
13
16
|
|
|
@@ -17,14 +20,15 @@ import { isRefusal, Refusal } from "#src/errors.ts";
|
|
|
17
20
|
import { readSourceTree, writeReported } from "#src/host-client/transfer.ts";
|
|
18
21
|
import { withRead } from "#src/knowledge/database.ts";
|
|
19
22
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
20
|
-
import { releaseImage, requireProgram } from "#src/knowledge/program.ts";
|
|
21
|
-
import { currentStartScreen, listSwitches, releaseLabeled } from "#src/knowledge/read.ts";
|
|
23
|
+
import { releaseImage, requireProgram, startScreenKey } from "#src/knowledge/program.ts";
|
|
24
|
+
import { currentStartScreen, listSwitches, releaseLabeled, type StartScreenRow } from "#src/knowledge/read.ts";
|
|
22
25
|
import { LEFTOVER_FOLDER, LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
|
|
23
|
-
import { checkPackedBuilds, COPIER_SOURCE, leftoverRange, loaderSymbols, packedRanges, packLoader, type PackedLoader } from "#src/loader.ts";
|
|
26
|
+
import { checkPackedBuilds, COPIER_SOURCE, leftoverRange, loaderSymbols, packedRanges, packLoader, type PackedLoader, settingsLines } from "#src/loader.ts";
|
|
24
27
|
import { assemble, showSymbol, symbolsFileText } from "#src/native/acme.ts";
|
|
25
28
|
import { EXOMIZER, findTool } from "#src/native/discover.ts";
|
|
26
29
|
import { localToolContext } from "#src/native/local.ts";
|
|
27
30
|
import type { AcmeParams, AssembledSymbol } from "#src/native/types.ts";
|
|
31
|
+
import { type PackedStage, packStage, STAGE_FILE, stageFileMismatch, stageOfBuild } from "#src/stage.ts";
|
|
28
32
|
import { listed as listedItems, OPTIONS, reply, runScript, UsageError } from "#src/script.ts";
|
|
29
33
|
import { compareBuild, type LeftOutLeftover, type Reference } from "#src/compare.ts";
|
|
30
34
|
|
|
@@ -64,12 +68,49 @@ function refusalOf(work: () => void): string | undefined {
|
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
71
|
+
/** The build of a file of the source, with these switch values. Refuses with its first diagnostic. */
|
|
72
|
+
async function assembleSource(params: AcmeParams, contents: Buffer[], file: string): Promise<{ program: Buffer; symbols: AssembledSymbol[] }> {
|
|
73
|
+
const { result, attachments } = await assemble({ ...params, entrySource: file }, contents, localToolContext());
|
|
74
|
+
if (!result.assembled) {
|
|
75
|
+
const [first] = result.diagnostics;
|
|
76
|
+
const where = first === undefined ? "" : `: ${first.file ?? file}${first.line === undefined ? "" : ` line ${first.line}`}: ${first.message}`;
|
|
77
|
+
throw new Refusal("operation-failed", `${file} does not assemble with these switch values${where}. Generate the source with the loader again. If it still does not assemble, give this message to the user.`);
|
|
78
|
+
}
|
|
79
|
+
return { program: attachments![0]!, symbols: result.symbols ?? [] };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The show stage of a start screen from a captured stage around the packed
|
|
84
|
+
* loader of these switch values, as generate builds it. The bytes of the stage
|
|
85
|
+
* do not depend on the switch values: they come from the build of
|
|
86
|
+
* start_screen_stage.asm of the source, and the show stage is planned again
|
|
87
|
+
* around this packed loader. Gives why the build gets no loader when the
|
|
88
|
+
* stage does not fit or the file does not hold its bytes.
|
|
89
|
+
*/
|
|
90
|
+
async function showStage(packed: PackedLoader, row: StartScreenRow, source: { params: AcmeParams; contents: Buffer[]; stageIndex: number; settings: string[]; key: string }): Promise<PackedStage | string> {
|
|
91
|
+
const { params, contents, stageIndex } = source;
|
|
92
|
+
const generated = await assembleSource(params, contents, STAGE_FILE);
|
|
93
|
+
// Each plan of the show stage builds with the other files of the source, and its text in place of start_screen_stage.asm.
|
|
94
|
+
const assembleStage = (text: string) => {
|
|
95
|
+
const bytes = Buffer.from(text, "utf8");
|
|
96
|
+
const files = params.files.map((file, index) => (index === stageIndex ? { ...file, size: bytes.length } : file));
|
|
97
|
+
return assembleSource({ ...params, files }, contents.map((content, index) => (index === stageIndex ? bytes : content)), STAGE_FILE);
|
|
98
|
+
};
|
|
99
|
+
try {
|
|
100
|
+
return await packStage(packed.program, stageOfBuild(generated.program, generated.symbols, row.colourRam === true), row, { settings: source.settings, header: [], key: source.key }, assembleStage, localToolContext());
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (!isRefusal(error) || error.code !== "invalid-input") throw error;
|
|
103
|
+
return `The show stage of the start screen from ${row.stage} cannot be built. ${error.message}`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
67
107
|
/**
|
|
68
108
|
* What a generated source needs from the knowledge of the space, in one read:
|
|
69
109
|
* the default of each switch (the knowledge gives them, the start screen is in
|
|
70
110
|
* and the leftovers are out), and for the packed form, given the leftover
|
|
71
|
-
* ranges of the source, the loaded ranges or why the build gets no loader (
|
|
72
|
-
* start screen of a captured stage,
|
|
111
|
+
* ranges of the source, the loaded ranges or why the build gets no loader (no
|
|
112
|
+
* program in the knowledge), and a start screen of a captured stage, whose
|
|
113
|
+
* show stage holds the packed loader.
|
|
73
114
|
*/
|
|
74
115
|
function generatedKnowledge(space: Space, leftovers: readonly AddressRange[] | undefined) {
|
|
75
116
|
return withRead((db) => {
|
|
@@ -79,9 +120,11 @@ function generatedKnowledge(space: Space, leftovers: readonly AddressRange[] | u
|
|
|
79
120
|
leftovers === undefined
|
|
80
121
|
? undefined
|
|
81
122
|
: refusalOf(() => {
|
|
82
|
-
loaded = packedRanges(requireProgram(db, space).segments, leftovers
|
|
123
|
+
loaded = packedRanges(requireProgram(db, space).segments, leftovers);
|
|
83
124
|
});
|
|
84
|
-
|
|
125
|
+
const startScreen = leftovers === undefined ? undefined : currentStartScreen(db, space);
|
|
126
|
+
const stageScreen = startScreen?.stage === undefined ? undefined : { row: startScreen, key: startScreenKey(db, startScreen) };
|
|
127
|
+
return { defaults, loaded, noLoader, stageScreen };
|
|
85
128
|
});
|
|
86
129
|
}
|
|
87
130
|
|
|
@@ -170,6 +213,16 @@ await runScript({
|
|
|
170
213
|
const loaded = generated?.loaded;
|
|
171
214
|
// Why the build writes no loader program.
|
|
172
215
|
let noLoader = generated?.noLoader;
|
|
216
|
+
// A start screen of a captured stage: the show stage of the source holds its bytes.
|
|
217
|
+
const stageKnown = generated?.stageScreen;
|
|
218
|
+
const stageScreen = stageKnown?.row;
|
|
219
|
+
if (stageKnown !== undefined && noLoader === undefined) {
|
|
220
|
+
const { row, key } = stageKnown;
|
|
221
|
+
const stageIndex = inSource(STAGE_FILE);
|
|
222
|
+
if (stageIndex < 0) noLoader = `The start screen is of the captured stage ${row.stage}, and ${sourceRoot} has no ${STAGE_FILE} with its bytes. Generate the source with the loader.`;
|
|
223
|
+
// A file of another start screen, or of an earlier capture or patch of the stage, has other bytes.
|
|
224
|
+
else noLoader = stageFileMismatch(textOf(stageIndex), key, sourceRoot, row.stage!);
|
|
225
|
+
}
|
|
173
226
|
// The toolkit never installs a tool: without Exomizer the build refuses by name before ACME runs.
|
|
174
227
|
if (packedForm && noLoader === undefined) findTool(EXOMIZER);
|
|
175
228
|
|
|
@@ -182,25 +235,25 @@ await runScript({
|
|
|
182
235
|
const shown = shownOf(result.symbols!);
|
|
183
236
|
|
|
184
237
|
// The loader is made before a file is written: a refusal writes nothing.
|
|
185
|
-
let loader: { program: Buffer; symbols: AssembledSymbol[]; packed?: PackedLoader } | undefined;
|
|
238
|
+
let loader: { program: Buffer; symbols: AssembledSymbol[]; packed?: PackedLoader; stage?: { space: string } & Pick<PackedLoader, "packedBytes" | "unpackedBytes"> } | undefined;
|
|
186
239
|
if (loaderIndex >= 0 && noLoader === undefined) {
|
|
187
|
-
const copier = await
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const where = first === undefined ? "" : `: ${first.file ?? LOADER_FILE}${first.line === undefined ? "" : ` line ${first.line}`}: ${first.message}`;
|
|
191
|
-
throw new Refusal("operation-failed", `${LOADER_FILE} does not assemble with these switch values${where}. Generate the source with the loader again. If it still does not assemble, give this message to the user.`);
|
|
192
|
-
}
|
|
193
|
-
const copierBuild = copier.attachments![0]!;
|
|
194
|
-
const symbols = loaderSymbols(result.symbols!, copier.result.symbols!);
|
|
195
|
-
if (loaded === undefined) loader = { program: copierBuild, symbols };
|
|
240
|
+
const copier = await assembleSource(params, contents, LOADER_FILE);
|
|
241
|
+
const symbols = loaderSymbols(result.symbols!, copier.symbols);
|
|
242
|
+
if (loaded === undefined) loader = { program: copier.program, symbols };
|
|
196
243
|
else {
|
|
197
|
-
const at = copier.
|
|
244
|
+
const at = copier.symbols.find((symbol) => symbol.name === COPIER_SOURCE);
|
|
198
245
|
if (at?.kind !== "address") throw new Refusal("invalid-input", `${LOADER_FILE} has no label ${COPIER_SOURCE} at its copier. Generate the source with the loader again.`);
|
|
199
246
|
const packedFrom = loaded;
|
|
200
|
-
noLoader = refusalOf(() => checkPackedBuilds(built,
|
|
247
|
+
noLoader = refusalOf(() => checkPackedBuilds(built, copier.program, copier.symbols, packedFrom));
|
|
201
248
|
if (noLoader === undefined) {
|
|
202
|
-
const packed = await packLoader(built,
|
|
203
|
-
loader = { program: packed.program, symbols, packed };
|
|
249
|
+
const packed = await packLoader(built, copier.program, { loaded: packedFrom, copier: at.address }, localToolContext());
|
|
250
|
+
if (stageScreen === undefined) loader = { program: packed.program, symbols, packed };
|
|
251
|
+
else {
|
|
252
|
+
const settings = settingsLines({ switches: inSource("switches.asm") >= 0, config: config >= 0 });
|
|
253
|
+
const stage = await showStage(packed, stageScreen, { params, contents, stageIndex: inSource(STAGE_FILE), settings, key: stageKnown!.key });
|
|
254
|
+
if (typeof stage === "string") noLoader = stage;
|
|
255
|
+
else loader = { program: stage.packed.program, symbols: loaderSymbols(result.symbols!, copier.symbols, stage.symbols), packed, stage: { space: stageScreen.stage!, packedBytes: stage.packed.packedBytes, unpackedBytes: stage.packed.unpackedBytes } };
|
|
256
|
+
}
|
|
204
257
|
}
|
|
205
258
|
}
|
|
206
259
|
}
|
|
@@ -245,6 +298,7 @@ await runScript({
|
|
|
245
298
|
...writeReported(loaderPath, loader.program),
|
|
246
299
|
symbolsFile: writeReported(symbolsPath(loaderPath), symbolsFileText(shownOf(loader.symbols))),
|
|
247
300
|
...(loader.packed === undefined ? {} : { packed: { packedBytes: loader.packed.packedBytes, unpackedBytes: loader.packed.unpackedBytes } }),
|
|
301
|
+
...(loader.stage === undefined ? {} : { stage: loader.stage }),
|
|
248
302
|
verified: false,
|
|
249
303
|
},
|
|
250
304
|
}),
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// every link and image of the pages.
|
|
7
7
|
|
|
8
8
|
import { existsSync, readdirSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
9
|
-
import { basename, join, posix } from "node:path";
|
|
9
|
+
import { basename, isAbsolute, join, posix } from "node:path";
|
|
10
10
|
import type { DatabaseSync } from "node:sqlite";
|
|
11
11
|
|
|
12
12
|
import { formatC64Address, formatC64RangeFields, inRanges } from "#src/c64.ts";
|
|
@@ -19,7 +19,7 @@ import { changedEvidence, type EvidenceChange } from "#src/knowledge/evidence.ts
|
|
|
19
19
|
import { programImage } from "#src/knowledge/program.ts";
|
|
20
20
|
import { listComments, listModules, listReferences, listRegions, listSymbols, sourceRevision } from "#src/knowledge/read.ts";
|
|
21
21
|
import { compareText } from "#src/knowledge/text.ts";
|
|
22
|
-
import { groupOf, KNOWLEDGE_TEXT_DIRECTORY as TEXT_DIRECTORY, namedGroup, PROJECT_DIRECTORY, projectRoot, resolveProjectFile, resolveProjectPath, type ProjectGroup } from "#src/project.ts";
|
|
22
|
+
import { groupOf, KNOWLEDGE_TEXT_DIRECTORY as TEXT_DIRECTORY, namedGroup, PROJECT_DIRECTORY, projectRelative, projectRoot, resolveProjectFile, resolveProjectPath, type ProjectGroup } from "#src/project.ts";
|
|
23
23
|
import { GENERATED_MARK, referenceStamp } from "#src/reference-pages.ts";
|
|
24
24
|
import { listed, OPTIONS, reply, runScript, UsageError, type Call, type Reply } from "#src/script.ts";
|
|
25
25
|
import { checkLinks, linkPage, type Files, type LinkContext, type Names, type Problem } from "./lib/links.ts";
|
|
@@ -50,15 +50,16 @@ function oldFiles(out: string, directory: string): string[] {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
function generate(call: Call): Reply {
|
|
53
|
-
|
|
54
|
-
const
|
|
53
|
+
// One spelling for each folder, relative to the project folder: the pages link by these paths, also when the paths are given absolute.
|
|
54
|
+
const source = projectRelative(call.subject(0)) || ".";
|
|
55
|
+
const out = projectRelative(call.string("out")!) || ".";
|
|
55
56
|
// The files of an earlier run are deleted: only in a folder that is inside the project, also after its symbolic links.
|
|
56
57
|
let directory = resolveProjectPath(out);
|
|
57
58
|
if (existsSync(directory)) {
|
|
58
59
|
try {
|
|
59
60
|
directory = resolveProjectFile(out);
|
|
60
61
|
} catch {
|
|
61
|
-
throw new UsageError(`--out must be a path
|
|
62
|
+
throw new UsageError(`--out must be a path inside the project folder, also through symbolic links, not ${out}`);
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
const map = readSourceMap(source);
|
|
@@ -233,20 +234,40 @@ function link(call: Call): Reply {
|
|
|
233
234
|
/** A .md entry of a directory that is a symbolic link to no file, or to a file outside the folder of the run. */
|
|
234
235
|
const unreadable = (page: string): Problem => ({ page, line: 1, kind: "missing-file", message: `${shown(page)} is a symbolic link to no file or to a file outside ${folder}.` });
|
|
235
236
|
|
|
236
|
-
|
|
237
|
+
// An absolute page becomes relative to the folder of the pages, also through a symbolic link, so that each page has one spelling.
|
|
238
|
+
const fromBase = (path: string) => {
|
|
239
|
+
if (!isAbsolute(path)) return path;
|
|
240
|
+
try {
|
|
241
|
+
return projectRelative(path, join(root, scope.base)) || ".";
|
|
242
|
+
} catch {
|
|
243
|
+
throw new UsageError(`<page> must be a path inside ${folder}, relative to it or absolute, not ${path}`);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
const spelled = new Map(call.subjects.map((path) => [posix.normalize(fromBase(path)), path]));
|
|
247
|
+
const given = [...spelled.keys()];
|
|
237
248
|
const pagesGiven = given.map(toRun);
|
|
238
249
|
given.forEach((path, index) => {
|
|
239
|
-
if (!within(pagesGiven[index]!, scope.base) || !files.inside(pagesGiven[index]!)) throw new UsageError(`<page> must be a path
|
|
250
|
+
if (!within(pagesGiven[index]!, scope.base) || !files.inside(pagesGiven[index]!)) throw new UsageError(`<page> must be a path inside ${folder}, relative to it or absolute, not ${spelled.get(path)}`);
|
|
240
251
|
});
|
|
241
252
|
given.forEach((path, index) => {
|
|
242
253
|
const page = pagesGiven[index]!;
|
|
243
254
|
if (!page.endsWith(".md") && files.exists(page) && !isDirectory(page, root)) throw new UsageError(`<pages> takes .md files and directories, not ${path}`);
|
|
244
255
|
});
|
|
245
256
|
const directories = pagesGiven.filter((path) => !path.endsWith(".md") || isDirectory(path, root));
|
|
246
|
-
// --source and --reference are relative to each project folder: the projects of a group have the same layout.
|
|
257
|
+
// --source and --reference are relative to each project folder: the projects of a group have the same layout. An absolute path names a folder in one of them.
|
|
258
|
+
const inMember = (value: string) => {
|
|
259
|
+
for (const member of members) {
|
|
260
|
+
try {
|
|
261
|
+
return projectRelative(value, member.root) || ".";
|
|
262
|
+
} catch {
|
|
263
|
+
// In another project of the group, or in none.
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return value;
|
|
267
|
+
};
|
|
247
268
|
const inProjectFolder = (name: string, value: string) => {
|
|
248
|
-
const path = posix.normalize(value.replaceAll("\\", "/"));
|
|
249
|
-
if (posix.isAbsolute(path) || /^[A-Za-z]:/.test(path) || path === ".." || path.startsWith("../")) throw new UsageError(`--${name} must be a path
|
|
269
|
+
const path = posix.normalize((isAbsolute(value) ? inMember(value) : value).replaceAll("\\", "/"));
|
|
270
|
+
if (posix.isAbsolute(path) || /^[A-Za-z]:/.test(path) || path === ".." || path.startsWith("../")) throw new UsageError(`--${name} must be a path inside the project folder, relative to it or absolute, not ${value}`);
|
|
250
271
|
return path;
|
|
251
272
|
};
|
|
252
273
|
const source = inProjectFolder("source", call.string("source")!);
|
|
@@ -39,7 +39,7 @@ Commit the folder `.c64-re-tools/knowledge/` of the project with git.
|
|
|
39
39
|
| Record the verdict of one comment of a check | `verdict 4711 '$2100' wrong --class callers --why 'JSR at $1f00 calls it too' --text 'Moves the player.'` |
|
|
40
40
|
| Write all knowledge to one file | `export --out .c64-re-tools/local/knowledge.json` |
|
|
41
41
|
| Find what the knowledge holds of the program | `program` |
|
|
42
|
-
| Put a captured program into the knowledge | `image .c64-re-tools/local/capture/image.json` |
|
|
42
|
+
| Put a captured program into the knowledge | `image .c64-re-tools/local/capture/releases/game/image.json` |
|
|
43
43
|
| Put a PRG into the knowledge | `image releases/game.prg` |
|
|
44
44
|
| Add the coverage of runs | `coverage .c64-re-tools/local/runs/rooms/room0.bin` |
|
|
45
45
|
| Add the coverage of a recording | `coverage tests/recordings/walk` |
|
|
@@ -63,6 +63,7 @@ Commit the folder `.c64-re-tools/knowledge/` of the project with git.
|
|
|
63
63
|
| Write a macro | `macro inc16 --params dst --body-file inc16.asm` |
|
|
64
64
|
| Write instructions as one use of a macro | `use '$1005-$100a' inc16 --args ptr` |
|
|
65
65
|
| Do many writes as one revision | `apply .c64-re-tools/local/batch.json` |
|
|
66
|
+
| Check the batch of one agent | `join batch.json` |
|
|
66
67
|
| Show the batches of parallel agents as one list of writes | `join a.json b.json` |
|
|
67
68
|
| Write the batches of parallel agents as one revision | `join a.json b.json --apply` |
|
|
68
69
|
| Read the history of an address or a name | `history '$2100'` |
|
|
@@ -124,7 +125,7 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
124
125
|
| `--why <text>` | `verdict` | With `wrong`: the evidence, with the addresses and the instructions. With `unsure`: the run that can show the claim. With `correct`: the evidence. It is optional. |
|
|
125
126
|
| `--text <text>` | `verdict` | With `wrong`: the correct comment. |
|
|
126
127
|
| `--name <name>` | `verdict` | With `wrong`: the correct name at the address. |
|
|
127
|
-
| `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing`, `join`, `checks` | The most items in each list of the body. The default is 50. The counts are always complete. |
|
|
128
|
+
| `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing`, `coverage`, `join`, `checks` | The most items in each list of the body. The default is 50. The counts are always complete. |
|
|
128
129
|
| `--kind <kind>` | `symbols`, `rename` | The symbol kind: `label`, `routine`, `variable`, `data` or `vector`. A read gives all kinds by default. A new symbol without `--kind` is a `label`. A `rename` without `--kind` keeps the kind of the symbol. |
|
|
129
130
|
| `--kind <kind>` | `references` | Only references of this kind: `call`, `jump`, `read`, `write`, `reference` or `pointer`. |
|
|
130
131
|
| `--kind <kind>` | `switch` | Necessary. The switch kind: `protection`, `trainer`, `cheat`, `crack`, `fix` or `change`. |
|
|
@@ -235,7 +236,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
235
236
|
### `releases`
|
|
236
237
|
|
|
237
238
|
- `body.releases` lists the releases, the base release first. Each item has `label`, `base`, `define`, `file` and `sha256`. `define` is the assembler define that builds the release.
|
|
238
|
-
- `file` is the path of the file of the release, and `sha256` is the SHA-256 of that file. Use them for the facts of a release, for example in a README. Do not calculate a SHA-256 yourself.
|
|
239
|
+
- `file` is the path of the program file of the release, and `sha256` is the SHA-256 of that file. For a release from the `image.json` of a capture, this file is the program file that the capture ran. This file can hold packed bytes, or a disk with more parts. Use them for the facts of a release, for example in a README. Do not calculate a SHA-256 yourself.
|
|
239
240
|
|
|
240
241
|
### `macros`
|
|
241
242
|
|
|
@@ -269,7 +270,8 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
269
270
|
- A line comment is a line of its own before its line, for example `; Draws the room.`.
|
|
270
271
|
- The ACME line is the instruction with the names of its target. An operand expression of the knowledge replaces the operand. A table of addresses or words shows its values as `!word` lines, with the name of each target. A split table and the other bytes show as `!byte` lines.
|
|
271
272
|
- The names are the names of the generated source. A platform name of a ROM shows only when the program uses that ROM. A line in the I/O area (`$D000-$DFFF`) gets no platform name, because that name is the name of the register and not of the RAM. A target inside a data region shows as `<name>+<offset>` only when a symbol is at the start of the region.
|
|
272
|
-
-
|
|
273
|
+
- The lines show the bytes of the segments. When the knowledge has the entry state of a capture, the lines also show the bytes of the entry state at $0002-$03ff. The analyzers read the same bytes.
|
|
274
|
+
- A range outside these bytes has no lines. Then the `hint` gives the ranges that have bytes.
|
|
273
275
|
- With `--code`, `lines` has only the instructions of the code regions and their line comments.
|
|
274
276
|
- With `--out`, the text file has the lines, one on each line. `body.lines` is the number of lines, and the body has `out`, `bytes` and `sha256` of the text file.
|
|
275
277
|
- Use `listing` in place of your own disassembler. To find the targets of a table, classify the table with its type. Then read its listing. Do not decode the bytes of a table yourself.
|
|
@@ -340,7 +342,7 @@ Errors of this group:
|
|
|
340
342
|
| `addresses`, `addresses-split` | A table of addresses: one table of 16-bit values, or a low-byte table and then a high-byte table. |
|
|
341
343
|
| `rts-addresses`, `rts-addresses-split` | The same, with each value the target minus 1, for a PHA, PHA, RTS dispatch. |
|
|
342
344
|
| `jumps` | A table of `JMP abs` instructions. Each 3-byte entry is an entry point. It is code. |
|
|
343
|
-
| `workspace` | RAM that the program writes at run time.
|
|
345
|
+
| `workspace` | RAM that the program writes at run time. The check of the source compares these bytes in each release too. When a release has other bytes here, record them with `patch --from-release`. Or capture that release again, and exclude the bytes that the program does not read. |
|
|
344
346
|
| `unused` | Bytes that nothing executes or reads. |
|
|
345
347
|
| `dual-use` | Code at one time, and data or a vector at another time. No analyzer finding conflicts with it. |
|
|
346
348
|
|
|
@@ -401,7 +403,7 @@ An operand expression tells the generated source how to write the operand of one
|
|
|
401
403
|
|
|
402
404
|
### `release <label>`
|
|
403
405
|
|
|
404
|
-
- `body.release` gives the release, with its `define`, `file` and `sha256`. `body.bytes` gives the number of bytes of the
|
|
406
|
+
- `body.release` gives the release, with its `define`, `file` and `sha256`. `body.bytes` gives the number of bytes of the release.
|
|
405
407
|
- See "Releases" of `<skill>/references/source-knowledge.md`.
|
|
406
408
|
|
|
407
409
|
### `unrelease <label>`
|
|
@@ -461,6 +463,7 @@ An operand expression tells the generated source how to write the operand of one
|
|
|
461
463
|
|
|
462
464
|
- `<map>` is a 64 KiB coverage map of a run, or a recording folder. For a recording folder, the script takes the coverage map of the recording.
|
|
463
465
|
- `body` holds `revision`, `imported`, `replaced`, `known`, `added` and `removed`. `imported` lists the new maps. `replaced` lists the new maps that replace an earlier map of the same path. `known` lists the maps that the space has already. `added` and `removed` count the ranges of accesses that the coverage gets and loses.
|
|
466
|
+
- `body.commentsToCheck` lists the comments at the addresses that the runs now execute or no longer execute. `executed` is `true` when the runs now execute the address. The list is there only when it has comments. Read what each comment tells about the runs. Correct each comment that is no longer true.
|
|
464
467
|
- When `added` or `removed` is not 0, do as `hint` tells.
|
|
465
468
|
- After you record a run again into the same place, put its map into the knowledge again. See "Maps and their paths" of `<skill>/references/coverage.md`.
|
|
466
469
|
|
|
@@ -473,7 +476,8 @@ An operand expression tells the generated source how to write the operand of one
|
|
|
473
476
|
### `join <batch>...`
|
|
474
477
|
|
|
475
478
|
- `join` joins the batches of agents that name the program at the same time. See "Batches of parallel agents" of `<skill>/references/batches.md`.
|
|
476
|
-
-
|
|
479
|
+
- `join` also takes one batch. Then `writes` shows the writes of that batch, and `join` checks the batch as it checks more batches.
|
|
480
|
+
- Without `--apply`, `join` writes no knowledge. But it does all the checks of `--apply`. When the knowledge refuses a write, `join` gives the same error as with `--apply`. `body` holds `writes`, `repeated` and `choices`. `writes` lists the joined writes. `choices` lists each place where the batches gave different values, with the value that stays.
|
|
477
481
|
- Examine `choices` and `writes`. `nextAction` is the same `join` with `--apply`. Run it when the choices agree with your task.
|
|
478
482
|
- With `--apply`, `join` writes the joined writes as one revision, or nothing when the knowledge refuses one write. Then `body` holds `revision`, `writes`, `replaced`, `repeated` and `choices`, as for `apply`.
|
|
479
483
|
- When one name or one module file is at two addresses, `join` writes nothing and gives the error `conflict`. Correct the batches that the `error` names. Then do `join` again.
|
|
@@ -43,6 +43,7 @@ When more agents name the program at the same time, give each agent one range of
|
|
|
43
43
|
`join` makes one list of writes from the batches:
|
|
44
44
|
|
|
45
45
|
- At an address in the owner range of a batch, the name, the comment, the operand and the module of that batch stay. At an address that no batch owns, the first batch in the command stays.
|
|
46
|
-
- A batch can give an address a name that `join` replaces. Then `join` also replaces that name in the operand expressions
|
|
46
|
+
- A batch can give an address a name that `join` replaces. Then `join` also replaces that name in the operand expressions, the macro arguments, the patch code, the macro bodies and the comments of that batch. In a comment, `join` replaces only the full word. For example, a replaced `x_pos` does not change `x_pos_hi`.
|
|
47
|
+
- A name with no underscore, no digit and no capital letter after a small letter can be an English word, for example `score`. `join` does not replace this name in a comment, because the comment can use the word as text.
|
|
47
48
|
- The regions of the owner come after the regions of the other batches. Thus the regions of the owner stay where they overlap.
|
|
48
49
|
- A name from a batch stays when another batch removes the symbol at that address.
|
|
@@ -7,7 +7,7 @@ This file gives the rules of the releases, the switches, the patches, the macros
|
|
|
7
7
|
A release is one version of the program, for example the original or a crack. Record each release with `release <label> --file <file>`.
|
|
8
8
|
|
|
9
9
|
- A label is upper case, for example `FIRESTAR`, `TBC` or `V2`.
|
|
10
|
-
- `--file` is a PRG or the `image.json` of a capture. The project knowledge keeps the bytes of the release, the path of the file and
|
|
10
|
+
- `--file` is a PRG or the `image.json` of a capture. The project knowledge keeps the bytes of the release, and the path and the SHA-256 of the program file. For an `image.json`, the bytes come from the capture, and the program file is the file that the capture ran. After the write, the project does not need the file. A file can stay in `.c64-re-tools/local/`.
|
|
11
11
|
- The base release is the release whose bytes are the program of the knowledge. Record it with `--base`. The script refuses `--base` when the segments or the bytes of the file are not the program.
|
|
12
12
|
- A space has one base release. Record the base release before the first switch.
|
|
13
13
|
- To change the bytes of a release, record the release again with its new file.
|
|
@@ -10,15 +10,15 @@ import type { DatabaseSync } from "node:sqlite";
|
|
|
10
10
|
import { type AddressRange, formatC64Address, formatC64Range, formatC64RangeFields, inRanges, rangesOverlap, REFERENCE_KINDS } from "#src/c64.ts";
|
|
11
11
|
import { Refusal } from "#src/errors.ts";
|
|
12
12
|
import { IO_RAM } from "#src/host-client/coverage.ts";
|
|
13
|
-
import { readImage } from "#src/host-client/image.ts";
|
|
13
|
+
import { checkedProgramCitation, readImage } from "#src/host-client/image.ts";
|
|
14
14
|
import { readProjectFile, readProjectJson, writeReported } from "#src/host-client/transfer.ts";
|
|
15
15
|
import { CONFLICT_RULES, conflicts, type Conflict } from "#src/knowledge/conflicts.ts";
|
|
16
|
-
import { withRead, withWrite } from "#src/knowledge/database.ts";
|
|
16
|
+
import { withRead, withTrial, withWrite } from "#src/knowledge/database.ts";
|
|
17
17
|
import { OPERAND_SELECTS, operandText, type OperandSelect } from "#src/knowledge/expression.ts";
|
|
18
18
|
import { historyAt, historyNamed, historyOfMacro, historyOfSwitch, revision, revisionCounts, revisionNote, revisions, type HistoryEntry } from "#src/knowledge/history.ts";
|
|
19
19
|
import { joinBatches, type Batch, type JoinChoice, type JoinClash } from "#src/knowledge/join.ts";
|
|
20
20
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
21
|
-
import { addCoverage, coverageAccess, coverageRangeCounts, memoryRows, operandImages as programImages, programCoverage, programImage, releaseCode, requireProgram, setImage, type ImageRequest, type ProgramImage } from "#src/knowledge/program.ts";
|
|
21
|
+
import { addCoverage, coverageAccess, coverageRangeCounts, entryMemory, isProgram, memoryRows, operandImages as programImages, programCoverage, programImage, releaseCode, requireProgram, setImage, type ImageRequest, type ProgramImage } from "#src/knowledge/program.ts";
|
|
22
22
|
import { coloursOfCapture, startScreenOfCapture, startScreenOfStage } from "#src/knowledge/start-screen.ts";
|
|
23
23
|
import {
|
|
24
24
|
at,
|
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
type SwitchRow,
|
|
63
63
|
type SymbolRow,
|
|
64
64
|
} from "#src/knowledge/read.ts";
|
|
65
|
-
import { ANALYZERS, COMMENT_PLACEMENTS, DEFAULT_SPACE, EVIDENCE_KINDS, isSemantic, ORIGINS, REGION_TYPES, RELEASE_DEFINE, SEMANTIC_ORIGINS, START_SCREEN_MODES, SWITCH_KINDS, SYMBOL_KINDS, type Origin, type StartScreenMode, type SwitchKind } from "#src/knowledge/schema.ts";
|
|
65
|
+
import { ANALYZERS, COMMENT_PLACEMENTS, DEFAULT_SPACE, EVIDENCE_KINDS, inSpace, isSemantic, ORIGINS, REGION_TYPES, RELEASE_DEFINE, SEMANTIC_ORIGINS, spaceOption, START_SCREEN_MODES, SWITCH_KINDS, SYMBOL_KINDS, type Origin, type StartScreenMode, type SwitchKind } from "#src/knowledge/schema.ts";
|
|
66
66
|
import {
|
|
67
67
|
addReference,
|
|
68
68
|
applyBatch,
|
|
@@ -315,12 +315,13 @@ function byAddress<T extends { address: number }>(rows: readonly T[]): Map<numbe
|
|
|
315
315
|
|
|
316
316
|
/**
|
|
317
317
|
* The lookups of a listing of a range: the program and the coverage in the knowledge, the knowledge of the space and the platform names of the ROMs that the program uses.
|
|
318
|
+
* The lines show `memory`, the bytes that the analyzers read (entryMemory); a target outside the segments is named as c64-source names it.
|
|
318
319
|
* The rows of the range are read once: a listing asks for each line.
|
|
319
320
|
*/
|
|
320
|
-
function listingSource(db: DatabaseSync | undefined, image: ProgramImage, range: AddressRange): ListingSource {
|
|
321
|
+
function listingSource(db: DatabaseSync | undefined, image: ProgramImage, memory: Pick<ProgramImage, "segments" | "byteAt">, range: AddressRange): ListingSource {
|
|
321
322
|
const space = image.space;
|
|
322
323
|
const coverage = programCoverage(db, space)?.map;
|
|
323
|
-
const byteAt = programBytes(
|
|
324
|
+
const byteAt = programBytes(memory);
|
|
324
325
|
const platform = programPlatform(space, coverage, image.state);
|
|
325
326
|
const entries = platform.filter((entry) => entry.end > entry.address);
|
|
326
327
|
const secondNames = byAddress(listAnalyzerNames(db, range, undefined, undefined, space));
|
|
@@ -335,7 +336,7 @@ function listingSource(db: DatabaseSync | undefined, image: ProgramImage, range:
|
|
|
335
336
|
}
|
|
336
337
|
return {
|
|
337
338
|
byteAt,
|
|
338
|
-
entryStart: (at) => (
|
|
339
|
+
entryStart: (at) => (inRanges(image.segments, at) ? undefined : entries.find((entry) => at > entry.address && at <= entry.end)?.address),
|
|
339
340
|
...namesOf(db, space, platform),
|
|
340
341
|
...(space === DEFAULT_SPACE ? { io: IO_RAM } : {}),
|
|
341
342
|
secondNames: (at) => (secondNames.get(at) ?? []).map((row) => row.name),
|
|
@@ -374,7 +375,7 @@ function knowledgePath(path: string, what: string): string {
|
|
|
374
375
|
try {
|
|
375
376
|
return projectRelative(path);
|
|
376
377
|
} catch {
|
|
377
|
-
throw new UsageError(`${what} must be a path
|
|
378
|
+
throw new UsageError(`${what} must be a path inside the project folder, relative to it or absolute, not ${path}.`);
|
|
378
379
|
}
|
|
379
380
|
}
|
|
380
381
|
|
|
@@ -392,8 +393,7 @@ function evidenceOf(value: string, space: string): Evidence {
|
|
|
392
393
|
// A coverage map is evidence by the name that coverage imported it with: the latest import into the space of the write.
|
|
393
394
|
if (kind === "coverage") {
|
|
394
395
|
const run = withRead((db) => coverageRuns(db).filter((item) => item.name === ref && item.space === space).at(-1));
|
|
395
|
-
|
|
396
|
-
if (run === undefined) throw new UsageError(`--evidence coverage:${given} names no coverage map of the knowledge${where}. Import the map with coverage${space === DEFAULT_SPACE ? "" : ` --space ${space}`} first.`);
|
|
396
|
+
if (run === undefined) throw new UsageError(`--evidence coverage:${given} names no coverage map of the knowledge${inSpace(space)}. Import the map with coverage${spaceOption(space)} first.`);
|
|
397
397
|
return { kind, ref, sha256: run.sha256, ...(run.space === DEFAULT_SPACE ? {} : { space: run.space }) };
|
|
398
398
|
}
|
|
399
399
|
const bytes = readProjectFile(ref).bytes;
|
|
@@ -848,12 +848,14 @@ const READ_COMMANDS: CommandSpec[] = [
|
|
|
848
848
|
(db, call) => {
|
|
849
849
|
const range = call.parseRange(call.subject(0), "<range>");
|
|
850
850
|
const image = requireProgram(db, call.space);
|
|
851
|
-
const
|
|
851
|
+
const memory = entryMemory(image);
|
|
852
|
+
const lines = listingLines(listing(listingSource(db, image, memory, range), range.start, range.end, { code: call.flag("code") }));
|
|
852
853
|
const out = call.string("out");
|
|
853
854
|
const body = out !== undefined ? { lines: lines.length, ...writeReported(out, lines.map((line) => `${line}\n`).join(""), { what: "--out" }) } : { lines: list(call, lines, (line) => line, "a larger --max-listed, a smaller <range>, or --out <file> for all lines") };
|
|
854
|
-
// A range outside the program has no lines: the hint names the
|
|
855
|
-
if (
|
|
856
|
-
|
|
855
|
+
// A range outside the program has no lines: the hint names the ranges that have them.
|
|
856
|
+
if (memory.segments.some((part) => rangesOverlap(part, range))) return body;
|
|
857
|
+
const held = `${memory.segments.map(formatC64Range).join(", ")}${memory.fromState.length === 0 ? "" : ` (the segments, and ${memory.fromState.map(formatC64Range).join(", ")} of the entry state)`}`;
|
|
858
|
+
return reply(body, { hint: `The range ${formatC64Range(range)} is outside the program. The program has bytes only in ${held}. Give a range in one of them.` });
|
|
857
859
|
},
|
|
858
860
|
),
|
|
859
861
|
];
|
|
@@ -1025,7 +1027,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1025
1027
|
writeCommand(
|
|
1026
1028
|
{
|
|
1027
1029
|
name: "release",
|
|
1028
|
-
summary: "Records a release of the program from its PRG or the image.json of its capture: the knowledge keeps the bytes of the release, and the path and the SHA-256 of the file. The base release is the one whose bytes are the program of the knowledge.",
|
|
1030
|
+
summary: "Records a release of the program from its PRG or the image.json of its capture: the knowledge keeps the bytes of the release, and the path and the SHA-256 of the program file. For an image.json, the program file is the file that the capture ran. The base release is the one whose bytes are the program of the knowledge.",
|
|
1029
1031
|
subjects: [{ name: "<label>", help: "the release label, for example FIRESTAR or V2" }],
|
|
1030
1032
|
options: {
|
|
1031
1033
|
file: { kind: "path", value: "<file>", help: "the PRG or image.json of the release. After the write, the knowledge does not need the file", required: true },
|
|
@@ -1039,23 +1041,19 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1039
1041
|
const image = readImage(file);
|
|
1040
1042
|
const commentText = call.string("comment");
|
|
1041
1043
|
const base = call.flag("base");
|
|
1044
|
+
// The image.json of a capture names the program file that the capture ran: the release cites that file, as git ignores a capture in local/.
|
|
1045
|
+
const cited = image.program === undefined ? { file, sha256: sha256(readProjectFile(file).bytes) } : checkedProgramCitation(file, image.program);
|
|
1042
1046
|
// The base release has no bytes of its own: its bytes are the program.
|
|
1043
1047
|
const request = {
|
|
1044
1048
|
space: call.space,
|
|
1045
1049
|
label: call.subject(0),
|
|
1046
|
-
|
|
1047
|
-
sha256: sha256(readProjectFile(file).bytes),
|
|
1050
|
+
...cited,
|
|
1048
1051
|
...(base ? { base } : { rows: memoryRows(image.segments, image.byteAt) }),
|
|
1049
1052
|
...(commentText === undefined ? {} : { comment: commentText }),
|
|
1050
1053
|
};
|
|
1051
1054
|
return (db) => {
|
|
1052
1055
|
if (base) {
|
|
1053
|
-
|
|
1054
|
-
const same = JSON.stringify(program.segments) === JSON.stringify(image.segments) && program.segments.every((segment) => {
|
|
1055
|
-
for (let address = segment.start; address <= segment.end; address++) if (program.byteAt(address) !== image.byteAt(address)) return false;
|
|
1056
|
-
return true;
|
|
1057
|
-
});
|
|
1058
|
-
if (!same) throw new Refusal("invalid-input", `The bytes of ${file} are not the program of the knowledge. Give --base only to the release whose file image put into the knowledge.`);
|
|
1056
|
+
if (!isProgram(requireProgram(db, call.space), image)) throw new Refusal("invalid-input", `The bytes of ${file} are not the program of the knowledge${inSpace(call.space)}. Give --base only to the release whose file image put into the knowledge.`);
|
|
1059
1057
|
}
|
|
1060
1058
|
const bytes = image.segments.reduce((sum, segment) => sum + segment.end - segment.start + 1, 0);
|
|
1061
1059
|
return { ...shown(setRelease(db, context, request), "release", release), bytes };
|
|
@@ -1199,6 +1197,8 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1199
1197
|
name: "coverage",
|
|
1200
1198
|
summary: "Puts coverage maps of the emulator, of a run or of a recording folder into the coverage of the knowledge. Each map is named by its path: a new map of a path replaces the earlier map of that path, and --evidence coverage:<path> cites it.",
|
|
1201
1199
|
subjects: [{ name: "<map>", help: "a 64 KiB coverage map, or a recording folder: then its coverage map", list: true }],
|
|
1200
|
+
options: LIST,
|
|
1201
|
+
notes: "commentsToCheck lists the comments at the addresses that the runs now execute or no longer execute. executed is true when the runs now execute the address.",
|
|
1202
1202
|
},
|
|
1203
1203
|
(call, context) => {
|
|
1204
1204
|
const maps = call.subjects.map((given) => {
|
|
@@ -1208,14 +1208,30 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1208
1208
|
});
|
|
1209
1209
|
return (db) => {
|
|
1210
1210
|
const { revision, current } = addCoverage(db, context, { space: call.space, maps });
|
|
1211
|
-
|
|
1211
|
+
// A comment can tell what the runs execute: where that changed, its claim can be false now. The script does not read the text.
|
|
1212
|
+
const toCheck = current.added === 0 && current.removed === 0 ? [] : listComments(db, undefined, undefined, call.space).filter((row) => current.executeChange(row.address) !== undefined);
|
|
1213
|
+
const checked = (row: CommentRow) => ({ ...comment(row), executed: current.executeChange(row.address) === "gained" });
|
|
1214
|
+
const body = {
|
|
1215
|
+
revision,
|
|
1216
|
+
...spaceOf(current),
|
|
1217
|
+
imported: current.imported,
|
|
1218
|
+
replaced: current.replaced,
|
|
1219
|
+
known: current.known,
|
|
1220
|
+
added: current.added,
|
|
1221
|
+
removed: current.removed,
|
|
1222
|
+
...(toCheck.length === 0 ? {} : { commentsToCheck: list(call, toCheck, checked, MORE) }),
|
|
1223
|
+
};
|
|
1224
|
+
const next =
|
|
1225
|
+
toCheck.length === 0
|
|
1226
|
+
? "Generate the source again, then the reference."
|
|
1227
|
+
: `${toCheck.length} comment${toCheck.length === 1 ? " is" : "s are"} at addresses that the runs now execute or no longer execute: see commentsToCheck. Read what each one tells about the runs, and correct each comment that is no longer true. Then generate the source again, then the reference.`;
|
|
1212
1228
|
// Only a range that the coverage gained or lost changes the source and the reference.
|
|
1213
1229
|
const hint =
|
|
1214
1230
|
revision === null
|
|
1215
1231
|
? "The knowledge has each map already. Nothing changed."
|
|
1216
1232
|
: current.added === 0 && current.removed === 0
|
|
1217
1233
|
? "The coverage did not change. The knowledge keeps the maps as evidence. The source and the reference do not change."
|
|
1218
|
-
: `The coverage gained ${current.added} and lost ${current.removed} ranges of accesses. They can change the leftovers and the code that no run executed.
|
|
1234
|
+
: `The coverage gained ${current.added} and lost ${current.removed} ranges of accesses. They can change the leftovers and the code that no run executed. ${next}`;
|
|
1219
1235
|
return reply(body, { hint });
|
|
1220
1236
|
};
|
|
1221
1237
|
},
|
|
@@ -1333,12 +1349,11 @@ const CHECKS: CommandSpec = {
|
|
|
1333
1349
|
/** join: the batches of agents that worked in parallel, as one list of writes. With --apply, it writes them as one revision. */
|
|
1334
1350
|
const JOIN: CommandSpec = {
|
|
1335
1351
|
name: "join",
|
|
1336
|
-
summary: "Joins the batches of agents that worked in parallel into one list of writes, and shows it. With --apply, it writes the list as one revision, or nothing when one write is refused.",
|
|
1352
|
+
summary: "Joins the batches of agents that worked in parallel into one list of writes, and shows it. One batch shows its own writes. With --apply, it writes the list as one revision, or nothing when one write is refused.",
|
|
1337
1353
|
subjects: [{ name: "<batch>", help: 'a batch: a list of writes, or {"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}', list: true }],
|
|
1338
|
-
options: { ...WRITE, apply: { kind: "flag", help: "write the joined writes to the project knowledge as one revision. Without it, the
|
|
1354
|
+
options: { ...WRITE, apply: { kind: "flag", help: "write the joined writes to the project knowledge as one revision. Without it, the script does every check of --apply, writes nothing and shows the writes" }, ...LIST },
|
|
1339
1355
|
notes: "At an address in the owner range of a batch, its name, comment, operand and module win, and its regions come last. One name or one module file at two addresses writes nothing.",
|
|
1340
1356
|
run: (call) => {
|
|
1341
|
-
if (call.subjects.length < 2) throw new UsageError("join needs two or more batch files.");
|
|
1342
1357
|
const batches: Batch[] = call.subjects.map((file) => {
|
|
1343
1358
|
const value = readProjectJson(file);
|
|
1344
1359
|
const shaped = Array.isArray(value) ? { ops: value } : (value as { owner?: unknown; ops?: unknown });
|
|
@@ -1363,11 +1378,13 @@ const JOIN: CommandSpec = {
|
|
|
1363
1378
|
const joined = joinBatches(batches);
|
|
1364
1379
|
const choice = (item: JoinChoice) => ({ ...item, at: typeof item.at === "number" ? formatC64Address(item.at) : item.at, ...(item.space === DEFAULT_SPACE ? { space: undefined } : {}) });
|
|
1365
1380
|
if (joined.clashes.length > 0) {
|
|
1366
|
-
const clash = (item: JoinClash) => `${item.what} ${item.value} at ${item.places.map((place) => `${formatC64Address(place.address)} (${place.file})`).join(" and ")}${item.space
|
|
1381
|
+
const clash = (item: JoinClash) => `${item.what} ${item.value} at ${item.places.map((place) => `${formatC64Address(place.address)} (${place.file})`).join(" and ")}${inSpace(item.space)}`;
|
|
1367
1382
|
throw new Refusal("conflict", `The batches give one ${joined.clashes.map(clash).join(", one ")}. Nothing was written. Give each name and each module file one address in the batches, then join again.`);
|
|
1368
1383
|
}
|
|
1369
1384
|
const shown = { repeated: joined.repeated, choices: joined.choices.map(choice) };
|
|
1370
1385
|
if (call.flag("apply")) return { ...withWrite((db) => applied(db, contextOf(call), joined.ops)), ...shown };
|
|
1386
|
+
// The writes run as a trial: every check of --apply runs, and nothing is written.
|
|
1387
|
+
withTrial((db) => applied(db, contextOf(call), joined.ops));
|
|
1371
1388
|
const body = { writes: listed(joined.ops.map(batchJson), call.count("max-listed")!, (write) => write, MORE), ...shown };
|
|
1372
1389
|
return reply(body, { hint: "Examine each item of choices and writes. Then nextAction writes them to the project knowledge as one revision.", nextAction: call.next("join", ...call.subjects, "--apply") });
|
|
1373
1390
|
},
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// unpacks the result again in the emulator of Exomizer and checks the bytes
|
|
4
4
|
// and the entry before it writes the program.
|
|
5
5
|
|
|
6
|
-
import { posix } from "node:path";
|
|
7
6
|
|
|
8
7
|
import { findHandoffs, formatC64Address, formatC64Byte, formatC64RangeFields, parseTokenized, prgRange } from "#src/c64.ts";
|
|
9
8
|
import { compareBuild, mergedPrograms } from "#src/compare.ts";
|
|
@@ -11,6 +10,7 @@ import { isRefusal, Refusal } from "#src/errors.ts";
|
|
|
11
10
|
import { readProjectFile, writeReported } from "#src/host-client/transfer.ts";
|
|
12
11
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
13
12
|
import { pack } from "#src/native/exomizer.ts";
|
|
13
|
+
import { resolveReadPath } from "#src/project.ts";
|
|
14
14
|
import { localToolContext } from "#src/native/local.ts";
|
|
15
15
|
import { OPTIONS, reply, runScript, UsageError } from "#src/script.ts";
|
|
16
16
|
|
|
@@ -29,7 +29,14 @@ function sysEntry(program: Uint8Array): number | string {
|
|
|
29
29
|
return sys.address;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
/** True when two project paths name one file, also when one is relative and the other absolute. A path that the project rules refuse names no file here: its read refuses it. */
|
|
33
|
+
const samePath = (a: string, b: string) => {
|
|
34
|
+
try {
|
|
35
|
+
return resolveReadPath(a) === resolveReadPath(b);
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
33
40
|
|
|
34
41
|
await runScript({
|
|
35
42
|
name: "packer",
|