@henols/c64-re-tools 2.6.0-rc.11 → 2.6.0-rc.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.6.0-rc.11",
3
+ "version": "2.6.0-rc.12",
4
4
  "description": "Agent-friendly Commodore 64 engineering toolkit for reverse engineering, debugging, development and testing.",
5
5
  "license": "MIT",
6
6
  "author": "Henrik Olsson",
@@ -11,6 +11,7 @@ import { bitmapFrame, charsetFrame, encodePng, PATTERN_PALETTES, scaleFrame, scr
11
11
  import { mermaidGraph, ownerOf, routineEdges, routineHeads, type GraphReference, type RoutineHead } from "#src/knowledge/graph.ts";
12
12
  import type { CommentRow, ModuleRow, ReferenceRow, RegionRow, SymbolRow } from "#src/knowledge/read.ts";
13
13
  import type { RegionType } from "#src/knowledge/schema.ts";
14
+ import { platformNames } from "#src/platform.ts";
14
15
  import type { SourceMap } from "./source-map.ts";
15
16
 
16
17
  /** The first line of every generated page. A page without it is a page of a person, and docs.ts generate never writes over it. */
@@ -73,6 +74,8 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
73
74
  const entries = new Map<string, Entry>();
74
75
  const sortedNames = [...new Set([...input.symbols.map((symbol) => symbol.address), ...map.labels.filter((label) => label.file === "constants.asm").map((label) => label.address)])].sort((a, b) => a - b);
75
76
  const nextName = (address: number) => sortedNames.find((other) => other > address);
77
+ /** A name of the platform covers only its register or area: RANDOM is $D41B, not the color RAM after it. */
78
+ const platformEnd = new Map(platformNames().map((entry) => [entry.name, entry.end]));
76
79
  const regionAt = (address: number) => input.regions.find((region) => region.start <= address && region.end >= address);
77
80
  const spanOf = (address: number, kind: string) => {
78
81
  if (kind === "routine" || kind === "label") return address;
@@ -90,7 +93,8 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
90
93
  // A name that c64-source makes (l_xxxx) is no entry: it has no meaning of its own.
91
94
  if (symbol === undefined && label.file !== "constants.asm") continue;
92
95
  const kind = symbol?.kind ?? "platform";
93
- entries.set(label.name, { name: label.name, address: label.address, kind, page: pageOfFile(label.file), spanEnd: spanOf(label.address, kind) });
96
+ const platform = symbol === undefined ? platformEnd.get(label.name) : undefined;
97
+ entries.set(label.name, { name: label.name, address: label.address, kind, page: pageOfFile(label.file), spanEnd: platform ?? spanOf(label.address, kind) });
94
98
  }
95
99
  const entryAt = new Map<number, Entry>();
96
100
  for (const entry of entries.values()) if (!entryAt.has(entry.address)) entryAt.set(entry.address, entry);
@@ -413,6 +413,7 @@ Data becomes free only when all of these are true:
413
413
  - No run read, wrote or executed a byte of it.
414
414
  - No code that stays reads it or names it. No table that stays has an entry in it.
415
415
  - It is not in the BASIC line that starts the program, and not at $fffa-$ffff.
416
+ - No `charset`, `sprite`, `bitmap` or `screen` region has a byte of it. For example, `unused` bytes in a bitmap stay.
416
417
 
417
418
  The coverage does not show the reads of the VIC-II. Thus `charset`, `sprite`, `bitmap` and `screen` data stay, unless `--drop` names them. The bytes of the start screen always stay. Bytes without a region also stay.
418
419
 
@@ -23,6 +23,9 @@ import { OPCODES } from "#src/opcodes.ts";
23
23
  */
24
24
  export const DROPPABLE_DATA: readonly RegionType[] = ["bytes", "words", ...POINTER_TABLE_TYPES, "petscii", "workspace", "unused"];
25
25
 
26
+ /** The data that the VIC-II reads: a region of another type that overlaps it stays too, for example unused bytes in a bitmap. */
27
+ const VIC_DATA: readonly RegionType[] = ["charset", "sprite", "bitmap", "screen"];
28
+
26
29
  /** Regions of code: their bytes are the blocks of the decoded instructions. */
27
30
  const CODE_TYPES: readonly RegionType[] = ["code", "jumps", "dual-use"];
28
31
 
@@ -323,6 +326,7 @@ export function planDrops(input: DropInput): DropPlan {
323
326
  const units = automatic
324
327
  ? regions.filter((region) => {
325
328
  if (!DROPPABLE_DATA.includes(region.type) || gone.some((range) => overlaps(range, region))) return false;
329
+ if (regions.some((other) => VIC_DATA.includes(other.type) && overlaps(other, region))) return false;
326
330
  if ([...input.keep, ...input.changed, VECTORS, ...(input.basic === undefined ? [] : [input.basic])].some((range) => overlaps(range, region))) return false;
327
331
  for (let address = region.start; address <= region.end; address++) if (touched(address)) return false;
328
332
  return true;
@@ -528,7 +528,11 @@ export function layout(input: SourceInput): Layout {
528
528
  expressions.push({ address: operand.address, text: expression, kind: mode === "imm" ? "address" : useKind(item!.opcode) });
529
529
  }
530
530
  // The names of expressions and macro args come first: a platform name there names the register for the plain operands too.
531
- for (const { text: expression, kind } of expressions) for (const name of identifiers(expression)) useName(name, kind);
531
+ // An expression inside a written use names nothing: the macro line names only its args.
532
+ const useExpression = ({ text, kind }: { text: string; kind: UseKind }) => {
533
+ for (const name of identifiers(text)) useName(name, kind);
534
+ };
535
+ for (const expression of expressions) if (!inUse.has(expression.address)) useExpression(expression);
532
536
  for (const candidate of candidates) for (const arg of candidate.use.args) for (const name of identifiers(arg)) useName(name, "macro argument");
533
537
  // An instruction with an expression names what the expression names, not its plain target.
534
538
  const written = new Set(expressions.map((expression) => expression.address));
@@ -557,7 +561,9 @@ export function layout(input: SourceInput): Layout {
557
561
  macrosAsInstructions.push({ start: candidate.use.start, end: candidate.use.end, macro: candidate.use.macro, reason: `The source has a label at ${formatC64Address(inside)}, inside the use.` });
558
562
  for (const item of candidate.items) {
559
563
  inUse.delete(item.address);
560
- if (takesAddress(OPCODES[item.opcode]!.mode) && !written.has(item.address)) useOperand(item);
564
+ const expression = expressions.find((each) => each.address === item.address);
565
+ if (expression !== undefined) useExpression(expression);
566
+ else if (takesAddress(OPCODES[item.opcode]!.mode)) useOperand(item);
561
567
  }
562
568
  }
563
569
  }
@@ -1846,7 +1846,7 @@ await runScript({
1846
1846
  drop: { ...OPTIONS.range, multiple: true, help: "a range that becomes free: code that the entry does not reach (see unreachableExecuted), or data. Nothing that stays may go to it or read it" },
1847
1847
  "max-listed": OPTIONS["max-listed"],
1848
1848
  },
1849
- notes: "Fixes, trainers and cheats are in, protection and crack changes are out, and a change keeps its default. Code becomes free only when no run executed it and nothing reaches it; data only when no run touched it and nothing names it. Charset, sprite, bitmap and screen data stay unless --drop names them. Addresses do not move: a free range is $00 with a label free_xxxx. The export needs coverage in the knowledge to make ranges free by itself.",
1849
+ notes: "Fixes, trainers and cheats are in, protection and crack changes are out, and a change keeps its default. Code becomes free only when no run executed it and nothing reaches it; data only when no run touched it and nothing names it. Charset, sprite, bitmap and screen data, and data in them, stay unless --drop names them. Addresses do not move: a free range is $00 with a label free_xxxx. The export needs coverage in the knowledge to make ranges free by itself.",
1850
1850
  run: async (call) => exportReply(await exportProject(call)),
1851
1851
  },
1852
1852
  ],