@henols/c64-re-tools 2.6.0-rc.9 → 2.7.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +7 -7
- package/skills/c64-assembler/scripts/assembler.ts +4 -3
- package/skills/c64-basic/SKILL.md +1 -1
- package/skills/c64-development/SKILL.md +7 -7
- package/skills/c64-disk/SKILL.md +13 -13
- package/skills/c64-docs/SKILL.md +25 -10
- package/skills/c64-docs/references/page-types.md +11 -11
- package/skills/c64-docs/references/style.md +21 -0
- package/skills/c64-docs/scripts/docs.ts +78 -18
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +117 -31
- package/skills/c64-docs/scripts/lib/source-map.ts +14 -0
- package/skills/c64-knowledge/SKILL.md +15 -14
- package/skills/c64-knowledge/scripts/knowledge.ts +17 -10
- package/skills/c64-memory-map/SKILL.md +1 -1
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +5 -4
- package/skills/c64-provenance/scripts/lib/compare.ts +1 -1
- package/skills/c64-reverse-engineering/SKILL.md +26 -11
- package/skills/c64-source/SKILL.md +18 -15
- package/skills/c64-source/scripts/lib/export.ts +20 -8
- package/skills/c64-source/scripts/lib/loader.ts +51 -28
- package/skills/c64-source/scripts/lib/source.ts +27 -20
- package/skills/c64-source/scripts/source.ts +68 -53
- package/skills/c64-static-analysis/SKILL.md +24 -22
- package/skills/c64-static-analysis/scripts/lib/findings.ts +11 -11
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +4 -4
- package/skills/c64-static-analysis/scripts/lib/macros.ts +3 -1
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -27
- package/skills/c64-testing/SKILL.md +32 -24
- package/skills/c64-testing/references/recording-format.md +15 -9
- package/skills/c64-testing/references/scenario-format.md +9 -7
- package/skills/c64-testing/scripts/lib/recording.ts +214 -49
- package/skills/c64-testing/scripts/lib/replay.ts +45 -19
- package/skills/c64-testing/scripts/lib/runs.ts +7 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +31 -31
- package/skills/c64-testing/scripts/testing.ts +37 -16
- package/skills/c64-unpacker/SKILL.md +16 -14
- package/skills/c64-unpacker/scripts/lib/stages.ts +18 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +38 -6
- package/src/build-name.ts +9 -4
- package/src/c64.ts +1 -1
- package/src/host/main.ts +2 -2
- package/src/host/server.ts +3 -1
- package/src/host/tools/index.ts +1 -1
- package/src/host/vice/process.ts +34 -17
- package/src/host/vice/session.ts +55 -27
- package/src/host-client/steps.ts +4 -1
- package/src/host-client/tools.ts +1 -1
- package/src/knowledge/evidence.ts +66 -0
- package/src/knowledge/history.ts +5 -5
- package/src/knowledge/import.ts +12 -5
- package/src/knowledge/program.ts +81 -33
- package/src/knowledge/read.ts +3 -3
- package/src/knowledge/schema.ts +7 -7
- package/src/knowledge/separate.ts +2 -2
- package/src/knowledge/start-screen.ts +2 -0
- package/src/knowledge/text.ts +28 -3
- package/src/knowledge/write.ts +7 -7
- package/src/mcp/tools/debug.ts +23 -21
- package/src/mcp/tools/memory.ts +12 -9
- package/src/native/c64run.ts +7 -4
- package/src/native/{ghidra → decompiler}/analyze.ts +17 -17
- package/src/native/{ghidra → decompiler}/language/c64rt_6510.slaspec +1 -1
- package/src/native/{ghidra → decompiler}/walk.ts +6 -6
- package/src/native/types.ts +25 -25
- package/src/opcodes.ts +1 -1
- package/src/project.ts +1 -1
- package/src/reference-pages.ts +64 -0
- package/src/script.ts +2 -2
- package/tools/c64run.c +151 -5
- /package/src/native/{ghidra → decompiler}/c64rt-wasm.ts +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.cspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.ldefs +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.pspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.sla +0 -0
- /package/src/native/{ghidra → decompiler}/pcode.ts +0 -0
- /package/src/native/{ghidra → decompiler}/wasm.ts +0 -0
|
@@ -7,18 +7,22 @@
|
|
|
7
7
|
|
|
8
8
|
import { existsSync, readdirSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
9
9
|
import { basename, join, posix } from "node:path";
|
|
10
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
10
11
|
|
|
11
12
|
import { Refusal } from "#src/errors.ts";
|
|
12
13
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
13
14
|
import { writeProjectFile, writeReported } from "#src/host-client/transfer.ts";
|
|
14
15
|
import { conflicts } from "#src/knowledge/conflicts.ts";
|
|
15
|
-
import { openForRead } from "#src/knowledge/database.ts";
|
|
16
|
+
import { openForRead, TEXT_DIRECTORY } from "#src/knowledge/database.ts";
|
|
17
|
+
import { changedEvidence, type EvidenceChange } from "#src/knowledge/evidence.ts";
|
|
16
18
|
import { programImage, type ProgramImage } from "#src/knowledge/program.ts";
|
|
17
19
|
import { listComments, listModules, listReferences, listRegions, listSymbols, sourceRevision } from "#src/knowledge/read.ts";
|
|
18
|
-
import {
|
|
20
|
+
import { compareText } from "#src/knowledge/text.ts";
|
|
21
|
+
import { groupOf, namedGroup, PROJECT_DIRECTORY, projectRoot, resolveProjectFile, resolveProjectPath, type ProjectGroup } from "#src/project.ts";
|
|
22
|
+
import { GENERATED_MARK, referenceStamp } from "#src/reference-pages.ts";
|
|
19
23
|
import { listed, OPTIONS, reply, runScript, UsageError, type Call, type Reply } from "#src/script.ts";
|
|
20
24
|
import { checkLinks, linkPage, type Files, type LinkContext, type Names, type Problem } from "./lib/links.ts";
|
|
21
|
-
import { buildReference
|
|
25
|
+
import { buildReference } from "./lib/reference.ts";
|
|
22
26
|
import { readSourceMap } from "./lib/source-map.ts";
|
|
23
27
|
|
|
24
28
|
// ---------------------------------------------------------------------------
|
|
@@ -247,27 +251,65 @@ function link(call: Call): Reply {
|
|
|
247
251
|
const reference = checkedReference !== undefined ? checkedReference : foundReference === undefined ? undefined : foundReference.slice(memberOf(foundReference)!.prefix.length).replace(/^\//, "");
|
|
248
252
|
const referenceOf = (member: Member) => (reference === undefined ? undefined : posix.join(member.prefix, reference));
|
|
249
253
|
const problems: Problem[] = [];
|
|
254
|
+
/** The evidence files of the knowledge of each read project that are missing or changed, with paths relative to the root of the run. */
|
|
255
|
+
const evidence: Array<EvidenceChange & { project?: string }> = [];
|
|
256
|
+
const evidenceRead = new Set<Member>();
|
|
257
|
+
const addEvidence = (member: Member, db: DatabaseSync | undefined) => {
|
|
258
|
+
if (evidenceRead.has(member)) return;
|
|
259
|
+
evidenceRead.add(member);
|
|
260
|
+
for (const change of changedEvidence(db, member.root)) evidence.push({ ...change, file: posix.join(member.prefix, change.file), ...(member.label === undefined ? {} : { project: member.label }) });
|
|
261
|
+
};
|
|
262
|
+
/** The projects whose knowledge cannot be read: one problem each, not the end of the run. */
|
|
263
|
+
const unreadableKnowledge = new Set<Member>();
|
|
264
|
+
const markUnreadable = (member: Member, error: Refusal) => {
|
|
265
|
+
if (unreadableKnowledge.has(member)) return;
|
|
266
|
+
unreadableKnowledge.add(member);
|
|
267
|
+
problems.push({ page: posix.join(member.prefix, PROJECT_DIRECTORY, TEXT_DIRECTORY), line: 1, kind: "unreadable-knowledge", message: `The knowledge of the project ${member.label} cannot be read: ${error.message}` });
|
|
268
|
+
};
|
|
269
|
+
/** The evidence of a project that no page names. */
|
|
270
|
+
const readEvidence = (member: Member) => {
|
|
271
|
+
if (evidenceRead.has(member) || unreadableKnowledge.has(member)) return;
|
|
272
|
+
let db: DatabaseSync | undefined;
|
|
273
|
+
try {
|
|
274
|
+
db = openForRead(member.root);
|
|
275
|
+
addEvidence(member, db);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (!(error instanceof Refusal)) throw error;
|
|
278
|
+
markUnreadable(member, error);
|
|
279
|
+
} finally {
|
|
280
|
+
db?.close();
|
|
281
|
+
}
|
|
282
|
+
};
|
|
250
283
|
|
|
251
284
|
/** The names of a project, read the first time a page needs them. A project with given pages is read before the pages. */
|
|
252
285
|
const loaded = new Map<Member, Names>();
|
|
253
|
-
const load = (member: Member, required: boolean): Names => {
|
|
286
|
+
const load = (member: Member, required: boolean): Names | undefined => {
|
|
254
287
|
const done = loaded.get(member);
|
|
255
288
|
if (done !== undefined) return done;
|
|
256
289
|
const of = member.label === undefined ? "" : ` of the project ${member.label}`;
|
|
257
290
|
const inProject = (path: string) => posix.join(member.prefix, path);
|
|
258
|
-
|
|
291
|
+
// The knowledge first: a project that a page only names, with knowledge that cannot be read, is one problem and has no names.
|
|
292
|
+
let db: DatabaseSync | undefined;
|
|
259
293
|
try {
|
|
260
|
-
|
|
294
|
+
db = openForRead(member.root);
|
|
261
295
|
} catch (error) {
|
|
262
|
-
if (
|
|
263
|
-
|
|
296
|
+
if (required || !(error instanceof Refusal)) throw error;
|
|
297
|
+
markUnreadable(member, error);
|
|
298
|
+
return undefined;
|
|
264
299
|
}
|
|
265
|
-
|
|
300
|
+
let map;
|
|
266
301
|
let symbols;
|
|
267
302
|
let revision;
|
|
268
303
|
try {
|
|
304
|
+
try {
|
|
305
|
+
map = readSourceMap(source, member.root);
|
|
306
|
+
} catch (error) {
|
|
307
|
+
if (member.label === undefined || !(error instanceof WireFailure)) throw error;
|
|
308
|
+
throw new WireFailure(error.code, `In the project ${member.label}: ${error.message}`);
|
|
309
|
+
}
|
|
269
310
|
revision = sourceRevision(db, map.space);
|
|
270
311
|
symbols = listSymbols(db, undefined, undefined, undefined, map.space);
|
|
312
|
+
addEvidence(member, db);
|
|
271
313
|
} finally {
|
|
272
314
|
db?.close();
|
|
273
315
|
}
|
|
@@ -319,9 +361,9 @@ function link(call: Call): Reply {
|
|
|
319
361
|
problems.push(unreadable(page));
|
|
320
362
|
continue;
|
|
321
363
|
}
|
|
322
|
-
const stamp =
|
|
323
|
-
if (
|
|
324
|
-
problems.push({ page, line: 1, kind: "stale-reference", message: `${shown(page)} is from knowledge revision ${stamp
|
|
364
|
+
const stamp = referenceStamp(text);
|
|
365
|
+
if (stamp !== undefined && stamp.revision !== map.revision) {
|
|
366
|
+
problems.push({ page, line: 1, kind: "stale-reference", message: `${shown(page)} is from knowledge revision ${stamp.revision}, and the source${of} from ${map.revision}. Run docs.ts generate again.` });
|
|
325
367
|
}
|
|
326
368
|
}
|
|
327
369
|
const names: Names = {
|
|
@@ -343,16 +385,21 @@ function link(call: Call): Reply {
|
|
|
343
385
|
for (const member of members) if (pagesGiven.some((page) => memberOf(page) === member)) load(member, true);
|
|
344
386
|
|
|
345
387
|
const labels = members.map((member) => member.label!);
|
|
388
|
+
/** The names of a project that a page names: a project whose knowledge cannot be read has none, so its mentions stay as they are. */
|
|
389
|
+
const loadNamed = (member: Member): Names | undefined => {
|
|
390
|
+
if (unreadableKnowledge.has(member)) return undefined;
|
|
391
|
+
return load(member, false);
|
|
392
|
+
};
|
|
346
393
|
const namesFor = (page: string) => (label: string | undefined): ReturnType<LinkContext["names"]> => {
|
|
347
394
|
if (group === undefined) return label === undefined ? load(members[0]!, false) : undefined;
|
|
348
395
|
if (label === undefined) {
|
|
349
396
|
const own = memberOf(page);
|
|
350
|
-
if (own !== undefined) return
|
|
397
|
+
if (own !== undefined) return loadNamed(own);
|
|
351
398
|
return { kind: "unlabelled-name", message: `A page of the group folder must name the project of each name. Write the folder of the project before the name, for example \`${labels[0]}:name\`.` };
|
|
352
399
|
}
|
|
353
400
|
const member = members.find((each) => each.label === label);
|
|
354
401
|
if (member === undefined) return { kind: "unknown-label", message: `${label} is no project of the group folder. The projects are ${labels.join(", ")}. Correct the label.` };
|
|
355
|
-
return
|
|
402
|
+
return loadNamed(member);
|
|
356
403
|
};
|
|
357
404
|
const managed = (path: string) => members.some((member) => within(path, posix.join(member.prefix, source)) || within(path, referenceOf(member)));
|
|
358
405
|
|
|
@@ -380,6 +427,8 @@ function link(call: Call): Reply {
|
|
|
380
427
|
writeProjectFile(page, Buffer.from(linked.text, "utf8"), { root });
|
|
381
428
|
texts.set(page, linked.text);
|
|
382
429
|
}
|
|
430
|
+
// A shared page of the group folder can tell about each project: the evidence of each project counts, also of a project that no page names. After the pages, a project that a page names is read once.
|
|
431
|
+
if (pagesGiven.some((page) => memberOf(page) === undefined)) members.forEach(readEvidence);
|
|
383
432
|
const byKind: Record<string, number> = {};
|
|
384
433
|
for (const problem of problems) byKind[problem.kind] = (byKind[problem.kind] ?? 0) + 1;
|
|
385
434
|
const shownProblems = listed(problems, call.count("max-listed")!, (problem) => ({
|
|
@@ -395,11 +444,21 @@ function link(call: Call): Reply {
|
|
|
395
444
|
...(check ? { notUpToDate: { links, pages: changedPages } } : { linked: { links, pages: changedPages } }),
|
|
396
445
|
problems: { byKind, ...shownProblems },
|
|
397
446
|
};
|
|
447
|
+
// Two projects can give the same file, one of them through a ../ path: the project orders them.
|
|
448
|
+
evidence.sort((a, b) => compareText(a.file, b.file) || compareText(a.project ?? "", b.project ?? ""));
|
|
449
|
+
const shownEvidence = listed(evidence, call.count("max-listed")!, (change) => ({ ...change, file: shown(change.file) }));
|
|
450
|
+
if (evidence.length > 0) output.evidence = shownEvidence;
|
|
398
451
|
const again = (withCheck: boolean) =>
|
|
399
452
|
call.next("link", ...call.subjects, "--source", call.string("source")!, ...(givenReference === undefined ? [] : ["--reference", givenReference]), ...(withCheck ? ["--check"] : []), ...(scope.unnamed ? ["--project", root] : []));
|
|
400
453
|
const hints: string[] = [];
|
|
401
454
|
let nextAction: string | undefined;
|
|
402
455
|
if (reference === undefined) hints.push("No reference/ folder is in or beside the given pages, so the links to the reference are not checked. Give --reference <dir>, or run generate first.");
|
|
456
|
+
if (evidence.length > 0) {
|
|
457
|
+
hints.push(
|
|
458
|
+
"The project knowledge gives the files in evidence as evidence, and each file is missing or changed since the revisions in its item. For a coverage map that changed, put the map into the project knowledge again. For a file that you did not change on purpose, restore it from git. Else examine the facts of the revisions against the new file, and give the new file as evidence of the next write of these facts. Then run nextAction.",
|
|
459
|
+
);
|
|
460
|
+
if (shownEvidence.rest !== undefined) hints.push(`evidence is cut. To list all files, give ${shownEvidence.rest}.`);
|
|
461
|
+
}
|
|
403
462
|
if (problems.length > 0) {
|
|
404
463
|
hints.push("Correct each problem in problems.listed as its message tells. Then run nextAction.");
|
|
405
464
|
if (shownProblems.rest !== undefined) hints.push(`problems is cut. To list all problems, give ${shownProblems.rest}.`);
|
|
@@ -407,8 +466,9 @@ function link(call: Call): Reply {
|
|
|
407
466
|
} else if (check && links > 0) {
|
|
408
467
|
hints.push("Some links are not up to date. Run nextAction to write them.");
|
|
409
468
|
nextAction = again(false);
|
|
410
|
-
}
|
|
411
|
-
|
|
469
|
+
} else if (evidence.length > 0) nextAction = again(true);
|
|
470
|
+
// Evidence fails only a check: link without --check still writes the links.
|
|
471
|
+
return reply({ result: problems.length > 0 || (check && (links > 0 || evidence.length > 0)) ? "FAIL" : "PASS", ...output }, { ...(hints.length === 0 ? {} : { hint: hints.join(" ") }), nextAction });
|
|
412
472
|
}
|
|
413
473
|
|
|
414
474
|
const SOURCE = { kind: "path", value: "<dir>", help: "the folder of the source that was generated from the knowledge, relative to the project folder" } as const;
|
|
@@ -433,13 +493,13 @@ await runScript({
|
|
|
433
493
|
},
|
|
434
494
|
{
|
|
435
495
|
name: "link",
|
|
436
|
-
summary: "Links each name with its address in the pages to its line in the source, and checks every link and image. result is FAIL when a page has a problem, or with --check when a link is not up to date.",
|
|
496
|
+
summary: "Links each name with its address in the pages to its line in the source, and checks every link and image. result is FAIL when a page has a problem, or with --check when a link is not up to date or a file of the evidence of the knowledge is missing or changed.",
|
|
437
497
|
subjects: [{ name: "<page>", help: ".md files and folders of the documentation, relative to the project folder or the group folder, for example README.md docs. link reads each file and every .md file below each folder", list: true }],
|
|
438
498
|
options: {
|
|
439
499
|
// Text, not a path of the run: in a group, each project has the source and the reference at this path.
|
|
440
500
|
source: { kind: "text", value: "<dir>", help: `${SOURCE.help}. In a group, the same folder in each project`, required: true },
|
|
441
501
|
reference: { kind: "text", value: "<dir>", help: "the folder of the reference pages of generate, relative to the project folder; in a group, the same folder in each project. The default is the first reference/ folder in a given folder or beside a given page" },
|
|
442
|
-
check: { kind: "flag", help: "write
|
|
502
|
+
check: { kind: "flag", help: "write no page. FAIL when a link is not up to date, a page has a problem, or a file of the evidence of the knowledge is missing or changed" },
|
|
443
503
|
"max-listed": OPTIONS["max-listed"],
|
|
444
504
|
},
|
|
445
505
|
notes: "A name in backticks with its address in backticks after it, for example `draw_room` `$09BC`, becomes one link to the line of the name in the source. A name without an address gets no link. A name gets one link in each section, and a table gets no links. In a group folder, write the folder of the project before the name, for example `v2:draw_room` `$09BC`.",
|
|
@@ -40,7 +40,7 @@ export interface LinkContext {
|
|
|
40
40
|
managed: (path: string) => boolean;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export type ProblemKind = "unknown-name" | "wrong-address" | "repeated-link" | "link-in-table" | "missing-file" | "missing-anchor" | "missing-line" | "outside-project" | "outside-group" | "unknown-label" | "unlabelled-name" | "stale-reference";
|
|
43
|
+
export type ProblemKind = "unknown-name" | "wrong-address" | "repeated-link" | "link-in-table" | "missing-file" | "missing-anchor" | "missing-line" | "outside-project" | "outside-group" | "unknown-label" | "unlabelled-name" | "stale-reference" | "unreadable-knowledge";
|
|
44
44
|
|
|
45
45
|
export interface Problem {
|
|
46
46
|
page: string;
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
import { posix } from "node:path";
|
|
7
7
|
|
|
8
8
|
import { formatC64Address, POINTER_TABLE_TYPES, pointerTableEntries, type PointerTableType } from "#src/c64.ts";
|
|
9
|
+
import { IO_RAM } from "#src/host-client/coverage.ts";
|
|
9
10
|
import { bitmapFrame, charsetFrame, encodePng, PATTERN_PALETTES, scaleFrame, screenText, spriteSheet, type GraphicsMode } from "#src/graphics.ts";
|
|
10
11
|
import { mermaidGraph, ownerOf, routineEdges, routineHeads, type GraphReference, type RoutineHead } from "#src/knowledge/graph.ts";
|
|
11
12
|
import type { CommentRow, ModuleRow, ReferenceRow, RegionRow, SymbolRow } from "#src/knowledge/read.ts";
|
|
12
13
|
import type { RegionType } from "#src/knowledge/schema.ts";
|
|
14
|
+
import { platformNames } from "#src/platform.ts";
|
|
15
|
+
import { referenceHeader } from "#src/reference-pages.ts";
|
|
13
16
|
import type { SourceMap } from "./source-map.ts";
|
|
14
17
|
|
|
15
|
-
/** The first line of every generated page. A page without it is a page of a person, and docs.ts generate never writes over it. */
|
|
16
|
-
export const GENERATED_MARK = "<!-- Generated by c64-docs";
|
|
17
|
-
|
|
18
18
|
export interface ReferenceInput {
|
|
19
19
|
/** The reference directory, relative to the project folder. */
|
|
20
20
|
out: string;
|
|
@@ -40,11 +40,15 @@ const TABLE_TYPES: readonly RegionType[] = [...POINTER_TABLE_TYPES, "jumps", "wo
|
|
|
40
40
|
const GRAPHICS_TYPES: readonly RegionType[] = ["sprite", "bitmap", "charset", "screen"];
|
|
41
41
|
/** A list longer than this ends with the number of the rest. */
|
|
42
42
|
const MAX_LISTED = 40;
|
|
43
|
+
/** A list of one entry of a module page is shorter: the reader scans it. */
|
|
44
|
+
const MAX_FACTS = 12;
|
|
43
45
|
/** A call graph with more edges is not readable: then it shows the calls only, and at most this many. */
|
|
44
|
-
const MAX_EDGES =
|
|
46
|
+
const MAX_EDGES = 30;
|
|
45
47
|
/** A name outside the image covers the addresses that references use up to the next name, at most this many. */
|
|
46
48
|
const MAX_SPAN = 256;
|
|
47
|
-
/**
|
|
49
|
+
/** A source line that uses an ACME macro: +name, after a label or not. An anonymous label (+ alone) is no use. */
|
|
50
|
+
const MACRO_USE = /^\s*(?:[\w.]+\s+)?\+[A-Za-z_]/;
|
|
51
|
+
/** The kinds of a reference that reads a table: the decompiler gives an indexed read (lda table,x) as "reference". */
|
|
48
52
|
const TABLE_READS: readonly string[] = ["read", "reference", "pointer"];
|
|
49
53
|
|
|
50
54
|
const hex = (address: number) => formatC64Address(address).toUpperCase();
|
|
@@ -72,6 +76,8 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
72
76
|
const entries = new Map<string, Entry>();
|
|
73
77
|
const sortedNames = [...new Set([...input.symbols.map((symbol) => symbol.address), ...map.labels.filter((label) => label.file === "constants.asm").map((label) => label.address)])].sort((a, b) => a - b);
|
|
74
78
|
const nextName = (address: number) => sortedNames.find((other) => other > address);
|
|
79
|
+
/** A name of the platform covers only its register or area: RANDOM is $D41B, not the color RAM after it. */
|
|
80
|
+
const platformEnd = new Map(platformNames().map((entry) => [entry.name, entry.end]));
|
|
75
81
|
const regionAt = (address: number) => input.regions.find((region) => region.start <= address && region.end >= address);
|
|
76
82
|
const spanOf = (address: number, kind: string) => {
|
|
77
83
|
if (kind === "routine" || kind === "label") return address;
|
|
@@ -89,7 +95,8 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
89
95
|
// A name that c64-source makes (l_xxxx) is no entry: it has no meaning of its own.
|
|
90
96
|
if (symbol === undefined && label.file !== "constants.asm") continue;
|
|
91
97
|
const kind = symbol?.kind ?? "platform";
|
|
92
|
-
|
|
98
|
+
const platform = symbol === undefined ? platformEnd.get(label.name) : undefined;
|
|
99
|
+
entries.set(label.name, { name: label.name, address: label.address, kind, page: pageOfFile(label.file), spanEnd: platform ?? spanOf(label.address, kind) });
|
|
93
100
|
}
|
|
94
101
|
const entryAt = new Map<number, Entry>();
|
|
95
102
|
for (const entry of entries.values()) if (!entryAt.has(entry.address)) entryAt.set(entry.address, entry);
|
|
@@ -132,14 +139,52 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
132
139
|
const shown = named.base === address ? named.name : `${named.name}+${address - named.base}`;
|
|
133
140
|
return entries.has(named.name) ? entryOfName(page, named.name, shown) : codeOfName(page, named.name).replace(`\`${named.name}\``, `\`${shown}\``);
|
|
134
141
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
/** An address as the name that holds it, without the offset: a list names actor_queue once, not actor_queue+3 and actor_queue+6. */
|
|
143
|
+
const baseTarget = (page: string, address: number) => {
|
|
144
|
+
const named = nameFor(address);
|
|
145
|
+
if (named === undefined) return codeOfAddress(page, address);
|
|
146
|
+
return entries.has(named.name) ? entryOfName(page, named.name, named.name) : codeOfName(page, named.name);
|
|
147
|
+
};
|
|
148
|
+
const capped = (items: string[], limit = MAX_LISTED) => (items.length <= limit ? items.join(", ") : `${items.slice(0, limit).join(", ")} and ${items.length - limit} more`);
|
|
149
|
+
/**
|
|
150
|
+
* The references that use the data at their target. An access to the I/O area inside the image is the
|
|
151
|
+
* register, as the source writes it: it uses no data of the RAM under it, unless the knowledge names that
|
|
152
|
+
* address. So the code of the SID and the CIAs is no reader of the sprites in RAM at $d400 or $dc00.
|
|
153
|
+
*/
|
|
154
|
+
const named = new Set(input.symbols.map((symbol) => symbol.address));
|
|
155
|
+
const dataReferences = input.references.filter((reference) => !(reference.to >= IO_RAM.start && reference.to <= IO_RAM.end && input.image?.inImage(reference.to) === true && !named.has(reference.to)));
|
|
156
|
+
/**
|
|
157
|
+
* How the source line of a reference uses a platform name, as the source writes it: "named", "indexed"
|
|
158
|
+
* (name,x or name,y: the index can reach the registers after it), or undefined when the line does not
|
|
159
|
+
* name it, for example lda $d000,x with the character ROM in. "named" when the source text is not there,
|
|
160
|
+
* and for a macro use (+name): each byte of the macro maps to that line, which does not show its body.
|
|
161
|
+
*/
|
|
162
|
+
const platformUse = (reference: ReferenceRow, use: RegExp): "named" | "indexed" | undefined => {
|
|
163
|
+
const line = map.lineOf(reference.from);
|
|
164
|
+
const text = line === undefined ? undefined : map.textOf?.(line);
|
|
165
|
+
if (text === undefined || MACRO_USE.test(text)) return "named";
|
|
166
|
+
const found = use.exec(text);
|
|
167
|
+
return found === null ? undefined : found[1] === undefined ? "named" : "indexed";
|
|
168
|
+
};
|
|
169
|
+
/** The routines that read or write a range, each once and linked to its entry. `platform` is the platform name of the range. */
|
|
170
|
+
const ownersOf = (page: string, start: number, end: number, kind: string, platform?: string) => {
|
|
171
|
+
const use = platform === undefined ? undefined : new RegExp(`(?<![\\w.])${platform}(?!\\w)([^,)]*,\\s*[xXyY]\\b)?`);
|
|
172
|
+
// A routine with an indexed use and a direct use shows once, as indexed.
|
|
173
|
+
const owners = new Map<string, boolean>();
|
|
174
|
+
for (const reference of dataReferences) {
|
|
175
|
+
if (reference.kind !== kind || reference.to < start || reference.to > end) continue;
|
|
176
|
+
const how = use === undefined ? "named" : platformUse(reference, use);
|
|
177
|
+
if (how === undefined) continue;
|
|
178
|
+
const name = ownerAt(reference.from)?.name ?? hex(reference.from);
|
|
179
|
+
owners.set(name, (owners.get(name) ?? false) || how === "indexed");
|
|
180
|
+
}
|
|
181
|
+
return capped(
|
|
182
|
+
[...owners].map(([name, indexed]) => {
|
|
183
|
+
const shown = entries.has(name) ? entryOfName(page, name, name) : `\`${name}\``;
|
|
184
|
+
return indexed ? `${shown} (indexed)` : shown;
|
|
185
|
+
}),
|
|
142
186
|
);
|
|
187
|
+
};
|
|
143
188
|
|
|
144
189
|
// --- The routine graph ----------------------------------------------------
|
|
145
190
|
const tableReferences: GraphReference[] = [];
|
|
@@ -182,6 +227,12 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
182
227
|
return named === undefined ? codeOfAddress(page, from) : `${named} ${codeOfAddress(page, from)}`;
|
|
183
228
|
};
|
|
184
229
|
const edges = routineEdges(heads, boundaries, graphReferences);
|
|
230
|
+
/** The routine that holds an address, linked to its entry; the address when no routine holds it. */
|
|
231
|
+
const ownerLink = (page: string, from: number) => {
|
|
232
|
+
const owner = ownerAt(from);
|
|
233
|
+
if (owner === undefined) return codeOfAddress(page, from);
|
|
234
|
+
return entries.has(owner.name) ? entryOfName(page, owner.name, owner.name) : codeOfName(page, owner.name);
|
|
235
|
+
};
|
|
185
236
|
|
|
186
237
|
// --- File ranges ----------------------------------------------------------
|
|
187
238
|
const fileRanges = new Map<string, { start: number; end: number }>();
|
|
@@ -194,7 +245,7 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
194
245
|
}
|
|
195
246
|
const titleOf = (file: string) => input.modules.find((module) => module.file === file)?.title;
|
|
196
247
|
|
|
197
|
-
const header =
|
|
248
|
+
const header = referenceHeader(input.revision, map.mapPath);
|
|
198
249
|
const files: ReferenceFile[] = [];
|
|
199
250
|
const write = (path: string, lines: string[]) => files.push({ path, bytes: Buffer.from(`${[header, ...lines].join("\n").replace(/\n{3,}/g, "\n\n")}\n`, "utf8") });
|
|
200
251
|
|
|
@@ -204,9 +255,9 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
204
255
|
.filter((comment) => comment.address === address)
|
|
205
256
|
.sort((a, b) => (a.placement === b.placement ? 0 : a.placement === "line" ? -1 : 1))
|
|
206
257
|
.map((comment) => comment.text.replace(/\s*\r?\n\s*/g, " ").trim());
|
|
207
|
-
const incoming = (entry: Entry) =>
|
|
258
|
+
const incoming = (entry: Entry) => dataReferences.filter((reference) => reference.to >= entry.address && reference.to <= entry.spanEnd);
|
|
208
259
|
const outgoing = (head: RoutineHead) => input.references.filter((reference) => ownerAt(reference.from)?.address === head.address);
|
|
209
|
-
const entryText = (page: string, entry: Entry): string[] => {
|
|
260
|
+
const entryText = (page: string, entry: Entry, labels: readonly Entry[]): string[] => {
|
|
210
261
|
const lines = ["", `<a id="${entry.name}"></a>`, `### ${codeOfName(page, entry.name)} \`${entry.spanEnd > entry.address ? range(entry.address, entry.spanEnd) : hex(entry.address)}\``, "", `*${entry.kind}*`];
|
|
211
262
|
const comments = commentLines(entry.address);
|
|
212
263
|
if (comments.length > 0) lines.push("", ...comments);
|
|
@@ -218,9 +269,9 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
218
269
|
const by = (kinds: readonly string[]) =>
|
|
219
270
|
fromOthers
|
|
220
271
|
.filter((reference) => kinds.includes(reference.kind) && !((reference.kind === "reference" || reference.kind === "pointer") && strong.has(reference.from)))
|
|
221
|
-
.map((reference) =>
|
|
272
|
+
.map((reference) => ownerLink(page, reference.from));
|
|
222
273
|
const add = (label: string, items: string[]) => {
|
|
223
|
-
if (items.length > 0) facts.push(`- **${label}:** ${capped([...new Set(items)])}`);
|
|
274
|
+
if (items.length > 0) facts.push(`- **${label}:** ${capped([...new Set(items)], MAX_FACTS)}`);
|
|
224
275
|
};
|
|
225
276
|
add("Called from", by(["call"]));
|
|
226
277
|
add("Jumped to from", by(["jump"]));
|
|
@@ -237,7 +288,7 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
237
288
|
const all = outgoing(head);
|
|
238
289
|
const named = new Set(all.filter((reference) => reference.kind !== "reference" && reference.kind !== "pointer").map((reference) => `${reference.from}:${reference.to}`));
|
|
239
290
|
const from = all.filter((reference) => !((reference.kind === "reference" || reference.kind === "pointer") && named.has(`${reference.from}:${reference.to}`)));
|
|
240
|
-
const to = (kinds: readonly string[]) => from.filter((reference) => kinds.includes(reference.kind) && ownerAt(reference.to)?.address !== head.address).map((reference) =>
|
|
291
|
+
const to = (kinds: readonly string[]) => from.filter((reference) => kinds.includes(reference.kind) && ownerAt(reference.to)?.address !== head.address).map((reference) => baseTarget(page, reference.to));
|
|
241
292
|
add("Calls", to(["call"]));
|
|
242
293
|
add("Jumps to", to(["jump"]));
|
|
243
294
|
add("Reads", to(["read"]));
|
|
@@ -245,8 +296,17 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
245
296
|
add("Refers to", to(["reference", "pointer"]));
|
|
246
297
|
}
|
|
247
298
|
if (facts.length > 0) lines.push("", ...facts);
|
|
248
|
-
return lines;
|
|
299
|
+
return [...lines, ...labelTable(page, labels)];
|
|
249
300
|
};
|
|
301
|
+
/** The labels that only code of their own file reaches: one row each, with the anchor that links to the label. */
|
|
302
|
+
const labelTable = (page: string, labels: readonly Entry[]) =>
|
|
303
|
+
labels.length === 0
|
|
304
|
+
? []
|
|
305
|
+
: ["", "| Label | Address | Comment |", "|---|---|---|", ...labels.map((label) => `| <a id="${label.name}"></a>${codeOfName(page, label.name)} | \`${hex(label.address)}\` | ${commentLines(label.address).join(" ").replace(/\|/g, "\\|")} |`)];
|
|
306
|
+
const entersAt = new Map<number, ReferenceRow[]>();
|
|
307
|
+
for (const reference of input.references) if (reference.kind === "call" || reference.kind === "jump") entersAt.set(reference.to, [...(entersAt.get(reference.to) ?? []), reference]);
|
|
308
|
+
// A pointer to code (lda #<irq_handler) is a vector: the CPU enters there from no file.
|
|
309
|
+
const pointedAt = new Set(input.references.filter((reference) => reference.kind === "pointer").map((reference) => reference.to));
|
|
250
310
|
const tableAnchor = (table: RegionRow) => entryAt.get(table.start)?.name ?? `table_${table.start.toString(16).padStart(4, "0")}`;
|
|
251
311
|
function tableLink(page: string, table: RegionRow): string {
|
|
252
312
|
return `[\`${entryAt.get(table.start)?.name ?? range(table.start, table.end)}\`](${rel(page, posix.join(out, "tables.md"))}#${tableAnchor(table)})`;
|
|
@@ -266,16 +326,31 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
266
326
|
const own = (pieceEntries.get(file) ?? []).sort((a, b) => a.address - b.address);
|
|
267
327
|
const title = titleOf(file);
|
|
268
328
|
const lines = [`# ${file}${title === undefined ? "" : `: ${title}`}`, "", `Range \`${span === undefined ? "-" : range(span.start, span.end)}\`. Source: [${file}](${rel(page, map.pathOf(file))}). Index: [the reference](${rel(page, posix.join(out, "index.md"))}).`];
|
|
329
|
+
// A label that only code of this file enters is a row: under the routine that holds it, else in the labels of the page.
|
|
330
|
+
const headAt = new Set(heads.map((head) => head.address));
|
|
331
|
+
const fromOtherFiles = (address: number) => (entersAt.get(address) ?? []).filter((reference) => map.lineOf(reference.from)?.file !== file);
|
|
332
|
+
const mains = new Set(own.filter((entry) => entry.kind !== "label" || headAt.has(entry.address) || pointedAt.has(entry.address) || fromOtherFiles(entry.address).length > 0).map((entry) => entry.address));
|
|
333
|
+
const labelsOf = new Map<number | undefined, Entry[]>();
|
|
334
|
+
for (const entry of own) {
|
|
335
|
+
if (mains.has(entry.address)) continue;
|
|
336
|
+
const owner = ownerAt(entry.address)?.address;
|
|
337
|
+
const group = owner !== undefined && mains.has(owner) ? owner : undefined;
|
|
338
|
+
labelsOf.set(group, [...(labelsOf.get(group) ?? []), entry]);
|
|
339
|
+
}
|
|
269
340
|
if (span !== undefined) {
|
|
270
341
|
const inside = (address: number) => address >= span.start && address <= span.end;
|
|
271
|
-
const ownHeads =
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
if (
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
342
|
+
const ownHeads = heads.filter((head) => inside(head.address));
|
|
343
|
+
// The overview: each routine, and each label that code of another file enters.
|
|
344
|
+
const starts = [...new Set([...ownHeads.map((head) => head.address), ...own.filter((entry) => mains.has(entry.address) && (entry.kind === "routine" || entry.kind === "label")).map((entry) => entry.address)])].sort((a, b) => a - b);
|
|
345
|
+
if (starts.length > 0) {
|
|
346
|
+
lines.push("", "## Routines", "", "| Routine | Address | Reached from | Summary |", "|---|---|---|---|");
|
|
347
|
+
for (const start of starts) {
|
|
348
|
+
const name = entryAt.get(start)?.name ?? ownHeads.find((head) => head.address === start)!.name;
|
|
349
|
+
const shown = entries.has(name) ? entryOfName(page, name, name) : codeOfName(page, name);
|
|
350
|
+
const callers = [...new Set([...edges.filter((edge) => edge.to === start && edge.kind !== "jump").map((edge) => edge.from), ...fromOtherFiles(start).map((reference) => reference.from)].map((from) => ownerLink(page, from)))];
|
|
351
|
+
const summary = /^.*?[.!?](?=\s|$)|^.*$/.exec(commentLines(start).join(" "))![0].replace(/\|/g, "\\|");
|
|
352
|
+
lines.push(`| ${shown} | \`${hex(start)}\` | ${capped(callers, MAX_FACTS)} | ${summary} |`);
|
|
353
|
+
}
|
|
279
354
|
}
|
|
280
355
|
const regions = input.regions.filter((region) => region.start <= span.end && region.end >= span.start && region.type !== "code");
|
|
281
356
|
if (regions.length > 0) {
|
|
@@ -286,9 +361,20 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
286
361
|
lines.push(`| ${codeOfAddress(page, region.start)}${region.end === region.start ? "" : `-\`${hex(region.end)}\``} | ${region.type}${region.element === undefined ? "" : ` of ${region.element}`} | ${name === undefined ? "" : codeOfName(page, name.name)} | ${owners("read")} | ${owners("write")} |`);
|
|
287
362
|
}
|
|
288
363
|
}
|
|
364
|
+
// Jumps are the control flow inside a group of routines: the graph draws the calls and the table entries only.
|
|
365
|
+
const ownAt = new Set(ownHeads.map((head) => head.address));
|
|
366
|
+
const reaching = edges.filter((edge) => edge.kind !== "jump" && (ownAt.has(edge.from) || ownAt.has(edge.to)));
|
|
367
|
+
const shown = reaching.slice(0, MAX_EDGES);
|
|
368
|
+
if (shown.length > 0) {
|
|
369
|
+
lines.push("", "## Call graph", "", "A solid arrow is a call, a thick arrow a table entry. Rounded nodes are in this file.");
|
|
370
|
+
if (shown.length < reaching.length) lines.push("", `The graph shows ${shown.length} of the ${reaching.length} edges.`);
|
|
371
|
+
lines.push("", "```mermaid", mermaidGraph(heads, shown, ownAt), "```");
|
|
372
|
+
}
|
|
289
373
|
}
|
|
290
|
-
if (own.length > 0) lines.push("", "##
|
|
291
|
-
for (const entry of own) lines.push(...entryText(page, entry));
|
|
374
|
+
if (own.length > 0) lines.push("", "## Details");
|
|
375
|
+
for (const entry of own) if (mains.has(entry.address)) lines.push(...entryText(page, entry, labelsOf.get(entry.address) ?? []));
|
|
376
|
+
const loose = labelsOf.get(undefined) ?? [];
|
|
377
|
+
if (loose.length > 0) lines.push("", "## Labels", ...labelTable(page, loose));
|
|
292
378
|
counts.entries += own.length;
|
|
293
379
|
write(page, lines);
|
|
294
380
|
}
|
|
@@ -369,7 +455,7 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
|
|
|
369
455
|
lines.push("", "## Variables outside the program", "", "| Address | Name | Comment | Read by | Written by |", "|---|---|---|---|---|");
|
|
370
456
|
for (const entry of outside) {
|
|
371
457
|
const at = `\`${entry.spanEnd > entry.address ? range(entry.address, entry.spanEnd) : hex(entry.address)}\``;
|
|
372
|
-
const owners = (kind: string) => ownersOf(page, entry.address, entry.spanEnd, kind);
|
|
458
|
+
const owners = (kind: string) => ownersOf(page, entry.address, entry.spanEnd, kind, entry.kind === "platform" ? entry.name : undefined);
|
|
373
459
|
lines.push(`| ${at} | <a id="${entry.name}"></a>${codeOfName(page, entry.name)} | ${commentLines(entry.address).join(" ").replace(/\|/g, "\\|")} | ${owners("read")} | ${owners("write")} |`);
|
|
374
460
|
}
|
|
375
461
|
counts.entries += outside.length;
|
|
@@ -32,6 +32,8 @@ export interface SourceMap {
|
|
|
32
32
|
lineOf: (address: number) => SourceLine | undefined;
|
|
33
33
|
/** The project path of a source file. */
|
|
34
34
|
pathOf: (file: string) => string;
|
|
35
|
+
/** The text of a source line, without its comment; undefined when the file or the line is not there. */
|
|
36
|
+
textOf?: (line: SourceLine) => string | undefined;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
/** Reads the source map of the source in `directory` of the project `root`. A missing map is a refusal with the remedy. */
|
|
@@ -61,6 +63,7 @@ export function readSourceMap(directory: string, root?: string): SourceMap {
|
|
|
61
63
|
.map((item) => ({ start: parseC64Address(String(item.start)), end: parseC64Address(String(item.end)), file: String(item.file), line: Number(item.line) }))
|
|
62
64
|
.sort((a, b) => a.start - b.start);
|
|
63
65
|
const byName = new Map(labels.map((label) => [label.name, label]));
|
|
66
|
+
const texts = new Map<string, string[] | undefined>();
|
|
64
67
|
return {
|
|
65
68
|
directory,
|
|
66
69
|
mapPath: path,
|
|
@@ -82,5 +85,16 @@ export function readSourceMap(directory: string, root?: string): SourceMap {
|
|
|
82
85
|
return undefined;
|
|
83
86
|
},
|
|
84
87
|
pathOf: (file) => posix.join(directory, file),
|
|
88
|
+
textOf: (line) => {
|
|
89
|
+
if (!texts.has(line.file)) {
|
|
90
|
+
try {
|
|
91
|
+
texts.set(line.file, readProjectFile(posix.join(directory, line.file), root === undefined ? {} : { root }).bytes.toString("utf8").split(/\r?\n/));
|
|
92
|
+
} catch {
|
|
93
|
+
texts.set(line.file, undefined);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const text = texts.get(line.file)?.[line.line - 1];
|
|
97
|
+
return text?.replace(/;.*$/, "");
|
|
98
|
+
},
|
|
85
99
|
};
|
|
86
100
|
}
|
|
@@ -35,7 +35,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
|
|
|
35
35
|
| Write all knowledge to one file | `export --out .c64-re-tools/local/knowledge.json` |
|
|
36
36
|
| Find what the knowledge holds of the program | `program` |
|
|
37
37
|
| Put a captured program into the knowledge | `image .c64-re-tools/local/capture/image.json` |
|
|
38
|
-
| Put a PRG into the knowledge | `image
|
|
38
|
+
| Put a PRG into the knowledge | `image releases/game.prg` |
|
|
39
39
|
| Put drive code into the knowledge | `image drive.prg --space drive8` |
|
|
40
40
|
| Add the coverage of runs | `coverage .c64-re-tools/local/runs/rooms/room0.bin` |
|
|
41
41
|
| Name the symbol at an address | `rename '$2100' update_player --kind routine --reason 'reads joystick 2'` |
|
|
@@ -48,8 +48,8 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
|
|
|
48
48
|
| Find the places that a removal blocks | `suppressions --range '$2000-$2fff'` |
|
|
49
49
|
| Start a file of the generated source | `module '$2000' game/player.asm --title 'Player movement'` |
|
|
50
50
|
| Write the operand of an instruction as an expression | `operand '$8079' --lo irq_handler` |
|
|
51
|
-
| Record a release of the program | `release
|
|
52
|
-
| Write a switch | `switch PROTECTION --kind protection --releases
|
|
51
|
+
| Record a release of the program | `release FIRESTAR --file releases/game.prg --base` |
|
|
52
|
+
| Write a switch | `switch PROTECTION --kind protection --releases FIRESTAR` |
|
|
53
53
|
| Write the code of a switch for a range | `patch '$100e-$1010' PROTECTION --code-file no-check.asm` |
|
|
54
54
|
| List the releases, switches and patches | `switches` |
|
|
55
55
|
| Record the start screen of the program | `start-screen --mode multicolour --screen '$5c00' --bitmap '$6000' --colours '$8328' --border 0 --background 0` |
|
|
@@ -70,7 +70,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
|
|
|
70
70
|
## Addresses, names and spaces
|
|
71
71
|
|
|
72
72
|
- A symbol is the name of an address from the user or the LLM. Get it from `at`, `search` or `symbols`.
|
|
73
|
-
- An analyzer name is a second name from DXA,
|
|
73
|
+
- An analyzer name is a second name from DXA, the decompiler or an idiom search, for example `FUN_17e2`. Each analyzer keeps its own name at an address. Get them from `at`, `search` or `symbols --analyzer`.
|
|
74
74
|
- The generated source uses only the symbols. To use an analyzer name in the source, give the address that name with `rename`.
|
|
75
75
|
- A symbol name is a label for ACME: a letter or an underscore, then letters, digits or underscores. The knowledge refuses the name of a 6502 instruction, for example `lda`, in upper or lower case.
|
|
76
76
|
- A space is `c64` (the default), `drive8` for code in the 1541 drive, `loading` or `bank0` to `bank255`. `loading` is the captured stage of the loading that shows the start screen. `bank0` to `bank255` are cartridge banks, or other memory images of the program, for example a file that the program loads later. Drive code, the stage and banks use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
|
|
@@ -82,7 +82,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
|
|
|
82
82
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
83
83
|
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
84
84
|
- In a group folder, each version of a program is a project. The script refuses the group folder and each folder in it that is not a project. Give `--project` with a project of the group, for example `--project v1`.
|
|
85
|
-
- A path that a command only reads can go into another project of the group, for example `../v1/
|
|
85
|
+
- A path that a command only reads can go into another project of the group, for example `../v1/releases/game.prg`. The command writes only in its own project.
|
|
86
86
|
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
87
87
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
88
88
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
@@ -113,7 +113,7 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
113
113
|
| `--evidence <kind:ref>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
|
|
114
114
|
| `--expect-revision <revision>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
|
|
115
115
|
| `--range <start>-<end>` | `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `uses`, `export` | Only the rows in this range. The default is all addresses. |
|
|
116
|
-
| `--origin <origin>` | `search`, `symbols`, `regions`, `comments`, `references`, `modules`, `operands`, `patches`, `macros`, `uses`, `export` | Only the rows of these origins: `user`, `llm`, `dxa`, `
|
|
116
|
+
| `--origin <origin>` | `search`, `symbols`, `regions`, `comments`, `references`, `modules`, `operands`, `patches`, `macros`, `uses`, `export` | Only the rows of these origins: `user`, `llm`, `dxa`, `decompiler`, `heuristic`, `semantic` (user and llm), `analyzer` (dxa, decompiler and heuristic), or a comma list. The default is all origins. |
|
|
117
117
|
| `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing`, `join` | The most items in each list of the body. The default is 50. The counts are always complete. |
|
|
118
118
|
| `--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. |
|
|
119
119
|
| `--kind <kind>` | `references` | Only references of this kind: `call`, `jump`, `read`, `write`, `reference` or `pointer`. |
|
|
@@ -200,7 +200,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
200
200
|
### `suppressions`
|
|
201
201
|
|
|
202
202
|
- `body.suppressions` lists the places that a removal blocks. Each item has `suppresses` (`symbol`, `region` or `reference`), the place, and the `reason` of the removal.
|
|
203
|
-
- `unclassify` and `unreference` block the place for DXA and
|
|
203
|
+
- `unclassify` and `unreference` block the place for DXA and the decompiler. A later analysis does not add a region in that range or that reference again. This is also true for a fact from the LLM.
|
|
204
204
|
- `remove-symbol` does not block the address, because an analyzer name never becomes a symbol.
|
|
205
205
|
- A `rename`, `classify` or `reference` at a blocked place ends the block there. A `revert` to a revision before the removal also ends the block.
|
|
206
206
|
- `at` and `history` also show the blocks.
|
|
@@ -251,7 +251,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
251
251
|
- `body.lines` has `count` and `listed`. `listed` holds one line for each instruction of a code region, and one `!byte` line for other bytes.
|
|
252
252
|
- Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames`, `lineComments` and `comment`. `lineComments` are the line comments before the line. `comment` is the side comment.
|
|
253
253
|
- `text` is the instruction with the names of its target. An operand expression of the knowledge replaces the operand.
|
|
254
|
-
-
|
|
254
|
+
- `access` is there when the knowledge has coverage. It tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line. `-` tells that no run did. An `r` on code can come from a read of the 6502 that the program does not do. Examples are the third byte of a JSR and the opcode after a branch that the CPU takes. Another example is the opcode at the PC when an interrupt starts. An indexed read (`lda table,x`) that crosses a page also reads the byte $100 below its target. A read watchpoint does not stop at these reads.
|
|
255
255
|
- With `--out`, the body has `lines` as a number, and `out`, `bytes` and `sha256` of the text file.
|
|
256
256
|
- If the knowledge has no program in the space, the script refuses. Put the program in with `image` first.
|
|
257
257
|
- Use `listing` in place of your own disassembler.
|
|
@@ -279,7 +279,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
|
|
|
279
279
|
### `revision <revision>`
|
|
280
280
|
|
|
281
281
|
- `body.revision` gives the revision. `body.added` and `body.closed` list the rows that it added and closed.
|
|
282
|
-
- The rows include the memory, entry and coverage rows of the program.
|
|
282
|
+
- The rows include the memory, entry and coverage rows of the program. A coverage row gives the `map`, the access `kind` and the number of `ranges` of that kind in the map.
|
|
283
283
|
|
|
284
284
|
---
|
|
285
285
|
|
|
@@ -396,7 +396,7 @@ A rebuild keeps all of the program in the source: unused bytes, dead code, old c
|
|
|
396
396
|
Do not write a file of the rebuild by hand, for example a boot file, a packed picture or a script that changes bytes. Record each change in the knowledge, and generate the source.
|
|
397
397
|
|
|
398
398
|
- `--file` is a PRG or the `image.json` of a capture. The project knowledge keeps the bytes of the release. After the write, the project does not need the file. A capture can stay in `.c64-re-tools/local/`.
|
|
399
|
-
- A label is upper case, for example `
|
|
399
|
+
- A label is upper case, for example `FIRESTAR`, `TBC` or `V2`.
|
|
400
400
|
- 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.
|
|
401
401
|
- A space has one base release. Record the base release before the first switch.
|
|
402
402
|
- The build of a release gives each switch the value of that release. The check of the generated source compares that build with the bytes of the release in the project knowledge.
|
|
@@ -435,8 +435,8 @@ Use this when a stage of the loading shows the screen, and the program at the en
|
|
|
435
435
|
#### A start screen in the program
|
|
436
436
|
|
|
437
437
|
- Capture the program while the bytes of the screen are in memory.
|
|
438
|
-
- Get the mode, the addresses and the colours from the VIC-II while the
|
|
439
|
-
- Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while
|
|
438
|
+
- Get the mode, the addresses and the colours from the VIC-II while the program of the base release shows the screen.
|
|
439
|
+
- Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while that program shows the screen. Give their address with `--colours`. If the program does not have them, give one colour with `--colour`.
|
|
440
440
|
|
|
441
441
|
#### The rules of the VIC-II
|
|
442
442
|
|
|
@@ -540,8 +540,9 @@ A macro writes a run of instructions as one line of the source, for example `+in
|
|
|
540
540
|
### `coverage <map>...`
|
|
541
541
|
|
|
542
542
|
- `<map>` is a 64 KiB coverage map of a run. Write each map in `.c64-re-tools/local/`.
|
|
543
|
-
- `body` holds `revision`, `imported`, `known` and `
|
|
544
|
-
-
|
|
543
|
+
- `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 are the latest map of their path in the space already. `added` and `removed` count the ranges of accesses that the coverage gets and loses. When both are 0, the source and the reference do not change.
|
|
544
|
+
- The knowledge keeps one map for each path in a space. A new map of a path replaces the earlier map of that path. Thus, after you record a run again into the same folder, put its new map into the project knowledge. Then the coverage has only the new run of that folder.
|
|
545
|
+
- The coverage of a space is the union of its maps. It has each address that a run executed, read or wrote. It also has each address that one run wrote and executed: self-modified code.
|
|
545
546
|
- `coverage` puts each map into the space of `--space`. You can add the same map to each space.
|
|
546
547
|
- `--evidence coverage:<map>` names a map by its path at the import. It refers to the last import of that map into the space of the write.
|
|
547
548
|
|