@henols/c64-re-tools 2.3.0-rc.2 → 2.3.0-rc.4

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.
@@ -99,16 +99,28 @@ export function viceVersionOf(text: string): ViceVersion | undefined {
99
99
  return { major: Number(match[1]), minor: Number(match[2]), ...(match[3] === undefined ? {} : { revision: Number(match[3]) }) };
100
100
  }
101
101
 
102
+ /** What a VICE flaw stops from working: joystick input, or the load of a tape image. */
103
+ export type ViceFeature = "joystick" | "tape";
104
+
105
+ /** A known VICE flaw: the text for the person at the host, and what it stops from working. */
106
+ export interface ViceFlaw {
107
+ text: string;
108
+ breaks: readonly ViceFeature[];
109
+ }
110
+
102
111
  /**
103
112
  * Known flaws of VICE versions that c64-re-tools still runs on. A flaw
104
- * is not worked around: it is named with the VICE version that fixes it.
105
- * `upTo` is the last flawed major.minor; `fixedRevision` the first SVN
106
- * revision with the fix, for builds from VICE's source tree.
113
+ * is not worked around: the tools that it breaks refuse with
114
+ * not-implemented, and the host names the flaw and the VICE version that
115
+ * fixes it on its console. `upTo` is the last flawed major.minor;
116
+ * `fixedRevision` the first SVN revision with the fix, for builds from
117
+ * VICE's source tree.
107
118
  */
108
119
  const VICE_FLAWS = [
109
120
  {
110
121
  upTo: { major: 3, minor: 10 },
111
122
  fixedRevision: 45971,
123
+ breaks: ["joystick", "tape"],
112
124
  text:
113
125
  "VICE 3.10 and older hold bits 5-7 of CIA 1 ports A and B low with the joystick device that c64-re-tools uses (VICE bug #2202). " +
114
126
  "$DC00 and $DC01 read $1F with no input. A program that waits for one key of the keyboard matrix (for example LDA $DC01 / CMP #$EF for SPACE) waits forever. " +
@@ -118,12 +130,12 @@ const VICE_FLAWS = [
118
130
  },
119
131
  ] as const;
120
132
 
121
- /** The known flaws of this VICE version, as text for a person or an agent. */
122
- export function viceFlaws(version: ViceVersion): string[] {
133
+ /** The known flaws of this VICE version. */
134
+ export function viceFlaws(version: ViceVersion): ViceFlaw[] {
123
135
  return VICE_FLAWS.filter((flaw) => {
124
136
  const newer = version.major > flaw.upTo.major || (version.major === flaw.upTo.major && version.minor > flaw.upTo.minor);
125
137
  return !newer && (version.revision === undefined || version.revision < flaw.fixedRevision);
126
- }).map((flaw) => flaw.text);
138
+ }).map((flaw) => ({ text: flaw.text, breaks: flaw.breaks }));
127
139
  }
128
140
 
