@henols/c64-re-tools 2.2.0-rc.1 → 2.2.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.
package/README.md CHANGED
@@ -36,15 +36,17 @@ Windsurf.
36
36
  ## How it works
37
37
 
38
38
  VICE and the Host Runtime run on your computer, where VICE can open a window.
39
- The agent runs in your project, preferably in a dev container. It reaches VICE
40
- through an MCP server, and it runs ACME, DXA and Ghidra through its skills.
39
+ The agent runs in a dev container in your project. It reaches VICE through an
40
+ MCP server, and it runs ACME, DXA, Ghidra and c64run through its skills.
41
41
 
42
42
  ## Install
43
43
 
44
+ ### Host
45
+
44
46
  You need Node.js 24 or newer and VICE 3.9 or later (`x64sc`, `c1541`, `petcat`)
45
- with its ROM files on the host. Use the latest VICE release.
47
+ with its ROM files. Use the latest VICE release.
46
48
 
47
- Start the Host Runtime on the host, and leave it running:
49
+ Start the Host Runtime, and leave it running:
48
50
 
49
51
  ```
50
52
  npx -y --package=@henols/c64-re-tools@latest c64-re-tools-host
@@ -54,42 +56,25 @@ npx -y --package=@henols/c64-re-tools@latest c64-re-tools-host
54
56
 
55
57
  ### Dev container
56
58
 
57
- This is the preferred way. The container gets Node.js 24, ACME, dxa, Java 21, Ghidra and c64run.
58
- At each start it installs the newest toolkit of the channel into the project,
59
- with the tools of that version, so the tools and the skills always match. Add to `.devcontainer/devcontainer.json`:
60
-
61
- ```json
62
- "features": {
63
- "https://github.com/henols/c64-re-tools/releases/latest/download/devcontainer-feature-c64-re-tools.tgz": { "target": "claude" }
64
- },
65
- "runArgs": ["--add-host=host.docker.internal:host-gateway"]
66
- ```
67
-
68
- `target` is the harness, or a comma list such as `claude,codex`. The Feature
69
- needs a Debian or Ubuntu image. `runArgs` is for Docker on Linux.
70
-
71
- To use prereleases, add `"channel": "next"` next to `target`, then rebuild the
72
- container. To go back to releases, remove `channel` (or set `"latest"`) and
73
- rebuild. The Feature reads its options only when the container is built.
74
- With `next`, the container gets the newer of the prerelease and the release,
75
- so it is never older than `latest`.
76
-
77
- ### Without a container
78
-
79
- Install ACME, dxa, Ghidra and c64run as in [docs/install-tools.md](docs/install-tools.md).
80
- Then, in your project:
59
+ You need Docker or Podman. Copy the example into your project:
81
60
 
82
61
  ```
83
- npx -y @henols/c64-re-tools@latest install --target claude
62
+ mkdir -p .devcontainer
63
+ curl -fsSL -o .devcontainer/devcontainer.json https://raw.githubusercontent.com/henols/c64-re-tools/main/devcontainer/example/devcontainer.json
84
64
  ```
85
65
 
86
- For a prerelease, use `@next` in place of `@latest`. npm moves `next` only when
87
- a prerelease is tagged, so after a release `@next` can be older than `@latest`.
66
+ Its comments tell what to change: the harness, the release channel, the image
67
+ and the address of the Host Runtime. If the project already has a
68
+ `devcontainer.json`, copy the c64-re-tools Feature and `runArgs` into it.
88
69
 
89
- `--target` is `claude`, `codex`, `pi`, `opencode`, `gemini`, `copilot`, `cursor`
90
- or `windsurf`. Without it, `install` installs for all of them.
70
+ Open the project in the container, for example with "Reopen in Container" in
71
+ VS Code, or with `npx -y @devcontainers/cli up --workspace-folder .`. The
72
+ Feature gives the container ACME, dxa, Java 21, Ghidra and c64run. At each
73
+ start it installs the newest toolkit of its channel into the project, with the
74
+ tools of that version. It reads its options only when the container is built:
75
+ rebuild after a change.
91
76
 
92
- Check what works:
77
+ Check what works, in the container:
93
78
 
94
79
  ```
95
80
  npx -y @henols/c64-re-tools@latest status
@@ -115,8 +100,8 @@ The agent keeps what it learns about a program as text in
115
100
  `.c64-re-tools/knowledge/`. Commit that folder with the project. If a command
116
101
  reports conflicts after a `git pull`, run `knowledge.ts merge`.
117
102
 
118
- Several programs in one repository: install once at the root and give each
119
- program its own folder. A folder with `.c64-re-tools/` is a project.
103
+ Several programs in one repository: open the repository root in the dev
104
+ container and give each program its own folder. A folder with `.c64-re-tools/` is a project.
120
105
 
121
106
  ## Skills
122
107
 
@@ -125,7 +110,8 @@ program its own folder. A folder with `.c64-re-tools/` is a project.
125
110
  | c64-assembler | Builds ACME source, with errors and symbols. |
126
111
  | c64-emulator | Runs, debugs and observes the program in VICE. |
127
112
  | c64-memory-map | What an address or a register value means. |
128
- | c64-testing | Runs scenarios: original against rebuild, or many steps on one program. |
113
+ | c64-development | Writes new programs, and adds features and fixes, with tests that give PASS or FAIL. |
114
+ | c64-testing | Runs scenarios: original against rebuild, or many steps on one program with expected values. |
129
115
  | c64-disk | Directory, BAM, entries, sector chains and extraction of disk images. |
130
116
  | c64-basic | BASIC V2 listings and the SYS/USR handoff to machine code. |
131
117
  | c64-unpacker | Packing evidence, and capture of the unpacked program. |
@@ -138,12 +124,12 @@ program its own folder. A folder with `.c64-re-tools/` is a project.
138
124
 
139
125
  ## Settings
140
126
 
127
+ Set the host variables where the Host Runtime starts, and the others in
128
+ `containerEnv` of the `devcontainer.json`.
129
+
141
130
  | Variable | Meaning |
142
131
  | --- | --- |
143
132
  | `C64RT_VICE`, `C64RT_C1541`, `C64RT_PETCAT` | Full path of the VICE tool, when it is not on `PATH` (host). |
144
- | `C64RT_ACME`, `C64RT_DXA`, `C64RT_C64RUN` | Full path of the tool, when it is not on `PATH`. |
145
- | `C64RT_C64_ROMS` | The C64 ROM folder of c64run, when it is not `share/c64-re-tools/roms` next to its `bin`. |
146
- | `C64RT_GHIDRA` | The Ghidra installation directory, when `analyzeHeadless` is not on `PATH`. |
147
133
  | `C64RT_HOST` | `host:port` of the Host Runtime, when it is not on 127.0.0.1, `host.docker.internal` or `host.containers.internal` at port 6464. |
148
134
  | `C64RT_VIDEO` | `pal` (default) or `ntsc`. |
149
135
  | `C64RT_TRACE` | A directory for a trace of a run. See [docs/debug-install.md](docs/debug-install.md). |
@@ -159,7 +145,9 @@ pnpm test
159
145
  pnpm host # the Host Runtime from this checkout
160
146
  ```
161
147
 
162
- Tests that need real tools are skipped unless you turn them on:
148
+ Tests that need real tools are skipped unless you turn them on. On Debian or
149
+ Ubuntu, `sudo bash tools/install-container.sh` installs ACME, dxa, c64run and
150
+ Ghidra (in `/opt/ghidra`, with Java 21 from you), as the dev container does:
163
151
 
164
152
  ```
165
153
  C64RT_LIVE_VICE=/usr/bin/x64sc C64RT_GHIDRA=/opt/ghidra pnpm test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henols/c64-re-tools",
3
- "version": "2.2.0-rc.1",
3
+ "version": "2.2.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",
@@ -111,3 +111,4 @@ With `--compare`, `compare` gives `identical` and `segments`: one check for each
111
111
 
112
112
  - Run or debug the program → c64-emulator
113
113
  - Compare the rebuild with the original → c64-testing
