@henols/c64-re-tools 2.1.3 → 2.1.5
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 +3 -3
- package/package.json +2 -1
- package/skills/c64-assembler/SKILL.md +1 -1
- package/skills/c64-assembler/scripts/assembler.ts +2 -2
- package/skills/c64-docs/SKILL.md +1 -1
- package/skills/c64-docs/scripts/docs.ts +5 -3
- package/skills/c64-emulator/SKILL.md +2 -0
- package/skills/c64-knowledge/SKILL.md +1 -0
- package/skills/c64-memory-map/SKILL.md +1 -1
- package/skills/c64-memory-map/scripts/memory-map.ts +4 -2
- package/skills/c64-provenance/SKILL.md +1 -1
- package/skills/c64-provenance/scripts/lib/compare.ts +12 -0
- package/skills/c64-provenance/scripts/lib/library.ts +7 -2
- package/skills/c64-provenance/scripts/provenance.ts +13 -7
- package/skills/c64-source/SKILL.md +2 -1
- package/skills/c64-source/scripts/source.ts +31 -15
- package/skills/c64-static-analysis/scripts/lib/findings.ts +24 -2
- package/skills/c64-testing/references/scenario-format.md +2 -0
- package/skills/c64-testing/scripts/lib/runs.ts +1 -1
- package/skills/c64-testing/scripts/lib/scenario.ts +4 -3
- package/skills/c64-testing/scripts/testing.ts +1 -1
- package/skills/c64-unpacker/SKILL.md +3 -2
- package/skills/c64-unpacker/scripts/lib/loads.ts +5 -2
- package/src/host/vice/session.ts +22 -2
- package/src/host-client/vice-session.ts +3 -3
- package/src/knowledge/write.ts +46 -1
- package/src/mcp/tools/media.ts +3 -4
- package/src/media.ts +3 -0
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +2 -2
- package/src/project.ts +6 -2
- package/src/script.ts +9 -1
- package/tools/c64run.c +655 -0
- package/tools/install-chips.sh +66 -0
- package/tools/install-container.sh +61 -0
- package/tools/install-dxa.sh +336 -0
- package/tools/install-ghidra.sh +40 -0
|
@@ -129,19 +129,19 @@ export class ViceSessionClient {
|
|
|
129
129
|
|
|
130
130
|
/** Loads a project PRG into memory without reset or start; finishes stopped. `root` is the project folder; it stays on this side. */
|
|
131
131
|
async programLoad(params: { path: string; address?: number; root?: string }): Promise<{ state: RunState; loadAddress: number; size: number }> {
|
|
132
|
-
const file = readProjectFile(params.path, params.root === undefined ? {} : { root: params.root });
|
|
132
|
+
const file = readProjectFile(params.path, params.root === undefined ? { what: "path" } : { root: params.root, what: "path" });
|
|
133
133
|
return this.#request("programLoad", params.address === undefined ? {} : { address: params.address }, [file.bytes]);
|
|
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
137
|
async autostart(params: { path: string; index: number; run: boolean; root?: string }): Promise<{ state: RunState; emulatorFlaw?: string }> {
|
|
138
|
-
const file = readProjectFile(params.path, params.root === undefined ? {} : { root: params.root });
|
|
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
|
}
|
|
141
141
|
|
|
142
142
|
/** Attaches a project disk image to drive 8. `root` is the project folder; it stays on this side. */
|
|
143
143
|
async diskAttach(params: { path: string; root?: string }): Promise<{ attached: boolean }> {
|
|
144
|
-
const file = readProjectFile(params.path, params.root === undefined ? {} : { root: params.root });
|
|
144
|
+
const file = readProjectFile(params.path, params.root === undefined ? { what: "path" } : { root: params.root, what: "path" });
|
|
145
145
|
return this.#request("diskAttach", { type: file.type }, [file.bytes]);
|
|
146
146
|
}
|
|
147
147
|
|
package/src/knowledge/write.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { type AddressRange, formatC64Address, instructionLength, SPACE_PATTERN,
|
|
|
8
8
|
import { isoCet } from "../time.ts";
|
|
9
9
|
import { CONFLICT_RULES, conflicts, conflictTable, type Conflict, type ConflictRow } from "./conflicts.ts";
|
|
10
10
|
import { transaction } from "./database.ts";
|
|
11
|
-
import { labelProblem } from "../opcodes.ts";
|
|
11
|
+
import { labelProblem, MNEMONICS } from "../opcodes.ts";
|
|
12
12
|
import { checkExpression, evaluate, identifiers, operandText, replaceIdentifiers } from "./expression.ts";
|
|
13
13
|
import {
|
|
14
14
|
COMMENT_COLUMNS,
|
|
@@ -787,11 +787,56 @@ function checkPatch(request: PatchRequest): void {
|
|
|
787
787
|
checkCommentText(request.comment, "A patch comment");
|
|
788
788
|
}
|
|
789
789
|
|
|
790
|
+
/** The data directives whose length the items give: the bytes of each item. */
|
|
791
|
+
const DATA_ITEM_BYTES: Record<string, number> = { "!byte": 1, "!by": 1, "!8": 1, "!08": 1, "!word": 2, "!wo": 2, "!16": 2 };
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
* The least count of bytes that ACME patch code assembles to, when each line
|
|
795
|
+
* is empty, a comment, a data directive (!byte, !word, !fill with a number) or
|
|
796
|
+
* a 6510 instruction without a label. An instruction is 1 byte without an
|
|
797
|
+
* operand (or with A), else at least 2. Undefined for code with another line,
|
|
798
|
+
* for example a label, a macro use or a condition: then only the build of the
|
|
799
|
+
* switch (c64-source generate) gives the length.
|
|
800
|
+
*/
|
|
801
|
+
export function leastPatchBytes(code: string): number | undefined {
|
|
802
|
+
let bytes = 0;
|
|
803
|
+
for (const raw of code.split("\n")) {
|
|
804
|
+
if (/["']/.test(raw)) return undefined;
|
|
805
|
+
const line = raw.replace(/;.*$/, "").trim();
|
|
806
|
+
if (line === "") continue;
|
|
807
|
+
const [word, ...rest] = line.split(/\s+/);
|
|
808
|
+
const lower = word!.toLowerCase();
|
|
809
|
+
const operand = rest.join(" ");
|
|
810
|
+
const itemBytes = DATA_ITEM_BYTES[lower];
|
|
811
|
+
if (itemBytes !== undefined) {
|
|
812
|
+
if (operand === "") return undefined;
|
|
813
|
+
bytes += itemBytes * operand.split(",").length;
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
if (lower === "!fill" || lower === "!fi") {
|
|
817
|
+
const count = /^(?:\$([0-9a-f]+)|([0-9]+))\s*(?:,|$)/i.exec(operand);
|
|
818
|
+
if (count === null) return undefined;
|
|
819
|
+
bytes += count[1] === undefined ? Number.parseInt(count[2]!, 10) : Number.parseInt(count[1], 16);
|
|
820
|
+
continue;
|
|
821
|
+
}
|
|
822
|
+
const instruction = /^([a-z]{3})(?:\+([123]))?$/.exec(lower);
|
|
823
|
+
if (instruction === null || !MNEMONICS.has(instruction[1]!)) return undefined;
|
|
824
|
+
if (instruction[2] !== undefined) bytes += 1 + Number(instruction[2]);
|
|
825
|
+
else bytes += operand === "" || operand.toLowerCase() === "a" ? 1 : 2;
|
|
826
|
+
}
|
|
827
|
+
return bytes;
|
|
828
|
+
}
|
|
829
|
+
|
|
790
830
|
function patchStep(db: DatabaseSync, change: Change, context: ChangeContext & { image?: OperandImage }, request: PatchRequest): Step<PatchRow, PatchRow> {
|
|
791
831
|
const space = spaceOf(request);
|
|
792
832
|
const range = `${formatC64Address(request.start)}-${formatC64Address(request.end)}`;
|
|
793
833
|
if (context.image === undefined) throw new Refusal("invalid-input", "A patch is checked against the image, and no image was given.");
|
|
794
834
|
checkInImage(context.image, request.start, request.end, "a patch");
|
|
835
|
+
const least = leastPatchBytes(request.code);
|
|
836
|
+
const length = request.end - request.start + 1;
|
|
837
|
+
if (least !== undefined && least > length) {
|
|
838
|
+
throw new Refusal("invalid-input", `The patch code is at least ${least} bytes, and the range ${range} has ${length}. Make the code shorter, or make the range larger.`);
|
|
839
|
+
}
|
|
795
840
|
const symbol = symbolNamed(db, request.switch, space);
|
|
796
841
|
if (symbol !== undefined) throw new Refusal("conflict", `The switch name ${request.switch} is the name of the symbol at ${formatC64Address(symbol.address)}. Give the switch another name.`);
|
|
797
842
|
if (space === DEFAULT_SPACE && context.image.platform.has(request.switch)) throw new Refusal("conflict", `The switch name ${request.switch} is a C64 platform name. Give the switch another name.`);
|
package/src/mcp/tools/media.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { extname } from "node:path";
|
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
|
|
9
9
|
import { formatC64Address } from "../../c64.ts";
|
|
10
|
+
import { refuseNotPrg } from "../../host-client/image.ts";
|
|
10
11
|
import { projectFolder, readProjectFile } from "../../host-client/transfer.ts";
|
|
11
12
|
import { WireFailure } from "../../protocol/messages.ts";
|
|
12
13
|
import { AUTOSTART_TYPES, DISK_TYPES, MAX_SNAPSHOTS, RUN_STATES } from "../../protocol/vice.ts";
|
|
@@ -70,10 +71,8 @@ export const c64ProgramLoad = defineTool({
|
|
|
70
71
|
outputSchema: z.object({ state: z.enum(RUN_STATES), loadAddress: AddressOutput, size: z.number().int().min(1).max(0x10000) }),
|
|
71
72
|
readOnly: false,
|
|
72
73
|
async run(input, session) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
throw new WireFailure("invalid-input", `${input.path} is a .${type} image, not a PRG. Use c64_autostart, or c64_disk_attach for a disk image.`);
|
|
76
|
-
}
|
|
74
|
+
// The same rule as every PRG reader of the scripts: .prg or no extension.
|
|
75
|
+
refuseNotPrg(input.path, extname(input.path).slice(1).toLowerCase(), "Use c64_autostart, or c64_disk_attach for a disk image");
|
|
77
76
|
const root = projectFolder(input.project);
|
|
78
77
|
const result = await session.programLoad(input.address === undefined ? { path: input.path, root } : { path: input.path, address: input.address, root });
|
|
79
78
|
return { state: result.state, loadAddress: formatC64Address(result.loadAddress), size: result.size };
|
package/src/media.ts
CHANGED
|
@@ -49,6 +49,9 @@ export function checkMedia(type: string, bytes: Buffer): void {
|
|
|
49
49
|
const header = bytes.length >= 0x40 ? bytes.readUInt32BE(0x10) : 0;
|
|
50
50
|
if (bytes.length < 0x40) refuse("the header is shorter than 64 bytes");
|
|
51
51
|
if (bytes.toString("latin1", header, header + 4) !== "CHIP") refuse("it has no CHIP packet with ROM data after the header");
|
|
52
|
+
const packet = bytes.length >= header + 0x10 ? bytes.readUInt32BE(header + 4) : 0;
|
|
53
|
+
const size = bytes.length >= header + 0x10 ? bytes.readUInt16BE(header + 0x0e) : 0;
|
|
54
|
+
if (packet < 0x10 || header + packet > bytes.length || size > packet - 0x10) refuse(`the CHIP packet at offset ${header} runs past the end of the file`);
|
|
52
55
|
}
|
|
53
56
|
if (!hasSignature(type, bytes)) refuse(`it does not start with ${SIGNATURES[type]!.map((signature) => `"${signature.trimEnd()}"`).join(" or ")}`);
|
|
54
57
|
const sizes = SIZES[type];
|
package/src/native/c64run.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The c64run session: one replay core (a C64 emulator, see
|
|
2
|
-
//
|
|
2
|
+
// tools/c64run.c) for the life of a skill script,
|
|
3
3
|
// driven by one command line and one answer line at a time over its stdin and
|
|
4
4
|
// stdout. It is started through the supervisor like every native tool, so it
|
|
5
5
|
// stops with the script.
|
package/src/native/discover.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { isAbsolute, join, posix, win32 } from "node:path";
|
|
|
8
8
|
import { WireFailure } from "../protocol/messages.ts";
|
|
9
9
|
|
|
10
10
|
/** Where the user finds the install steps of the native tools for each system. */
|
|
11
|
-
export const INSTALL_STEPS = "Steps for each system: https://github.com/henols/c64-re-tools/blob/main/docs/install-tools.md";
|
|
11
|
+
export const INSTALL_STEPS = "Steps for each system: https://github.com/henols/c64-re-tools/blob/main/docs/install-tools.md. In the dev container of c64-re-tools, restart the container: each start installs the tools of the toolkit version.";
|
|
12
12
|
|
|
13
13
|
export interface ToolSpec {
|
|
14
14
|
/** Human name, for messages. */
|
|
@@ -60,7 +60,7 @@ export const C64RUN: ToolSpec = {
|
|
|
60
60
|
envVar: "C64RT_C64RUN",
|
|
61
61
|
binaries: ["c64run"],
|
|
62
62
|
where: "on this machine",
|
|
63
|
-
remedy: `Install c64run (the replay core of c64-testing, with its C64 ROMs) on the machine that runs the skill scripts so that c64run is on PATH, or set C64RT_C64RUN to its full path.
|
|
63
|
+
remedy: `Install c64run (the replay core of c64-testing, with its C64 ROMs) on the machine that runs the skill scripts so that c64run is on PATH, or set C64RT_C64RUN to its full path. ${INSTALL_STEPS}`,
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
export const VICE: ToolSpec = {
|
package/src/project.ts
CHANGED
|
@@ -251,9 +251,13 @@ export function checkOutputPath(path: string, kind: OutputKind, options: { root?
|
|
|
251
251
|
};
|
|
252
252
|
const inKnowledge = (fromRoot: string) => {
|
|
253
253
|
const part = knowledgePart(fromRoot);
|
|
254
|
-
if (part
|
|
255
|
-
|
|
254
|
+
if (part === undefined) return;
|
|
255
|
+
const prefix = `${what === undefined ? "" : `${what}: `}${path}`;
|
|
256
|
+
// The index is one file in the folder for local files: another name in that folder is good.
|
|
257
|
+
if (!part.endsWith("/")) {
|
|
258
|
+
throw new Refusal("invalid-input", `${prefix} is the index of the knowledge${path === part ? "" : ` (${part})`}. Only the c64-knowledge skill writes it: a write there destroys the index. Give another file name, for example ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/<other name>.`);
|
|
256
259
|
}
|
|
260
|
+
throw new Refusal("invalid-input", `${prefix} is in ${part}, the knowledge of the project. Only the c64-knowledge skill writes it: a write there destroys the knowledge. Give a path outside ${part}, for example ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/<${kind === "folder" ? "folder" : "file"}>.`);
|
|
257
261
|
};
|
|
258
262
|
let target: string;
|
|
259
263
|
try {
|
package/src/script.ts
CHANGED
|
@@ -65,6 +65,12 @@ export interface OptionSpec {
|
|
|
65
65
|
* --out and --out-<name> has it.
|
|
66
66
|
*/
|
|
67
67
|
output?: OutputKind;
|
|
68
|
+
/**
|
|
69
|
+
* An option whose value has a form: an example of that form for a value
|
|
70
|
+
* that is missing or starts with -, made from that value when it fits.
|
|
71
|
+
* The message then gives the form, not --<name>=<value>.
|
|
72
|
+
*/
|
|
73
|
+
example?: (given: string | undefined) => string;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
/** 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. */
|
|
@@ -468,8 +474,10 @@ function refuseOptionWords(command: CommandSpec, options: Readonly<Record<string
|
|
|
468
474
|
} else {
|
|
469
475
|
valueIndex = index + 1;
|
|
470
476
|
const next = words[valueIndex];
|
|
471
|
-
|
|
477
|
+
const form = (given: string | undefined) => (spec.example === undefined ? "" : `, for example --${name} ${spec.example(given)}`);
|
|
478
|
+
if (next === undefined) throw new UsageError(`--${name} needs a value: give --${name} ${spec.value ?? "<value>"}${form(undefined)}`);
|
|
472
479
|
if (isOptionWord(next)) {
|
|
480
|
+
if (spec.example !== undefined) throw new UsageError(`--${name} needs a value of the form ${spec.value ?? "<value>"}: give --${name} ${spec.value ?? "<value>"}${form(next)}, not ${next}`);
|
|
473
481
|
if ((spec.kind === "count" || spec.kind === "number") && /^-\d/.test(next)) {
|
|
474
482
|
const range = spec.kind === "count" ? `a whole number from ${spec.min ?? 0} to ${spec.max ?? Number.MAX_SAFE_INTEGER}` : `a number from ${spec.min ?? 0} to ${spec.max ?? 0xffff}`;
|
|
475
483
|
throw new UsageError(`--${name} must be ${range}, not ${JSON.stringify(next)}`);
|