@henols/c64-re-tools 2.3.0-rc.5 → 2.3.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +149 -78
- package/skills/c64-assembler/scripts/assembler.ts +18 -11
- package/skills/c64-basic/SKILL.md +90 -52
- package/skills/c64-basic/scripts/basic.ts +15 -6
- package/skills/c64-development/SKILL.md +46 -73
- package/skills/c64-disk/SKILL.md +145 -73
- package/skills/c64-disk/scripts/disk.ts +11 -6
- package/skills/c64-docs/SKILL.md +199 -118
- package/skills/c64-docs/references/page-types.md +3 -3
- package/skills/c64-docs/references/style.md +9 -13
- package/skills/c64-docs/scripts/docs.ts +39 -15
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +2 -2
- package/skills/c64-docs/scripts/lib/source-map.ts +2 -2
- package/skills/c64-export/SKILL.md +21 -45
- package/skills/c64-knowledge/SKILL.md +489 -233
- package/skills/c64-knowledge/scripts/knowledge.ts +31 -26
- package/skills/c64-memory-map/SKILL.md +131 -65
- package/skills/c64-memory-map/scripts/memory-map.ts +19 -11
- package/skills/c64-packer/SKILL.md +120 -72
- package/skills/c64-packer/scripts/packer.ts +10 -3
- package/skills/c64-provenance/SKILL.md +301 -173
- package/skills/c64-provenance/scripts/lib/library.ts +6 -6
- package/skills/c64-provenance/scripts/provenance.ts +85 -36
- package/skills/c64-reverse-engineering/SKILL.md +55 -72
- package/skills/c64-source/SKILL.md +316 -224
- package/skills/c64-source/scripts/lib/export.ts +9 -14
- package/skills/c64-source/scripts/lib/loader.ts +5 -5
- package/skills/c64-source/scripts/lib/source.ts +5 -5
- package/skills/c64-source/scripts/source.ts +106 -21
- package/skills/c64-static-analysis/SKILL.md +188 -112
- package/skills/c64-static-analysis/scripts/static-analysis.ts +29 -9
- package/skills/c64-testing/SKILL.md +272 -166
- package/skills/c64-testing/references/recording-format.md +11 -12
- package/skills/c64-testing/references/scenario-format.md +20 -5
- package/skills/c64-testing/scripts/lib/diff-files.ts +8 -8
- package/skills/c64-testing/scripts/lib/recording.ts +7 -7
- package/skills/c64-testing/scripts/lib/replay.ts +7 -7
- package/skills/c64-testing/scripts/lib/runs.ts +6 -7
- package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
- package/skills/c64-testing/scripts/testing.ts +35 -15
- package/skills/c64-unpacker/SKILL.md +273 -127
- package/skills/c64-unpacker/scripts/lib/loads.ts +3 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +70 -11
- package/skills/emulator/SKILL.md +12 -12
- package/src/errors.ts +22 -2
- package/src/host/vice/session.ts +1 -1
- package/src/host-client/entry-state.ts +1 -1
- package/src/host-client/image.ts +3 -3
- package/src/host-client/steps.ts +1 -1
- package/src/knowledge/expression.ts +1 -1
- package/src/knowledge/names.ts +2 -3
- package/src/knowledge/program.ts +2 -3
- package/src/knowledge/write.ts +2 -2
- package/src/mcp/inputs.ts +1 -1
- package/src/mcp/tools/input.ts +1 -1
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/exomizer.ts +2 -2
- package/src/project.ts +2 -2
- package/src/script.ts +164 -75
package/package.json
CHANGED
|
@@ -1,113 +1,184 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-assembler
|
|
3
|
-
description:
|
|
3
|
+
description: Assembles C64 6510 source code with the ACME assembler and writes the program (PRG) into the project. It gives the source errors with their file and line, and the symbols with their addresses or values. Use it to build a rebuilt program or a new program. Use it to check that a rebuild is identical to the program in the project knowledge or to the file of a release. It does not run the program, and it does not change the project knowledge.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# C64 assembler
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use this script to assemble C64 source code with ACME and to write the program into the project.
|
|
9
|
+
Use only the commands of the script. Do not assemble the source in another way.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
```bash
|
|
12
|
+
node <skill>/scripts/assembler.ts <command>
|
|
13
|
+
```
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
`<skill>` is the base directory of this skill. Run the script with `node`. You can run it from any directory.
|
|
16
|
+
Each command in this skill, for example `build src main.a --out build/game.prg`, goes in the place of `<command>`.
|
|
17
|
+
Each command prints one JSON envelope on stdout. See the section "JSON output".
|
|
18
|
+
To get the command list, run the script with no arguments.
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
---
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
- The entry source: the main file, relative to the source root.
|
|
18
|
-
- The output path: where to write the PRG, relative to the project folder.
|
|
19
|
-
- Optional include directories, symbol definitions and a start address.
|
|
22
|
+
## Select the command
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
| Goal | Command |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Build the program from the source | `build src main.a --out build/game.prg` |
|
|
27
|
+
| Build a source that includes files from a folder | `build src main.a --out build/game.prg --include lib` |
|
|
28
|
+
| Build a source that sets no start address | `build src main.a --out build/game.prg --set-pc '$0801'` |
|
|
29
|
+
| Check that the rebuild is identical to the program in the project knowledge | `build src main.asm --out build/game.prg --compare` |
|
|
30
|
+
| Build a release and check it against the file of that release | `build src main.asm --out build/original.prg --release ORIGINAL --compare` |
|
|
31
|
+
| Check the rebuild of a program in another space, for example the drive | `build src main.asm --out build/drive.prg --compare --space drive8` |
|
|
32
|
+
| 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` |
|
|
33
|
+
| 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` |
|
|
34
|
+
| Write only the bytes of the program, without the load address | `build src main.a --out build/game.bin --plain` |
|
|
22
35
|
|
|
23
|
-
|
|
24
|
-
node <skill>/scripts/assembler.ts build src main.a --out build/game.prg
|
|
25
|
-
```
|
|
36
|
+
---
|
|
26
37
|
|
|
27
|
-
|
|
28
|
-
|---|---|
|
|
29
|
-
| `--include lib` | An include directory, relative to the source root. Use it again for more directories. |
|
|
30
|
-
| `--define DEBUG=1` | An assembler symbol: an integer, also as `$` hex, or `true` or `false`. Use it again for more symbols. |
|
|
31
|
-
| `--set-pc '$0801'` | The start address when the source does not set one. |
|
|
32
|
-
| `--release ORIGINAL` | Build a release of the knowledge. The script defines `RELEASE_ORIGINAL=1`, so each switch has the value of that release. With `--compare`, the script compares with the file of the release. A release build does not read `config.asm`. |
|
|
33
|
-
| `--compare` | Check the program byte by byte against the program in the knowledge, each segment. Put it in with `image` of the c64-knowledge skill. `--space drive8` or `--space bank0` compares with the program of that space. The script refuses `--space` without `--compare` or `--release`. |
|
|
34
|
-
| `--plain` | Write only the bytes of the program, without the 2-byte load address of a PRG. `loadRange` still tells where the bytes go. |
|
|
35
|
-
| `--all-symbols` | List all symbols. Without it, the list does not include the constants that the source does not use. `unusedConstants` gives their count. |
|
|
36
|
-
| `--max-listed 200` | Show at most 200 symbols in the result. The default is 50. `symbols.count` gives the count of all symbols. |
|
|
37
|
-
| `--out-symbols build/game.json` | Write the symbols to this file as `{"symbols": [...]}`. Without `--all-symbols`, the file does not have the constants that the source does not use. Give this file to the c64-testing skill as the symbols of the rebuild. |
|
|
38
|
+
## The source and the program
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
- `<source-root>` is the folder in the project that holds all the source files of the program. Put each file that the program includes under the source root. The script cannot read a file outside it.
|
|
41
|
+
- `<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`.
|
|
42
|
+
- For a source that you generated from the project knowledge, the source root is the folder of that source. The entry is `main.asm`.
|
|
43
|
+
- `--out` is the path of the program, relative to the project folder.
|
|
44
|
+
- Get the label of a release from the releases in the project knowledge. Record a release in the project knowledge before you build it.
|
|
45
|
+
- Before you use `--compare`, put the program bytes into the project knowledge.
|
|
46
|
+
- The target CPU is the 6510. The program is a C64 PRG, or the bytes only with `--plain`.
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
### Switches
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
A source that you generated from the project knowledge has switches in `config.asm`.
|
|
44
51
|
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
49
|
-
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
50
|
-
- The script examines each `--out` path before it starts work. It refuses a path in `.c64-re-tools/knowledge/` and the index of the knowledge, because only c64-knowledge writes them. It refuses a folder where the command writes a file, and a file where the command writes a folder.
|
|
51
|
-
- The result is one JSON object on one line. A file that the script writes shows as `{"out", "bytes", "sha256"}`. A list shows as `{"count", "listed"}`, and `rest` tells where to get the rest of a long list.
|
|
52
|
-
- An error is `{"error": {"code": "...", "message": "..."}}`. The message tells what is wrong and what to do.
|
|
53
|
-
- The exit status is 0 for done or PASS, 1 for FAIL, 2 for an error and 3 for INCONCLUSIVE.
|
|
52
|
+
- 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`.
|
|
53
|
+
- 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`.
|
|
54
|
+
- With `--release <label>`, each switch has the value of that release. A release build does not read `config.asm`.
|
|
54
55
|
|
|
55
|
-
###
|
|
56
|
+
### Paths and the project folder
|
|
56
57
|
|
|
57
|
-
-
|
|
58
|
-
- If the working directory is not in a project
|
|
58
|
+
- 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/`.
|
|
59
|
+
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
60
|
+
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
61
|
+
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
62
|
+
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
59
63
|
- 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.
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
64
|
+
- 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.
|
|
65
|
+
- The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
|
|
66
|
+
- When a file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses evidence in that folder.
|
|
67
|
+
- 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.
|
|
68
|
+
- 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.
|
|
63
69
|
- 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`.
|
|
64
70
|
|
|
65
|
-
|
|
71
|
+
---
|
|
66
72
|
|
|
67
|
-
|
|
68
|
-
2. Run the script.
|
|
69
|
-
3. If `result` is `PASS`, the PRG is at `out`. `loadRange` tells where it loads. `symbols` is a list with `count` and `listed`. Each item in `listed` is one symbol:
|
|
70
|
-
- Kind `address` has a value in `loadRange`. It gives the `address`.
|
|
71
|
-
- Kind `constant` has a value outside `loadRange`. It gives the `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.
|
|
72
|
-
- `used` is `false` when the source does not use the symbol.
|
|
73
|
-
4. If `result` is `FAIL` and `assembled` is `false`, read `diagnostics`. Each one has a severity, a file, a line and a message. Correct the source and run the script again.
|
|
74
|
-
5. To run the program, give the PRG path to the emulator skill.
|
|
73
|
+
## Flags
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
Each flag applies only to the commands in the table. On another command, the script refuses the flag.
|
|
77
76
|
|
|
78
|
-
|
|
77
|
+
| Flag | Command | Effect |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `--out <file.prg>` | `build` | Required. The path of the program, relative to the project folder. |
|
|
80
|
+
| `--include <dir>` | `build` | An include folder, relative to the source root. Give the flag again for each folder. The default is no include folder. |
|
|
81
|
+
| `--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. |
|
|
82
|
+
| `--set-pc <address>` | `build` | The start address when the source does not set one, for example `'$0801'`. |
|
|
83
|
+
| `--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. |
|
|
84
|
+
| `--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. |
|
|
85
|
+
| `--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`. |
|
|
86
|
+
| `--plain` | `build` | Write only the bytes of the program, without the 2-byte load address. Off by default. |
|
|
87
|
+
| `--all-symbols` | `build` | List also the constants that the source does not use. Off by default. |
|
|
88
|
+
| `--max-listed <n>` | `build` | List at most `n` symbols. The default is 50. `symbols.count` always gives the count of all symbols. |
|
|
89
|
+
| `--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. |
|
|
79
90
|
|
|
80
|
-
|
|
81
|
-
- none.
|
|
91
|
+
---
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
- diagnostics
|
|
85
|
-
- build output
|
|
93
|
+
## Build
|
|
86
94
|
|
|
87
|
-
|
|
95
|
+
### `build <source-root> <entry>`
|
|
88
96
|
|
|
89
|
-
|
|
97
|
+
Assembles the source and writes the program to `--out`.
|
|
90
98
|
|
|
91
|
-
`
|
|
99
|
+
`body` holds:
|
|
92
100
|
|
|
93
|
-
- `
|
|
94
|
-
- `
|
|
95
|
-
- `
|
|
96
|
-
- `
|
|
101
|
+
- `result`: `PASS` or `FAIL`.
|
|
102
|
+
- `assembled`: `false` when the source has errors.
|
|
103
|
+
- `out`, `bytes` and `sha256`: the program file.
|
|
104
|
+
- `plain`: `true` with `--plain`.
|
|
105
|
+
- `loadRange`: `start`, `end` and `bytes` of the program in C64 memory. With `--plain`, `loadRange` tells where the bytes go.
|
|
106
|
+
- `symbols`: `count`, `listed` and `rest`. Each item has `name`, `kind` and `used`:
|
|
107
|
+
- Kind `address` has a value in `loadRange`. It gives `address`.
|
|
108
|
+
- 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.
|
|
109
|
+
- `used` is `false` when the source does not use the symbol.
|
|
110
|
+
- `symbolsFile`: the file of `--out-symbols`, with `out`, `bytes` and `sha256`.
|
|
111
|
+
- `unusedConstants`: the count of the constants that the list does not include. It is not in the body with `--all-symbols`.
|
|
112
|
+
- `diagnostics`: each item has `severity` (`error`, `warning` or `note`), `file`, `line` and `message`. `file` and `line` are not in an item without a location in the source.
|
|
113
|
+
- `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`:
|
|
114
|
+
- `identical`.
|
|
115
|
+
- `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.
|
|
116
|
+
- `not covered`, with `uncovered`: the build does not hold all bytes of the segment.
|
|
97
117
|
|
|
98
|
-
|
|
118
|
+
Do as the result tells:
|
|
99
119
|
|
|
100
|
-
|
|
120
|
+
- `result` is `PASS`: the program is at `out`. To run or debug the program, load the file at `out` into the emulator.
|
|
121
|
+
- `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.
|
|
122
|
+
- `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.
|
|
123
|
+
- `hint` tells that `symbols` is cut: give a larger `--max-listed`, or `--out-symbols <file.json>` for the full list.
|
|
124
|
+
- Error `not-found` names the entry: give the main source file relative to the source root.
|
|
125
|
+
- Error `not-found` names an include folder: give `--include` a folder with files, relative to the source root.
|
|
126
|
+
- 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.
|
|
127
|
+
- Error `not-found` tells that the knowledge has no program: put the program bytes into the project knowledge. Then use `--compare` again.
|
|
128
|
+
- Error `invalid-input`: an option or a path is wrong. Do as `hint` tells. The script refuses `--space` without `--compare` or `--release`.
|
|
101
129
|
|
|
102
|
-
|
|
103
|
-
- `FAIL` with `assembled: true`: the build is not identical to the program in the knowledge. Read `compare.segments`.
|
|
104
|
-
- `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
|
|
105
|
-
- `invalid-input`: an option or a path is wrong. Read the message and correct the call.
|
|
106
|
-
- `not-found`: the source root has no main source file with that name, or no folder with files for an `--include`. Give a path relative to the source root.
|
|
130
|
+
The script does not keep the diagnostics or the program in the project knowledge.
|
|
107
131
|
|
|
108
|
-
|
|
132
|
+
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.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Workflow
|
|
137
|
+
|
|
138
|
+
1. Find the source root and the entry.
|
|
139
|
+
2. Run `build`.
|
|
140
|
+
3. If `assembled` is `false`, correct the source. Then do step 2 again.
|
|
141
|
+
4. For a rebuild, run `build` with `--compare`. For a release, also give `--release <label>`.
|
|
142
|
+
5. Run or debug the program at `out` in the emulator.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## JSON output
|
|
147
|
+
|
|
148
|
+
Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
|
|
149
|
+
|
|
150
|
+
On success, the exit code is 0:
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
On failure, the exit code is 2:
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
- `body` holds the result. The section of each command gives the fields of its body.
|
|
163
|
+
- 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.
|
|
164
|
+
- `error` is one sentence. It tells what is wrong.
|
|
165
|
+
- `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
|
|
166
|
+
- `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
|
|
167
|
+
- `code` does not change between versions. Do the action for the code:
|
|
168
|
+
|
|
169
|
+
| `code` | Action |
|
|
170
|
+
|---|---|
|
|
171
|
+
| `installation-incomplete`, `machine-unavailable` | Stop the task. Give `error` and `hint` to the user and wait for the user. Do not install, start or change a tool. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script. |
|
|
172
|
+
| `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
|
|
173
|
+
| `operation-failed` | Give `error` and `hint` to the user. |
|
|
174
|
+
| Another code | Do as `hint` tells. |
|
|
175
|
+
|
|
176
|
+
These fields have the same meaning in each body:
|
|
177
|
+
|
|
178
|
+
| Field | Meaning |
|
|
179
|
+
|---|---|
|
|
180
|
+
| `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
|
|
181
|
+
| `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. |
|
|
109
182
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
- Pack the program into one small PRG that unpacks itself → c64-packer
|
|
113
|
-
- Write a new program, or add a feature or a correction → c64-development
|
|
183
|
+
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.
|
|
184
|
+
To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
|
|
@@ -15,7 +15,7 @@ import { RELEASE_DEFINE } from "#src/knowledge/schema.ts";
|
|
|
15
15
|
import { assemble, showSymbol, symbolsFileText } from "#src/native/acme.ts";
|
|
16
16
|
import { localToolContext } from "#src/native/local.ts";
|
|
17
17
|
import type { AcmeParams, AssembledSymbol } from "#src/native/types.ts";
|
|
18
|
-
import { listed as listedItems, OPTIONS, runScript, UsageError } from "#src/script.ts";
|
|
18
|
+
import { listed as listedItems, OPTIONS, reply, runScript, UsageError } from "#src/script.ts";
|
|
19
19
|
import { compareBuild, type Reference } from "#src/compare.ts";
|
|
20
20
|
|
|
21
21
|
function parseDefine(text: string): [string, number | boolean] {
|
|
@@ -37,7 +37,7 @@ await runScript({
|
|
|
37
37
|
name: "build",
|
|
38
38
|
summary: "Assembles the source and writes the program. result is PASS when it assembles (and with --compare, when it is the program of the knowledge or of the --release), else FAIL with the diagnostics or the differences.",
|
|
39
39
|
subjects: [
|
|
40
|
-
{ name: "<source-root>", help: "the folder in the project
|
|
40
|
+
{ name: "<source-root>", help: "the folder in the project that holds all the source files of the program" },
|
|
41
41
|
{ name: "<entry>", help: "the main source file, relative to the source root" },
|
|
42
42
|
],
|
|
43
43
|
options: {
|
|
@@ -51,9 +51,9 @@ await runScript({
|
|
|
51
51
|
plain: { kind: "flag", help: "write the bytes only, without the 2-byte load address of a PRG" },
|
|
52
52
|
"all-symbols": { kind: "flag", help: "list also the constants that the source does not use" },
|
|
53
53
|
"max-listed": { ...OPTIONS["max-listed"], help: "list at most n symbols (default 50). The count is always given" },
|
|
54
|
-
"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
|
|
54
|
+
"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" },
|
|
55
55
|
},
|
|
56
|
-
notes: "Symbol values are $ and at least four hex digits.
|
|
56
|
+
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.",
|
|
57
57
|
run: async (call) => {
|
|
58
58
|
const [sourceRoot, entry] = [call.subject(0), call.subject(1)];
|
|
59
59
|
const out = call.string("out")!;
|
|
@@ -68,7 +68,7 @@ await runScript({
|
|
|
68
68
|
if (label === undefined) program = requireProgram(db, call.space);
|
|
69
69
|
else {
|
|
70
70
|
const release = releaseLabeled(db, label, call.space);
|
|
71
|
-
if (release === undefined) throw new Refusal("not-found", `There is no release ${label} in the knowledge. Record
|
|
71
|
+
if (release === undefined) throw new Refusal("not-found", `There is no release ${label} in the knowledge. Record the release in the project knowledge first, or give the label of a recorded release.`);
|
|
72
72
|
releaseDefine = { [`${RELEASE_DEFINE}${label}`]: 1 };
|
|
73
73
|
if (call.flag("compare")) program = release.base ? requireProgram(db, call.space) : readImage(release.file);
|
|
74
74
|
}
|
|
@@ -90,7 +90,7 @@ await runScript({
|
|
|
90
90
|
const params: AcmeParams = { files: tree.files, entrySource: entry, includeDirs: call.strings("include"), defines: { ...releaseDefine, ...Object.fromEntries(call.strings("define").map(parseDefine)) }, ...(setPc === undefined ? {} : { setPc }) };
|
|
91
91
|
|
|
92
92
|
const { result, attachments } = await assemble(params, tree.contents, localToolContext());
|
|
93
|
-
if (!result.assembled) return { result: "FAIL", assembled: false, diagnostics: result.diagnostics };
|
|
93
|
+
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." });
|
|
94
94
|
const plain = call.flag("plain");
|
|
95
95
|
const written = writeReported(out, plain ? attachments![0]!.subarray(2) : attachments![0]!, { what: "--out" });
|
|
96
96
|
const range = result.loadRange!;
|
|
@@ -99,19 +99,26 @@ await runScript({
|
|
|
99
99
|
const all = call.flag("all-symbols");
|
|
100
100
|
const shown = result.symbols!.filter((symbol) => all || symbol.kind === "address" || symbol.used);
|
|
101
101
|
const symbolsPath = call.string("out-symbols");
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, "a larger --max-listed, or --out-symbols <file.json> for the whole list");
|
|
103
|
+
// A build that differs from its reference is a failed check.
|
|
104
|
+
const different = compared !== undefined && !compared.identical;
|
|
105
|
+
const hints = [
|
|
106
|
+
...(different ? ["The program is not identical to the reference program. Read compare.segments: each segment that is different gives its first difference."] : []),
|
|
107
|
+
...(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."] : []),
|
|
108
|
+
...(symbols.rest === undefined ? [] : [`symbols is cut. To get all symbols, give ${symbols.rest}.`]),
|
|
109
|
+
];
|
|
110
|
+
return reply({
|
|
111
|
+
result: different ? "FAIL" : "PASS",
|
|
105
112
|
assembled: true,
|
|
106
113
|
...written,
|
|
107
114
|
...(plain ? { plain: true } : {}),
|
|
108
115
|
loadRange: { start: formatC64Address(range.start), end: formatC64Address(range.end), bytes: range.bytes },
|
|
109
|
-
symbols
|
|
116
|
+
symbols,
|
|
110
117
|
...(symbolsPath === undefined ? {} : { symbolsFile: writeReported(symbolsPath, symbolsFileText(shown), { what: "--out-symbols" }) }),
|
|
111
118
|
...(all ? {} : { unusedConstants: result.symbols!.length - shown.length }),
|
|
112
119
|
diagnostics: result.diagnostics,
|
|
113
120
|
...(compared === undefined ? {} : { compare: compared }),
|
|
114
|
-
};
|
|
121
|
+
}, hints.length === 0 ? {} : { hint: hints.join(" ") });
|
|
115
122
|
},
|
|
116
123
|
},
|
|
117
124
|
],
|
|
@@ -1,82 +1,120 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-basic
|
|
3
|
-
description:
|
|
3
|
+
description: Decodes a C64 BASIC V2 program (PRG) into a readable listing. It finds where the BASIC gives control to machine code with SYS or USR. Use it on the start file of a game or of a demo. Use it to find the address where the machine code starts. It does not run the program, and it does not disassemble machine code.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# C64 BASIC
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use this script to decode a C64 BASIC V2 program and to find its handoffs to machine code.
|
|
9
|
+
Use only the commands of the script. Do not decode BASIC in another way.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
```bash
|
|
12
|
+
node <skill>/scripts/basic.ts <command>
|
|
13
|
+
```
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
`<skill>` is the base directory of this skill. Run the script with `node`. You can run it from any directory.
|
|
16
|
+
Each command in this skill, for example `list extracted/game.prg`, goes in the place of `<command>`.
|
|
17
|
+
Each command prints one JSON envelope on stdout. See the section "JSON output".
|
|
18
|
+
To get the command list, run the script with no arguments.
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
---
|
|
15
21
|
|
|
16
|
-
|
|
22
|
+
## Select the command
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
| Goal | Command |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Read the BASIC lines of a program | `list extracted/game.prg` |
|
|
27
|
+
| Find the address where BASIC starts the machine code | `list extracted/game.prg` |
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
## Programs
|
|
30
|
+
|
|
31
|
+
- `<program>` is a PRG file. A PRG starts with its 2-byte load address.
|
|
32
|
+
- Get the PRG from a disk image, a tape file or a cartridge file first. The script refuses a disk image, a tape file and a cartridge file.
|
|
23
33
|
|
|
24
|
-
###
|
|
34
|
+
### Paths and the project folder
|
|
25
35
|
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives.
|
|
36
|
+
- 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/`.
|
|
37
|
+
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
38
|
+
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
29
39
|
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
30
40
|
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
31
|
-
- The script examines each `--out` path before it starts work. It refuses a path in `.c64-re-tools/knowledge/` and the index of the knowledge, because only c64-knowledge writes them. It refuses a folder where the command writes a file, and a file where the command writes a folder.
|
|
32
|
-
- The result is one JSON object on one line. A file that the script writes shows as `{"out", "bytes", "sha256"}`. A list shows as `{"count", "listed"}`, and `rest` tells where to get the rest of a long list.
|
|
33
|
-
- An error is `{"error": {"code": "...", "message": "..."}}`. The message tells what is wrong and what to do.
|
|
34
|
-
- The exit status is 0 for done or PASS, 1 for FAIL, 2 for an error and 3 for INCONCLUSIVE.
|
|
35
|
-
|
|
36
|
-
### Project folder
|
|
37
|
-
|
|
38
|
-
- Paths are relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
39
|
-
- If the working directory is not in a project and has projects below it, the script refuses and lists them. Then give `--project <folder>` to each script.
|
|
40
41
|
- 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.
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
42
|
+
- 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.
|
|
43
|
+
- The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
|
|
44
|
+
- When a file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses evidence in that folder.
|
|
45
|
+
- 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.
|
|
46
|
+
- 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.
|
|
44
47
|
- 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`.
|
|
45
48
|
|
|
46
|
-
##
|
|
49
|
+
## Decode a program
|
|
50
|
+
|
|
51
|
+
### `list <program>`
|
|
52
|
+
|
|
53
|
+
`body` holds:
|
|
54
|
+
|
|
55
|
+
- `listing`: the BASIC lines. Each line starts with its BASIC line number. Keywords show in lower case. A control character in a string shows in braces, for example `{clr}`.
|
|
56
|
+
- `handoffs`: each place where the BASIC gives control to machine code. Each handoff has a `kind` (`sys` or `usr`) and the BASIC `line`.
|
|
57
|
+
- A `sys` handoff with an `address` calls the machine code at that address. The script calculates a SYS argument with numbers, π, `+`, `-`, `*`, `/` and brackets. For example, `SYS π*656` calls `$080c`.
|
|
58
|
+
- 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`.
|
|
59
|
+
- `loadRange`: the `start` and the `end` of the program in memory.
|
|
60
|
+
- `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.
|
|
61
|
+
|
|
62
|
+
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.
|
|
47
63
|
|
|
48
|
-
|
|
49
|
-
2. Read `listing`. Each line starts with its BASIC line number. Keywords show in lower case. Control characters in strings show in braces, for example `{clr}`.
|
|
50
|
-
3. Read `handoffs`. Each handoff has a `kind` (`sys` or `usr`) and the BASIC `line`.
|
|
51
|
-
- A `sys` handoff with an `address`: BASIC calls the machine code at that address. The script calculates a SYS argument with numbers, π, `+`, `-`, `*`, `/` and brackets. For example, `SYS π*656` calls `$080c`.
|
|
52
|
-
- A handoff with `computed: true`: the address comes from a calculation at run time, for example with `PEEK`. A `sys` handoff gives its argument in `expression`. Use the emulator skill to find the address.
|
|
53
|
-
4. Compare the address with `loadRange` and `basicEnd`. From `basicEnd` to the end of `loadRange`, the file holds bytes that are not BASIC. Usually this is the machine code that the handoff calls. Some programs have no end marker (two zero bytes) after the last line. The machine code starts directly after the last line. Then `basicEnd` is the first byte of that machine code.
|
|
64
|
+
Some programs have no end marker (two zero bytes) after the last line. Then the machine code starts directly after the last line, and `basicEnd` is the first byte of that machine code.
|
|
54
65
|
|
|
55
|
-
|
|
66
|
+
`hint` gives the next task:
|
|
56
67
|
|
|
57
|
-
|
|
68
|
+
- A handoff address: disassemble the machine code at that address.
|
|
69
|
+
- A computed handoff: find the address in the emulator at run time. Do not guess the address.
|
|
70
|
+
- No handoff: the BASIC starts no machine code with SYS or USR. Look in the listing for a POKE into a vector or a LOAD of another file. Do not make up a handoff.
|
|
58
71
|
|
|
59
|
-
|
|
60
|
-
- none.
|
|
72
|
+
When the address where the machine code starts is a durable fact, record it in the project knowledge. Do not record the listing.
|
|
61
73
|
|
|
62
|
-
|
|
63
|
-
- the listing.
|
|
74
|
+
Failure:
|
|
64
75
|
|
|
65
|
-
|
|
76
|
+
- `invalid-input` with "is no BASIC program": the file is not a BASIC program. Usually the file is machine code. Disassemble it from its load address. A memory dump also gives this error.
|
|
77
|
+
- `invalid-input` with "is a disk image" or a similar text: get the PRG out of the file first.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## JSON output
|
|
82
|
+
|
|
83
|
+
Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
|
|
84
|
+
|
|
85
|
+
On success, the exit code is 0:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
On failure, the exit code is 2:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
|
|
95
|
+
```
|
|
66
96
|
|
|
67
|
-
|
|
97
|
+
- `body` holds the result. The section of each command gives the fields of its body.
|
|
98
|
+
- 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.
|
|
99
|
+
- `error` is one sentence. It tells what is wrong.
|
|
100
|
+
- `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
|
|
101
|
+
- `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
|
|
102
|
+
- `code` does not change between versions. Do the action for the code:
|
|
68
103
|
|
|
69
|
-
|
|
104
|
+
| `code` | Action |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `installation-incomplete`, `machine-unavailable` | Stop the task. Give `error` and `hint` to the user and wait for the user. Do not install, start or change a tool. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script. |
|
|
107
|
+
| `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
|
|
108
|
+
| `operation-failed` | Give `error` and `hint` to the user. |
|
|
109
|
+
| Another code | Do as `hint` tells. |
|
|
70
110
|
|
|
71
|
-
|
|
111
|
+
These fields have the same meaning in each body:
|
|
72
112
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
113
|
+
| Field | Meaning |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
|
|
116
|
+
| `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. |
|
|
77
117
|
|
|
78
|
-
|
|
118
|
+
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.
|
|
119
|
+
To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
|
|
79
120
|
|
|
80
|
-
- Machine code at the handoff address → c64-static-analysis
|
|
81
|
-
- Run the program to the handoff → emulator
|
|
82
|
-
- Record the entry point → c64-knowledge
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The c64-basic script: decodes a project C64 BASIC V2 program with petcat
|
|
2
|
-
// through the Host Runtime and reports its machine-code handoffs.
|
|
2
|
+
// through the Host Runtime and reports its machine-code handoffs. The SYS
|
|
3
|
+
// argument is calculated when it holds only numbers, pi, + - * / and brackets.
|
|
3
4
|
|
|
4
5
|
import { statSync } from "node:fs";
|
|
5
6
|
|
|
@@ -7,11 +8,11 @@ import { formatC64Address } from "#src/c64.ts";
|
|
|
7
8
|
import { Refusal } from "#src/errors.ts";
|
|
8
9
|
import { decodeBasic } from "#src/host-client/tools.ts";
|
|
9
10
|
import { resolveProjectPath } from "#src/project.ts";
|
|
10
|
-
import { runScript } from "#src/script.ts";
|
|
11
|
+
import { reply, runScript } from "#src/script.ts";
|
|
11
12
|
|
|
12
13
|
await runScript({
|
|
13
14
|
name: "basic",
|
|
14
|
-
summary: "Decodes a C64 BASIC V2 program
|
|
15
|
+
summary: "Decodes a C64 BASIC V2 program and reports its machine-code handoffs: SYS and USR.",
|
|
15
16
|
commands: [
|
|
16
17
|
{
|
|
17
18
|
name: "list",
|
|
@@ -20,16 +21,24 @@ await runScript({
|
|
|
20
21
|
run: async (call) => {
|
|
21
22
|
const program = call.subject(0);
|
|
22
23
|
const result = await decodeBasic({ program });
|
|
23
|
-
if (!result.decoded) throw new Refusal("invalid-input", `${program} is no BASIC program: ${result.reason}
|
|
24
|
+
if (!result.decoded) throw new Refusal("invalid-input", `${program} is no BASIC program: ${result.reason}`, { hint: "Usually the file is machine code. Disassemble it from its load address." });
|
|
24
25
|
const size = statSync(resolveProjectPath(program)).size - 2;
|
|
25
26
|
const end = result.loadAddress + size - 1;
|
|
26
|
-
|
|
27
|
+
const handoffs = result.handoffs.map((handoff) => ("address" in handoff ? { ...handoff, address: formatC64Address(handoff.address) } : handoff));
|
|
28
|
+
const body = {
|
|
27
29
|
loadRange: { start: formatC64Address(result.loadAddress), end: formatC64Address(end) },
|
|
28
30
|
// From here to the end of the load range, the file holds no BASIC (often machine code).
|
|
29
31
|
basicEnd: result.basicEnd <= end ? formatC64Address(result.basicEnd) : null,
|
|
30
32
|
listing: result.listing,
|
|
31
|
-
handoffs
|
|
33
|
+
handoffs,
|
|
32
34
|
};
|
|
35
|
+
const known = handoffs.flatMap((handoff) => ("address" in handoff ? [handoff.address] : []));
|
|
36
|
+
const computed = handoffs.filter((handoff) => !("address" in handoff)).map((handoff) => handoff.line);
|
|
37
|
+
const hints: string[] = [];
|
|
38
|
+
if (handoffs.length === 0) hints.push("The BASIC starts no machine code with SYS or USR. Look in the listing for a POKE into a vector or a LOAD of another file.");
|
|
39
|
+
if (known.length > 0) hints.push(`Disassemble the machine code at ${known.join(", ")}.`);
|
|
40
|
+
if (computed.length > 0) hints.push(`The handoff address in line ${computed.join(", ")} comes from a calculation at run time. Find it in the emulator.`);
|
|
41
|
+
return reply(body, { hint: hints.join(" ") });
|
|
33
42
|
},
|
|
34
43
|
},
|
|
35
44
|
],
|