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

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 (91) hide show
  1. package/package.json +2 -2
  2. package/skills/c64-assembler/SKILL.md +27 -13
  3. package/skills/c64-assembler/scripts/assembler.ts +26 -14
  4. package/skills/c64-development/SKILL.md +2 -2
  5. package/skills/c64-docs/SKILL.md +4 -4
  6. package/skills/c64-docs/scripts/docs.ts +7 -7
  7. package/skills/c64-docs/scripts/lib/reference.ts +13 -5
  8. package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
  9. package/skills/c64-knowledge/SKILL.md +60 -36
  10. package/skills/c64-knowledge/scripts/knowledge.ts +75 -59
  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 +74 -49
  18. package/skills/c64-source/scripts/lib/export.ts +76 -32
  19. package/skills/c64-source/scripts/lib/loader.ts +33 -10
  20. package/skills/c64-source/scripts/lib/source.ts +14 -25
  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 +257 -134
  24. package/skills/c64-static-analysis/SKILL.md +8 -6
  25. package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
  26. package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
  27. package/skills/c64-static-analysis/scripts/lib/macros.ts +3 -1
  28. package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
  29. package/skills/c64-testing/SKILL.md +5 -2
  30. package/skills/c64-testing/references/recording-format.md +18 -3
  31. package/skills/c64-testing/references/scenario-format.md +7 -6
  32. package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
  33. package/skills/c64-testing/scripts/lib/play.ts +39 -41
  34. package/skills/c64-testing/scripts/lib/recording.ts +46 -37
  35. package/skills/c64-testing/scripts/lib/replay.ts +1 -1
  36. package/skills/c64-testing/scripts/lib/runs.ts +2 -2
  37. package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
  38. package/skills/c64-testing/scripts/testing.ts +6 -1
  39. package/skills/c64-unpacker/SKILL.md +6 -3
  40. package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
  41. package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
  42. package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
  43. package/skills/emulator/SKILL.md +7 -12
  44. package/src/build-name.ts +50 -0
  45. package/src/c64-keys.ts +98 -0
  46. package/src/c64.ts +21 -1
  47. package/src/cli/main.ts +3 -29
  48. package/src/host/main.ts +1 -1
  49. package/src/host/tools/index.ts +1 -6
  50. package/src/host/vice/session.ts +88 -9
  51. package/src/host-client/steps.ts +17 -17
  52. package/src/host-client/tools.ts +2 -7
  53. package/src/host-client/vice-session.ts +7 -1
  54. package/src/knowledge/program.ts +44 -1
  55. package/src/knowledge/read.ts +33 -10
  56. package/src/knowledge/schema.ts +37 -11
  57. package/src/knowledge/start-screen.ts +68 -0
  58. package/src/knowledge/text.ts +5 -2
  59. package/src/knowledge/write.ts +69 -30
  60. package/src/mcp/inputs.ts +12 -0
  61. package/src/mcp/server.ts +1 -1
  62. package/src/mcp/tools/input.ts +38 -5
  63. package/src/mcp/tools/machine.ts +3 -42
  64. package/src/mcp/tools/media.ts +1 -1
  65. package/src/native/acme.ts +1 -1
  66. package/src/native/c64run.ts +1 -1
  67. package/src/native/discover.ts +3 -3
  68. package/src/native/dxa.ts +12 -1
  69. package/src/native/ghidra/analyze.ts +74 -63
  70. package/src/native/ghidra/c64rt-wasm.ts +4 -0
  71. package/src/native/ghidra/language/c64rt_6510.sla +0 -0
  72. package/src/native/ghidra/pcode.ts +222 -0
  73. package/src/native/ghidra/walk.ts +205 -0
  74. package/src/native/ghidra/wasm.ts +98 -0
  75. package/src/native/processes.ts +4 -4
  76. package/src/native/types.ts +2 -2
  77. package/src/platform.ts +30 -1
  78. package/src/project.ts +17 -4
  79. package/src/protocol/tools.ts +1 -45
  80. package/src/protocol/vice.ts +47 -0
  81. package/src/script.ts +3 -3
  82. package/src/vsf.ts +98 -0
  83. package/tools/c64run.c +9 -12
  84. package/tools/install-container.sh +1 -2
  85. package/src/cli/status.ts +0 -127
  86. package/src/host/tools/status.ts +0 -47
  87. package/src/native/ghidra/index.ts +0 -170
  88. package/src/native/ghidra/scripts/C64Export.java +0 -274
  89. package/src/native/ghidra/scripts/C64Prepare.java +0 -66
  90. package/src/native/status.ts +0 -135
  91. package/tools/install-ghidra.sh +0 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.6.0-rc.1",
