@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
@@ -17,7 +17,8 @@ import { operandText } from "#src/knowledge/expression.ts";
17
17
  import { historyAt, historyNamed, historyOfMacro, historyOfSwitch, revision, revisionNote, revisions, type HistoryEntry } from "#src/knowledge/history.ts";
18
18
  import { joinBatches, type Batch, type JoinChoice, type JoinClash } from "#src/knowledge/join.ts";
19
19
  import { knowledgeNames } from "#src/knowledge/names.ts";
20
- import { addCoverage, programCoverage, programImage, requireProgram, setImage, type ImageRequest } from "#src/knowledge/program.ts";
20
+ import { addCoverage, coverageRangeCounts, memoryRows, operandImages as programImages, programCoverage, programImage, requireProgram, setImage, type ImageRequest } from "#src/knowledge/program.ts";
21
+ import { startScreenOfStage } from "#src/knowledge/start-screen.ts";
21
22
  import {
22
23
  analyzerNamesAt,
23
24
  at,
@@ -158,8 +159,6 @@ const switchRow = (row: SwitchRow, base?: string, patches?: readonly PatchRow[])
158
159
  const release = (row: ReleaseRow) => ({
159
160
  ...spaceOf(row),
160
161
  label: row.label,
161
- file: row.file,
162
- sha256: row.sha256,
163
162
  base: row.base,
164
163
  define: `--define ${RELEASE_DEFINE}${row.label}=1`,
165
164
  ...(row.comment === undefined ? {} : { comment: row.comment }),
@@ -177,6 +176,7 @@ const startScreen = (row: StartScreenRow) => ({
177
176
  background: row.background,
178
177
  ...(row.stage === undefined ? {} : { stage: row.stage }),
179
178
  ...(row.call === undefined ? {} : { call: formatC64Address(row.call) }),
179
+ ...(row.colourRam === true ? { colourRam: true } : {}),
180
180
  ...(row.comment === undefined ? {} : { comment: row.comment }),
181
181
  origin: row.origin,
182
182
  revision: row.revision,
@@ -203,11 +203,11 @@ function suppression(row: SuppressionRow) {
203
203
  return { ...spaceOf(row), suppresses: row.entity, ...place, origin: row.origin, revision: row.revision };
204
204
  }
205
205
 
206
- /** A row of the program in a revision: memory bytes, the entry, or a coverage range. */
206
+ /** A row of the program in a revision: memory bytes, the entry, or the ranges of one kind of a coverage map. */
207
207
  function programRow(entry: Extract<HistoryEntry, { entity: "memory" | "entry" | "coverage" }>) {
208
208
  if (entry.entity === "memory") return { ...spaceOf(entry.row), start: formatC64Address(entry.row.address), end: formatC64Address(entry.row.address + entry.row.bytes - 1), bytes: entry.row.bytes, origin: entry.row.origin, revision: entry.row.revision };
209
209
  if (entry.entity === "entry") return { ...spaceOf(entry.row), address: formatC64Address(entry.row.address), state: entry.row.state, stages: entry.row.stages, origin: entry.row.origin, revision: entry.row.revision };
210
- return { ...spaceOf(entry.row), kind: entry.row.kind, start: formatC64Address(entry.row.start), end: formatC64Address(entry.row.end), origin: entry.row.origin, revision: entry.row.revision };
210
+ return { ...spaceOf(entry.row), map: entry.row.map, kind: entry.row.kind, ranges: entry.row.ranges, origin: entry.row.origin, revision: entry.row.revision };
211
211
  }
212
212
 
213
213
  function historyEntry(entry: HistoryEntry) {
@@ -271,8 +271,10 @@ function listingSource(db: DatabaseSync | undefined, space: string): ListingSour
271
271
  const coverage = programCoverage(db, space)?.map;
272
272
  const inside = (at: number) => image.segments.some((segment) => at >= segment.start && at <= segment.end);
273
273
  const platform = new Map(space === DEFAULT_SPACE ? platformNames().map((entry) => [entry.address, entry.name]) : []);
274
+ const entries = space === DEFAULT_SPACE ? platformNames().filter((entry) => entry.end > entry.address) : [];
274
275
  return {
275
276
  byteAt: (at) => (inside(at) ? image.byteAt(at) : undefined),
277
+ entryStart: (at) => (inside(at) ? undefined : entries.find((entry) => at > entry.address && at <= entry.end)?.address),
276
278
  // A user or LLM name, else the platform name; an analyzer name in symbols (knowledge from an older version) gives way to it.
277
279
  nameOf: (at) => {
278
280
  const own = symbolAt(db, at, space);
@@ -297,7 +299,7 @@ function listingSource(db: DatabaseSync | undefined, space: string): ListingSour
297
299
  /** Every value of --origin, for the message of a wrong one. */
298
300
  const ORIGIN_VALUES = `one of ${ORIGINS.join(", ")}, semantic or analyzer, or a comma list of them. semantic is ${SEMANTIC_ORIGINS.join(" and ")}. analyzer is ${ANALYZERS.slice(0, -1).join(", ")} and ${ANALYZERS.at(-1)}`;
299
301
 
300
- /** --origin for reads: one origin, semantic (user and llm), analyzer (dxa, ghidra and heuristic), or a comma list. */
302
+ /** --origin for reads: one origin, semantic (user and llm), analyzer (dxa, decompiler and heuristic), or a comma list. */
301
303
  function originFilter(value: string): Origin[] {
302
304
  const origins = new Set<Origin>();
303
305
  for (const part of value.split(",")) {
@@ -359,15 +361,9 @@ function imageRequest(path: string, space: string): ImageRequest {
359
361
  return request;
360
362
  }
361
363
 
362
- /**
363
- * The program in the knowledge that operand, patch and macro use writes
364
- * are checked against, with the platform names. A byte outside
365
- * the segments of the program is not in it.
366
- */
367
- function operandImage(db: DatabaseSync, space: string): OperandImage {
368
- const image = requireProgram(db, space);
369
- const inside = (at: number) => image.segments.some((segment) => at >= segment.start && at <= segment.end);
370
- return { byteAt: (at) => (inside(at) ? image.byteAt(at) : undefined), platform: new Map(platformNames().map((entry) => [entry.name, entry.address])) };
364
+ /** The programs that operand, patch and macro use writes are checked against, with the platform names. */
365
+ function operandImages(db: DatabaseSync): (space: string) => OperandImage {
366
+ return programImages(db, new Map(platformNames().map((entry) => [entry.name, entry.address])));
371
367
  }
372
368
 
373
369
  /** An offset: a whole number in decimal or $ hex, with an optional minus sign. */
@@ -562,7 +558,7 @@ const READ_COMMANDS: CommandSpec[] = [
562
558
  },
563
559
  ),
564
560
  readCommand(
565
- { name: "symbols", summary: "The symbols, or with --analyzer the second names that DXA, Ghidra and the idioms gave.", options: { ...FILTER, kind: SYMBOL_KIND, analyzer: { kind: "flag", help: "the analyzer names in place of the symbols" }, ...LIST } },
561
+ { name: "symbols", summary: "The symbols, or with --analyzer the second names that DXA, the decompiler and the idioms gave.", options: { ...FILTER, kind: SYMBOL_KIND, analyzer: { kind: "flag", help: "the analyzer names in place of the symbols" }, ...LIST } },
566
562
  (db, call) => {
567
563
  const kind = call.string("kind") as (typeof SYMBOL_KINDS)[number] | undefined;
568
564
  if (call.flag("analyzer")) return { analyzerNames: list(call, listAnalyzerNames(db, rangeOf(call), kind, originsOf(call), call.space), symbol, RANGE_REST) };
@@ -602,7 +598,6 @@ const READ_COMMANDS: CommandSpec[] = [
602
598
  readCommand({ name: "spaces", summary: "The address spaces that hold knowledge.", options: LIST }, (db, call) => ({ spaces: list(call, listSpaces(db), (space) => space, MORE) })),
603
599
  readCommand({ name: "program", summary: "The program in the knowledge: its segments and entry, and the coverage maps that coverage imported, with the ranges." }, (db, call) => {
604
600
  const image = programImage(db, call.space);
605
- const ranges = db === undefined ? [] : (db.prepare("SELECT kind, count(*) AS count FROM current_coverage WHERE space = ? GROUP BY kind ORDER BY kind").all(call.space) as Array<{ kind: string; count: number }>);
606
601
  return {
607
602
  ...(call.space === DEFAULT_SPACE ? {} : { space: call.space }),
608
603
  image:
@@ -616,7 +611,7 @@ const READ_COMMANDS: CommandSpec[] = [
616
611
  stages: image.stages?.length ?? 0,
617
612
  },
618
613
  ...((row) => (row === undefined ? {} : { startScreen: startScreen(row) }))(currentStartScreen(db, call.space)),
619
- coverage: { maps: [...new Set(coverageRuns(db).filter((run) => run.space === call.space).map((run) => run.name))], ranges: Object.fromEntries(ranges.map((row) => [row.kind, row.count])) },
614
+ coverage: { maps: [...new Set(coverageRuns(db).filter((run) => run.space === call.space).map((run) => run.name))], ranges: coverageRangeCounts(db, call.space) },
620
615
  };
621
616
  }),
622
617
  readCommand(
@@ -810,7 +805,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
810
805
  request.symbol = call.string(select)!;
811
806
  if (offset !== undefined) request.offset = offsetOf(offset, "--offset");
812
807
  }
813
- return (db) => shown(setOperand(db, { ...context, image: operandImage(db, call.space) }, request), "operand", operand);
808
+ return (db) => shown(setOperand(db, { ...context, image: operandImages(db) }, request), "operand", operand);
814
809
  },
815
810
  ),
816
811
  writeCommand({ name: "unoperand", summary: "Removes the operand expression at an address.", subjects: [ADDRESS] }, (call) => {
@@ -837,7 +832,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
837
832
  if ((code === undefined) === !call.flag("nop")) throw new UsageError("patch needs exactly one of --code, --code-file or --nop.");
838
833
  const commentText = call.string("comment");
839
834
  const request = { space: call.space, ...call.parseRange(call.subject(0), "<range>"), switch: call.subject(1), code: code ?? "", ...(commentText === undefined ? {} : { comment: commentText }) };
840
- return (db) => shown(setPatch(db, { ...context, image: operandImage(db, call.space) }, request), "patch", patch);
835
+ return (db) => shown(setPatch(db, { ...context, image: operandImages(db) }, request), "patch", patch);
841
836
  },
842
837
  ),
843
838
  writeCommand(
@@ -881,7 +876,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
881
876
  ...(commentText === undefined ? {} : { comment: commentText }),
882
877
  };
883
878
  return (db) => {
884
- const result = setSwitch(db, { ...context, image: operandImage(db, call.space) }, request);
879
+ const result = setSwitch(db, { ...context, image: operandImages(db) }, request);
885
880
  const base = listReleases(db, undefined, call.space).find((row) => row.base)?.label;
886
881
  return shown(result, "switch", (row: SwitchRow) => switchRow(row, base));
887
882
  };
@@ -895,27 +890,23 @@ const WRITE_COMMANDS: CommandSpec[] = [
895
890
  writeCommand(
896
891
  {
897
892
  name: "release",
898
- summary: "Records a release of the program: its PRG or the image.json of its capture in the project. The base release is the one whose bytes are the program of the knowledge.",
893
+ summary: "Records a release of the program from its PRG or the image.json of its capture: the knowledge keeps the bytes of the release. The base release is the one whose bytes are the program of the knowledge.",
899
894
  subjects: [{ name: "<label>", help: "the release label, for example ORIGINAL or FIRESTAR" }],
900
895
  options: {
901
- file: { kind: "path", value: "<file>", help: "the PRG or image.json of the release, in a folder that git keeps", required: true },
896
+ file: { kind: "path", value: "<file>", help: "the PRG or image.json of the release. After the write, the knowledge does not need the file", required: true },
902
897
  base: { kind: "flag", help: "this release is the program of the knowledge: its segments and bytes must be the same" },
903
898
  comment: { kind: "text", value: "<text>", help: "what the release is, for example the group and the date" },
904
899
  },
905
- notes: "The build of a release defines RELEASE_<label>=1: each switch then has the value of that release. The check of the generated source builds each release and compares it with the bytes of its file.",
900
+ notes: "The build of a release defines RELEASE_<label>=1: each switch then has the value of that release. The check of the generated source builds each release and compares it with the bytes of the release in the knowledge.",
906
901
  },
907
902
  (call) => {
908
903
  const context = contextOf(call);
909
904
  const file = knowledgePath(call.string("file")!, "--file");
910
- const root = projectRoot();
911
- if (isInside(join(root, PROJECT_DIRECTORY, LOCAL_DIRECTORY), resolveProjectPath(file, root))) {
912
- throw new UsageError(`--file ${file} is in ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/, which git ignores. Move the release to a folder that git keeps, for example original/.`);
913
- }
914
905
  const image = readImage(file);
915
- const sha256 = createHash("sha256").update(readProjectFile(file).bytes).digest("hex");
916
906
  const commentText = call.string("comment");
917
907
  const base = call.flag("base");
918
- const request = { space: call.space, label: call.subject(0), file, sha256, ...(base ? { base } : {}), ...(commentText === undefined ? {} : { comment: commentText }) };
908
+ // The base release has no bytes of its own: its bytes are the program.
909
+ const request = { space: call.space, label: call.subject(0), ...(base ? { base } : { rows: memoryRows(image.segments, image.byteAt) }), ...(commentText === undefined ? {} : { comment: commentText }) };
919
910
  return (db) => {
920
911
  if (base) {
921
912
  const program = requireProgram(db, call.space);
@@ -925,7 +916,8 @@ const WRITE_COMMANDS: CommandSpec[] = [
925
916
  });
926
917
  if (!same) throw new Refusal("invalid-input", `The bytes of ${file} are not the program of the knowledge. Give --base only to the release whose file image put into the knowledge.`);
927
918
  }
928
- return shown(setRelease(db, context, request), "release", release);
919
+ const bytes = image.segments.reduce((sum, segment) => sum + segment.end - segment.start + 1, 0);
920
+ return { ...shown(setRelease(db, context, request), "release", release), bytes };
929
921
  };
930
922
  },
931
923
  ),
@@ -939,42 +931,62 @@ const WRITE_COMMANDS: CommandSpec[] = [
939
931
  name: "start-screen",
940
932
  summary: "Records the start screen of the program: a loading, title or presentation screen of the program itself, in memory at the entry or in a captured stage of the loading. The loader of the generated source shows it and waits for a key or a fire button before the entry.",
941
933
  options: {
942
- mode: { kind: "choice", value: "<mode>", choices: START_SCREEN_MODES, help: `one of ${START_SCREEN_MODES.join(", ")}`, required: true },
943
- screen: { kind: "address", value: "<address>", help: "the screen: the 1000 characters of a text screen, or the 1000 colour bytes of a bitmap", required: true },
934
+ mode: { kind: "choice", value: "<mode>", choices: START_SCREEN_MODES, help: `one of ${START_SCREEN_MODES.join(", ")}. Necessary without --stage` },
935
+ screen: { kind: "address", value: "<address>", help: "the screen: the 1000 characters of a text screen, or the 1000 colour bytes of a bitmap. Necessary without --stage" },
944
936
  bitmap: { kind: "address", value: "<address>", help: "the 8000 bytes of the bitmap. hires and multicolour need it" },
945
937
  charset: { kind: "address", value: "<address>", help: "the 2048 bytes of the charset, or '$1000' or '$1800' for the character ROM in VIC bank 0. text needs it" },
946
938
  colours: { kind: "address", value: "<address>", help: "the 1000 bytes that the loader copies to the colour RAM" },
947
939
  colour: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "one colour for all of the colour RAM, in place of --colours" },
948
- border: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the border colour", required: true },
949
- background: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the background colour", required: true },
950
- stage: { kind: "text", value: "<space>", help: "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" },
940
+ border: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the border colour. Necessary without --stage" },
941
+ background: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the background colour. Necessary without --stage" },
942
+ stage: { kind: "text", value: "<space>", help: "the space of the captured stage that shows the screen: loading. The script takes the mode, the addresses and the colours from the capture of the stage. Without it, the bytes are in the program at the entry" },
951
943
  call: { kind: "address", value: "<address>", help: "a routine of the stage that the start screen calls before it waits, for example the routine that starts the loading tune. It must return with RTS. Needs --stage" },
952
944
  comment: { kind: "text", value: "<text>", help: "what the screen is" },
953
945
  },
954
- notes: "Record only a screen of the program itself, never a screen of a crack. If a release changed the screen, for example with the text of a crack, stop and ask the user how to deal with it. text and multicolour need --colours or --colour; hires uses neither. With --stage, the addresses are in the program of that space. A write replaces the start screen of the knowledge.",
946
+ notes: "Record only a screen of the program itself, never a screen of a crack. If a release changed the screen, for example with the text of a crack, stop and ask the user how to deal with it. text and multicolour need --colours or --colour; hires uses neither. With --stage, the script takes the screen from the capture of the stage: give only --stage, and --call for a tune. A flag that you give too replaces the value of the capture. A write replaces the start screen of the knowledge.",
955
947
  },
956
948
  (call) => {
957
949
  const context = contextOf(call);
958
950
  const commentText = call.string("comment");
959
- const optional = (key: "bitmap" | "charset" | "colours") => ((value) => (value === undefined ? {} : { [key]: value }))(call.address(key));
960
- const colour = call.count("colour");
951
+ // The values that the call gives. With --stage, the capture of the stage gives the others.
952
+ const given: { mode?: StartScreenMode; screen?: number; bitmap?: number; charset?: number; colours?: number; colour?: number; border?: number; background?: number } = {};
953
+ const mode = call.string("mode") as StartScreenMode | undefined;
954
+ if (mode !== undefined) given.mode = mode;
955
+ for (const key of ["screen", "bitmap", "charset", "colours"] as const) {
956
+ const value = call.address(key);
957
+ if (value !== undefined) given[key] = value;
958
+ }
959
+ for (const key of ["colour", "border", "background"] as const) {
960
+ const value = call.count(key);
961
+ if (value !== undefined) given[key] = value;
962
+ }
961
963
  const stage = call.string("stage");
962
964
  const routine = call.address("call");
963
- const request = {
965
+ const extra = {
964
966
  space: call.space,
965
- mode: call.string("mode") as StartScreenMode,
966
- screen: call.address("screen")!,
967
- ...optional("bitmap"),
968
- ...optional("charset"),
969
- ...optional("colours"),
970
- ...(colour === undefined ? {} : { colour }),
971
- border: call.count("border")!,
972
- background: call.count("background")!,
973
967
  ...(stage === undefined ? {} : { stage }),
974
968
  ...(routine === undefined ? {} : { call: routine }),
975
969
  ...(commentText === undefined ? {} : { comment: commentText }),
976
970
  };
977
- return (db) => shown(setStartScreen(db, context, request), "startScreen", startScreen);
971
+ const complete = (values: typeof given & { colourRam?: true }, remedy: string) => {
972
+ const missing = (["mode", "screen", "border", "background"] as const).filter((key) => values[key] === undefined);
973
+ if (missing.length > 0) throw new UsageError(`Give ${missing.map((key) => `--${key}`).join(", ")}, ${remedy}`);
974
+ return { ...values, mode: values.mode!, screen: values.screen!, border: values.border!, background: values.background!, ...extra };
975
+ };
976
+ if (stage === undefined) {
977
+ const request = complete(given, "or give --stage with the space of a captured stage that shows the screen.");
978
+ return (db) => shown(setStartScreen(db, context, request), "startScreen", startScreen);
979
+ }
980
+ return (db) => {
981
+ // The capture of the stage gives the screen. A flag of the call replaces a value of the capture, and --colours or --colour replaces the colour RAM.
982
+ const image = programImage(db, stage);
983
+ if (image === undefined) throw new Refusal("not-found", `The knowledge has no program in ${stage}. Capture the stage while it shows the start screen, and put the capture into the project knowledge with image --space ${stage}. Then record the start screen again.`);
984
+ const captured = mode === undefined ? startScreenOfStage(image.state, stage) : undefined;
985
+ const { colourRam, ...fromCapture } = captured ?? { colourRam: undefined };
986
+ const ownColours = given.colours !== undefined || given.colour !== undefined;
987
+ const request = complete({ ...fromCapture, ...(colourRam === true && !ownColours ? { colourRam } : {}), ...given }, "or give --stage alone to take the screen from the capture.");
988
+ return shown(setStartScreen(db, context, request), "startScreen", startScreen);
989
+ };
978
990
  },
979
991
  ),
980
992
  writeCommand({ name: "unstart-screen", summary: "Removes the start screen. The loader of the generated source then starts the program at once." }, (call) => {
@@ -1020,7 +1032,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
1020
1032
  const context = contextOf(call);
1021
1033
  const request = { space: call.space, ...call.parseRange(call.subject(0), "<range>"), macro: call.subject(1), args: commaList(call.string("args") ?? "") };
1022
1034
  return (db) => {
1023
- const result = setMacroUse(db, { ...context, image: operandImage(db, call.space) }, request);
1035
+ const result = setMacroUse(db, { ...context, image: operandImages(db) }, request);
1024
1036
  return { revision: result.revision, use: macroUse(result.current), ...(result.previous === undefined ? {} : { previous: macroUse(result.previous) }) };
1025
1037
  };
1026
1038
  },
@@ -1048,7 +1060,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
1048
1060
  writeCommand(
1049
1061
  {
1050
1062
  name: "coverage",
1051
- summary: "Joins coverage maps of the emulator or of a run into the coverage of the knowledge. Each map is named by its path: --evidence coverage:<path> cites it.",
1063
+ summary: "Puts coverage maps of the emulator or of a run into the coverage of the knowledge. Each map is named by its path: a new map of a path replaces the earlier map of that path, and --evidence coverage:<path> cites it.",
1052
1064
  subjects: [{ name: "<map>", help: "a 64 KiB coverage map", list: true }],
1053
1065
  },
1054
1066
  (call) => {
@@ -1056,7 +1068,15 @@ const WRITE_COMMANDS: CommandSpec[] = [
1056
1068
  const maps = call.subjects.map((path) => ({ bytes: readProjectFile(path).bytes, name: knowledgePath(path, "<map>") }));
1057
1069
  return (db) => {
1058
1070
  const { revision, current } = addCoverage(db, context, { space: call.space, maps });
1059
- return { revision, ...spaceOf(current), imported: current.imported, known: current.known, ranges: current.ranges };
1071
+ const body = { revision, ...spaceOf(current), imported: current.imported, replaced: current.replaced, known: current.known, added: current.added, removed: current.removed };
1072
+ // Only a range that the coverage gained or lost changes the source and the reference.
1073
+ const hint =
1074
+ revision === null
1075
+ ? "The knowledge has each map already. Nothing changed."
1076
+ : current.added === 0 && current.removed === 0
1077
+ ? "The coverage did not change. The knowledge keeps the maps as evidence. The source and the reference do not change."
1078
+ : `The coverage gained ${current.added} and lost ${current.removed} ranges of accesses. They can change the leftovers and the code that no run executed. Generate the source again, then the reference.`;
1079
+ return reply(body, { hint });
1060
1080
  };
1061
1081
  },
1062
1082
  ),
@@ -1065,7 +1085,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
1065
1085
  name: "revert",
1066
1086
  summary: "Makes the knowledge the same as at one revision: all spaces, or with --space only that space. The revert is a new revision: the history stays complete.",
1067
1087
  subjects: [REVISION],
1068
- options: { space: { kind: "space", value: "<space>", help: "revert only this space: c64, drive8, or bank0 to bank255. The other spaces do not change. Without --space, every space reverts" } },
1088
+ options: { space: { kind: "space", value: "<space>", help: "revert only this space: c64, drive8, loading, or bank0 to bank255. The other spaces do not change. Without --space, every space reverts" } },
1069
1089
  },
1070
1090
  (call) => {
1071
1091
  const context = contextOf(call);
@@ -1104,23 +1124,25 @@ const WRITE_COMMANDS: CommandSpec[] = [
1104
1124
  }
1105
1125
  if (!Array.isArray(parsed)) throw new Refusal("invalid-input", `The batch ${path} is not a JSON list of writes. Give a list such as [{"op": "rename", "address": "$2100", "name": "update_player"}].`);
1106
1126
  const operations = parsed.map((item, index) => batchOperation(call, item, `write ${index + 1}`));
1107
- const checked = operations.some((operation) => operation.op === "operand" || operation.op === "patch" || operation.op === "use");
1108
- return (db) => {
1109
- const applied = applyBatch(db, checked ? { ...context, image: operandImage(db, call.space) } : context, operations);
1110
- // replaced: each write that replaced a row of another origin, with that row as previous gives it for one write.
1111
- const replaced = applied.steps.flatMap((step, index) => (step.previous === undefined ? [] : [{ write: index + 1, op: operations[index]!.op, previous: shownPrevious(step.previous) }]));
1112
- return { revision: applied.revision, writes: applied.steps.length, replaced };
1113
- };
1127
+ return (db) => applied(db, context, operations);
1114
1128
  },
1115
1129
  ),
1116
1130
  ];
1117
1131
 
1118
- /** join: the batches of agents that worked in parallel, as one batch for apply. It writes no knowledge. */
1132
+ /** Applies the writes of a batch as one revision, and gives the revision, the count and each row of another origin that a write replaced. */
1133
+ function applied(db: DatabaseSync, context: WriteContext, operations: BatchOperation[]) {
1134
+ const result = applyBatch(db, { ...context, image: operandImages(db) }, operations);
1135
+ // replaced: each write that replaced a row of another origin, with that row as previous gives it for one write.
1136
+ const replaced = result.steps.flatMap((step, index) => (step.previous === undefined ? [] : [{ write: index + 1, op: operations[index]!.op, previous: shownPrevious(step.previous) }]));
1137
+ return { revision: result.revision, writes: result.steps.length, replaced };
1138
+ }
1139
+
1140
+ /** join: the batches of agents that worked in parallel, as one list of writes. With --apply, it writes them as one revision. */
1119
1141
  const JOIN: CommandSpec = {
1120
1142
  name: "join",
1121
- summary: "Joins the batches of agents that worked in parallel into one batch for apply. It writes no knowledge.",
1143
+ summary: "Joins the batches of agents that worked in parallel into one list of writes, and shows it. With --apply, it writes the list as one revision, or nothing when one write is refused.",
1122
1144
  subjects: [{ name: "<batch>", help: 'a batch: a list of writes, or {"owner": {"start": "$1000", "end": "$1fff"}, "ops": [...]}', list: true }],
1123
- options: { ...SPACE, out: { ...OPTIONS.out, output: "file", value: "<file>", help: "the joined batch, relative to the project folder", required: true } },
1145
+ options: { ...WRITE, apply: { kind: "flag", help: "write the joined writes to the project knowledge as one revision. Without it, the result only shows them" }, ...LIST },
1124
1146
  notes: "At an address in the owner range of a batch, its name, comment, operand and module win, and its regions come last. One name or one module file at two addresses writes nothing.",
1125
1147
  run: (call) => {
1126
1148
  if (call.subjects.length < 2) throw new UsageError("join needs two or more batch files.");
@@ -1157,9 +1179,10 @@ const JOIN: CommandSpec = {
1157
1179
  const clash = (item: JoinClash) => `${item.what} ${item.value} at ${item.places.map((place) => `${formatC64Address(place.address)} (${place.file})`).join(" and ")}${item.space === DEFAULT_SPACE ? "" : ` in ${item.space}`}`;
1158
1180
  throw new Refusal("conflict", `The batches give one ${joined.clashes.map(clash).join(", one ")}. Nothing was written. Give each name and each module file one address in the batches, then join again.`);
1159
1181
  }
1160
- const out = call.string("out")!;
1161
- const body = { writes: joined.ops.length, repeated: joined.repeated, choices: joined.choices.map(choice), ...writeReported(out, `${JSON.stringify(joined.ops.map(batchJson), null, 1)}\n`, { what: "--out" }) };
1162
- return reply(body, { hint: "Examine each item of choices. Then apply the joined batch.", nextAction: call.next("apply", out) });
1182
+ const shown = { repeated: joined.repeated, choices: joined.choices.map(choice) };
1183
+ if (call.flag("apply")) return { ...withWrite((db) => applied(db, contextOf(call), joined.ops)), ...shown };
1184
+ const body = { writes: listed(joined.ops.map(batchJson), call.count("max-listed")!, (write) => write, MORE), ...shown };
1185
+ return reply(body, { hint: "Examine each item of choices and writes. Then nextAction writes them to the project knowledge as one revision.", nextAction: call.next("join", ...call.subjects, "--apply") });
1163
1186
  },
1164
1187
  };
1165
1188
 
@@ -1243,7 +1266,7 @@ function batchFields(fields: Record<string, unknown>, at: string, address: (text
1243
1266
 
1244
1267
  await runScript({
1245
1268
  name: "knowledge",
1246
- summary: "Reads and writes the knowledge of the project: names, regions, comments, references, the program and its coverage, and the source knowledge. A read needs no knowledge folder. Every command takes --space: c64 (the default), drive8 for 1541 drive code, or bank0 to bank255 for cartridge banks. revert without --space reverts all spaces.",
1269
+ summary: "Reads and writes the knowledge of the project: names, regions, comments, references, the program and its coverage, and the source knowledge. A read needs no knowledge folder. Every command takes --space: c64 (the default), drive8 for 1541 drive code, loading for a captured stage of the loading, or bank0 to bank255 for cartridge banks. revert without --space reverts all spaces.",
1247
1270
  names: knowledgeNames,
1248
1271
  commands: [...READ_COMMANDS, ...WRITE_COMMANDS, JOIN],
1249
1272
  });
@@ -11,6 +11,8 @@ export interface ListingSource {
11
11
  byteAt: (address: number) => number | undefined;
12
12
  /** The name of an address: a symbol, else a platform name. */
13
13
  nameOf: (address: number) => string | undefined;
14
+ /** The start of the platform entry of more bytes that holds an address outside the image (NMINV for its high byte), or undefined. */
15
+ entryStart?: (address: number) => number | undefined;
14
16
  /** The analyzer names of an address, for reference. */
15
17
  secondNames: (address: number) => string[];
16
18
  /** The knowledge regions, in address order. */
@@ -52,9 +54,22 @@ function accessOf(coverage: Uint8Array | undefined, start: number, length: numbe
52
54
  return text === "" ? "-" : text;
53
55
  }
54
56
 
57
+ /**
58
+ * The name of an operand target, as c64-source writes it: its own name, else
59
+ * name+offset inside a named data region, or inside a platform entry of more bytes.
60
+ */
61
+ function targetName(target: number, source: ListingSource): string | undefined {
62
+ const own = source.nameOf(target);
63
+ if (own !== undefined) return own;
64
+ const region = source.regions.find((row) => target > row.start && target <= row.end && !CODE.has(row.type) && row.type !== "dual-use");
65
+ const start = region?.start ?? source.entryStart?.(target);
66
+ const name = start === undefined ? undefined : source.nameOf(start);
67
+ return name === undefined ? undefined : `${name}+${target - start!}`;
68
+ }
69
+
55
70
  /** The operand value of an instruction as an expression: the name of its target where one exists, else the number. Empty for no operand. */
56
- function operandOf(mode: Mode, address: number, low: number, high: number, nameOf: ListingSource["nameOf"]): string {
57
- const named = (target: number, digits: 2 | 4) => nameOf(target) ?? (digits === 2 ? formatC64Byte(target) : formatC64Address(target));
71
+ function operandOf(mode: Mode, address: number, low: number, high: number, source: ListingSource): string {
72
+ const named = (target: number, digits: 2 | 4) => targetName(target, source) ?? (digits === 2 ? formatC64Byte(target) : formatC64Address(target));
58
73
  if (mode === "imp") return "";
59
74
  if (mode === "imm") return formatC64Byte(low);
60
75
  if (mode === "rel") return named((address + 2 + (low < 0x80 ? low : low - 0x100)) & 0xffff, 4);
@@ -108,7 +123,7 @@ export function listing(source: ListingSource, start: number, end: number): List
108
123
  const bytes = Array.from({ length: length - 1 }, (_, offset) => source.byteAt(address + 1 + offset));
109
124
  if (address + length - 1 <= region.end && bytes.every((value) => value !== undefined)) {
110
125
  // The operand expression of the knowledge in the syntax of the addressing mode, as c64-source writes it.
111
- const operand = source.operand(address) ?? operandOf(opcode.mode, address, bytes[0] ?? 0, bytes[1] ?? 0, source.nameOf);
126
+ const operand = source.operand(address) ?? operandOf(opcode.mode, address, bytes[0] ?? 0, bytes[1] ?? 0, source);
112
127
  if (address >= start) lines.push(line(address, length, instructionWith(byte, operand)));
113
128
  address += length;
114
129
  continue;
@@ -25,7 +25,7 @@ To get the command list, run the script with no arguments.
25
25
  |---|---|
26
26
  | Pack a BASIC program at `$0801` that starts with `SYS` | `pack build/game.prg --out build/game-packed.prg` |
27
27
  | Pack a program that starts at a known address | `pack build/main.prg --entry '$0400' --out build/release.prg` |
28
- | Merge more PRG files into one packed program | `pack build/loader.prg build/main.prg --entry '$0400' --out build/release.prg` |
28
+ | Merge more PRG files into one packed program | `pack build/clean_loader.prg build/clean.prg --entry '$0400' --out build/clean_packed.prg` |
29
29
  | Start the program with RAM in place of the BASIC and KERNAL ROMs | `pack build/game.prg --exit-memory '$35' --out build/game-packed.prg` |
30
30
 
31
31
  ---
@@ -34,7 +34,7 @@ To get the command list, run the script with no arguments.
34
34
  | Save a module of the program as a routine of the library | `routine '$1000' --library ../library` |
35
35
  | Save a range of the program as a routine with a name | `routine '$1000-$1026' --name play --library ../library` |
36
36
  | Find the routines of the library in the program | `match --library ../library` |
37
- | Write the names of the found routines as a batch of changes | `match --library ../library --out .c64-re-tools/local/match.json` |
37
+ | Write the names of the found routines to the project knowledge | `match --library ../library --apply` |
38
38
 
39
39
  ---
40
40
 
@@ -86,7 +86,8 @@ Each flag applies only to the commands in the table. On another command, the scr
86
86
  | `--min-block <n>` | `compare` | With `--align`: the minimum number of bytes in a block, from 8. The default is 16. |
87
87
  | `--frames <n>` | `compare` | Run each release for `n` frames, and give each listed difference its runtime evidence. The default is no run. |
88
88
  | `--steps <file>` | `compare` | With `--frames`: run the action steps of this file before the frames. The default is no steps. |
89
- | `--out <file>` | `separate`, `leftovers`, `match` | `separate` and `leftovers` write all items to this file. `match` writes the batch of changes to this file. The default is no file. |
89
+ | `--out <file>` | `separate`, `leftovers` | Write all items to this file. The default is no file. |
90
+ | `--apply` | `match` | Write the changes to the project knowledge as one revision of the LLM. Without it, `match` writes nothing. |
90
91
  | `--max-listed <n>` | `separate`, `leftovers`, `match` | List at most `n` items of each list. The default is 50. `count` always gives the full number. |
91
92
  | `--min-text <n>` | `leftovers` | The minimum number of characters in a text, from 4. The default is 8. A short text, for example a group name, can need 6. |
92
93
  | `--library <folder>` | `routine`, `match` | Required. The library folder. |
@@ -265,9 +266,9 @@ Finds each routine of the library in the program of the project knowledge.
265
266
  - `library` and `routines`: the library folder and the number of routines in it.
266
267
  - `matches`: each item has `routine`, `start`, `end` and `shift`. `shift` is the address in the program minus the address in the library.
267
268
  - `differing` in each match: each operand that addresses something outside the routine and that is different. It gives the value in the `library` and in the `program`. Examine each one. For example, the program can use other variables or another SID voice.
268
- - `batch`: only with `--out`. `out`, `bytes` and `sha256` give the batch file. `writes` counts its writes. `known` counts the writes that the project knowledge has already. `leftOut` lists the writes that the script left out, and why. `check` lists each comment of the batch that gives an address outside its routine. Each item has `routine`, `address`, `comment` and the `outside` addresses. Such an address can be different in this program. Examine each comment, and correct its text in the batch file if it is necessary.
269
+ - `changes`: with matches. `writes` lists the writes for the project knowledge. `known` counts the writes that the project knowledge has already. `leftOut` lists the writes that the script left out, and why. `check` lists each comment of `writes` that gives an address outside its routine. Each item has `routine`, `address`, `comment` and the `outside` addresses. Such an address can be different in this program. With `--apply`, `revision` gives the revision of the changes.
269
270
 
270
- The batch has the names, regions, comments, references and operand expressions of each routine at its address in the program. The script leaves out a write in these conditions:
271
+ The changes have the names, regions, comments, references and operand expressions of each routine at its address in the program. The script leaves out a write in these conditions:
271
272
 
272
273
  - The program has a user or LLM row at that place.
273
274
  - The program uses the name at another address.
@@ -275,14 +276,14 @@ The batch has the names, regions, comments, references and operand expressions o
275
276
  - The routine occurs more than one time, and the script did not choose this copy.
276
277
  - The script left out the name that an operand expression uses, or the expression does not give the operand in the program.
277
278
 
278
- A routine can occur more than one time. Then the script finds the nearest routines before and after it in the library that occur only one time. The script writes the names at the copy that has the shift of one of these routines. If no copy or more than one copy has such a shift, the script writes no names for the routine. Then `batch.leftOut` gives each copy with the reason `ambiguous`.
279
+ A routine can occur more than one time. Then the script finds the nearest routines before and after it in the library that occur only one time. The script writes the names at the copy that has the shift of one of these routines. If no copy or more than one copy has such a shift, the script writes no names for the routine. Then `changes.leftOut` gives each copy with the reason `ambiguous`.
279
280
 
280
- An address `$xxxx` in a comment moves with the routine when the address is in the routine. An address outside the routine does not move, and `batch.check` gives the comment.
281
+ An address `$xxxx` in a comment moves with the routine when the address is in the routine. An address outside the routine does not move, and `changes.check` gives the comment.
281
282
 
282
283
  `hint` and `nextAction`:
283
284
 
284
- - Without `--out`, with matches: `nextAction` runs `match` with `--out`. Examine `differing` of each match first.
285
- - With `--out`, with writes: `hint` tells you to apply the changes in the batch file to the project knowledge. Read `batch.leftOut` first. When `batch.check` has comments, `hint` tells you to examine them first. Apply the changes as one revision of the LLM.
285
+ - Without `--apply`, with writes: `nextAction` runs `match` with `--apply`. Examine `differing` of each match, `changes.writes` and `changes.leftOut` first.
286
+ - When `changes.check` has comments, `hint` tells you to examine them after the write. Correct each comment that is different in the project knowledge.
286
287
  - No match: `hint` tells that a packed program can hold a routine in a packed form. Unpack the program, put it into the project knowledge, and run `match` again.
287
288
 
288
289
  Traps:
@@ -333,8 +334,8 @@ Traps:
333
334
  1. Put the program into the project knowledge, and name the routine there.
334
335
  2. Run `routine`. Read `leftOut`.
335
336
  3. In another project, put the program into the project knowledge. Run `match`.
336
- 4. Run `match` with `--out`. Read `batch.leftOut` and `batch.check`.
337
- 5. Apply the changes in the batch file to the project knowledge.
337
+ 4. Read `changes.writes` and `changes.leftOut`. Run `match` with `--apply`.
338
+ 5. Examine the comments in `changes.check`. Correct each comment that is different in the project knowledge.
338
339
 
339
340
  ---
340
341
 
@@ -2,7 +2,7 @@
2
2
  // with one <name>.json for each routine, outside every project. A routine holds
3
3
  // its bytes, which of its bytes move with it, and its knowledge at offsets from
4
4
  // its start, so match finds it in another program at another address and
5
- // suggests its names there as an apply batch. Nothing here writes knowledge.
5
+ // suggests its names there as writes of the knowledge. Nothing here writes knowledge.
6
6
 
7
7
  import { createHash } from "node:crypto";
8
8
  import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
@@ -468,7 +468,7 @@ export interface ProgramKnowledge {
468
468
  referenceSuppressed: (reference: { from: number; to: number; kind: ReferenceKind }) => boolean;
469
469
  }
470
470
 
471
- /** One write of an apply batch, in the form of knowledge.ts apply. */
471
+ /** One change of match, as the result shows it: a write of the knowledge with its addresses as $ text. */
472
472
  export type BatchWrite = Record<string, string | number> & { op: string };
473
473
 
474
474
  export interface Skipped {
@@ -478,7 +478,7 @@ export interface Skipped {
478
478
  reason: string;
479
479
  }
480
480
 
481
- /** A comment of the batch that names an address outside its routine: that address can be different in the program. */
481
+ /** A comment of the changes that names an address outside its routine: that address can be different in the program. */
482
482
  export interface Check {
483
483
  routine: string;
484
484
  address: string;
@@ -487,7 +487,7 @@ export interface Check {
487
487
  }
488
488
 
489
489
  export interface Suggestions {
490
- batch: BatchWrite[];
490
+ writes: BatchWrite[];
491
491
  /** Writes that the program already has. */
492
492
  known: number;
493
493
  leftOut: Skipped[];
@@ -554,7 +554,7 @@ function movedComment(text: string, routine: Routine, shift: number): { text: st
554
554
 
555
555
  /**
556
556
  * The names, regions, comments, references and operand expressions of each
557
- * matched routine at its program addresses, as an apply batch. A write that
557
+ * matched routine at its program addresses, as writes of the knowledge. A write that
558
558
  * the program already has is counted as known. A write that would replace a
559
559
  * user or LLM row, take a name that the program uses elsewhere, undo a
560
560
  * removal, or give an operand that is not in the image, is left out with the
@@ -564,12 +564,12 @@ function movedComment(text: string, routine: Routine, shift: number): { text: st
564
564
  * is in `check`.
565
565
  */
566
566
  export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[] }>, program: ProgramKnowledge, image: Searched, platform: ReadonlyMap<string, number>): Suggestions {
567
- const batch: BatchWrite[] = [];
567
+ const writes: BatchWrite[] = [];
568
568
  const leftOut: Skipped[] = [];
569
569
  const check: Check[] = [];
570
570
  let known = 0;
571
571
  const show = formatC64Address;
572
- /** The names that are at their place after the batch: written here or known. */
572
+ /** The names that are at their place after the changes: written here or known. */
573
573
  const placed = new Map<string, number>();
574
574
  const symbolsHere = new Map<number, string>();
575
575
  const regionsHere: Array<{ start: number; end: number }> = [];
@@ -591,11 +591,11 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
591
591
  placed.set(symbol.name, address);
592
592
  } else if (existing !== undefined && semantic(existing)) skip(address, "rename", `the program names it ${existing.name} (${existing.origin})`);
593
593
  else if (elsewhere !== undefined && elsewhere.address !== address) skip(address, "rename", `the program uses the name ${symbol.name} at ${show(elsewhere.address)}`);
594
- else if (placed.has(symbol.name) && placed.get(symbol.name) !== address) skip(address, "rename", `the batch gives the name ${symbol.name} to ${show(placed.get(symbol.name)!)}`);
595
- else if (symbolsHere.has(address)) skip(address, "rename", `the batch names it ${symbolsHere.get(address)}`);
594
+ else if (placed.has(symbol.name) && placed.get(symbol.name) !== address) skip(address, "rename", `the changes give the name ${symbol.name} to ${show(placed.get(symbol.name)!)}`);
595
+ else if (symbolsHere.has(address)) skip(address, "rename", `the changes name it ${symbolsHere.get(address)}`);
596
596
  else if (program.symbolSuppressed(address)) skip(address, "rename", "a removal of a name holds there");
597
597
  else {
598
- batch.push({ op: "rename", address: show(address), name: symbol.name, kind: symbol.kind });
598
+ writes.push({ op: "rename", address: show(address), name: symbol.name, kind: symbol.kind });
599
599
  placed.set(symbol.name, address);
600
600
  symbolsHere.set(address, symbol.name);
601
601
  }
@@ -609,10 +609,10 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
609
609
  else if (overlapping.some(semantic)) {
610
610
  const other = overlapping.find(semantic)!;
611
611
  skip(start, "classify", `the program has the ${other.type} region ${show(other.start)}-${show(other.end)} (${other.origin})`);
612
- } else if (regionsHere.some((item) => item.start <= end && item.end >= start)) skip(start, "classify", "the batch classifies an overlapping range");
612
+ } else if (regionsHere.some((item) => item.start <= end && item.end >= start)) skip(start, "classify", "the changes classify an overlapping range");
613
613
  else if (program.regionSuppressed(start, end)) skip(start, "classify", "a removal of a region holds there");
614
614
  else {
615
- batch.push({ op: "classify", start: show(start), end: show(end), type: region.type, ...(region.element === undefined ? {} : { element: region.element }) });
615
+ writes.push({ op: "classify", start: show(start), end: show(end), type: region.type, ...(region.element === undefined ? {} : { element: region.element }) });
616
616
  regionsHere.push({ start, end });
617
617
  }
618
618
  }
@@ -624,7 +624,7 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
624
624
  if (existing?.text === text) known++;
625
625
  else if (existing !== undefined) skip(address, "comment", `the program has a ${comment.placement} comment there (${existing.origin})`);
626
626
  else {
627
- batch.push({ op: "comment", address: show(address), placement: comment.placement, text });
627
+ writes.push({ op: "comment", address: show(address), placement: comment.placement, text });
628
628
  if (outside.length > 0) check.push({ routine: routine.name, address: show(address), comment: text, outside });
629
629
  }
630
630
  }
@@ -633,7 +633,7 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
633
633
  const wanted = { from: at(reference.from), to: at(reference.to), kind: reference.kind };
634
634
  if (program.referencesFrom(wanted.from).some((item) => item.to === wanted.to && item.kind === wanted.kind)) known++;
635
635
  else if (program.referenceSuppressed(wanted)) skip(wanted.from, "reference", "a removal of this reference holds");
636
- else batch.push({ op: "reference", from: show(wanted.from), to: show(wanted.to), kind: wanted.kind });
636
+ else writes.push({ op: "reference", from: show(wanted.from), to: show(wanted.to), kind: wanted.kind });
637
637
  }
638
638
 
639
639
  const own = new Set(routine.symbols.map((symbol) => symbol.name));
@@ -660,7 +660,7 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
660
660
  skip(address, "operand", problem);
661
661
  continue;
662
662
  }
663
- batch.push({
663
+ writes.push({
664
664
  op: "operand",
665
665
  address: show(address),
666
666
  select: operand.select,
@@ -670,7 +670,7 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
670
670
  });
671
671
  }
672
672
  }
673
- return { batch, known, leftOut, check };
673
+ return { writes, known, leftOut, check };
674
674
  }
675
675
 
676
676
  /** Why the expression is not the operand of the instruction at `address` in the image, or undefined when it is. */