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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/package.json +2 -2
  2. package/skills/c64-assembler/SKILL.md +28 -14
  3. package/skills/c64-assembler/scripts/assembler.ts +28 -15
  4. package/skills/c64-development/SKILL.md +4 -4
  5. package/skills/c64-docs/SKILL.md +9 -7
  6. package/skills/c64-docs/scripts/docs.ts +24 -11
  7. package/skills/c64-docs/scripts/lib/reference.ts +119 -33
  8. package/skills/c64-docs/scripts/lib/source-map.ts +23 -4
  9. package/skills/c64-knowledge/SKILL.md +67 -42
  10. package/skills/c64-knowledge/scripts/knowledge.ts +90 -67
  11. package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
  12. package/skills/c64-packer/SKILL.md +1 -1
  13. package/skills/c64-provenance/SKILL.md +11 -10
  14. package/skills/c64-provenance/scripts/lib/library.ts +16 -16
  15. package/skills/c64-provenance/scripts/provenance.ts +33 -23
  16. package/skills/c64-reverse-engineering/SKILL.md +17 -11
  17. package/skills/c64-source/SKILL.md +71 -47
  18. package/skills/c64-source/scripts/lib/export.ts +89 -34
  19. package/skills/c64-source/scripts/lib/loader.ts +79 -36
  20. package/skills/c64-source/scripts/lib/source.ts +38 -32
  21. package/skills/c64-source/scripts/lib/stage.ts +11 -5
  22. package/skills/c64-source/scripts/lib/start-screen.asm +4 -2
  23. package/skills/c64-source/scripts/source.ts +278 -145
  24. package/skills/c64-static-analysis/SKILL.md +29 -25
  25. package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
  26. package/skills/c64-static-analysis/scripts/lib/findings.ts +11 -11
  27. package/skills/c64-static-analysis/scripts/lib/instructions.ts +26 -24
  28. package/skills/c64-static-analysis/scripts/lib/macros.ts +3 -1
  29. package/skills/c64-static-analysis/scripts/static-analysis.ts +69 -67
  30. package/skills/c64-testing/SKILL.md +15 -5
  31. package/skills/c64-testing/references/recording-format.md +26 -5
  32. package/skills/c64-testing/references/scenario-format.md +11 -8
  33. package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
  34. package/skills/c64-testing/scripts/lib/play.ts +39 -41
  35. package/skills/c64-testing/scripts/lib/recording.ts +220 -46
  36. package/skills/c64-testing/scripts/lib/replay.ts +32 -6
  37. package/skills/c64-testing/scripts/lib/runs.ts +8 -3
  38. package/skills/c64-testing/scripts/lib/scenario.ts +18 -11
  39. package/skills/c64-testing/scripts/testing.ts +23 -2
  40. package/skills/c64-unpacker/SKILL.md +10 -5
  41. package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
  42. package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
  43. package/skills/c64-unpacker/scripts/lib/stages.ts +18 -3
  44. package/skills/c64-unpacker/scripts/unpacker.ts +43 -9
  45. package/skills/emulator/SKILL.md +7 -12
  46. package/src/build-name.ts +55 -0
  47. package/src/c64-keys.ts +98 -0
  48. package/src/c64.ts +22 -2
  49. package/src/cli/main.ts +3 -29
  50. package/src/host/main.ts +3 -3
  51. package/src/host/server.ts +3 -1
  52. package/src/host/tools/index.ts +2 -7
  53. package/src/host/vice/process.ts +34 -17
  54. package/src/host/vice/session.ts +138 -31
  55. package/src/host-client/steps.ts +21 -18
  56. package/src/host-client/tools.ts +2 -7
  57. package/src/host-client/vice-session.ts +7 -1
  58. package/src/knowledge/evidence.ts +66 -0
  59. package/src/knowledge/history.ts +5 -5
  60. package/src/knowledge/import.ts +12 -5
  61. package/src/knowledge/program.ts +123 -32
  62. package/src/knowledge/read.ts +36 -13
  63. package/src/knowledge/schema.ts +43 -17
  64. package/src/knowledge/start-screen.ts +70 -0
  65. package/src/knowledge/text.ts +33 -5
  66. package/src/knowledge/write.ts +75 -36
  67. package/src/mcp/inputs.ts +12 -0
  68. package/src/mcp/server.ts +1 -1
  69. package/src/mcp/tools/debug.ts +23 -21
  70. package/src/mcp/tools/input.ts +38 -5
  71. package/src/mcp/tools/machine.ts +3 -42
  72. package/src/mcp/tools/media.ts +1 -1
  73. package/src/mcp/tools/memory.ts +12 -9
  74. package/src/native/acme.ts +1 -1
  75. package/src/native/c64run.ts +7 -4
  76. package/src/native/decompiler/analyze.ts +98 -0
  77. package/src/native/decompiler/c64rt-wasm.ts +4 -0
  78. package/src/native/decompiler/language/c64rt_6510.sla +0 -0
  79. package/src/native/{ghidra → decompiler}/language/c64rt_6510.slaspec +1 -1
  80. package/src/native/decompiler/pcode.ts +222 -0
  81. package/src/native/decompiler/walk.ts +205 -0
  82. package/src/native/decompiler/wasm.ts +98 -0
  83. package/src/native/discover.ts +3 -3
  84. package/src/native/dxa.ts +12 -1
  85. package/src/native/processes.ts +4 -4
  86. package/src/native/types.ts +27 -27
  87. package/src/opcodes.ts +1 -1
  88. package/src/platform.ts +30 -1
  89. package/src/project.ts +17 -4
  90. package/src/protocol/tools.ts +1 -45
  91. package/src/protocol/vice.ts +47 -0
  92. package/src/reference-pages.ts +64 -0
  93. package/src/script.ts +4 -4
  94. package/src/vsf.ts +98 -0
  95. package/tools/c64run.c +158 -15
  96. package/tools/install-container.sh +1 -2
  97. package/src/cli/status.ts +0 -127
  98. package/src/host/tools/status.ts +0 -47
  99. package/src/native/ghidra/analyze.ts +0 -87
  100. package/src/native/ghidra/index.ts +0 -170
  101. package/src/native/ghidra/scripts/C64Export.java +0 -274
  102. package/src/native/ghidra/scripts/C64Prepare.java +0 -66
  103. package/src/native/status.ts +0 -135
  104. package/tools/install-ghidra.sh +0 -40
  105. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.cspec +0 -0
  106. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.ldefs +0 -0
  107. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.pspec +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.6.0-rc.2",