129
141
  export function isOlderThanMinimum(version: { major: number; minor: number }): boolean {
@@ -8,7 +8,7 @@ import type { ViceOperation, ViceOperations } from "./vice.ts";
8
8
  /** Private Host Runtime protocol identifier. */
9
9
  export const HOST_PROTOCOL_ID = "c64-re-tools-host" as const;
10
10
  /** Bumped on any incompatible change; a mismatch fails the handshake. */
11
- export const HOST_PROTOCOL_VERSION = 3;
11
+ export const HOST_PROTOCOL_VERSION = 4;
12
12
  /** After ready, the client pings this often, on every connection. */
13
13
  export const HEARTBEAT_INTERVAL_MS = 10_000;
14
14
  /** Either side closes a connection that has sent nothing for this long. */
@@ -512,19 +512,15 @@ export interface ViceOperations {
512
512
  /** Attachment: the PRG bytes, load address first. */
513
513
  programLoad: { params: { address?: number }; result: { state: RunState; loadAddress: number; size: number } };
514
514
  /** Attachment: the program or image bytes; `type` is the file's extension. `index` is VICE's file number: 0 loads "*", 1 is the first directory entry. */
515
- /**
516
- * `emulatorFlaw`: for a tape image, a known flaw of the host's VICE version that a tape load meets.
517
- * `joysticksCentred`: the control ports that held a direction or fire and were centred first.
518
- */
519
- autostart: { params: { type: string; index: number; run: boolean }; result: { state: RunState; emulatorFlaw?: string; joysticksCentred?: Array<1 | 2> } };
515
+ /** `joysticksCentred`: the control ports that held a direction or fire and were centred first. */
516
+ autostart: { params: { type: string; index: number; run: boolean }; result: { state: RunState; joysticksCentred?: Array<1 | 2> } };
520
517
  /** Attachment: the disk image bytes; `type` is the file's extension. */
521
518
  diskAttach: { params: { type: string }; result: { attached: boolean } };
522
519
  /** pc is the reset vector when run is false: the CPU stops there. */
523
520
  reset: { params: { mode: ResetMode; run: boolean }; result: { state: RunState; pc?: number } };
524
521
  /** `data`: PETSCII bytes as lowercase hex. */
525
- /** `emulatorFlaw`: a known flaw of the host's VICE version that this input meets. */
526
- keyboard: { params: { data: string }; result: { queuedBytes: number; emulatorFlaw?: string } };
527
- joystick: { params: JoystickState; result: JoystickState & { emulatorFlaw?: string } };
522
+ keyboard: { params: { data: string }; result: { queuedBytes: number } };
523
+ joystick: { params: JoystickState; result: JoystickState };
528
524
  breakpoint: { params: BreakpointParams; result: Breakpoint | PointRemoved | { breakpoints: Breakpoint[] } };
529
525
  watchpoint: { params: WatchpointParams; result: Watchpoint | PointRemoved | { watchpoints: Watchpoint[] } };
530
526
  cpuHistory: { params: { limit: number; space: Space }; result: { entries: HistoryEntry[] } };
@@ -1185,7 +1181,6 @@ export function validateViceResult<O extends ViceOperation>(op: O, value: unknow
1185
1181
  case "autostart": {
1186
1182
  if (!isOneOf(RUN_STATES, value.state)) throw new ProtocolError(`${op} result is malformed`);
1187
1183
  if (op === "reset" && value.pc !== undefined && !isInteger(value.pc, 0, 0xffff)) throw new ProtocolError("reset result is malformed");
1188
- if (op === "autostart" && !(value.emulatorFlaw === undefined || typeof value.emulatorFlaw === "string")) throw new ProtocolError("autostart result is malformed");
1189
1184
  if (op === "autostart" && !(value.joysticksCentred === undefined || (Array.isArray(value.joysticksCentred) && value.joysticksCentred.every((port) => port === 1 || port === 2)))) {
1190
1185
  throw new ProtocolError("autostart result is malformed");
1191
1186
  }
@@ -1201,7 +1196,7 @@ export function validateViceResult<O extends ViceOperation>(op: O, value: unknow
1201
1196
  break;
1202
1197
  }
1203
1198
  case "keyboard": {
1204
- if (!isInteger(value.queuedBytes, 1, MAX_KEYBOARD_BYTES) || !(value.emulatorFlaw === undefined || typeof value.emulatorFlaw === "string")) throw new ProtocolError("keyboard result is malformed");
1199
+ if (!isInteger(value.queuedBytes, 1, MAX_KEYBOARD_BYTES)) throw new ProtocolError("keyboard result is malformed");
1205
1200
  break;
1206
1201
  }
1207
1202
  case "breakpoint": {
@@ -1438,8 +1433,7 @@ export function validateViceResult<O extends ViceOperation>(op: O, value: unknow
1438
1433
  const ok =
1439
1434
  (value.port === 1 || value.port === 2) &&
1440
1435
  isOneOf(JOYSTICK_DIRECTIONS, value.direction) &&
1441
- typeof value.fire === "boolean" &&
1442
- (value.emulatorFlaw === undefined || typeof value.emulatorFlaw === "string");
1436
+ typeof value.fire === "boolean";
1443
1437
  if (!ok) throw new ProtocolError("joystick result is malformed");
1444
1438
  break;
1445
1439
  }
package/README.md DELETED
@@ -1,143 +0,0 @@
1
- # c64-re-tools
2
-
3
- <img src="assets/branding/c64-re-tools-transparent.svg" alt="C64 RE Tools" width="440">
4
-
5
-
6
- Let an AI agent work on Commodore 64 programs. The agent drives a real VICE
7
- emulator and runs ACME, DXA, Ghidra and Exomizer. Use it to build new C64 apps and games,
8
- and to reverse engineer old ones.
9
-
10
- It works with Claude Code, Codex, pi, opencode, Gemini, Copilot, Cursor and
11
- Windsurf.
12
-
13
- ## What it can do
14
-
15
- Ask for what you want in plain words. The agent picks the skill for each step.
16
-
17
- **Build new apps and games**
18
-
19
- - Assemble 6510 source with ACME, with errors by file and line, and symbols.
20
- - Pack and crunch a program with Exomizer into one PRG that unpacks itself, checked byte for byte before it is written.
21
- - Load and run the program in VICE. Set breakpoints and watchpoints, step, and read the CPU history and the call stack.
22
- - Read, write, search and compare memory, and disassemble it.
23
- - Show the VIC-II, sprite, SID and CIA state, and capture the screen.
24
- - Type on the keyboard and move the joystick.
25
- - Count cycles, profile the code, and wait for a raster line.
26
- - Run many steps in one go and keep screens, snapshots and coverage as files.
27
- - Tell what any address or register value means on the C64.
28
- - Add features and fixes to a program. Each change has a switch, so you can build the program with it or without it.
29
- - Test a program with scenarios: steps with expected values that give PASS or FAIL.
30
-
31
- **Reverse engineer existing programs**
32
-
33
- - Read D64, D71, D81, G64, T64 and CRT images, list BASIC and find the SYS address.
34
- - Find packers and capture the unpacked program from the emulator.
35
- - Analyse the code with DXA and Ghidra. The toolkit brings its own NMOS 6510 language for Ghidra, with all 256 opcodes.
36
- - Keep names, regions and comments as text in the project, ready for git.
37
- - Compare releases, and find routines that several programs share.
38
- - Generate ACME source that rebuilds the program byte for byte, and its documentation.
39
- - Test that a rebuild behaves as the original: PASS, FAIL or INCONCLUSIVE.
40
- - Export a rebuild as the start of a new program: one value for each switch, unused code removed, as a zip file.
41
-
42
- ## How it works
43
-
44
- VICE and the Host Runtime run on your computer, where VICE can open a window.
45
- The agent runs in a dev container in your project. It reaches VICE through an
46
- MCP server, and it runs ACME, DXA, Ghidra, Exomizer and c64run through its skills.
47
-
48
- ## Install
49
-
50
- ### Host
51
-
52
- You need Node.js 24 or newer and VICE 3.9 or later (`x64sc`, `c1541`, `petcat`)
53
- with its ROM files. Use the latest VICE release.
54
-
55
- Start the Host Runtime, and leave it running:
56
-
57
- ```
58
- npx -y --package=@henols/c64-re-tools@latest c64-re-tools-host
59
- ```
60
-
61
- ### Dev container
62
-
63
- You need Docker or Podman. Copy the example into your project:
64
-
65
- ```
66
- mkdir -p .devcontainer
67
- curl -fsSL -o .devcontainer/devcontainer.json https://raw.githubusercontent.com/henols/c64-re-tools/main/devcontainer/example/devcontainer.json
68
- ```
69
-
70
- Its comments tell what to change: the harness, the release channel, the image
71
- and the address of the Host Runtime. If the project already has a
72
- `devcontainer.json`, copy the c64-re-tools Feature and `runArgs` into it.
73
-
74
- Open the project in the container, for example with "Reopen in Container" in
75
- VS Code, or with `npx -y @devcontainers/cli up --workspace-folder .`. The
76
- Feature gives the container ACME, dxa, Exomizer, Java 21, Ghidra and c64run. At each
77
- start it installs the newest toolkit of its channel into the project, with the
78
- tools of that version. It reads its options only when the container is built:
79
- rebuild after a change.
80
-
81
- Check what works, in the container:
82
-
83
- ```
84
- npx -y @henols/c64-re-tools@latest status
85
- ```
86
-
87
- ## Use it
88
-
89
- Start the agent in the project, for example `claude`, and ask for what you want:
90
-
91
- ```
92
- Write a game in ACME where a sprite moves with the joystick and the border
93
- flashes when it hits the edge. Build it, run it, and show me the screen.
94
- ```
95
- ```
96
- The music stops when the title screen starts. Find out why.
97
- ```
98
- ```
99
- Reverse engineer original/game.d64. Find how it starts, unpack it if it is
100
- packed, and name the main routines.
101
- ```
102
- ```
103
- Find the routine that draws the score, and explain how it works.
104
- ```
105
-
106
- The agent keeps what it learns about a program as text in
107
- `.c64-re-tools/knowledge/`. Commit that folder with the project. If a command
108
- reports conflicts after a `git pull`, run `knowledge.ts merge`.
109
-
110
- Several programs in one repository: open the repository root in the dev
111
- container and give each program its own folder. A folder with `.c64-re-tools/` is a project.
112
-
113
- ## Settings
114
-
115
- Set the host variables where the Host Runtime starts, and the others in
116
- `containerEnv` of the `devcontainer.json`.
117
-
118
- | Variable | Meaning |
119
- | --- | --- |
120
- | `C64RT_VICE`, `C64RT_C1541`, `C64RT_PETCAT` | Full path of the VICE tool, when it is not on `PATH` (host). |
121
- | `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. |
122
- | `C64RT_VIDEO` | `pal` (default) or `ntsc`. |
123
- | `C64RT_TRACE` | A directory for the trace of the MCP server and the skill scripts. See [Trace](#trace). |
124
-
125
- ## Trace
126
-
127
- Turn on the trace when a tool fails and its error does not tell why. Each
128
- program then writes what it does to a directory, as JSON lines. The Host
129
- Runtime also keeps a copy of the VICE log. The agent does not see the trace.
130
-
131
- On the host, `--log-dir` names the directory, and `--log-console` prints the
132
- same events:
133
-
134
- ```
135
- npx -y --package=@henols/c64-re-tools@latest c64-re-tools-host --log-dir $HOME/c64-trace --log-console
136
- ```
137
-
138
- For the MCP server and the skill scripts, set `C64RT_TRACE` to an absolute
139
- directory in `containerEnv` of the `devcontainer.json`.
140
-
141
- ## License
142
-
143
- MIT. See [LICENSE](LICENSE).