@henols/c64-re-tools 2.8.0-rc.5 → 2.8.0-rc.7
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 +4 -3
- package/skills/c64-knowledge/scripts/knowledge.ts +31 -12
- package/skills/c64-packer/scripts/packer.ts +9 -2
- package/skills/c64-provenance/SKILL.md +1 -1
- package/skills/c64-provenance/scripts/lib/runtime.ts +5 -16
- package/skills/c64-source/references/loader.md +8 -7
- package/skills/c64-source/scripts/lib/loader.ts +4 -111
- 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/static-analysis.ts +32 -21
- package/skills/c64-testing/SKILL.md +6 -0
- package/skills/c64-testing/scripts/lib/play.ts +8 -7
- package/skills/c64-testing/scripts/lib/recording.ts +218 -12
- package/skills/c64-testing/scripts/lib/replay.ts +7 -3
- 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 +24 -11
- package/skills/c64-unpacker/SKILL.md +6 -4
- package/skills/c64-unpacker/scripts/lib/loads.ts +4 -2
- package/skills/c64-unpacker/scripts/lib/machine.ts +128 -5
- package/skills/c64-unpacker/scripts/lib/stages.ts +5 -1
- package/skills/c64-unpacker/scripts/unpacker.ts +13 -12
- package/skills/emulator/SKILL.md +2 -2
- package/src/host/vice/adapter.ts +2 -1
- package/src/host-client/image.ts +33 -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 +31 -8
- package/src/knowledge/names.ts +2 -2
- package/src/knowledge/program.ts +67 -7
- package/src/knowledge/schema.ts +6 -0
- package/src/knowledge/start-screen.ts +55 -2
- package/src/knowledge/write.ts +18 -12
- 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/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")!);
|
|
@@ -125,7 +125,7 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
125
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. |
|
|
126
126
|
| `--text <text>` | `verdict` | With `wrong`: the correct comment. |
|
|
127
127
|
| `--name <name>` | `verdict` | With `wrong`: the correct name at the address. |
|
|
128
|
-
| `--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. |
|
|
129
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. |
|
|
130
130
|
| `--kind <kind>` | `references` | Only references of this kind: `call`, `jump`, `read`, `write`, `reference` or `pointer`. |
|
|
131
131
|
| `--kind <kind>` | `switch` | Necessary. The switch kind: `protection`, `trainer`, `cheat`, `crack`, `fix` or `change`. |
|
|
@@ -342,7 +342,7 @@ Errors of this group:
|
|
|
342
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. |
|
|
343
343
|
| `rts-addresses`, `rts-addresses-split` | The same, with each value the target minus 1, for a PHA, PHA, RTS dispatch. |
|
|
344
344
|
| `jumps` | A table of `JMP abs` instructions. Each 3-byte entry is an entry point. It is code. |
|
|
345
|
-
| `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. |
|
|
346
346
|
| `unused` | Bytes that nothing executes or reads. |
|
|
347
347
|
| `dual-use` | Code at one time, and data or a vector at another time. No analyzer finding conflicts with it. |
|
|
348
348
|
|
|
@@ -463,6 +463,7 @@ An operand expression tells the generated source how to write the operand of one
|
|
|
463
463
|
|
|
464
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.
|
|
465
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.
|
|
466
467
|
- When `added` or `removed` is not 0, do as `hint` tells.
|
|
467
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`.
|
|
468
469
|
|
|
@@ -476,7 +477,7 @@ An operand expression tells the generated source how to write the operand of one
|
|
|
476
477
|
|
|
477
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`.
|
|
478
479
|
- `join` also takes one batch. Then `writes` shows the writes of that batch, and `join` checks the batch as it checks more batches.
|
|
479
|
-
- Without `--apply`, `join` writes no knowledge. `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.
|
|
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.
|
|
480
481
|
- Examine `choices` and `writes`. `nextAction` is the same `join` with `--apply`. Run it when the choices agree with your task.
|
|
481
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`.
|
|
482
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.
|
|
@@ -10,10 +10,10 @@ 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";
|
|
@@ -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,
|
|
@@ -375,7 +375,7 @@ function knowledgePath(path: string, what: string): string {
|
|
|
375
375
|
try {
|
|
376
376
|
return projectRelative(path);
|
|
377
377
|
} catch {
|
|
378
|
-
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}.`);
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
|
|
@@ -393,8 +393,7 @@ function evidenceOf(value: string, space: string): Evidence {
|
|
|
393
393
|
// A coverage map is evidence by the name that coverage imported it with: the latest import into the space of the write.
|
|
394
394
|
if (kind === "coverage") {
|
|
395
395
|
const run = withRead((db) => coverageRuns(db).filter((item) => item.name === ref && item.space === space).at(-1));
|
|
396
|
-
|
|
397
|
-
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.`);
|
|
398
397
|
return { kind, ref, sha256: run.sha256, ...(run.space === DEFAULT_SPACE ? {} : { space: run.space }) };
|
|
399
398
|
}
|
|
400
399
|
const bytes = readProjectFile(ref).bytes;
|
|
@@ -1043,7 +1042,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1043
1042
|
const commentText = call.string("comment");
|
|
1044
1043
|
const base = call.flag("base");
|
|
1045
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/.
|
|
1046
|
-
const cited = image.program === undefined ? { file, sha256: sha256(readProjectFile(file).bytes) } :
|
|
1045
|
+
const cited = image.program === undefined ? { file, sha256: sha256(readProjectFile(file).bytes) } : checkedProgramCitation(file, image.program);
|
|
1047
1046
|
// The base release has no bytes of its own: its bytes are the program.
|
|
1048
1047
|
const request = {
|
|
1049
1048
|
space: call.space,
|
|
@@ -1054,7 +1053,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1054
1053
|
};
|
|
1055
1054
|
return (db) => {
|
|
1056
1055
|
if (base) {
|
|
1057
|
-
if (!isProgram(requireProgram(db, call.space), image)) 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.`);
|
|
1058
1057
|
}
|
|
1059
1058
|
const bytes = image.segments.reduce((sum, segment) => sum + segment.end - segment.start + 1, 0);
|
|
1060
1059
|
return { ...shown(setRelease(db, context, request), "release", release), bytes };
|
|
@@ -1198,6 +1197,8 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1198
1197
|
name: "coverage",
|
|
1199
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.",
|
|
1200
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.",
|
|
1201
1202
|
},
|
|
1202
1203
|
(call, context) => {
|
|
1203
1204
|
const maps = call.subjects.map((given) => {
|
|
@@ -1207,14 +1208,30 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1207
1208
|
});
|
|
1208
1209
|
return (db) => {
|
|
1209
1210
|
const { revision, current } = addCoverage(db, context, { space: call.space, maps });
|
|
1210
|
-
|
|
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.`;
|
|
1211
1228
|
// Only a range that the coverage gained or lost changes the source and the reference.
|
|
1212
1229
|
const hint =
|
|
1213
1230
|
revision === null
|
|
1214
1231
|
? "The knowledge has each map already. Nothing changed."
|
|
1215
1232
|
: current.added === 0 && current.removed === 0
|
|
1216
1233
|
? "The coverage did not change. The knowledge keeps the maps as evidence. The source and the reference do not change."
|
|
1217
|
-
: `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}`;
|
|
1218
1235
|
return reply(body, { hint });
|
|
1219
1236
|
};
|
|
1220
1237
|
},
|
|
@@ -1334,7 +1351,7 @@ const JOIN: CommandSpec = {
|
|
|
1334
1351
|
name: "join",
|
|
1335
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.",
|
|
1336
1353
|
subjects: [{ name: "<batch>", help: 'a batch: a list of writes, or {"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}', list: true }],
|
|
1337
|
-
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 },
|
|
1338
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.",
|
|
1339
1356
|
run: (call) => {
|
|
1340
1357
|
const batches: Batch[] = call.subjects.map((file) => {
|
|
@@ -1361,11 +1378,13 @@ const JOIN: CommandSpec = {
|
|
|
1361
1378
|
const joined = joinBatches(batches);
|
|
1362
1379
|
const choice = (item: JoinChoice) => ({ ...item, at: typeof item.at === "number" ? formatC64Address(item.at) : item.at, ...(item.space === DEFAULT_SPACE ? { space: undefined } : {}) });
|
|
1363
1380
|
if (joined.clashes.length > 0) {
|
|
1364
|
-
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)}`;
|
|
1365
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.`);
|
|
1366
1383
|
}
|
|
1367
1384
|
const shown = { repeated: joined.repeated, choices: joined.choices.map(choice) };
|
|
1368
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));
|
|
1369
1388
|
const body = { writes: listed(joined.ops.map(batchJson), call.count("max-listed")!, (write) => write, MORE), ...shown };
|
|
1370
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") });
|
|
1371
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",
|
|
@@ -125,7 +125,7 @@ With `--shift`, the addresses of `segments`, `common` and `differences` are the
|
|
|
125
125
|
With `--frames`, the body also holds:
|
|
126
126
|
|
|
127
127
|
- `runtime` in each difference: one item for each release that started, by the number of the release. `start` and `end` are the addresses in the release, without the shift.
|
|
128
|
-
- `first`: the first access in that release: `read`, `write`, `execute` or `none`. An instruction that reads and then writes the same byte, for example INC, counts as `read`. A store counts as `write`, also an indexed store that first makes a dummy read of the byte, for example `STA ($06),Y`. The operand bytes of an executed instruction count as `execute`, for example the `$03` of `LDA #$03`. During a `press` step, no access stops the run. Thus a range that the program reads and writes during a `press` step counts as `read
|
|
128
|
+
- `first`: the first access in that release: `read`, `write`, `read-write`, `execute` or `none`. An instruction that reads and then writes the same byte, for example INC, counts as `read`. A store counts as `write`, also an indexed store that first makes a dummy read of the byte, for example `STA ($06),Y`. The operand bytes of an executed instruction count as `execute`, for example the `$03` of `LDA #$03`. During a `press` step, no access stops the run. Thus a range that the program reads and writes during a `press` step counts as `read-write`: the order is not known.
|
|
129
129
|
- `changed`: `true` when the bytes at the end of the run are not the bytes of the release.
|
|
130
130
|
- `run`: `frames`, `steps` and `releases`. `releases` tells for each release, by its number, if it started, or the `reason` that it did not start. `skipped` tells that the releases have no differences, so no release ran.
|
|
131
131
|
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
// tells which instruction made a read and a write.
|
|
7
7
|
|
|
8
8
|
import { type AddressRange, COVERAGE, EXECUTE, instructionLength, READ, WRITE } from "#src/c64.ts";
|
|
9
|
-
import { isRefusal } from "#src/errors.ts";
|
|
10
9
|
import { runProgram } from "#src/host-client/autostart.ts";
|
|
11
10
|
import { readCoverage } from "#src/host-client/coverage.ts";
|
|
12
11
|
import { startAtEntry, type EntryState } from "#src/host-client/entry-state.ts";
|
|
@@ -14,9 +13,9 @@ import { runActionStep, type ActionStep } from "#src/host-client/steps.ts";
|
|
|
14
13
|
import { knowledgeAt } from "#src/knowledge/names.ts";
|
|
15
14
|
import { isStore } from "#src/opcodes.ts";
|
|
16
15
|
import { readProjectFile } from "#src/host-client/transfer.ts";
|
|
17
|
-
import { readMemoryInParts, type ViceSessionClient } from "#src/host-client/vice-session.ts";
|
|
16
|
+
import { lastOpcode, readMemoryInParts, type ViceSessionClient } from "#src/host-client/vice-session.ts";
|
|
18
17
|
|
|
19
|
-
export type FirstAccess = "read" | "write" | "execute" | "none";
|
|
18
|
+
export type FirstAccess = "read" | "write" | "read-write" | "execute" | "none";
|
|
20
19
|
|
|
21
20
|
export interface RangeAccess {
|
|
22
21
|
first: FirstAccess;
|
|
@@ -35,27 +34,17 @@ const MAX_WATCH = 256;
|
|
|
35
34
|
* The first access that coverage flags show. A read and a write at one stop
|
|
36
35
|
* are of the instruction that made the access (`opcode`, when the CPU history
|
|
37
36
|
* gives it): an indexed store makes a dummy read before its write, and a
|
|
38
|
-
* read-modify-write reads first. Without the instruction
|
|
37
|
+
* read-modify-write reads first. Without the instruction (the taps of a press,
|
|
38
|
+
* the end of the run), the order of a read and a write is not known: read-write.
|
|
39
39
|
*/
|
|
40
40
|
export function accessOf(flags: number, opcode?: number): FirstAccess {
|
|
41
41
|
if ((flags & EXECUTE) !== 0) return "execute";
|
|
42
|
-
if ((flags & READ) !== 0 && (flags & WRITE) !== 0
|
|
42
|
+
if ((flags & READ) !== 0 && (flags & WRITE) !== 0) return opcode === undefined ? "read-write" : isStore(opcode) ? "write" : "read";
|
|
43
43
|
if ((flags & READ) !== 0) return "read";
|
|
44
44
|
if ((flags & WRITE) !== 0) return "write";
|
|
45
45
|
return "none";
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/** The opcode of the last instruction in the CPU history, or undefined when the session gives no history (after a JAM, or none since a restore). */
|
|
49
|
-
async function lastOpcode(client: ViceSessionClient): Promise<number | undefined> {
|
|
50
|
-
try {
|
|
51
|
-
const [entry] = (await client.cpuHistory({ limit: 1, space: "c64" })).entries;
|
|
52
|
-
return entry === undefined ? undefined : Buffer.from(entry.bytes, "hex")[0];
|
|
53
|
-
} catch (error) {
|
|
54
|
-
if (isRefusal(error) && error.code === "operation-failed") return undefined;
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
48
|
/** Starts the release; returns why it did not start, or undefined. */
|
|
60
49
|
async function start(client: ViceSessionClient, how: Start): Promise<string | undefined> {
|
|
61
50
|
if (how.kind === "program") {
|
|
@@ -9,6 +9,7 @@ This file gives the loader program of `generate --out <dir> --loader`, the field
|
|
|
9
9
|
- `loader.program` is the loader program. `loader.symbols` is its symbols file. The symbols file holds the labels of `loader.asm`, `main.asm` and `start_screen_stage.asm`. Give the two files to a test of the loader program.
|
|
10
10
|
- The loader program has the switch values of `config.asm`. With the defaults, it is the clean program: no copy protection, all corrections and no leftovers. The entry state is the state of the base release.
|
|
11
11
|
- The name of the loader program changes with the switch values. Then the script removes the loader program of the earlier run and its symbols.
|
|
12
|
+
- This can remove `build/clean_loader.prg`, the loader program of the defaults. It is the default build. Then `hint` tells you how to make it again. To keep it, do not change `config.asm`. Get the loader program of other switch values from a build. See "The loader of other switch values".
|
|
12
13
|
- The loader program sets the entry state of the capture and jumps to the entry. It sets the memory, $00/$01, the registers, the VIC-II, the colour RAM, the raster line and the CIA timers.
|
|
13
14
|
- The loader changes the free stack byte below the stack pointer (`stackByte`). It does not set the SID, the time of day of the CIAs, the CIA interrupt flags or the interrupt registers of the VIC-II. A program that reads SID voice 3 for random numbers can thus give a different result. When you compare the reference and the rebuild, observe after the program sets its own random numbers.
|
|
14
15
|
- For the loader program of a release, build `loader.asm` with the build option `--release <label>`. This is possible only when `loader.packed` is not in the result. That loader program also does not have the leftovers.
|
|
@@ -23,15 +24,15 @@ This file gives the loader program of `generate --out <dir> --loader`, the field
|
|
|
23
24
|
|
|
24
25
|
## The loader of other switch values
|
|
25
26
|
|
|
26
|
-
To get the loader program of other switch values, build `main.asm` of the source with these switch values, for example `TRAINER=1`. `config.asm`
|
|
27
|
+
To get the loader program of other switch values, build `main.asm` of the source with these switch values, for example `TRAINER=1`. `config.asm` and the other files of the source do not change. The build result then has the loader program in `loader.out` and its symbols file in `loader.symbolsFile.out`. With a start screen of a captured stage, the loader program also has the show stage of `start_screen_stage.asm`. Then `loader.stage` gives the space of the stage. No check of this loader program runs, so `loader.verified` is `false`. Test the loader program before you trust it.
|
|
27
28
|
|
|
28
|
-
The build
|
|
29
|
+
The build writes no loader program in these cases. `loader.reason` tells why.
|
|
29
30
|
|
|
30
|
-
-
|
|
31
|
-
- The
|
|
32
|
-
- The
|
|
31
|
+
- The switch values change a byte that `loader.asm` holds. These bytes are between the free ranges of `loader.asm`, or below $0400.
|
|
32
|
+
- The start screen is of a captured stage, and the source has no `start_screen_stage.asm`. Or the file is of an earlier start screen, or of an earlier capture of the stage.
|
|
33
|
+
- The memory has no room for the show stage.
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
Do the action that `loader.reason` gives. When it tells you to set the switch values in `config.asm`, the generation of the source with the loader removes `build/clean_loader.prg`. See "The loader program".
|
|
35
36
|
|
|
36
37
|
## The fields of the loader
|
|
37
38
|
|
|
@@ -74,6 +75,6 @@ The loader program then shows the start screen before it unpacks the program. Th
|
|
|
74
75
|
- The loader program has only the bytes of the stage that the start screen uses. These are the screen, the bitmap and the charset. With a call, they are also each byte of the stage that is not free from the call, as in "The free ranges". A call thus needs the coverage of the stage.
|
|
75
76
|
- With colours from the colour RAM of the capture, the loader program sets the colour RAM to these colours.
|
|
76
77
|
- The patches of the stage are in at the defaults of their switches. Thus a patch under a switch can remove the text of a crack from the picture.
|
|
77
|
-
- `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make the loader program again, run `generate --out <dir> --loader`.
|
|
78
|
+
- `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make the loader program again, run `generate --out <dir> --loader`. A build with other switch values also uses the bytes of the stage in this file.
|
|
78
79
|
- The show stage needs Exomizer. The show code needs free memory in $0400-$9fff or $c000-$cfff. When the memory is too small, the reason gives the largest free ranges.
|
|
79
80
|
- The check also compares the VIC-II, the screen bytes and the colour RAM with the start screen.
|