@henols/c64-re-tools 2.7.1 → 2.8.0-rc.2

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 (70) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +23 -38
  3. package/skills/c64-assembler/scripts/assembler.ts +137 -17
  4. package/skills/c64-basic/SKILL.md +11 -31
  5. package/skills/c64-basic/scripts/basic.ts +4 -1
  6. package/skills/c64-development/SKILL.md +2 -2
  7. package/skills/c64-disk/SKILL.md +11 -32
  8. package/skills/c64-docs/SKILL.md +27 -45
  9. package/skills/c64-docs/references/page-types.md +20 -18
  10. package/skills/c64-docs/references/style.md +10 -4
  11. package/skills/c64-docs/scripts/docs.ts +13 -2
  12. package/skills/c64-docs/scripts/lib/reference.ts +47 -5
  13. package/skills/c64-knowledge/SKILL.md +138 -267
  14. package/skills/c64-knowledge/references/batches.md +48 -0
  15. package/skills/c64-knowledge/references/coverage.md +29 -0
  16. package/skills/c64-knowledge/references/source-knowledge.md +72 -0
  17. package/skills/c64-knowledge/references/start-screen.md +44 -0
  18. package/skills/c64-knowledge/scripts/knowledge.ts +266 -61
  19. package/skills/c64-knowledge/scripts/lib/check.ts +133 -0
  20. package/skills/c64-knowledge/scripts/lib/listing.ts +71 -8
  21. package/skills/c64-memory-map/SKILL.md +11 -32
  22. package/skills/c64-packer/SKILL.md +11 -31
  23. package/skills/c64-provenance/SKILL.md +43 -64
  24. package/skills/c64-provenance/scripts/lib/leftovers.ts +8 -3
  25. package/skills/c64-provenance/scripts/provenance.ts +65 -56
  26. package/skills/c64-reverse-engineering/SKILL.md +20 -47
  27. package/skills/c64-reverse-engineering/references/comment-check.md +42 -0
  28. package/skills/c64-reverse-engineering/references/versions.md +47 -0
  29. package/skills/c64-source/SKILL.md +48 -237
  30. package/skills/c64-source/references/export.md +50 -0
  31. package/skills/c64-source/references/loader.md +78 -0
  32. package/skills/c64-source/references/source-format.md +46 -0
  33. package/skills/c64-source/scripts/lib/export.ts +28 -13
  34. package/skills/c64-source/scripts/lib/loader.ts +4 -82
  35. package/skills/c64-source/scripts/lib/source.ts +3 -5
  36. package/skills/c64-source/scripts/source.ts +48 -51
  37. package/skills/c64-static-analysis/SKILL.md +52 -52
  38. package/skills/c64-static-analysis/scripts/lib/coverage.ts +55 -2
  39. package/skills/c64-static-analysis/scripts/lib/idioms.ts +43 -17
  40. package/skills/c64-static-analysis/scripts/static-analysis.ts +79 -15
  41. package/skills/c64-testing/SKILL.md +72 -58
  42. package/skills/c64-testing/references/recording-format.md +5 -80
  43. package/skills/c64-testing/references/scenario-format.md +4 -12
  44. package/skills/c64-testing/scripts/lib/play.ts +16 -8
  45. package/skills/c64-testing/scripts/lib/recording.ts +74 -9
  46. package/skills/c64-testing/scripts/lib/replay.ts +4 -0
  47. package/skills/c64-testing/scripts/lib/runs.ts +112 -1
  48. package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
  49. package/skills/c64-testing/scripts/lib/start-screen.ts +27 -0
  50. package/skills/c64-testing/scripts/testing.ts +34 -13
  51. package/skills/c64-unpacker/SKILL.md +10 -30
  52. package/skills/emulator/SKILL.md +7 -36
  53. package/src/build-name.ts +12 -1
  54. package/src/c64.ts +16 -0
  55. package/src/knowledge/history.ts +8 -0
  56. package/src/knowledge/program.ts +84 -4
  57. package/src/knowledge/read.ts +46 -2
  58. package/src/knowledge/recording-files.ts +32 -0
  59. package/src/knowledge/schema.ts +3 -1
  60. package/src/knowledge/separate.ts +165 -11
  61. package/src/knowledge/start-screen.ts +99 -17
  62. package/src/knowledge/text.ts +2 -1
  63. package/src/knowledge/write.ts +15 -8
  64. package/src/loader.ts +167 -0
  65. package/src/native/decompiler/analyze.ts +7 -6
  66. package/src/native/decompiler/walk.ts +32 -2
  67. package/src/native/dxa.ts +4 -4
  68. package/src/native/types.ts +34 -4
  69. package/src/script.ts +102 -25
  70. package/skills/c64-export/SKILL.md +0 -63
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.7.1",
3
+ "version": "2.8.0-rc.2",
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",
@@ -28,7 +28,7 @@ To get the command list, run the script with no arguments.
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
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` |
31
+ | Build a generated source with other switch values, and its loader program | `build src main.asm --switch TRAINER=1` |
32
32
  | Check that the rebuild is identical to the program in the project knowledge | `build src main.asm --compare` |
33
33
  | Build a release and check it against the bytes of that release | `build src main.asm --release FIRESTAR --compare` |
34
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` |
@@ -44,7 +44,7 @@ To get the command list, run the script with no arguments.
44
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`.
45
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`.
46
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.
47
+ - The script also writes the symbols file of the program. `symbolsFile.out` gives its path. Give this file to a test run as the symbols of the rebuild.
48
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.
49
49
  - Before you use `--compare`, put the program bytes into the project knowledge.
