@henols/c64-re-tools 2.8.0-rc.1 → 2.8.0-rc.3

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 (120) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +7 -4
  3. package/skills/c64-assembler/scripts/assembler.ts +73 -44
  4. package/skills/c64-disk/scripts/disk.ts +3 -3
  5. package/skills/c64-disk/scripts/lib/containers.ts +2 -2
  6. package/skills/c64-docs/SKILL.md +1 -1
  7. package/skills/c64-docs/scripts/docs.ts +12 -20
  8. package/skills/c64-docs/scripts/lib/links.ts +1 -1
  9. package/skills/c64-docs/scripts/lib/markdown.ts +1 -1
  10. package/skills/c64-docs/scripts/lib/reference.ts +59 -13
  11. package/skills/c64-knowledge/SKILL.md +17 -8
  12. package/skills/c64-knowledge/scripts/knowledge.ts +200 -218
  13. package/skills/c64-knowledge/scripts/lib/check.ts +2 -3
  14. package/skills/c64-knowledge/scripts/lib/listing.ts +62 -31
  15. package/skills/c64-packer/scripts/packer.ts +3 -3
  16. package/skills/c64-provenance/SKILL.md +28 -18
  17. package/skills/c64-provenance/scripts/lib/compare.ts +31 -21
  18. package/skills/c64-provenance/scripts/lib/leftovers.ts +17 -35
  19. package/skills/c64-provenance/scripts/lib/library.ts +10 -10
  20. package/skills/c64-provenance/scripts/lib/runtime.ts +3 -14
  21. package/skills/c64-provenance/scripts/provenance.ts +144 -113
  22. package/skills/c64-source/SKILL.md +6 -1
  23. package/skills/c64-source/references/loader.md +2 -1
  24. package/skills/c64-source/scripts/lib/export.ts +54 -301
  25. package/skills/c64-source/scripts/lib/loader.ts +31 -51
  26. package/skills/c64-source/scripts/lib/source.ts +53 -45
  27. package/skills/c64-source/scripts/lib/stage.ts +9 -25
  28. package/skills/c64-source/scripts/source.ts +134 -294
  29. package/skills/c64-static-analysis/SKILL.md +13 -7
  30. package/skills/c64-static-analysis/scripts/lib/coverage.ts +1 -3
  31. package/skills/c64-static-analysis/scripts/lib/findings.ts +16 -3
  32. package/skills/c64-static-analysis/scripts/lib/idioms.ts +98 -19
  33. package/skills/c64-static-analysis/scripts/lib/triage.ts +112 -0
  34. package/skills/c64-static-analysis/scripts/static-analysis.ts +249 -147
  35. package/skills/c64-testing/SKILL.md +13 -7
  36. package/skills/c64-testing/scripts/lib/diff-files.ts +6 -13
  37. package/skills/c64-testing/scripts/lib/recording.ts +47 -66
  38. package/skills/c64-testing/scripts/lib/replay.ts +53 -9
  39. package/skills/c64-testing/scripts/lib/runs.ts +11 -29
  40. package/skills/c64-testing/scripts/lib/scenario.ts +30 -31
  41. package/skills/c64-testing/scripts/lib/start-screen.ts +42 -5
  42. package/skills/c64-testing/scripts/testing.ts +32 -7
  43. package/skills/c64-unpacker/SKILL.md +9 -7
  44. package/skills/c64-unpacker/scripts/lib/evidence.ts +23 -38
  45. package/skills/c64-unpacker/scripts/lib/loads.ts +24 -39
  46. package/skills/c64-unpacker/scripts/lib/machine.ts +38 -18
  47. package/skills/c64-unpacker/scripts/lib/stages.ts +124 -40
  48. package/skills/c64-unpacker/scripts/unpacker.ts +81 -68
  49. package/skills/emulator/SKILL.md +1 -0
  50. package/src/c64.ts +133 -10
  51. package/src/cli/ap-sdk.ts +1 -1
  52. package/src/cli/cleanup.ts +4 -2
  53. package/src/compare.ts +36 -16
  54. package/src/errors.ts +10 -1
  55. package/src/host/main.ts +2 -1
  56. package/src/host/server.ts +7 -11
  57. package/src/host/tools/c1541.ts +9 -3
  58. package/src/host/vice/adapter.ts +20 -43
  59. package/src/host/vice/binary-monitor.ts +22 -21
  60. package/src/host/vice/process.ts +31 -40
  61. package/src/host/vice/session.ts +187 -247
  62. package/src/host/vice/text-monitor.ts +3 -3
  63. package/src/host-client/autostart.ts +1 -1
  64. package/src/host-client/connect.ts +2 -1
  65. package/src/host-client/coverage.ts +0 -3
  66. package/src/host-client/entry-state.ts +4 -11
  67. package/src/host-client/image.ts +6 -11
  68. package/src/host-client/steps.ts +13 -113
  69. package/src/host-client/tools.ts +4 -4
  70. package/src/host-client/transfer.ts +10 -0
  71. package/src/host-client/vice-session.ts +10 -6
  72. package/src/knowledge/code-reach.ts +364 -0
  73. package/src/knowledge/conflicts.ts +34 -72
  74. package/src/knowledge/database.ts +40 -28
  75. package/src/knowledge/evidence.ts +2 -2
  76. package/src/knowledge/graph.ts +3 -3
  77. package/src/knowledge/history.ts +50 -90
  78. package/src/knowledge/import.ts +28 -68
  79. package/src/knowledge/join.ts +1 -1
  80. package/src/knowledge/names.ts +12 -7
  81. package/src/knowledge/program.ts +59 -72
  82. package/src/knowledge/read.ts +104 -100
  83. package/src/knowledge/schema.ts +9 -3
  84. package/src/knowledge/separate.ts +175 -80
  85. package/src/knowledge/start-screen.ts +7 -5
  86. package/src/knowledge/text.ts +56 -33
  87. package/src/knowledge/write.ts +274 -515
  88. package/src/loader.ts +7 -25
  89. package/src/mcp/inputs.ts +3 -3
  90. package/src/mcp/server.ts +19 -38
  91. package/src/mcp/session-source.ts +2 -1
  92. package/src/mcp/tools/debug.ts +97 -24
  93. package/src/mcp/tools/execution.ts +1 -1
  94. package/src/mcp/tools/input.ts +3 -3
  95. package/src/mcp/tools/machine.ts +3 -3
  96. package/src/mcp/tools/media.ts +4 -4
  97. package/src/mcp/tools/memory.ts +13 -17
  98. package/src/mcp/tools/video.ts +11 -25
  99. package/src/native/acme.ts +3 -3
  100. package/src/native/c64run.ts +2 -1
  101. package/src/native/decompiler/analyze.ts +11 -8
  102. package/src/native/decompiler/walk.ts +3 -4
  103. package/src/native/decompiler/wasm.ts +2 -2
  104. package/src/native/discover.ts +1 -1
  105. package/src/native/dxa.ts +9 -11
  106. package/src/native/exomizer.ts +1 -1
  107. package/src/native/processes.ts +4 -1
  108. package/src/native/run.ts +3 -3
  109. package/src/native/types.ts +9 -8
  110. package/src/opcodes.ts +3 -0
  111. package/src/platform.ts +9 -10
  112. package/src/program-code.ts +151 -0
  113. package/src/project.ts +8 -5
  114. package/src/protocol/framing.ts +51 -18
  115. package/src/protocol/messages.ts +1 -11
  116. package/src/protocol/tools.ts +0 -3
  117. package/src/protocol/vice.ts +588 -773
  118. package/src/script.ts +25 -23
  119. package/src/time.ts +1 -1
  120. package/src/trace.ts +3 -2
