@henols/c64-re-tools 2.3.0-rc.3 → 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.
- package/package.json +1 -1
- package/skills/c64-static-analysis/SKILL.md +1 -1
- package/skills/c64-testing/SKILL.md +1 -0
- package/skills/c64-unpacker/SKILL.md +2 -1
- package/skills/c64-unpacker/scripts/lib/loads.ts +2 -4
- package/skills/emulator/SKILL.md +2 -1
- package/src/errors.ts +1 -0
- package/src/host/main.ts +1 -1
- package/src/host/tools/status.ts +1 -1
- package/src/host/vice/session.ts +29 -9
- package/src/host-client/vice-session.ts +1 -1
- package/src/mcp/tools/input.ts +4 -5
- package/src/mcp/tools/machine.ts +1 -5
- package/src/mcp/tools/media.ts +0 -1
- package/src/native/discover.ts +18 -6
- package/src/protocol/messages.ts +1 -1
- package/src/protocol/vice.ts +6 -12
package/package.json
CHANGED
|
@@ -112,7 +112,7 @@ The script never replaces a name or a region from the user or the LLM. DXA and G
|
|
|
112
112
|
|
|
113
113
|
A `heuristic` region replaces the part of a DXA or Ghidra region where it lies, because an idiom is specific evidence about those bytes. DXA and Ghidra never replace a `heuristic` region. If they find code there, the result shows a conflict. A heuristic table can be too long or too short, because the script cannot know its length. Correct it with the c64-knowledge skill. Your region replaces it, and a removal holds.
|
|
114
114
|
|
|
115
|
-
A new analysis replaces the earlier facts of the same analyzer in the analyzed range, also its analyzer names. The history keeps the earlier facts.
|
|
115
|
+
A new analysis replaces the earlier facts of the same analyzer in the analyzed range, also its analyzer names. The history keeps the earlier facts.
|
|
116
116
|
|
|
117
117
|
A fact that the user or the LLM removes does not come back. The next analysis does not write a fact at that place, and counts it as `suppressed`. To remove a wrong fact, use the c64-knowledge skill.
|
|
118
118
|
|
|
@@ -199,6 +199,7 @@ PASS, FAIL or INCONCLUSIVE, the checkpoints and the smallest differences that ex
|
|
|
199
199
|
- INCONCLUSIVE, "has no symbol": one side has no symbol with that name. Add the name to the knowledge or to the rebuild source.
|
|
200
200
|
- INCONCLUSIVE, "no emulator" or "could not run": the emulator failed. Tell the user the message.
|
|
201
201
|
- `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
|
|
202
|
+
- `not-implemented`: the tool does not work in this setup. Give the message to the user. Do not use that tool or step again in this task.
|
|
202
203
|
- A FAIL with only a `screen` difference: add `vicii` or `sprites` to the observation to find which chip state is different.
|
|
203
204
|
- A program that uses random numbers: set the random seed with a `write` step on both sides. If that is not possible, observe only values that do not depend on the random numbers.
|
|
204
205
|
- The two sides start differently, for example the original after a cracked intro. Give the steps that only one side needs a `side`. Then make the memory the same with a `normalize` step. It writes the entry state of the capture in the knowledge.
|
|
@@ -165,11 +165,12 @@ For `loads`: `captures`, with the name, the PC, the segments, `differsFromReset`
|
|
|
165
165
|
- `captured: false`: the program did not get to the address in the time limit. The reason tells where it stopped. Find a better address with the emulator skill, or give more frames. If it stopped in a key wait, give `--steps` with a `type` step.
|
|
166
166
|
- A step did not reach its target: the reason names the step. Change the step or give it more frames.
|
|
167
167
|
- `loaded: false` with an empty `captures` and the reason `BASIC ran no program line`: the PRG has no BASIC start line. Use `capture` with `--entry`.
|
|
168
|
-
- `loaded: false` and no capture has a segment: the program did not load a part, or it did not start. `keyWait: true` on a capture tells that the C64 waited for a key at the READY prompt or at an INPUT statement.
|
|
168
|
+
- `loaded: false` and no capture has a segment: the program did not load a part, or it did not start. `keyWait: true` on a capture tells that the C64 waited for a key at the READY prompt or at an INPUT statement.
|
|
169
169
|
- Do not name a packer from weak evidence. The script never names one.
|
|
170
170
|
- Some programs unpack in more than one stage. Run `stages` to find each stage. Capture at the entry of the last stage. Make sure that it is the application and not a second unpacker.
|
|
171
171
|
- `not-found` or `invalid-input`: a path or an argument is wrong. Read the message.
|
|
172
172
|
- `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
|
|
173
|
+
- `not-implemented`: the tool does not work in this setup. Give the message to the user. Do not use that tool or step again in this task.
|
|
173
174
|
|
|
174
175
|
## Handoffs
|
|
175
176
|
|
|
@@ -118,8 +118,6 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
118
118
|
let loadedProgram: Buffer | undefined;
|
|
119
119
|
/** False while the map holds the writes of the KERNAL RAM test. */
|
|
120
120
|
let writesKnown = true;
|
|
121
|
-
/** A known flaw of the host's VICE version that a tape load meets. */
|
|
122
|
-
let emulatorFlaw: string | undefined;
|
|
123
121
|
if (program.toLowerCase().endsWith(".prg")) {
|
|
124
122
|
const { bytes } = readProjectFile(program);
|
|
125
123
|
if (!(await autostartLoaded(client, program, bytes))) return { output: { loaded: false, reason: `The program was not in memory after ${LOAD_LIMIT_FRAMES} frames.`, captures: [] }, failed: true };
|
|
@@ -138,7 +136,7 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
138
136
|
// A disk, tape or cartridge: VICE loads and starts it. The RAM test of the KERNAL puts back what it writes.
|
|
139
137
|
previous = await readRam(client, 0x0000, 0x10000);
|
|
140
138
|
await client.memmap({ action: "clear" });
|
|
141
|
-
|
|
139
|
+
await client.autostart({ path: program, index: 0, run: true });
|
|
142
140
|
writesKnown = false;
|
|
143
141
|
if (!program.toLowerCase().endsWith(".crt")) {
|
|
144
142
|
// The map starts again where the KERNAL LOAD starts, after the RAM test: then it holds only what the program wrote.
|
|
@@ -228,7 +226,7 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
228
226
|
if (captures.length > 0 && captures.every((capture) => (capture.segments as unknown[]).length === 0)) {
|
|
229
227
|
const waits = captures.some((capture) => capture.keyWait === true) ? " The C64 waited for a key at READY. or at an INPUT statement, so the load ended or did not start." : "";
|
|
230
228
|
const reason = `No capture has a segment: the program changed no block of RAM from ${formatC64Address(FIRST_SEGMENT_ADDRESS)} on.${waits}`;
|
|
231
|
-
return { output: { loaded: false, reason, captures
|
|
229
|
+
return { output: { loaded: false, reason, captures }, failed: true };
|
|
232
230
|
}
|
|
233
231
|
return { output: { loaded: true, captures }, failed: false };
|
|
234
232
|
} finally {
|
package/skills/emulator/SKILL.md
CHANGED
|
@@ -27,7 +27,7 @@ Use only the MCP tools. Each MCP session has its own machine. Nothing else can c
|
|
|
27
27
|
|
|
28
28
|
| Need | C64 tool |
|
|
29
29
|
|---|---|
|
|
30
|
-
| Run state, warp mode, window
|
|
30
|
+
| Run state, warp mode, window | `c64_status` |
|
|
31
31
|
| Reset, power cycle | `c64_reset` |
|
|
32
32
|
| Fast emulation | `c64_warp` |
|
|
33
33
|
| Show the machine to the user in a window, hide it again | `c64_window` |
|
|
@@ -121,6 +121,7 @@ If you cannot get the machine into the necessary state, say which state you coul
|
|
|
121
121
|
An error is `{"error": {"code": "...", "message": "..."}}`. The message tells what is wrong and what to do. Obey the message. These rules also apply:
|
|
122
122
|
|
|
123
123
|
- `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
|
|
124
|
+
- `not-implemented`: the tool does not work in this setup. Give the message to the user. Do not use that tool or step again in this task.
|
|
124
125
|
- `machine-unavailable` with a message that names a pause or a dialog in the window: do not send more operations. Give the message to the user. When the user tells you that the emulator runs again, do the operation again.
|
|
125
126
|
- `machine-unavailable` for a different cause: wait a few seconds. Then do the operation again one time. If you get the same error again, stop the task. Tell the user to restart the c64-re-tools MCP server, and wait for the user.
|
|
126
127
|
- `machine-state-lost`: do not use results from before the error. Do what the message tells. Then read the machine state again.
|
package/src/errors.ts
CHANGED
package/src/host/main.ts
CHANGED
|
@@ -108,7 +108,7 @@ async function main(): Promise<number> {
|
|
|
108
108
|
log(`VICE ${vice.major}.${vice.minor}${vice.revision === undefined ? "" : ` r${vice.revision}`} starts`);
|
|
109
109
|
const flaws = viceFlaws(vice);
|
|
110
110
|
// A known VICE flaw is named, not worked around.
|
|
111
|
-
for (const flaw of flaws) log(`Known VICE flaw: ${flaw}`);
|
|
111
|
+
for (const flaw of flaws) log(`Known VICE flaw: ${flaw.text}`);
|
|
112
112
|
|
|
113
113
|
let server;
|
|
114
114
|
try {
|
package/src/host/tools/status.ts
CHANGED
|
@@ -41,7 +41,7 @@ export async function hostStatus(context: ToolContext, started?: ViceVersion): P
|
|
|
41
41
|
// VICE runs with its known flaws; status names them.
|
|
42
42
|
const vice = checked[0]!;
|
|
43
43
|
const version = vice.runs ? viceVersionOf(vice.version ?? "") : undefined;
|
|
44
|
-
const flaws = version === undefined ? [] : viceFlaws(version);
|
|
44
|
+
const flaws = version === undefined ? [] : viceFlaws(version).map((flaw) => flaw.text);
|
|
45
45
|
if (flaws.length > 0) checked[0] = { ...vice, flaws };
|
|
46
46
|
return { result: { host: { version: PACKAGE.version, platform: platform(), release: release(), arch: arch() }, tools: checked } };
|
|
47
47
|
}
|
package/src/host/vice/session.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { decodeProgramCounter, MonitorConnectionError, MonitorError, MonitorTime
|
|
|
31
31
|
import { decodeCia, decodeSid, decodeSprite, decodeVicii } from "./chips.ts";
|
|
32
32
|
import { compareFrames, differenceImage } from "./screen.ts";
|
|
33
33
|
import { isRefusal } from "../../errors.ts";
|
|
34
|
+
import type { ViceFeature, ViceFlaw } from "../../native/discover.ts";
|
|
34
35
|
import { checkMedia, hasSignature } from "../../media.ts";
|
|
35
36
|
import { launchVice, startErrorLines, type ViceMode, type ViceProcess } from "./process.ts";
|
|
36
37
|
import { TextMonitorError, TextMonitorTimeoutError } from "./text-monitor.ts";
|
|
@@ -125,12 +126,18 @@ export interface SessionOptions {
|
|
|
125
126
|
launch?: ViceLauncher;
|
|
126
127
|
/** Makes the host remove a path if it dies; returns the release. */
|
|
127
128
|
ownPath?: (path: string) => () => void;
|
|
128
|
-
/** The known flaws of this VICE version
|
|
129
|
-
flaws?: readonly
|
|
129
|
+
/** The known flaws of this VICE version: the tools that a flaw breaks refuse with not-implemented. */
|
|
130
|
+
flaws?: readonly ViceFlaw[];
|
|
130
131
|
/** Lists the entries of a disk image, so an autostart index is checked first. Without it, VICE gets the index unchecked. */
|
|
131
132
|
directory?: DiskDirectory;
|
|
132
133
|
}
|
|
133
134
|
|
|
135
|
+
/** The refusal of a tool that a known VICE flaw breaks: what does not work, and what to do. */
|
|
136
|
+
const BROKEN_MESSAGES: Record<ViceFeature, string> = {
|
|
137
|
+
joystick: "Joystick input is not implemented in this setup. Do not use the joystick in this task. Give this message to the user.",
|
|
138
|
+
tape: "The load of a tape image is not implemented in this setup. Do not load tape images in this task. Give this message to the user.",
|
|
139
|
+
};
|
|
140
|
+
|
|
134
141
|
export type DiskDirectory = (type: DiskImageType, image: Buffer) => Promise<DiskFile[]>;
|
|
135
142
|
|
|
136
143
|
/**
|
|
@@ -154,8 +161,8 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
154
161
|
#mode: ViceMode = "headless";
|
|
155
162
|
readonly #videoStandard: VideoStandard;
|
|
156
163
|
readonly #log: (line: string) => void;
|
|
157
|
-
/**
|
|
158
|
-
readonly #
|
|
164
|
+
/** What the known VICE flaws break, each with the text of its flaw. */
|
|
165
|
+
readonly #broken: ReadonlyMap<ViceFeature, string>;
|
|
159
166
|
readonly #untilReturnLimitMs: number;
|
|
160
167
|
readonly #stepLimitMs: number;
|
|
161
168
|
readonly #launch: ViceLauncher | undefined;
|
|
@@ -264,7 +271,7 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
264
271
|
this.#stepLimitMs = options.stepLimitMs ?? RUNNING_COMMAND_TIMEOUT_MS;
|
|
265
272
|
this.#launch = options.launch;
|
|
266
273
|
this.#directory = options.directory;
|
|
267
|
-
this.#
|
|
274
|
+
this.#broken = new Map((options.flaws ?? []).flatMap((flaw) => flaw.breaks.map((feature) => [feature, flaw.text] as const)));
|
|
268
275
|
this.#workDir = mkdtempSync(join(tmpdir(), "c64-re-tools-session-"));
|
|
269
276
|
this.#releaseWorkDir = options.ownPath?.(this.#workDir) ?? (() => {});
|
|
270
277
|
this.#watch(vice);
|
|
@@ -423,6 +430,7 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
423
430
|
return this.#programLoad(params as ViceOperations["programLoad"]["params"], onlyAttachment(attachments));
|
|
424
431
|
case "autostart": {
|
|
425
432
|
const { type, index, run } = params as ViceOperations["autostart"]["params"];
|
|
433
|
+
if (type === "tap") this.#refuseBroken("tape", "c64_autostart of a tape image");
|
|
426
434
|
const bytes = onlyAttachment(attachments);
|
|
427
435
|
checkMedia(type, bytes);
|
|
428
436
|
if (index > 0 && this.#directory !== undefined && isOneOf(DISK_IMAGE_TYPES, type)) checkDirectoryEntry(await this.#directory(type, bytes), index);
|
|
@@ -449,7 +457,7 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
449
457
|
this.#replaceStaged(stagedKind(type), file);
|
|
450
458
|
// A reset sets the CPU clock back, so the stopwatch starts again.
|
|
451
459
|
this.#timingStart = 0n;
|
|
452
|
-
return { state: "running", ...(
|
|
460
|
+
return { state: "running", ...(centred.length === 0 ? {} : { joysticksCentred: centred }) };
|
|
453
461
|
}
|
|
454
462
|
case "diskAttach": {
|
|
455
463
|
const { type } = params as ViceOperations["diskAttach"]["params"];
|
|
@@ -472,7 +480,7 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
472
480
|
);
|
|
473
481
|
}
|
|
474
482
|
await this.#observe(() => this.#machine.feedKeyboard(bytes));
|
|
475
|
-
return { queuedBytes: bytes.length
|
|
483
|
+
return { queuedBytes: bytes.length };
|
|
476
484
|
}
|
|
477
485
|
case "breakpoint":
|
|
478
486
|
return this.#breakpoint(params as BreakpointParams);
|
|
@@ -557,10 +565,11 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
557
565
|
case "observe":
|
|
558
566
|
return this.#observeAll(params as ObserveParams);
|
|
559
567
|
case "joystick": {
|
|
568
|
+
this.#refuseBroken("joystick", "c64_joystick");
|
|
560
569
|
const joystick = params as JoystickState;
|
|
561
570
|
await this.#observe(() => this.#machine.setJoystick(joystick));
|
|
562
571
|
this.#joysticks.set(joystick.port, joystick);
|
|
563
|
-
return
|
|
572
|
+
return joystick;
|
|
564
573
|
}
|
|
565
574
|
case "warp": {
|
|
566
575
|
const { enabled } = params as ViceOperations["warp"]["params"];
|
|
@@ -1172,6 +1181,17 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
1172
1181
|
return publicView(point);
|
|
1173
1182
|
}
|
|
1174
1183
|
|
|
1184
|
+
/**
|
|
1185
|
+
* Refuses a tool that a known flaw of this VICE breaks: not-implemented for
|
|
1186
|
+
* the caller, without the VICE version, and the flaw on the host console.
|
|
1187
|
+
*/
|
|
1188
|
+
#refuseBroken(feature: ViceFeature, tool: string): void {
|
|
1189
|
+
const flaw = this.#broken.get(feature);
|
|
1190
|
+
if (flaw === undefined) return;
|
|
1191
|
+
this.#log(`${tool} was used, and this VICE does not support it. ${flaw}`);
|
|
1192
|
+
throw new WireFailure("not-implemented", BROKEN_MESSAGES[feature]);
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1175
1195
|
/**
|
|
1176
1196
|
* Writes transferred bytes into the session directory. VICE reads an
|
|
1177
1197
|
* attached image from its file, so an image stays until another one
|
|
@@ -1818,7 +1838,7 @@ export function viceSessionFactory(options: {
|
|
|
1818
1838
|
env?: NodeJS.ProcessEnv;
|
|
1819
1839
|
log?: (line: string) => void;
|
|
1820
1840
|
/** The known flaws of the VICE version that the host checked at start. */
|
|
1821
|
-
flaws?: readonly
|
|
1841
|
+
flaws?: readonly ViceFlaw[];
|
|
1822
1842
|
directory?: DiskDirectory;
|
|
1823
1843
|
}): ViceSessionFactory {
|
|
1824
1844
|
return async ({ videoStandard, log = options.log ?? (() => {}) }) => {
|
|
@@ -134,7 +134,7 @@ export class ViceSessionClient {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/** Autostarts a project program or image, as VICE's autostart does. `root` is the project folder; it stays on this side. */
|
|
137
|
-
async autostart(params: { path: string; index: number; run: boolean; root?: string }): Promise<{ state: RunState
|
|
137
|
+
async autostart(params: { path: string; index: number; run: boolean; root?: string }): Promise<{ state: RunState }> {
|
|
138
138
|
const file = readProjectFile(params.path, params.root === undefined ? { what: "path" } : { root: params.root, what: "path" });
|
|
139
139
|
return this.#request("autostart", { type: file.type, index: params.index, run: params.run }, [file.bytes]);
|
|
140
140
|
}
|
package/src/mcp/tools/input.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { keyboardBytes } from "../../host-client/steps.ts";
|
|
|
7
7
|
import { TOOL_INPUTS } from "../inputs.ts";
|
|
8
8
|
import { defineTool } from "../server.ts";
|
|
9
9
|
|
|
10
|
-
const EMULATOR_FLAW = z.string().optional().describe("a known flaw of the emulator version that affects input, and the version that fixes it");
|
|
11
10
|
|
|
12
11
|
export const c64Keyboard = defineTool({
|
|
13
12
|
name: "c64_keyboard",
|
|
@@ -19,9 +18,9 @@ export const c64Keyboard = defineTool({
|
|
|
19
18
|
'Mode text types text, for example "RUN\\n". Letters of either case type the normal (unshifted) key. A line break types RETURN. ' +
|
|
20
19
|
"Mode petscii types PETSCII codes 1 to 255 in bytes, for example [147] to clear the screen. " +
|
|
21
20
|
"While c64_autostart loads a program, this tool refuses keys: see c64_autostart. " +
|
|
22
|
-
"This does not change the run state of the machine.
|
|
21
|
+
"This does not change the run state of the machine.",
|
|
23
22
|
inputSchema: TOOL_INPUTS.keyboard,
|
|
24
|
-
outputSchema: z.object({ queuedBytes: z.number().int().min(1).max(MAX_KEYBOARD_BYTES)
|
|
23
|
+
outputSchema: z.object({ queuedBytes: z.number().int().min(1).max(MAX_KEYBOARD_BYTES) }),
|
|
25
24
|
readOnly: false,
|
|
26
25
|
async run(input, session) {
|
|
27
26
|
// The schema checked the keys: keyboardBytes gives bytes here.
|
|
@@ -36,9 +35,9 @@ export const c64Joystick = defineTool({
|
|
|
36
35
|
description:
|
|
37
36
|
"Set the joystick in control port 1 or 2: a direction (or center) and the fire button. " +
|
|
38
37
|
"The C64 sees this state until you change it. To release the joystick, set direction center and fire false. " +
|
|
39
|
-
"Most games read port 2. This does not change the run state of the machine.
|
|
38
|
+
"Most games read port 2. This does not change the run state of the machine.",
|
|
40
39
|
inputSchema: TOOL_INPUTS.joystick,
|
|
41
|
-
outputSchema: z.object({ port: z.union([z.literal(1), z.literal(2)]), direction: z.enum(JOYSTICK_DIRECTIONS), fire: z.boolean()
|
|
40
|
+
outputSchema: z.object({ port: z.union([z.literal(1), z.literal(2)]), direction: z.enum(JOYSTICK_DIRECTIONS), fire: z.boolean() }),
|
|
42
41
|
readOnly: false,
|
|
43
42
|
async run(input, session) {
|
|
44
43
|
return session.joystick(input);
|
package/src/mcp/tools/machine.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
5
|
import { formatC64Address } from "../../c64.ts";
|
|
6
|
-
import { PACKAGE } from "../../package.ts";
|
|
7
6
|
import { VIDEO_STANDARDS } from "../../protocol/messages.ts";
|
|
8
7
|
import { POINT_STOP_REASONS, RESET_MODES, RUN_STATES, SPACES, WINDOW_ACTIONS } from "../../protocol/vice.ts";
|
|
9
8
|
import { AddressOutput, defineTool } from "../server.ts";
|
|
@@ -16,8 +15,7 @@ export const c64Status = defineTool({
|
|
|
16
15
|
"and if warp mode is on. It also tells if the emulator window is open (window). " +
|
|
17
16
|
"When the CPU has stopped, the result also gives the program counter (pc). " +
|
|
18
17
|
"When a breakpoint, a watchpoint or a JAM opcode stopped the CPU, stopReason tells which, and pointId gives the id of the breakpoint or watchpoint. " +
|
|
19
|
-
"cartridge is true while a cartridge from c64_autostart is attached: a reset keeps it, and an autostart of another file detaches it.
|
|
20
|
-
"version is the c64-re-tools version of this MCP server.",
|
|
18
|
+
"cartridge is true while a cartridge from c64_autostart is attached: a reset keeps it, and an autostart of another file detaches it.",
|
|
21
19
|
inputSchema: z.object({}).strict(),
|
|
22
20
|
outputSchema: z.object({
|
|
23
21
|
state: z.enum(RUN_STATES),
|
|
@@ -29,7 +27,6 @@ export const c64Status = defineTool({
|
|
|
29
27
|
pointId: z.number().int().min(1).optional().describe("the id of the breakpoint or watchpoint that stopped the CPU"),
|
|
30
28
|
space: z.enum(SPACES).optional().describe("with pc: c64, or drive8 when a breakpoint or watchpoint in the disk drive stopped the CPU. pc is the address in that space"),
|
|
31
29
|
cartridge: z.boolean().describe("true while a cartridge from c64_autostart is attached"),
|
|
32
|
-
version: z.string().describe("the c64-re-tools version of this MCP server"),
|
|
33
30
|
}),
|
|
34
31
|
readOnly: true,
|
|
35
32
|
async run(_input, session) {
|
|
@@ -40,7 +37,6 @@ export const c64Status = defineTool({
|
|
|
40
37
|
warp: status.warp,
|
|
41
38
|
window: status.window,
|
|
42
39
|
cartridge: status.cartridge,
|
|
43
|
-
version: PACKAGE.version,
|
|
44
40
|
...(status.pc === undefined ? {} : { pc: formatC64Address(status.pc) }),
|
|
45
41
|
...(status.stopReason === undefined ? {} : { stopReason: status.stopReason }),
|
|
46
42
|
...(status.pointId === undefined ? {} : { pointId: status.pointId }),
|
package/src/mcp/tools/media.ts
CHANGED
|
@@ -42,7 +42,6 @@ export const c64Autostart = defineTool({
|
|
|
42
42
|
.strict(),
|
|
43
43
|
outputSchema: z.object({
|
|
44
44
|
state: z.enum(RUN_STATES),
|
|
45
|
-
emulatorFlaw: z.string().optional().describe("for a tape image: a known flaw of this VICE version that stops a tape load"),
|
|
46
45
|
joysticksCentred: z.array(z.union([z.literal(1), z.literal(2)])).optional().describe("the joystick ports that held a direction or fire and were centred before the reset"),
|
|
47
46
|
}),
|
|
48
47
|
readOnly: false,
|
package/src/native/discover.ts
CHANGED
|
@@ -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:
|
|
105
|
-
*
|
|
106
|
-
*
|
|
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
|
|
122
|
-
export function viceFlaws(version: ViceVersion):
|
|
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 {
|
package/src/protocol/messages.ts
CHANGED
|
@@ -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 =
|
|
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. */
|
package/src/protocol/vice.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
526
|
-
|
|
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)
|
|
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
|
}
|