@henols/c64-re-tools 2.3.0-rc.5 → 2.3.0
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-assembler/SKILL.md +149 -78
- package/skills/c64-assembler/scripts/assembler.ts +18 -11
- package/skills/c64-basic/SKILL.md +90 -52
- package/skills/c64-basic/scripts/basic.ts +15 -6
- package/skills/c64-development/SKILL.md +46 -73
- package/skills/c64-disk/SKILL.md +145 -73
- package/skills/c64-disk/scripts/disk.ts +11 -6
- package/skills/c64-docs/SKILL.md +199 -118
- package/skills/c64-docs/references/page-types.md +3 -3
- package/skills/c64-docs/references/style.md +9 -13
- package/skills/c64-docs/scripts/docs.ts +39 -15
- package/skills/c64-docs/scripts/lib/links.ts +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +2 -2
- package/skills/c64-docs/scripts/lib/source-map.ts +2 -2
- package/skills/c64-export/SKILL.md +21 -45
- package/skills/c64-knowledge/SKILL.md +489 -233
- package/skills/c64-knowledge/scripts/knowledge.ts +31 -26
- package/skills/c64-memory-map/SKILL.md +131 -65
- package/skills/c64-memory-map/scripts/memory-map.ts +19 -11
- package/skills/c64-packer/SKILL.md +120 -72
- package/skills/c64-packer/scripts/packer.ts +10 -3
- package/skills/c64-provenance/SKILL.md +301 -173
- package/skills/c64-provenance/scripts/lib/library.ts +6 -6
- package/skills/c64-provenance/scripts/provenance.ts +85 -36
- package/skills/c64-reverse-engineering/SKILL.md +55 -72
- package/skills/c64-source/SKILL.md +316 -224
- package/skills/c64-source/scripts/lib/export.ts +9 -14
- package/skills/c64-source/scripts/lib/loader.ts +5 -5
- package/skills/c64-source/scripts/lib/source.ts +5 -5
- package/skills/c64-source/scripts/source.ts +106 -21
- package/skills/c64-static-analysis/SKILL.md +188 -112
- package/skills/c64-static-analysis/scripts/static-analysis.ts +29 -9
- package/skills/c64-testing/SKILL.md +272 -166
- package/skills/c64-testing/references/recording-format.md +11 -12
- package/skills/c64-testing/references/scenario-format.md +20 -5
- package/skills/c64-testing/scripts/lib/diff-files.ts +8 -8
- package/skills/c64-testing/scripts/lib/recording.ts +7 -7
- package/skills/c64-testing/scripts/lib/replay.ts +7 -7
- package/skills/c64-testing/scripts/lib/runs.ts +6 -7
- package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
- package/skills/c64-testing/scripts/testing.ts +35 -15
- package/skills/c64-unpacker/SKILL.md +273 -127
- package/skills/c64-unpacker/scripts/lib/loads.ts +3 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +70 -11
- package/skills/emulator/SKILL.md +12 -12
- package/src/errors.ts +22 -2
- package/src/host/vice/session.ts +1 -1
- package/src/host-client/entry-state.ts +1 -1
- package/src/host-client/image.ts +3 -3
- package/src/host-client/steps.ts +1 -1
- package/src/knowledge/expression.ts +1 -1
- package/src/knowledge/names.ts +2 -3
- package/src/knowledge/program.ts +2 -3
- package/src/knowledge/write.ts +2 -2
- package/src/mcp/inputs.ts +1 -1
- package/src/mcp/tools/input.ts +1 -1
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/exomizer.ts +2 -2
- package/src/project.ts +2 -2
- package/src/script.ts +164 -75
|
@@ -93,11 +93,11 @@ import {
|
|
|
93
93
|
} from "#src/knowledge/write.ts";
|
|
94
94
|
import { platformNames } from "#src/platform.ts";
|
|
95
95
|
import { isInside, LOCAL_DIRECTORY, PROJECT_DIRECTORY, projectRelative, projectRoot, resolveProjectPath } from "#src/project.ts";
|
|
96
|
-
import { listed, OPTIONS, runScript, UsageError, type Call, type CommandSpec, type OptionSpec, type SubjectSpec } from "#src/script.ts";
|
|
96
|
+
import { listed, OPTIONS, reply, runScript, UsageError, type Call, type CommandSpec, type OptionSpec, type SubjectSpec } from "#src/script.ts";
|
|
97
97
|
import { listing, listingText, type ListingSource } from "./lib/listing.ts";
|
|
98
98
|
|
|
99
99
|
function oneOf<T extends string>(values: readonly T[], value: string | undefined, what: string): T {
|
|
100
|
-
if (value === undefined || !(values as readonly string[]).includes(value)) throw new UsageError(`${what} must be one of: ${values.join(", ")}
|
|
100
|
+
if (value === undefined || !(values as readonly string[]).includes(value)) throw new UsageError(`${what} must be one of: ${values.join(", ")}.`);
|
|
101
101
|
return value as T;
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -283,7 +283,7 @@ function originFilter(value: string): Origin[] {
|
|
|
283
283
|
if (part === "semantic") for (const origin of SEMANTIC_ORIGINS) origins.add(origin);
|
|
284
284
|
else if (part === "analyzer") for (const origin of ANALYZERS) origins.add(origin);
|
|
285
285
|
else if ((ORIGINS as readonly string[]).includes(part)) origins.add(part as Origin);
|
|
286
|
-
else throw new UsageError(`--origin cannot be ${JSON.stringify(part)}. Give ${ORIGIN_VALUES}
|
|
286
|
+
else throw new UsageError(`--origin cannot be ${JSON.stringify(part)}. Give ${ORIGIN_VALUES}.`);
|
|
287
287
|
}
|
|
288
288
|
return [...origins];
|
|
289
289
|
}
|
|
@@ -293,7 +293,7 @@ function knowledgePath(path: string, what: string): string {
|
|
|
293
293
|
try {
|
|
294
294
|
return projectRelative(path);
|
|
295
295
|
} catch {
|
|
296
|
-
throw new UsageError(`${what} must be a path relative to the project folder that stays inside it, not ${path}
|
|
296
|
+
throw new UsageError(`${what} must be a path relative to the project folder that stays inside it, not ${path}.`);
|
|
297
297
|
}
|
|
298
298
|
}
|
|
299
299
|
|
|
@@ -314,7 +314,7 @@ function evidenceOf(value: string, space: string): Evidence {
|
|
|
314
314
|
try {
|
|
315
315
|
const run = coverageRuns(db).filter((item) => item.name === ref && item.space === space).at(-1);
|
|
316
316
|
const where = space === DEFAULT_SPACE ? "" : ` in ${space}`;
|
|
317
|
-
if (run === undefined) throw new UsageError(`--evidence coverage:${given} names no coverage map of the knowledge${where}
|
|
317
|
+
if (run === undefined) throw new UsageError(`--evidence coverage:${given} names no coverage map of the knowledge${where}. Import the map with coverage${space === DEFAULT_SPACE ? "" : ` --space ${space}`} first.`);
|
|
318
318
|
return { kind, ref, sha256: run.sha256, ...(run.space === DEFAULT_SPACE ? {} : { space: run.space }) };
|
|
319
319
|
} finally {
|
|
320
320
|
db?.close();
|
|
@@ -323,12 +323,12 @@ function evidenceOf(value: string, space: string): Evidence {
|
|
|
323
323
|
const bytes = readProjectFile(ref).bytes;
|
|
324
324
|
const root = projectRoot();
|
|
325
325
|
if (isInside(join(root, PROJECT_DIRECTORY, LOCAL_DIRECTORY), resolveProjectPath(ref, root))) {
|
|
326
|
-
throw new UsageError(`--evidence ${kind}:${ref} is in ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/, which git ignores
|
|
326
|
+
throw new UsageError(`--evidence ${kind}:${ref} is in ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/, which git ignores. Move it to a folder that git keeps, for example a run folder to runs/<name>/. Then give the new path.`);
|
|
327
327
|
}
|
|
328
328
|
return { kind, ref, sha256: createHash("sha256").update(bytes).digest("hex") };
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
-
/** An image.json of
|
|
331
|
+
/** An image.json of a capture or a PRG as a write of the program, with the entry state of the capture. */
|
|
332
332
|
function imageRequest(path: string, space: string): ImageRequest {
|
|
333
333
|
const image = readImage(path);
|
|
334
334
|
const request: ImageRequest = { space, segments: image.segments, byteAt: image.byteAt };
|
|
@@ -428,7 +428,7 @@ const WRITE: Record<string, OptionSpec> = {
|
|
|
428
428
|
/** A list command: --max-listed limits each list of its result. */
|
|
429
429
|
const LIST = { "max-listed": OPTIONS["max-listed"] };
|
|
430
430
|
/** Where to get the rest of a list that a --range limits. */
|
|
431
|
-
const RANGE_REST = "a larger --max-listed, a smaller --range, or
|
|
431
|
+
const RANGE_REST = "a larger --max-listed, a smaller --range, or export --out <file> for all current knowledge";
|
|
432
432
|
const MORE = "a larger --max-listed";
|
|
433
433
|
|
|
434
434
|
/** A list in a result: its count and its first --max-listed items, with rest when it is cut. */
|
|
@@ -456,7 +456,11 @@ function readCommand(spec: Omit<CommandSpec, "run">, answer: (db: DatabaseSync |
|
|
|
456
456
|
try {
|
|
457
457
|
const result = answer(db, call);
|
|
458
458
|
const found = conflicts(db);
|
|
459
|
-
|
|
459
|
+
if (found.length === 0) return result;
|
|
460
|
+
return reply(
|
|
461
|
+
{ ...result, conflicts: found.map(showConflict) },
|
|
462
|
+
{ hint: "A git merge left conflicts in the knowledge: see conflicts. Each write stops until you decide them. Run merge, then tell the user each item of its choices.", nextAction: call.next("merge", "--reason", "decide the conflicts of a git merge") },
|
|
463
|
+
);
|
|
460
464
|
} finally {
|
|
461
465
|
db?.close();
|
|
462
466
|
}
|
|
@@ -496,7 +500,7 @@ function shown<T, U>(result: { revision: string | null; current: T; previous?: T
|
|
|
496
500
|
function textOrFile(call: Call, option: string): string | undefined {
|
|
497
501
|
const inline = call.string(option);
|
|
498
502
|
const file = call.string(`${option}-file`);
|
|
499
|
-
if (inline !== undefined && file !== undefined) throw new UsageError(`
|
|
503
|
+
if (inline !== undefined && file !== undefined) throw new UsageError(`Give --${option} or --${option}-file, not both.`);
|
|
500
504
|
if (file !== undefined) return readProjectFile(file).bytes.toString("utf8");
|
|
501
505
|
return inline;
|
|
502
506
|
}
|
|
@@ -610,7 +614,7 @@ const READ_COMMANDS: CommandSpec[] = [
|
|
|
610
614
|
const name = call.string("name");
|
|
611
615
|
const macroName = call.string("macro");
|
|
612
616
|
const switchName = call.string("switch");
|
|
613
|
-
if ([call.subjects.length > 0, name !== undefined, macroName !== undefined, switchName !== undefined].filter(Boolean).length !== 1) throw new UsageError("history needs exactly one of <address>, --name, --macro and --switch");
|
|
617
|
+
if ([call.subjects.length > 0, name !== undefined, macroName !== undefined, switchName !== undefined].filter(Boolean).length !== 1) throw new UsageError("history needs exactly one of <address>, --name, --macro and --switch.");
|
|
614
618
|
const entries =
|
|
615
619
|
switchName !== undefined
|
|
616
620
|
? historyOfSwitch(db, switchName, call.space)
|
|
@@ -772,12 +776,12 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
772
776
|
(call) => {
|
|
773
777
|
const context = contextOf(call);
|
|
774
778
|
const given = (["lo", "hi", "value", "expr"] as const).filter((option) => call.string(option) !== undefined);
|
|
775
|
-
if (given.length !== 1) throw new UsageError("operand needs exactly one of --lo, --hi, --value or --expr");
|
|
779
|
+
if (given.length !== 1) throw new UsageError("operand needs exactly one of --lo, --hi, --value or --expr.");
|
|
776
780
|
const select: OperandSelect = given[0]!;
|
|
777
781
|
const offset = call.string("offset");
|
|
778
782
|
const request: { space: string; address: number; select: OperandSelect; symbol?: string; offset?: number; expression?: string } = { space: call.space, address: call.parseAddress(call.subject(0), "<address>"), select };
|
|
779
783
|
if (select === "expr") {
|
|
780
|
-
if (offset !== undefined) throw new UsageError("--offset works with --lo, --hi and --value, not with --expr");
|
|
784
|
+
if (offset !== undefined) throw new UsageError("--offset works with --lo, --hi and --value, not with --expr.");
|
|
781
785
|
request.expression = call.string("expr")!;
|
|
782
786
|
} else {
|
|
783
787
|
request.symbol = call.string(select)!;
|
|
@@ -807,7 +811,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
807
811
|
(call) => {
|
|
808
812
|
const context = contextOf(call);
|
|
809
813
|
const code = textOrFile(call, "code");
|
|
810
|
-
if ((code === undefined) === !call.flag("nop")) throw new UsageError("patch needs exactly one of --code, --code-file or --nop");
|
|
814
|
+
if ((code === undefined) === !call.flag("nop")) throw new UsageError("patch needs exactly one of --code, --code-file or --nop.");
|
|
811
815
|
const commentText = call.string("comment");
|
|
812
816
|
const request = { space: call.space, ...call.parseRange(call.subject(0), "<range>"), switch: call.subject(1), code: code ?? "", ...(commentText === undefined ? {} : { comment: commentText }) };
|
|
813
817
|
return (db) => shown(setPatch(db, { ...context, image: operandImage(db, call.space) }, request), "patch", patch);
|
|
@@ -868,21 +872,21 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
868
872
|
writeCommand(
|
|
869
873
|
{
|
|
870
874
|
name: "release",
|
|
871
|
-
summary: "Records a release of the program: its PRG or
|
|
875
|
+
summary: "Records a release of the program: its PRG or the image.json of its capture in the project. The base release is the one whose bytes are the program of the knowledge.",
|
|
872
876
|
subjects: [{ name: "<label>", help: "the release label, for example ORIGINAL or FIRESTAR" }],
|
|
873
877
|
options: {
|
|
874
878
|
file: { kind: "path", value: "<file>", help: "the PRG or image.json of the release, in a folder that git keeps", required: true },
|
|
875
879
|
base: { kind: "flag", help: "this release is the program of the knowledge: its segments and bytes must be the same" },
|
|
876
880
|
comment: { kind: "text", value: "<text>", help: "what the release is, for example the group and the date" },
|
|
877
881
|
},
|
|
878
|
-
notes: "The build of a release defines RELEASE_<label>=1: each switch then has the value of that release.
|
|
882
|
+
notes: "The build of a release defines RELEASE_<label>=1: each switch then has the value of that release. The check of the generated source builds each release and compares it with the bytes of its file.",
|
|
879
883
|
},
|
|
880
884
|
(call) => {
|
|
881
885
|
const context = contextOf(call);
|
|
882
886
|
const file = knowledgePath(call.string("file")!, "--file");
|
|
883
887
|
const root = projectRoot();
|
|
884
888
|
if (isInside(join(root, PROJECT_DIRECTORY, LOCAL_DIRECTORY), resolveProjectPath(file, root))) {
|
|
885
|
-
throw new UsageError(`--file ${file} is in ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/, which git ignores
|
|
889
|
+
throw new UsageError(`--file ${file} is in ${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/, which git ignores. Move the release to a folder that git keeps, for example original/.`);
|
|
886
890
|
}
|
|
887
891
|
const image = readImage(file);
|
|
888
892
|
const sha256 = createHash("sha256").update(readProjectFile(file).bytes).digest("hex");
|
|
@@ -896,7 +900,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
896
900
|
for (let address = segment.start; address <= segment.end; address++) if (program.byteAt(address) !== image.byteAt(address)) return false;
|
|
897
901
|
return true;
|
|
898
902
|
});
|
|
899
|
-
if (!same) throw new Refusal("invalid-input", `The bytes of ${file} are not the program of the knowledge.
|
|
903
|
+
if (!same) throw new Refusal("invalid-input", `The bytes of ${file} are not the program of the knowledge. Give --base only to the release whose file image put into the knowledge.`);
|
|
900
904
|
}
|
|
901
905
|
return shown(setRelease(db, context, request), "release", release);
|
|
902
906
|
};
|
|
@@ -923,7 +927,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
923
927
|
(call) => {
|
|
924
928
|
const context = contextOf(call);
|
|
925
929
|
const body = textOrFile(call, "body");
|
|
926
|
-
if (body === undefined || body === "") throw new UsageError("macro needs --body or --body-file with text");
|
|
930
|
+
if (body === undefined || body === "") throw new UsageError("macro needs --body or --body-file with text.");
|
|
927
931
|
const commentText = call.string("comment");
|
|
928
932
|
const request = { space: call.space, name: call.subject(0), params: commaList(call.string("params") ?? ""), body, ...(commentText === undefined ? {} : { comment: commentText }) };
|
|
929
933
|
return (db) => shown(setMacro(db, context, request), "macro", macro);
|
|
@@ -958,8 +962,8 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
958
962
|
writeCommand(
|
|
959
963
|
{
|
|
960
964
|
name: "image",
|
|
961
|
-
summary: "Puts the program into the knowledge: its bytes, and for
|
|
962
|
-
subjects: [{ name: "<file>", help: "
|
|
965
|
+
summary: "Puts the program into the knowledge: its bytes, and for the image.json of a capture also the entry, the entry state and the stages. Only changed bytes write.",
|
|
966
|
+
subjects: [{ name: "<file>", help: "the image.json of a capture or of loads, or a PRG" }],
|
|
963
967
|
},
|
|
964
968
|
(call) => {
|
|
965
969
|
const context = contextOf(call);
|
|
@@ -973,7 +977,7 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
973
977
|
writeCommand(
|
|
974
978
|
{
|
|
975
979
|
name: "coverage",
|
|
976
|
-
summary: "Joins coverage maps of
|
|
980
|
+
summary: "Joins coverage maps of the emulator or of a run into the coverage of the knowledge. Each map is named by its path: --evidence coverage:<path> cites it.",
|
|
977
981
|
subjects: [{ name: "<map>", help: "a 64 KiB coverage map", list: true }],
|
|
978
982
|
},
|
|
979
983
|
(call) => {
|
|
@@ -1025,9 +1029,9 @@ const WRITE_COMMANDS: CommandSpec[] = [
|
|
|
1025
1029
|
try {
|
|
1026
1030
|
parsed = JSON.parse(text);
|
|
1027
1031
|
} catch (error) {
|
|
1028
|
-
throw new Refusal("invalid-input", `
|
|
1032
|
+
throw new Refusal("invalid-input", `The batch ${path} is not JSON: ${(error as Error).message}`);
|
|
1029
1033
|
}
|
|
1030
|
-
if (!Array.isArray(parsed)) throw new Refusal("invalid-input", `
|
|
1034
|
+
if (!Array.isArray(parsed)) throw new Refusal("invalid-input", `The batch ${path} is not a JSON list of writes. Give a list such as [{"op": "rename", "address": "$2100", "name": "update_player"}].`);
|
|
1031
1035
|
const operations = parsed.map((item, index) => batchOperation(call, item, `write ${index + 1}`));
|
|
1032
1036
|
const checked = operations.some((operation) => operation.op === "operand" || operation.op === "patch" || operation.op === "use");
|
|
1033
1037
|
return (db) => {
|
|
@@ -1048,7 +1052,7 @@ const JOIN: CommandSpec = {
|
|
|
1048
1052
|
options: { ...SPACE, out: { ...OPTIONS.out, output: "file", value: "<file>", help: "the joined batch, relative to the project folder", required: true } },
|
|
1049
1053
|
notes: "At an address in the owner range of a batch, its name, comment, operand and module win, and its regions come last. One name or one module file at two addresses writes nothing.",
|
|
1050
1054
|
run: (call) => {
|
|
1051
|
-
if (call.subjects.length < 2) throw new UsageError("join needs two or more batch files");
|
|
1055
|
+
if (call.subjects.length < 2) throw new UsageError("join needs two or more batch files.");
|
|
1052
1056
|
const batches: Batch[] = call.subjects.map((file) => {
|
|
1053
1057
|
let value: unknown;
|
|
1054
1058
|
try {
|
|
@@ -1083,7 +1087,8 @@ const JOIN: CommandSpec = {
|
|
|
1083
1087
|
throw new Refusal("conflict", `The batches give one ${joined.clashes.map(clash).join(", one ")}. Nothing was written. Give each name and each module file one address in the batches, then join again.`);
|
|
1084
1088
|
}
|
|
1085
1089
|
const out = call.string("out")!;
|
|
1086
|
-
|
|
1090
|
+
const body = { writes: joined.ops.length, repeated: joined.repeated, choices: joined.choices.map(choice), ...writeReported(out, `${JSON.stringify(joined.ops.map(batchJson), null, 1)}\n`, { what: "--out" }) };
|
|
1091
|
+
return reply(body, { hint: "Examine each item of choices. Then apply the joined batch.", nextAction: call.next("apply", out) });
|
|
1087
1092
|
},
|
|
1088
1093
|
};
|
|
1089
1094
|
|
|
@@ -1,97 +1,163 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: c64-memory-map
|
|
3
|
-
description:
|
|
3
|
+
description: Gives the C64 platform meaning of an address. Examples are a VIC-II, SID or CIA register, a KERNAL routine, a vector or a system variable. It also decodes the value of a hardware register, for example the memory configuration in $01 or the screen address in $D018. It tells when an address has no platform meaning and belongs to the application. Use it when code reads or writes an address that you do not know. Use it to get the platform names as an include file for ACME. It does not read the memory of a running program, and it does not change the project knowledge.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# C64 memory map
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Use this script to get the C64 platform meaning of an address or of a register value.
|
|
9
|
+
Use only the commands of the script. Do not look up C64 platform addresses in another way.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
```bash
|
|
12
|
+
node <skill>/scripts/memory-map.ts <command>
|
|
13
|
+
```
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
`<skill>` is the base directory of this skill. Run the script with `node`. You can run it from any directory.
|
|
16
|
+
Each command in this skill, for example `at '$d020'`, goes in the place of `<command>`.
|
|
17
|
+
Each command prints one JSON envelope on stdout. See the section "JSON output".
|
|
18
|
+
To get the command list, run the script with no arguments.
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
---
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
- Or a register and a value to decode.
|
|
22
|
+
## Select the command
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
| Goal | Command |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Find what one or more addresses mean | `at '$d020' '$0314' '$ffd2'` |
|
|
27
|
+
| Find the address of a platform name | `at SCROLY CHROUT` |
|
|
28
|
+
| Decode the memory configuration | `decode '$01' '$35'` |
|
|
29
|
+
| Decode the screen and character addresses of the VIC-II | `decode '$d018' '$15' --bank '$97'` |
|
|
30
|
+
| Read all registers of a chip | `list vic` |
|
|
31
|
+
| Read the KERNAL jump table | `list kernal` |
|
|
32
|
+
| Write the platform names as an ACME include file | `export --out src/hw.asm` |
|
|
33
|
+
|
|
34
|
+
## Addresses, registers and values
|
|
35
|
+
|
|
36
|
+
- `<address>` is an address from the code or from the question. It can also be a platform name, for example `SCROLY` or `CHROUT`, in upper or lower case. The commands `list` and `export` show the platform names. A platform name comes before a name of the project knowledge.
|
|
37
|
+
- `<register>` is the address or the platform name of a register that has a decoder. The decoders are for `$01`, `$D010`, `$D011`, `$D015` to `$D01F`, `$D016`, `$D018`, `$DC0D`, `$DD00` and `$DD0D`.
|
|
38
|
+
- `<value>` is the value of the register, from 0 to 255. Write it as `$` and hex digits, as a decimal number, or as `%` and binary digits. Put a `$` value in single quotes in a shell.
|
|
39
|
+
- `<list>` is one of `vic`, `sid`, `cia1`, `cia2`, `kernal` and `system`.
|
|
40
|
+
|
|
41
|
+
### Paths and the project folder
|
|
42
|
+
|
|
43
|
+
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
44
|
+
- If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
|
|
45
|
+
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
|
|
46
|
+
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
47
|
+
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
48
|
+
- Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
|
|
49
|
+
- The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
|
|
50
|
+
- The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
|
|
51
|
+
- When a file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses evidence in that folder.
|
|
52
|
+
- Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
|
|
53
|
+
- Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
|
|
54
|
+
- A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
|
|
20
55
|
|
|
21
|
-
|
|
22
|
-
node <skill>/scripts/memory-map.ts at '$d020' '$0314' '$ffd2'
|
|
23
|
-
node <skill>/scripts/memory-map.ts decode '$d018' '$15' --bank '$97'
|
|
24
|
-
node <skill>/scripts/memory-map.ts list vic
|
|
25
|
-
node <skill>/scripts/memory-map.ts export --out src/hw.asm
|
|
26
|
-
```
|
|
56
|
+
## Flags
|
|
27
57
|
|
|
28
|
-
|
|
29
|
-
|---|---|
|
|
30
|
-
| `at <address> ...` | For each address: `kind` (`platform` or `application`), the area, the name and the meaning. |
|
|
31
|
-
| `decode <register> <value>` | The meaning of the value. Use `--bank` with the value of `$DD00` to get the addresses for `$D018`. The other registers refuse `--bank`. The decoders are for `$01`, `$D010`, `$D011`, `$D015` to `$D01F`, `$D016`, `$D018`, `$DC0D`, `$DD00` and `$DD0D`. |
|
|
32
|
-
| `list <vic\|sid\|cia1\|cia2\|kernal\|system>` | The entries of that group as a list: `count` and `listed`. `--max-listed` limits `listed`. The default is 50. |
|
|
33
|
-
| `export --out <file>` | Writes all platform names to a project file as an ACME include: one line for each name, with its meaning as a comment. A zero-page name is `NAME = $xx`. Other names are `NAME = $xxxx`. |
|
|
58
|
+
Each flag applies only to the commands in the table. On another command, the script refuses the flag.
|
|
34
59
|
|
|
35
|
-
|
|
60
|
+
| Flag | Command | Effect |
|
|
61
|
+
|---|---|---|
|
|
62
|
+
| `--bank <value>` | `decode` | The value of `$DD00`. With it, a `$D018` value gives addresses, not only offsets in the VIC-II bank. Only for `$D018`. No default. |
|
|
63
|
+
| `--max-listed <n>` | `list` | The maximum number of entries in `listed`. The default is 50. |
|
|
64
|
+
| `--out <file>` | `export` | The include file to write, relative to the project folder. Required. |
|
|
36
65
|
|
|
37
|
-
|
|
66
|
+
---
|
|
38
67
|
|
|
39
|
-
|
|
68
|
+
## Look up an address
|
|
40
69
|
|
|
41
|
-
|
|
42
|
-
- `<script>.ts --help` lists the commands. `<script>.ts <command> --help` gives the subjects and the options of one command. The help is JSON: `{"text": "..."}`.
|
|
43
|
-
- An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Quote an address in a shell.
|
|
44
|
-
- A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
|
|
45
|
-
- Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
|
|
46
|
-
- The script examines each `--out` path before it starts work. It refuses a path in `.c64-re-tools/knowledge/` and the index of the knowledge, because only c64-knowledge writes them. It refuses a folder where the command writes a file, and a file where the command writes a folder.
|
|
47
|
-
- The result is one JSON object on one line. A file that the script writes shows as `{"out", "bytes", "sha256"}`. A list shows as `{"count", "listed"}`, and `rest` tells where to get the rest of a long list.
|
|
48
|
-
- An error is `{"error": {"code": "...", "message": "..."}}`. The message tells what is wrong and what to do.
|
|
49
|
-
- The exit status is 0 for done or PASS, 1 for FAIL, 2 for an error and 3 for INCONCLUSIVE.
|
|
70
|
+
### `at <address>...`
|
|
50
71
|
|
|
51
|
-
|
|
72
|
+
`body.addresses` holds one item for each address:
|
|
52
73
|
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
74
|
+
- `kind`: `platform` or `application`.
|
|
75
|
+
- `platform`: the C64 gives the address a meaning. Read `name` and `meaning`.
|
|
76
|
+
- `application`: the address has no platform meaning. The program decides its use. This is not a failure.
|
|
77
|
+
- `area`: the memory area of the address, for example `VIC-II registers`, `color RAM` or `free RAM`.
|
|
78
|
+
- `mirrorOf`: for an I/O register, the register that this mirror address repeats.
|
|
79
|
+
- `entryStart`: the first address of the entry, for a byte in an entry of more than one byte. An example is the high byte of a vector.
|
|
80
|
+
- `visible`: for an address from `$D000` to `$DFFF`. The address is visible only when `$01` shows I/O at `$D000`. This area holds the chip registers, the color RAM and the cartridge I/O areas.
|
|
81
|
+
|
|
82
|
+
When an address has the kind `application`, `hint` names it. Find its use in the disassembly or in the emulator.
|
|
83
|
+
|
|
84
|
+
Do not record platform facts in the project knowledge. A conclusion about the application can go into the project knowledge. An example is "the program writes the address of its IRQ handler to `$0314`".
|
|
85
|
+
|
|
86
|
+
Failure:
|
|
87
|
+
|
|
88
|
+
- `invalid-input` with "is not a C64 platform name": the name is not a platform name and not a name in the project knowledge. Give a `$` address, a platform name, or a symbol of the project knowledge.
|
|
89
|
+
- `invalid-input` with "must be $ and 1 to 4 hex digits": the address is not correct. A decimal number is not an address.
|
|
60
90
|
|
|
61
|
-
|
|
91
|
+
### `decode <register> <value>`
|
|
62
92
|
|
|
63
|
-
|
|
64
|
-
2. Read `kind`:
|
|
65
|
-
- `platform`: the C64 gives the address a meaning. Read `name` and `meaning`.
|
|
66
|
-
- `application`: the address has no platform meaning. The program decides its use. Find its use with the c64-static-analysis or emulator skill.
|
|
67
|
-
3. For an I/O register, `mirrorOf` shows the register that a mirror address repeats. `visible` tells that an address in `$D000`-`$DFFF` is visible only when `$01` shows I/O at `$D000`. This area holds the chip registers, the color RAM and the cartridge I/O areas.
|
|
68
|
-
4. For a byte in a multi-byte entry, for example the high byte of a vector, `entryStart` gives the first address of the entry.
|
|
69
|
-
5. To understand a value in a register, run `decode`. For the memory configuration, decode the value of `$01`.
|
|
70
|
-
6. For source that you write by hand, run `export` and include the file with `!source`. The c64-source skill uses the same names without the file.
|
|
93
|
+
`body` holds `register`, `value`, `name`, and the meaning of each bit field of the value. Examples:
|
|
71
94
|
|
|
72
|
-
|
|
95
|
+
- `$01`: what the CPU sees at `$A000`, `$D000` and `$E000`.
|
|
96
|
+
- `$D018`: the offsets of the screen, the characters and the bitmap in the VIC-II bank. With `--bank`, also `bank` and the addresses `screen`, `characters` and `bitmap`.
|
|
97
|
+
- `$DD00`: the VIC-II bank and its addresses.
|
|
73
98
|
|
|
74
|
-
|
|
99
|
+
Some registers have a different meaning for a read and for a write, for example `$DC0D`. Then the body gives both.
|
|
75
100
|
|
|
76
|
-
|
|
77
|
-
- none.
|
|
101
|
+
For `$D018` without `--bank`, `hint` tells you to give `--bank` with the value of `$DD00`. Get that value from the code or from the emulator.
|
|
78
102
|
|
|
79
|
-
|
|
103
|
+
Failure:
|
|
80
104
|
|
|
81
|
-
|
|
105
|
+
- `invalid-input` with "There is no decoder": the register has no decoder. Use `at` for its meaning.
|
|
106
|
+
- `invalid-input` with "--bank works only with $d018": remove `--bank`.
|
|
82
107
|
|
|
83
|
-
|
|
108
|
+
### `list <list>`
|
|
84
109
|
|
|
85
|
-
|
|
110
|
+
`body.entries` is a list of the entries of the group: `count`, `listed` and `rest`. Each item has `start`, `end` for an entry of more than one byte, `name` and `meaning`.
|
|
86
111
|
|
|
87
|
-
|
|
112
|
+
When the list is cut, `hint` gives the full count, and `nextAction` runs `list` again with a `--max-listed` that holds all entries.
|
|
88
113
|
|
|
89
|
-
|
|
90
|
-
- `invalid-input`: the address, the register or the value is not correct, or no decoder exists for the register. Read the message.
|
|
114
|
+
### `export`
|
|
91
115
|
|
|
92
|
-
|
|
116
|
+
Writes all platform names to the project file at `--out`, as an ACME include file. Each line gives one name and its meaning as a comment. A zero-page name is `NAME = $xx`. Another name is `NAME = $xxxx`.
|
|
117
|
+
|
|
118
|
+
`body` holds `names` (the number of names) and the file as `out`, `bytes` and `sha256`.
|
|
119
|
+
|
|
120
|
+
Include the file with `!source` in source that you write by hand.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## JSON output
|
|
125
|
+
|
|
126
|
+
Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
|
|
127
|
+
|
|
128
|
+
On success, the exit code is 0:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
On failure, the exit code is 2:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
- `body` holds the result. The section of each command gives the fields of its body.
|
|
141
|
+
- A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
|
|
142
|
+
- `error` is one sentence. It tells what is wrong.
|
|
143
|
+
- `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
|
|
144
|
+
- `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
|
|
145
|
+
- `code` does not change between versions. Do the action for the code:
|
|
146
|
+
|
|
147
|
+
| `code` | Action |
|
|
148
|
+
|---|---|
|
|
149
|
+
| `installation-incomplete`, `machine-unavailable` | Stop the task. Give `error` and `hint` to the user and wait for the user. Do not install, start or change a tool. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script. |
|
|
150
|
+
| `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
|
|
151
|
+
| `operation-failed` | Give `error` and `hint` to the user. |
|
|
152
|
+
| Another code | Do as `hint` tells. |
|
|
153
|
+
|
|
154
|
+
These fields have the same meaning in each body:
|
|
155
|
+
|
|
156
|
+
| Field | Meaning |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
|
|
159
|
+
| `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
|
|
93
160
|
|
|
94
|
-
|
|
161
|
+
To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
|
|
162
|
+
To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
|
|
95
163
|
|
|
96
|
-
- The value of an address at run time → emulator
|
|
97
|
-
- A conclusion about the application → c64-knowledge
|
|
@@ -7,7 +7,7 @@ import { isRefusal, Refusal } from "#src/errors.ts";
|
|
|
7
7
|
import { writeReported } from "#src/host-client/transfer.ts";
|
|
8
8
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
9
9
|
import { decode, IO, lookup, platformNames, ROM, SYSTEM, type Entry } from "#src/platform.ts";
|
|
10
|
-
import { listed, OPTIONS, runScript, UsageError } from "#src/script.ts";
|
|
10
|
+
import { listed, OPTIONS, reply, runScript, UsageError } from "#src/script.ts";
|
|
11
11
|
|
|
12
12
|
const show = (entry: Entry) => ({ start: formatC64Address(entry.start), ...(entry.end !== entry.start ? { end: formatC64Address(entry.end) } : {}), name: entry.name, meaning: entry.meaning });
|
|
13
13
|
|
|
@@ -25,7 +25,7 @@ function names(name: string, space: string): number {
|
|
|
25
25
|
return knowledgeNames(name, space);
|
|
26
26
|
} catch (error) {
|
|
27
27
|
if (!isRefusal(error) || error.code !== "not-found") throw error;
|
|
28
|
-
throw new Refusal("not-found", `${name} is not a C64 platform name and not a name in the knowledge. Give a $ address, a platform name that
|
|
28
|
+
throw new Refusal("not-found", `${name} is not a C64 platform name and not a name in the knowledge. Give a $ address, a platform name that the command list or export shows (for example SCROLY or CHROUT), or a symbol of the project knowledge.`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -47,8 +47,8 @@ await runScript({
|
|
|
47
47
|
name: "at",
|
|
48
48
|
summary: "The platform meaning of each address: its name, area and meaning.",
|
|
49
49
|
subjects: [{ name: "<address>", help: "an address, a platform name such as SCROLY, or a name of the knowledge", list: true }],
|
|
50
|
-
run: (call) =>
|
|
51
|
-
addresses
|
|
50
|
+
run: (call) => {
|
|
51
|
+
const addresses = call.subjects.map((text) => {
|
|
52
52
|
const found = lookup(call.parseAddress(text, "<address>"));
|
|
53
53
|
// The chip registers, color RAM and the cartridge I/O areas show only while $01 maps I/O in.
|
|
54
54
|
const io = found.address >= 0xd000 && found.address <= 0xdfff;
|
|
@@ -59,8 +59,11 @@ await runScript({
|
|
|
59
59
|
...(found.entryStart === undefined ? {} : { entryStart: formatC64Address(found.entryStart) }),
|
|
60
60
|
...(io ? { visible: "when $01 shows I/O at $D000 (the default)" } : {}),
|
|
61
61
|
};
|
|
62
|
-
})
|
|
63
|
-
|
|
62
|
+
});
|
|
63
|
+
const application = addresses.filter((address) => address.kind === "application").map((address) => address.address);
|
|
64
|
+
if (application.length === 0) return { addresses };
|
|
65
|
+
return reply({ addresses }, { hint: `The program decides the use of ${application.join(", ")}. Find its use in the disassembly or in the emulator.` });
|
|
66
|
+
},
|
|
64
67
|
},
|
|
65
68
|
{
|
|
66
69
|
name: "decode",
|
|
@@ -74,8 +77,10 @@ await runScript({
|
|
|
74
77
|
const register = call.parseAddress(call.subject(0), "<register>");
|
|
75
78
|
const value = call.parseNumber(call.subject(1), "<value>", 0, 0xff);
|
|
76
79
|
const bank = call.count("bank");
|
|
77
|
-
if (bank !== undefined && register !== 0xd018) throw new UsageError(`--bank works only with $d018 (VMCSB), not with ${formatC64Address(register)}. Remove --bank
|
|
78
|
-
|
|
80
|
+
if (bank !== undefined && register !== 0xd018) throw new UsageError(`--bank works only with $d018 (VMCSB), not with ${formatC64Address(register)}. Remove --bank.`);
|
|
81
|
+
const body = { register: formatC64Address(register), value: formatC64Byte(value), name: lookup(register).name, ...decode(register, value, bank) };
|
|
82
|
+
if (register === 0xd018 && bank === undefined) return reply(body, { hint: "The addresses are offsets in the VIC-II bank. To get the addresses, give --bank with the value of $dd00." });
|
|
83
|
+
return body;
|
|
79
84
|
},
|
|
80
85
|
},
|
|
81
86
|
{
|
|
@@ -84,9 +89,12 @@ await runScript({
|
|
|
84
89
|
subjects: [{ name: "<list>", help: `one of ${Object.keys(LISTS).join(", ")}` }],
|
|
85
90
|
options: { "max-listed": OPTIONS["max-listed"] },
|
|
86
91
|
run: (call) => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
const name = call.subject(0);
|
|
93
|
+
const list = LISTS[name];
|
|
94
|
+
if (list === undefined) throw new UsageError(`<list> must be one of ${Object.keys(LISTS).join(", ")}, not ${name}.`);
|
|
95
|
+
const entries = listed(list(), call.count("max-listed")!, show, "a larger --max-listed, or the command export for every platform name");
|
|
96
|
+
if (entries.rest === undefined) return { entries };
|
|
97
|
+
return reply({ entries }, { hint: `The list is cut. To get all ${entries.count} entries, give --max-listed ${entries.count}.`, nextAction: call.next("list", name, "--max-listed", String(entries.count)) });
|
|
90
98
|
},
|
|
91
99
|
},
|
|
92
100
|
{
|