@@ -2,10 +2,9 @@
2
2
  // each item. knowledge.ts reads and writes the files; these functions check
3
3
  // each verdict and count the result, so the files stay consistent.
4
4
 
5
- import { createHash } from "node:crypto";
6
-
7
5
  import { SYMBOL_NAME } from "#src/c64.ts";
8
6
  import { Refusal } from "#src/errors.ts";
7
+ import { sha256 } from "#src/knowledge/text.ts";
9
8
 
10
9
  export const CHECK_VERDICTS = ["correct", "wrong", "unsure"] as const;
11
10
  export type CheckVerdict = (typeof CHECK_VERDICTS)[number];
@@ -52,7 +51,7 @@ export interface Verdicts {
52
51
  * in address order. A changed text or another row does not move a row.
53
52
  */
54
53
  export function pickSample<T extends { space: string; address: number; placement: string }>(rows: readonly T[], seed: number, count: number): T[] {
55
- const key = (row: T) => createHash("sha256").update(`${seed}:${row.space}:${row.address}:${row.placement}`).digest("hex");
54
+ const key = (row: T) => sha256(`${seed}:${row.space}:${row.address}:${row.placement}`);
56
55
  return rows
57
56
  .map((row) => ({ row, key: key(row) }))
58
57
  .sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
@@ -3,14 +3,19 @@
3
3
  // the bytes from coverage files, and the references in and out. Nothing here
4
4
  // reads files: knowledge.ts gives the lookups.
5
5
 
6
- import { COVERAGE, formatC64Address, formatC64Byte, POINTER_TABLE_TYPES, pointerTableEntries, type PointerTableType } from "#src/c64.ts";
6
+ import { type AddressRange, COVERAGE, formatC64Address, formatC64Byte, hexByte, inRanges, POINTER_TABLE_TYPES, pointerEntryText, pointerTableEntries, type PointerTableType, splitEntryByte } from "#src/c64.ts";
7
+ import { CODE_REGION_TYPES, INSTRUCTION_REGION_TYPES } from "#src/knowledge/schema.ts";
7
8
  import { instructionWith, MODE_LENGTH, OPCODES, type Mode } from "#src/opcodes.ts";
8
9
 
9
10
  export interface ListingSource {
10
11
  /** The image byte at an address, or undefined outside the image. */
11
12
  byteAt: (address: number) => number | undefined;
12
- /** The name of an address: a symbol, else a platform name. */
13
- nameOf: (address: number) => string | undefined;
13
+ /** The symbol of an address in the knowledge, without platform names. */
14
+ symbolOf: (address: number) => string | undefined;
15
+ /** The platform name of an address, of a ROM that the program uses. None without it. */
16
+ platformOf?: (address: number) => string | undefined;
17
+ /** The I/O area: inside the image, its platform names name the registers, not the RAM of the program, so they are no labels. */
18
+ io?: AddressRange;
14
19
  /** The start of the platform entry of more bytes that holds an address outside the image (NMINV for its high byte), or undefined. */
15
20
  entryStart?: (address: number) => number | undefined;
16
21
  /** The analyzer names of an address, for reference. */
@@ -44,7 +49,8 @@ export interface ListingLine {
44
49
 
45
50
  type Region = ListingSource["regions"][number];
46
51
 
47
- const CODE = new Set(["code", "jumps"]);
52
+ const CODE = new Set<string>(CODE_REGION_TYPES);
53
+ const INSTRUCTIONS = new Set<string>(INSTRUCTION_REGION_TYPES);
48
54
  const TABLES = new Set<string>(["words", ...POINTER_TABLE_TYPES]);
49
55
  const DATA_PER_LINE = 8;
50
56
 
@@ -57,17 +63,31 @@ function accessOf(coverage: Uint8Array | undefined, start: number, length: numbe
57
63
  return text === "" ? "-" : text;
58
64
  }
59
65
 
66
+ /** The name of an address: its symbol, else its platform name. */
67
+ function nameOf(address: number, source: ListingSource): string | undefined {
68
+ return source.symbolOf(address) ?? source.platformOf?.(address);
69
+ }
70
+
71
+ /** The label of a line of the image, as c64-source writes it: a platform name in the I/O area names the register, not the RAM there. */
72
+ function labelOf(address: number, source: ListingSource): string | undefined {
73
+ return source.io !== undefined && inRanges([source.io], address) ? source.symbolOf(address) : nameOf(address, source);
74
+ }
75
+
60
76
  /**
61
77
  * The name of an operand target, as c64-source writes it: its own name, else
62
- * name+offset inside a named data region, or inside a platform entry of more bytes.
78
+ * name+offset inside a data region with a symbol at its start, or inside a
79
+ * platform entry of more bytes. A platform name at the start of a region is
80
+ * no name of the region: colour RAM in a region from $D000 is not SP0X+2048.
63
81
  */
64
82
  function targetName(target: number, source: ListingSource): string | undefined {
65
- const own = source.nameOf(target);
83
+ const own = nameOf(target, source);
66
84
  if (own !== undefined) return own;
67
- const region = source.regions.find((row) => target > row.start && target <= row.end && !CODE.has(row.type) && row.type !== "dual-use");
68
- const start = region?.start ?? source.entryStart?.(target);
69
- const name = start === undefined ? undefined : source.nameOf(start);
70
- return name === undefined ? undefined : `${name}+${target - start!}`;
85
+ const region = source.regions.find((row) => target > row.start && target <= row.end && !INSTRUCTIONS.has(row.type));
86
+ const table = region === undefined ? undefined : source.symbolOf(region.start);
87
+ if (table !== undefined) return `${table}+${target - region!.start}`;
88
+ const entry = source.entryStart?.(target);
89
+ const name = entry === undefined ? undefined : nameOf(entry, source);
90
+ return name === undefined ? undefined : `${name}+${target - entry!}`;
71
91
  }
72
92
 
73
93
  /** The operand value of an instruction as an expression: the name of its target where one exists, else the number. Empty for no operand. */
@@ -80,8 +100,9 @@ function operandOf(mode: Mode, address: number, low: number, high: number, sourc
80
100
  }
81
101
 
82
102
  /**
83
- * The values of a table region as c64-source writes them: a word of a words or an address table
84
- * as one !word value, and each byte of a split table as <target or >target. A byte of no entry has no value.
103
+ * The values of a table region in the form that c64-source writes, with the names of the
104
+ * knowledge and the platform: a word of a words or an address table as one !word value, and
105
+ * each byte of a split table as <target or >target. A byte of no entry has no value.
85
106
  */
86
107
  function tableValues(region: Region, source: ListingSource): Map<number, { length: 1 | 2; text: string }> {
87
108
  const values = new Map<number, { length: 1 | 2; text: string }>();
@@ -97,15 +118,13 @@ function tableValues(region: Region, source: ListingSource): Map<number, { lengt
97
118
  const split = region.type === "addresses-split" || region.type === "rts-addresses-split";
98
119
  for (const entry of pointerTableEntries({ start: region.start, end: region.end, type: region.type as PointerTableType }, byteAt)) {
99
120
  if (!present(entry.low) || !present(entry.high)) continue;
100
- const target = targetName(entry.target, source) ?? formatC64Address(entry.target);
101
- const text = rts ? `${target}-1` : target;
121
+ const text = pointerEntryText(entry.target, rts, (address) => targetName(address, source));
102
122
  if (!split) {
103
123
  values.set(entry.low, { length: 2, text });
104
124
  continue;
105
125
  }
106
- const part = /^[$A-Za-z_.0-9]+$/.test(text) ? text : `(${text})`;
107
- values.set(entry.low, { length: 1, text: `<${part}` });
108
- values.set(entry.high, { length: 1, text: `>${part}` });
126
+ values.set(entry.low, { length: 1, text: splitEntryByte(text, false) });
127
+ values.set(entry.high, { length: 1, text: splitEntryByte(text, true) });
109
128
  }
110
129
  return values;
111
130
  }
@@ -119,8 +138,8 @@ export function listing(source: ListingSource, start: number, end: number, optio
119
138
  const lines: ListingLine[] = [];
120
139
  const data = options.code !== true;
121
140
  const line = (address: number, length: number, text: string): ListingLine => {
122
- const bytes = Array.from({ length }, (_, offset) => source.byteAt(address + offset)!.toString(16).padStart(2, "0")).join(" ");
123
- const label = source.nameOf(address);
141
+ const bytes = Array.from({ length }, (_, offset) => hexByte(source.byteAt(address + offset)!)).join(" ");
142
+ const label = labelOf(address, source);
124
143
  const second = source.secondNames(address).filter((name) => name !== label);
125
144
  const { line: lineComments, side: own } = source.comments(address);
126
145
  // A comment inside the line (knowledge of an older version) shows with its address, as in the source of c64-source.
@@ -163,9 +182,11 @@ export function listing(source: ListingSource, start: number, end: number, optio
163
182
  const length = MODE_LENGTH[opcode.mode];
164
183
  const bytes = Array.from({ length: length - 1 }, (_, offset) => source.byteAt(address + 1 + offset));
165
184
  if (address + length - 1 <= region.end && bytes.every((value) => value !== undefined)) {
166
- // The operand expression of the knowledge in the syntax of the addressing mode, as c64-source writes it.
167
- const operand = source.operand(address) ?? operandOf(opcode.mode, address, bytes[0] ?? 0, bytes[1] ?? 0, source);
168
- if (address >= start) lines.push(line(address, length, instructionWith(byte, operand)));
185
+ if (address >= start) {
186
+ // The operand expression of the knowledge in the syntax of the addressing mode, as c64-source writes it.
187
+ const operand = source.operand(address) ?? operandOf(opcode.mode, address, bytes[0] ?? 0, bytes[1] ?? 0, source);
188
+ lines.push(line(address, length, instructionWith(byte, operand)));
189
+ }
169
190
  address += length;
170
191
  continue;
171
192
  }
@@ -183,7 +204,7 @@ export function listing(source: ListingSource, start: number, end: number, optio
183
204
  let at = address;
184
205
  while (size !== undefined && at <= end && texts.length * size < DATA_PER_LINE) {
185
206
  const value = table.get(at);
186
- if (value?.length !== size || (at !== address && source.nameOf(at) !== undefined) || (size === 2 && source.nameOf(at + 1) !== undefined)) break;
207
+ if (value?.length !== size || (at !== address && labelOf(at, source) !== undefined) || (size === 2 && labelOf(at + 1, source) !== undefined)) break;
187
208
  texts.push(value.text);
188
209
  at += size;
189
210
  }
@@ -196,7 +217,7 @@ export function listing(source: ListingSource, start: number, end: number, optio
196
217
  // Bytes up to the next label, table value, region edge or end of the line.
197
218
  const values: number[] = [];
198
219
  let at = address;
199
- while (at <= end && values.length < DATA_PER_LINE && source.byteAt(at) !== undefined && (at === address || (source.nameOf(at) === undefined && regionAt(at) === region && table?.has(at) !== true))) {
220
+ while (at <= end && values.length < DATA_PER_LINE && source.byteAt(at) !== undefined && (at === address || (labelOf(at, source) === undefined && regionAt(at) === region && table?.has(at) !== true))) {
200
221
  values.push(source.byteAt(at)!);
201
222
  at++;
202
223
  }
@@ -206,19 +227,29 @@ export function listing(source: ListingSource, start: number, end: number, optio
206
227
  return lines;
207
228
  }
208
229
 
209
- /** A listing as text, one line for each line, with its line comments above it. */
210
- export function listingText(lines: readonly ListingLine[]): string {
230
+ /**
231
+ * A listing as text lines, as the agent reads it: each line comment as a line
232
+ * of its own, `; <comment>`, before its line, and each line as
233
+ * `<address> <bytes> <access> <label>: <text> ; <comment> | refs in <n> out <n> | also <names>`.
234
+ * Two spaces separate the parts. A part that the line does not have is not there.
235
+ */
236
+ export function listingLines(lines: readonly ListingLine[]): string[] {
211
237
  const out: string[] = [];
212
238
  for (const item of lines) {
213
- for (const comment of item.lineComments ?? []) out.push(` ; ${comment}`);
214
- const head = `${formatC64Address(item.address)} ${item.bytes.padEnd(9)} ${(item.access ?? "").padEnd(3)}`;
215
- const body = (item.label === undefined ? "" : `${item.label} `).padEnd(20) + item.text;
239
+ for (const comment of item.lineComments ?? []) out.push(`; ${comment}`);
216
240
  const notes = [
217
241
  ...(item.comment === undefined ? [] : [item.comment]),
218
242
  ...(item.referencesIn + item.referencesOut === 0 ? [] : [`refs in ${item.referencesIn} out ${item.referencesOut}`]),
219
243
  ...(item.analyzerNames === undefined ? [] : [`also ${item.analyzerNames.join(", ")}`]),
220
244
  ];
221
- out.push(`${head} ${body.padEnd(44)}${notes.length === 0 ? "" : ` ; ${notes.join(" | ")}`}`.trimEnd());
245
+ const parts = [
246
+ formatC64Address(item.address),
247
+ item.bytes,
248
+ ...(item.access === undefined ? [] : [item.access]),
249
+ `${item.label === undefined ? "" : `${item.label}: `}${item.text}`,
250
+ ...(notes.length === 0 ? [] : [`; ${notes.join(" | ")}`]),
251
+ ];
252
+ out.push(parts.join(" "));
222
253
  }
223
- return `${out.join("\n")}\n`;
254
+ return out;
224
255
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { posix } from "node:path";
7
7
 
8
- import { findHandoffs, formatC64Address, parseTokenized, prgRange } from "#src/c64.ts";
8
+ import { findHandoffs, formatC64Address, formatC64Byte, formatC64RangeFields, parseTokenized, prgRange } from "#src/c64.ts";
9
9
  import { compareBuild, mergedPrograms } from "#src/compare.ts";
10
10
  import { isRefusal, Refusal } from "#src/errors.ts";
11
11
  import { readProjectFile, writeReported } from "#src/host-client/transfer.ts";
@@ -84,9 +84,9 @@ await runScript({
84
84
  unpackedBytes,
85
85
  percent: Math.round((packed.program.length / unpackedBytes) * 1000) / 10,
86
86
  entry: formatC64Address(entry),
87
- ...(exitMemory === undefined ? {} : { exitMemory: `$${exitMemory.toString(16)}` }),
87
+ ...(exitMemory === undefined ? {} : { exitMemory: formatC64Byte(exitMemory) }),
88
88
  ...(packed.cycles === undefined ? {} : { unpackSeconds: Math.round((packed.cycles / PAL_CYCLES_PER_SECOND) * 10) / 10 }),
89
- inputs: programs.map((program) => ({ file: program.file, loadRange: { start: formatC64Address(program.start), end: formatC64Address(program.end) }, bytes: program.body.length })),
89
+ inputs: programs.map((program) => ({ file: program.file, loadRange: formatC64RangeFields(program), bytes: program.body.length })),
90
90
  check: { entry: formatC64Address(packed.entry), ...check },
91
91
  };
92
92
  const hint =
@@ -24,6 +24,7 @@ To get the command list, run the script with no arguments.
24
24
  | Goal | Command |
25
25
  |---|---|
26
26
  | Compare two or more releases | `compare releases/a.prg releases/b.prg releases/c.prg` |
27
+ | Compare the releases in the project knowledge | `compare V1 V2 V3` |
27
28
  | Compare a release that loads at a different address | `compare releases/a.prg releases/b.prg --shift 2:-256` |
28
29
  | Compare only the bytes in a range | `compare releases/a.prg releases/b.prg --range '$0900-$09ff'` |
29
30
  | Map two releases with moved code in blocks of equal bytes | `compare releases/a/image.json releases/b/image.json --align --range '$0400-$bfff'` |
@@ -44,6 +45,7 @@ To get the command list, run the script with no arguments.
44
45
 
45
46
  - `compare` takes two or more releases. A release is one of these:
46
47
  - `knowledge`: the program in the project knowledge.
48
+ - The label of a release in the project knowledge, for example `V2`. The base release is the program in the project knowledge. For another release, the project knowledge keeps only its bytes. Thus `--frames` cannot start it. To run that release, give its file. A label that is not a release gets error `not-found`, with the labels of the releases.
47
49
  - A PRG file. The script puts it at its load address.
48
50
  - The `image.json` of a capture folder. Keep all files of the capture folder together. Without them, `--frames` cannot start the release.
49
51
  - Get a PRG out of a disk image before you compare it. The script refuses a disk image, a tape image and a cartridge image.
@@ -106,23 +108,26 @@ Compares the releases byte by byte at the addresses where all releases have byte
106
108
 
107
109
  `body` holds:
108
110
 
109
- - `releases`: the `name`, the `shift` and the `segments` of each release. An image has bytes only in its segments.
111
+ - `releases`: the `release`, the `name`, the `shift` and the `segments` of each release. `release` is the number of the release. An image has bytes only in its segments.
112
+ - `outsideCommon`: the ranges of the release in `--range` that are not in `common`. Another release has no bytes there, so the script does not compare these bytes. Examine them in each release.
110
113
  - `common`: the ranges where all releases have bytes. The script compares only these ranges.
111
114
  - `identicalBytes` and `differingBytes`: the counts of the bytes.
112
115
  - `identicalShare`: the share of identical bytes, with 3 decimals. It is 1 only when no byte differs.
113
- - `differences`: each item has `start`, `end`, `values` and `groups`. `values` gives the bytes of each release, at most 32. `groups` gives the releases that have the same bytes there.
116
+ - `differences`: each item has `start`, `end`, `values` and `groups`. `values` gives the bytes of each release, at most 32, by the number of the release. `groups` gives the numbers of the releases that have the same bytes there.
114
117
  - `moreDifferences: true`: `differences` holds only the first differences.
115
118
  - `suggestedShifts`: only when `identicalShare` is less than 0.5. Each item has `release`, `shift` and `matchingSequences`. Each release has at most 3 shifts, with the most `matchingSequences` first. `current: true` marks the shift of this run.
119
+ - `matchingSequences` counts the sequences of 8 bytes of release 1 in `--range` that the release has at that shift.
120
+ - A shift has at least 8 `matchingSequences`. Thus a range of fewer than 15 bytes gets no shift.
116
121
  - `shiftsNotSuggested`: each item has a `reason`. The reason tells why a shift does not fit in `$0000-$ffff`.
117
122
 
118
123
  With `--shift`, the addresses of `segments`, `common` and `differences` are the release addresses plus the `shift` of the release.
119
124
 
120
125
  With `--frames`, the body also holds:
121
126
 
122
- - `runtime` in each difference: one item for each release that started. `start` and `end` are the addresses in the release, without the shift.
127
+ - `runtime` in each difference: one item for each release that started, by the number of the release. `start` and `end` are the addresses in the release, without the shift.
123
128
  - `first`: the first access in that release: `read`, `write`, `execute` or `none`. An instruction that reads and then writes the same byte, for example INC, counts as `read`. The operand bytes of an executed instruction count as `execute`, for example the `$03` of `LDA #$03`.
124
129
  - `changed`: `true` when the bytes at the end of the run are not the bytes of the release.
125
- - `run`: `frames`, `steps` and `releases`. `releases` tells for each release if it started, or the `reason` that it did not start. `skipped` tells that the releases have no differences, so no release ran.
130
+ - `run`: `frames`, `steps` and `releases`. `releases` tells for each release, by its number, if it started, or the `reason` that it did not start. `skipped` tells that the releases have no differences, so no release ran.
126
131
 
127
132
  A PRG starts with RUN after its load. An image starts at its entry, with the entry state of its capture.
128
133
 
@@ -138,17 +143,21 @@ With `--align`, the body holds a map in place of `differences` and the shift sug
138
143
  `hint` and `nextAction`:
139
144
 
140
145
  - `identicalShare` is low, and a shift is in `suggestedShifts`: `nextAction` runs `compare` with the first shift that the run does not have. Try each shift. Data that did not move and code that moved give different shifts.
141
- - `identicalShare` is low, and no shift is better: `nextAction` runs `compare` with `--align`. The code and the data can be at other addresses in each release.
146
+ - `identicalShare` is low, no shift is better, and `suggestedShifts` or `shiftsNotSuggested` has items: `nextAction` runs `compare` with `--align`. The code and the data can be at other addresses in each release.
142
147
  - `moreDifferences` or a `more...` count is in the body: `hint` tells you to compare a smaller `--range`.
143
148
 
144
149
  Traps:
145
150
 
146
151
  - `common` is empty: the releases do not have bytes at the same addresses. Give `--shift`, or a `--range` that all releases have.
147
- - A release has `started: false`: the PRG has no BASIC start, or the capture folder of the image has no entry state. The `reason` tells which. The other releases still give evidence.
152
+ - `identicalShare` is low, and the body has no `suggestedShifts` and no `shiftsNotSuggested`: the bytes do not show a shift, for example in a small `--range`. The releases can have different bytes at the same addresses. Read `differences`.
153
+ - A release has `started: false`: the `reason` tells why it did not start. The other releases still give evidence. These releases do not start:
154
+ - A PRG without a BASIC start.
155
+ - An image whose capture folder has no entry state.
156
+ - The label of a release that is not the base release.
148
157
  - Each release writes a range before it reads it: the range is probably runtime state, not a difference of the releases.
149
158
  - A range has `first: none` in each release: the run did not use it. Run more frames or other steps before you decide.
150
159
  - The script refuses `--align` with `--shift` or `--frames`. It refuses `--min-block` without `--align`, and `--steps` without `--frames`.
151
- - Error `not-found`: the project has no file at that path.
160
+ - Error `not-found`: the project has no file at that path, or the project knowledge has no release with that label. The message gives the labels of the releases. For a file with a name in upper case and no extension, give `./` before the name.
152
161
 
153
162
  ---
154
163
 
@@ -169,16 +178,17 @@ Gives evidence from the program in the project knowledge, its stages and its cov
169
178
  - `access` is `executed`, `read`, `written`, `read-written` or `untouched`. `untouched` bytes did not take part in the runs.
170
179
  - A `read` byte right after executed code, or at a return address, can be a dummy read of the 6502. The program does not use it.
171
180
  - `roots`: the addresses where the reachability starts, each with `address` and `from`. The roots are the entry, and the NMI, RESET and IRQ vectors at `$fffa`-`$ffff` when the program holds them. A text in place of the list tells why no code region is reachable.
172
- - `codeRegions.total`: the number of code regions in the project knowledge.
173
- - `codeRegions.unreachable`: the code regions that no chain of call and jump references reaches from a root.
181
+ - `codeRegions`: the code regions in the project knowledge, as a list. Each region has `reachable`, and `executed` with coverage. `unknown` is `true` for a region that no root reaches and that no run executed, when the project knowledge has no coverage. It is also `true` when a flow in `unresolved` can go to the region.
182
+ - `codeRegions.unreachable`: the code regions that no chain of call and jump references reaches from a root. When the code stores the address of a handler with immediates in an interrupt vector at `$0314`-`$0319` or `$fffa`-`$ffff`, that code reaches the handler.
183
+ - `unresolved`: only when a code region is unknown. These are the flows in the reached or executed code regions whose targets the project knowledge does not give.
174
184
  - `outside`: only with coverage. `read` and `executed` give the RAM outside the program that the program used but did not write. A loader or an earlier stage put these bytes there. `generated` gives the code that the program wrote outside its segments.
175
185
  - `out`, `bytes` and `sha256`: the `--out` file. It has the fields of the body, with all items of each list.
176
186
 
177
- `hint`: a list is cut. Run the command again with a larger `--max-listed`.
187
+ `hint`: a list is cut. Run the command again with a larger `--max-listed`, or read the `--out` file.
178
188
 
179
189
  Traps:
180
190
 
181
- - No code regions in the project knowledge: `codeRegions` is empty. Analyze the program for its code regions and its references first.
191
+ - No code regions in the project knowledge: `codeRegions.count` is 0. Analyze the program for its code regions and its references first.
182
192
  - Many `untouched` ranges: do more coverage runs for these parts. Put the coverage into the project knowledge before you decide.
183
193
  - Error `not-found`: the project knowledge has no program. Put the program into the project knowledge.
184
194
 
@@ -193,16 +203,16 @@ Finds what the program in the project knowledge holds in addition to its working
193
203
  | `text` | Text, and lines of assembler source. `encoding` is `petscii`, `screen`, `ascii` or `high-bit`. `reversed: true` marks screen codes with bit 7 set. `source: true` marks lines of assembler source. A line end in `text` is a new line. `mnemonics` counts 6502 instructions in the text. A text of more than 120 characters is cut, and `length` gives its full length. |
194
204
  | `basic` | Two or more BASIC lines away from the BASIC start. `linkedAt` is the address where BASIC linked the lines. It can be a different address from the address of the bytes now. |
195
205
  | `fill` | One byte that repeats at least 16 times, or a pattern of two to four bytes that repeats for at least 32 bytes. `pattern` is the repeated bytes. |
196
- | `residue` | Bytes that no run touched, and that are not text, BASIC, fill or a code region. `bytes` shows the first 16 bytes. |
206
+ | `residue` | Bytes that no run touched, and that are not text, BASIC, fill, a code region, dead code or unknown code. `bytes` shows the first 16 bytes. |
197
207
  | `copies` | At least 32 bytes that are the same as earlier bytes of the program. `copyOf` is the address of the earlier bytes. |
198
- | `deadCode` | Code regions that no root reaches, as in `codeRegions.unreachable` of `separate`, and that no run executed. |
199
- | `unknownCode` | Code regions that no root reaches and that no run executed, but that are not dead code. No coverage shows that they did not run, or a flow in `unresolved` can go to them. Each flow has `at` and `kind`. |
208
+ | `deadCode` | Code that no run executed and that nothing reaches. The script decodes the instructions from the entry, the routines, the code regions and the coverage. A call, a jump, a branch, a table entry or an interrupt vector reaches code. The reach starts at the entry, at the code that a run executed, at the patches and at the start screen. The leftover files of a generated source hold the same code. |
209
+ | `unknownCode` | Code that no run executed and that nothing reaches, but that is not dead code: a flow in `unresolved` can go to it. Each flow has `at` and `kind`: `indirect-jump`, `written-operand` or `pushed-return`. |
200
210
 
201
211
  Each finding has `stages`: the unpack stages that wrote its bytes. A stage before the last stage is a depacker, an intro or a loader. Each finding also has `access`: the accesses of its bytes in the coverage.
202
212
 
203
213
  `out`, `bytes` and `sha256` give the `--out` file. It has the fields of the body, with all findings and the full texts.
204
214
 
205
- `hint`: a list is cut. Run the command again with a larger `--max-listed`. To get only the lists that you need, give `--fields`, for example `--fields text,deadCode`.
215
+ `hint`: a list is cut. Run the command again with a larger `--max-listed`, or read the `--out` file. To get only the lists that you need, give `--fields`, for example `--fields text,deadCode`.
206
216
 
207
217
  Text from another computer can show the tools of the developer:
208
218
 
@@ -219,9 +229,9 @@ Read the findings with care:
219
229
 
220
230
  Traps:
221
231
 
222
- - No coverage: `residue` is empty. Put the coverage of runs that use many parts of the program into the project knowledge.
223
- - No code regions: `deadCode` is empty, and `residue` can include code. Analyze the program for its code regions first.
224
- - `unknownCode` has items: a flow in `unresolved` can go to the code, or the knowledge has no coverage. Do not call this code dead. Find the targets of each flow in the emulator, and record a jump reference from the flow to each target in the project knowledge. When the flow goes outside the program, record the reference to that address.
232
+ - No coverage: `residue`, `deadCode` and `unknownCode` are empty. Put the coverage of runs that use many parts of the program into the project knowledge.
233
+ - No code regions and no routines: the script decodes only the code that the entry and the coverage reach. Then `deadCode` is empty, and `residue` can include code. Analyze the program for its code regions first.
234
+ - `unknownCode` has items: a flow in `unresolved` can go to the code. Do not call this code dead. Find the targets of each flow in the emulator, and record a jump reference from the flow to each target in the project knowledge. When the flow goes outside the program, record the reference to that address.
225
235
  - Error `not-found`: the project knowledge has no program. Put the program into the project knowledge.
226
236
 
227
237
  ---
@@ -7,7 +7,7 @@
7
7
  // bytes. It never decides which bytes the publisher shipped: that needs evidence
8
8
  // beyond one comparison.
9
9
 
10
- import { type AddressRange, formatC64Address } from "#src/c64.ts";
10
+ import { type AddressRange, formatC64Range } from "#src/c64.ts";
11
11
 
12
12
  export interface Release {
13
13
  name: string;
@@ -20,15 +20,17 @@ export interface Release {
20
20
  export interface DifferingRange {
21
21
  start: number;
22
22
  end: number;
23
- /** The bytes of each release in this range, by release name. */
24
- values: Record<string, number[]>;
25
- /** Releases with the same bytes here, largest group first. */
26
- groups: string[][];
23
+ /** The bytes of each release in this range, in the order of the releases: a name can be given two times. */
24
+ values: number[][];
25
+ /** The numbers of the releases (1 is the first) with the same bytes here, largest group first. */
26
+ groups: number[][];
27
27
  }
28
28
 
29
29
  export interface Comparison {
30
30
  /** The addresses where every release has bytes. */
31
31
  common: AddressRange[];
32
+ /** For each release, in order: its addresses in the range that are not in common, because another release has no bytes there. */
33
+ outsideCommon: AddressRange[][];
32
34
  identicalBytes: number;
33
35
  differingBytes: number;
34
36
  differences: DifferingRange[];
@@ -54,10 +56,15 @@ export function identicalShare(identical: number, differing: number): number {
54
56
  }
55
57
 
56
58
  /** The ranges where every release has bytes, inside from..to. */
57
- export function commonRanges(releases: Release[], from = 0x0000, to = 0xffff): AddressRange[] {
59
+ function commonRanges(releases: Release[], from = 0x0000, to = 0xffff): AddressRange[] {
58
60
  return rangesOf(Array.from({ length: to - from + 1 }, (_, offset) => from + offset).filter((address) => releases.every((release) => covers(release, address))));
59
61
  }
60
62
 
63
+ /** The addresses of a release inside from..to where another release has no bytes. */
64
+ function outsideOthers(release: Release, releases: Release[], from: number, to: number): AddressRange[] {
65
+ return rangesOf(addressesOf(release).filter((address) => address >= from && address <= to && !releases.every((other) => covers(other, address))));
66
+ }
67
+
61
68
  /** Consecutive addresses in order as ranges. */
62
69
  function rangesOf(addresses: number[]): AddressRange[] {
63
70
  const ranges: AddressRange[] = [];
@@ -71,6 +78,7 @@ function rangesOf(addresses: number[]): AddressRange[] {
71
78
 
72
79
  export function compareReleases(releases: Release[], options: { from?: number; to?: number; maxRanges?: number } = {}): Comparison {
73
80
  const common = commonRanges(releases, options.from, options.to);
81
+ const outsideCommon = releases.map((release) => outsideOthers(release, releases, options.from ?? 0x0000, options.to ?? 0xffff));
74
82
  let identicalBytes = 0;
75
83
  const differing: number[] = [];
76
84
  for (const range of common) {
@@ -90,17 +98,15 @@ export function compareReleases(releases: Release[], options: { from?: number; t
90
98
  }
91
99
  const limit = options.maxRanges ?? 64;
92
100
  const differences = ranges.slice(0, limit).map((range) => {
93
- const values: Record<string, number[]> = {};
94
- const groups = new Map<string, string[]>();
95
- for (const release of releases) {
96
- const bytes = Array.from({ length: range.end - range.start + 1 }, (_, offset) => release.byteAt(range.start + offset));
97
- values[release.name] = bytes;
101
+ const values = releases.map((release) => Array.from({ length: range.end - range.start + 1 }, (_, offset) => release.byteAt(range.start + offset)));
102
+ const groups = new Map<string, number[]>();
103
+ for (const [index, bytes] of values.entries()) {
98
104
  const key = bytes.join(",");
99
- groups.set(key, [...(groups.get(key) ?? []), release.name]);
105
+ groups.set(key, [...(groups.get(key) ?? []), index + 1]);
100
106
  }
101
107
  return { ...range, values, groups: [...groups.values()].sort((a, b) => b.length - a.length) };
102
108
  });
103
- return { common, identicalBytes, differingBytes: differing.length, differences, moreDifferences: ranges.length > limit };
109
+ return { common, outsideCommon, identicalBytes, differingBytes: differing.length, differences, moreDifferences: ranges.length > limit };
104
110
  }
105
111
 
106
112
  /** The addresses of a release in order, so that a window of bytes can run over its segments. */
@@ -127,15 +133,19 @@ function indexWindows(release: Release, addresses: number[]): Map<string, number
127
133
  }
128
134
 
129
135
  /** Most shifts that suggestShifts gives: data that did not move can outvote code that did. */
130
- export const MAX_SUGGESTED_SHIFTS = 3;
136
+ const MAX_SUGGESTED_SHIFTS = 3;
137
+
138
+ /** The fewest equal 8-byte sequences for a shift: fewer occur by chance, and a range of fewer than 15 bytes has fewer. */
139
+ export const MIN_MATCHING_SEQUENCES = 8;
131
140
 
132
141
  /**
133
- * The shifts that put `other` over `base` best: the most common address
134
- * differences between equal 8-byte sequences, most votes first. A shift with
135
- * less than a tenth of the best one's votes is chance. Empty when nothing matches.
142
+ * The shifts that put `other` over the bytes of `base` in `range` best: the
143
+ * most common address differences between equal 8-byte sequences, most votes
144
+ * first. A shift with fewer than MIN_MATCHING_SEQUENCES votes, or with less than
145
+ * a tenth of the best one's votes, is chance. Empty when nothing matches.
136
146
  */
137
- export function suggestShifts(base: Release, other: Release): Array<{ shift: number; matches: number }> {
138
- const positions = indexWindows(base, addressesOf(base));
147
+ export function suggestShifts(base: Release, other: Release, range: AddressRange = { start: 0x0000, end: 0xffff }): Array<{ shift: number; matches: number }> {
148
+ const positions = indexWindows(base, addressesOf(base).filter((address) => address >= range.start && address <= range.end));
139
149
  const otherAddresses = addressesOf(other);
140
150
  const votes = new Map<number, number>();
141
151
  for (let at = 0; at + WINDOW <= otherAddresses.length; at++) {
@@ -145,7 +155,7 @@ export function suggestShifts(base: Release, other: Release): Array<{ shift: num
145
155
  }
146
156
  }
147
157
  const ranked = [...votes].map(([shift, matches]) => ({ shift, matches })).sort((a, b) => b.matches - a.matches || Math.abs(a.shift) - Math.abs(b.shift));
148
- return ranked.filter((found) => found.matches * 10 >= ranked[0]!.matches).slice(0, MAX_SUGGESTED_SHIFTS);
158
+ return ranked.filter((found) => found.matches >= MIN_MATCHING_SEQUENCES && found.matches * 10 >= ranked[0]!.matches).slice(0, MAX_SUGGESTED_SHIFTS);
149
159
  }
150
160
 
151
161
  export interface Block {
@@ -275,7 +285,7 @@ export type ShiftSuggestion = { release: number; shift: number; matchingSequence
275
285
  export function shiftSuggestion(releases: Release[], applied: number[], index: number, found: { shift: number; matches: number }): ShiftSuggestion {
276
286
  const outside = (release: Release, by: number) => release.segments.find((segment) => segment.start + by < 0 || segment.end + by > 0xffff);
277
287
  const why = (number: number, by: number, segment: AddressRange) =>
278
- `release ${number} moved by ${by} puts ${formatC64Address(segment.start)}-${formatC64Address(segment.end)} ${segment.start + by < 0 ? "below $0000" : "past $ffff"}`;
288
+ `release ${number} moved by ${by} puts ${formatC64Range(segment)} ${segment.start + by < 0 ? "below $0000" : "past $ffff"}`;
279
289
  const own = outside(releases[index]!, found.shift);
280
290
  if (own === undefined) return { release: index + 1, shift: applied[index]! + found.shift, matchingSequences: found.matches };
281
291
  const reasons = [why(index + 1, found.shift, own)];
@@ -1,13 +1,14 @@
1
1
  // Leftovers in one program for the c64-provenance script: text in PETSCII,
2
2
  // screen codes, ASCII or text with bit 7 set (Apple II), assembler source
3
3
  // lines, BASIC lines away from the BASIC start, fills, untouched
4
- // bytes outside code regions that no other finding explains, exact copies of
5
- // a byte range, and code that no call or jump reaches and no run executed. Each finding gets the stages and the accesses of
4
+ // bytes outside code that no other finding explains, exact copies of
5
+ // a byte range, and the unused and the unknown code of the code reach. Each finding gets the stages and the accesses of
6
6
  // its bytes from the separation. Evidence only: nothing here decides what a
7
7
  // leftover is or who made it.
8
8
 
9
- import { type AddressRange, basicLineText } from "#src/c64.ts";
9
+ import { type AddressRange, basicLineText, mergeRanges, subtract } from "#src/c64.ts";
10
10
  import { MNEMONICS } from "#src/opcodes.ts";
11
+ import type { CodeReach } from "#src/knowledge/code-reach.ts";
11
12
  import type { Access, Separation } from "#src/knowledge/separate.ts";
12
13
 
13
14
  export interface LeftoversInput {
@@ -15,6 +16,8 @@ export interface LeftoversInput {
15
16
  /** 64 KiB with the program bytes at their addresses. */
16
17
  memory: Uint8Array;
17
18
  separation: Separation;
19
+ /** The code reach of the program, as the leftovers of a generated source take it. */
20
+ code: Pick<CodeReach, "unused" | "unknown">;
18
21
  /** The first address of the BASIC start, which RUN lists: it is no leftover. */
19
22
  basicStart?: number;
20
23
  /** The fewest characters of a text (default 8). */
@@ -62,12 +65,8 @@ export interface CopyFinding extends AddressRange, Placement {
62
65
  copyOf: number;
63
66
  }
64
67
 
65
- /** A code region that no call or jump reaches from the entry, and that no run executed. */
66
- export interface DeadCodeFinding extends AddressRange, Placement {
67
- type: string;
68
- /** false when the coverage shows that it did not run; absent without coverage. */
69
- executed?: false;
70
- }
68
+ /** Code that nothing that stays reaches and that no run executed. */
69
+ export type CodeFinding = AddressRange & Placement;
71
70
 
72
71
  export interface Leftovers {
73
72
  text: TextFinding[];
@@ -75,9 +74,10 @@ export interface Leftovers {
75
74
  fill: FillFinding[];
76
75
  residue: ResidueFinding[];
77
76
  copies: CopyFinding[];
78
- deadCode: DeadCodeFinding[];
79
- /** Code that nothing reaches and that no run executed, which is not dead: a flow that nobody resolved can go there, or no coverage shows that it did not run. */
80
- unknownCode: DeadCodeFinding[];
77
+ /** The unused code of the code reach. */
78
+ deadCode: CodeFinding[];
79
+ /** Code that nothing reaches and that no run executed, which is not dead: a flow that nobody resolved can go there. */
80
+ unknownCode: CodeFinding[];
81
81
  }
82
82
 
83
83
  const MIN_TEXT = 8;
@@ -399,20 +399,8 @@ export function findCopies(memory: Uint8Array, segments: AddressRange[]): CopyFi
399
399
  return found;
400
400
  }
401
401
 
402
- /** Splits `range` at the parts that `taken` covers, and keeps the pieces of at least `min` bytes. */
403
- function without(range: AddressRange, taken: AddressRange[], min: number): AddressRange[] {
404
- const pieces: AddressRange[] = [];
405
- let start = range.start;
406
- for (const part of taken.filter((item) => item.start <= range.end && item.end >= range.start).sort((a, b) => a.start - b.start)) {
407
- if (part.start > start) pieces.push({ start, end: part.start - 1 });
408
- start = Math.max(start, part.end + 1);
409
- }
410
- if (start <= range.end) pieces.push({ start, end: range.end });
411
- return pieces.filter((piece) => piece.end - piece.start + 1 >= min);
412
- }
413
-
414
402
  export function findLeftovers(input: LeftoversInput): Leftovers {
415
- const { memory, segments, separation } = input;
403
+ const { memory, segments, separation, code } = input;
416
404
  const ranges = separation.ranges;
417
405
  const placement = (range: AddressRange): Placement => {
418
406
  const parts = ranges.filter((part) => part.start <= range.end && part.end >= range.start);
@@ -433,15 +421,9 @@ export function findLeftovers(input: LeftoversInput): Leftovers {
433
421
  if (last !== undefined && last.end + 1 === part.start) last.end = part.end;
434
422
  else untouched.push({ start: part.start, end: part.end });
435
423
  }
424
+ const deadCode = mergeRanges(code.unused);
436
425
  // Untouched code is code that the runs did not get to, or dead code, which has its own list.
437
- const explained = [...text, ...basic, ...fill, ...separation.codeRegions];
438
- const residue = untouched.flatMap((range) => without(range, explained, MIN_RESIDUE));
439
- // The references miss IRQ vectors and jumps through tables: code that ran is not dead.
440
- const unreached = separation.codeRegions
441
- .filter((region) => region.reachable === false && region.executed !== true)
442
- .map((region) => ({ start: region.start, end: region.end, type: region.type, ...(region.executed === false ? { executed: false as const } : {}), unknown: region.unknown === true }));
443
- const finding = ({ unknown: _, ...region }: (typeof unreached)[number]): DeadCodeFinding => region;
444
- const deadCode = unreached.filter((region) => !region.unknown).map(finding);
445
- const unknownCode = unreached.filter((region) => region.unknown).map(finding);
446
- return { text: placed(text), basic: placed(basic), fill: placed(fill), residue: placed(residue), copies: placed(findCopies(memory, segments)), deadCode: placed(deadCode), unknownCode: placed(unknownCode) };
426
+ const explained = [...text, ...basic, ...fill, ...separation.codeRegions, ...deadCode, ...code.unknown];
427
+ const residue = untouched.flatMap((range) => subtract(range, explained).filter((piece) => piece.end - piece.start + 1 >= MIN_RESIDUE));
428
+ return { text: placed(text), basic: placed(basic), fill: placed(fill), residue: placed(residue), copies: placed(findCopies(memory, segments)), deadCode: placed(deadCode), unknownCode: placed(code.unknown) };
447
429
  }