50
50
  - The target CPU is the 6510. The program is a C64 PRG, or the bytes only with `--plain`.
@@ -54,7 +54,8 @@ To get the command list, run the script with no arguments.
54
54
  A source that you generated from the project knowledge has switches in `config.asm`.
55
55
 
56
56
  - Without `--release`, the build uses the values in `config.asm`. With the default values, the program is the clean program: no copy protection, no trainers, no cheats, no crack changes, and all corrections. This program can be different from the base release. Thus `--compare` can give `FAIL`.
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`.
57
+ - To build other switch values, give `--switch` for each switch, for example `--switch TRAINER=1`. `config.asm` does not change. Do not use `--define` for a switch.
58
+ - With `--switch` and the entry `main.asm`, a source with `loader.asm` also gives its loader program with these switch values. See "Build".
58
59
  - With `--release <label>`, each switch has the value of that release. A release build does not read `config.asm`.
59
60
 
60
61
  ### Build names
@@ -64,11 +65,11 @@ Without `--out`, the name of the program tells what the build is:
64
65
  | Build | Name |
65
66
  |---|---|
66
67
  | `--release <label>` | `release_<label>.prg`, for example `release_FIRESTAR.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`. |
68
+ | Each switch value is its default | `clean.prg` |
69
+ | A switch value 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
70
  | A source without `config.asm` | the name of the entry, for example `main.prg` |
70
71
 
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
+ An entry other than `main.asm` adds its name. 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
73
 
73
74
  ### Paths and the project folder
74
75
 
@@ -80,12 +81,11 @@ An entry other than `main.asm` adds its name, for example `clean_loader.prg` for
80
81
  - A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
81
82
  - Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
82
83
  - Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
83
- - The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
84
+ - The script refuses an `--out` path in `.c64-re-tools/knowledge/`. Change the project knowledge only with the commands that change it.
84
85
  - The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
85
86
  - When a test or another file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses that evidence in that folder.
86
- - A coverage map can stay in `.c64-re-tools/local/`. The project knowledge keeps its ranges and its SHA-256.
87
- - Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
88
- - Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
87
+ - A coverage map can stay in `.c64-re-tools/local/`. Do not move a coverage map after you put it into the project knowledge.
88
+ - To keep a run as evidence, use the command that keeps a run. It copies the run, its results and its snapshot files into `runs/<name>/`, and it changes the paths in the copy. Then git keeps them, and another person can do the run again.
89
89
  - A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
90
90
 
91
91
  ---
@@ -99,6 +99,7 @@ Each flag applies only to the commands in the table. On another command, the scr
99
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
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. |
101
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. |
102
+ | `--switch NAME=VALUE` | `build` | A switch of `config.asm` with the value 0 or 1 for this build. Give the flag again for each switch. `config.asm` does not change. The script refuses it with `--release`. |
102
103
  | `--set-pc <address>` | `build` | The start address when the source does not set one, for example `'$0801'`. |
103
104
  | `--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. |
104
105
  | `--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. |
@@ -113,7 +114,7 @@ Each flag applies only to the commands in the table. On another command, the scr
113
114
 
114
115
  ### `build <source-root> <entry>`
115
116
 
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.
117
+ Assembles the source and writes the program to `--out`, or to `build/<name>.prg`. It also writes the symbols file, which `symbolsFile` gives. Without `--all-symbols`, that file does not have the constants that the source does not use.
117
118
 
118
119
  `body` holds:
119
120
 
@@ -133,18 +134,21 @@ Assembles the source and writes the program to `--out`, or to `build/<name>.prg`
133
134
  - `identical`.
134
135
  - `different`, with `differences` and `firstDifference`. `firstDifference` gives `address`, and the byte of the build (`built`) and of the reference (`reference`), each as `$` and two hex digits.
135
136
  - `not covered`, with `uncovered`: the build does not hold all bytes of the segment.
137
+ - `loader`: only with `--switch`, the entry `main.asm` and a `loader.asm` in the source root. It is the loader program of these switch values, with `out`, `bytes` and `sha256`. `symbolsFile` is its symbols file. `packed` gives `packedBytes` and `unpackedBytes` of the packed form. `verified` is always `false`, because no check of the loader program runs. When the script cannot make the loader program, `loader` holds only `written`, which is `false`, and `reason`.
136
138
 
137
139
  Do as the result tells:
138
140
 
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.
141
+ - `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: `loader.program` of the generation of the source with the loader, or `loader.out` of a build with `--switch`. Test the loader program of `loader.out` before you trust it.
140
142
  - `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.
141
143
  - `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.