114
+ - Write a new program, or add a feature or a fix → c64-development
@@ -0,0 +1,179 @@
1
+ ---
2
+ name: c64-development
3
+ description: Use this skill to write a new C64 program in 6510 assembly for ACME. Also use it to add a feature or a fix to a program. It builds, runs, debugs and tests the program step by step, with tests that give PASS or FAIL. It works on source that a person wrote, and on a rebuilt program with switches. It decides which specialist skill does each step. Use it for requests such as "write a game", "add a high score", "fix the sprite flicker" or "make the border flash". Do not use it to find out what an unknown program does. Use c64-reverse-engineering for that.
4
+ ---
5
+
6
+ # c64-development
7
+
8
+ ## Purpose
9
+
10
+ Coordinate the development of a C64 program: a new program, a new feature or a fix. Make each change in small steps. Prove each step with a test that gives PASS.
11
+
12
+ This skill does not do the specialist work itself.
13
+
14
+ ## Inputs
15
+
16
+ - The request: the program, the feature or the defect.
17
+ - The acceptance checks: what the user must see or what memory must hold when the work is complete.
18
+ - The project: its source, its tests and its knowledge.
19
+
20
+ ## Tools / execution path
21
+
22
+ This skill uses the other skills. It does not use the host runtime or the emulator directly.
23
+
24
+ | Work | Skill |
25
+ |---|---|
26
+ | Assemble the source to a PRG, with errors and symbols | c64-assembler |
27
+ | Run, look, debug and measure | c64-emulator |
28
+ | Tests with expected values (`expect` steps in a run), and original against rebuild | c64-testing |
29
+ | The meaning of an address or a register, and an include of the platform names | c64-memory-map |
30
+ | Patches and switches of a rebuilt program, names and comments | c64-knowledge |
31
+ | The source of a rebuilt program | c64-source |
32
+ | Ranges that a rebuilt program does not use | c64-provenance |
33
+ | Documentation | c64-docs |
34
+
35
+ ### Project folder
36
+
37
+ One repository can hold several programs, with one project folder for each program. A project folder holds `.c64-re-tools/`. Work on one project at a time:
38
+
39
+ - From the root of the repository, give `--project <folder>` to each skill script, and `project` to each emulator tool with a path.
40
+ - Write all files in the project folder. Do not write files at the root of the repository.
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, step files, snapshots and memory dumps.
42
+ - Keep the run files that are tests in `tests/`. Git keeps them.
43
+ - Write the knowledge only with the c64-knowledge script. Do not write or edit the files in `.c64-re-tools/knowledge/` yourself.
44
+
45
+ ## Workflow
46
+
47
+ First select the path:
48
+
49
+ - The project has no program yet: path A.
50
+ - The program has source that a person wrote: path B.
51
+ - The source comes from c64-source: path C. The source has `main.asm` and `source-map.json` from c64-source. Do not edit this source. The next `source.ts generate` writes over it.
52
+
53
+ ### Acceptance checks
54
+
55
+ Before you write code, write the acceptance checks. If the request does not give them, ask the user. Write each check as an `expect` step in a run file in `tests/`. Examples:
56
+
57
+ - the text at `$0400` after the start
58
+ - the value of a variable after a joystick input
59
+ - the border color in a frame
60
+ - the address of the main loop.
61
+
62
+ A check that only a person can judge, for example smooth animation, goes into a checklist with `testing.ts checklist` of c64-testing.
63
+
64
+ ### A. A new program
65
+
66
+ Use this layout. No script makes it.
67
+
68
+ ```
69
+ src/ the source, with src/main.a as the entry
70
+ build/ programs and symbol files from c64-assembler
71
+ tests/ run files with expect steps
72
+ docs/ the documentation, when the user asks for it
73
+ ```
74
+
75
+ Start the program with a BASIC line, so that `c64_autostart` and a run with `start.program` can start it:
76
+
77
+ ```
78
+ * = $0801
79
+ !word next, 10 ; line 10
80
+ !byte $9e ; SYS
81
+ !text "2061", 0
82
+ next !word 0 ; end of the BASIC program
83
+ start ; $080d = 2061
84
+ ```
85
+
86
+ Do these steps for each small part of the program:
87
+
88
+ 1. Find the meaning of each register with c64-memory-map. Make an include of the platform names with `memory-map.ts export --out src/hw.a`. Include it with `!source`. Do not type the addresses of registers yourself.
89
+ 2. Write the code for one part.
90
+ 3. Build it with c64-assembler: `assembler.ts build src main.a --out build/<name>.prg --out-symbols build/<name>.json`. Change the source at the file and the line of each error.
91
+ 4. Start it with `c64_autostart` of c64-emulator. Look at the screen with `c64_screen`. Read the screen memory, not only the image.
92
+ 5. Write the `expect` steps of this part in a run file. Give `"symbols": "build/<name>.json"`, so that a step can use the labels of the source.
93
+ 6. Run all run files in `tests/` with `testing.ts run`. Go to the next part only when each run gives PASS.
94
+
95
+ To find a defect, use c64-emulator:
96
+
97
+ - Stop at the code with `c64_breakpoint`, or at a write to a variable with `c64_watchpoint`.
98
+ - Get to a state with `c64_run_until`.
99
+ - Measure an interrupt or a loop with `c64_timing`. Find the routines that use the most cycles with `c64_profile`.
100
+ - Save the state with `c64_snapshot` before a risky try.
101
+
102
+ Find the cause before you change the code. Do not change code at random until a test passes.
103
+
104
+ When the user must play or look at the program, use the window procedure of c64-emulator. Open the window, tell the user what to do, wait, and close the window.
105
+
106
+ ### B. A feature or a fix in source that a person wrote
107
+
108
+ 1. Write a run file with an `expect` step that shows the defect or the missing feature.
109
+ 2. Run it with `testing.ts run`. Make sure that it gives FAIL. A test that gives PASS before the change does not test the change.
110
+ 3. For a defect, find the cause with c64-emulator.
111
+ 4. Change the source. Build it with c64-assembler.
112
+ 5. Run the new run file and all other run files in `tests/`. Each run must give PASS.
113
+
114
+ ### C. A feature or a fix in a rebuilt program
115
+
116
+ A rebuilt program gets its source from the knowledge. A change is a switch and its patches in the knowledge. The build of the base release stays identical to the original. See the section "Releases and switches" of c64-knowledge.
117
+
118
+ 1. Read the releases and the switches with `knowledge.ts releases` and `knowledge.ts switches` of c64-knowledge. If the knowledge has no base release, record it first, for example `knowledge.ts release ORIGINAL --file original/game.prg --base`.
119
+ 2. Give each feature and each fix its own switch. Then each one can be on or off alone. Write the switch with `knowledge.ts switch <SWITCH> --kind <kind>`. No release has your change, so do not give `--releases`. Select the kind:
120
+ - A fix: `fix`, for example `FIX_FLICKER`. The default build has it.
121
+ - A trainer or a cheat: `trainer` or `cheat`. The default build does not have it.
122
+ - Another feature: `change`, for example `HISCORE`. Ask the user if the default build must have it. Give `--default 1` or `--default 0`.
123
+ 3. Find the code to change with c64-knowledge (`at`, `regions`) and c64-emulator.
124
+ 4. Write the code in a file in `.c64-re-tools/local/`. Write the patch with `knowledge.ts patch '<range>' <SWITCH> --code-file <file>` of c64-knowledge. The code must fit in the range.
125
+ 5. If the code does not fit, write a short patch with a `jsr` to the new code. Put the new code in a second patch of the same switch, in a range that the program does not use. The range must have evidence: `provenance.ts leftovers` of c64-provenance, or code that no run executed and that the program cannot reach. If no range has this evidence, stop and ask the user.
126
+ 6. Make the source again with `source.ts generate --out src` of c64-source. The checks `check`, `switches`, `default` and `releases` must pass. A switch must not give `overflow` or `does not assemble`.
127
+ 7. Build with c64-assembler:
128
+ - `--release <base label> --compare`: this build must be identical to the original.
129
+ - The default build, with no option.
130
+ - A build with `--define <SWITCH>=1` when the default build does not have the switch.
131
+ 8. Test the build that has the switch:
132
+ - Run the scenarios in `tests/` with `testing.ts test`, where the behavior must stay the same as the original.
133
+ - Run a run file with `expect` steps that show the feature or the fix.
134
+
135
+ ### The answer
136
+
137
+ Give the user a short answer at the end:
138
+
139
+ 1. Each acceptance check and its result.
140
+ 2. The run files in `tests/` and the result of each.
141
+ 3. For path C: the switches, and how to build with each one.
142
+ 4. Open questions and the checks that only a person can judge.
143
+
144
+ ## Knowledge
145
+
146
+ For a new program, the source is the truth. Record names and comments in the knowledge only when the user asks for the knowledge or for documentation. Then put the program in with `knowledge.ts image build/<name>.prg` of c64-knowledge first.
147
+
148
+ For a rebuilt program, write each change as a switch and its patches with c64-knowledge.
149
+
150
+ Do not store:
151
+
152
+ - test results
153
+ - the state of the current work
154
+ - guesses.
155
+
156
+ ## Result
157
+
158
+ A program that builds, with a run file in `tests/` for each acceptance check, and each run gives PASS. For a rebuilt program: a switch for each change, and a build of the base release that is identical to the original.
159
+
160
+ ## Failure and conflicts
161
+
162
+ - A skill reports `installation-incomplete`, or `machine-unavailable` with a message that the host runtime does not run: stop the whole task. Give the message to the user and wait for the user. Do not continue with other skills. Do not make a replacement for the tool or the host runtime, for example your own assembler or emulator script.
163
+ - A tool gives a wrong result: tell the user the defect and the evidence, and wait for the user. Do not make a workaround.
164
+ - A test gives FAIL: change the program until the test gives PASS. Do not change the expected value to make the test pass. Change an expected value only when the user changes the acceptance check.
165
+ - A run gives FAIL because a `runUntil` did not get to its target: the program did not get to that state. Find why with c64-emulator.
166
+ - The program reads the keyboard hardware, and a key does not arrive: read the keyboard text of c64-emulator. Do not change the program to make it accept a key.
167
+ - A patch does not fit, and no unused range has evidence: stop and ask the user.
168
+
169
+ ## Handoffs
170
+
171
+ - Assemble → c64-assembler
172
+ - Run, debug and measure → c64-emulator
173
+ - Tests with expected values, and original against rebuild → c64-testing
174
+ - The meaning of an address or a register → c64-memory-map
175
+ - Patches, names and comments → c64-knowledge
176
+ - The source of a rebuilt program → c64-source
177
+ - Unused ranges of a rebuilt program → c64-provenance
178
+ - Documentation → c64-docs
179
+ - Code that nobody understands yet → c64-reverse-engineering
@@ -185,3 +185,5 @@ A clear answer for the scope, with the durable conclusions in the project knowle
185
185
  ## Handoffs
