@henols/c64-re-tools 2.2.0-rc.1 → 2.2.0-rc.3
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 +30 -41
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +1 -0
- package/skills/c64-assembler/scripts/assembler.ts +2 -9
- package/skills/c64-development/SKILL.md +180 -0
- package/skills/c64-export/SKILL.md +87 -0
- package/skills/c64-provenance/scripts/lib/leftovers.ts +1 -1
- package/skills/c64-provenance/scripts/provenance.ts +1 -1
- package/skills/c64-reverse-engineering/SKILL.md +4 -0
- package/skills/c64-source/SKILL.md +88 -1
- package/skills/c64-source/scripts/lib/export.ts +471 -0
- package/skills/c64-source/scripts/source.ts +432 -64
- package/skills/c64-testing/SKILL.md +5 -3
- package/skills/c64-testing/references/scenario-format.md +34 -2
- package/skills/c64-testing/scripts/lib/runs.ts +122 -12
- package/skills/c64-testing/scripts/testing.ts +1 -1
- package/src/cli/main.ts +7 -7
- package/src/knowledge/program.ts +1 -1
- package/{skills/c64-provenance/scripts/lib → src/knowledge}/separate.ts +35 -21
- package/src/native/acme.ts +11 -0
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +5 -5
- package/src/native/ghidra/index.ts +5 -9
- package/src/native/status.ts +1 -1
- package/src/project.ts +25 -1
- package/src/zip.ts +89 -0
- package/tools/install-chips.sh +10 -19
- package/tools/install-dxa.sh +9 -51
- package/tools/install-ghidra.sh +6 -6
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
|
|
40
|
-
|
|
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
|
|
47
|
+
with its ROM files. Use the latest VICE release.
|
|
46
48
|
|
|
47
|
-
Start the Host Runtime
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
|
|
90
|
-
|
|
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:
|
|
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,9 @@ 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-
|
|
113
|
+
| c64-development | Writes new programs, and adds features and fixes, with tests that give PASS or FAIL. |
|
|
114
|
+
| c64-export | Exports a rebuilt program as the start of a new program: one value per switch, no unused code, a zip file. |
|
|
115
|
+
| c64-testing | Runs scenarios: original against rebuild, or many steps on one program with expected values. |
|
|
129
116
|
| c64-disk | Directory, BAM, entries, sector chains and extraction of disk images. |
|
|
130
117
|
| c64-basic | BASIC V2 listings and the SYS/USR handoff to machine code. |
|
|
131
118
|
| c64-unpacker | Packing evidence, and capture of the unpacked program. |
|
|
@@ -138,12 +125,12 @@ program its own folder. A folder with `.c64-re-tools/` is a project.
|
|
|
138
125
|
|
|
139
126
|
## Settings
|
|
140
127
|
|
|
128
|
+
Set the host variables where the Host Runtime starts, and the others in
|
|
129
|
+
`containerEnv` of the `devcontainer.json`.
|
|
130
|
+
|
|
141
131
|
| Variable | Meaning |
|
|
142
132
|
| --- | --- |
|
|
143
133
|
| `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
134
|
| `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
135
|
| `C64RT_VIDEO` | `pal` (default) or `ntsc`. |
|
|
149
136
|
| `C64RT_TRACE` | A directory for a trace of a run. See [docs/debug-install.md](docs/debug-install.md). |
|
|
@@ -159,7 +146,9 @@ pnpm test
|
|
|
159
146
|
pnpm host # the Host Runtime from this checkout
|
|
160
147
|
```
|
|
161
148
|
|
|
162
|
-
Tests that need real tools are skipped unless you turn them on
|
|
149
|
+
Tests that need real tools are skipped unless you turn them on. On Debian or
|
|
150
|
+
Ubuntu, `sudo bash tools/install-container.sh` installs ACME, dxa, c64run and
|
|
151
|
+
Ghidra (in `/opt/ghidra`, with Java 21 from you), as the dev container does:
|
|
163
152
|
|
|
164
153
|
```
|
|
165
154
|
C64RT_LIVE_VICE=/usr/bin/x64sc C64RT_GHIDRA=/opt/ghidra pnpm test
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
|
12
12
|
import { requireProgram } from "#src/knowledge/program.ts";
|
|
13
13
|
import { releaseLabeled } from "#src/knowledge/read.ts";
|
|
14
14
|
import { RELEASE_DEFINE } from "#src/knowledge/schema.ts";
|
|
15
|
-
import { assemble } from "#src/native/acme.ts";
|
|
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
18
|
import { listed as listedItems, OPTIONS, runScript, UsageError } from "#src/script.ts";
|
|
@@ -28,13 +28,6 @@ function parseDefine(text: string): [string, number | boolean] {
|
|
|
28
28
|
throw new UsageError(`--define ${match[1]} needs an integer or true/false, not ${value}`);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
/** A symbol of the build: an address as $ and four hex digits, a constant as $ and at least four hex digits. */
|
|
32
|
-
function showSymbol(symbol: AssembledSymbol) {
|
|
33
|
-
return symbol.kind === "address"
|
|
34
|
-
? { name: symbol.name, kind: "address", address: formatC64Address(symbol.address), used: symbol.used }
|
|
35
|
-
: { name: symbol.name, kind: "constant", value: `$${symbol.value.toString(16).padStart(4, "0")}`, used: symbol.used };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
31
|
await runScript({
|
|
39
32
|
name: "assembler",
|
|
40
33
|
summary: "Assembles project source with ACME and writes the program into the project.",
|
|
@@ -114,7 +107,7 @@ await runScript({
|
|
|
114
107
|
...(plain ? { plain: true } : {}),
|
|
115
108
|
loadRange: { start: formatC64Address(range.start), end: formatC64Address(range.end), bytes: range.bytes },
|
|
116
109
|
symbols: listedItems(shown, call.count("max-listed")!, showSymbol, "a larger --max-listed, or --out-symbols <file.json> for the whole list"),
|
|
117
|
-
...(symbolsPath === undefined ? {} : { symbolsFile: writeReported(symbolsPath,
|
|
110
|
+
...(symbolsPath === undefined ? {} : { symbolsFile: writeReported(symbolsPath, symbolsFileText(shown), { what: "--out-symbols" }) }),
|
|
118
111
|
...(all ? {} : { unusedConstants: result.symbols!.length - shown.length }),
|
|
119
112
|
diagnostics: result.diagnostics,
|
|
120
113
|
...(compared === undefined ? {} : { compare: compared }),
|
|
@@ -0,0 +1,180 @@
|
|
|
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. A project from the c64-export skill also takes 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
|
|
180
|
+
- The start of a new program from a rebuilt program → c64-export
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: c64-export
|
|
3
|
+
description: Use this skill to export a rebuilt C64 program as the start of a new program. The export sets each switch to one value in the code. Corrections, trainers and cheats are in, and copy protection and crack changes are out. It removes code and data that nothing uses. It writes a new project folder with the source, a baseline program, the tests and a small knowledge, and a zip file of the folder. Use it for requests such as "export the project", "start a new game from this rebuild" or "make a clean package of the code". Do not use it to change the rebuild. Use c64-development for that.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# c64-export
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Make the start of a new program from a rebuilt program. The new program is a new project. A person changes its source directly.
|
|
11
|
+
|
|
12
|
+
This skill does not change the rebuilt project or its knowledge.
|
|
13
|
+
|
|
14
|
+
## Inputs
|
|
15
|
+
|
|
16
|
+
- A rebuilt project: `source.ts generate` of the c64-source skill gives PASS.
|
|
17
|
+
- The folder of the new project. It must be new or empty, and no project can hold it. Use a folder beside the project, for example `../game-new`.
|
|
18
|
+
- Optional: the coverage of the runs in the knowledge. Without coverage, nothing becomes free by itself.
|
|
19
|
+
|
|
20
|
+
## Tools / execution path
|
|
21
|
+
|
|
22
|
+
This skill uses the other skills. It does not use the host runtime directly.
|
|
23
|
+
|
|
24
|
+
| Work | Skill |
|
|
25
|
+
|---|---|
|
|
26
|
+
| The export | c64-source: `source.ts export` |
|
|
27
|
+
| The switches and the code at an address | c64-knowledge |
|
|
28
|
+
| The build of the new project | c64-assembler |
|
|
29
|
+
| The tests of the new project | c64-testing |
|
|
30
|
+
|
|
31
|
+
## Workflow
|
|
32
|
+
|
|
33
|
+
1. Run `source.ts generate --out src` of c64-source. It must give PASS. If it does not, stop and complete the rebuild with the c64-reverse-engineering skill.
|
|
34
|
+
2. Read the switches with `knowledge.ts switches` of c64-knowledge. Tell the user the export value of each switch:
|
|
35
|
+
- `fix`, `trainer` and `cheat`: 1. The code becomes a part of the new program.
|
|
36
|
+
- `protection` and `crack`: 0.
|
|
37
|
+
- `change`: its default.
|
|
38
|
+
|
|
39
|
+
If the user wants another value for a switch, change its kind or its default with `knowledge.ts switch` first.
|
|
40
|
+
3. Run `source.ts export --to <folder>` of c64-source.
|
|
41
|
+
4. Read `unreachableExecuted`. Each range is code that a run executed and that the entry does not get to now. For each range, find the code that calls it with c64-knowledge:
|
|
42
|
+
- Only code that the export removed calls it, for example a copy check: drop it.
|
|
43
|
+
- Code that the knowledge does not show can call it, for example through a pointer: keep it.
|
|
44
|
+
- If you are not sure, ask the user.
|
|
45
|
+
5. To drop a range, remove the folder and the zip file of the export. Then run `source.ts export` again with `--drop '<range>'` for each range.
|
|
46
|
+
6. Build the new project with c64-assembler. Give `--project <folder>`. Use the build commands in its `README.md`. The build with `--compare` must give PASS.
|
|
47
|
+
7. Run each test of the new project with c64-testing. Give `--project <folder>`. Use the test commands in its `README.md`. Each test must give PASS.
|
|
48
|
+
|
|
49
|
+
### The answer
|
|
50
|
+
|
|
51
|
+
Give the user a short answer at the end:
|
|
52
|
+
|
|
53
|
+
1. The folder and the zip file.
|
|
54
|
+
2. The value of each switch.
|
|
55
|
+
3. The free ranges, with their bytes.
|
|
56
|
+
4. Each test and its result, and the tests that the export left out, with the reason.
|
|
57
|
+
5. The next step: the c64-development skill, path B.
|
|
58
|
+
|
|
59
|
+
## Knowledge
|
|
60
|
+
|
|
61
|
+
Read:
|
|
62
|
+
|
|
63
|
+
- the switches, and the code at the addresses of `unreachableExecuted`.
|
|
64
|
+
|
|
65
|
+
Automatic write:
|
|
66
|
+
|
|
67
|
+
- none in the rebuilt project. The export writes the knowledge of the new project.
|
|
68
|
+
|
|
69
|
+
## Result
|
|
70
|
+
|
|
71
|
+
A new project folder and a zip file of it. Its build is identical to its baseline, and each of its tests gives PASS.
|
|
72
|
+
|
|
73
|
+
## Failure and conflicts
|
|
74
|
+
|
|
75
|
+
- `export` gives FAIL with `stage`: read `reason`. The c64-source skill tells what to do for each stage.
|
|
76
|
+
- `export` refuses the folder: give a new or empty folder outside every project. Remove a folder or a zip file of an earlier export only when this task made it.
|
|
77
|
+
- A test of the new project gives FAIL: the export dropped a range that the program uses. Remove the folder and the zip file. Run `export` again with `--keep` for the range, then test again.
|
|
78
|
+
- 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 make a replacement for the tool or the host runtime.
|
|
79
|
+
|
|
80
|
+
## Handoffs
|
|
81
|
+
|
|
82
|
+
- The rebuild is not complete → c64-reverse-engineering
|
|
83
|
+
- The export → c64-source
|
|
84
|
+
- Switches and the code at an address → c64-knowledge
|
|
85
|
+
- The build of the new project → c64-assembler
|
|
86
|
+
- The tests of the new project → c64-testing
|
|
87
|
+
- A new feature or a fix in the new project → c64-development
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { type AddressRange, basicLineText } from "#src/c64.ts";
|
|
10
10
|
import { MNEMONICS } from "#src/opcodes.ts";
|
|
11
|
-
import type { Access, Separation } from "
|
|
11
|
+
import type { Access, Separation } from "#src/knowledge/separate.ts";
|
|
12
12
|
|
|
13
13
|
export interface LeftoversInput {
|
|
14
14
|
segments: AddressRange[];
|
|
@@ -47,7 +47,7 @@ import { compareReleases, identicalShare, shiftSuggestion, suggestShifts, type R
|
|
|
47
47
|
import { findRoutine, libraryFolder, readLibrary, routineFrom, saveRoutine, suggest } from "./lib/library.ts";
|
|
48
48
|
import { watchRelease, type Start } from "./lib/runtime.ts";
|
|
49
49
|
import { findLeftovers } from "./lib/leftovers.ts";
|
|
50
|
-
import { separate, type Root } from "
|
|
50
|
+
import { separate, type Root } from "#src/knowledge/separate.ts";
|
|
51
51
|
|
|
52
52
|
const hexBytes = (bytes: number[]) => Buffer.from(bytes).toString("hex").replace(/(..)(?!$)/g, "$1 ");
|
|
53
53
|
|
|
@@ -185,3 +185,7 @@ 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 correction of the rebuilt program → c64-development
|
|
190
|
+
|
|
191
|
+
The start of a new program from the rebuilt program → c64-export
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-source
|
|
3
|
-
description: Use this skill to generate ACME source code for a C64 program from the project knowledge. The knowledge holds the program, its entry state, the coverage and the names. The script runs Ghidra for the instructions and writes the source files. It checks with ACME that the source assembles to the same bytes as the program. It can also write a loader that sets the entry state of an unpacked program. Use it to make a rebuild. Do not edit the generated files. Change the knowledge and generate again.
|
|
3
|
+
description: Use this skill to generate ACME source code for a C64 program from the project knowledge. The knowledge holds the program, its entry state, the coverage and the names. The script runs Ghidra for the instructions and writes the source files. It checks with ACME that the source assembles to the same bytes as the program. It can also write a loader that sets the entry state of an unpacked program. It can also export the program as the start of a new program. The export is a new project with one value for each switch and without unused code. Use it to make a rebuild. Do not edit the generated files. Change the knowledge and generate again.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# c64-source
|
|
@@ -137,6 +137,88 @@ The script simulates the copies first. Then it runs `loader.prg` in the emulator
|
|
|
137
137
|
|
|
138
138
|
The entry state is the state of the base release. Thus the script builds and checks `loader.prg` with the switch values of the base release. For a loader of the default build, build `loader.asm` with the c64-assembler skill and no option.
|
|
139
139
|
|
|
140
|
+
## Export for a new application
|
|
141
|
+
|
|
142
|
+
`export` writes the program of the knowledge as the start of a new program: a new project folder and a zip file of it. A person changes the source of the new project directly. The c64-export skill gives the full procedure.
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
node <skill>/scripts/source.ts export --to ../game-new
|
|
146
|
+
node <skill>/scripts/source.ts export --to ../game-new --name game --drop '$081b-$0822'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
| Option | Meaning |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `--to ../game-new` | The folder of the new project, relative to the project folder. The folder must be new or empty, and no project can hold it. The script also writes `../game-new.zip`. |
|
|
152
|
+
| `--name game` | The name of `baseline/game.prg` and `build/game.prg`. The default is the name of the folder. |
|
|
153
|
+
| `--keep '$2000-$20ff'` | A range that stays, also when nothing uses it. Use it again for more ranges. |
|
|
154
|
+
| `--drop '$081b-$0822'` | A range that becomes free. Use it again for more ranges. Code that stays must not go to the range or read it. |
|
|
155
|
+
| `--max-listed 20` | List at most this number of items in each list. The default is 50. |
|
|
156
|
+
|
|
157
|
+
The script does these steps. It writes nothing until all the checks pass.
|
|
158
|
+
|
|
159
|
+
1. It builds the source of the base release. The build must give the program byte by byte, with all the patches.
|
|
160
|
+
2. It sets each switch to its export value:
|
|
161
|
+
- `fix`, `trainer` and `cheat`: 1. Trainers and cheats become a part of the new program.
|
|
162
|
+
- `protection` and `crack`: 0.
|
|
163
|
+
- `change`: its default.
|
|
164
|
+
3. It builds the program with these values. This build can change bytes only in the patches.
|
|
165
|
+
4. It finds the free ranges. Each free range gets the bytes $00 and the label `free_xxxx`. No address moves.
|
|
166
|
+
5. It makes the source of the new program. ACME must assemble the source to the new program byte by byte. For a capture with an entry state, the script also makes `loader.asm` and simulates its copies. It does not run the loader in the emulator.
|
|
167
|
+
6. It writes the new project and the zip file.
|
|
168
|
+
|
|
169
|
+
### The free ranges
|
|
170
|
+
|
|
171
|
+
The script divides the decoded instructions into blocks. A block stops after RTS, RTI, JMP, BRK or a JAM, and before a gap. A block of code becomes free only when both of these are true:
|
|
172
|
+
|
|
173
|
+
- No run of the coverage executed it.
|
|
174
|
+
- No path gets to it from the entry, the hardware vectors or the code that stays. A path is a call, a jump, a branch, a reference of the knowledge or an operand expression. An entry of a table and two immediate operands that give its address are paths too.
|
|
175
|
+
|
|
176
|
+
Code that a run executed always stays. `unreachableExecuted` lists the executed code that the entry and the vectors do not get to. An example is a copy check whose call the export removed. Give its range to `--drop` to make it free.
|
|
177
|
+
|
|
178
|
+
Data becomes free only when all of these are true:
|
|
179
|
+
|
|
180
|
+
- Its region type is `bytes`, `words`, a table of addresses, `petscii`, `workspace` or `unused`.
|
|
181
|
+
- No run read, wrote or executed a byte of it.
|
|
182
|
+
- No code that stays reads it or names it, and no table that stays has an entry in it.
|
|
183
|
+
- It is not at the first address of the program and not at $fffa-$ffff.
|
|
184
|
+
|
|
185
|
+
The VIC-II reads `charset`, `sprite`, `bitmap` and `screen` data without the CPU, so the coverage does not show these reads. This data stays unless `--drop` names it. Bytes without a region also stay.
|
|
186
|
+
|
|
187
|
+
The entry is the entry of the knowledge. Without it, the entry is the address of the first SYS in the BASIC line of the program. Without coverage, nothing becomes free by itself. Without an entry and without the hardware vectors in the image, no code is unreachable.
|
|
188
|
+
|
|
189
|
+
### The new project
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
README.md the commands to build and test, the free ranges and the origin
|
|
193
|
+
src/ main.asm, constants.asm, macros.asm, the modules and loader.asm
|
|
194
|
+
baseline/<name>.prg the exported program, and baseline/<name>.json with its symbols
|
|
195
|
+
tests/ the tests of the project, changed for the new program
|
|
196
|
+
.c64-re-tools/knowledge/ the knowledge of the new program
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
- The source has no mark line, no `switches.asm`, no patch zones and no `; not executed` lines. It keeps the names, the comments, the operand expressions and the macros. A line comment at each changed patch gives the switch, its kind, its value and the comments of the switch and the patch.
|
|
200
|
+
- The knowledge has one revision `export`. It holds the program, the entry and its state, the names, the comments, the regions and the modules. It has no history, analyzer names, references, operand expressions, macros, patches, switches, releases or coverage.
|
|
201
|
+
- The tests come from the JSON files in `tests/`:
|
|
202
|
+
- A scenario compares the build of the new project with the baseline. Both sides are the same program, so a step of the original side alone goes. A step of the rebuild side alone runs on both sides.
|
|
203
|
+
- A run file runs the build of the new project.
|
|
204
|
+
- Both take the names from the symbol files.
|
|
205
|
+
- The script leaves out a test that restores a snapshot. It also leaves out a test with a name that the new program does not have, or with an address in a free range.
|
|
206
|
+
- The script does not copy recordings, record files or `runs/`.
|
|
207
|
+
- The zip file holds the folder without `.c64-re-tools/local/`.
|
|
208
|
+
|
|
209
|
+
The result of `export`:
|
|
210
|
+
|
|
211
|
+
- `result`: `PASS` when the script wrote the new project. `FAIL` with `stage` when a check failed: `original`, `switches`, `export` or `loader`. Then the script wrote nothing.
|
|
212
|
+
- `to` and `zip`: the folder and the zip file.
|
|
213
|
+
- `switches`: each switch with `kind`, `base` and the export `value`.
|
|
214
|
+
- `free`: the count of free bytes, and each free range with `bytes`, `what` and `label`.
|
|
215
|
+
- `unreachableExecuted`: each range of executed code that the entry does not get to, with the `routine` before it and its `--drop` option.
|
|
216
|
+
- `knowledge`: the counts of the rows of the new knowledge.
|
|
217
|
+
- `tests`: the `written` tests, and the `leftOut` tests with the reason.
|
|
218
|
+
- `loader`: the copies, the copier, `stackByte` and `simulated: true`.
|
|
219
|
+
- `noCoverage` or `unrooted`: why nothing became free by itself.
|
|
220
|
+
- `spacesLeftOut`: the spaces that the export does not have. The export has only the space `c64`.
|
|
221
|
+
|
|
140
222
|
## Knowledge
|
|
141
223
|
|
|
142
224
|
Read:
|
|
@@ -199,6 +281,10 @@ Do not store:
|
|
|
199
281
|
- `loader.verified: false` with a `reason`: the script did not make the loader. The script still writes and checks the source. When no copy order or no free pages exist, or the loader needs too many copies, the reason gives the ranges. Capture the program again with fewer segments, or write the loader by hand.
|
|
200
282
|
- `loader.verified: false` with `differences`: the loader ran, and `differences` gives the bytes and registers that are not equal.
|
|
201
283
|
- `loader.verified: false` with `stop`: the loader did not get to its copier or to its jump. `stop` gives the address where it stopped and `port`, the value of $01. `history` gives the last 16 instructions. `cause` gives the first byte of the copier that is not equal to its byte in the loader file. If the copier ran, `cause` can also give the first byte that a copy did not write correctly.
|
|
284
|
+
- `export` with `stage: "original"`: the source of the knowledge does not pass. Run `generate`, and correct the knowledge until `generate` gives PASS.
|
|
285
|
+
- `export` with `stage: "switches"`: the build with the export values changes bytes outside the patches, or a patch does not fit. Read `build`. Correct the patches.
|
|
286
|
+
- `export` refuses two switches that change one range: the export puts both alternatives in. Give all but one of them the kind `change` and the default of the base release with `switch` of the c64-knowledge skill.
|
|
287
|
+
- `export` refuses `--drop`: read the message. It names the code that stays and goes to the range or reads it, or the code or region that the range cuts.
|
|
202
288
|
- `installation-incomplete`, or `machine-unavailable` with a message that the host runtime does not run: stop the task. Give the message to the user and wait for the user. The message gives the remedy. Do not make a replacement for the tool or the host runtime, for example your own disassembler or emulator script.
|
|
203
289
|
|
|
204
290
|
## Handoffs
|
|
@@ -208,3 +294,4 @@ Do not store:
|
|
|
208
294
|
- Names, regions, comments and modules → c64-knowledge
|
|
209
295
|
- Build the program → c64-assembler
|
|
210
296
|
- Test the rebuild against the original → c64-testing
|
|
297
|
+
- The start of a new program from the rebuild → c64-export
|