142
144
  - `hint` tells that `symbols` is cut: give a larger `--max-listed`, or read the symbols file for the full list.
145
+ - `loader.written` is `false`: the script wrote the program of `main.asm`, but it cannot make the loader program of these switch values. Do as `loader.reason` tells.
143
146
  - Error `not-found` names the entry: give the main source file relative to the source root.
144
147
  - Error `not-found` names an include folder: give `--include` a folder with files, relative to the source root.
145
148
  - Error `invalid-input` names an include folder: the folder is outside the project folder. Give `--include` a folder inside the project folder.
146
149
  - Error `not-found` names a release: the project knowledge has no release with that label. Record the release in the project knowledge, or give the label of a recorded release.
147
150
  - Error `not-found` tells that the knowledge has no program: put the program bytes into the project knowledge. Then use `--compare` again.
151
+ - Error `invalid-input` names a switch: give `--switch` a switch of `config.asm`, with the value 0 or 1.
148
152
  - Error `invalid-input`: an option or a path is wrong. Do as `hint` tells. The script refuses `--space` without `--compare` or `--release`.
149
153
 
150
154
  The script does not keep the diagnostics or the program in the project knowledge.
@@ -167,24 +171,15 @@ To compare runs of the rebuild with runs of the reference, give the symbols file
167
171
 
168
172
  Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
169
173
 
170
- On success, the exit code is 0:
171
-
172
- ```json
173
- {"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
174
- ```
175
-
176
- On failure, the exit code is 2:
177
-
178
- ```json
179
- {"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
180
- ```
181
-
174
+ - On success, the exit code is 0: `{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}`
175
+ - On failure, the exit code is 2: `{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}`
182
176
  - `body` holds the result. The section of each command gives the fields of its body.
183
177
  - A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
184
- - `error` is one sentence. It tells what is wrong.
185
- - `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
186
- - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
187
- - `code` does not change between versions. Do the action for the code:
178
+ - `error` is one sentence. It tells what is wrong. `hint` tells what to do or what to examine. Read it before your next step.
179
+ - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task.
180
+ - A list has `count`, `listed` and `rest`. `listed` holds at most `--max-listed` items. `rest` tells how to get the other items. A file that the command wrote has `out`, `bytes` and `sha256`.
181
+ - To get only some fields of `body`, give `--fields <path>,<path>`, for example `--fields count,listed.start`. A path through a list gives that field of each item. Do not write code to filter an envelope.
182
+ - To get the command list, run the script with no arguments. To get the subjects and the flags of one command, run `<command> --help`.
188
183
 
189
184
  | `code` | Action |
190
185
  |---|---|
@@ -192,13 +187,3 @@ On failure, the exit code is 2:
192
187
  | `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
193
188
  | `operation-failed` | Give `error` and `hint` to the user. |
194
189
  | Another code | Do as `hint` tells. |
195
-
196
- These fields have the same meaning in each body:
197
-
198
- | Field | Meaning |
199
- |---|---|
200
- | `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
201
- | `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
202
-
203
- To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
204
- To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
@@ -1,21 +1,36 @@
1
1
  // The c64-assembler script: assembles project source with ACME, which it runs
2
- // itself, and writes the program into the project.
2
+ // itself, and writes the program into the project. With --switch, a generated
3
+ // source gets other switch values: the script changes them in its copy of
4
+ // config.asm, so the file stays as it is, and the build name follows from the
5
+ // values. A generated source with loader.asm then also gets its loader
6
+ // program with the same values: the build of loader.asm in the plain form,
7
+ // and in the packed form the pack of the build of main.asm with the build of
8
+ // loader.asm, the copier, as generate packs it. No check of that loader runs.
9
+ // When the knowledge or the builds do not permit the pack, the build writes
10
+ // the program of main.asm and no loader program, and tells why.
3
11
 
4
- import { BUILD_DIRECTORY, type BuildKind, buildName, CONFIG_FILE, configValues, symbolsPath } from "#src/build-name.ts";
5
- import { formatC64Address } from "#src/c64.ts";
6
- import { Refusal } from "#src/errors.ts";
12
+ import { posix } from "node:path";
13
+
14
+ import { BUILD_DIRECTORY, type BuildKind, buildName, CONFIG_FILE, configValues, COPIER_LINE, symbolsPath, withConfigValues } from "#src/build-name.ts";
15
+ import { type AddressRange, formatC64Address } from "#src/c64.ts";
16
+ import { isRefusal, Refusal } from "#src/errors.ts";
7
17
  import { readSourceTree, writeReported } from "#src/host-client/transfer.ts";
8
18
  import { openForRead } from "#src/knowledge/database.ts";
9
19
  import { knowledgeNames } from "#src/knowledge/names.ts";