186
186
 
187
187
  All specialist skills in the table above.
188
+
189
+ A new feature or a fix for the rebuilt program → c64-development
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  name: c64-testing
3
- description: Use this skill to test if a rebuilt or changed C64 program behaves as the original. It runs one scenario on the original and then on the rebuild in an emulator. It compares memory, registers, chip state and the screen with explicit rules, and gives PASS, FAIL or INCONCLUSIVE. It also makes a checklist for a human playtest. Use its run command to explore a program with many steps, for example to visit each room or level. A run keeps screens, coverage maps and snapshots as files. Use its record and replay commands to keep a long play session of the original and replay it on each rebuild. Do not use it to find the cause of a difference.
3
+ description: Use this skill to test if a rebuilt or changed C64 program behaves as the original. It runs one scenario on the original and then on the rebuild in an emulator. It compares memory, registers, chip state and the screen with explicit rules, and gives PASS, FAIL or INCONCLUSIVE. It also makes a checklist for a human playtest. Use its run command to explore a program with many steps, for example to visit each room or level. A run keeps screens, coverage maps and snapshots as files. An expect step in a run compares memory and registers with expected values, for a new program or a fix that has no original. Use its record and replay commands to keep a long play session of the original and replay it on each rebuild. Do not use it to find the cause of a difference.
4
4
  ---
5
5
 
6
6
  # c64-testing
7
7
 
8
8
  ## Purpose
9
9
 
10
- Test if a rebuild or a changed program behaves as the original in a scenario. Give one result: PASS, FAIL or INCONCLUSIVE.
10
+ Test if a rebuild or a changed program behaves as the original in a scenario. Test if a program has the expected values in a run. Give one result: PASS, FAIL or INCONCLUSIVE.
11
11
 
12
12
  A PASS proves only the behavior that the scenario does and observes. It does not prove that the two programs are equal in all behavior.
13
13
 
@@ -51,12 +51,13 @@ The run file gives where to start (a program, or a snapshot file), the steps, an
51
51
  | `{ "observe": "room3", "memory": ["$c100"], "registers": true }` | Record memory, registers, `vicii` or `sprites` in `results.json`. |
52
52
  | `{ "trace": "d011", "points": [{ "kind": "write", "start": "$d011" }], "frames": 100 }` | Record each hit of the points for 100 frames in `d011.json`: the instruction, its registers and the raster line and cycle. A point has the `kind` `exec`, `read` or `write`, a `start` and an optional `end`. `maxHits` limits the hits. |
53
53
  | `{ "observe": "all3", "memory": "all" }` | Write all 64 KiB of RAM to `all3.bin`, also the RAM under the ROMs and the I/O area. |
54
+ | `{ "expect": "title", "memory": [{ "address": "$0400", "text": "HELLO" }], "registers": { "a": 0 } }` | Compare memory and registers with the expected values. `data` gives hex bytes, `text` gives screen codes. `mask` compares only some bits. A value that is not equal does not stop the run. |
54
55
 
55
56
  Each step that writes a file must have its own file name. The script refuses a run where two steps write the same file, for example `{ "coverage": "x" }` and `{ "observe": "x", "memory": "all" }`, which both write `x.bin`. The script also examines the start program and each snapshot file before the emulator starts.
56
57
 
57
58
  A memory item can have `"view": "ram"`. Then it reads the RAM under the ROMs and the I/O area, for example code at `$e000` under the KERNAL. The default view `cpu` reads as the CPU sees memory. An item larger than 4096 bytes goes into its own `.bin` file, and `results.json` gives the file name.
58
59
 
59
- See [references/scenario-format.md](references/scenario-format.md), section Runs. `result` is PASS when all steps ran, and FAIL when a step did not run. `reason` tells why. A long run can need more time than one shell call. Then run it in the background.
60
+ See [references/scenario-format.md](references/scenario-format.md), section Runs. `result` is PASS when all steps ran and each `expect` step passed. It is FAIL when a step did not run, and `reason` tells why. It is also FAIL when an `expect` step found a value that is not equal. Then `failedExpectations` names the steps, and `expectations` gives the expected and the actual values. A long run can need more time than one shell call. Then run it in the background.
60
61
 
61
62
  ### Recordings
62
63
 
@@ -218,4 +219,5 @@ Do not add a mask or a tolerance only to make a test pass. A tolerance must have
218
219
  - Find the cause of a difference → c64-emulator
219
220
  - Find the code that causes it → c64-static-analysis
220
221
  - Rebuild after a correction → c64-assembler
222
+ - Write or change a program, with expect steps as its tests → c64-development
221
223
  - Record a confirmed conclusion → c64-knowledge
@@ -92,7 +92,7 @@ A run file (for `testing.ts run`) has:
92
92
  - `start`: `{ "program": "game.prg" }` to autostart a program with a BASIC start line, `{ "program": "game.prg", "load": true }` to load it with the CPU stopped (set `pc` in a step), or `{ "snapshot": ".c64-re-tools/local/snapshots/room0.vsf" }`.
93
93
  - `symbols`: optional, `knowledge`, `none` (default), or a JSON file as for a subject. Without `symbols`, a run has no names: give `"symbols": "knowledge"` to use the names of the knowledge.
94
94
  - `videoStandard`: optional, `pal` (default) or `ntsc`.
95
- - `steps`: the steps `write`, `registers`, `joystick`, `type`, `frames` and `runUntil` of a scenario, and the run steps `snapshot`, `save`, `screen`, `coverage`, `trace` and `observe`.
95
+ - `steps`: the steps `write`, `registers`, `joystick`, `type`, `frames` and `runUntil` of a scenario, and the run steps `snapshot`, `save`, `screen`, `coverage`, `trace`, `observe` and `expect`.
96
96
 
