@henols/c64-re-tools 2.1.8 → 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 +29 -41
- package/package.json +1 -1
- package/skills/c64-assembler/SKILL.md +5 -2
- package/skills/c64-assembler/scripts/assembler.ts +24 -12
- package/skills/c64-development/SKILL.md +179 -0
- package/skills/c64-docs/references/page-types.md +1 -1
- package/skills/c64-knowledge/SKILL.md +66 -13
- package/skills/c64-knowledge/scripts/knowledge.ts +165 -18
- package/skills/c64-provenance/SKILL.md +11 -3
- package/skills/c64-reverse-engineering/SKILL.md +30 -13
- package/skills/c64-source/SKILL.md +33 -13
- package/skills/c64-source/scripts/lib/loader.ts +3 -1
- package/skills/c64-source/scripts/lib/source.ts +151 -37
- package/skills/c64-source/scripts/source.ts +135 -45
- 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/skills/c64-unpacker/SKILL.md +4 -1
- package/src/cli/main.ts +7 -7
- package/src/knowledge/conflicts.ts +32 -8
- package/src/knowledge/history.ts +18 -0
- package/src/knowledge/read.ts +98 -4
- package/src/knowledge/schema.ts +43 -2
- package/src/knowledge/text.ts +22 -0
- package/src/knowledge/write.ts +248 -25
- 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/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,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-
|
|
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
|
@@ -31,7 +31,8 @@ node <skill>/scripts/assembler.ts build src main.a --out build/game.prg
|
|
|
31
31
|
| `--include lib` | An include directory, relative to the source root. Use it again for more directories. |
|
|
32
32
|
| `--define DEBUG=1` | An assembler symbol: an integer, also as `$` hex, or `true` or `false`. Use it again for more symbols. |
|
|
33
33
|
| `--set-pc '$0801'` | The start address when the source does not set one. |
|
|
34
|
-
| `--
|
|
34
|
+
| `--release ORIGINAL` | Build a release of the knowledge. The script defines `RELEASE_ORIGINAL=1`, so each switch has the value of that release. With `--compare`, the script compares with the file of the release. A `--define` of a switch overrides the release. |
|
|
35
|
+
| `--compare` | Check the program byte by byte against the program in the knowledge, each segment. Put it in with `image` of the c64-knowledge skill. `--space drive8` or `--space bank0` compares with the program of that space. The script refuses `--space` without `--compare` or `--release`. |
|
|
35
36
|
| `--plain` | Write only the bytes of the program, without the 2-byte load address of a PRG. `loadRange` still tells where the bytes go. |
|
|
36
37
|
| `--all-symbols` | List all symbols. Without it, the list does not include the constants that the source does not use. `unusedConstants` gives their count. |
|
|
37
38
|
| `--max-listed 200` | Show at most 200 symbols in the result. The default is 50. `symbols.count` gives the count of all symbols. |
|
|
@@ -74,7 +75,7 @@ The target CPU is the 6510. The output is a C64 PRG, or the bytes only with `--p
|
|
|
74
75
|
4. If `result` is `FAIL` and `assembled` is `false`, read `diagnostics`. Each one has a severity, a file, a line and a message. Correct the source and run the script again.
|
|
75
76
|
5. To run the program, give the PRG path to the c64-emulator skill.
|
|
76
77
|
|
|
77
|
-
The source of the c64-source skill has switches.
|
|
78
|
+
The source of the c64-source skill has switches in `switches.asm`. Without an option, the build is the default build: the clean program without copy protection, trainers, cheats and crack changes, and with all corrections. This build can differ from the program in the knowledge, so `--compare` can give `FAIL`. Use `--release <label> --compare` to check the build of a release. `--define TRAINER=1` puts in the patches of the switch `TRAINER`.
|
|
78
79
|
|
|
79
80
|
## Knowledge
|
|
80
81
|
|
|
@@ -94,6 +95,7 @@ A symbol from the rebuilt source can give the address of a routine in the rebuil
|
|
|
94
95
|
- `PASS`: the PRG is in the project at `out`, with its load range and symbols.
|
|
95
96
|
- `FAIL` with `assembled: false`: the source has errors. `diagnostics` gives them.
|
|
96
97
|
- `FAIL` with `assembled: true`: `--compare` found differences. The PRG is at `out`.
|
|
98
|
+
- `not-found` with `--release`: the knowledge has no release with that label. The c64-knowledge skill records releases.
|
|
97
99
|
|
|
98
100
|
With `--compare`, `compare` gives `identical` and `segments`: one check for each segment of the program in the knowledge. The `result` of a check is `identical`, `different` with `firstDifference`, or `not covered` when the build does not hold the segment. `firstDifference` gives the `address`, and the byte of the build (`built`) and of the knowledge (`reference`), each as `$` and two hex digits.
|
|
99
101
|
|
|
@@ -109,3 +111,4 @@ With `--compare`, `compare` gives `identical` and `segments`: one check for each
|
|
|
109
111
|
|
|
110
112
|
- Run or debug the program → c64-emulator
|
|
111
113
|
- Compare the rebuild with the original → c64-testing
|
|
114
|
+
- Write a new program, or add a feature or a fix → c64-development
|
|
@@ -5,15 +5,18 @@ import { posix } from "node:path";
|
|
|
5
5
|
|
|
6
6
|
import { formatC64Address } from "#src/c64.ts";
|
|
7
7
|
import { Refusal } from "#src/errors.ts";
|
|
8
|
+
import { readImage } from "#src/host-client/image.ts";
|
|
8
9
|
import { readProjectTree, writeReported } from "#src/host-client/transfer.ts";
|
|
9
10
|
import { openForRead } from "#src/knowledge/database.ts";
|
|
10
11
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
11
|
-
import { requireProgram
|
|
12
|
+
import { requireProgram } from "#src/knowledge/program.ts";
|
|
13
|
+
import { releaseLabeled } from "#src/knowledge/read.ts";
|
|
14
|
+
import { RELEASE_DEFINE } from "#src/knowledge/schema.ts";
|
|
12
15
|
import { assemble } from "#src/native/acme.ts";
|
|
13
16
|
import { localToolContext } from "#src/native/local.ts";
|
|
14
17
|
import type { AcmeParams, AssembledSymbol } from "#src/native/types.ts";
|
|
15
18
|
import { listed as listedItems, OPTIONS, runScript, UsageError } from "#src/script.ts";
|
|
16
|
-
import { compareBuild } from "./lib/compare.ts";
|
|
19
|
+
import { compareBuild, type Reference } from "./lib/compare.ts";
|
|
17
20
|
|
|
18
21
|
function parseDefine(text: string): [string, number | boolean] {
|
|
19
22
|
const match = /^([A-Za-z_][A-Za-z0-9_]*)=(.+)$/.exec(text);
|
|
@@ -39,7 +42,7 @@ await runScript({
|
|
|
39
42
|
commands: [
|
|
40
43
|
{
|
|
41
44
|
name: "build",
|
|
42
|
-
summary: "Assembles the source and writes the program. result is PASS when it assembles (and with --compare, when it is the program of the knowledge), else FAIL with the diagnostics or the differences.",
|
|
45
|
+
summary: "Assembles the source and writes the program. result is PASS when it assembles (and with --compare, when it is the program of the knowledge or of the --release), else FAIL with the diagnostics or the differences.",
|
|
43
46
|
subjects: [
|
|
44
47
|
{ name: "<source-root>", help: "the folder in the project to assemble from: all of it is sent" },
|
|
45
48
|
{ name: "<entry>", help: "the main source file, relative to the source root" },
|
|
@@ -49,24 +52,33 @@ await runScript({
|
|
|
49
52
|
include: { kind: "text", value: "<dir>", multiple: true, help: "an include folder, relative to the source root" },
|
|
50
53
|
define: { kind: "text", value: "NAME=VALUE", multiple: true, help: "an assembler symbol: an integer ($hex allowed) or true/false" },
|
|
51
54
|
"set-pc": { kind: "address", value: "<address>", help: "the start address when the source sets none, for example '$0801'" },
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
release: { kind: "text", value: "<label>", help: `build a release of the knowledge: defines ${RELEASE_DEFINE}<label>=1, so each switch has the value of that release. With --compare, the reference is the file of the release` },
|
|
56
|
+
compare: { kind: "flag", help: "check the program byte by byte against the program in the knowledge (or the file of --release), each segment" },
|
|
57
|
+
space: { kind: "space", value: "<space>", help: "with --compare or --release: the knowledge space of the program: c64 (the default), drive8, or bank0 to bank255" },
|
|
54
58
|
plain: { kind: "flag", help: "write the bytes only, without the 2-byte load address of a PRG" },
|
|
55
59
|
"all-symbols": { kind: "flag", help: "list also the constants that the source does not use" },
|
|
56
60
|
"max-listed": { ...OPTIONS["max-listed"], help: "list at most n symbols (default 50). The count is always given" },
|
|
57
61
|
"out-symbols": { kind: "path", output: "file", value: "<file.json>", help: "write the listed symbols to this project file as {\"symbols\": [...]}: the names of the rebuild for c64-testing. Without --all-symbols, the file does not have the constants that the source does not use" },
|
|
58
62
|
},
|
|
59
|
-
notes: "Symbol values are $ and at least four hex digits. Put the program into the knowledge with knowledge.ts image of the c64-knowledge skill before --compare.",
|
|
63
|
+
notes: "Symbol values are $ and at least four hex digits. Put the program into the knowledge with knowledge.ts image of the c64-knowledge skill before --compare. Without --release and --define, the build is the default build of switches.asm: the clean program, which is not the bytes of a release when a switch has a default that the base release does not have.",
|
|
60
64
|
run: async (call) => {
|
|
61
65
|
const [sourceRoot, entry] = [call.subject(0), call.subject(1)];
|
|
62
66
|
const out = call.string("out")!;
|
|
63
|
-
// Read the
|
|
64
|
-
let program:
|
|
65
|
-
|
|
66
|
-
if (call.flag("compare"))
|
|
67
|
+
// Read the reference before ACME runs, so a project without it stops at once.
|
|
68
|
+
let program: Reference | undefined;
|
|
69
|
+
const label = call.string("release");
|
|
70
|
+
if (call.string("space") !== undefined && !call.flag("compare") && label === undefined) throw new UsageError("--space works only with --compare or --release: it names the knowledge space of the program");
|
|
71
|
+
let releaseDefine: Record<string, number> = {};
|
|
72
|
+
if (call.flag("compare") || label !== undefined) {
|
|
67
73
|
const db = openForRead();
|
|
68
74
|
try {
|
|
69
|
-
program = requireProgram(db, call.space);
|
|
75
|
+
if (label === undefined) program = requireProgram(db, call.space);
|
|
76
|
+
else {
|
|
77
|
+
const release = releaseLabeled(db, label, call.space);
|
|
78
|
+
if (release === undefined) throw new Refusal("not-found", `There is no release ${label} in the knowledge. Record it with knowledge.ts release of the c64-knowledge skill.`);
|
|
79
|
+
releaseDefine = { [`${RELEASE_DEFINE}${label}`]: 1 };
|
|
80
|
+
if (call.flag("compare")) program = release.base ? requireProgram(db, call.space) : readImage(release.file);
|
|
81
|
+
}
|
|
70
82
|
} finally {
|
|
71
83
|
db?.close();
|
|
72
84
|
}
|
|
@@ -82,7 +94,7 @@ await runScript({
|
|
|
82
94
|
throw new Refusal("not-found", `There is no include folder ${folder} with files in the source root ${sourceRoot}. Give --include a folder relative to the source root.`);
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
|
-
const params: AcmeParams = { files: tree.files, entrySource: entry, includeDirs: call.strings("include"), defines: Object.fromEntries(call.strings("define").map(parseDefine)), ...(setPc === undefined ? {} : { setPc }) };
|
|
97
|
+
const params: AcmeParams = { files: tree.files, entrySource: entry, includeDirs: call.strings("include"), defines: { ...releaseDefine, ...Object.fromEntries(call.strings("define").map(parseDefine)) }, ...(setPc === undefined ? {} : { setPc }) };
|
|
86
98
|
|
|
87
99
|
const { result, attachments } = await assemble(params, tree.contents, localToolContext());
|
|
88
100
|
if (!result.assembled) return { result: "FAIL", assembled: false, diagnostics: result.diagnostics };
|
|
@@ -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
|
|
@@ -13,7 +13,7 @@ One entry page for the program: `README.md` in the project folder. A large subsy
|
|
|
13
13
|
5. **Findings.** A table of the facts that a reader does not expect, each with its evidence. Put a bug of the original program here.
|
|
14
14
|
6. **The reference.** A link to `docs/reference/index.md`.
|
|
15
15
|
7. **Still open.** What is not known yet, and which run can find it.
|
|
16
|
-
8. **The
|
|
16
|
+
8. **The releases and the rebuild.** What each release holds, for example a crack with a cracktro and a mover. Which release is the base release, the program of the knowledge. Which changes of the release to the machine state stay, and how the loader sets them. A table of the switches from `knowledge.ts switches`: the name, the kind, the default and the releases that have the switch on. How to build the default program and each release. Which scenarios compare the original with the rebuild.
|
|
17
17
|
|
|
18
18
|
```markdown
|
|
19
19
|
# <Program>: <subject>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-knowledge
|
|
3
|
-
description: Use this skill to read, write, correct and review the durable knowledge of a C64 project in .c64-re-tools/knowledge/. The knowledge holds the program, its entry state and the coverage of the runs. It gives the knowledge at an address, and it names symbols, classifies memory regions, sets comments and records references. It records patches and macros for the generated source. It also shows the history of each change, and it can revert to an earlier revision. Do not use it for live emulator state or for static analysis.
|
|
3
|
+
description: Use this skill to read, write, correct and review the durable knowledge of a C64 project in .c64-re-tools/knowledge/. The knowledge holds the program, its entry state and the coverage of the runs. It gives the knowledge at an address, and it names symbols, classifies memory regions, sets comments and records references. It records releases, switches, patches and macros for the generated source. It also shows the history of each change, and it can revert to an earlier revision. Do not use it for live emulator state or for static analysis.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# c64-knowledge
|
|
@@ -55,14 +55,16 @@ A symbol is the name of an address from the user or the LLM. An analyzer name is
|
|
|
55
55
|
| Start a file of generated source | `module '$2000' player.asm --title 'Player movement'` / `unmodule '$2000'` |
|
|
56
56
|
| Write the operand of an instruction as an expression | `operand '$8079' --lo irq_handler` / `unoperand '$8079'` |
|
|
57
57
|
| Operand expressions | `operands` with `--range` |
|
|
58
|
-
|
|
|
59
|
-
|
|
|
58
|
+
| Record a release of the program | `release ORIGINAL --file original/game.prg --base` / `unrelease V2` |
|
|
59
|
+
| Write a switch | `switch PROTECTION --kind protection --releases ORIGINAL` / `unswitch PROTECTION` |
|
|
60
|
+
| Write the code of a switch for a range | `patch '$100e-$1010' PROTECTION --code-file no-check.asm` / `unpatch '$100e'` |
|
|
61
|
+
| Releases, switches and patches | `releases`, `switches`, and `patches` with `--switch` |
|
|
60
62
|
| Write a macro | `macro inc16 --params dst --body-file inc16.asm` / `unmacro inc16` |
|
|
61
63
|
| Write instructions as one use of a macro | `use '$1005-$100a' inc16 --args ptr` / `unuse '$1005'` |
|
|
62
64
|
| Macros and their uses | `macros`, and `uses` with `--range` and `--macro` |
|
|
63
65
|
| Files of generated source | `modules` |
|
|
64
66
|
| The address spaces that hold knowledge | `spaces` |
|
|
65
|
-
| History | `history '$2100'`, `history --name update_player`, `history --macro inc16`, `revisions`, `revision 20261015T2145` |
|
|
67
|
+
| History | `history '$2100'`, `history --name update_player`, `history --macro inc16`, `history --switch PROTECTION`, `revisions`, `revision 20261015T2145` |
|
|
66
68
|
| Go back to an earlier state | `revert 20261015T2145` for all spaces, or `revert 20261015T2145 --space bank3` for one space |
|
|
67
69
|
| Decide the conflicts after a git merge | `merge --reason 'merge of two computers'` |
|
|
68
70
|
|
|
@@ -173,7 +175,8 @@ The ops and their fields:
|
|
|
173
175
|
| `operand` | `address`, `select` (`lo`, `hi`, `value` or `expr`), `symbol` and `offset` (optional), or `expression` for `expr` |
|
|
174
176
|
| `unoperand` | `address` |
|
|
175
177
|
| `patch` | `start`, `end`, `switch`, `code` (empty for NOP only), `comment` (optional) |
|
|
176
|
-
| `unpatch
|
|
178
|
+
| `unpatch` | `start`, `switch` (optional) |
|
|
179
|
+
| `unuse` | `start` |
|
|
177
180
|
| `macro` | `name`, `params` (a list or a comma list), `body`, `comment` (optional) |
|
|
178
181
|
| `unmacro` | `name` |
|
|
179
182
|
| `use` | `start`, `end`, `macro`, `args` (a list or a comma list) |
|
|
@@ -205,7 +208,7 @@ Then apply the joined batch with the command in `apply`.
|
|
|
205
208
|
|
|
206
209
|
## Modules
|
|
207
210
|
|
|
208
|
-
A module tells the c64-source skill where a file of the generated source starts. The file runs to the next module or to the end of its segment. Each address has one module, and each file name has one module. A file name has letters, digits, underscores or hyphens, and ends in `.asm`. The c64-source skill writes `main.asm`, `loader.asm`, `constants.asm` and `macros.asm` itself. Thus a module cannot have one of these names, in upper or lower case. The title becomes the first line of the file. A `module` write without a title keeps the title that the module has. Modules have a history, and `revert` restores them.
|
|
211
|
+
A module tells the c64-source skill where a file of the generated source starts. The file runs to the next module or to the end of its segment. Each address has one module, and each file name has one module. A file name has letters, digits, underscores or hyphens, and ends in `.asm`. The c64-source skill writes `main.asm`, `loader.asm`, `switches.asm`, `constants.asm` and `macros.asm` itself. Thus a module cannot have one of these names, in upper or lower case. The title becomes the first line of the file. A `module` write without a title keeps the title that the module has. Modules have a history, and `revert` restores them.
|
|
209
212
|
|
|
210
213
|
## Operand expressions
|
|
211
214
|
|
|
@@ -230,21 +233,71 @@ Give one selector:
|
|
|
230
233
|
|
|
231
234
|
Write an operand expression for each immediate that is a byte of an address. Also write one for each table read through the byte before the table. The pointer candidates of the c64-static-analysis skill show many of these places.
|
|
232
235
|
|
|
233
|
-
##
|
|
236
|
+
## Releases and switches
|
|
234
237
|
|
|
235
|
-
A
|
|
238
|
+
A rebuild keeps all of the program. It keeps unused bytes, dead code, old copies and leftovers of the development. It keeps a copy protection, a trainer and a cheat in the source. A switch puts each of them in or out of the build. Only a cracktro is not in the rebuild: see the c64-unpacker skill.
|
|
236
239
|
|
|
237
|
-
|
|
238
|
-
|
|
240
|
+
### Releases
|
|
241
|
+
|
|
242
|
+
A release is a PRG or a c64-unpacker `image.json` of the program, in a folder that git keeps, for example `original/`. `release` records its label, its file and the SHA-256 of the file.
|
|
243
|
+
|
|
244
|
+
- The base release is the release whose bytes are the program of the knowledge. Record it with `--base`. The script refuses `--base` when the segments or the bytes of the file are not the program.
|
|
245
|
+
- A space has one base release. Record the base release before the first switch.
|
|
246
|
+
- The build of a release defines `RELEASE_<label>=1`. Then each switch has the value of that release. The c64-source skill checks that this build gives the bytes of the file.
|
|
247
|
+
- A label is upper case, for example `ORIGINAL`, `FIRESTAR` or `V2`.
|
|
248
|
+
- `unrelease` refuses a release that a switch names. It also refuses the base release while the knowledge has switches.
|
|
249
|
+
|
|
250
|
+
### Switches
|
|
251
|
+
|
|
252
|
+
All switches are in `switches.jsonl` of the knowledge, and the c64-source skill writes all of them to `switches.asm`. A switch has a kind, a default and the releases that have it on.
|
|
253
|
+
|
|
254
|
+
| Kind | What it changes | Default |
|
|
255
|
+
|---|---|---|
|
|
256
|
+
| `protection` | A copy protection | 0 (off) |
|
|
257
|
+
| `trainer` | A trainer, for example infinite lives | 0 (off) |
|
|
258
|
+
| `cheat` | A cheat | 0 (off) |
|
|
259
|
+
| `crack` | A change that a cracker made in the program, for example a credit text | 0 (off) |
|
|
260
|
+
| `fix` | A correction that one or more releases have | 1 (on). Give `--default 0` only for an alternative (below). |
|
|
261
|
+
| `change` | Another difference between releases | Give `--default 0` or `--default 1` |
|
|
262
|
+
|
|
263
|
+
- The default build is the clean program. It has no copy protection, trainer, cheat or crack change, and it has all corrections. The script refuses `--default 1` for `protection`, `trainer`, `cheat` and `crack`.
|
|
264
|
+
- `--releases` lists the labels of the releases that have the switch on. A switch that no release has on, for example a trainer of your own, has no `--releases`.
|
|
265
|
+
- The base value of a switch is 1 when the base release has it on, else 0. The program of the knowledge has the base value of each switch.
|
|
266
|
+
- A switch name is upper case, for example `PROTECTION`, `TRAINER` or `FIX_LIVES`. It cannot start with `RELEASE_`. It cannot be the name of a symbol or a platform name.
|
|
267
|
+
- A `switch` write without `--releases` or `--comment` keeps the releases and the comment that the switch has.
|
|
268
|
+
- The script refuses a change of the base value while the switch has patches. Remove the patches first, because they hold the other state.
|
|
269
|
+
- `unswitch` refuses a switch that has patches.
|
|
270
|
+
- `switches` gives each switch with `default`, `base`, `releases`, its patches, and the defines `on` and `off`. `releases` gives each release with its define.
|
|
271
|
+
|
|
272
|
+
### Patches
|
|
273
|
+
|
|
274
|
+
A patch is ACME code for a range of the program. The code is the bytes of the switch in the state that the base release does not have. Examples:
|
|
275
|
+
|
|
276
|
+
- The base release has a copy protection. The switch `PROTECTION` names the base release. The code is the program without the protection, for example NOP in place of the `JSR` to the check.
|
|
277
|
+
- The base release has the protection already removed, and another release has it: the code is the bytes of the protection from that release. When no release has these bytes, record in a comment that the crack removed the protection.
|
|
278
|
+
- A correction is only in release `V2`: the switch `FIX_LIVES` names `V2`, and the code is the bytes of `V2`.
|
|
279
|
+
- A correction is in the base release and not in `V1`. The switch names the base release, and the code is the bytes of `V1`.
|
|
280
|
+
|
|
281
|
+
Rules:
|
|
282
|
+
|
|
283
|
+
- Write the switch first. `patch` refuses a switch that the knowledge does not have.
|
|
284
|
+
- Many patches can have the same switch.
|
|
239
285
|
- The code must fit in the range. NOP ($EA) fills the bytes after the code. `--nop` gives a range of NOP only.
|
|
240
|
-
- `patch` refuses code that is longer than the range when each line is a 6510 instruction, `!byte`, `!word`, `!fill` or a comment. `patch` does not check the length of other code, for example code with a label or a macro. It does not assemble the code. `generate` of the c64-source skill
|
|
286
|
+
- `patch` refuses code that is longer than the range when each line is a 6510 instruction, `!byte`, `!word`, `!fill` or a comment. `patch` does not check the length of other code, for example code with a label or a macro. It does not assemble the code. `generate` of the c64-source skill does these checks.
|
|
241
287
|
- `--code` gives the code as text. `--code-file` reads the code from a project file. The code can use the labels and the macros of the source, and local labels with a dot, for example `.skip`.
|
|
242
288
|
- The braces in the code must be pairs, because the source puts the code inside `{ }`.
|
|
243
|
-
-
|
|
289
|
+
- Patches of different switches can have the same range. They are alternatives, for example two releases with two different corrections of one bug. The default build can put in only one of them. Thus `switch` refuses defaults that put in two alternatives.
|
|
290
|
+
- The knowledge refuses all other overlaps of patches. A patch cannot overlap a macro use.
|
|
291
|
+
- A patch with the same start and the same switch replaces the patch.
|
|
292
|
+
- When patches of two switches start at one address, give `unpatch` the switch with `--switch`.
|
|
244
293
|
- Each byte of the range must be in the program of the knowledge.
|
|
245
294
|
- A `patch` write without `--comment` keeps the comment that the patch has.
|
|
246
295
|
|
|
247
|
-
Build
|
|
296
|
+
Build with the c64-assembler skill:
|
|
297
|
+
|
|
298
|
+
- The default build has no options.
|
|
299
|
+
- A release: `--release ORIGINAL`.
|
|
300
|
+
- One switch: `--define TRAINER=1`. A define overrides the release.
|
|
248
301
|
|
|
249
302
|
## Macros
|
|
250
303
|
|