@henols/c64-re-tools 2.5.1-rc.2 → 2.6.0-rc.10
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 +2 -2
- package/skills/c64-assembler/SKILL.md +26 -12
- package/skills/c64-assembler/scripts/assembler.ts +25 -13
- package/skills/c64-development/SKILL.md +2 -2
- package/skills/c64-docs/SKILL.md +4 -4
- package/skills/c64-docs/scripts/docs.ts +7 -7
- package/skills/c64-docs/scripts/lib/reference.ts +3 -3
- package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
- package/skills/c64-knowledge/SKILL.md +29 -20
- package/skills/c64-knowledge/scripts/knowledge.ts +33 -39
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +11 -10
- package/skills/c64-provenance/scripts/lib/library.ts +16 -16
- package/skills/c64-provenance/scripts/provenance.ts +33 -23
- package/skills/c64-reverse-engineering/SKILL.md +16 -10
- package/skills/c64-source/SKILL.md +60 -42
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +26 -7
- package/skills/c64-source/scripts/lib/source.ts +21 -24
- package/skills/c64-source/scripts/lib/stage.ts +6 -5
- package/skills/c64-source/scripts/source.ts +213 -106
- package/skills/c64-static-analysis/SKILL.md +7 -5
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
- package/skills/c64-testing/SKILL.md +5 -2
- package/skills/c64-testing/references/recording-format.md +18 -3
- package/skills/c64-testing/references/scenario-format.md +7 -6
- package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
- package/skills/c64-testing/scripts/lib/play.ts +39 -41
- package/skills/c64-testing/scripts/lib/recording.ts +46 -37
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/runs.ts +2 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
- package/skills/c64-unpacker/SKILL.md +4 -1
- package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/skills/emulator/SKILL.md +7 -12
- package/src/build-name.ts +50 -0
- package/src/c64-keys.ts +98 -0
- package/src/c64.ts +20 -0
- package/src/cli/main.ts +3 -29
- package/src/host/main.ts +1 -1
- package/src/host/tools/index.ts +1 -6
- package/src/host/vice/session.ts +88 -9
- package/src/host-client/steps.ts +17 -17
- package/src/host-client/tools.ts +2 -7
- package/src/host-client/vice-session.ts +7 -1
- package/src/knowledge/program.ts +44 -1
- package/src/knowledge/read.ts +28 -8
- package/src/knowledge/schema.ts +33 -9
- package/src/knowledge/start-screen.ts +4 -0
- package/src/knowledge/text.ts +4 -2
- package/src/knowledge/write.ts +59 -25
- package/src/mcp/inputs.ts +12 -0
- package/src/mcp/server.ts +1 -1
- package/src/mcp/tools/input.ts +38 -5
- package/src/mcp/tools/machine.ts +3 -42
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/acme.ts +1 -1
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +3 -3
- package/src/native/dxa.ts +12 -1
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +4 -4
- package/src/native/types.ts +2 -2
- package/src/platform.ts +30 -1
- package/src/project.ts +17 -4
- package/src/protocol/tools.ts +1 -45
- package/src/protocol/vice.ts +47 -0
- package/src/script.ts +1 -1
- package/src/vsf.ts +98 -0
- package/tools/c64run.c +9 -12
- package/tools/install-container.sh +1 -2
- package/src/cli/status.ts +0 -127
- package/src/host/tools/status.ts +0 -47
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/src/native/status.ts +0 -135
- package/tools/install-ghidra.sh +0 -40
package/src/protocol/tools.ts
CHANGED
|
@@ -79,38 +79,12 @@ export type PetcatResult =
|
|
|
79
79
|
handoffs: BasicHandoff[];
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
/** One native tool on the host, as host.status found and ran it. */
|
|
83
|
-
export interface ToolStatus {
|
|
84
|
-
name: string;
|
|
85
|
-
found: boolean;
|
|
86
|
-
/** Where it is, when found. */
|
|
87
|
-
path?: string;
|
|
88
|
-
/** Its version text, when it ran. */
|
|
89
|
-
version?: string;
|
|
90
|
-
runs: boolean;
|
|
91
|
-
/** What is wrong and what to do, when it is missing or does not run. */
|
|
92
|
-
problem?: string;
|
|
93
|
-
/** Known flaws of this version, each with the version that fixes it. The tool still runs. */
|
|
94
|
-
flaws?: string[];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/** The Host Runtime itself: its package version and the system it runs on. */
|
|
98
|
-
export interface HostInfo {
|
|
99
|
-
version: string;
|
|
100
|
-
/** Node's name of the operating system: linux, darwin or win32. */
|
|
101
|
-
platform: string;
|
|
102
|
-
/** The release of the operating system. */
|
|
103
|
-
release: string;
|
|
104
|
-
arch: string;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
82
|
export interface ToolOperations {
|
|
108
|
-
"host.status": { params: Record<string, never>; result: { host: HostInfo; tools: ToolStatus[] } };
|
|
109
83
|
"c1541.inspect": { params: C1541Params; result: C1541Result };
|
|
110
84
|
"petcat.decode": { params: PetcatParams; result: PetcatResult };
|
|
111
85
|
}
|
|
112
86
|
export type ToolOperation = keyof ToolOperations;
|
|
113
|
-
export const TOOL_OPERATIONS = ["
|
|
87
|
+
export const TOOL_OPERATIONS = ["c1541.inspect", "petcat.decode"] as const satisfies readonly ToolOperation[];
|
|
114
88
|
|
|
115
89
|
const RELATIVE_PATH = /^(?!\/)(?!.*(?:^|\/)\.\.?(?:\/|$))[^\0\\]+$/;
|
|
116
90
|
|
|
@@ -166,10 +140,6 @@ export function validateToolParams<O extends ToolOperation>(op: O, params: unkno
|
|
|
166
140
|
oneFile(attachments, "the program");
|
|
167
141
|
return {} as ToolOperations[O]["params"];
|
|
168
142
|
}
|
|
169
|
-
case "host.status":
|
|
170
|
-
onlyFields(params, []);
|
|
171
|
-
if (attachments.length !== 0) invalid("host.status takes no attachment");
|
|
172
|
-
return {} as ToolOperations[O]["params"];
|
|
173
143
|
}
|
|
174
144
|
return invalid(`unknown tool operation: ${String(op)}`);
|
|
175
145
|
}
|
|
@@ -186,20 +156,6 @@ export function validateToolResult<O extends ToolOperation>(op: O, value: unknow
|
|
|
186
156
|
if (!isPetcatResult(value) || attachments.length !== 0) throw new ProtocolError("petcat.decode result is malformed");
|
|
187
157
|
return value as unknown as ToolOperations[O]["result"];
|
|
188
158
|
}
|
|
189
|
-
case "host.status": {
|
|
190
|
-
const tools = value.tools;
|
|
191
|
-
const isStatus = (tool: unknown) =>
|
|
192
|
-
isObject(tool) &&
|
|
193
|
-
typeof tool.name === "string" &&
|
|
194
|
-
typeof tool.found === "boolean" &&
|
|
195
|
-
typeof tool.runs === "boolean" &&
|
|
196
|
-
[tool.path, tool.version, tool.problem].every((field) => field === undefined || typeof field === "string") &&
|
|
197
|
-
(tool.flaws === undefined || (Array.isArray(tool.flaws) && tool.flaws.every((flaw: unknown) => typeof flaw === "string")));
|
|
198
|
-
const host = value.host;
|
|
199
|
-
const isHost = isObject(host) && [host.version, host.platform, host.release, host.arch].every((field) => typeof field === "string");
|
|
200
|
-
if (!isHost || !Array.isArray(tools) || !tools.every(isStatus) || attachments.length !== 0) throw new ProtocolError("host.status result is malformed");
|
|
201
|
-
return value as unknown as ToolOperations[O]["result"];
|
|
202
|
-
}
|
|
203
159
|
}
|
|
204
160
|
throw new ProtocolError(`unknown tool operation: ${String(op)}`);
|
|
205
161
|
}
|
package/src/protocol/vice.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The VICE-session operations of the Host Runtime wire: their vocabulary, shapes and validators.
|
|
2
2
|
|
|
3
|
+
import { MAX_PRESS_FRAMES, MAX_PRESS_TAPS, MAX_TAP_KEYS, type KeyTap } from "../c64-keys.ts";
|
|
3
4
|
import { invalid, isInteger, isObject, isOneOf, onlyFields, ProtocolError, VIDEO_STANDARDS, type VideoStandard } from "./messages.ts";
|
|
4
5
|
|
|
5
6
|
export const SPACES = ["c64", "drive8"] as const;
|
|
@@ -475,6 +476,20 @@ export interface ExecutionResult {
|
|
|
475
476
|
space?: "c64" | "drive8";
|
|
476
477
|
}
|
|
477
478
|
|
|
479
|
+
/**
|
|
480
|
+
* The end of a press: `taps` taps were done. A breakpoint, watchpoint or JAM
|
|
481
|
+
* can stop the taps early; then `stopReason` tells which, and the machine
|
|
482
|
+
* stays stopped. All keys are up again in both cases.
|
|
483
|
+
*/
|
|
484
|
+
export interface PressResult {
|
|
485
|
+
taps: number;
|
|
486
|
+
state: RunState;
|
|
487
|
+
stopReason?: PointStopReason;
|
|
488
|
+
pc?: number;
|
|
489
|
+
pointId?: number;
|
|
490
|
+
space?: "c64" | "drive8";
|
|
491
|
+
}
|
|
492
|
+
|
|
478
493
|
/** c64_run_until targets. */
|
|
479
494
|
export type RunTarget =
|
|
480
495
|
| { kind: "address"; address: number; space: Space; condition?: Condition }
|
|
@@ -528,6 +543,8 @@ export interface ViceOperations {
|
|
|
528
543
|
/** `data`: PETSCII bytes as lowercase hex. */
|
|
529
544
|
keyboard: { params: { data: string }; result: { queuedBytes: number } };
|
|
530
545
|
joystick: { params: JoystickState; result: JoystickState };
|
|
546
|
+
/** Each tap holds its keys for `frames` frames, then waits `frames` frames with all keys up. */
|
|
547
|
+
press: { params: { taps: KeyTap[]; frames: number }; result: PressResult };
|
|
531
548
|
breakpoint: { params: BreakpointParams; result: Breakpoint | PointRemoved | { breakpoints: Breakpoint[] } };
|
|
532
549
|
watchpoint: { params: WatchpointParams; result: Watchpoint | PointRemoved | { watchpoints: Watchpoint[] } };
|
|
533
550
|
cpuHistory: { params: { limit: number; space: Space }; result: { entries: HistoryEntry[] } };
|
|
@@ -589,6 +606,7 @@ export const VICE_OPERATIONS = [
|
|
|
589
606
|
"reset",
|
|
590
607
|
"keyboard",
|
|
591
608
|
"joystick",
|
|
609
|
+
"press",
|
|
592
610
|
"breakpoint",
|
|
593
611
|
"watchpoint",
|
|
594
612
|
"screenCapture",
|
|
@@ -915,6 +933,24 @@ export function validateViceParams<O extends ViceOperation>(op: O, params: unkno
|
|
|
915
933
|
if (/^(?:..)*?00/.test(params.data)) invalid("PETSCII byte 0 cannot be typed");
|
|
916
934
|
return { data: params.data } as ViceOperations[O]["params"];
|
|
917
935
|
}
|
|
936
|
+
case "press": {
|
|
937
|
+
onlyFields(params, ["taps", "frames"]);
|
|
938
|
+
if (!Array.isArray(params.taps) || params.taps.length === 0 || params.taps.length > MAX_PRESS_TAPS) invalid(`taps must be a list of 1 to ${MAX_PRESS_TAPS} taps`);
|
|
939
|
+
const taps = (params.taps as unknown[]).map((tap): KeyTap => {
|
|
940
|
+
if (!isObject(tap)) invalid("each tap must be an object with keys and restore");
|
|
941
|
+
onlyFields(tap, ["keys", "restore"], "a tap");
|
|
942
|
+
const { keys, restore } = tap;
|
|
943
|
+
if (!Array.isArray(keys) || !keys.every((key, index) => isInteger(key, 0, 63) && (index === 0 || key > (keys[index - 1] as number)))) {
|
|
944
|
+
invalid("keys of a tap must be matrix places from 0 to 63, each once, in rising order");
|
|
945
|
+
}
|
|
946
|
+
if (typeof restore !== "boolean") invalid("restore of a tap must be true or false");
|
|
947
|
+
const count = keys.length + (restore ? 1 : 0);
|
|
948
|
+
if (count === 0 || count > MAX_TAP_KEYS) invalid(`a tap holds 1 to ${MAX_TAP_KEYS} keys, RESTORE included`);
|
|
949
|
+
return { keys: keys as number[], restore };
|
|
950
|
+
});
|
|
951
|
+
if (!isInteger(params.frames, 1, MAX_PRESS_FRAMES)) invalid(`frames must be a whole number from 1 to ${MAX_PRESS_FRAMES}`);
|
|
952
|
+
return { taps, frames: params.frames } as ViceOperations[O]["params"];
|
|
953
|
+
}
|
|
918
954
|
case "joystick": {
|
|
919
955
|
onlyFields(params, ["port", "direction", "fire"]);
|
|
920
956
|
if (params.port !== 1 && params.port !== 2) invalid("port must be 1 or 2");
|
|
@@ -1206,6 +1242,17 @@ export function validateViceResult<O extends ViceOperation>(op: O, value: unknow
|
|
|
1206
1242
|
if (!isInteger(value.queuedBytes, 1, MAX_KEYBOARD_BYTES)) throw new ProtocolError("keyboard result is malformed");
|
|
1207
1243
|
break;
|
|
1208
1244
|
}
|
|
1245
|
+
case "press": {
|
|
1246
|
+
const ok =
|
|
1247
|
+
isInteger(value.taps, 0, MAX_PRESS_TAPS) &&
|
|
1248
|
+
isOneOf(RUN_STATES, value.state) &&
|
|
1249
|
+
(value.stopReason === undefined || isOneOf(POINT_STOP_REASONS, value.stopReason)) &&
|
|
1250
|
+
(value.pc === undefined || isInteger(value.pc, 0, 0xffff)) &&
|
|
1251
|
+
(value.pointId === undefined || isInteger(value.pointId, 1, Number.MAX_SAFE_INTEGER)) &&
|
|
1252
|
+
(value.space === undefined || isOneOf(SPACES, value.space));
|
|
1253
|
+
if (!ok) throw new ProtocolError("press result is malformed");
|
|
1254
|
+
break;
|
|
1255
|
+
}
|
|
1209
1256
|
case "breakpoint": {
|
|
1210
1257
|
const ok = Array.isArray(value.breakpoints) ? value.breakpoints.every(isBreakpoint) : isRemoved(value) || isBreakpoint(value);
|
|
1211
1258
|
if (!ok) throw new ProtocolError("breakpoint result is malformed");
|
package/src/script.ts
CHANGED
|
@@ -121,7 +121,7 @@ export interface OptionSpec {
|
|
|
121
121
|
/** The options that have one meaning in every script. A command can change the help, the value and whether it is required, never the kind. */
|
|
122
122
|
export const OPTIONS = {
|
|
123
123
|
out: { kind: "path", value: "<path>", help: "write the output here, relative to the project folder" },
|
|
124
|
-
space: { kind: "space", value: "<space>", help: "the knowledge space: c64 (the default), drive8 for 1541 drive code, loading for a captured stage of the loading, or bank0 to bank255 for a cartridge bank", default: "c64" },
|
|
124
|
+
space: { kind: "space", value: "<space>", help: "the knowledge space: c64 (the default), drive8 for 1541 drive code, loading for a captured stage of the loading, or bank0 to bank255 for a cartridge bank or another memory image of the program", default: "c64" },
|
|
125
125
|
range: { kind: "range", value: "<start>-<end>", help: "only the addresses from start to end, for example '$c000-$cfff'" },
|
|
126
126
|
entry: { kind: "address", value: "<address>", help: "an entry point of the program" },
|
|
127
127
|
steps: { kind: "path", value: "<file>", help: "a JSON file of action steps that run after the start" },
|
package/src/vsf.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// The modules of a VICE snapshot file (.vsf), and the two changes that press
|
|
2
|
+
// keys in it: the keyboard matrix and a RESTORE. VICE saves a module as its
|
|
3
|
+
// name (16 bytes), its version (major, minor), its size with this header
|
|
4
|
+
// (4 bytes) and its data; every number is little-endian.
|
|
5
|
+
|
|
6
|
+
import { hasSignature, VSF_SIGNATURE } from "./media.ts";
|
|
7
|
+
|
|
8
|
+
/** The size of the header of a module: the name (16 bytes), the version (2 bytes) and the size (4 bytes). */
|
|
9
|
+
const MODULE_HEADER = 22;
|
|
10
|
+
const VSF_VERSION = "VICE Version\x1a";
|
|
11
|
+
|
|
12
|
+
export interface SnapshotModule {
|
|
13
|
+
major: number;
|
|
14
|
+
minor: number;
|
|
15
|
+
/** The data of the module: a view into the file, so a change to it changes the file. */
|
|
16
|
+
data: Buffer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The module `name` of a snapshot file. Undefined when the file is no snapshot or has no such module. */
|
|
20
|
+
export function snapshotModule(file: Buffer, name: string): SnapshotModule | undefined {
|
|
21
|
+
if (!hasSignature("vsf", file)) return undefined;
|
|
22
|
+
// The magic, the version (2 bytes) and the machine name (16 bytes); a newer VICE adds its own version (8 bytes).
|
|
23
|
+
let at = VSF_SIGNATURE.length + 2 + 16;
|
|
24
|
+
if (file.subarray(at, at + VSF_VERSION.length).toString("latin1") === VSF_VERSION) at += VSF_VERSION.length + 8;
|
|
25
|
+
while (at + MODULE_HEADER <= file.length) {
|
|
26
|
+
const size = file.readUInt32LE(at + 18);
|
|
27
|
+
if (size < MODULE_HEADER || at + size > file.length) return undefined;
|
|
28
|
+
if (file.subarray(at, at + 16).toString("latin1").replace(/\0+$/, "") === name) {
|
|
29
|
+
return { major: file[at + 16]!, minor: file[at + 17]!, data: file.subarray(at + MODULE_HEADER, at + size) };
|
|
30
|
+
}
|
|
31
|
+
at += size;
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** VICE's keyboard module: keyarr (16 rows) and rev_keyarr (8 columns), each a DWORD. */
|
|
37
|
+
const KEYBOARD = { name: "KEYBOARD", major: 1, minor: 1, size: (16 + 8) * 4 };
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The CPU module of x64sc. VICE r46088 renamed MAINCPU 1.4 to MAINC64CPU 1.5;
|
|
41
|
+
* the data is the same: the clock (8 bytes), A, X, Y, SP, PC (2), P, five
|
|
42
|
+
* DWORDs, five clocks (irq_clk, nmi_clk, ...), then nirq, nnmi and
|
|
43
|
+
* global_pending_int, then two clocks.
|
|
44
|
+
*/
|
|
45
|
+
const CPU = [
|
|
46
|
+
{ name: "MAINC64CPU", major: 1, minor: 5 },
|
|
47
|
+
{ name: "MAINCPU", major: 1, minor: 4 },
|
|
48
|
+
];
|
|
49
|
+
const CPU_SIZE = 103;
|
|
50
|
+
const NMI_CLK = 43;
|
|
51
|
+
const NNMI = 79;
|
|
52
|
+
const PENDING = 83;
|
|
53
|
+
/** IK_NMI of global_pending_int. */
|
|
54
|
+
const PENDING_NMI = 1;
|
|
55
|
+
|
|
56
|
+
/** A module of a version that the patch knows, or why there is none. */
|
|
57
|
+
function known(file: Buffer, versions: Array<{ name: string; major: number; minor: number }>, size: number): Buffer | string {
|
|
58
|
+
for (const version of versions) {
|
|
59
|
+
const module = snapshotModule(file, version.name);
|
|
60
|
+
if (module === undefined) continue;
|
|
61
|
+
if (module.major !== version.major || module.minor !== version.minor || module.data.length < size) {
|
|
62
|
+
return `the snapshot has ${version.name} ${module.major}.${module.minor} with ${module.data.length} bytes, and c64-re-tools knows ${version.major}.${version.minor} with ${size}`;
|
|
63
|
+
}
|
|
64
|
+
return module.data;
|
|
65
|
+
}
|
|
66
|
+
return `the snapshot has no module ${versions.map((version) => version.name).join(" or ")}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Sets the keyboard matrix of a snapshot file: bit n of rows[r] is the key at
|
|
71
|
+
* row r, column n. Gives why it cannot, for a snapshot of another layout.
|
|
72
|
+
*/
|
|
73
|
+
export function setSnapshotMatrix(file: Buffer, rows: readonly number[]): string | undefined {
|
|
74
|
+
const data = known(file, [KEYBOARD], KEYBOARD.size);
|
|
75
|
+
if (typeof data === "string") return data;
|
|
76
|
+
for (let row = 0; row < 16; row++) data.writeUInt32LE(rows[row] ?? 0, row * 4);
|
|
77
|
+
for (let column = 0; column < 8; column++) {
|
|
78
|
+
let lines = 0;
|
|
79
|
+
for (let row = 0; row < 8; row++) if (((rows[row] ?? 0) >> column) & 1) lines |= 1 << row;
|
|
80
|
+
data.writeUInt32LE(lines, 64 + column * 4);
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Presses RESTORE in a snapshot file, as VICE does: an NMI from now on, unless
|
|
87
|
+
* another source holds the NMI line or an NMI is pending already, which gives
|
|
88
|
+
* no new edge. Gives why it cannot, for a snapshot of another layout.
|
|
89
|
+
*/
|
|
90
|
+
export function pressSnapshotRestore(file: Buffer): string | undefined {
|
|
91
|
+
const data = known(file, CPU, CPU_SIZE);
|
|
92
|
+
if (typeof data === "string") return data;
|
|
93
|
+
const pending = data.readUInt32LE(PENDING);
|
|
94
|
+
if (data.readUInt32LE(NNMI) !== 0 || (pending & PENDING_NMI) !== 0) return undefined;
|
|
95
|
+
data.writeUInt32LE(pending | PENDING_NMI, PENDING);
|
|
96
|
+
data.writeBigUInt64LE(data.readBigUInt64LE(0), NMI_CLK);
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
package/tools/c64run.c
CHANGED
|
@@ -27,11 +27,9 @@
|
|
|
27
27
|
#include "systems/c1541.h"
|
|
28
28
|
#include "systems/c64.h"
|
|
29
29
|
|
|
30
|
-
#define C64RUN_PROTOCOL
|
|
31
|
-
//
|
|
32
|
-
#define
|
|
33
|
-
#define C64RUN_KEY_RSHIFT 0x12
|
|
34
|
-
#define C64RUN_KEY_UPARROW 0x5E
|
|
30
|
+
#define C64RUN_PROTOCOL 4
|
|
31
|
+
// The key code of matrix place 0 (row 0, column 0); place n has code 0x80 + n.
|
|
32
|
+
#define C64RUN_KEY_PLACE 0x80
|
|
35
33
|
#ifndef CHIPS_COMMIT
|
|
36
34
|
#define CHIPS_COMMIT "unknown"
|
|
37
35
|
#endif
|
|
@@ -335,10 +333,9 @@ static const char* init(const char* romdir) {
|
|
|
335
333
|
.chars = { .ptr = rom[2], .size = 0x1000 },
|
|
336
334
|
},
|
|
337
335
|
});
|
|
338
|
-
//
|
|
339
|
-
|
|
340
|
-
kbd_register_key(&sys.kbd,
|
|
341
|
-
kbd_register_key(&sys.kbd, C64RUN_KEY_UPARROW, 6, 6, 0);
|
|
336
|
+
// One code for each place of the matrix: place row * 8 + column, where the row is the
|
|
337
|
+
// line of CIA 1 port A and the column the bit of port B (chips: column, line).
|
|
338
|
+
for (int place = 0; place < 64; place++) kbd_register_key(&sys.kbd, C64RUN_KEY_PLACE + place, place & 7, place >> 3, 0);
|
|
342
339
|
const uint16_t vector = rom[0][0x1FFC] | (rom[0][0x1FFD] << 8);
|
|
343
340
|
for (int i = 0; i < 3; i++) free(rom[i]);
|
|
344
341
|
pins = sys.pins;
|
|
@@ -536,11 +533,11 @@ int main(int argc, char** argv) {
|
|
|
536
533
|
c64_joystick(&sys, (uint8_t)j1, (uint8_t)j2);
|
|
537
534
|
printf("ok\n");
|
|
538
535
|
} else if (!strcmp(cmd, "key")) {
|
|
539
|
-
// key <code hex> down|up:
|
|
540
|
-
//
|
|
541
|
-
// 11 and 12 are the left and right SHIFT alone, 5e the up arrow, ff RESTORE (NMI).
|
|
536
|
+
// key <code hex> down|up: 80 + place is the key at matrix place row * 8 + column
|
|
537
|
+
// (80-bf), ff is RESTORE (NMI). chips holds at most 4 keys at once.
|
|
542
538
|
unsigned code;
|
|
543
539
|
if (sscanf(a1, "%x", &code) != 1 || (strcmp(a2, "down") && strcmp(a2, "up"))) { printf("err key: give a code and down or up\n"); continue; }
|
|
540
|
+
if ((code < C64RUN_KEY_PLACE || code >= C64RUN_KEY_PLACE + 64) && code != C64_KEY_RESTORE) { printf("err key: give 80-bf (a matrix place) or ff (RESTORE)\n"); continue; }
|
|
544
541
|
if (!strcmp(a2, "down")) c64_key_down(&sys, (int)code);
|
|
545
542
|
else {
|
|
546
543
|
// chips releases a key in kbd_update, after its sticky time: one call
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# The native tools of the skill scripts in a Debian or Ubuntu dev container,
|
|
3
|
-
# as root: ACME, dxa, Exomizer, c64run with its C64 ROMs
|
|
3
|
+
# as root: ACME, dxa, Exomizer, and c64run with its C64 ROMs. The dev container
|
|
4
4
|
# Feature runs the copy of this script that comes with the toolkit version it
|
|
5
5
|
# installs, so the tools and the skills are always of the same version.
|
|
6
6
|
# A tool is installed again only when its install files changed: a stamp in
|
|
@@ -57,6 +57,5 @@ packages acme unzip curl ca-certificates build-essential
|
|
|
57
57
|
tool dxa install-dxa.sh
|
|
58
58
|
tool exomizer install-exomizer.sh
|
|
59
59
|
tool c64run install-chips.sh c64run.c
|
|
60
|
-
tool ghidra install-ghidra.sh
|
|
61
60
|
|
|
62
61
|
[[ -z "${APT_UPDATED}" ]] || rm -rf /var/lib/apt/lists/*
|
package/src/cli/status.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// The status report of the CLI: the installed skills and MCP declarations,
|
|
2
|
-
// the tools on this machine and the Host Runtime with its tools.
|
|
3
|
-
|
|
4
|
-
import { readFileSync } from "node:fs";
|
|
5
|
-
import { isAbsolute, join } from "node:path";
|
|
6
|
-
|
|
7
|
-
import { installedItems, scopeRoot, type InstallItem, type Scope } from "./cleanup.ts";
|
|
8
|
-
import { hostTools, type ToolCallOptions } from "../host-client/tools.ts";
|
|
9
|
-
import { viceVersionOf } from "../native/discover.ts";
|
|
10
|
-
import { PACKAGE } from "../package.ts";
|
|
11
|
-
import { STOP_AND_ASK } from "../protocol/messages.ts";
|
|
12
|
-
import type { HostInfo, ToolStatus } from "../protocol/tools.ts";
|
|
13
|
-
|
|
14
|
-
/** One line per tool under `heading`: its version, or why it does not run; then each known flaw of it. */
|
|
15
|
-
export function toolLines(heading: string, tools: readonly ToolStatus[]): string[] {
|
|
16
|
-
return [
|
|
17
|
-
heading,
|
|
18
|
-
...tools.flatMap((tool) => [
|
|
19
|
-
tool.runs
|
|
20
|
-
? ` ${tool.name}: ${tool.version} (${tool.path})`
|
|
21
|
-
: tool.found
|
|
22
|
-
? ` ${tool.name}: found at ${tool.path} but it does not run. ${tool.problem}`
|
|
23
|
-
: ` ${tool.name}: missing. ${tool.problem}`,
|
|
24
|
-
...(tool.flaws ?? []).map((flaw) => ` Known flaw: ${flaw}`),
|
|
25
|
-
]),
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Whether the Host Runtime answers, and the tools it has. VICE and its tools
|
|
31
|
-
* live on the host; it finds and runs each one. One request shows both that
|
|
32
|
-
* the host answers and what it has. `ready` is true when the host answers and
|
|
33
|
-
* every tool on it runs.
|
|
34
|
-
*/
|
|
35
|
-
export async function hostStatusLines(options: ToolCallOptions = {}): Promise<{ lines: string[]; ready: boolean }> {
|
|
36
|
-
let host: HostInfo;
|
|
37
|
-
let tools: ToolStatus[];
|
|
38
|
-
try {
|
|
39
|
-
({ host, tools } = await hostTools(options));
|
|
40
|
-
} catch (error) {
|
|
41
|
-
// status is read by a person: the instruction for an agent stays out.
|
|
42
|
-
return { lines: [`Host Runtime: not reachable. ${(error as Error).message.replace(` ${STOP_AND_ASK}`, "")}`], ready: false };
|
|
43
|
-
}
|
|
44
|
-
const mixed = mixedViceBuilds(tools);
|
|
45
|
-
return {
|
|
46
|
-
lines: [
|
|
47
|
-
`Host Runtime: reachable, c64-re-tools ${host.version} on ${host.platform} ${host.release} (${host.arch})`,
|
|
48
|
-
...(host.version === PACKAGE.version ? [] : [` Warning: the Host Runtime is c64-re-tools ${host.version} and this is ${PACKAGE.version}. Start the host again so that both are the same version.`]),
|
|
49
|
-
...toolLines("Tools on the host:", tools),
|
|
50
|
-
...(mixed === undefined ? [] : [` Warning: ${mixed}`]),
|
|
51
|
-
],
|
|
52
|
-
ready: tools.every((tool) => tool.runs),
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** A warning when x64sc, c1541 and petcat that run come from different VICE versions or builds. */
|
|
57
|
-
export function mixedViceBuilds(tools: readonly ToolStatus[]): string | undefined {
|
|
58
|
-
const running = tools.filter((tool) => tool.runs && tool.version !== undefined);
|
|
59
|
-
const builds = running.map((tool) => {
|
|
60
|
-
const version = viceVersionOf(tool.version!);
|
|
61
|
-
return version === undefined ? tool.version! : `VICE ${version.major}.${version.minor}${version.revision === undefined ? "" : ` SVN r${version.revision}`}`;
|
|
62
|
-
});
|
|
63
|
-
if (new Set(builds).size <= 1) return undefined;
|
|
64
|
-
return `the VICE tools come from different VICE builds: ${running.map((tool) => `${tool.version} (${tool.path})`).join(", ")}. Put x64sc, c1541 and petcat of one VICE first on PATH, or set C64RT_VICE, C64RT_C1541 and C64RT_PETCAT.`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The skills and MCP declarations that install wrote for this project and
|
|
69
|
-
* globally: the c64-re-tools version of each harness's skills,
|
|
70
|
-
* from their package.json, and the command that starts the MCP server. A
|
|
71
|
-
* warning names skills of another version than this one.
|
|
72
|
-
*/
|
|
73
|
-
export function installedLines(cwd = process.cwd()): string[] {
|
|
74
|
-
const lines: string[] = [];
|
|
75
|
-
for (const scope of ["project", "global"] as const satisfies readonly Scope[]) {
|
|
76
|
-
const items = installedItems(scope, undefined, cwd);
|
|
77
|
-
if (items.length === 0) continue;
|
|
78
|
-
const root = scopeRoot(scope, cwd);
|
|
79
|
-
lines.push(`Installed ${scope === "project" ? `in this project (${root})` : "globally"}:`);
|
|
80
|
-
for (const harness of [...new Set(items.map((item) => item.harness))]) {
|
|
81
|
-
const skills = items.filter((item) => item.harness === harness && item.kind === "skill");
|
|
82
|
-
const versions = [...new Set(skills.map((item) => skillVersion(item, root)).filter((version) => version !== undefined))];
|
|
83
|
-
if (skills.length > 0) {
|
|
84
|
-
lines.push(` ${harness}: ${skills.length} skills, c64-re-tools ${versions.length === 0 ? "of an unknown version" : versions.join(" and ")}`);
|
|
85
|
-
const other = versions.filter((version) => version !== PACKAGE.version);
|
|
86
|
-
if (other.length > 0) lines.push(` Warning: the ${harness} skills are c64-re-tools ${other.join(" and ")} and this is ${PACKAGE.version}. Run npx -y ${PACKAGE.name}@${PACKAGE.tag} update${scope === "global" ? " --global" : ""} to install this version.`);
|
|
87
|
-
}
|
|
88
|
-
for (const item of items.filter((candidate) => candidate.harness === harness && candidate.kind === "mcp")) {
|
|
89
|
-
lines.push(` ${harness} MCP server: ${mcpCommand(item, root) ?? `declared in ${item.files.join(", ")}`}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (lines.length === 0) return ["Installed: nothing in this project or globally."];
|
|
94
|
-
return lines;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function itemPath(file: string, root: string): string {
|
|
98
|
-
return isAbsolute(file) ? file : join(root, file);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/** The version in the package.json of an installed skill; a skill without scripts has none. */
|
|
102
|
-
function skillVersion(item: InstallItem, root: string): string | undefined {
|
|
103
|
-
const file = item.files.find((candidate) => candidate.endsWith("/package.json") || candidate.endsWith("\\package.json"));
|
|
104
|
-
if (file === undefined) return undefined;
|
|
105
|
-
try {
|
|
106
|
-
const { version } = JSON.parse(readFileSync(itemPath(file, root), "utf8")) as { version?: unknown };
|
|
107
|
-
return typeof version === "string" ? version : undefined;
|
|
108
|
-
} catch {
|
|
109
|
-
return undefined;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** The command of the MCP server in a JSON configuration file, or undefined for another format. */
|
|
114
|
-
function mcpCommand(item: InstallItem, root: string): string | undefined {
|
|
115
|
-
const key = item.detail?.mergeKey;
|
|
116
|
-
const [file] = item.files;
|
|
117
|
-
if (key === undefined || file === undefined) return undefined;
|
|
118
|
-
try {
|
|
119
|
-
const servers = (JSON.parse(readFileSync(itemPath(file, root), "utf8")) as Record<string, unknown>)[key] as Record<string, { command?: unknown; args?: unknown }> | undefined;
|
|
120
|
-
const server = servers?.[item.name];
|
|
121
|
-
if (typeof server?.command !== "string") return undefined;
|
|
122
|
-
const args = Array.isArray(server.args) ? server.args.filter((arg): arg is string => typeof arg === "string") : [];
|
|
123
|
-
return [server.command, ...args].join(" ");
|
|
124
|
-
} catch {
|
|
125
|
-
return undefined;
|
|
126
|
-
}
|
|
127
|
-
}
|
package/src/host/tools/status.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
// host.status: VICE and the tools that come with it, each found the way its
|
|
2
|
-
// operations find it and run once with a version option. A tool from a
|
|
3
|
-
// VICE older than MIN_VICE is reported as not working, as its operations refuse it.
|
|
4
|
-
// VICE itself is reported with the version that the host read from the
|
|
5
|
-
// running emulator at start: the Homebrew x64sc of VICE 3.10 on macOS stops
|
|
6
|
-
// on -version ("argv[0] is NULL") although the emulator runs.
|
|
7
|
-
|
|
8
|
-
import { arch, platform, release } from "node:os";
|
|
9
|
-
|
|
10
|
-
import { PACKAGE } from "../../package.ts";
|
|
11
|
-
import type { HostInfo, ToolStatus } from "../../protocol/tools.ts";
|
|
12
|
-
import { C1541, findTool, isOlderThanMinimum, MIN_VICE, PETCAT, VICE, viceFlaws, viceVersionOf, type ToolSpec, type ViceVersion } from "../../native/discover.ts";
|
|
13
|
-
import type { ToolContext } from "../../native/run.ts";
|
|
14
|
-
import { probeTools } from "../../native/status.ts";
|
|
15
|
-
import { findVice } from "../vice/process.ts";
|
|
16
|
-
|
|
17
|
-
function requireMinimum(status: ToolStatus, tool: ToolSpec): ToolStatus {
|
|
18
|
-
if (!status.runs) return status;
|
|
19
|
-
const version = viceVersionOf(status.version ?? "");
|
|
20
|
-
if (version !== undefined && !isOlderThanMinimum(version)) return status;
|
|
21
|
-
const found = version === undefined ? "It does not tell its VICE version" : `It comes from VICE ${version.major}.${version.minor}`;
|
|
22
|
-
return { ...status, runs: false, problem: `${found}, and c64-re-tools needs VICE ${MIN_VICE.major}.${MIN_VICE.minor} or later. ${tool.remedy}` };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** The version text of a VICE version, as x64sc -version prints it. */
|
|
26
|
-
const versionText = (version: ViceVersion) => `x64sc (VICE ${version.major}.${version.minor}${version.revision === undefined ? "" : ` SVN r${version.revision}`})`;
|
|
27
|
-
|
|
28
|
-
/** `started`: the version that the host read from the emulator at start; without it, VICE is probed with -version too. */
|
|
29
|
-
export async function hostStatus(context: ToolContext, started?: ViceVersion): Promise<{ result: { host: HostInfo; tools: ToolStatus[] } }> {
|
|
30
|
-
const specs = [VICE, C1541, PETCAT];
|
|
31
|
-
const probed = await probeTools(
|
|
32
|
-
[
|
|
33
|
-
...(started === undefined ? [{ name: VICE.name, find: findVice, args: ["-version"], pattern: /^x64sc \(VICE \d/ }] : []),
|
|
34
|
-
{ name: C1541.name, find: (env) => findTool(C1541, env), args: ["-version"], pattern: /^c1541 \(VICE \d/ },
|
|
35
|
-
{ name: PETCAT.name, find: (env) => findTool(PETCAT, env), args: ["-version"], pattern: /^petcat \(VICE \d/ },
|
|
36
|
-
],
|
|
37
|
-
context,
|
|
38
|
-
);
|
|
39
|
-
const tools = started === undefined ? probed : [{ name: VICE.name, found: true, path: findVice(context.env ?? process.env), version: versionText(started), runs: true }, ...probed];
|
|
40
|
-
const checked = tools.map((status, index) => requireMinimum(status, specs[index]!));
|
|
41
|
-
// VICE runs with its known flaws; status names them.
|
|
42
|
-
const vice = checked[0]!;
|
|
43
|
-
const version = vice.runs ? viceVersionOf(vice.version ?? "") : undefined;
|
|
44
|
-
const flaws = version === undefined ? [] : viceFlaws(version).map((flaw) => flaw.text);
|
|
45
|
-
if (flaws.length > 0) checked[0] = { ...vice, flaws };
|
|
46
|
-
return { result: { host: { version: PACKAGE.version, platform: platform(), release: release(), arch: arch() }, tools: checked } };
|
|
47
|
-
}
|