97
97
  A `trace` step has a name, `points` (1 to 8), `frames` (1 to 3000) and an optional `maxHits` (at most 20000). A point has `kind` (`exec`, `read` or `write`), `start` and an optional `end`. The step writes `<name>.json` with each hit. `results.json` gives the file, the count of hits, the frames and why the trace ended. A trace that a breakpoint, a watchpoint or a JAM ends also ends the run.
98
98
 
@@ -100,7 +100,39 @@ In a run, an `observe` step can have `memory`, `registers`, `vicii` and `sprites
100
100
 
101
101
  In a run, a memory item has `address`, `size` (1 to 65536) and `view`. An item larger than 4096 bytes goes into the file `<observe>-<address>.bin`, without the `$`. `"memory": "all"` writes all 64 KiB of RAM to `<observe>.bin`.
102
102
 
103
- A name in `save`, `screen`, `coverage` and `observe` has 1 to 64 letters, digits, dots, underscores or hyphens. The files go into the `--out` directory, with `results.json`. It has the observations, the files and the steps done. If a `runUntil` step did not reach its target, it also tells why the run stopped.
103
+ A name in `save`, `screen`, `coverage`, `observe` and `expect` has 1 to 64 letters, digits, dots, underscores or hyphens. The files go into the `--out` directory, with `results.json`. It has the observations, the expectations, the files and the steps done. If a `runUntil` step did not reach its target, it also tells why the run stopped.
104
+
105
+ ### Expected values
106
+
107
+ An `expect` step compares the memory and the registers with the values that the step gives. It writes no file. Use it to test a program that has no original, for example a new program or a fix.
108
+
109
+ ```json
110
+ { "expect": "title",
111
+ "memory": [
112
+ { "address": "$0400", "text": "HELLO FROM C64" },
113
+ { "address": "score", "data": "0000" },
114
+ { "address": "$d020", "data": "01", "mask": "0f" }
115
+ ],
116
+ "registers": { "pc": "main_loop", "a": 0, "flags": { "i": true } } }
117
+ ```
118
+
119
+ The step has a name, and `memory`, `registers` or both.
120
+
121
+ A memory item has `address` and one of these two keys:
122
+
123
+ - `data`: the bytes as hex. The step compares each byte.
124
+ - `text`: characters on the screen, as screen codes of the upper-case set. The step reads one byte for each character. It compares the text, not the reverse video. A graphics character reads as a dot. Write letters in upper case.
125
+
126
+ A memory item can also have:
127
+
128
+ - `mask`: hex bytes with the same length as `data`. The step compares only the bits that are 1 in the mask. Use it for an I/O register with bits that read as 1, for example `$d020`.
129
+ - `view`: `cpu` (default) or `ram`.
130
+
131
+ A memory item has at most 4096 bytes.
132
+
133
+ `registers` has the fields of a `registers` step: `pc`, `a`, `x`, `y`, `sp` and `flags`. Only `pc` can be a name.
134
+
135
+ A value that is not equal does not stop the run. The later steps run. `results.json` and the result have `expectations`. For each step, it gives `pass` and the count of values that are not equal. It also lists at most 16 of them, with the expected and the actual value. `failedExpectations` names each step that did not pass. The result is FAIL when an expectation did not pass.
104
136
 
105
137
  Example: visit two rooms from the same start.
106
138
 
@@ -1,13 +1,15 @@
1
1
  // The runs of c64-testing: steps in their own emulator, from a program or a
2
2
  // snapshot file, and what the steps ask for written into a folder: screens,
3
3
  // coverage maps, snapshot files, and results.json with the observations. One
4
- // side, no comparison.
4
+ // side, no comparison with another program: an expect step checks the memory
5
+ // and registers against the values that the run file gives.
5
6
 
6
- import { formatC64Address, formatSprite, formatVicii, parseC64Address } from "#src/c64.ts";
7
+ import { formatC64Address, formatC64Byte, formatSprite, formatVicii, parseC64Address } from "#src/c64.ts";
8
+ import { screenText } from "#src/graphics.ts";
7
9
  import { runProgram } from "#src/host-client/autostart.ts";
8
10
  import { isRefusal, Refusal } from "#src/errors.ts";
9
11
  import { readCoverage } from "#src/host-client/coverage.ts";
10
- import { ACTION_STEP_KINDS, checkActionStep, checkStepNames, isInteger, isObject, refuseOldStep, renamedField, runActionStep, VICE_STEP_KINDS, type ActionStep, type ActionStepKind } from "#src/host-client/steps.ts";
12
+ import { ACTION_STEP_KINDS, checkActionStep, checkLocation, checkStepNames, isInteger, isObject, refuseOldStep, renamedField, runActionStep, VICE_STEP_KINDS, type ActionStep, type ActionStepKind } from "#src/host-client/steps.ts";
11
13
  import { readPrg } from "#src/host-client/image.ts";
12
14
  import { MAX_MEMORY_READ, MAX_TRACE_FRAMES, MAX_TRACE_HITS, MAX_TRACE_POINTS, TRACE_KINDS, WireFailure, type TraceHit, type TraceKind } from "#src/host-client/tools.ts";
13
15
  import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
@@ -23,7 +25,27 @@ type RunStep =
23
25
  | { screen: string }
24
26
  | { coverage: string }
25
27
  | { trace: string; points: Array<{ kind: TraceKind; start: string; end?: string }>; frames: number; maxHits?: number }
26
- | { observe: string; memory?: "all" | Array<string | { address: string; size?: number; view?: "cpu" | "ram" }>; registers?: boolean; vicii?: boolean; sprites?: number[] };
28
+ | { observe: string; memory?: "all" | Array<string | { address: string; size?: number; view?: "cpu" | "ram" }>; registers?: boolean; vicii?: boolean; sprites?: number[] }
29
+ | { expect: string; memory?: ExpectedMemory[]; registers?: ExpectedRegisters };
30
+
31
+ /** Expected bytes at an address: hex data, under an optional mask, or text as screen codes. */
32
+ interface ExpectedMemory {
33
+ address: string;
34
+ data?: string;
35
+ text?: string;
36
+ mask?: string;
37
+ view?: "cpu" | "ram";
38
+ }
39
+
40
+ type ExpectedRegisters = Extract<ActionStep, { registers: unknown }>["registers"];
41
+
42
+ /** One value that differs from the expected value. */
43
+ interface Mismatch {
44
+ address?: string;
45
+ register?: string;
46
+ expected: string | number | boolean;
47
+ actual: string | number | boolean;
48
+ }
27
49
 
28
50
  interface Run {
29
51
  name: string;
@@ -33,9 +55,15 @@ interface Run {
33
55
  steps: RunStep[];
34
56
  }
35
57
 
36
- const OWN_KINDS = ["snapshot", "save", "screen", "coverage", "observe", "trace"] as const;
58
+ const OWN_KINDS = ["snapshot", "save", "screen", "coverage", "observe", "expect", "trace"] as const;
37
59
  const TRACE_KEYS = ["trace", "points", "frames", "maxHits"];
38
60
  const OBSERVE_KEYS = ["observe", "memory", "registers", "vicii", "sprites"];
61
+ const EXPECT_KEYS = ["expect", "memory", "registers"];
62
+ const EXPECTED_MEMORY_KEYS = ["address", "data", "text", "mask", "view"];
63
+ /** The characters that screenText gives for the screen codes 0 to 63; a graphics code gives a dot. */
64
+ const SCREEN_TEXT = /^[@A-Z[£\]^< !"#$%&'()*+,\-./0-9:;=>?]+$/;
65
+ /** The most differing bytes that an expectation lists; count gives all of them. */
66
+ const MAX_LISTED_MISMATCHES = 16;
39
67
  /** A name of a file that a step writes: letters, digits, dots, underscores or hyphens. */
40
68
  const NAME = /^[A-Za-z0-9._-]{1,64}$/;
41
69
  /** The file of the observations, which every run writes. */
@@ -96,12 +124,12 @@ function readRun(path: string): Run {
96
124
  (value.steps as unknown[]).forEach((step, index) => {
97
125
  const at = `step ${index + 1}`;
98
126
  if (!isObject(step)) return fail(`${at} must be an object`);
99
- const kinds = "observe" in step ? ["observe"] : "trace" in step ? ["trace"] : Object.keys(step).filter((key) => (ACTION_STEP_KINDS as readonly string[]).includes(key) || (OWN_KINDS as readonly string[]).includes(key));
127
+ const kinds = "observe" in step ? ["observe"] : "expect" in step ? ["expect"] : "trace" in step ? ["trace"] : Object.keys(step).filter((key) => (ACTION_STEP_KINDS as readonly string[]).includes(key) || (OWN_KINDS as readonly string[]).includes(key));
100
128
  if (kinds.length > 1) return fail(`${at} has ${kinds.length} step kinds: ${kinds.join(", ")}. Give each one its own step`);
101
129
  if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...VICE_STEP_KINDS, ...OWN_KINDS].join(", ")}`);
