@henols/c64-re-tools 2.6.0-rc.2 → 2.6.0-rc.20

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.
Files changed (107) hide show
  1. package/package.json +2 -2
  2. package/skills/c64-assembler/SKILL.md +28 -14
  3. package/skills/c64-assembler/scripts/assembler.ts +28 -15
  4. package/skills/c64-development/SKILL.md +4 -4
  5. package/skills/c64-docs/SKILL.md +9 -7
  6. package/skills/c64-docs/scripts/docs.ts +24 -11
  7. package/skills/c64-docs/scripts/lib/reference.ts +119 -33
  8. package/skills/c64-docs/scripts/lib/source-map.ts +23 -4
  9. package/skills/c64-knowledge/SKILL.md +67 -42
  10. package/skills/c64-knowledge/scripts/knowledge.ts +90 -67
  11. package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
  12. package/skills/c64-packer/SKILL.md +1 -1
  13. package/skills/c64-provenance/SKILL.md +11 -10
  14. package/skills/c64-provenance/scripts/lib/library.ts +16 -16
  15. package/skills/c64-provenance/scripts/provenance.ts +33 -23
  16. package/skills/c64-reverse-engineering/SKILL.md +17 -11
  17. package/skills/c64-source/SKILL.md +71 -47
  18. package/skills/c64-source/scripts/lib/export.ts +89 -34
  19. package/skills/c64-source/scripts/lib/loader.ts +79 -36
  20. package/skills/c64-source/scripts/lib/source.ts +38 -32
  21. package/skills/c64-source/scripts/lib/stage.ts +11 -5
  22. package/skills/c64-source/scripts/lib/start-screen.asm +4 -2
  23. package/skills/c64-source/scripts/source.ts +278 -145
  24. package/skills/c64-static-analysis/SKILL.md +29 -25
  25. package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
  26. package/skills/c64-static-analysis/scripts/lib/findings.ts +11 -11
  27. package/skills/c64-static-analysis/scripts/lib/instructions.ts +26 -24
  28. package/skills/c64-static-analysis/scripts/lib/macros.ts +3 -1
  29. package/skills/c64-static-analysis/scripts/static-analysis.ts +69 -67
  30. package/skills/c64-testing/SKILL.md +15 -5
  31. package/skills/c64-testing/references/recording-format.md +26 -5
  32. package/skills/c64-testing/references/scenario-format.md +11 -8
  33. package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
  34. package/skills/c64-testing/scripts/lib/play.ts +39 -41
  35. package/skills/c64-testing/scripts/lib/recording.ts +220 -46
  36. package/skills/c64-testing/scripts/lib/replay.ts +32 -6
  37. package/skills/c64-testing/scripts/lib/runs.ts +8 -3
  38. package/skills/c64-testing/scripts/lib/scenario.ts +18 -11
  39. package/skills/c64-testing/scripts/testing.ts +23 -2
  40. package/skills/c64-unpacker/SKILL.md +10 -5
  41. package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
  42. package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
  43. package/skills/c64-unpacker/scripts/lib/stages.ts +18 -3
  44. package/skills/c64-unpacker/scripts/unpacker.ts +43 -9
  45. package/skills/emulator/SKILL.md +7 -12
  46. package/src/build-name.ts +55 -0
  47. package/src/c64-keys.ts +98 -0
  48. package/src/c64.ts +22 -2
  49. package/src/cli/main.ts +3 -29
  50. package/src/host/main.ts +3 -3
  51. package/src/host/server.ts +3 -1
  52. package/src/host/tools/index.ts +2 -7
  53. package/src/host/vice/process.ts +34 -17
  54. package/src/host/vice/session.ts +138 -31
  55. package/src/host-client/steps.ts +21 -18
  56. package/src/host-client/tools.ts +2 -7
  57. package/src/host-client/vice-session.ts +7 -1
  58. package/src/knowledge/evidence.ts +66 -0
  59. package/src/knowledge/history.ts +5 -5
  60. package/src/knowledge/import.ts +12 -5
  61. package/src/knowledge/program.ts +123 -32
  62. package/src/knowledge/read.ts +36 -13
  63. package/src/knowledge/schema.ts +43 -17
  64. package/src/knowledge/start-screen.ts +70 -0
  65. package/src/knowledge/text.ts +33 -5
  66. package/src/knowledge/write.ts +75 -36
  67. package/src/mcp/inputs.ts +12 -0
  68. package/src/mcp/server.ts +1 -1
  69. package/src/mcp/tools/debug.ts +23 -21
  70. package/src/mcp/tools/input.ts +38 -5
  71. package/src/mcp/tools/machine.ts +3 -42
  72. package/src/mcp/tools/media.ts +1 -1
  73. package/src/mcp/tools/memory.ts +12 -9
  74. package/src/native/acme.ts +1 -1
  75. package/src/native/c64run.ts +7 -4
  76. package/src/native/decompiler/analyze.ts +98 -0
  77. package/src/native/decompiler/c64rt-wasm.ts +4 -0
  78. package/src/native/decompiler/language/c64rt_6510.sla +0 -0
  79. package/src/native/{ghidra → decompiler}/language/c64rt_6510.slaspec +1 -1
  80. package/src/native/decompiler/pcode.ts +222 -0
  81. package/src/native/decompiler/walk.ts +205 -0
  82. package/src/native/decompiler/wasm.ts +98 -0
  83. package/src/native/discover.ts +3 -3
  84. package/src/native/dxa.ts +12 -1
  85. package/src/native/processes.ts +4 -4
  86. package/src/native/types.ts +27 -27
  87. package/src/opcodes.ts +1 -1
  88. package/src/platform.ts +30 -1
  89. package/src/project.ts +17 -4
  90. package/src/protocol/tools.ts +1 -45
  91. package/src/protocol/vice.ts +47 -0
  92. package/src/reference-pages.ts +64 -0
  93. package/src/script.ts +4 -4
  94. package/src/vsf.ts +98 -0
  95. package/tools/c64run.c +158 -15
  96. package/tools/install-container.sh +1 -2
  97. package/src/cli/status.ts +0 -127
  98. package/src/host/tools/status.ts +0 -47
  99. package/src/native/ghidra/analyze.ts +0 -87
  100. package/src/native/ghidra/index.ts +0 -170
  101. package/src/native/ghidra/scripts/C64Export.java +0 -274
  102. package/src/native/ghidra/scripts/C64Prepare.java +0 -66
  103. package/src/native/status.ts +0 -135
  104. package/tools/install-ghidra.sh +0 -40
  105. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.cspec +0 -0
  106. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.ldefs +0 -0
  107. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.pspec +0 -0