3
+ "version": "2.6.0-rc.11",
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",
@@ -34,7 +34,7 @@
34
34
  "scripts": {
35
35
  "host": "node src/host/main.ts",
36
36
  "typecheck": "tsc -p tsconfig.json",
37
- "test": "node --test \"src/**/*.test.ts\" \"test/**/*.test.ts\""
37
+ "test": "node test/run.ts"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "24.13.3",
@@ -27,10 +27,11 @@ To get the command list, run the script with no arguments.
27
27
  | Build a source that includes files from a folder | `build src main.a --out build/game.prg --include lib` |
28
28
  | Build a source that includes a file that you generated into a folder next to the source root | `build src boot.asm --out build/boot.prg --include ../build` |
29
29
  | Build a source that sets no start address | `build src main.a --out build/game.prg --set-pc '$0801'` |
30
- | Check that the rebuild is identical to the program in the project knowledge | `build src main.asm --out build/game.prg --compare` |
31
- | Build a release and check it against the file of that release | `build src main.asm --out build/original.prg --release ORIGINAL --compare` |
30
+ | Build a generated source with the values of `config.asm` | `build src main.asm` |
31
+ | Build the loader of a generated source | `build src loader.asm` |
32
+ | Check that the rebuild is identical to the program in the project knowledge | `build src main.asm --compare` |
33
+ | Build a release and check it against the bytes of that release | `build src main.asm --release ORIGINAL --compare` |
32
34
  | Check the rebuild of a program in another space, for example the drive | `build src main.asm --out build/drive.prg --compare --space drive8` |
33
- | Write the symbols of the rebuild to a file for a test run | `build src main.asm --out build/game.prg --out-symbols build/game.json` |
34
35
  | List all symbols, also the constants that the source does not use | `build src main.a --out build/game.prg --all-symbols --max-listed 500` |
35
36
  | Write only the bytes of the program, without the load address | `build src main.a --out build/game.bin --plain` |
36
37
 
@@ -42,7 +43,8 @@ To get the command list, run the script with no arguments.
42
43
  - An include folder is a path relative to the source root, inside the project folder. It can be outside the source root, for example `--include ../build`.
43
44
  - `<entry>` is the main source file, relative to the source root. It normally sets its start address, for example `* = $0801`. If it does not, give `--set-pc`.
44
45
  - For a source that you generated from the project knowledge, the source root is the folder of that source. The entry is `main.asm`.
45
- - `--out` is the path of the program, relative to the project folder.
46
+ - `--out` is the path of the program, relative to the project folder. Without `--out`, the script writes `build/<name>.prg`. See "Build names".
47
+ - The script writes the symbols of the program to `symbols/<name>.json` in the folder of the program, for example `build/symbols/clean.json`. Give this file to a test run as the symbols of the rebuild.
46
48
  - Get the label of a release from the releases in the project knowledge. Record a release in the project knowledge before you build it.
47
49
  - Before you use `--compare`, put the program bytes into the project knowledge.
48
50
  - The target CPU is the 6510. The program is a C64 PRG, or the bytes only with `--plain`.
@@ -55,6 +57,19 @@ A source that you generated from the project knowledge has switches in `config.a
55
57
  - To turn a switch on, change its value in `config.asm`, for example `TRAINER = 1`. Do not use `--define` for a switch. ACME then stops with `Symbol already defined`.
56
58
  - With `--release <label>`, each switch has the value of that release. A release build does not read `config.asm`.
57
59
 
60
+ ### Build names
61
+
62
+ Without `--out`, the name of the program tells what the build is:
63
+
64
+ | Build | Name |
65
+ |---|---|
66
+ | `--release <label>` | `release_<label>.prg`, for example `release_ORIGINAL.prg` |
67
+ | Each value of `config.asm` is its default | `clean.prg` |
68
+ | A value of `config.asm` is not its default | `custom_<switches>.prg`, for example `custom_trainer.prg`. A switch that is off has `no_` before its name, for example `custom_no_start_screen.prg`. |
69
+ | A source without `config.asm` | the name of the entry, for example `main.prg` |
70
+
71
+ An entry other than `main.asm` adds its name, for example `clean_loader.prg` for `loader.asm`. With `--plain`, the extension is `.bin`. Do not give `--out` for a build of a generated source. Then the name always tells the build.
72
+
58
73
  ### Paths and the project folder
59
74
 
60
75
  - Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
@@ -81,17 +96,16 @@ Each flag applies only to the commands in the table. On another command, the scr
81
96
 
82
97
  | Flag | Command | Effect |
83
98
  |---|---|---|
84
- | `--out <file.prg>` | `build` | Required. The path of the program, relative to the project folder. |
85
- | `--include <dir>` | `build` | An include folder: a path relative to the source root, inside the project folder. Give the flag again for each folder. The default is no include folder. |
99
+ | `--out <file.prg>` | `build` | The path of the program, relative to the project folder. The default is `build/<name>.prg`. See "Build names". |
100
+ | `--include <folder>` | `build` | An include folder: a path relative to the source root, inside the project folder. Give the flag again for each folder. The default is no include folder. |
86
101
  | `--define NAME=VALUE` | `build` | An assembler symbol: an integer, also `$` and hex digits, or `true` or `false`. Give the flag again for each symbol. Do not use it for a switch. |
87
102
  | `--set-pc <address>` | `build` | The start address when the source does not set one, for example `'$0801'`. |
88
- | `--release <label>` | `build` | Build a release of the project knowledge. Each switch gets the value of that release. With `--compare`, the reference is the file of the release. |
103
+ | `--release <label>` | `build` | Build a release of the project knowledge. Each switch gets the value of that release. With `--compare`, the reference is the bytes of the release in the project knowledge. |
89
104
  | `--compare` | `build` | Compare the program byte by byte with the program in the project knowledge, or with the file of `--release`, segment by segment. Off by default. |
90
- | `--space <space>` | `build` | The space of the program in the project knowledge: `c64`, `drive8`, or `bank0` to `bank255`. The default is `c64`. Give it only with `--compare` or `--release`. |
105
+ | `--space <space>` | `build` | The space of the program in the project knowledge: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. Give it only with `--compare` or `--release`. |
91
106
  | `--plain` | `build` | Write only the bytes of the program, without the 2-byte load address. Off by default. |
92
107
  | `--all-symbols` | `build` | List also the constants that the source does not use. Off by default. |
93
108
  | `--max-listed <n>` | `build` | List at most `n` symbols. The default is 50. `symbols.count` always gives the count of all symbols. |
94
- | `--out-symbols <file.json>` | `build` | Write the listed symbols to this file as `{"symbols": [...]}`. Without `--all-symbols`, the file does not have the constants that the source does not use. |
95
109
 
96
110
  ---
97
111
 
@@ -99,7 +113,7 @@ Each flag applies only to the commands in the table. On another command, the scr
99
113
 
100
114
  ### `build <source-root> <entry>`
101
115
 
102
- Assembles the source and writes the program to `--out`.
116
+ Assembles the source and writes the program to `--out`, or to `build/<name>.prg`. It also writes the symbols to `symbols/<name>.json` in the folder of the program. Without `--all-symbols`, that file does not have the constants that the source does not use.
103
117
 
104
118
  `body` holds:
105
119
 
@@ -112,7 +126,7 @@ Assembles the source and writes the program to `--out`.
112
126
  - Kind `address` has a value in `loadRange`. It gives `address`.
113
127
  - Kind `constant` has a value outside `loadRange`. It gives `value` as `$` and four or more hex digits. A label in a `!pseudopc` block can be a constant, because its value is the run address, not the load address.
114
128
  - `used` is `false` when the source does not use the symbol.
115
- - `symbolsFile`: the file of `--out-symbols`, with `out`, `bytes` and `sha256`.
129
+ - `symbolsFile`: the symbols file, with `out`, `bytes` and `sha256`.
116
130
  - `unusedConstants`: the count of the constants that the list does not include. It is not in the body with `--all-symbols`.
117
131
  - `diagnostics`: each item has `severity` (`error`, `warning` or `note`), `file`, `line` and `message`. `file` is relative to the source root. A file in an include folder outside the source root starts with `../`. `file` and `line` are not in an item without a location in the source.
118
132
  - `compare`: only with `--compare`. `identical` is `true` when each segment is identical. `segments` has one item for each segment of the reference program, with `start`, `end` and `result`:
@@ -125,7 +139,7 @@ Do as the result tells:
125
139
  - `result` is `PASS`: the program is at `out`. To run or debug the program, load the file at `out` into the emulator.
126
140
  - `result` is `FAIL` and `assembled` is `false`: the source has errors, and the script wrote no program. `hint` tells you to correct the source. Correct the source at the file and the line of each diagnostic. Then run `build` again.
127
141
  - `result` is `FAIL` and `assembled` is `true`: the program is not identical to the reference. The script wrote the program. Read the first difference of each segment in `compare.segments`. Without `--release`, read the section "Switches" first.
128
- - `hint` tells that `symbols` is cut: give a larger `--max-listed`, or `--out-symbols <file.json>` for the full list.
142
+ - `hint` tells that `symbols` is cut: give a larger `--max-listed`, or read the symbols file for the full list.
129
143
  - Error `not-found` names the entry: give the main source file relative to the source root.
130
144
  - Error `not-found` names an include folder: give `--include` a folder with files, relative to the source root.
131
145
  - Error `invalid-input` names an include folder: the folder is outside the project folder. Give `--include` a folder inside the project folder.
@@ -135,7 +149,7 @@ Do as the result tells:
135
149
 
136
150
  The script does not keep the diagnostics or the program in the project knowledge.
137
151
 
138
- To compare runs of the rebuild with runs of the original, give the file of `--out-symbols` to the test run as the symbols of the rebuild. A symbol of the rebuild gives the address of a routine in the rebuild.
152
+ To compare runs of the rebuild with runs of the original, give the symbols file to the test run as the symbols of the rebuild. A symbol of the rebuild gives the address of a routine in the rebuild.
139
153
 
140
154
  ---
141
155
 
@@ -1,15 +1,15 @@
1
1
  // The c64-assembler script: assembles project source with ACME, which it runs
2
2
  // itself, and writes the program into the project.
3
3
 
4
+ import { BUILD_DIRECTORY, type BuildKind, buildName, CONFIG_FILE, configValues, symbolsPath } from "#src/build-name.ts";
4
5
  import { formatC64Address } from "#src/c64.ts";
5
6
  import { Refusal } from "#src/errors.ts";
6
- import { readImage } from "#src/host-client/image.ts";
7
7
  import { readSourceTree, writeReported } from "#src/host-client/transfer.ts";
8
8
  import { openForRead } from "#src/knowledge/database.ts";
9
9
  import { knowledgeNames } from "#src/knowledge/names.ts";
10
- import { requireProgram } from "#src/knowledge/program.ts";
11
- import { releaseLabeled } from "#src/knowledge/read.ts";
12
- import { RELEASE_DEFINE } from "#src/knowledge/schema.ts";
10
+ import { releaseImage, requireProgram } from "#src/knowledge/program.ts";
11
+ import { listSwitches, releaseLabeled } from "#src/knowledge/read.ts";
12
+ import { LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
13
13
  import { assemble, showSymbol, symbolsFileText } from "#src/native/acme.ts";
14
14
  import { localToolContext } from "#src/native/local.ts";
15
15
  import type { AcmeParams, AssembledSymbol } from "#src/native/types.ts";
@@ -26,6 +26,16 @@ function parseDefine(text: string): [string, number | boolean] {
26
26
  throw new UsageError(`--define ${match[1]} needs an integer or true/false, not ${value}`);
27
27
  }
28
28
 
29
+ /** The default of each switch of a generated source: the knowledge gives them, the start screen is in and the leftovers are out. */
30
+ function switchDefaults(space: Space): Map<string, number> {
31
+ const db = openForRead();
32
+ try {
33
+ return new Map([[START_SCREEN_SWITCH, 1], [LEFTOVERS_SWITCH, 0], ...listSwitches(db, undefined, space).map((row) => [row.name, row.default] as const)]);
34
+ } finally {
35
+ db?.close();
36
+ }
37
+ }
38
+
29
39
  await runScript({
30
40
  name: "assembler",
31
41
  summary: "Assembles project source with ACME and writes the program into the project.",
@@ -39,22 +49,20 @@ await runScript({
39
49
  { name: "<entry>", help: "the main source file, relative to the source root" },
40
50
  ],
41
51
  options: {
42
- out: { ...OPTIONS.out, output: "file", value: "<file.prg>", help: "where to write the program, relative to the project folder", required: true },
43
- include: { kind: "text", value: "<dir>", multiple: true, help: "an include folder: a path relative to the source root, inside the project folder" },
52
+ out: { ...OPTIONS.out, output: "file", value: "<file.prg>", help: "where to write the program, relative to the project folder. The default is build/<build>.prg: release_<label> with --release, else clean or custom_<switches> from config.asm, with _<entry> for an entry other than main.asm" },
53
+ include: { kind: "text", value: "<folder>", multiple: true, help: "an include folder: a path relative to the source root, inside the project folder" },
44
54
  define: { kind: "text", value: "NAME=VALUE", multiple: true, help: "an assembler symbol: an integer ($hex allowed) or true/false" },
45
55
  "set-pc": { kind: "address", value: "<address>", help: "the start address when the source sets none, for example '$0801'" },
46
56
  release: { kind: "text", value: "<label>", help: `build a release of the knowledge: defines ${RELEASE_DEFINE}<label>=1, so each switch has the value of that release. With --compare, the reference is the file of the release` },
47
57
  compare: { kind: "flag", help: "check the program byte by byte against the program in the knowledge (or the file of --release), each segment" },
48
- space: { kind: "space", value: "<space>", help: "with --compare or --release: the knowledge space of the program: c64 (the default), drive8, or bank0 to bank255" },
58
+ space: { kind: "space", value: "<space>", help: "with --compare or --release: the knowledge space of the program: c64 (the default), drive8, loading, or bank0 to bank255" },
49
59
  plain: { kind: "flag", help: "write the bytes only, without the 2-byte load address of a PRG" },
50
60
  "all-symbols": { kind: "flag", help: "list also the constants that the source does not use" },
51
61
  "max-listed": { ...OPTIONS["max-listed"], help: "list at most n symbols (default 50). The count is always given" },
52
- "out-symbols": { kind: "path", output: "file", value: "<file.json>", help: "write the listed symbols to this project file as {\"symbols\": [...]}: the names of the rebuild for a test run. Without --all-symbols, the file does not have the constants that the source does not use" },
53
62
  },
54
63
  notes: "Symbol values are $ and at least four hex digits. Before --compare, put the program bytes into the project knowledge. Without --release, the build has the switch values of config.asm. With the defaults, this is the clean program, which is not the bytes of a release when a switch has a default that the base release does not have. Set a switch in config.asm, not with --define: ACME stops with Symbol already defined.",
55
64
  run: async (call) => {
56
65
  const [sourceRoot, entry] = [call.subject(0), call.subject(1)];
57
- const out = call.string("out")!;
58
66
  // Read the reference before ACME runs, so a project without it stops at once.
59
67
  let program: Reference | undefined;
60
68
  const label = call.string("release");
@@ -68,7 +76,7 @@ await runScript({
68
76
  const release = releaseLabeled(db, label, call.space);
69
77
  if (release === undefined) throw new Refusal("not-found", `There is no release ${label} in the knowledge. Record the release in the project knowledge first, or give the label of a recorded release.`);
70
78
  releaseDefine = { [`${RELEASE_DEFINE}${label}`]: 1 };
71
- if (call.flag("compare")) program = release.base ? requireProgram(db, call.space) : readImage(release.file);
79
+ if (call.flag("compare")) program = releaseImage(db, label, call.space);
72
80
  }
73
81
  } finally {
74
82
  db?.close();
@@ -77,19 +85,22 @@ await runScript({
77
85
  const setPc = call.address("set-pc");
78
86
  const { contents, ...tree } = readSourceTree(sourceRoot, call.strings("include"));
79
87
  if (!tree.files.some((file) => file.path === (tree.sourceDir === "" ? entry : `${tree.sourceDir}/${entry}`))) throw new Refusal("not-found", `${entry} is not a file in ${sourceRoot}. Give the main source file relative to the source root.`);
88
+ // The name of the build tells what it is: the release, or the switch values of config.asm.
89
+ const config = tree.files.findIndex((file) => file.path === (tree.sourceDir === "" ? CONFIG_FILE : `${tree.sourceDir}/${CONFIG_FILE}`));
90
+ const kind: BuildKind | undefined = label !== undefined ? { release: label } : config < 0 ? undefined : { values: configValues(contents[config]!.toString("utf8")), defaults: switchDefaults(call.space) };
91
+ const plain = call.flag("plain");
92
+ const out = call.string("out") ?? `${BUILD_DIRECTORY}/${buildName(entry, kind)}.${plain ? "bin" : "prg"}`;
80
93
  const params: AcmeParams = { ...tree, entrySource: entry, defines: { ...releaseDefine, ...Object.fromEntries(call.strings("define").map(parseDefine)) }, ...(setPc === undefined ? {} : { setPc }) };
81
94
 
82
95
  const { result, attachments } = await assemble(params, contents, localToolContext());
83
96
  if (!result.assembled) return reply({ result: "FAIL", assembled: false, diagnostics: result.diagnostics }, { hint: "The source has errors, and no program was written. Correct the source at the file and the line of each diagnostic. Then run build again." });
84
- const plain = call.flag("plain");
85
97
  const written = writeReported(out, plain ? attachments![0]!.subarray(2) : attachments![0]!, { what: "--out" });
86
98
  const range = result.loadRange!;
87
99
  const compared = program === undefined ? undefined : compareBuild(attachments![0]!, program);
88
100
  // An include file of platform names gives many constants that the program does not use.
89
101
  const all = call.flag("all-symbols");
90
102
  const shown = result.symbols!.filter((symbol) => all || symbol.kind === "address" || symbol.used);
91
- const symbolsPath = call.string("out-symbols");
92
- const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, "a larger --max-listed, or --out-symbols <file.json> for the whole list");
103
+ const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, `a larger --max-listed, or read ${symbolsPath(out)}`);
93
104
  // A build that differs from its reference is a failed check.
94
105
  const different = compared !== undefined && !compared.identical;
95
106
  const hints = [
@@ -104,7 +115,8 @@ await runScript({
104
115
  ...(plain ? { plain: true } : {}),
105
116
  loadRange: { start: formatC64Address(range.start), end: formatC64Address(range.end), bytes: range.bytes },
106
117
  symbols,
107
- ...(symbolsPath === undefined ? {} : { symbolsFile: writeReported(symbolsPath, symbolsFileText(shown), { what: "--out-symbols" }) }),
118
+ // The symbols of the program for a test run, in symbols/ next to it.
119
+ symbolsFile: writeReported(symbolsPath(out), symbolsFileText(shown), { what: "--out" }),
108
120
  ...(all ? {} : { unusedConstants: result.symbols!.length - shown.length }),
109
121
  diagnostics: result.diagnostics,
110
122
  ...(compared === undefined ? {} : { compare: compared }),
@@ -29,7 +29,7 @@ First select the path:
29
29
 
30
30
  - The project has no program yet: path A.
31
31
  - The program has source that a person wrote: path B. A project that an export of a rebuilt program made also takes path B.
32
- - The source comes from a generation from the project knowledge: path C. Such a source has `main.asm` and `source-map.json`. Do not edit this source. The next generation of the source writes over it.
32
+ - The source comes from a generation from the project knowledge: path C. Such a source has `main.asm`, and the first line of each generated file tells that it is generated. Do not edit this source. The next generation of the source writes over it.
33
33
 
34
34
  ### Acceptance checks
35
35
 
@@ -110,7 +110,7 @@ A rebuilt program gets its source from the project knowledge. A change is a swit
110
110
  - Build the default build.
111
111
  - When the default build does not have the switch, set the switch to 1 in `src/config.asm`. Then build the default build. After the test, set the value back to the default if the user did not ask for the change.
112
112
  8. Test the build that has the switch:
113
- - Run the test scenarios in `tests/` where the behavior must stay the same as the original.
113
+ - When the behavior must stay the same as the original, replay a recording that executes the changed code. Run a test scenario in `tests/` only when no recording executes that code.
114
114
  - Run a run file with `expect` steps that show the feature or the fix.
115
115
 
116
116
  ### The answer
@@ -41,7 +41,7 @@ The documentation is Markdown in the project. It has two parts:
41
41
 
42
42
  Get the values for the commands from these places:
43
43
 
44
- - `<source-dir>` and `--source`: the folder of the source that you generated from the project knowledge, for example `src`. It must hold `source-map.json`. The source must be from the current revision of the project knowledge.
44
+ - `<source-dir>` and `--source`: the folder of the source that you generated from the project knowledge, for example `src`. The source must be from the current revision of the project knowledge in its space. A change in another space does not make the source old.
45
45
  - `--out`: a folder that holds only the reference, for example `docs/reference`. Keep the pages that you write outside it.
46
46
  - `<page>`: the entry page `README.md` and the folder of the other pages, for example `docs`.
47
47
  - The program bytes: put them into the project knowledge before `generate`. Then the reference decodes the tables and shows the graphics.
@@ -84,7 +84,7 @@ Each flag applies only to the commands in the table. On another command, the scr
84
84
  | Flag | Command | Effect |
85
85
  |---|---|---|
86
86
  | `--out <dir>` | `generate` | Required. The folder of the reference, relative to the project folder. `generate` writes only there. It refuses to start when the folder holds a page that it did not write. |
87
- | `--source <dir>` | `link` | Required. The folder of the generated source, with its `source-map.json`, relative to the project folder. In a group folder, each project has its source in this folder. |
87
+ | `--source <dir>` | `link` | Required. The folder of the generated source, relative to the project folder. In a group folder, each project has its source in this folder. |
88
88
  | `--reference <dir>` | `link` | The folder of the reference, relative to the project folder. In a group folder, each project has its reference in this folder. The default is the first `reference` folder in a given folder or beside a given page, for example `docs/reference`. |
89
89
  | `--check` | `link` | Write nothing. `result` is `FAIL` when a link is not up to date or a page has a problem. Off by default. |
90
90
  | `--max-listed <n>` | `generate`, `link` | List at most `n` items in each list. The default is 50. The count is always in the body. |
@@ -121,7 +121,7 @@ In a call graph, a solid arrow is a call, a thick arrow is a table entry, and a
121
121
 
122
122
  Errors and their actions:
123
123
 
124
- - `not-found` for `source-map.json` or for the source folder: generate the source from the project knowledge. Then run `generate` again.
124
+ - `not-found` for the source map or for the source folder: generate the source from the project knowledge. Then run `generate` again.
125
125
  - `invalid-input` that names an old revision: the project knowledge changed after you generated the source. Generate the source again, then run `generate` again.
126
126
  - `invalid-input` that names a page in `--out`: `generate` did not write that page. Move the page out of the folder.
127
127
  - `conflict`: the project knowledge has conflicts from a git merge. Resolve the merge conflicts of the project knowledge. Then generate the source again, and run `generate` again.
@@ -208,7 +208,7 @@ Errors:
208
208
  ## Workflow
209
209
 
210
210
  1. Read the project knowledge. The documentation can only be as good as the knowledge. Each routine needs a name and a comment. Each table needs a region and a name. Each file of the source needs a module with a title. Record what is missing in the project knowledge.
211
- 2. Generate the source from the project knowledge. Make sure that the check of the source gives identical bytes. This also writes `source-map.json`.
211
+ 2. Generate the source from the project knowledge. Make sure that the check of the source gives identical bytes. This also writes the source map.
212
212
  3. Run `generate`. Read `index.md` of the reference. A module with no routines, or a routine with no comment, shows what the knowledge does not have yet.
213
213
  4. Make the plan of the pages. Start from the modules and the call graphs. Find the main loop, the interrupt chain, the dispatch tables, the state machines and the data formats. Each subsystem gets one page in `docs/`. The entry page `README.md` lists the pages. Use the page types in `<skill>/references/page-types.md`.
214
214
  5. Collect the facts about the development and the copy protection. These facts are the most interesting parts for a reader, so look for them carefully.
@@ -14,7 +14,7 @@ import { writeProjectFile, writeReported } from "#src/host-client/transfer.ts";
14
14
  import { conflicts } from "#src/knowledge/conflicts.ts";
15
15
  import { openForRead } from "#src/knowledge/database.ts";
16
16
  import { programImage, type ProgramImage } from "#src/knowledge/program.ts";
17
- import { currentRevision, listComments, listModules, listReferences, listRegions, listSymbols } from "#src/knowledge/read.ts";
17
+ import { listComments, listModules, listReferences, listRegions, listSymbols, sourceRevision } from "#src/knowledge/read.ts";
18
18
  import { groupOf, namedGroup, projectRoot, resolveProjectFile, resolveProjectPath, type ProjectGroup } from "#src/project.ts";
19
19
  import { listed, OPTIONS, reply, runScript, UsageError, type Call, type Reply } from "#src/script.ts";
20
20
  import { checkLinks, linkPage, type Files, type LinkContext, type Names, type Problem } from "./lib/links.ts";
@@ -64,10 +64,10 @@ function generate(call: Call): Reply {
64
64
  image = programImage(db, map.space);
65
65
  const found = conflicts(db).length;
66
66
  if (found > 0) throw new Refusal("conflict", `The knowledge has ${found} conflict${found === 1 ? "" : "s"} from a git merge. Nothing was written. Resolve the merge conflicts of the project knowledge. Then generate the source again from the knowledge, and run generate again.`);
67
- const revision = currentRevision(db);
68
- // A source of another revision has other lines: the links would point to the wrong code.
67
+ // A source of another revision has other lines: the links would point to the wrong code. A change in another space does not change the source.
68
+ const revision = sourceRevision(db, map.space);
69
69
  if (map.revision !== revision) {
70
- throw new WireFailure("invalid-input", `${map.pathOf("source-map.json")} is from knowledge revision ${map.revision}, and the knowledge is at revision ${revision}. Nothing was written. Generate the source again from the knowledge. Then run generate again.`);
70
+ throw new WireFailure("invalid-input", `${map.mapPath} is from knowledge revision ${map.revision}, and the knowledge of the source is at revision ${revision}. Nothing was written. Generate the source again from the knowledge. Then run generate again.`);
71
71
  }
72
72
  knowledge = {
73
73
  revision,
@@ -266,13 +266,13 @@ function link(call: Call): Reply {
266
266
  let symbols;
267
267
  let revision;
268
268
  try {
269
- revision = currentRevision(db);
269
+ revision = sourceRevision(db, map.space);
270
270
  symbols = listSymbols(db, undefined, undefined, undefined, map.space);
271
271
  } finally {
272
272
  db?.close();
273
273
  }
274
274
  if (map.revision !== revision) {
275
- problems.push({ page: inProject(map.pathOf("source-map.json")), line: 1, kind: "stale-reference", message: `The source${of} is from knowledge revision ${map.revision}, and the knowledge is at ${revision}. Generate the source and the reference again, then run docs.ts link.` });
275
+ problems.push({ page: inProject(map.mapPath), line: 1, kind: "stale-reference", message: `The source${of} is from knowledge revision ${map.revision}, and the knowledge of the source is at ${revision}. Generate the source and the reference again, then run docs.ts link.` });
276
276
  }
277
277
  const addresses = new Map<string, number>();
278
278
  for (const label of map.labels) addresses.set(label.name, label.address);
@@ -411,7 +411,7 @@ function link(call: Call): Reply {
411
411
  return reply({ result: problems.length > 0 || (check && links > 0) ? "FAIL" : "PASS", ...output }, { ...(hints.length === 0 ? {} : { hint: hints.join(" ") }), nextAction });
412
412
  }
413
413
 
414
- const SOURCE = { kind: "path", value: "<dir>", help: "the folder of the source that was generated from the knowledge, with its source-map.json, relative to the project folder" } as const;
414
+ const SOURCE = { kind: "path", value: "<dir>", help: "the folder of the source that was generated from the knowledge, relative to the project folder" } as const;
415
415
 
416
416
  await runScript({
417
417
  name: "docs",
@@ -6,6 +6,7 @@
6
6
  import { posix } from "node:path";
7
7
 
8
8
  import { formatC64Address, POINTER_TABLE_TYPES, pointerTableEntries, type PointerTableType } from "#src/c64.ts";
9
+ import { IO_RAM } from "#src/host-client/coverage.ts";
9
10
  import { bitmapFrame, charsetFrame, encodePng, PATTERN_PALETTES, scaleFrame, screenText, spriteSheet, type GraphicsMode } from "#src/graphics.ts";
10
11
  import { mermaidGraph, ownerOf, routineEdges, routineHeads, type GraphReference, type RoutineHead } from "#src/knowledge/graph.ts";
11
12
  import type { CommentRow, ModuleRow, ReferenceRow, RegionRow, SymbolRow } from "#src/knowledge/read.ts";
@@ -34,8 +35,8 @@ export interface ReferenceFile {
34
35
  bytes: Buffer;
35
36
  }
36
37
 
37
- /** Files that the source map lists but that hold no code of the program. */
38
- const NOT_PIECES = new Set(["main.asm", "constants.asm", "macros.asm", "loader.asm"]);
38
+ /** Files that the source map lists but that hold no code of the program: they get no module page. */
39
+ const NOT_PIECES = new Set(["main.asm", "constants.asm", "macros.asm", "loader.asm", "config.asm", "switches.asm", "start_screen.asm", "start_screen_stage.asm"]);
39
40
  const TABLE_TYPES: readonly RegionType[] = [...POINTER_TABLE_TYPES, "jumps", "words"];
40
41
  const GRAPHICS_TYPES: readonly RegionType[] = ["sprite", "bitmap", "charset", "screen"];
41
42
  /** A list longer than this ends with the number of the rest. */
@@ -133,10 +134,17 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
133
134
  return entries.has(named.name) ? entryOfName(page, named.name, shown) : codeOfName(page, named.name).replace(`\`${named.name}\``, `\`${shown}\``);
