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

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 (36) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +26 -12
  3. package/skills/c64-assembler/scripts/assembler.ts +24 -11
  4. package/skills/c64-knowledge/SKILL.md +31 -16
  5. package/skills/c64-knowledge/scripts/knowledge.ts +62 -33
  6. package/skills/c64-packer/SKILL.md +1 -1
  7. package/skills/c64-reverse-engineering/SKILL.md +1 -1
  8. package/skills/c64-source/SKILL.md +51 -30
  9. package/skills/c64-source/scripts/lib/export.ts +76 -32
  10. package/skills/c64-source/scripts/lib/loader.ts +29 -9
  11. package/skills/c64-source/scripts/lib/source.ts +5 -16
  12. package/skills/c64-source/scripts/lib/stage.ts +11 -5
  13. package/skills/c64-source/scripts/lib/start-screen.asm +4 -2
  14. package/skills/c64-source/scripts/source.ts +145 -46
  15. package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
  16. package/skills/c64-testing/SKILL.md +3 -1
  17. package/skills/c64-testing/references/recording-format.md +1 -0
  18. package/skills/c64-testing/references/scenario-format.md +5 -3
  19. package/skills/c64-testing/scripts/lib/recording.ts +25 -8
  20. package/skills/c64-testing/scripts/lib/replay.ts +1 -1
  21. package/skills/c64-testing/scripts/lib/scenario.ts +14 -5
  22. package/skills/c64-unpacker/SKILL.md +4 -2
  23. package/skills/c64-unpacker/scripts/lib/loads.ts +33 -12
  24. package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
  25. package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
  26. package/src/build-name.ts +47 -0
  27. package/src/c64.ts +21 -1
  28. package/src/host/vice/session.ts +6 -1
  29. package/src/knowledge/read.ts +5 -2
  30. package/src/knowledge/schema.ts +5 -3
  31. package/src/knowledge/start-screen.ts +68 -0
  32. package/src/knowledge/text.ts +1 -0
  33. package/src/knowledge/write.ts +22 -16
  34. package/src/native/acme.ts +1 -1
  35. package/src/platform.ts +30 -1
  36. package/src/script.ts +3 -3
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.4",
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",
@@ -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 file 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
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 file of the release. |
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,6 +1,7 @@
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 { 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
7
  import { readImage } from "#src/host-client/image.ts";
@@ -8,8 +9,8 @@ import { readSourceTree, writeReported } from "#src/host-client/transfer.ts";
8
9
  import { openForRead } from "#src/knowledge/database.ts";
9
10
  import { knowledgeNames } from "#src/knowledge/names.ts";
10
11
  import { requireProgram } from "#src/knowledge/program.ts";
11
- import { releaseLabeled } from "#src/knowledge/read.ts";
12
- import { RELEASE_DEFINE } from "#src/knowledge/schema.ts";
12
+ import { listSwitches, releaseLabeled } from "#src/knowledge/read.ts";
13
+ import { LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
13
14
  import { assemble, showSymbol, symbolsFileText } from "#src/native/acme.ts";
14
15
  import { localToolContext } from "#src/native/local.ts";
15
16
  import type { AcmeParams, AssembledSymbol } from "#src/native/types.ts";
@@ -26,6 +27,16 @@ function parseDefine(text: string): [string, number | boolean] {
26
27
  throw new UsageError(`--define ${match[1]} needs an integer or true/false, not ${value}`);
27
28
  }
28
29
 
30
+ /** The default of each switch of a generated source: the knowledge gives them, the start screen is in and the leftovers are out. */
31
+ function switchDefaults(space: Space): Map<string, number> {
32
+ const db = openForRead();
33
+ try {
34
+ return new Map([[START_SCREEN_SWITCH, 1], [LEFTOVERS_SWITCH, 0], ...listSwitches(db, undefined, space).map((row) => [row.name, row.default] as const)]);
35
+ } finally {
36
+ db?.close();
37
+ }
38
+ }
39
+
29
40
  await runScript({
30
41
  name: "assembler",
31
42
  summary: "Assembles project source with ACME and writes the program into the project.",
@@ -39,22 +50,20 @@ await runScript({
39
50
  { name: "<entry>", help: "the main source file, relative to the source root" },
40
51
  ],
41
52
  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" },
53
+ 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" },
54
+ include: { kind: "text", value: "<folder>", multiple: true, help: "an include folder: a path relative to the source root, inside the project folder" },
44
55
  define: { kind: "text", value: "NAME=VALUE", multiple: true, help: "an assembler symbol: an integer ($hex allowed) or true/false" },
45
56
  "set-pc": { kind: "address", value: "<address>", help: "the start address when the source sets none, for example '$0801'" },
46
57
  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
58
  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" },
59
+ 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
60
  plain: { kind: "flag", help: "write the bytes only, without the 2-byte load address of a PRG" },
50
61
  "all-symbols": { kind: "flag", help: "list also the constants that the source does not use" },
51
62
  "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
63
  },
54
64
  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
65
  run: async (call) => {
56
66
  const [sourceRoot, entry] = [call.subject(0), call.subject(1)];
57
- const out = call.string("out")!;
58
67
  // Read the reference before ACME runs, so a project without it stops at once.
59
68
  let program: Reference | undefined;
60
69
  const label = call.string("release");
@@ -77,19 +86,22 @@ await runScript({
77
86
  const setPc = call.address("set-pc");
78
87
  const { contents, ...tree } = readSourceTree(sourceRoot, call.strings("include"));
79
88
  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.`);
89
+ // The name of the build tells what it is: the release, or the switch values of config.asm.
90
+ const config = tree.files.findIndex((file) => file.path === (tree.sourceDir === "" ? CONFIG_FILE : `${tree.sourceDir}/${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/${buildName(entry, kind)}.${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 }),
@@ -53,7 +53,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
53
53
  | Write the code of a switch for a range | `patch '$100e-$1010' PROTECTION --code-file no-check.asm` |
54
54
  | List the releases, switches and patches | `switches` |
55
55
  | Record the start screen of the program | `start-screen --mode multicolour --screen '$5c00' --bitmap '$6000' --colours '$8328' --border 0 --background 0` |
56
- | Record the start screen of a captured stage, and its tune | `start-screen --mode multicolour --screen '$cc00' --bitmap '$e000' --colours '$8328' --border 3 --background 1 --stage bank1 --call '$9000'` |
56
+ | Record the start screen of a captured stage, and its tune | `start-screen --stage loading --call '$9000'` |
57
57
  | Remove the start screen | `unstart-screen` |
58
58
  | Write a macro | `macro inc16 --params dst --body-file inc16.asm` |
59
59
  | Write instructions as one use of a macro | `use '$1005-$100a' inc16 --args ptr` |
@@ -72,7 +72,7 @@ The knowledge is text in `.c64-re-tools/knowledge/` of the project. Commit that
72
72
  - An analyzer name is a second name from DXA, Ghidra or an idiom search, for example `FUN_17e2`. Each analyzer keeps its own name at an address. Get them from `at`, `search` or `symbols --analyzer`.
73
73
  - The generated source uses only the symbols. To use an analyzer name in the source, give the address that name with `rename`.
74
74
  - A symbol name is a label for ACME: a letter or an underscore, then letters, digits or underscores. The knowledge refuses the name of a 6502 instruction, for example `lda`, in upper or lower case.
75
- - A space is `c64` (the default), `drive8` for code in the 1541 drive, or `bank0` to `bank255` for cartridge banks and for a captured stage of the loading. Drive code, banks and stages use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
75
+ - A space is `c64` (the default), `drive8` for code in the 1541 drive, `loading` or `bank0` to `bank255`. `loading` is the captured stage of the loading that shows the start screen. `bank0` to `bank255` are cartridge banks. Drive code, the stage and banks use the same addresses as the C64. Thus each space has its own knowledge. A name is unique in one space.
76
76
  - A revision id has the form `20261015T214501.123-k3f9qz`. It starts with the date and the time. Give the full id, or a start of the id that only one revision has. Get the ids from `revisions`, or from the `revision` field of a result. The revision `0` is the knowledge before the first revision.
77
77
  - A file of a capture is the `image.json` that the capture of a packed program wrote. Keep the other files of the capture next to it.
78
78
 
@@ -102,7 +102,7 @@ Each flag applies only to the commands in the table. On another command, the scr
102
102
 
103
103
  | Flag | Command | Effect |
104
104
  |---|---|---|
105
- | `--space <space>` | All commands | The space of the command: `c64`, `drive8`, or `bank0` to `bank255`. The default is `c64`. Without `--space`, `revert` reverts all spaces. |
105
+ | `--space <space>` | All commands | The space of the command: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. Without `--space`, `revert` reverts all spaces. |
106
106
  | `--by <user\|llm>` | All commands in "Change the knowledge" | Who decided the change. The default is `llm`. Give `user` only when the user decided the change. |
107
107
  | `--reason <text>` | All commands in "Change the knowledge" | Why you make the change. The revision keeps it, and `history` shows it. |
108
108
  | `--evidence <kind:ref>` | All commands in "Change the knowledge" | One thing that the change rests on: `coverage:<map>`, `test:<file>`, `file:<file>` or `note:<text>`. You can give it more than one time. |
@@ -142,15 +142,15 @@ Each flag applies only to the commands in the table. On another command, the scr
142
142
  | `--body <text>` | `macro` | The body of the macro. |
143
143
  | `--body-file <file>` | `macro` | A project file with the body of the macro. |
144
144
  | `--args <x, y>` | `use` | One expression for each param of the macro, as a comma list. |
145
- | `--mode <mode>` | `start-screen` | Necessary. The mode of the VIC-II: `text`, `hires` or `multicolour`. |
146
- | `--screen <address>` | `start-screen` | Necessary. The address of the screen memory: 1000 bytes. |
145
+ | `--mode <mode>` | `start-screen` | The mode of the VIC-II: `text`, `hires` or `multicolour`. Necessary without `--stage`. |
146
+ | `--screen <address>` | `start-screen` | The address of the screen memory: 1000 bytes. Necessary without `--stage`. |
147
147
  | `--bitmap <address>` | `start-screen` | The address of the bitmap: 8000 bytes. `hires` and `multicolour` need it. |
148
148
  | `--charset <address>` | `start-screen` | The address of the charset: 2048 bytes. `text` needs it. |
149
149
  | `--colours <address>` | `start-screen` | The address of the 1000 bytes that the loader copies to the colour RAM. |
150
150
  | `--colour <0-15>` | `start-screen` | One colour for all of the colour RAM, in place of `--colours`. |
151
- | `--border <0-15>` | `start-screen` | Necessary. The border colour. |
152
- | `--background <0-15>` | `start-screen` | Necessary. The background colour. |
153
- | `--stage <space>` | `start-screen` | The space of a captured stage that holds the bytes of the screen, for example `bank1`. Without it, the bytes are in the program at the entry. |
151
+ | `--border <0-15>` | `start-screen` | The border colour. Necessary without `--stage`. |
152
+ | `--background <0-15>` | `start-screen` | The background colour. Necessary without `--stage`. |
153
+ | `--stage <space>` | `start-screen` | The space of the captured stage that shows the screen: `loading`. The script takes the mode, the addresses and the colours from the capture. Without it, the bytes are in the program at the entry. |
154
154
  | `--call <address>` | `start-screen` | A routine of the stage that the start screen calls before it waits, for example the start of the loading tune. It must return with RTS. It needs `--stage`. |
155
155
 
156
156
  ---
@@ -407,15 +407,30 @@ A start screen is a loading screen, a title screen or a presentation screen of t
407
407
  1. Record patches under a switch that take out the change.
408
408
  2. Use the screen as it is.
409
409
  3. Do not record a start screen.
410
- - The bytes of the screen must be in the program of the knowledge at the entry, or in a captured stage. Thus capture the program while the bytes of the screen are in memory.
411
- - When the bytes are only in a stage of the loading, do these steps:
412
- 1. Capture the stage while it shows the screen. Do not exclude the memory of the screen.
413
- 2. Put the capture into the knowledge in a space of its own, for example `image stage/image.json --space bank1`.
414
- 3. If the stage plays a tune or does other work during the screen, find the routine that starts it. Run the stage with coverage while that routine runs. Put the map into the knowledge with `coverage <map> --space bank1`.
415
- 4. Record the start screen with `--stage bank1`, and with `--call` for the routine.
416
- - With `--stage`, the addresses are in the program of that space. Each part and the call must be in it.
410
+ - The bytes of the screen must be in the program of the knowledge at the entry, or in a captured stage.
411
+
412
+ #### A start screen of a captured stage
413
+
414
+ Use this when a stage of the loading shows the screen, and the program at the entry does not have it. Do these steps:
415
+
416
+ 1. Capture the stage while it shows the screen. Do not exclude the memory of the screen.
417
+ 2. Put the capture into the knowledge in the space `loading`: `image stage/image.json --space loading`. Do not use another space for it.
418
+ 3. If the stage plays a tune or does other work during the screen, find the routine that starts it. Run the stage with coverage while that routine runs. Put the map into the knowledge with `coverage <map> --space loading`.
419
+ 4. Record the start screen with `start-screen --stage loading`, and with `--call` for the routine.
420
+
421
+ - The script takes the mode, the screen, the bitmap or the charset, the colours and the colour RAM from the capture. Do not find the addresses or the colours yourself.
422
+ - The generated source puts the screen in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
423
+ - A flag that you give replaces the value of the capture. Give a flag only to correct a value.
424
+ - A capture of an older version has no colour RAM. Then capture the stage again.
425
+
426
+ #### A start screen in the program
427
+
428
+ - Capture the program while the bytes of the screen are in memory.
417
429
  - Get the mode, the addresses and the colours from the VIC-II while the original program shows the screen.
418
- - The colour RAM is not in the capture. Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while the original shows the screen. Give their address with `--colours`. If the program does not have them, give one colour with `--colour`.
430
+ - Find the 1000 colour bytes in the program: compare them with the colour RAM at $d800 while the original shows the screen. Give their address with `--colours`. If the program does not have them, give one colour with `--colour`.
431
+
432
+ #### The rules of the VIC-II
433
+
419
434
  - `text` needs `--charset`. `hires` and `multicolour` need `--bitmap`. `text` and `multicolour` need `--colours` or `--colour`. `hires` uses neither.
420
435
  - The screen is at a step of $0400, the bitmap at a step of $2000 and the charset at a step of $0800. They must be in one VIC bank of 16 KB.
421
436
  - In VIC bank 0 and 2, the VIC-II reads the character ROM at $1000-$1fff of the bank. A screen or a bitmap cannot be there. A charset at $1000 or $1800 of the bank is the character ROM.
@@ -18,6 +18,7 @@ import { historyAt, historyNamed, historyOfMacro, historyOfSwitch, revision, rev
18
18
  import { joinBatches, type Batch, type JoinChoice, type JoinClash } from "#src/knowledge/join.ts";
19
19
  import { knowledgeNames } from "#src/knowledge/names.ts";
20
20
  import { addCoverage, programCoverage, programImage, requireProgram, setImage, type ImageRequest } from "#src/knowledge/program.ts";
21
+ import { startScreenOfStage } from "#src/knowledge/start-screen.ts";
21
22
  import {
22
23
  analyzerNamesAt,
23
24
  at,
@@ -177,6 +178,7 @@ const startScreen = (row: StartScreenRow) => ({
177
178
  background: row.background,
178
179
  ...(row.stage === undefined ? {} : { stage: row.stage }),
179
180
  ...(row.call === undefined ? {} : { call: formatC64Address(row.call) }),
181
+ ...(row.colourRam === true ? { colourRam: true } : {}),
180
182
  ...(row.comment === undefined ? {} : { comment: row.comment }),
181
183
  origin: row.origin,
182
184
  revision: row.revision,
@@ -360,14 +362,22 @@ function imageRequest(path: string, space: string): ImageRequest {
360
362
  }
361
363
 
362
364
  /**
363
- * The program in the knowledge that operand, patch and macro use writes
364
- * are checked against, with the platform names. A byte outside
365
- * the segments of the program is not in it.
365
+ * The program of each space in the knowledge that operand, patch and macro
366
+ * use writes in that space are checked against, with the platform names. A
367
+ * byte outside the segments of the program is not in it. Each program is
368
+ * read once, when a write in its space needs it.
366
369
  */
367
- function operandImage(db: DatabaseSync, space: string): OperandImage {
368
- const image = requireProgram(db, space);
369
- const inside = (at: number) => image.segments.some((segment) => at >= segment.start && at <= segment.end);
370
- return { byteAt: (at) => (inside(at) ? image.byteAt(at) : undefined), platform: new Map(platformNames().map((entry) => [entry.name, entry.address])) };
370
+ function operandImages(db: DatabaseSync): (space: string) => OperandImage {
371
+ const images = new Map<string, OperandImage>();
372
+ return (space) => {
373
+ const known = images.get(space);
374
+ if (known !== undefined) return known;
375
+ const image = requireProgram(db, space);
376
+ const inside = (at: number) => image.segments.some((segment) => at >= segment.start && at <= segment.end);
377
+ const made: OperandImage = { byteAt: (at) => (inside(at) ? image.byteAt(at) : undefined), platform: new Map(platformNames().map((entry) => [entry.name, entry.address])) };
378
+ images.set(space, made);
379
+ return made;
380
+ };
371
381
  }
372
382
 
373
383
  /** An offset: a whole number in decimal or $ hex, with an optional minus sign. */
@@ -810,7 +820,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
810
820
  request.symbol = call.string(select)!;
811
821
  if (offset !== undefined) request.offset = offsetOf(offset, "--offset");
812
822
  }
813
- return (db) => shown(setOperand(db, { ...context, image: operandImage(db, call.space) }, request), "operand", operand);
823
+ return (db) => shown(setOperand(db, { ...context, image: operandImages(db) }, request), "operand", operand);
814
824
  },
815
825
  ),
816
826
  writeCommand({ name: "unoperand", summary: "Removes the operand expression at an address.", subjects: [ADDRESS] }, (call) => {
@@ -837,7 +847,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
837
847
  if ((code === undefined) === !call.flag("nop")) throw new UsageError("patch needs exactly one of --code, --code-file or --nop.");
838
848
  const commentText = call.string("comment");
839
849
  const request = { space: call.space, ...call.parseRange(call.subject(0), "<range>"), switch: call.subject(1), code: code ?? "", ...(commentText === undefined ? {} : { comment: commentText }) };
840
- return (db) => shown(setPatch(db, { ...context, image: operandImage(db, call.space) }, request), "patch", patch);
850
+ return (db) => shown(setPatch(db, { ...context, image: operandImages(db) }, request), "patch", patch);
841
851
  },
842
852
  ),
843
853
  writeCommand(
@@ -881,7 +891,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
881
891
  ...(commentText === undefined ? {} : { comment: commentText }),
882
892
  };
883
893
  return (db) => {
884
- const result = setSwitch(db, { ...context, image: operandImage(db, call.space) }, request);
894
+ const result = setSwitch(db, { ...context, image: operandImages(db) }, request);
885
895
  const base = listReleases(db, undefined, call.space).find((row) => row.base)?.label;
886
896
  return shown(result, "switch", (row: SwitchRow) => switchRow(row, base));
887
897
  };
@@ -939,42 +949,62 @@ const WRITE_COMMANDS: CommandSpec[] = [
939
949
  name: "start-screen",
940
950
  summary: "Records the start screen of the program: a loading, title or presentation screen of the program itself, in memory at the entry or in a captured stage of the loading. The loader of the generated source shows it and waits for a key or a fire button before the entry.",
941
951
  options: {
942
- mode: { kind: "choice", value: "<mode>", choices: START_SCREEN_MODES, help: `one of ${START_SCREEN_MODES.join(", ")}`, required: true },
943
- screen: { kind: "address", value: "<address>", help: "the screen: the 1000 characters of a text screen, or the 1000 colour bytes of a bitmap", required: true },
952
+ mode: { kind: "choice", value: "<mode>", choices: START_SCREEN_MODES, help: `one of ${START_SCREEN_MODES.join(", ")}. Necessary without --stage` },
953
+ screen: { kind: "address", value: "<address>", help: "the screen: the 1000 characters of a text screen, or the 1000 colour bytes of a bitmap. Necessary without --stage" },
944
954
  bitmap: { kind: "address", value: "<address>", help: "the 8000 bytes of the bitmap. hires and multicolour need it" },
945
955
  charset: { kind: "address", value: "<address>", help: "the 2048 bytes of the charset, or '$1000' or '$1800' for the character ROM in VIC bank 0. text needs it" },
946
956
  colours: { kind: "address", value: "<address>", help: "the 1000 bytes that the loader copies to the colour RAM" },
947
957
  colour: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "one colour for all of the colour RAM, in place of --colours" },
948
- border: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the border colour", required: true },
949
- background: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the background colour", required: true },
950
- stage: { kind: "text", value: "<space>", help: "the space of a captured stage that holds the bytes of the screen, for example bank1. Without it, the bytes are in the program at the entry" },
958
+ border: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the border colour. Necessary without --stage" },
959
+ background: { kind: "count", value: "<0-15>", min: 0, max: 15, help: "the background colour. Necessary without --stage" },
960
+ stage: { kind: "text", value: "<space>", help: "the space of the captured stage that shows the screen: loading. The script takes the mode, the addresses and the colours from the capture of the stage. Without it, the bytes are in the program at the entry" },
951
961
  call: { kind: "address", value: "<address>", help: "a routine of the stage that the start screen calls before it waits, for example the routine that starts the loading tune. It must return with RTS. Needs --stage" },
952
962
  comment: { kind: "text", value: "<text>", help: "what the screen is" },
953
963
  },
954
- notes: "Record only a screen of the program itself, never a screen of a crack. If a release changed the screen, for example with the text of a crack, stop and ask the user how to deal with it. text and multicolour need --colours or --colour; hires uses neither. With --stage, the addresses are in the program of that space. A write replaces the start screen of the knowledge.",
964
+ notes: "Record only a screen of the program itself, never a screen of a crack. If a release changed the screen, for example with the text of a crack, stop and ask the user how to deal with it. text and multicolour need --colours or --colour; hires uses neither. With --stage, the script takes the screen from the capture of the stage: give only --stage, and --call for a tune. A flag that you give too replaces the value of the capture. A write replaces the start screen of the knowledge.",
955
965
  },
956
966
  (call) => {
957
967
  const context = contextOf(call);
958
968
  const commentText = call.string("comment");
959
- const optional = (key: "bitmap" | "charset" | "colours") => ((value) => (value === undefined ? {} : { [key]: value }))(call.address(key));
960
- const colour = call.count("colour");
969
+ // The values that the call gives. With --stage, the capture of the stage gives the others.
970
+ const given: { mode?: StartScreenMode; screen?: number; bitmap?: number; charset?: number; colours?: number; colour?: number; border?: number; background?: number } = {};
971
+ const mode = call.string("mode") as StartScreenMode | undefined;
972
+ if (mode !== undefined) given.mode = mode;
973
+ for (const key of ["screen", "bitmap", "charset", "colours"] as const) {
974
+ const value = call.address(key);
975
+ if (value !== undefined) given[key] = value;
976
+ }
977
+ for (const key of ["colour", "border", "background"] as const) {
978
+ const value = call.count(key);
979
+ if (value !== undefined) given[key] = value;
980
+ }
961
981
  const stage = call.string("stage");
962
982
  const routine = call.address("call");
963
- const request = {
983
+ const extra = {
964
984
  space: call.space,
965
- mode: call.string("mode") as StartScreenMode,
966
- screen: call.address("screen")!,
967
- ...optional("bitmap"),
968
- ...optional("charset"),
969
- ...optional("colours"),
970
- ...(colour === undefined ? {} : { colour }),
971
- border: call.count("border")!,
972
- background: call.count("background")!,
973
985
  ...(stage === undefined ? {} : { stage }),
974
986
  ...(routine === undefined ? {} : { call: routine }),
975
987
  ...(commentText === undefined ? {} : { comment: commentText }),
976
988
  };
977
- return (db) => shown(setStartScreen(db, context, request), "startScreen", startScreen);
989
+ const complete = (values: typeof given & { colourRam?: true }, remedy: string) => {
990
+ const missing = (["mode", "screen", "border", "background"] as const).filter((key) => values[key] === undefined);
991
+ if (missing.length > 0) throw new UsageError(`Give ${missing.map((key) => `--${key}`).join(", ")}, ${remedy}`);
992
+ return { ...values, mode: values.mode!, screen: values.screen!, border: values.border!, background: values.background!, ...extra };
993
+ };
994
+ if (stage === undefined) {
995
+ const request = complete(given, "or give --stage with the space of a captured stage that shows the screen.");
996
+ return (db) => shown(setStartScreen(db, context, request), "startScreen", startScreen);
997
+ }
998
+ return (db) => {
999
+ // The capture of the stage gives the screen. A flag of the call replaces a value of the capture, and --colours or --colour replaces the colour RAM.
1000
+ const image = programImage(db, stage);
1001
+ if (image === undefined) throw new Refusal("not-found", `The knowledge has no program in ${stage}. Capture the stage while it shows the start screen, and put the capture into the project knowledge with image --space ${stage}. Then record the start screen again.`);
1002
+ const captured = mode === undefined ? startScreenOfStage(image.state, stage) : undefined;
1003
+ const { colourRam, ...fromCapture } = captured ?? { colourRam: undefined };
1004
+ const ownColours = given.colours !== undefined || given.colour !== undefined;
1005
+ const request = complete({ ...fromCapture, ...(colourRam === true && !ownColours ? { colourRam } : {}), ...given }, "or give --stage alone to take the screen from the capture.");
1006
+ return shown(setStartScreen(db, context, request), "startScreen", startScreen);
1007
+ };
978
1008
  },
979
1009
  ),
980
1010
  writeCommand({ name: "unstart-screen", summary: "Removes the start screen. The loader of the generated source then starts the program at once." }, (call) => {
@@ -1020,7 +1050,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
1020
1050
  const context = contextOf(call);
1021
1051
  const request = { space: call.space, ...call.parseRange(call.subject(0), "<range>"), macro: call.subject(1), args: commaList(call.string("args") ?? "") };
1022
1052
  return (db) => {
1023
- const result = setMacroUse(db, { ...context, image: operandImage(db, call.space) }, request);
1053
+ const result = setMacroUse(db, { ...context, image: operandImages(db) }, request);
1024
1054
  return { revision: result.revision, use: macroUse(result.current), ...(result.previous === undefined ? {} : { previous: macroUse(result.previous) }) };
1025
1055
  };
1026
1056
  },
@@ -1065,7 +1095,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
1065
1095
  name: "revert",
1066
1096
  summary: "Makes the knowledge the same as at one revision: all spaces, or with --space only that space. The revert is a new revision: the history stays complete.",
1067
1097
  subjects: [REVISION],
1068
- options: { space: { kind: "space", value: "<space>", help: "revert only this space: c64, drive8, or bank0 to bank255. The other spaces do not change. Without --space, every space reverts" } },
1098
+ options: { space: { kind: "space", value: "<space>", help: "revert only this space: c64, drive8, loading, or bank0 to bank255. The other spaces do not change. Without --space, every space reverts" } },
1069
1099
  },
1070
1100
  (call) => {
1071
1101
  const context = contextOf(call);
@@ -1104,9 +1134,8 @@ const WRITE_COMMANDS: CommandSpec[] = [
1104
1134
  }
1105
1135
  if (!Array.isArray(parsed)) throw new Refusal("invalid-input", `The batch ${path} is not a JSON list of writes. Give a list such as [{"op": "rename", "address": "$2100", "name": "update_player"}].`);
1106
1136
  const operations = parsed.map((item, index) => batchOperation(call, item, `write ${index + 1}`));
1107
- const checked = operations.some((operation) => operation.op === "operand" || operation.op === "patch" || operation.op === "use");
1108
1137
  return (db) => {
1109
- const applied = applyBatch(db, checked ? { ...context, image: operandImage(db, call.space) } : context, operations);
1138
+ const applied = applyBatch(db, { ...context, image: operandImages(db) }, operations);
1110
1139
  // replaced: each write that replaced a row of another origin, with that row as previous gives it for one write.
1111
1140
  const replaced = applied.steps.flatMap((step, index) => (step.previous === undefined ? [] : [{ write: index + 1, op: operations[index]!.op, previous: shownPrevious(step.previous) }]));
1112
1141
  return { revision: applied.revision, writes: applied.steps.length, replaced };
@@ -1243,7 +1272,7 @@ function batchFields(fields: Record<string, unknown>, at: string, address: (text
1243
1272
 
1244
1273
  await runScript({
1245
1274
  name: "knowledge",
1246
- summary: "Reads and writes the knowledge of the project: names, regions, comments, references, the program and its coverage, and the source knowledge. A read needs no knowledge folder. Every command takes --space: c64 (the default), drive8 for 1541 drive code, or bank0 to bank255 for cartridge banks. revert without --space reverts all spaces.",
1275
+ summary: "Reads and writes the knowledge of the project: names, regions, comments, references, the program and its coverage, and the source knowledge. A read needs no knowledge folder. Every command takes --space: c64 (the default), drive8 for 1541 drive code, loading for a captured stage of the loading, or bank0 to bank255 for cartridge banks. revert without --space reverts all spaces.",
1247
1276
  names: knowledgeNames,
1248
1277
  commands: [...READ_COMMANDS, ...WRITE_COMMANDS, JOIN],
1249
1278
  });
@@ -25,7 +25,7 @@ To get the command list, run the script with no arguments.
25
25
  |---|---|
26
26
  | Pack a BASIC program at `$0801` that starts with `SYS` | `pack build/game.prg --out build/game-packed.prg` |
27
27
  | Pack a program that starts at a known address | `pack build/main.prg --entry '$0400' --out build/release.prg` |
28
- | Merge more PRG files into one packed program | `pack build/loader.prg build/main.prg --entry '$0400' --out build/release.prg` |
28
+ | Merge more PRG files into one packed program | `pack build/clean_loader.prg build/clean.prg --entry '$0400' --out build/clean_packed.prg` |
29
29
  | Start the program with RAM in place of the BASIC and KERNAL ROMs | `pack build/game.prg --exit-memory '$35' --out build/game-packed.prg` |
30
30
 
31
31
  ---
@@ -37,7 +37,7 @@ These rules apply to each rebuild:
37
37
 
38
38
  - Do not keep a cracktro. A capture of a packed program starts at the last stage, so the code of a cracktro is not in the program. When the capture has data of a cracktro that the program does not read, capture again and exclude that range.
39
39
  - Keep the start screen of the program, for example the loading picture of the publisher. Keep its bytes in the capture, and record the start screen in the project knowledge. The loader of the rebuild then shows it and waits for a key or a fire button. Do not keep a screen of a crack, for example a picture, an intro or a credit screen of a crack group.
40
- - When the start screen is only in a stage of the loading, capture that stage while it shows the screen. Put the capture into the project knowledge in a space of its own. Then record the start screen of that stage. Keep its tune: record the routine that starts the tune as the call of the start screen.
40
+ - When the start screen is only in a stage of the loading, capture that stage while it shows the screen. Put the capture into the project knowledge in the space `loading`. Then record the start screen of that stage. Keep its tune: record the routine that starts the tune as the call of the start screen.
41
41
  - A release can change the start screen, for example with the text of a crack. Then stop and ask the user how to deal with it. Do not decide alone.
42
42
  - Keep all other bytes: unused bytes, dead code, old copies, texts and leftovers of the development. Record each one as a region with a comment. Do not remove them. The source keeps them, and the build of each release has them. The default build and the loader do not have them.
43
43
  - Do not write a file of the rebuild by hand, for example a boot file, a packed picture or a script that changes bytes. Record each change in the project knowledge, and generate the source.