@@ -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;
@@ -34,17 +34,21 @@ export interface ReferenceFile {
34
34
  bytes: Buffer;
35
35
  }
36
36
 
37
- /** Files that the source map lists but that hold no code of the program. */
38
- const NOT_PIECES = new Set(["main.asm", "constants.asm", "macros.asm", "loader.asm"]);
37
+ /** Files that the source map lists but that hold no code of the program: they get no module page. */
38
+ const NOT_PIECES = new Set(["main.asm", "constants.asm", "macros.asm", "loader.asm", "config.asm", "switches.asm", "start_screen.asm", "start_screen_stage.asm"]);
39
39
  const TABLE_TYPES: readonly RegionType[] = [...POINTER_TABLE_TYPES, "jumps", "words"];
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 = 60;
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
- /** The kinds of a reference that reads a table: Ghidra gives an indexed read (lda table,x) as "reference". */
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
- entries.set(label.name, { name: label.name, address: label.address, kind, page: pageOfFile(label.file), spanEnd: spanOf(label.address, kind) });
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
- const capped = (items: string[]) => (items.length <= MAX_LISTED ? items.join(", ") : `${items.slice(0, MAX_LISTED).join(", ")} and ${items.length - MAX_LISTED} more`);
136
- /** The routines that read or write a range, each linked to its entry. */
137
- const ownersOf = (page: string, start: number, end: number, kind: string) =>
138
- capped(
139
- [...new Set(input.references.filter((reference) => reference.kind === kind && reference.to >= start && reference.to <= end).map((reference) => ownerAt(reference.from)?.name ?? hex(reference.from)))].map((name) =>
140
- entries.has(name) ? entryOfName(page, name, name) : `\`${name}\``,
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 = `${GENERATED_MARK} from knowledge revision ${input.revision} and ${map.pathOf("source-map.json")}. Do not edit: change the knowledge, generate the source again, then run docs.ts generate. -->`;
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) => input.references.filter((reference) => reference.to >= entry.address && reference.to <= entry.spanEnd);
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) => site(page, reference.from) + (reference.to === entry.address ? "" : ` (+${reference.to - entry.address})`));
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) => target(page, reference.to));
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 = new Set(heads.filter((head) => inside(head.address)).map((head) => head.address));
272
- let shown = edges.filter((edge) => ownHeads.has(edge.from) || ownHeads.has(edge.to));
273
- const all = shown.length;
274
- if (shown.length > MAX_EDGES) shown = shown.filter((edge) => edge.kind === "call").slice(0, MAX_EDGES);
275
- if (shown.length > 0) {
276
- lines.push("", "## Call graph", "", "A solid arrow is a call, a thick arrow a table entry, a dotted arrow a jump. Rounded nodes are in this file.");
277
- if (shown.length < all) lines.push("", `The graph shows ${shown.length} of the ${all} edges: the calls only.`);
278
- lines.push("", "```mermaid", mermaidGraph(heads, shown, ownHeads), "```");
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("", "## Names");
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;
@@ -1,5 +1,6 @@
1
- // The source map that c64-source writes next to the source: the line of
2
- // each name and of each address. The documentation links to these lines.
1
+ // The source map of a generated source: the line of each name and of each
2
+ // address. The generation writes it to the local folder of the project, not
3
+ // next to the source. The documentation links to these lines.
3
4
 
4
5
  import { posix } from "node:path";
5
6
 
@@ -7,6 +8,7 @@ import { parseC64Address } from "#src/c64.ts";
7
8
  import { WireFailure } from "#src/host-client/tools.ts";
8
9
  import { readProjectFile } from "#src/host-client/transfer.ts";
9
10
  import type { Space } from "#src/knowledge/schema.ts";
11
+ import { generatedDirectory } from "#src/project.ts";
10
12
 
11
13
  export const SOURCE_MAP_FILE = "source-map.json";
12
14
 
@@ -18,6 +20,8 @@ export interface SourceLine {
18
20
  export interface SourceMap {
19
21
  /** The source directory, relative to the project folder. */
20
22
  directory: string;
23
+ /** The source map file, relative to the project folder. */
24
+ mapPath: string;
21
25
  space: Space;
22
26
  revision: string;
23
27
  files: string[];
@@ -28,11 +32,13 @@ export interface SourceMap {
28
32
  lineOf: (address: number) => SourceLine | undefined;
29
33
  /** The project path of a source file. */
30
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;
31
37
  }
32
38
 
33
- /** Reads <directory>/source-map.json of the project `root`. A missing map is a refusal with the remedy. */
39
+ /** Reads the source map of the source in `directory` of the project `root`. A missing map is a refusal with the remedy. */
34
40
  export function readSourceMap(directory: string, root?: string): SourceMap {
35
- const path = posix.join(directory, SOURCE_MAP_FILE);
41
+ const path = posix.join(generatedDirectory(directory), SOURCE_MAP_FILE);
36
42
  let text: string;
37
43
  try {
38
44
  text = readProjectFile(path, root === undefined ? {} : { root }).bytes.toString("utf8");
@@ -57,8 +63,10 @@ export function readSourceMap(directory: string, root?: string): SourceMap {
57
63
  .map((item) => ({ start: parseC64Address(String(item.start)), end: parseC64Address(String(item.end)), file: String(item.file), line: Number(item.line) }))
58
64
  .sort((a, b) => a.start - b.start);
59
65
  const byName = new Map(labels.map((label) => [label.name, label]));
66
+ const texts = new Map<string, string[] | undefined>();
60
67
  return {
61
68
  directory,
69
+ mapPath: path,
62
70
  space: String(raw.space ?? "c64") as Space,
63
71
  revision: String(raw.revision),
64
72
  files: (raw.files as unknown[]).map(String),
@@ -77,5 +85,16 @@ export function readSourceMap(directory: string, root?: string): SourceMap {
77
85
  return undefined;
78
86
  },
79
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
+ },
80
99
  };
81
100
  }
@@ -46,19 +46,20 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
46
46
  | Write a comment | `comment '$2100' line Reads joystick 2.` |
47
47
  | Add a reference | `reference '$2000' '$2100' call` |
48
48
  | Find the places that a removal blocks | `suppressions --range '$2000-$2fff'` |
49
- | Start a file of the generated source | `module '$2000' player.asm --title 'Player movement'` |
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
51
  | Record a release of the program | `release ORIGINAL --file original/game.prg --base` |
52
52
  | Write a switch | `switch PROTECTION --kind protection --releases ORIGINAL` |
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` |
56
- | Record the start screen of a captured stage, and its tune | `start-screen --mode multicolour --screen '$cc00' --bitmap '$e000' --colours '$8328' --border 3 --background 1 --stage bank1 --call '$9000'` |
56
+ | Record the start screen of a captured stage, and its tune | `start-screen --stage loading --call '$9000'` |
57
57
  | Remove the start screen | `unstart-screen` |
58
58
  | Write a macro | `macro inc16 --params dst --body-file inc16.asm` |
59
59
  | Write instructions as one use of a macro | `use '$1005-$100a' inc16 --args ptr` |
60
60
  | Do many writes as one revision | `apply .c64-re-tools/local/batch.json` |
61
- | Make one batch from the batches of parallel agents | `join a.json b.json --out .c64-re-tools/local/joined.json` |
61
+ | Show the batches of parallel agents as one list of writes | `join a.json b.json` |
62
+ | Write the batches of parallel agents as one revision | `join a.json b.json --apply` |
62
63
  | Read the history of an address or a name | `history '$2100'` |
63
64
  | Read the last revisions | `revisions` |
64
65
  | Go back to an earlier state | `revert 20261015T2145` |
@@ -69,12 +70,12 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
69
70
  ## Addresses, names and spaces
70
71
 
71
72
  - A symbol is the name of an address from the user or the LLM. Get it from `at`, `search` or `symbols`.
72
- - An analyzer name is a second name from DXA, Ghidra 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`.
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`.
73
74
  - The generated source uses only the symbols. To use an analyzer name in the source, give the address that name with `rename`.
74
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.
75
- - A space is `c64` (the default), `drive8` for code in the 1541 drive, or `bank0` to `bank255` for cartridge banks and for a captured stage of the loading. Drive code, banks and stages use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
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.
76
77
  - A revision id has the form `20261015T214501.123-k3f9qz`. It starts with the date and the time. Give the full id, or a start of the id that only one revision has. Get the ids from `revisions`, or from the `revision` field of a result. The revision `0` is the knowledge before the first revision.
77
- - A file of a capture is the `image.json` that the capture of a packed program wrote. Keep the other files of the capture next to it.
78
+ - A file of a capture is the `image.json` that the capture of a packed program wrote. The other files of the capture must be next to it.
78
79
 
79
80
  ### Paths and the project folder
80
81
 
@@ -102,14 +103,18 @@ Each flag applies only to the commands in the table. On another command, the scr
102
103
 
103
104
  | Flag | Command | Effect |
104
105
  |---|---|---|
105
- | `--space <space>` | All commands | The space of the command: `c64`, `drive8`, or `bank0` to `bank255`. The default is `c64`. Without `--space`, `revert` reverts all spaces. |
106
+ | `--space <space>` | All commands | The space of the command: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. Without `--space`, `revert` reverts all spaces. |
106
107
  | `--by <user\|llm>` | All commands in "Change the knowledge" | Who decided the change. The default is `llm`. Give `user` only when the user decided the change. |
107
108
  | `--reason <text>` | All commands in "Change the knowledge" | Why you make the change. The revision keeps it, and `history` shows it. |
108
109
  | `--evidence <kind:ref>` | All commands in "Change the knowledge" | One thing that the change rests on: `coverage:<map>`, `test:<file>`, `file:<file>` or `note:<text>`. You can give it more than one time. |
109
110
  | `--expect-revision <revision>` | All commands in "Change the knowledge" | Refuse the change when the knowledge changed after this revision. Give the `revision` of your last read. |
111
+ | `--by <user\|llm>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
112
+ | `--reason <text>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
113
+ | `--evidence <kind:ref>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
114
+ | `--expect-revision <revision>` | `join` | With `--apply`: the same as for the commands in "Change the knowledge". |
110
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. |
111
- | `--origin <origin>` | `search`, `symbols`, `regions`, `comments`, `references`, `modules`, `operands`, `patches`, `macros`, `uses`, `export` | Only the rows of these origins: `user`, `llm`, `dxa`, `ghidra`, `heuristic`, `semantic` (user and llm), `analyzer` (dxa, ghidra and heuristic), or a comma list. The default is all origins. |
112
- | `--max-listed <n>` | `search`, `symbols`, `regions`, `comments`, `references`, `suppressions`, `modules`, `operands`, `patches`, `switches`, `releases`, `macros`, `uses`, `spaces`, `history`, `revisions`, `revision`, `listing` | The most items in each list of the body. The default is 50. The counts are always complete. |
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
+ | `--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. |
113
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. |
114
119
  | `--kind <kind>` | `references` | Only references of this kind: `call`, `jump`, `read`, `write`, `reference` or `pointer`. |
115
120
  | `--kind <kind>` | `switch` | Necessary. The switch kind: `protection`, `trainer`, `cheat`, `crack`, `fix` or `change`. |
@@ -121,7 +126,8 @@ Each flag applies only to the commands in the table. On another command, the scr
121
126
  | `--macro <name>` | `history` | The history of a macro in place of an address. |
122
127
  | `--name <name>` | `history` | The history of a name in place of an address. |
123
128
  | `--before <revision>` | `revisions` | Only the revisions before this one. |
124
- | `--out <file>` | `export`, `join` | Necessary. The JSON file to write. |
129
+ | `--out <file>` | `export` | Necessary. The JSON file to write. |
130
+ | `--apply` | `join` | Write the joined writes to the project knowledge as one revision. Without it, `join` writes nothing. |
125
131
  | `--out <file>` | `listing` | Write the listing as text to this file in place of the lines in the body. |
126
132
  | `--element <n>` | `classify` | The bytes of one element of a table. The length of the range must be a multiple of it. |
127
133
  | `--title <text>` | `module` | The title of the file. A `module` write without a title keeps the title that the module has. |
@@ -142,15 +148,15 @@ Each flag applies only to the commands in the table. On another command, the scr
142
148
  | `--body <text>` | `macro` | The body of the macro. |
143
149
  | `--body-file <file>` | `macro` | A project file with the body of the macro. |
144
150
  | `--args <x, y>` | `use` | One expression for each param of the macro, as a comma list. |
145
- | `--mode <mode>` | `start-screen` | Necessary. The mode of the VIC-II: `text`, `hires` or `multicolour`. |
146
- | `--screen <address>` | `start-screen` | Necessary. The address of the screen memory: 1000 bytes. |
151
+ | `--mode <mode>` | `start-screen` | The mode of the VIC-II: `text`, `hires` or `multicolour`. Necessary without `--stage`. |
152
+ | `--screen <address>` | `start-screen` | The address of the screen memory: 1000 bytes. Necessary without `--stage`. |
147
153
  | `--bitmap <address>` | `start-screen` | The address of the bitmap: 8000 bytes. `hires` and `multicolour` need it. |
148
154
  | `--charset <address>` | `start-screen` | The address of the charset: 2048 bytes. `text` needs it. |
149
155
  | `--colours <address>` | `start-screen` | The address of the 1000 bytes that the loader copies to the colour RAM. |
150
156
  | `--colour <0-15>` | `start-screen` | One colour for all of the colour RAM, in place of `--colours`. |
151
- | `--border <0-15>` | `start-screen` | Necessary. The border colour. |
152
- | `--background <0-15>` | `start-screen` | Necessary. The background colour. |
153
- | `--stage <space>` | `start-screen` | The space of a captured stage that holds the bytes of the screen, for example `bank1`. Without it, the bytes are in the program at the entry. |
157
+ | `--border <0-15>` | `start-screen` | The border colour. Necessary without `--stage`. |
158
+ | `--background <0-15>` | `start-screen` | The background colour. Necessary without `--stage`. |
159
+ | `--stage <space>` | `start-screen` | The space of the captured stage that shows the screen: `loading`. The script takes the mode, the addresses and the colours from the capture. Without it, the bytes are in the program at the entry. |
154
160
  | `--call <address>` | `start-screen` | A routine of the stage that the start screen calls before it waits, for example the start of the loading tune. It must return with RTS. It needs `--stage`. |
155
161
 
156
162
  ---
@@ -194,7 +200,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
194
200
  ### `suppressions`
195
201
 
196
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.
197
- - `unclassify` and `unreference` block the place for DXA and Ghidra. 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.
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.
198
204
  - `remove-symbol` does not block the address, because an analyzer name never becomes a symbol.
199
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.
200
206
  - `at` and `history` also show the blocks.
@@ -218,7 +224,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
218
224
 
219
225
  ### `releases`
220
226
 
221
- - `body.releases` lists the releases, the base release first. Each item has `label`, `file`, `sha256`, `base` and `define`.
227
+ - `body.releases` lists the releases, the base release first. Each item has `label`, `base` and `define`.
222
228
  - `define` is the assembler define that builds the release.
223
229
 
224
230
  ### `macros`
@@ -242,10 +248,10 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
242
248
 
243
249
  ### `listing <range>`
244
250
 
245
- - `body.lines` lists one line for each instruction of a code region, and one `!byte` line for other bytes.
246
- - Each line has `address`, `bytes`, `text`, `referencesIn` and `referencesOut`. It can also have `label`, `analyzerNames` and `comment`.
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
+ - 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.
247
253
  - `text` is the instruction with the names of its target. An operand expression of the knowledge replaces the operand.
248
- - When the knowledge has coverage, `access` tells if a run executed (`x`), read (`r`) or wrote (`w`) the bytes of the line, or `-` for none.
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.
249
255
  - With `--out`, the body has `lines` as a number, and `out`, `bytes` and `sha256` of the text file.
250
256
  - If the knowledge has no program in the space, the script refuses. Put the program in with `image` first.
251
257
  - Use `listing` in place of your own disassembler.
@@ -273,7 +279,7 @@ When a git merge left conflicts in the knowledge, each read body also has `confl
273
279
  ### `revision <revision>`
274
280
 
275
281
  - `body.revision` gives the revision. `body.added` and `body.closed` list the rows that it added and closed.
276
- - 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.
277
283
 
278
284
  ---
279
285
 
@@ -347,8 +353,10 @@ Errors of this group:
347
353
 
348
354
  - A module tells where a file of the generated source starts. The file runs to the next module or to the end of its segment.
349
355
  - Each address has one module, and each file name has one module.
350
- - A file name has letters, digits, underscores or hyphens, and ends in `.asm`. It has no folder.
351
- - The generated source has the files `main.asm`, `loader.asm`, `switches.asm`, `config.asm`, `constants.asm` and `macros.asm` already. Thus a module cannot have one of these names, in upper or lower case.
356
+ - A file name has letters, digits, underscores or hyphens, and ends in `.asm`. It can have one folder, for example `music/driver.asm`. A folder name has lower-case letters, digits, underscores or hyphens.
357
+ - Put the modules of one part of the program in one folder, for example `music/`, `irq/` or `graphics/`.
358
+ - The generated source has the files `main.asm`, `loader.asm`, `switches.asm`, `config.asm`, `constants.asm`, `macros.asm` and `start_screen.asm` already. It also has the folders `leftovers/` and `segments/`. Thus a module cannot have one of these files, also in a folder, or one of these folders, in upper or lower case.
359
+ - Two modules cannot have file names that are different only in upper or lower case.
352
360
  - The title becomes the first line of the file.
353
361
  - `body.module` gives the module after the write.
354
362
 
@@ -387,12 +395,13 @@ A rebuild keeps all of the program in the source: unused bytes, dead code, old c
387
395
 
388
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.
389
397
 
390
- - A release is a PRG or the `image.json` of a capture, in a folder that git keeps, for example `original/`. The script refuses a file in `.c64-re-tools/local/`.
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/`.
391
399
  - A label is upper case, for example `ORIGINAL`, `FIRESTAR` or `V2`.
392
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.
393
401
  - A space has one base release. Record the base release before the first switch.
394
- - 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 file.
395
- - `body.release` gives the release, with its `sha256` and its `define`.
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.
403
+ - To change the bytes of a release, record the release again with its new file.
404
+ - `body.release` gives the release, with its `define`. `body.bytes` gives the number of bytes of the file.
396
405
 
397
406
  ### `unrelease <label>`
398
407
 
@@ -407,15 +416,30 @@ A start screen is a loading screen, a title screen or a presentation screen of t
407
416
  1. Record patches under a switch that take out the change.
408
417
  2. Use the screen as it is.
409
418
  3. Do not record a start screen.
410
- - The bytes of the screen must be in the program of the knowledge at the entry, or in a captured stage. Thus capture the program while the bytes of the screen are in memory.
411
- - When the bytes are only in a stage of the loading, do these steps:
412
- 1. Capture the stage while it shows the screen. Do not exclude the memory of the screen.
413
- 2. Put the capture into the knowledge in a space of its own, for example `image stage/image.json --space bank1`.
414
- 3. If the stage plays a tune or does other work during the screen, find the routine that starts it. Run the stage with coverage while that routine runs. Put the map into the knowledge with `coverage <map> --space bank1`.
415
- 4. Record the start screen with `--stage bank1`, and with `--call` for the routine.
416
- - With `--stage`, the addresses are in the program of that space. Each part and the call must be in it.
419
+ - The bytes of the screen must be in the program of the knowledge at the entry, or in a captured stage.
420
+
421
+ #### A start screen of a captured stage
422
+
423
+ Use this when a stage of the loading shows the screen, and the program at the entry does not have it. Do these steps:
424
+
425
+ 1. Capture the stage while it shows the screen. Do not exclude the memory of the screen.
426
+ 2. Put the capture into the knowledge in the space `loading`: `image stage/image.json --space loading`. Do not use another space for it.
427
+ 3. If the stage plays a tune or does other work during the screen, find the routine that starts it. Run the stage with coverage while that routine runs. Put the map into the knowledge with `coverage <map> --space loading`.
428
+ 4. Record the start screen with `start-screen --stage loading`, and with `--call` for the routine.
429
+
430
+ - The script takes the mode, the screen, the bitmap or the charset, the colours and the colour RAM from the capture. Do not find the addresses or the colours yourself.
431
+ - The generated source puts the screen in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
432
+ - A flag that you give replaces the value of the capture. Give a flag only to correct a value.
433
+ - A capture of an older version has no colour RAM. Then capture the stage again.
434
+
435
+ #### A start screen in the program
436
+
437
+ - Capture the program while the bytes of the screen are in memory.
417
438
  - Get the mode, the addresses and the colours from the VIC-II while the original program shows the screen.
418
- - The colour RAM is not in the capture. Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while the original shows the screen. Give their address with `--colours`. If the program does not have them, give one colour with `--colour`.
439
+ - Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while the original shows the screen. Give their address with `--colours`. If the program does not have them, give one colour with `--colour`.
440
+
441
+ #### The rules of the VIC-II
442
+
419
443
  - `text` needs `--charset`. `hires` and `multicolour` need `--bitmap`. `text` and `multicolour` need `--colours` or `--colour`. `hires` uses neither.
420
444
  - The screen is at a step of $0400, the bitmap at a step of $2000 and the charset at a step of $0800. They must be in one VIC bank of 16 KB.
421
445
  - In VIC bank 0 and 2, the VIC-II reads the character ROM at $1000-$1fff of the bank. A screen or a bitmap cannot be there. A charset at $1000 or $1800 of the bank is the character ROM.
@@ -516,15 +540,16 @@ A macro writes a run of instructions as one line of the source, for example `+in
516
540
  ### `coverage <map>...`
517
541
 
518
542
  - `<map>` is a 64 KiB coverage map of a run. Write each map in `.c64-re-tools/local/`.
519
- - `body` holds `revision`, `imported`, `known` and `ranges`. `imported` lists the new maps. `known` lists the maps that the space has already.
520
- - `coverage` joins the maps. It keeps each address that a run executed, read or wrote. It also keeps each address that one run wrote and executed: self-modified code.
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.
521
546
  - `coverage` puts each map into the space of `--space`. You can add the same map to each space.
522
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.
523
548
 
524
549
  ### `apply <file>`
525
550
 
526
551
  - `<file>` is a JSON list of writes. Give `-` to read the list from standard input.
527
- - `body` holds `revision`, `writes` and `replaced`. Each item of `replaced` has the number of the `write`, its `op` and its `previous`.
552
+ - `body` holds `revision`, `writes` and `replaced`. `replaced` lists each write that replaced a row of a different origin, for example an `llm` write over a `user` row. Each item has the number of the `write`, its `op` and its `previous`. A write over a row of the same origin is not in `replaced`.
528
553
  - All writes become one revision. If the knowledge refuses one write, the script writes nothing, and the `error` names the write.
529
554
  - Each write has `op` and the fields of the command with the same name. Each write can also have `space`. For example:
530
555
 
@@ -557,7 +582,6 @@ A macro writes a run of instructions as one line of the source, for example `+in
557
582
  | `unuse` | `start` |
558
583
 
559
584
  - The script checks an `operand`, `patch` or `use` write against the program of its space.
560
- - Apply a batch from a library match or an idiom search in the same way. Read the notes of the result that wrote the batch first.
561
585
 
562
586
  ### `revert <revision>`
563
587
 
@@ -575,19 +599,20 @@ A macro writes a run of instructions as one line of the source, for example `+in
575
599
 
576
600
  ## Batches of parallel agents
577
601
 
578
- When more agents name the program at the same time, give each agent one range of addresses. Each agent writes one batch file and does not apply it. A batch has the form `{"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}`. `ops` holds the writes, as for `apply`. The owner ranges must not overlap.
602
+ When more agents name the program at the same time, give each agent one range of addresses. Each agent writes one batch file in `.c64-re-tools/local/` and does not apply it. A batch has the form `{"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}`. `ops` holds the writes, as for `apply`. The owner ranges must not overlap.
579
603
 
580
604
  ### `join <batch>...`
581
605
 
582
- - `join` makes one batch from two or more batch files. It writes no knowledge.
583
- - `body` holds `writes`, `repeated`, `choices`, `out`, `bytes` and `sha256`.
606
+ - `join` makes one list of writes from two or more batch files. Without `--apply`, it writes no knowledge.
607
+ - Without `--apply`, `body` holds `writes`, `repeated` and `choices`. `writes` lists the joined writes.
608
+ - 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`.
584
609
  - `choices` lists each place where the batches gave different values, with the value that stays.
585
610
  - At an address in the owner range of a batch, the name, the comment, the operand and the module of that batch stay. At an address that no batch owns, the first batch in the command stays.
586
611
  - A batch can give an address a name that `join` replaces. Then `join` also replaces that name in the operand expressions and macro arguments of that batch.
587
612
  - The regions of the owner come after the regions of the other batches. Thus the regions of the owner stay where they overlap.
588
613
  - A name from a batch stays when another batch removes the symbol at that address.
589
614
  - When one name or one module file is at two addresses, `join` writes nothing and gives the error `conflict`. The `error` names the addresses and the batches. Correct the batches. Then do `join` again.
590
- - The `hint` tells you to examine `choices`. `nextAction` is the `apply` command for the joined batch. Run it when the choices agree with your task.
615
+ - Without `--apply`, the `hint` tells you to examine `choices` and `writes`. `nextAction` is the same `join` with `--apply`. Run it when the choices agree with your task.
591
616
 
592
617
  ---
593
618