102
130
  const kind = kinds[0]!;
103
131
  refuseOldStep(kind, step, at, fail);
104
- const allowed = kind === "observe" ? OBSERVE_KEYS : kind === "trace" ? TRACE_KEYS : [kind];
132
+ const allowed = kind === "observe" ? OBSERVE_KEYS : kind === "expect" ? EXPECT_KEYS : kind === "trace" ? TRACE_KEYS : [kind];
105
133
  for (const key of Object.keys(step)) if (!allowed.includes(key)) fail(`${at} has the key ${key}, which a ${kind} step does not have`);
106
134
  if ((ACTION_STEP_KINDS as readonly string[]).includes(kind)) {
107
135
  // The step with its defaults filled in, as the shared schema of the action steps gives it.
@@ -129,6 +157,33 @@ function readRun(path: string): Run {
129
157
  if (step.maxHits !== undefined && !isInteger(step.maxHits, 1, MAX_TRACE_HITS)) fail(`${at}: maxHits must be a number from 1 to ${MAX_TRACE_HITS}`);
130
158
  return;
131
159
  }
160
+ if (kind === "expect") {
161
+ if (labels.has(name as string)) fail(`${at} needs a new name`);
162
+ labels.add(name as string);
163
+ if (step.memory === undefined && step.registers === undefined) fail(`${at}: expect needs memory, registers or both`);
164
+ if (step.memory !== undefined) {
165
+ if (!Array.isArray(step.memory) || step.memory.length === 0) return fail(`${at}: memory is a list of objects with address, and data or text`);
166
+ for (const item of step.memory as unknown[]) {
167
+ if (!isObject(item)) return fail(`${at}: memory is a list of objects with address, and data or text`);
168
+ for (const key of Object.keys(item)) if (!EXPECTED_MEMORY_KEYS.includes(key)) fail(`${at}: an expected memory object has the field ${key}. It has address, data or text, mask and view, and nothing else`);
169
+ checkLocation(item.address, `${at}: address`, fail);
170
+ if ((item.data === undefined) === (item.text === undefined)) fail(`${at}: an expected memory object needs data or text, not both`);
171
+ if (item.data !== undefined && (typeof item.data !== "string" || !/^(?:[0-9a-fA-F]{2})+$/.test(item.data))) fail(`${at}: data must be hex bytes, two digits per byte, no separators, for example 0801`);
172
+ if (item.text !== undefined && (typeof item.text !== "string" || !SCREEN_TEXT.test(item.text))) {
173
+ fail(`${at}: text has the characters of the upper-case set: @, A to Z, digits, space, the signs !"#$%&'()*+,-./:;<=>? and [£]^<. Write letters in upper case`);
174
+ }
175
+ const size = typeof item.data === "string" ? item.data.length / 2 : typeof item.text === "string" ? item.text.length : 0;
176
+ if (size > MAX_MEMORY_READ) fail(`${at}: an expected memory object has at most ${MAX_MEMORY_READ} bytes`);
177
+ if (item.mask !== undefined && (item.data === undefined || typeof item.mask !== "string" || !/^(?:[0-9a-fA-F]{2})+$/.test(item.mask) || item.mask.length !== (item.data as string).length)) {
178
+ fail(`${at}: mask needs data, and is hex bytes of the same length as data`);
179
+ }
180
+ if (item.view !== undefined && item.view !== "cpu" && item.view !== "ram") fail(`${at}: view must be cpu or ram`);
181
+ }
182
+ }
183
+ // The registers have the fields of a registers step: only pc can be a name.
184
+ if (step.registers !== undefined) step.registers = (checkActionStep("registers", { registers: step.registers }, at, fail) as { registers: ExpectedRegisters }).registers;
185
+ return;
186
+ }
132
187
  if (kind !== "observe") return;
133
188
  if (labels.has(name as string)) fail(`${at} needs a new observation name`);
134
189
  labels.add(name as string);
@@ -190,7 +245,38 @@ function showHit(hit: TraceHit) {
190
245
  return { ...hit, pc: formatC64Address(hit.pc), ...(hit.address === undefined ? {} : { address: formatC64Address(hit.address) }) };
191
246
  }
192
247
 
193
- /** Runs the run file and writes its files into `out`. failed: a step did not run. */
248
+ /**
249
+ * The values of an expect step that differ: each byte of data (under its
250
+ * mask), the text of screen codes as one string, and each register.
251
+ */
252
+ async function expected(client: ViceSessionClient, step: Extract<RunStep, { expect: string }>, at: (location: string) => number): Promise<Mismatch[]> {
253
+ const mismatches: Mismatch[] = [];
254
+ for (const item of step.memory ?? []) {
255
+ const address = at(item.address);
256
+ if (item.text !== undefined) {
257
+ const actual = screenText(await readMemoryInParts(client, address, item.text.length, item.view ?? "cpu")).join("");
258
+ if (actual !== item.text) mismatches.push({ address: formatC64Address(address), expected: item.text, actual });
259
+ continue;
260
+ }
261
+ const data = Buffer.from(item.data!, "hex");
262
+ const mask = item.mask === undefined ? undefined : Buffer.from(item.mask, "hex");
263
+ const actual = await readMemoryInParts(client, address, data.length, item.view ?? "cpu");
264
+ data.forEach((byte, offset) => {
265
+ const bits = mask?.[offset] ?? 0xff;
266
+ if ((actual[offset]! & bits) !== (byte & bits)) mismatches.push({ address: formatC64Address((address + offset) & 0xffff), expected: formatC64Byte(byte), actual: formatC64Byte(actual[offset]!) });
267
+ });
268
+ }
269
+ if (step.registers !== undefined) {
270
+ const registers = await client.registersGet("c64");
271
+ const { pc, flags, ...bytes } = step.registers;
272
+ if (pc !== undefined && registers.pc !== at(pc)) mismatches.push({ register: "pc", expected: formatC64Address(at(pc)), actual: formatC64Address(registers.pc) });
273
+ for (const [name, value] of Object.entries(bytes) as Array<["a" | "x" | "y" | "sp", number]>) if (registers[name] !== value) mismatches.push({ register: name, expected: value, actual: registers[name] });
274
+ for (const [name, value] of Object.entries(flags ?? {}) as Array<[keyof typeof registers.flags, boolean]>) if (registers.flags[name] !== value) mismatches.push({ register: `flags.${name}`, expected: value, actual: registers.flags[name] });
275
+ }
276
+ return mismatches;
277
+ }
278
+
279
+ /** Runs the run file and writes its files into `out`. failed: a step did not run, or an expect step found a value that differs. */
194
280
  export async function runFile(path: string, out: string): Promise<{ output: Record<string, unknown>; failed: boolean }> {
195
281
  const run = readRun(path);
196
282
  checkRunFiles(path, run);
@@ -206,8 +292,15 @@ export async function runFile(path: string, out: string): Promise<{ output: Reco
206
292
  };
207
293
  // Every name of the steps resolves before the emulator starts. A refusal names the step.
208
294
  run.steps.forEach((step, index) => {
209
- if ("trace" in step || "observe" in step) {
210
- const names = "trace" in step ? step.points.flatMap((point) => [point.start, ...(point.end === undefined ? [] : [point.end])]) : step.memory === undefined || step.memory === "all" ? [] : step.memory.map((item) => (typeof item === "string" ? item : item.address));
295
+ if ("trace" in step || "observe" in step || "expect" in step) {
296
+ const names =
297
+ "trace" in step
298
+ ? step.points.flatMap((point) => [point.start, ...(point.end === undefined ? [] : [point.end])])
299
+ : "expect" in step
300
+ ? [...(step.memory ?? []).map((item) => item.address), ...(step.registers?.pc === undefined ? [] : [step.registers.pc])]
301
+ : step.memory === undefined || step.memory === "all"
302
+ ? []
303
+ : step.memory.map((item) => (typeof item === "string" ? item : item.address));
211
304
  for (const name of names) {
212
305
  try {
213
306
  at(name);
@@ -227,6 +320,7 @@ export async function runFile(path: string, out: string): Promise<{ output: Reco
227
320
  files.push(name);
228
321
  };
229
322
  const observations: Record<string, unknown> = {};
323
+ const expectations: Array<{ expect: string; pass: boolean; count: number; mismatches: Mismatch[] }> = [];
230
324
  const traces: Record<string, unknown> = {};
231
325
  const client = await ViceSessionClient.open({ videoStandard: run.videoStandard ?? "pal" });
232
326
  let done = 0;
@@ -295,6 +389,10 @@ export async function runFile(path: string, out: string): Promise<{ output: Reco
295
389
  if (step.vicii === true) seen.vicii = formatVicii(await client.vicii());
296
390
  if (step.sprites !== undefined) seen.sprites = (await client.sprites(step.sprites)).sprites.map(formatSprite);
297
391
  observations[step.observe] = seen;
392
+ } else if ("expect" in step) {
393
+ // A mismatch does not stop the run: the later steps and expectations still run.
394
+ const mismatches = await expected(client, step, at);
395
+ expectations.push({ expect: step.expect, pass: mismatches.length === 0, count: mismatches.length, mismatches: mismatches.slice(0, MAX_LISTED_MISMATCHES) });
298
396
  } else {
299
397
  const notReached = await runActionStep(client, step, at);
300
398
  if (notReached !== undefined && "runUntil" in step) {
@@ -305,9 +403,21 @@ export async function runFile(path: string, out: string): Promise<{ output: Reco
305
403
  done++;
306
404
  }
307
405
  const pc = (await client.registersGet("c64")).pc;
308
- const results = { name: run.name, completed: reason === undefined, steps: run.steps.length, done, ...(reason === undefined ? {} : { reason }), pc: formatC64Address(pc), files: [...files], observations, ...(Object.keys(traces).length === 0 ? {} : { traces }) };
406
+ const failedExpectations = expectations.filter((item) => !item.pass).map((item) => item.expect);
407
+ const results = {
408
+ name: run.name,
409
+ completed: reason === undefined,
410
+ steps: run.steps.length,
411
+ done,
412
+ ...(reason === undefined ? {} : { reason }),
413
+ pc: formatC64Address(pc),
414
+ files: [...files],
415
+ observations,
416
+ ...(expectations.length === 0 ? {} : { expectations, failedExpectations }),
417
+ ...(Object.keys(traces).length === 0 ? {} : { traces }),
418
+ };
309
419
  write("results.json", Buffer.from(`${JSON.stringify(results, null, 2)}\n`));
310
- return { output: { ...results, files: written, observations: Object.keys(observations), out }, failed: reason !== undefined };
420
+ return { output: { ...results, files: written, observations: Object.keys(observations), out }, failed: reason !== undefined || failedExpectations.length > 0 };
311
421
  } finally {
312
422
  await client.close();
313
423
  }
@@ -131,7 +131,7 @@ const COMMANDS: CommandSpec[] = [
131
131
  },
132
132
  {
133
133
  name: "run",
134
- summary: "Runs the steps of a run file in its own emulator and writes what they ask for into --out: screens, coverage maps, snapshot files, traces, and results.json with the observations. result is FAIL when a step did not run.",
134
+ summary: "Runs the steps of a run file in its own emulator and writes what they ask for into --out: screens, coverage maps, snapshot files, traces, and results.json with the observations and the expectations. result is FAIL when a step did not run or an expect step found a value that differs.",
135
135
  subjects: [{ name: "<run.json>", help: "a run file, relative to the project folder. See references/scenario-format.md, section Runs" }],
136
136
  options: { out: { ...OPTIONS.out, output: "folder", value: "<dir>", required: true, help: "the folder for the files of the steps and results.json" } },
137
137
  run: async (call) => {
package/src/cli/main.ts CHANGED
@@ -29,14 +29,14 @@ Harnesses: claude, codex, pi, opencode, gemini, copilot, cursor, windsurf
29
29
  (comma-separated; default: all). Without --global the files go into the
30
30
  current folder; with --global into your home directory.
31
31
 
32
- Run it once at the root of the repository:
33
- npx -y ${PACKAGE.name}@${PACKAGE.tag} install. Each project folder below
34
- the root uses that install; a project is a folder with .c64-re-tools/. The
35
- VICE MCP declaration starts the latest c64-re-tools-mcp through npx. The Host
36
- Runtime runs on the machine with VICE: start it there with
37
- npx -y --package=${PACKAGE.name}@${PACKAGE.tag} c64-re-tools-host.
32
+ The dev container Feature of c64-re-tools runs install at the root of the
33
+ repository when it creates the container, and update at each start. Each
34
+ project folder below the root uses that install; a project is a folder with
35
+ .c64-re-tools/. The VICE MCP declaration starts the latest c64-re-tools-mcp
36
+ through npx. The Host Runtime runs on the machine with VICE: start it there
37
+ with npx -y --package=${PACKAGE.name}@${PACKAGE.tag} c64-re-tools-host.
38
38
  It runs VICE and the tools that come with it (c1541, petcat). The skill
39
- scripts run ACME, DXA and Ghidra themselves, on the machine of the agent.`;
39
+ scripts run ACME, DXA, Ghidra and c64run in the dev container.`;
40
40
 
41
41
  const here = dirname(fileURLToPath(import.meta.url));
42
42
 
@@ -127,7 +127,7 @@ export class C64RunSession {
127
127
  if (error instanceof WireFailure && /no ROM/.test(error.message)) {
128
128
  throw new WireFailure(
129
129
  "installation-incomplete",
130
- `${error.message}. c64run needs the C64 ROMs kernal-901227-03.bin, basic-901226-01.bin and chargen-901225-01.bin: set C64RT_C64_ROMS to a folder with them (the C64 folder of VICE has them). ${INSTALL_STEPS}`,
130
+ `${error.message}. c64run needs the C64 ROMs kernal-901227-03.bin, basic-901226-01.bin and chargen-901225-01.bin. ${INSTALL_STEPS}`,
131
131
  );
132
132
  }
133
133
  throw error;
@@ -7,8 +7,8 @@ import { isAbsolute, join, posix, win32 } from "node:path";
7
7
 
8
8
  import { WireFailure } from "../protocol/messages.ts";
9
9
 
10
- /** Where the user finds the install steps of the native tools for each system. */
11
- export const INSTALL_STEPS = "Steps for each system: https://github.com/henols/c64-re-tools/blob/main/docs/install-tools.md. In the dev container of c64-re-tools, restart the container: each start installs the tools of the toolkit version.";
10
+ /** The remedy for a missing native tool: the dev container of c64-re-tools installs every one. */
11
+ export const INSTALL_STEPS = "The dev container of c64-re-tools installs it at each start: restart the container, or rebuild it. Without that dev container, set it up as https://github.com/henols/c64-re-tools#dev-container tells.";
12
12
 
13
13
  export interface ToolSpec {
14
14
  /** Human name, for messages. */
@@ -28,7 +28,7 @@ export const ACME: ToolSpec = {
28
28
  envVar: "C64RT_ACME",
29
29
  binaries: ["acme"],
30
30
  where: "on this machine",
31
- remedy: `Install the ACME cross-assembler on the machine that runs the skill scripts so that acme is on PATH, or set C64RT_ACME to its full path. ${INSTALL_STEPS}`,
31
+ remedy: INSTALL_STEPS,
32
32
  };
33
33
 
34
34
  export const C1541: ToolSpec = {
@@ -52,7 +52,7 @@ export const DXA: ToolSpec = {
52
52
  envVar: "C64RT_DXA",
53
53
  binaries: ["dxa"],
54
54
  where: "on this machine",
55
- remedy: `Install dxa 0.1.5 on the machine that runs the skill scripts so that dxa is on PATH, or set C64RT_DXA to its full path. ${INSTALL_STEPS}`,
55
+ remedy: INSTALL_STEPS,
56
56
  };
57
57
 
58
58
  export const C64RUN: ToolSpec = {
@@ -60,7 +60,7 @@ export const C64RUN: ToolSpec = {
60
60
  envVar: "C64RT_C64RUN",
61
61
  binaries: ["c64run"],
62
62
  where: "on this machine",
63
- remedy: `Install c64run (the replay core of c64-testing, with its C64 ROMs) on the machine that runs the skill scripts so that c64run is on PATH, or set C64RT_C64RUN to its full path. ${INSTALL_STEPS}`,
63
+ remedy: INSTALL_STEPS,
64
64
  };
65
65
 
66
66
  export const VICE: ToolSpec = {
@@ -21,10 +21,6 @@ export const GHIDRA_LANGUAGE = "C64RT_6510:LE:16:nmos";
21
21
  export const LANGUAGE_DIRECTORY = fileURLToPath(new URL("./language/", import.meta.url));
22
22
  export const SCRIPT_DIRECTORY = fileURLToPath(new URL("./scripts/", import.meta.url));
23
23
 
24
- const REMEDY =
25
- "Install Ghidra on the machine that runs the skill scripts and set C64RT_GHIDRA to its installation directory " +
26
- `(the directory that holds support/analyzeHeadless), or put analyzeHeadless on PATH. ${INSTALL_STEPS}`;
27
-
28
24
  export interface GhidraInstallation {
29
25
  /** The installation directory. */
30
26
  root: string;
@@ -46,12 +42,12 @@ function installationAt(root: string, source: string): GhidraInstallation {
46
42
  if (!isExecutableFile(analyzeHeadless)) throw new Refusal("operation-failed", "no analyzeHeadless");
47
43
  properties = readFileSync(join(root, "Ghidra", "application.properties"), "utf8");
48
44
  } catch {
49
- throw new WireFailure("installation-incomplete", `${source} does not point to a Ghidra installation. ${REMEDY}`);
45
+ throw new WireFailure("installation-incomplete", `${source} does not point to a Ghidra installation. ${INSTALL_STEPS}`);
50
46
  }
51
47
  const value = (key: string) => new RegExp(`^${key.replace(/\./g, "\\.")}=(.*)$`, "m").exec(properties)?.[1]?.trim();
52
48
  const version = value("application.version");
53
49
  const release = value("application.release.name");
54
- if (version === undefined || release === undefined) throw new WireFailure("installation-incomplete", `The Ghidra installation at ${source} has no version. ${REMEDY}`);
50
+ if (version === undefined || release === undefined) throw new WireFailure("installation-incomplete", `The Ghidra installation at ${source} has no version. ${INSTALL_STEPS}`);
55
51
  const javaMin = value("application.java.min");
56
52
  return { root, analyzeHeadless, settingsName: `ghidra_${version}_${release}`, version, ...(javaMin === undefined || javaMin === "" ? {} : { javaMin }) };
57
53
  }
@@ -65,12 +61,12 @@ export function ghidraVersion(ghidra: GhidraInstallation): string {
65
61
  export function findGhidra(env: NodeJS.ProcessEnv = process.env): GhidraInstallation {
66
62
  const configured = env.C64RT_GHIDRA;
67
63
  if (configured !== undefined && configured !== "") {
68
- if (!isAbsolute(configured)) throw new WireFailure("installation-incomplete", `C64RT_GHIDRA on this machine is not an absolute path. ${REMEDY}`);
64
+ if (!isAbsolute(configured)) throw new WireFailure("installation-incomplete", `C64RT_GHIDRA on this machine is not an absolute path. ${INSTALL_STEPS}`);
69
65
  return installationAt(configured, "C64RT_GHIDRA");
70
66
  }
71
67
  const found = findOnPath(["analyzeHeadless"], env, [LAUNCHER_SUFFIX]);
72
68
  if (found !== undefined) return installationAt(resolve(dirname(realpathSync(found)), ".."), "analyzeHeadless on PATH");
73
- throw new WireFailure("installation-incomplete", `Ghidra is not installed on this machine. ${REMEDY}`);
69
+ throw new WireFailure("installation-incomplete", `Ghidra is not installed on this machine. ${INSTALL_STEPS}`);
74
70
  }
75
71
 
76
72
  /**
@@ -135,7 +131,7 @@ export function noJdk(ghidra: GhidraInstallation): WireFailure {
135
131
  const java = ghidra.javaMin === undefined ? "a JDK" : `JDK ${ghidra.javaMin} or later`;
136
132
  return new WireFailure(
137
133
  "installation-incomplete",
138
- `${ghidraVersion(ghidra)} found no Java that it can use. It needs ${java}. Install it on the machine that runs the skill scripts and put its java on PATH, or set JAVA_HOME to it. ${INSTALL_STEPS}`,
134
+ `${ghidraVersion(ghidra)} found no Java that it can use. It needs ${java}. ${INSTALL_STEPS}`,
139
135
  );
140
136
  }
141
137
 
@@ -114,7 +114,7 @@ export async function probeC64run(context: ToolContext): Promise<ToolStatus> {
114
114
  context,
115
115
  (output) => {
116
116
  const missing = /^roms=missing (.*)$/m.exec(output)?.[1];
117
- return missing === undefined ? undefined : `It has no C64 ROMs: ${missing}. Set C64RT_C64_ROMS to a folder with kernal-901227-03.bin, basic-901226-01.bin and chargen-901225-01.bin (the C64 folder of VICE has them). ${INSTALL_STEPS}`;
117
+ return missing === undefined ? undefined : `It has no C64 ROMs: ${missing}. ${INSTALL_STEPS}`;
118
118
  },
119
119
  );
120
120
  } catch (error) {
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  # Builds c64run, the replay core of c64-testing: floooh/chips c64.h at a pinned
3
3
  # commit with the line-command harness c64run.c next to this script. Installs
4
- # $PREFIX/bin/c64run and the three C64 ROMs that it loads to
5
- # $PREFIX/share/c64-re-tools/roms (PREFIX: /usr/local). Debian, Ubuntu, macOS.
4
+ # /usr/local/bin/c64run and the three C64 ROMs that it loads to
5
+ # /usr/local/share/c64-re-tools/roms. install-container.sh runs it as root,
6
+ # with a C compiler and curl.
6
7
 
7
8
  set -Eeuo pipefail
8
9
 
@@ -17,7 +18,7 @@ ROMS=(
17
18
  "basic.901226-01.bin basic-901226-01.bin 89878cea0a268734696de11c4bae593eaaa506465d2029d619c0e0cbccdfa62d"
18
19
  "characters.901225-01.bin chargen-901225-01.bin fd0d53b8480e86163ac98998976c72cc58d5dd8eb824ed7b829774e74213b420"
19
20
  )
20
- PREFIX="${PREFIX:-/usr/local}"
21
+ PREFIX="/usr/local"
21
22
  HERE="$(cd "$(dirname "$0")" && pwd)"
22
23
 
23
24
  fail() {
@@ -25,20 +26,10 @@ fail() {
25
26
  exit 1
26
27
  }
27
28
 
28
- if [[ "$(id -u)" -eq 0 || -w "${PREFIX}" ]]; then SUDO=""; else SUDO="sudo"; fi
29
-
30
- CC="${CC:-$(command -v gcc || command -v cc || true)}"
31
- if [[ -z "${CC}" ]] || ! command -v curl >/dev/null 2>&1; then
32
- command -v apt-get >/dev/null 2>&1 || fail "a C compiler and curl are needed."
33
- ${SUDO} apt-get update
34
- ${SUDO} apt-get install -y --no-install-recommends build-essential ca-certificates curl
35
- CC=gcc
36
- fi
29
+ [[ "$(id -u)" -eq 0 ]] || fail "run as root."
37
30
 
38
31
  check() {
39
- local sum
40
- if command -v sha256sum >/dev/null 2>&1; then sum="$(sha256sum "$2" | cut -d' ' -f1)"; else sum="$(shasum -a 256 "$2" | cut -d' ' -f1)"; fi
41
- [[ "${sum}" == "$1" ]]
32
+ [[ "$(sha256sum "$2" | cut -d' ' -f1)" == "$1" ]]
42
33
  }
43
34
 
44
35
  BUILD_DIR="$(mktemp -d -t c64run-build-XXXXXXXX)"
@@ -55,12 +46,12 @@ for rom in "${ROMS[@]}"; do
55
46
  check "${sha}" "${BUILD_DIR}/roms/${name}" || fail "the ROM ${name} has the wrong checksum."
56
47
  done
57
48
 
58
- "${CC}" -O2 -Wall -Wno-unused-function -DCHIPS_COMMIT="\"${CHIPS_COMMIT:0:12}\"" \
49
+ gcc -O2 -Wall -Wno-unused-function -DCHIPS_COMMIT="\"${CHIPS_COMMIT:0:12}\"" \
59
50
  -I "${BUILD_DIR}/chips-${CHIPS_COMMIT}" -o "${BUILD_DIR}/c64run" "${HERE}/c64run.c"
60
51
  started="$(printf 'init %s\nquit\n' "${BUILD_DIR}/roms" | "${BUILD_DIR}/c64run")"
61
52
  [[ "${started}" == ok*pc=fce2* ]] || fail "the compiled c64run does not reach the reset vector: ${started}"
62
53
 
63
- ${SUDO} install -d -m 0755 "${PREFIX}/bin" "${PREFIX}/share/c64-re-tools/roms"
64
- ${SUDO} install -m 0755 "${BUILD_DIR}/c64run" "${PREFIX}/bin/c64run"
65
- ${SUDO} install -m 0644 "${BUILD_DIR}"/roms/*.bin "${PREFIX}/share/c64-re-tools/roms/"
54
+ install -d -m 0755 "${PREFIX}/bin" "${PREFIX}/share/c64-re-tools/roms"
55
+ install -m 0755 "${BUILD_DIR}/c64run" "${PREFIX}/bin/c64run"
56
+ install -m 0644 "${BUILD_DIR}"/roms/*.bin "${PREFIX}/share/c64-re-tools/roms/"
66
57
  echo "c64run (chips ${CHIPS_COMMIT:0:12}) is installed in ${PREFIX}/bin/c64run, its ROMs in ${PREFIX}/share/c64-re-tools/roms."
@@ -3,7 +3,8 @@
3
3
  set -Eeuo pipefail
4
4
 
5
5
  # ------------------------------------------------------------
6
- # dxa installer for Debian / Ubuntu
6
+ # dxa installer. install-container.sh runs it as root, with build-essential
7
+ # and curl.
7
8
  #
8
9
  # Installs:
9
10
  # /usr/local/bin/dxa
@@ -59,39 +60,10 @@ trap cleanup EXIT
59
60
 
60
61
 
61
62
  # ------------------------------------------------------------
62
- # Check platform
63
+ # Check user
63
64
  # ------------------------------------------------------------
64
65
 
65
- if [[ ! -f /etc/os-release ]]; then
66
- error "This script is intended for Debian/Ubuntu-style Linux systems."
67
- fi
68
-
69
- # shellcheck disable=SC1091
70
- source /etc/os-release
71
-
72
- case "${ID:-}" in
73
- debian|ubuntu)
74
- ;;
75
- *)
76
- if [[ "${ID_LIKE:-}" != *debian* ]]; then
77
- error "Unsupported distribution: ${ID:-unknown}. This script expects Debian or Ubuntu."
78
- fi
79
- ;;
80
- esac
81
-
82
-
83
- # ------------------------------------------------------------
84
- # Determine sudo command
85
- # ------------------------------------------------------------
86
-
87
- if [[ "$(id -u)" -eq 0 ]]; then
88
- SUDO=""
89
- else
90
- command -v sudo >/dev/null 2>&1 ||
91
- error "sudo is required when the script is not run as root."
92
-
93
- SUDO="sudo"
94
- fi
66
+ [[ "$(id -u)" -eq 0 ]] || error "Run as root."
95
67
 
96
68
 
97
69
  # ------------------------------------------------------------
@@ -112,20 +84,6 @@ It will NOT install xa or xa65.
112
84
  EOF
113
85
 
114
86
 
115
- # ------------------------------------------------------------
116
- # Install build requirements
117
- # ------------------------------------------------------------
118
-
119
- info "Installing build requirements"
120
-
121
- ${SUDO} apt-get update
122
-
123
- ${SUDO} apt-get install -y --no-install-recommends \
124
- build-essential \
125
- ca-certificates \
126
- curl
127
-
128
-
129
87
  # ------------------------------------------------------------
130
88
  # Create temporary build directory
131
89
  # ------------------------------------------------------------
@@ -260,9 +218,9 @@ echo "Compiled dxa binary runs."
260
218
 
261
219
  info "Installing dxa"
262
220
 
263
- ${SUDO} install -d -m 0755 "${BIN_DIR}"
221
+ install -d -m 0755 "${BIN_DIR}"
264
222
 
265
- ${SUDO} install \
223
+ install \
266
224
  -m 0755 \
267
225
  "${DXA_BINARY}" \
268
226
  "${BIN_DIR}/dxa"
@@ -284,15 +242,15 @@ if [[ -n "${DXA_MANPAGE}" ]]; then
284
242
 
285
243
  info "Installing dxa manual page"
286
244
 
287
- ${SUDO} install -d -m 0755 "${MAN_DIR}"
245
+ install -d -m 0755 "${MAN_DIR}"
288
246
 
289
- ${SUDO} install \
247
+ install \
290
248
  -m 0644 \
291
249
  "${DXA_MANPAGE}" \
292
250
  "${MAN_DIR}/dxa.1"
293
251
 
294
252
  if command -v mandb >/dev/null 2>&1; then
295
- ${SUDO} mandb -q || true
253
+ mandb -q || true
296
254
  fi
297
255
  else
298
256
  echo
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env bash
2
- # Installs Ghidra in $DEST/ghidra_<version>_PUBLIC (DEST: /opt) and points
3
- # $DEST/ghidra at it, so that C64RT_GHIDRA=$DEST/ghidra stays the same when
4
- # the version changes. Removes the Ghidra versions that it installed before.
5
- # Ghidra needs Java 21. Debian and Ubuntu.
2
+ # Installs Ghidra in /opt/ghidra_<version>_PUBLIC and points /opt/ghidra at
3
+ # it, so that C64RT_GHIDRA=/opt/ghidra stays the same when the version
4
+ # changes. Removes the Ghidra versions that it installed before. Ghidra needs
5
+ # Java 21. install-container.sh runs it as root.
6
6
 
7
7
  set -Eeuo pipefail
8
8
 
@@ -10,7 +10,7 @@ GHIDRA_VERSION="12.1.3"
10
10
  GHIDRA_ZIP="ghidra_${GHIDRA_VERSION}_PUBLIC_20260817.zip"
11
11
  GHIDRA_URL="https://github.com/NationalSecurityAgency/ghidra/releases/download/Ghidra_${GHIDRA_VERSION}_build/${GHIDRA_ZIP}"
12
12
  GHIDRA_SHA256="93a5d11a9ad510622acaaf908c556a7b9b764d338e78a7567f3689bf5081fd54"
13
- DEST="${DEST:-/opt}"
13
+ DEST="/opt"
14
14
  GHIDRA_DIR="${DEST}/ghidra_${GHIDRA_VERSION}_PUBLIC"
15
15
 
16
16
  fail() {
@@ -18,7 +18,7 @@ fail() {
18
18
  exit 1
19
19
  }
20
20
 
21
- [[ "$(id -u)" -eq 0 || -w "${DEST}" ]] || fail "run as root, or set DEST to a folder that you can write."
21
+ [[ "$(id -u)" -eq 0 ]] || fail "run as root."
22
22
 
23
23
  if [[ ! -d "${GHIDRA_DIR}" ]]; then
24
24
  BUILD_DIR="$(mktemp -d -t ghidra-XXXXXXXX)"