3
+ "version": "2.6.0-rc.20",
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. For the packed form, this is only the copier. | `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`. The `loader.asm` of the packed form holds only the copier, so its build is `clean_copier.prg`. The packed loader program `clean_loader.prg` of the generated source stays. 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`:
@@ -122,10 +136,10 @@ Assembles the source and writes the program to `--out`.
122
136
 
123
137
  Do as the result tells:
124
138
 
125
- - `result` is `PASS`: the program is at `out`. To run or debug the program, load the file at `out` into the emulator.
139
+ - `result` is `PASS`: the program is at `out`. To run or debug the program, load the file at `out` into the emulator. A generated source with a loader is different: the build of `main.asm` does not set the entry state, and it can hold bytes for $d000-$dfff. Load the loader program in its place.
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();
@@ -76,20 +84,24 @@ await runScript({
76
84
  }
77
85
  const setPc = call.address("set-pc");
78
86
  const { contents, ...tree } = readSourceTree(sourceRoot, call.strings("include"));
79
- 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.`);
87
+ const inSource = (name: string) => tree.files.findIndex((file) => file.path === (tree.sourceDir === "" ? name : `${tree.sourceDir}/${name}`));
88
+ if (inSource(entry) < 0) throw new Refusal("not-found", `${entry} is not a file in ${sourceRoot}. Give the main source file relative to the source root.`);
89
+ // The name of the build tells what it is: the release, or the switch values of config.asm.
90
+ const config = inSource(CONFIG_FILE);
91
+ const kind: BuildKind | undefined = label !== undefined ? { release: label } : config < 0 ? undefined : { values: configValues(contents[config]!.toString("utf8")), defaults: switchDefaults(call.space) };
92
+ const plain = call.flag("plain");
93
+ const out = call.string("out") ?? `${BUILD_DIRECTORY}/${buildName(entry, kind, contents[inSource(entry)]!.toString("utf8"))}.${plain ? "bin" : "prg"}`;
80
94
  const params: AcmeParams = { ...tree, entrySource: entry, defines: { ...releaseDefine, ...Object.fromEntries(call.strings("define").map(parseDefine)) }, ...(setPc === undefined ? {} : { setPc }) };