10
20
  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";
21
+ import { currentStartScreen, listSwitches, releaseLabeled } from "#src/knowledge/read.ts";
22
+ import { LEFTOVER_FOLDER, LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
23
+ import { checkPackedBuilds, COPIER_SOURCE, leftoverRange, loaderSymbols, packedRanges, packLoader, type PackedLoader } from "#src/loader.ts";
13
24
  import { assemble, showSymbol, symbolsFileText } from "#src/native/acme.ts";
25
+ import { EXOMIZER, findTool } from "#src/native/discover.ts";
14
26
  import { localToolContext } from "#src/native/local.ts";
15
27
  import type { AcmeParams, AssembledSymbol } from "#src/native/types.ts";
16
28
  import { listed as listedItems, OPTIONS, reply, runScript, UsageError } from "#src/script.ts";
17
29
  import { compareBuild, type Reference } from "#src/compare.ts";
18
30
 
31
+ /** The loader of a generated source, which a build of main.asm with --switch also makes. */
32
+ const LOADER_FILE = "loader.asm";
33
+
19
34
  function parseDefine(text: string): [string, number | boolean] {
20
35
  const match = /^([A-Za-z_][A-Za-z0-9_]*)=(.+)$/.exec(text);
21
36
  if (match === null) throw new UsageError(`--define needs NAME=VALUE, not ${text}`);
@@ -26,6 +41,18 @@ function parseDefine(text: string): [string, number | boolean] {
26
41
  throw new UsageError(`--define ${match[1]} needs an integer or true/false, not ${value}`);
27
42
  }
28
43
 
44
+ /** The values of --switch, by name: each is 0 or 1, and each name comes once. */
45
+ function parseSwitches(texts: readonly string[]): Map<string, 0 | 1> {
46
+ const values = new Map<string, 0 | 1>();
47
+ for (const text of texts) {
48
+ const match = /^([A-Za-z_][A-Za-z0-9_]*)=([01])$/.exec(text);
49
+ if (match === null) throw new UsageError(`--switch needs NAME=0 or NAME=1, not ${text}`);
50
+ if (values.has(match[1]!)) throw new UsageError(`--switch gives ${match[1]} two times. Give each switch one time.`);
51
+ values.set(match[1]!, match[2] === "1" ? 1 : 0);
52
+ }
53
+ return values;
54
+ }
55
+
29
56
  /** The default of each switch of a generated source: the knowledge gives them, the start screen is in and the leftovers are out. */
30
57
  function switchDefaults(space: Space): Map<string, number> {
31
58
  const db = openForRead();
@@ -36,6 +63,27 @@ function switchDefaults(space: Space): Map<string, number> {
36
63
  }
37
64
  }
38
65
 
66
+ /** What the packed form needs from the knowledge of the space: the loaded ranges. Refuses a start screen of a captured stage and a segment below $0400. */
67
+ function packedLoaded(leftovers: readonly AddressRange[], space: Space): AddressRange[] {
68
+ const db = openForRead();
69
+ try {
70
+ return packedRanges(requireProgram(db, space).segments, leftovers, currentStartScreen(db, space)?.stage);
71
+ } finally {
72
+ db?.close();
73
+ }
74
+ }
75
+
76
+ /** The message of a refusal of `work`, or undefined when it did not refuse: a refusal of the loader program does not stop the build of main.asm. */
77
+ function refusalOf(work: () => void): string | undefined {
78
+ try {
79
+ work();
80
+ return undefined;
81
+ } catch (error) {
82
+ if (isRefusal(error)) return error.message;
83
+ throw error;
84
+ }
85
+ }
86
+
39
87
  await runScript({
40
88
  name: "assembler",
41
89
  summary: "Assembles project source with ACME and writes the program into the project.",
@@ -49,9 +97,10 @@ await runScript({
49
97
  { name: "<entry>", help: "the main source file, relative to the source root" },
50
98
  ],
51
99
  options: {
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" },
100
+ 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 the switch values, with _<entry> for an entry other than main.asm" },
53
101
  include: { kind: "text", value: "<folder>", multiple: true, help: "an include folder: a path relative to the source root, inside the project folder" },
54
- define: { kind: "text", value: "NAME=VALUE", multiple: true, help: "an assembler symbol: an integer ($hex allowed) or true/false" },
102
+ define: { kind: "text", value: "NAME=VALUE", multiple: true, help: "an assembler symbol: an integer ($hex allowed) or true/false. Not for a switch of config.asm: give --switch" },
103
+ switch: { kind: "text", value: "NAME=VALUE", multiple: true, help: "a switch of config.asm with the value 0 or 1 for this build. config.asm stays as it is. With main.asm and a loader.asm, the build also writes the loader program with these values" },
55
104
  "set-pc": { kind: "address", value: "<address>", help: "the start address when the source sets none, for example '$0801'" },
56
105
  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` },
57
106
  compare: { kind: "flag", help: "check the program byte by byte against the program in the knowledge (or the file of --release), each segment" },
@@ -60,13 +109,16 @@ await runScript({
60
109
  "all-symbols": { kind: "flag", help: "list also the constants that the source does not use" },
61
110
  "max-listed": { ...OPTIONS["max-listed"], help: "list at most n symbols (default 50). The count is always given" },
62
111
  },
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.",
112
+ notes:
113
+ "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 and of --switch. 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. Give a switch with --switch, not with --define: ACME stops with Symbol already defined. The loader program of --switch is not checked: loader.verified is false.",
64
114
  run: async (call) => {
65
115
  const [sourceRoot, entry] = [call.subject(0), call.subject(1)];
66
116
  // Read the reference before ACME runs, so a project without it stops at once.
67
117
  let program: Reference | undefined;
68
118
  const label = call.string("release");
119
+ const switches = parseSwitches(call.strings("switch"));
69
120
  if (call.string("space") !== undefined && !call.flag("compare") && label === undefined) throw new UsageError("--space works only with --compare or --release: it names the knowledge space of the program");
121
+ if (switches.size > 0 && label !== undefined) throw new UsageError("--switch does not work with --release: a release build has the switch values of that release");
70
122
  let releaseDefine: Record<string, number> = {};
71
123
  if (call.flag("compare") || label !== undefined) {
72
124
  const db = openForRead();
@@ -85,29 +137,86 @@ await runScript({
85
137
  const setPc = call.address("set-pc");
86
138
  const { contents, ...tree } = readSourceTree(sourceRoot, call.strings("include"));
87
139
  const inSource = (name: string) => tree.files.findIndex((file) => file.path === (tree.sourceDir === "" ? name : `${tree.sourceDir}/${name}`));
140
+ const textOf = (index: number) => contents[index]!.toString("utf8");
88
141
  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
142
  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) };
143
+ if (switches.size > 0) {
144
+ // ACME refuses a define of a symbol that config.asm sets: the values go into the copy of config.asm that ACME gets.
145
+ if (config < 0) throw new Refusal("invalid-input", `${sourceRoot} has no ${CONFIG_FILE}, so the source has no switches. Give --switch only for a generated source with switches.`);
146
+ const known = configValues(textOf(config));
147
+ const unknown = [...switches.keys()].filter((name) => !known.has(name));
148
+ if (unknown.length > 0) throw new Refusal("invalid-input", `${unknown.join(", ")} ${unknown.length === 1 ? "is not a switch" : "are not switches"} of ${CONFIG_FILE}. Give a switch of ${CONFIG_FILE}: ${[...known.keys()].join(", ")}.`);
149
+ const changed = Buffer.from(withConfigValues(textOf(config), switches), "utf8");
150
+ contents[config] = changed;
151
+ tree.files[config] = { ...tree.files[config]!, size: changed.length };
152
+ }
153
+ // The name of the build tells what it is: the release, or the switch values.
154
+ const kind: BuildKind | undefined = label !== undefined ? { release: label } : config < 0 ? undefined : { values: configValues(textOf(config)), defaults: switchDefaults(call.space) };
92
155
  const plain = call.flag("plain");
93
- const out = call.string("out") ?? `${BUILD_DIRECTORY}/${buildName(entry, kind, contents[inSource(entry)]!.toString("utf8"))}.${plain ? "bin" : "prg"}`;
156
+ const out = call.string("out") ?? `${BUILD_DIRECTORY}/${buildName(entry, kind, textOf(inSource(entry)))}.${plain ? "bin" : "prg"}`;
94
157
  const params: AcmeParams = { ...tree, entrySource: entry, defines: { ...releaseDefine, ...Object.fromEntries(call.strings("define").map(parseDefine)) }, ...(setPc === undefined ? {} : { setPc }) };
95
158
 
159
+ // With --switch, main.asm of a generated source with a loader also gives the loader program of these values.
160
+ const loaderIndex = switches.size > 0 && entry === "main.asm" ? inSource(LOADER_FILE) : -1;
161
+ let loaded: AddressRange[] | undefined;
162
+ // Why the build writes no loader program.
163
+ let noLoader: string | undefined;
164
+ if (loaderIndex >= 0 && textOf(loaderIndex).split(/\r?\n/).includes(COPIER_LINE)) {
165
+ // The packed form: the loaded ranges are the segments of the program without the leftover files of the source.
166
+ const folder = posix.join(tree.sourceDir, LEFTOVER_FOLDER);
167
+ const leftovers = tree.files.flatMap((file, index) => (posix.dirname(file.path) === folder ? (leftoverRange(textOf(index)) ?? []) : []));
168
+ noLoader = refusalOf(() => {
169
+ loaded = packedLoaded(leftovers, call.space);
170
+ });
171
+ // The toolkit never installs a tool: without Exomizer the build refuses by name before ACME runs.
172
+ if (noLoader === undefined) findTool(EXOMIZER);
173
+ }
174
+
96
175
  const { result, attachments } = await assemble(params, contents, localToolContext());
97
176
  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." });
98
- const written = writeReported(out, plain ? attachments![0]!.subarray(2) : attachments![0]!, { what: "--out" });
99
- const range = result.loadRange!;
100
- const compared = program === undefined ? undefined : compareBuild(attachments![0]!, program);
177
+ const built = attachments![0]!;
101
178
  // An include file of platform names gives many constants that the program does not use.
102
179
  const all = call.flag("all-symbols");
103
- const shown = result.symbols!.filter((symbol) => all || symbol.kind === "address" || symbol.used);
180
+ const shownOf = (symbols: readonly AssembledSymbol[]) => symbols.filter((symbol) => all || symbol.kind === "address" || symbol.used);
181
+ const shown = shownOf(result.symbols!);
182
+
183
+ // The loader is made before a file is written: a refusal writes nothing.
184
+ let loader: { program: Buffer; symbols: AssembledSymbol[]; packed?: PackedLoader } | undefined;
185
+ if (loaderIndex >= 0 && noLoader === undefined) {
186
+ const copier = await assemble({ ...params, entrySource: LOADER_FILE }, contents, localToolContext());
187
+ if (!copier.result.assembled) {
188
+ const [first] = copier.result.diagnostics;
189
+ const where = first === undefined ? "" : `: ${first.file ?? LOADER_FILE}${first.line === undefined ? "" : ` line ${first.line}`}: ${first.message}`;
190
+ throw new Refusal("operation-failed", `${LOADER_FILE} does not assemble with these switch values${where}. Generate the source with the loader again. If it still does not assemble, give this message to the user.`);
191
+ }
192
+ const copierBuild = copier.attachments![0]!;
193
+ const symbols = loaderSymbols(result.symbols!, copier.result.symbols!);
194
+ if (loaded === undefined) loader = { program: copierBuild, symbols };
195
+ else {
196
+ const at = copier.result.symbols!.find((symbol) => symbol.name === COPIER_SOURCE);
197
+ if (at?.kind !== "address") throw new Refusal("invalid-input", `${LOADER_FILE} has no label ${COPIER_SOURCE} at its copier. Generate the source with the loader again.`);
198
+ const packedFrom = loaded;
199
+ noLoader = refusalOf(() => checkPackedBuilds(built, copierBuild, packedFrom));
200
+ if (noLoader === undefined) {
201
+ const packed = await packLoader(built, copierBuild, { loaded: packedFrom, copier: at.address }, localToolContext());
202
+ loader = { program: packed.program, symbols, packed };
203
+ }
204
+ }
205
+ }
206
+
207
+ const written = writeReported(out, plain ? built.subarray(2) : built, { what: "--out" });
208
+ const range = result.loadRange!;
209
+ const compared = program === undefined ? undefined : compareBuild(built, program);
104
210
  const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, `a larger --max-listed, or read ${symbolsPath(out)}`);
105
211
  // A build that differs from its reference is a failed check.
106
212
  const different = compared !== undefined && !compared.identical;
213
+ const loaderPath = `${BUILD_DIRECTORY}/${buildName(LOADER_FILE, kind)}.prg`;
107
214
  const hints = [
108
215
  ...(different ? ["The program is not identical to the reference program. Read compare.segments: each segment that is different gives its first difference."] : []),
109
- ...(different && label === undefined ? ["Without --release, a source with switches builds with the values of config.asm, and that program can differ from the base release. To check a release, give --release <label> with --compare."] : []),
216
+ ...(different && label === undefined ? ["Without --release, a source with switches builds with the values of config.asm and --switch, and that program can differ from the base release. To check a release, give --release <label> with --compare."] : []),
110
217
  ...(symbols.rest === undefined ? [] : [`symbols is cut. To get all symbols, give ${symbols.rest}.`]),
218
+ ...(loader === undefined ? [] : ["loader.out is the loader program of these switch values. No check of the loader program ran, so loader.verified is false."]),
219
+ ...(noLoader === undefined ? [] : ["The build wrote the program of main.asm, but no loader program of these switch values: loader.reason tells why."]),
111
220
  ];
112
221
  return reply({
113
222
  result: different ? "FAIL" : "PASS",
@@ -121,6 +230,17 @@ await runScript({
121
230
  ...(all ? {} : { unusedConstants: result.symbols!.length - shown.length }),
122
231
  diagnostics: result.diagnostics,
123
232
  ...(compared === undefined ? {} : { compare: compared }),
233
+ ...(noLoader !== undefined ? { loader: { written: false, reason: noLoader } } : {}),
234
+ ...(loader === undefined
235
+ ? {}
236
+ : {
237
+ loader: {
238
+ ...writeReported(loaderPath, loader.program),
239
+ symbolsFile: writeReported(symbolsPath(loaderPath), symbolsFileText(shownOf(loader.symbols))),
240
+ ...(loader.packed === undefined ? {} : { packed: { packedBytes: loader.packed.packedBytes, unpackedBytes: loader.packed.unpackedBytes } }),
241
+ verified: false,
242
+ },
243
+ }),
124
244
  }, hints.length === 0 ? {} : { hint: hints.join(" ") });
125
245
  },
126
246
  },
@@ -41,12 +41,11 @@ To get the command list, run the script with no arguments.
41
41
  - A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
42
42
  - Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
43
43
  - Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
44
- - The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
44
+ - The script refuses an `--out` path in `.c64-re-tools/knowledge/`. Change the project knowledge only with the commands that change it.
45
45
  - The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
46
46
  - When a test or another file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses that evidence in that folder.
47
- - A coverage map can stay in `.c64-re-tools/local/`. The project knowledge keeps its ranges and its SHA-256.
48
- - Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
49
- - Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
47
+ - A coverage map can stay in `.c64-re-tools/local/`. Do not move a coverage map after you put it into the project knowledge.
48
+ - To keep a run as evidence, use the command that keeps a run. It copies the run, its results and its snapshot files into `runs/<name>/`, and it changes the paths in the copy. Then git keeps them, and another person can do the run again.
50
49
  - A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
51
50
 
52
51
  ## Decode a program
@@ -61,6 +60,7 @@ To get the command list, run the script with no arguments.
61
60
  - A handoff with `computed: true` gets its address from a calculation at run time, for example with `PEEK`. A `sys` handoff of this type gives its argument in `expression`.
62
61
  - `loadRange`: the `start` and the `end` of the program in memory.
63
62
  - `basicEnd`: the first address after the BASIC, or `null`. From `basicEnd` to the end of `loadRange`, the file holds bytes that are not BASIC. Usually these bytes are the machine code that the handoff calls.
63
+ - `machineCode`: only when the file has bytes after the BASIC. `start` and `end` are their addresses. `fileOffset` is the position of the first byte in the file, after the 2 bytes of the load address.
64
64
 
65
65
  The addresses are for a load to the load address of the file. A load without `,1` puts a BASIC program at `$0801`. Most loaders have `$0801` as their load address.
66
66
 
@@ -85,24 +85,15 @@ Failure:
85
85
 
86
86
  Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
87
87
 
88
- On success, the exit code is 0:
89
-
90
- ```json
91
- {"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
92
- ```
93
-
94
- On failure, the exit code is 2:
95
-
96
- ```json
97
- {"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
98
- ```
99
-
88
+ - On success, the exit code is 0: `{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}`
89
+ - On failure, the exit code is 2: `{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}`
100
90
  - `body` holds the result. The section of each command gives the fields of its body.
101
91
  - A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
102
- - `error` is one sentence. It tells what is wrong.
103
- - `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
104
- - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
105
- - `code` does not change between versions. Do the action for the code:
92
+ - `error` is one sentence. It tells what is wrong. `hint` tells what to do or what to examine. Read it before your next step.
93
+ - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task.
94
+ - A list has `count`, `listed` and `rest`. `listed` holds at most `--max-listed` items. `rest` tells how to get the other items. A file that the command wrote has `out`, `bytes` and `sha256`.
95
+ - To get only some fields of `body`, give `--fields <path>,<path>`, for example `--fields count,listed.start`. A path through a list gives that field of each item. Do not write code to filter an envelope.
96
+ - To get the command list, run the script with no arguments. To get the subjects and the flags of one command, run `<command> --help`.
106
97
 
107
98
  | `code` | Action |
108
99
  |---|---|
@@ -110,14 +101,3 @@ On failure, the exit code is 2:
110
101
  | `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
111
102
  | `operation-failed` | Give `error` and `hint` to the user. |
112
103
  | Another code | Do as `hint` tells. |
113
-
114
- These fields have the same meaning in each body:
115
-
116
- | Field | Meaning |
117
- |---|---|
118
- | `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
119
- | `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
120
-
121
- To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
122
- To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
123
-
@@ -25,10 +25,13 @@ await runScript({
25
25
  const size = statSync(resolveProjectPath(program)).size - 2;
26
26
  const end = result.loadAddress + size - 1;
27
27
  const handoffs = result.handoffs.map((handoff) => ("address" in handoff ? { ...handoff, address: formatC64Address(handoff.address) } : handoff));
28
+ const after = result.basicEnd <= end;
28
29
  const body = {
29
30
  loadRange: { start: formatC64Address(result.loadAddress), end: formatC64Address(end) },
30
31
  // From here to the end of the load range, the file holds no BASIC (often machine code).
31
- basicEnd: result.basicEnd <= end ? formatC64Address(result.basicEnd) : null,
32
+ basicEnd: after ? formatC64Address(result.basicEnd) : null,
33
+ // The same bytes in the file: 2 bytes of load address come before the program.
34
+ ...(after ? { machineCode: { start: formatC64Address(result.basicEnd), end: formatC64Address(end), fileOffset: result.basicEnd - result.loadAddress + 2 } } : {}),
32
35
  listing: result.listing,
33
36
  handoffs,
34
37
  };
@@ -68,9 +68,9 @@ Do these steps for each small part of the program:
68
68
 
69
69
  1. Find the meaning of each register in the memory map of the C64. Export the platform names as an include file to `src/hw.a`. Include it with `!source`. Do not type the addresses of registers yourself.
70
70
  2. Write the code for one part.
71
- 3. Assemble `src/main.a` into `build/<name>.prg`, with the symbols in `build/<name>.json`. Change the source at the file and the line of each error.
71
+ 3. Assemble `src/main.a` into `build/<name>.prg`. Change the source at the file and the line of each error.
72
72
  4. Start the program in the emulator with an autostart. Look at the screen. Read the screen memory, not only the screen image.
73
- 5. Write the `expect` steps of this part in a run file. Give the symbol file `build/<name>.json` in the run file, so that a step can use the labels of the source.
73
+ 5. Write the `expect` steps of this part in a run file. Give the symbols file of the build in the run file, so that a step can use the labels of the source. The result of the build gives the symbols file.
74
74
  6. Run all run files in `tests/`. Go to the next part only when each run gives PASS.
75
75
 
76
76
  To find a defect, debug the program in the emulator:
@@ -67,12 +67,11 @@ To get the command list, run the script with no arguments.
67
67
  - A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
68
68
  - Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
69
69
  - Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
70
- - The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
70
+ - The script refuses an `--out` path in `.c64-re-tools/knowledge/`. Change the project knowledge only with the commands that change it.
71
71
  - The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
72
72
  - When a test or another file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses that evidence in that folder.
73
- - A coverage map can stay in `.c64-re-tools/local/`. The project knowledge keeps its ranges and its SHA-256.
74
- - Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
75
- - Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
73
+ - A coverage map can stay in `.c64-re-tools/local/`. Do not move a coverage map after you put it into the project knowledge.
74
+ - To keep a run as evidence, use the command that keeps a run. It copies the run, its results and its snapshot files into `runs/<name>/`, and it changes the paths in the copy. Then git keeps them, and another person can do the run again.
76
75
  - A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
77
76
 
78
77
  ## Flags
@@ -93,7 +92,7 @@ Each flag applies only to the commands in the table. On another command, the scr
93
92
 
94
93
  For a disk image, `body` holds `diskName`, `diskId`, `dosType`, `freeBlocks` and `entries`. Each entry has `name`, `type`, `blocks`, `closed` and `locked`.
95
94
 
96
- For a tape file, `body` holds `name` and `entries`. Each entry has `name`, `start`, `end` and `bytes`. Many T64 files have a wrong end address. Then the entry has `fixedSize: true`, and the size comes from the position of the next file.
95
+ For a tape file, `body` holds `name` and `entries`. Each entry has `name`, `start`, `end` and `bytes`. Many T64 files have a wrong end address. Then the entry has `fixedSize: true`, and the script gives the correct `end` and `bytes`.
97
96
 
98
97
  For a cartridge file, `body` holds the header and `chips`. The header is `name`, `type`, `typeName`, `exrom`, `game`, and `mode` for type 0. Each chip has `bank`, `address`, `size` and `space`.
99
98
 
@@ -161,24 +160,15 @@ All banks use the same addresses. Thus `hint` tells you to analyze each bank PRG
161
160
 
162
161
  Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
163
162
 
164
- On success, the exit code is 0:
165
-
166
- ```json
167
- {"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
168
- ```
169
-
170
- On failure, the exit code is 2:
171
-
172
- ```json
173
- {"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
174
- ```
175
-
163
+ - On success, the exit code is 0: `{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}`
164
+ - On failure, the exit code is 2: `{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}`
176
165
  - `body` holds the result. The section of each command gives the fields of its body.
177
166
  - A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
178
- - `error` is one sentence. It tells what is wrong.
179
- - `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
180
- - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
181
- - `code` does not change between versions. Do the action for the code:
167
+ - `error` is one sentence. It tells what is wrong. `hint` tells what to do or what to examine. Read it before your next step.
168
+ - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task.
169
+ - A list has `count`, `listed` and `rest`. `listed` holds at most `--max-listed` items. `rest` tells how to get the other items. A file that the command wrote has `out`, `bytes` and `sha256`.
170
+ - To get only some fields of `body`, give `--fields <path>,<path>`, for example `--fields count,listed.start`. A path through a list gives that field of each item. Do not write code to filter an envelope.
171
+ - To get the command list, run the script with no arguments. To get the subjects and the flags of one command, run `<command> --help`.
182
172
 
183
173
  | `code` | Action |
184
174
  |---|---|
@@ -186,14 +176,3 @@ On failure, the exit code is 2:
186
176
  | `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
187
177
  | `operation-failed` | Give `error` and `hint` to the user. |
188
178
  | Another code | Do as `hint` tells. |
189
-
190
- These fields have the same meaning in each body:
191
-
192
- | Field | Meaning |
193
- |---|---|
194
- | `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
195
- | `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
196
-
197
- To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
198
- To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
199
-