134
135
  };
135
136
  const capped = (items: string[]) => (items.length <= MAX_LISTED ? items.join(", ") : `${items.slice(0, MAX_LISTED).join(", ")} and ${items.length - MAX_LISTED} more`);
137
+ /**
138
+ * The references that use the data at their target. An access to the I/O area inside the image is the
139
+ * register, as the source writes it: it uses no data of the RAM under it, unless the knowledge names that
140
+ * address. So the code of the SID and the CIAs is no reader of the sprites in RAM at $d400 or $dc00.
141
+ */
142
+ const named = new Set(input.symbols.map((symbol) => symbol.address));
143
+ const dataReferences = input.references.filter((reference) => !(reference.to >= IO_RAM.start && reference.to <= IO_RAM.end && input.image?.inImage(reference.to) === true && !named.has(reference.to)));
136
144
  /** The routines that read or write a range, each linked to its entry. */
137
145
  const ownersOf = (page: string, start: number, end: number, kind: string) =>
138
146
  capped(
139
- [...new Set(input.references.filter((reference) => reference.kind === kind && reference.to >= start && reference.to <= end).map((reference) => ownerAt(reference.from)?.name ?? hex(reference.from)))].map((name) =>
147
+ [...new Set(dataReferences.filter((reference) => reference.kind === kind && reference.to >= start && reference.to <= end).map((reference) => ownerAt(reference.from)?.name ?? hex(reference.from)))].map((name) =>
140
148
  entries.has(name) ? entryOfName(page, name, name) : `\`${name}\``,
141
149
  ),
142
150
  );
@@ -194,7 +202,7 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
194
202
  }