81
95
 
82
96
  const { result, attachments } = await assemble(params, contents, localToolContext());
83
97
  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
98
  const written = writeReported(out, plain ? attachments![0]!.subarray(2) : attachments![0]!, { what: "--out" });
86
99
  const range = result.loadRange!;
87
100
  const compared = program === undefined ? undefined : compareBuild(attachments![0]!, program);
88
101
  // An include file of platform names gives many constants that the program does not use.
89
102
  const all = call.flag("all-symbols");
90
103
  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");
104
+ const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, `a larger --max-listed, or read ${symbolsPath(out)}`);
93
105
  // A build that differs from its reference is a failed check.
94
106
  const different = compared !== undefined && !compared.identical;
95
107
  const hints = [
@@ -104,7 +116,8 @@ await runScript({
104
116
  ...(plain ? { plain: true } : {}),
105
117
  loadRange: { start: formatC64Address(range.start), end: formatC64Address(range.end), bytes: range.bytes },
106
118
  symbols,
107
- ...(symbolsPath === undefined ? {} : { symbolsFile: writeReported(symbolsPath, symbolsFileText(shown), { what: "--out-symbols" }) }),
119
+ // The symbols of the program for a test run, in symbols/ next to it.
120
+ symbolsFile: writeReported(symbolsPath(out), symbolsFileText(shown), { what: "--out" }),
108
121
  ...(all ? {} : { unusedConstants: result.symbols!.length - shown.length }),
109
122
  diagnostics: result.diagnostics,
110
123
  ...(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
 
@@ -109,9 +109,9 @@ A rebuilt program gets its source from the project knowledge. A change is a swit
109
109
  - Build the base release and compare it with the original. This build must be identical to the original.
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
- 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.
114
- - Run a run file with `expect` steps that show the feature or the fix.
112
+ 8. Test the builds:
113
+ - When the behavior must stay the same as the original, replay each recording on the default build. For a source with a loader, this is `build/clean_loader.prg`, else `build/clean.prg`. Do not replay a build with a switch that is not at its default. Run a test scenario in `tests/` only when no recording executes the changed code.
114
+ - On the build that has the switch, run a run file with `expect` steps that show the feature or the fix.
115
115
 
116
116
  ### The answer
117
117
 
@@ -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. |
@@ -112,16 +112,16 @@ Writes the reference pages from the project knowledge, the source map and the pr
112
112
  The reference has these pages:
113
113
 
114
114
  - `index.md`: each file of the source, with its range, its title, the count of routines and the count of names.
115
- - `modules/<file>.md`: a call graph of the file, its data regions with their readers and writers, and an entry for each name. An entry has the comment, the callers and the table that holds the name. For a routine, it also has the calls, the jumps, the reads and the writes.
115
+ - `modules/<file>.md`: first a table of the routines of the file. Each row has the callers and the first sentence of the comment. Then the data regions with their readers and writers, and a call graph. Then an entry for each routine and each data name. An entry has the comment, the callers and the table that holds the name. For a routine, it also has the calls, the jumps, the reads and the writes. A label that only code of its own file goes to is a row in a table under its routine.
116
116
  - `tables.md`: each table of addresses, jumps and words, entry by entry, with its target. An RTS table holds each target minus 1. The page gives the target.
117
- - `memory-map.md`: each region in address order. Then each variable outside the program, with its comment and the routines that read it and write it.
117
+ - `memory-map.md`: each region in address order. Then each variable outside the program, with its comment and the routines that read it and write it. A platform name, for example a chip register, has a routine only where the source line uses that name. `(indexed)` after a routine tells that the line adds X or Y to the address. That access can also go to the addresses after it, which can have no row.
118
118
  - `graphics.md`: each `sprite`, `bitmap`, `charset` and `screen` region. The project knowledge has no graphics mode. Thus a sprite, a bitmap or a charset shows in hires and in multicolour. A charset shows 16 characters in each row. A screen shows as text.
119
119
 
120
- In a call graph, a solid arrow is a call, a thick arrow is a table entry, and a dotted arrow is a jump. A table entry goes from each routine that reads the table to each target in code. A table of data addresses gives no arrow.
120
+ In a call graph, a solid arrow is a call, and a thick arrow is a table entry. The graph does not show the jumps. A table entry goes from each routine that reads the table to each target in code. A table of data addresses gives no arrow.
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.
@@ -176,12 +176,14 @@ In a group folder, a label names the project of a name. Write the label and a co
176
176
  - `linked`: `links`, the count of the links that it wrote, and `pages`, the pages that it changed. With `--check`, `notUpToDate` has the same fields for the links that are not up to date.
177
177
  - `problems`: `byKind`, `count`, `listed` and `rest`. Each item has `at` (the page and the line), `kind` and `message`. In a group folder, each item also has `project`: the label of the project of the page, or `shared`.
178
178
  - `group`: only in a group folder. `folder` is the group folder, relative to the folder of the pages. `projects` holds the labels.
179
+ - `evidence`: only when the project knowledge gives a file as evidence and the file is missing or changed. `count`, `listed` and `rest`. Each item has the `file`, its `state` (`missing` or `changed`) and the `revisions` that give the file. The project knowledge keeps the SHA-256 of each file of its evidence. An evidence item does not make `result` a FAIL.
179
180
 
180
181
  `hint` and `nextAction`:
181
182
 
182
183
  - A page has a problem: `hint` tells you to correct each problem. `nextAction` runs the same `link` command again.
183
184
  - With `--check`, a link is not up to date and no page has a problem: `nextAction` runs `link` without `--check` to write the links.
184
185
  - `reference` is `none`: no `reference` folder is in or beside the given pages. Give `--reference <dir>`, or run `generate` first.
186
+ - `evidence` has items: for a coverage map that changed, put the map into the project knowledge again. For a file that you did not change on purpose, restore it from git. Else examine the facts of the revisions against the new file. Give the new file as evidence of the next write of these facts.
185
187
 
186
188
  Do this for each `kind` of problem:
187
189
 
@@ -208,7 +210,7 @@ Errors:
208
210
  ## Workflow
209
211
 
210
212
  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`.
213
+ 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
214
  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
215
  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
216
  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.
@@ -13,12 +13,14 @@ import { WireFailure } from "#src/host-client/tools.ts";
13
13
  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
+ import { changedEvidence, type EvidenceChange } from "#src/knowledge/evidence.ts";
16
17
  import { programImage, type ProgramImage } from "#src/knowledge/program.ts";
17
- import { currentRevision, listComments, listModules, listReferences, listRegions, listSymbols } from "#src/knowledge/read.ts";
18
+ import { listComments, listModules, listReferences, listRegions, listSymbols, sourceRevision } from "#src/knowledge/read.ts";
18
19
  import { groupOf, namedGroup, projectRoot, resolveProjectFile, resolveProjectPath, type ProjectGroup } from "#src/project.ts";
20
+ import { GENERATED_MARK, referenceStamp } from "#src/reference-pages.ts";
19
21
  import { listed, OPTIONS, reply, runScript, UsageError, type Call, type Reply } from "#src/script.ts";
20
22
  import { checkLinks, linkPage, type Files, type LinkContext, type Names, type Problem } from "./lib/links.ts";
21
- import { buildReference, GENERATED_MARK } from "./lib/reference.ts";
23
+ import { buildReference } from "./lib/reference.ts";
22
24
  import { readSourceMap } from "./lib/source-map.ts";
23
25
 
24
26
  // ---------------------------------------------------------------------------
@@ -64,10 +66,10 @@ function generate(call: Call): Reply {
64
66
  image = programImage(db, map.space);
65
67
  const found = conflicts(db).length;
66
68
  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.
69
+ // 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.
70
+ const revision = sourceRevision(db, map.space);
69
71
  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.`);
72
+ 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
73
  }
72
74
  knowledge = {
73
75
  revision,
@@ -247,6 +249,8 @@ function link(call: Call): Reply {
247
249
  const reference = checkedReference !== undefined ? checkedReference : foundReference === undefined ? undefined : foundReference.slice(memberOf(foundReference)!.prefix.length).replace(/^\//, "");
248
250
  const referenceOf = (member: Member) => (reference === undefined ? undefined : posix.join(member.prefix, reference));
249
251
  const problems: Problem[] = [];
252
+ /** The evidence files of the knowledge of each read project that are missing or changed, with paths relative to the root of the run. */
253
+ const evidence: EvidenceChange[] = [];
250
254
 
251
255
  /** The names of a project, read the first time a page needs them. A project with given pages is read before the pages. */
252
256
  const loaded = new Map<Member, Names>();
@@ -266,13 +270,14 @@ function link(call: Call): Reply {
266
270
  let symbols;
267
271
  let revision;
268
272
  try {
269
- revision = currentRevision(db);
273
+ revision = sourceRevision(db, map.space);
270
274
  symbols = listSymbols(db, undefined, undefined, undefined, map.space);
275
+ for (const change of changedEvidence(db, member.root)) evidence.push({ ...change, file: inProject(change.file) });
271
276
  } finally {
272
277
  db?.close();
273
278
  }
274
279
  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.` });
280
+ 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
281
  }
277
282
  const addresses = new Map<string, number>();
278
283
  for (const label of map.labels) addresses.set(label.name, label.address);
@@ -319,9 +324,9 @@ function link(call: Call): Reply {
319
324
  problems.push(unreadable(page));
320
325
  continue;
321
326
  }
322
- const stamp = /^<!-- Generated by c64-docs from knowledge revision (\S+) /.exec(text);
323
- if (text.startsWith(GENERATED_MARK) && stamp !== null && stamp[1] !== map.revision) {
324
- problems.push({ page, line: 1, kind: "stale-reference", message: `${shown(page)} is from knowledge revision ${stamp[1]}, and the source${of} from ${map.revision}. Run docs.ts generate again.` });
327
+ const stamp = referenceStamp(text);
328
+ if (stamp !== undefined && stamp.revision !== map.revision) {
329
+ problems.push({ page, line: 1, kind: "stale-reference", message: `${shown(page)} is from knowledge revision ${stamp.revision}, and the source${of} from ${map.revision}. Run docs.ts generate again.` });
325
330
  }
326
331
  }
327
332
  const names: Names = {
@@ -395,11 +400,19 @@ function link(call: Call): Reply {
395
400
  ...(check ? { notUpToDate: { links, pages: changedPages } } : { linked: { links, pages: changedPages } }),
396
401
  problems: { byKind, ...shownProblems },
397
402
  };
403
+ const shownEvidence = listed(evidence, call.count("max-listed")!, (change) => ({ ...change, file: shown(change.file) }));
404
+ if (evidence.length > 0) output.evidence = shownEvidence;
398
405
  const again = (withCheck: boolean) =>
399
406
  call.next("link", ...call.subjects, "--source", call.string("source")!, ...(givenReference === undefined ? [] : ["--reference", givenReference]), ...(withCheck ? ["--check"] : []), ...(scope.unnamed ? ["--project", root] : []));
400
407
  const hints: string[] = [];
401
408
  let nextAction: string | undefined;
402
409
  if (reference === undefined) hints.push("No reference/ folder is in or beside the given pages, so the links to the reference are not checked. Give --reference <dir>, or run generate first.");
410
+ if (evidence.length > 0) {
411
+ hints.push(
412
+ "The project knowledge gives the files in evidence as evidence, and each file is missing or changed since the revisions in its item. For a coverage map that changed, put the map into the project knowledge again. For a file that you did not change on purpose, restore it from git. Else examine the facts of the revisions against the new file, and give the new file as evidence of the next write of these facts.",
413
+ );
414
+ if (shownEvidence.rest !== undefined) hints.push(`evidence is cut. To list all files, give ${shownEvidence.rest}.`);
415
+ }
403
416
  if (problems.length > 0) {
404
417
  hints.push("Correct each problem in problems.listed as its message tells. Then run nextAction.");
405
418
  if (shownProblems.rest !== undefined) hints.push(`problems is cut. To list all problems, give ${shownProblems.rest}.`);
@@ -411,7 +424,7 @@ function link(call: Call): Reply {
411
424
  return reply({ result: problems.length > 0 || (check && links > 0) ? "FAIL" : "PASS", ...output }, { ...(hints.length === 0 ? {} : { hint: hints.join(" ") }), nextAction });
412
425
  }
413
426
 
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;
427
+ 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
428
 
416
429
  await runScript({
417
430
  name: "docs",