195
203
  const titleOf = (file: string) => input.modules.find((module) => module.file === file)?.title;
196
204
 
197
- const header = `${GENERATED_MARK} from knowledge revision ${input.revision} and ${map.pathOf("source-map.json")}. Do not edit: change the knowledge, generate the source again, then run docs.ts generate. -->`;
205
+ const header = `${GENERATED_MARK} from knowledge revision ${input.revision} and ${map.mapPath}. Do not edit: change the knowledge, generate the source again, then run docs.ts generate. -->`;
198
206
  const files: ReferenceFile[] = [];
199
207
  const write = (path: string, lines: string[]) => files.push({ path, bytes: Buffer.from(`${[header, ...lines].join("\n").replace(/\n{3,}/g, "\n\n")}\n`, "utf8") });
200
208
 
@@ -204,7 +212,7 @@ export function buildReference(input: ReferenceInput): { files: ReferenceFile[];
204
212
  .filter((comment) => comment.address === address)
205
213
  .sort((a, b) => (a.placement === b.placement ? 0 : a.placement === "line" ? -1 : 1))
206
214
  .map((comment) => comment.text.replace(/\s*\r?\n\s*/g, " ").trim());
207
- const incoming = (entry: Entry) => input.references.filter((reference) => reference.to >= entry.address && reference.to <= entry.spanEnd);
215
+ const incoming = (entry: Entry) => dataReferences.filter((reference) => reference.to >= entry.address && reference.to <= entry.spanEnd);
208
216
  const outgoing = (head: RoutineHead) => input.references.filter((reference) => ownerAt(reference.from)?.address === head.address);
209
217
  const entryText = (page: string, entry: Entry): string[] => {
210
218
  const lines = ["", `<a id="${entry.name}"></a>`, `### ${codeOfName(page, entry.name)} \`${entry.spanEnd > entry.address ? range(entry.address, entry.spanEnd) : hex(entry.address)}\``, "", `*${entry.kind}*`];
@@ -1,5 +1,6 @@
1
- // The source map that c64-source writes next to the source: the line of
2
- // each name and of each address. The documentation links to these lines.
1
+ // The source map of a generated source: the line of each name and of each
2
+ // address. The generation writes it to the local folder of the project, not
3
+ // next to the source. The documentation links to these lines.
3
4
 
4
5
  import { posix } from "node:path";
5
6
 
@@ -7,6 +8,7 @@ import { parseC64Address } from "#src/c64.ts";
7
8
  import { WireFailure } from "#src/host-client/tools.ts";
8
9
  import { readProjectFile } from "#src/host-client/transfer.ts";
9
10
  import type { Space } from "#src/knowledge/schema.ts";
11
+ import { generatedDirectory } from "#src/project.ts";
10
12
 
11
13
  export const SOURCE_MAP_FILE = "source-map.json";
12
14
 
@@ -18,6 +20,8 @@ export interface SourceLine {
18
20
  export interface SourceMap {
19
21
  /** The source directory, relative to the project folder. */
20
22
  directory: string;
23
+ /** The source map file, relative to the project folder. */
24
+ mapPath: string;
21
25
  space: Space;
22
26
  revision: string;
23
27
  files: string[];
@@ -30,9 +34,9 @@ export interface SourceMap {
30
34
  pathOf: (file: string) => string;
31
35
  }
32
36
 
33
- /** Reads <directory>/source-map.json of the project `root`. A missing map is a refusal with the remedy. */
37
+ /** Reads the source map of the source in `directory` of the project `root`. A missing map is a refusal with the remedy. */
34
38
  export function readSourceMap(directory: string, root?: string): SourceMap {
35
- const path = posix.join(directory, SOURCE_MAP_FILE);
39
+ const path = posix.join(generatedDirectory(directory), SOURCE_MAP_FILE);
36
40
  let text: string;
37
41
  try {
38
42
  text = readProjectFile(path, root === undefined ? {} : { root }).bytes.toString("utf8");
@@ -59,6 +63,7 @@ export function readSourceMap(directory: string, root?: string): SourceMap {
59
63
  const byName = new Map(labels.map((label) => [label.name, label]));
60
64
  return {
61
65
  directory,
66
+ mapPath: path,
62
67
  space: String(raw.space ?? "c64") as Space,
63
68
  revision: String(raw.revision),
64
69
  files: (raw.files as unknown[]).map(String),