@henols/c64-re-tools 1.1.0 → 2.0.0-rc.3
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/LICENSE +21 -0
- package/README.md +138 -37
- package/distribution/package.ts +36 -0
- package/distribution/plugin.ts +120 -0
- package/package.json +34 -40
- package/skills/c64-assembler/SKILL.md +73 -0
- package/skills/c64-assembler/scripts/assemble.ts +103 -0
- package/skills/c64-basic/SKILL.md +67 -0
- package/skills/c64-basic/scripts/basic.ts +46 -0
- package/skills/c64-disk/SKILL.md +79 -0
- package/skills/c64-disk/scripts/disk.ts +65 -0
- package/skills/c64-emulator/SKILL.md +124 -0
- package/skills/c64-knowledge/SKILL.md +102 -0
- package/skills/c64-knowledge/scripts/knowledge.ts +257 -0
- package/skills/c64-memory-map/SKILL.md +76 -0
- package/skills/c64-memory-map/scripts/memmap.ts +81 -0
- package/skills/c64-memory-map/scripts/platform.ts +424 -0
- package/skills/c64-provenance/SKILL.md +76 -0
- package/skills/c64-provenance/scripts/compare.ts +92 -0
- package/skills/c64-provenance/scripts/provenance.ts +83 -0
- package/skills/c64-reverse-engineering/SKILL.md +90 -0
- package/skills/c64-static-analysis/SKILL.md +96 -0
- package/skills/c64-static-analysis/scripts/analyze.ts +175 -0
- package/skills/c64-static-analysis/scripts/findings.ts +73 -0
- package/skills/c64-testing/SKILL.md +79 -0
- package/skills/c64-testing/references/scenario-format.md +76 -0
- package/skills/c64-testing/scripts/checklist.ts +51 -0
- package/skills/c64-testing/scripts/scenario.ts +473 -0
- package/skills/c64-testing/scripts/test.ts +55 -0
- package/skills/c64-unpacker/SKILL.md +82 -0
- package/skills/c64-unpacker/scripts/evidence.ts +135 -0
- package/skills/c64-unpacker/scripts/unpack.ts +216 -0
- package/src/c64.ts +281 -0
- package/src/cli/ap-sdk.ts +44 -0
- package/src/cli/cleanup.ts +194 -0
- package/src/cli/main.ts +122 -0
- package/src/cli/status.ts +34 -0
- package/src/host/main.ts +106 -0
- package/src/host/server.ts +376 -0
- package/src/host/tools/c1541.ts +255 -0
- package/src/host/tools/index.ts +31 -0
- package/src/host/tools/petcat.ts +70 -0
- package/src/host/tools/status.ts +30 -0
- package/src/host/tools/version.ts +41 -0
- package/src/host/vice/adapter.ts +761 -0
- package/src/host/vice/binary-monitor.ts +389 -0
- package/src/host/vice/chips.ts +108 -0
- package/src/host/vice/connect.ts +34 -0
- package/src/host/vice/process.ts +402 -0
- package/src/host/vice/screen.ts +183 -0
- package/src/host/vice/session.ts +1316 -0
- package/src/host/vice/text-monitor.ts +223 -0
- package/src/host-client/connect.ts +238 -0
- package/src/host-client/tools.ts +89 -0
- package/src/host-client/transfer.ts +100 -0
- package/src/host-client/vice-session.ts +254 -0
- package/src/knowledge/database.ts +132 -0
- package/src/knowledge/history.ts +128 -0
- package/src/knowledge/import.ts +344 -0
- package/src/knowledge/read.ts +191 -0
- package/src/knowledge/schema.ts +140 -0
- package/src/knowledge/write.ts +348 -0
- package/src/mcp/main.ts +106 -0
- package/src/mcp/server.ts +307 -0
- package/src/mcp/tools/debug.ts +237 -0
- package/src/mcp/tools/execution.ts +116 -0
- package/src/mcp/tools/input.ts +69 -0
- package/src/mcp/tools/machine.ts +97 -0
- package/src/mcp/tools/media.ts +106 -0
- package/src/mcp/tools/memory.ts +203 -0
- package/src/mcp/tools/video.ts +260 -0
- package/src/native/acme.ts +116 -0
- package/src/native/discover.ts +141 -0
- package/src/native/dxa.ts +166 -0
- package/src/native/ghidra/analyze.ts +86 -0
- package/src/native/ghidra/index.ts +157 -0
- package/src/native/ghidra/language/c64rt_6510.cspec +34 -0
- package/src/native/ghidra/language/c64rt_6510.ldefs +15 -0
- package/src/native/ghidra/language/c64rt_6510.pspec +15 -0
- package/src/native/ghidra/language/c64rt_6510.slaspec +596 -0
- package/src/native/ghidra/scripts/C64Export.java +242 -0
- package/src/native/ghidra/scripts/C64Prepare.java +60 -0
- package/src/native/local.ts +34 -0
- package/src/native/processes.ts +350 -0
- package/src/native/run.ts +172 -0
- package/src/native/staging.ts +83 -0
- package/src/native/status.ts +101 -0
- package/src/native/types.ts +228 -0
- package/src/native/watchdog.ts +78 -0
- package/src/project.ts +39 -0
- package/src/protocol/framing.ts +132 -0
- package/src/protocol/messages.ts +243 -0
- package/src/protocol/tools.ts +247 -0
- package/src/protocol/vice.ts +1235 -0
- package/src/script.ts +59 -0
- package/src/time.ts +15 -0
- package/src/trace.ts +162 -0
- package/THIRD-PARTY-NOTICES.md +0 -26
- package/bin/cli.mjs +0 -283
- package/skills/acme-build/SKILL.md +0 -260
- package/skills/acme-build/scripts/acme.mjs +0 -341
- package/skills/acme-build/template.a +0 -53
- package/skills/c64-disk-access/SKILL.md +0 -159
- package/skills/c64-disk-access/scripts/c1541.mjs +0 -569
- package/skills/c64-memory-mapping/SKILL.md +0 -631
- package/skills/c64-memory-mapping/memmap.json +0 -8800
- package/skills/c64-memory-mapping/scripts/driver.mjs +0 -553
- package/skills/c64-petcat/SKILL.md +0 -87
- package/skills/c64-petcat/scripts/petcat.mjs +0 -221
- package/skills/c64-program-recon/SKILL.md +0 -706
- package/skills/c64-program-recon/references/control-flow.md +0 -180
- package/skills/c64-program-recon/references/graphics.md +0 -79
- package/skills/c64-program-recon/references/observation-hazards.md +0 -143
- package/skills/c64-program-recon/references/reconstruction.md +0 -133
- package/skills/c64-program-recon/references/sound-and-input.md +0 -74
- package/skills/c64-program-recon/references/tool-selection.md +0 -78
- package/skills/c64-program-recon/scripts/derive.mjs +0 -364
- package/skills/c64-program-recon/scripts/packer-finding.mjs +0 -709
- package/skills/c64-program-recon/templates/memory-map.template.md +0 -101
- package/skills/c64-provenance-diff/SKILL.md +0 -292
- package/skills/c64-provenance-diff/scripts/diff-images.mjs +0 -984
- package/skills/c64-provenance-diff/scripts/recovery-schema.mjs +0 -395
- package/skills/c64-ram-capture/RELEASES.json.example +0 -17
- package/skills/c64-ram-capture/SKILL.md +0 -474
- package/skills/c64-ram-capture/scripts/compare-cross-binary.mjs +0 -525
- package/skills/c64-ram-capture/scripts/compare.mjs +0 -258
- package/skills/c64-ram-capture/scripts/derive-transients.mjs +0 -575
- package/skills/c64-ram-capture/scripts/dump-artifacts.mjs +0 -317
- package/skills/c64-ram-capture/scripts/mcp-module.mjs +0 -174
- package/skills/c64-ram-capture/scripts/project-paths.mjs +0 -81
- package/skills/c64-ram-capture/scripts/releases.mjs +0 -109
- package/skills/c64-ram-capture/scripts/vsf-slice.mjs +0 -147
- package/skills/c64-ram-capture/scripts/watch-loads.mjs +0 -581
- package/skills/c64-ram-capture/templates/capture-record.template.md +0 -99
- package/skills/c64-ram-capture/transients/README.md +0 -137
- package/skills/routine-queue-walker/SKILL.md +0 -394
- package/skills/routine-queue-walker/scripts/completeness-report.mjs +0 -465
- package/skills/vice-wedge-triage/SKILL.md +0 -269
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// The c64-knowledge script: reads and writes .c64-re-tools/knowledge.db in the
|
|
2
|
+
// project directory (the working directory) and prints one compact JSON result.
|
|
3
|
+
|
|
4
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
|
|
7
|
+
import { formatC64Address, parseC64Address } from "#src/c64.ts";
|
|
8
|
+
import { KnowledgeError, openForRead, withWrite } from "#src/knowledge/database.ts";
|
|
9
|
+
import { historyAt, historyNamed, revision, revisions, type HistoryEntry } from "#src/knowledge/history.ts";
|
|
10
|
+
import {
|
|
11
|
+
at,
|
|
12
|
+
listComments,
|
|
13
|
+
listReferences,
|
|
14
|
+
listRegions,
|
|
15
|
+
listSymbols,
|
|
16
|
+
search,
|
|
17
|
+
type CommentRow,
|
|
18
|
+
type ReferenceRow,
|
|
19
|
+
type RegionRow,
|
|
20
|
+
type SymbolRow,
|
|
21
|
+
} from "#src/knowledge/read.ts";
|
|
22
|
+
import {
|
|
23
|
+
COMMENT_PLACEMENTS,
|
|
24
|
+
REFERENCE_KINDS,
|
|
25
|
+
REGION_TYPES,
|
|
26
|
+
SYMBOL_KINDS,
|
|
27
|
+
type CommentPlacement,
|
|
28
|
+
type ReferenceKind,
|
|
29
|
+
type RegionType,
|
|
30
|
+
type SymbolKind,
|
|
31
|
+
} from "#src/knowledge/schema.ts";
|
|
32
|
+
import {
|
|
33
|
+
addReference,
|
|
34
|
+
classifyRegion,
|
|
35
|
+
removeComment,
|
|
36
|
+
removeReference,
|
|
37
|
+
removeSymbol,
|
|
38
|
+
renameSymbol,
|
|
39
|
+
revert,
|
|
40
|
+
setComment,
|
|
41
|
+
unclassifyRegion,
|
|
42
|
+
type WriteContext,
|
|
43
|
+
} from "#src/knowledge/write.ts";
|
|
44
|
+
import { runScript, UsageError } from "#src/script.ts";
|
|
45
|
+
|
|
46
|
+
const USAGE = `knowledge.ts <command> [arguments] [options]
|
|
47
|
+
|
|
48
|
+
Read (no database needed):
|
|
49
|
+
at <address> everything known at one address
|
|
50
|
+
search <text> symbol names and comment texts
|
|
51
|
+
symbols [--start A --end A --kind K]
|
|
52
|
+
regions [--start A --end A --type T]
|
|
53
|
+
comments [--start A --end A]
|
|
54
|
+
references [--start A --end A --kind K]
|
|
55
|
+
history <address> | history --name <name>
|
|
56
|
+
revisions [--limit N --before N]
|
|
57
|
+
revision <id>
|
|
58
|
+
|
|
59
|
+
Write (one revision each; creates the database when needed):
|
|
60
|
+
rename <address> <name> [--kind K]
|
|
61
|
+
remove-symbol <address>
|
|
62
|
+
classify <start> <end> <type>
|
|
63
|
+
unclassify <start> <end>
|
|
64
|
+
comment <address> <line|side> <text>
|
|
65
|
+
uncomment <address> <line|side>
|
|
66
|
+
reference <from> <to> <kind>
|
|
67
|
+
unreference <from> <to> <kind>
|
|
68
|
+
revert <revision>
|
|
69
|
+
|
|
70
|
+
Write options:
|
|
71
|
+
--reason <text> why, kept with the revision
|
|
72
|
+
--expect-revision <N> refuse the write if knowledge changed after revision N
|
|
73
|
+
--origin user|llm who decided (default llm)
|
|
74
|
+
|
|
75
|
+
Addresses are $ and four hex digits; quote them in a shell: '$2100'.`;
|
|
76
|
+
|
|
77
|
+
function address(value: string | undefined, what = "address"): number {
|
|
78
|
+
if (value === undefined) throw new UsageError(`${what} is missing`);
|
|
79
|
+
try {
|
|
80
|
+
return parseC64Address(value);
|
|
81
|
+
} catch {
|
|
82
|
+
throw new UsageError(`${what} must be $ followed by four hex digits, for example '$2100', not ${value}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function oneOf<T extends string>(values: readonly T[], value: string | undefined, what: string): T {
|
|
87
|
+
if (value === undefined || !(values as readonly string[]).includes(value)) throw new UsageError(`${what} must be one of: ${values.join(", ")}`);
|
|
88
|
+
return value as T;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function integer(value: string | undefined, what: string): number {
|
|
92
|
+
if (value === undefined || !/^\d+$/.test(value)) throw new UsageError(`${what} must be a whole number`);
|
|
93
|
+
return Number(value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Output shapes: addresses as $xxxx, nothing internal.
|
|
97
|
+
const symbol = (row: SymbolRow) => ({ address: formatC64Address(row.address), name: row.name, kind: row.kind, origin: row.origin, revision: row.revision });
|
|
98
|
+
const region = (row: RegionRow) => ({ start: formatC64Address(row.start), end: formatC64Address(row.end), type: row.type, origin: row.origin, revision: row.revision });
|
|
99
|
+
const comment = (row: CommentRow) => ({ address: formatC64Address(row.address), placement: row.placement, text: row.text, origin: row.origin, revision: row.revision });
|
|
100
|
+
const reference = (row: ReferenceRow) => ({ from: formatC64Address(row.from), to: formatC64Address(row.to), kind: row.kind, origin: row.origin, revision: row.revision });
|
|
101
|
+
|
|
102
|
+
function historyEntry(entry: HistoryEntry) {
|
|
103
|
+
const shown =
|
|
104
|
+
entry.entity === "symbol"
|
|
105
|
+
? symbol(entry.row)
|
|
106
|
+
: entry.entity === "region"
|
|
107
|
+
? region(entry.row)
|
|
108
|
+
: entry.entity === "comment"
|
|
109
|
+
? comment(entry.row)
|
|
110
|
+
: reference(entry.row);
|
|
111
|
+
const { revision: _revision, ...row } = shown;
|
|
112
|
+
return { entity: entry.entity, ...row, fromRevision: entry.from, ...(entry.to === undefined ? {} : { toRevision: entry.to }) };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function run(argv: string[]): unknown {
|
|
116
|
+
const { values, positionals } = parseArgs({
|
|
117
|
+
args: argv,
|
|
118
|
+
allowPositionals: true,
|
|
119
|
+
strict: true,
|
|
120
|
+
options: {
|
|
121
|
+
start: { type: "string" },
|
|
122
|
+
end: { type: "string" },
|
|
123
|
+
kind: { type: "string" },
|
|
124
|
+
type: { type: "string" },
|
|
125
|
+
name: { type: "string" },
|
|
126
|
+
limit: { type: "string" },
|
|
127
|
+
before: { type: "string" },
|
|
128
|
+
reason: { type: "string" },
|
|
129
|
+
"expect-revision": { type: "string" },
|
|
130
|
+
origin: { type: "string" },
|
|
131
|
+
help: { type: "boolean" },
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
const [command, ...args] = positionals;
|
|
135
|
+
if (values.help || command === undefined) throw new UsageError("");
|
|
136
|
+
const range = { start: values.start === undefined ? 0x0000 : address(values.start, "--start"), end: values.end === undefined ? 0xffff : address(values.end, "--end") };
|
|
137
|
+
|
|
138
|
+
const read = new Set(["at", "search", "symbols", "regions", "comments", "references", "history", "revisions", "revision"]);
|
|
139
|
+
const write = new Set(["rename", "remove-symbol", "classify", "unclassify", "comment", "uncomment", "reference", "unreference", "revert"]);
|
|
140
|
+
// Refuse a mistyped command before anything opens, so no database appears by accident.
|
|
141
|
+
if (!read.has(command) && !write.has(command)) throw new UsageError(`unknown command: ${command}`);
|
|
142
|
+
if (read.has(command)) {
|
|
143
|
+
const db = openForRead();
|
|
144
|
+
try {
|
|
145
|
+
switch (command) {
|
|
146
|
+
case "at": {
|
|
147
|
+
const known = at(db, address(args[0]));
|
|
148
|
+
return {
|
|
149
|
+
address: formatC64Address(known.address),
|
|
150
|
+
...(known.symbol === undefined ? {} : { symbol: symbol(known.symbol) }),
|
|
151
|
+
...(known.region === undefined ? {} : { region: region(known.region) }),
|
|
152
|
+
comments: known.comments.map(comment),
|
|
153
|
+
referencesFrom: known.referencesFrom.map(reference),
|
|
154
|
+
referencesTo: known.referencesTo.map(reference),
|
|
155
|
+
revision: known.revision,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
case "search": {
|
|
159
|
+
if (args[0] === undefined || args[0] === "") throw new UsageError("search needs text");
|
|
160
|
+
const found = search(db, args[0], values.limit === undefined ? 50 : integer(values.limit, "--limit"));
|
|
161
|
+
return { symbols: found.symbols.map(symbol), comments: found.comments.map(comment) };
|
|
162
|
+
}
|
|
163
|
+
case "symbols":
|
|
164
|
+
return { symbols: listSymbols(db, range, values.kind === undefined ? undefined : oneOf(SYMBOL_KINDS, values.kind, "--kind")).map(symbol) };
|
|
165
|
+
case "regions":
|
|
166
|
+
return { regions: listRegions(db, range, values.type === undefined ? undefined : oneOf(REGION_TYPES, values.type, "--type")).map(region) };
|
|
167
|
+
case "comments":
|
|
168
|
+
return { comments: listComments(db, range).map(comment) };
|
|
169
|
+
case "references":
|
|
170
|
+
return { references: listReferences(db, range, values.kind === undefined ? undefined : oneOf(REFERENCE_KINDS, values.kind, "--kind")).map(reference) };
|
|
171
|
+
case "history":
|
|
172
|
+
return { history: (values.name === undefined ? historyAt(db, address(args[0])) : historyNamed(db, values.name)).map(historyEntry) };
|
|
173
|
+
case "revisions": {
|
|
174
|
+
const options: { limit?: number; before?: number } = {};
|
|
175
|
+
if (values.limit !== undefined) options.limit = integer(values.limit, "--limit");
|
|
176
|
+
if (values.before !== undefined) options.before = integer(values.before, "--before");
|
|
177
|
+
return { revisions: revisions(db, options) };
|
|
178
|
+
}
|
|
179
|
+
default: {
|
|
180
|
+
const changes = revision(db, integer(args[0], "revision"));
|
|
181
|
+
return { revision: changes.revision, added: changes.added.map(historyEntry), closed: changes.closed.map(historyEntry) };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
} finally {
|
|
185
|
+
db?.close();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const context: WriteContext = { origin: values.origin === undefined ? "llm" : oneOf(["user", "llm"] as const, values.origin, "--origin") };
|
|
190
|
+
if (values.reason !== undefined) context.description = values.reason;
|
|
191
|
+
if (values["expect-revision"] !== undefined) context.expectedRevision = integer(values["expect-revision"], "--expect-revision");
|
|
192
|
+
// Every argument is checked before the database opens: a refused write creates no database.
|
|
193
|
+
const operation = writeOperation(command, args, values.kind, context);
|
|
194
|
+
return withWrite(operation);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
type WriteOperation = (db: DatabaseSync) => unknown;
|
|
198
|
+
|
|
199
|
+
function writeOperation(command: string, args: string[], kind: string | undefined, context: WriteContext): WriteOperation {
|
|
200
|
+
switch (command) {
|
|
201
|
+
case "rename": {
|
|
202
|
+
if (args[1] === undefined) throw new UsageError("name is missing");
|
|
203
|
+
const request: { address: number; name: string; kind?: SymbolKind } = { address: address(args[0]), name: args[1] };
|
|
204
|
+
if (kind !== undefined) request.kind = oneOf(SYMBOL_KINDS, kind, "--kind");
|
|
205
|
+
return (db) => {
|
|
206
|
+
const result = renameSymbol(db, context, request);
|
|
207
|
+
return { revision: result.revision, symbol: symbol(result.current), ...(result.previous === undefined ? {} : { previous: symbol(result.previous) }) };
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
case "remove-symbol": {
|
|
211
|
+
const request = { address: address(args[0]) };
|
|
212
|
+
return (db) => ({ revision: removeSymbol(db, context, request).revision });
|
|
213
|
+
}
|
|
214
|
+
case "classify": {
|
|
215
|
+
const request = { start: address(args[0], "start"), end: address(args[1], "end"), type: oneOf(REGION_TYPES, args[2], "type") as RegionType };
|
|
216
|
+
return (db) => {
|
|
217
|
+
const result = classifyRegion(db, context, request);
|
|
218
|
+
return { revision: result.revision, regions: result.current.map(region), ...(result.previous === undefined ? {} : { previous: result.previous.map(region) }) };
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
case "unclassify": {
|
|
222
|
+
const request = { start: address(args[0], "start"), end: address(args[1], "end") };
|
|
223
|
+
return (db) => ({ revision: unclassifyRegion(db, context, request).revision });
|
|
224
|
+
}
|
|
225
|
+
case "comment": {
|
|
226
|
+
if (args.length < 3) throw new UsageError("text is missing");
|
|
227
|
+
const request = { address: address(args[0]), placement: oneOf(COMMENT_PLACEMENTS, args[1], "placement") as CommentPlacement, text: args.slice(2).join(" ") };
|
|
228
|
+
return (db) => {
|
|
229
|
+
const result = setComment(db, context, request);
|
|
230
|
+
return { revision: result.revision, comment: comment(result.current) };
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
case "uncomment": {
|
|
234
|
+
const request = { address: address(args[0]), placement: oneOf(COMMENT_PLACEMENTS, args[1], "placement") };
|
|
235
|
+
return (db) => ({ revision: removeComment(db, context, request).revision });
|
|
236
|
+
}
|
|
237
|
+
case "reference": {
|
|
238
|
+
const request = { from: address(args[0], "from"), to: address(args[1], "to"), kind: oneOf(REFERENCE_KINDS, args[2], "kind") as ReferenceKind };
|
|
239
|
+
return (db) => {
|
|
240
|
+
const result = addReference(db, context, request);
|
|
241
|
+
return { revision: result.revision, reference: reference(result.current) };
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
case "unreference": {
|
|
245
|
+
const request = { from: address(args[0], "from"), to: address(args[1], "to"), kind: oneOf(REFERENCE_KINDS, args[2], "kind") };
|
|
246
|
+
return (db) => ({ revision: removeReference(db, context, request).revision });
|
|
247
|
+
}
|
|
248
|
+
case "revert": {
|
|
249
|
+
const request = { revision: integer(args[0], "revision") };
|
|
250
|
+
return (db) => ({ revision: revert(db, context, request).revision });
|
|
251
|
+
}
|
|
252
|
+
default:
|
|
253
|
+
throw new UsageError(`unknown command: ${command}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
await runScript(() => run(process.argv.slice(2)), { usage: USAGE, refusals: [KnowledgeError] });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: c64-memory-map
|
|
3
|
+
description: Use this skill to find what a C64 address means on the platform. 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 you when an address has no platform meaning and belongs to the application.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# c64-memory-map
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
Give the C64 platform meaning of an address or of a register value.
|
|
11
|
+
|
|
12
|
+
This skill does not read the emulator and does not change project knowledge.
|
|
13
|
+
|
|
14
|
+
## Inputs
|
|
15
|
+
|
|
16
|
+
- One or more addresses.
|
|
17
|
+
- Or a register and a value to decode.
|
|
18
|
+
|
|
19
|
+
## Tools / execution path
|
|
20
|
+
|
|
21
|
+
The script looks up local reference data. It does not use the host runtime.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
node <skill>/scripts/memmap.ts at '$d020' '$0314' '$ffd2'
|
|
25
|
+
node <skill>/scripts/memmap.ts decode '$d018' '$15' --bank '$97'
|
|
26
|
+
node <skill>/scripts/memmap.ts list vic
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Command | Result |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `at <address> ...` | For each address: `kind` (`platform` or `application`), the area, the name and the meaning. |
|
|
32
|
+
| `decode <register> <value>` | The meaning of the value. Use `--bank` with the value of `$DD00` to get the addresses for `$D018`. |
|
|
33
|
+
| `list <vic\|sid\|cia1\|cia2\|kernal\|system>` | All entries of that group. |
|
|
34
|
+
|
|
35
|
+
Write an address or a value as `$` and hex digits, as a decimal number, or as `%` and binary digits. Put a `$` value in single quotes in a shell.
|
|
36
|
+
|
|
37
|
+
The script prints one JSON object.
|
|
38
|
+
|
|
39
|
+
## Workflow
|
|
40
|
+
|
|
41
|
+
1. Run `at` for the addresses in the code or the question.
|
|
42
|
+
2. Read `kind`:
|
|
43
|
+
- `platform`: the C64 gives the address a meaning. Read `name` and `meaning`.
|
|
44
|
+
- `application`: the address has no platform meaning. The program decides its use. Find its use with the c64-static-analysis or c64-emulator skill.
|
|
45
|
+
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.
|
|
46
|
+
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.
|
|
47
|
+
5. To understand a value in a register, run `decode`. For the memory configuration, decode the value of `$01`.
|
|
48
|
+
|
|
49
|
+
The decoders are for `$01`, `$D010`, `$D011`, `$D015` to `$D01F` (the sprite and interrupt bits), `$D016`, `$D018`, `$DC0D`, `$DD00` and `$DD0D`.
|
|
50
|
+
|
|
51
|
+
## Knowledge
|
|
52
|
+
|
|
53
|
+
Automatic write:
|
|
54
|
+
- none.
|
|
55
|
+
|
|
56
|
+
Platform facts are reference data. Do not store them as project knowledge.
|
|
57
|
+
|
|
58
|
+
A conclusion about the application can be project knowledge. For example: "the program writes its own IRQ handler address to `$0314`". Record it with the c64-knowledge skill.
|
|
59
|
+
|
|
60
|
+
## Result
|
|
61
|
+
|
|
62
|
+
The platform meaning of each address, or the decoded meaning of a register value.
|
|
63
|
+
|
|
64
|
+
The exit status is 0 for a result. The exit status is 2 for a wrong argument.
|
|
65
|
+
|
|
66
|
+
## Failure and conflicts
|
|
67
|
+
|
|
68
|
+
- `kind: application`: this is not a failure. The address has no platform meaning.
|
|
69
|
+
- `invalid-input`: the address, the register or the value is not correct, or no decoder exists for the register. Read the message.
|
|
70
|
+
|
|
71
|
+
Some registers have a different meaning for a read and for a write, for example `$DC0D`. The decoded result shows both.
|
|
72
|
+
|
|
73
|
+
## Handoffs
|
|
74
|
+
|
|
75
|
+
- The value of an address at run time → c64-emulator
|
|
76
|
+
- A conclusion about the application → c64-knowledge
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// The c64-memory-map script: the platform meaning of C64 addresses and of
|
|
2
|
+
// values in platform registers. Local lookup only; nothing is stored.
|
|
3
|
+
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
|
|
6
|
+
import { runScript, UsageError } from "#src/script.ts";
|
|
7
|
+
import { decode, IO, lookup, ROM, SYSTEM, type Entry } from "./platform.ts";
|
|
8
|
+
|
|
9
|
+
const USAGE = `memmap.ts at <address> [<address> ...]
|
|
10
|
+
memmap.ts decode <register> <value> [--bank <$dd00 value>]
|
|
11
|
+
memmap.ts list <vic|sid|cia1|cia2|kernal|system>
|
|
12
|
+
|
|
13
|
+
Addresses and values are $ and hex digits, decimal, or % and binary digits.
|
|
14
|
+
The result is one JSON object.`;
|
|
15
|
+
|
|
16
|
+
const hex = (value: number, digits = 4) => `$${value.toString(16).padStart(digits, "0")}`;
|
|
17
|
+
|
|
18
|
+
function number(text: string, max: number, what: string): number {
|
|
19
|
+
let value = Number.NaN;
|
|
20
|
+
if (/^\$[0-9a-f]{1,4}$/i.test(text)) value = Number.parseInt(text.slice(1), 16);
|
|
21
|
+
else if (/^%[01]{1,16}$/.test(text)) value = Number.parseInt(text.slice(1), 2);
|
|
22
|
+
else if (/^\d{1,5}$/.test(text)) value = Number(text);
|
|
23
|
+
if (!(value >= 0 && value <= max)) throw new UsageError(`${what} must be from 0 to ${hex(max, max > 0xff ? 4 : 2)}, not ${text}`);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const show = (entry: Entry) => ({ start: hex(entry.start), ...(entry.end !== entry.start ? { end: hex(entry.end) } : {}), name: entry.name, meaning: entry.meaning });
|
|
28
|
+
|
|
29
|
+
function run(argv: string[]): unknown {
|
|
30
|
+
const { values, positionals } = parseArgs({ args: argv, strict: true, allowPositionals: true, options: { bank: { type: "string" }, help: { type: "boolean" } } });
|
|
31
|
+
if (values.help || positionals.length === 0) throw new UsageError("");
|
|
32
|
+
const [command, ...rest] = positionals;
|
|
33
|
+
switch (command) {
|
|
34
|
+
case "at": {
|
|
35
|
+
if (rest.length === 0) throw new UsageError("give at least one address");
|
|
36
|
+
return {
|
|
37
|
+
addresses: rest.map((text) => {
|
|
38
|
+
const found = lookup(number(text, 0xffff, "an address"));
|
|
39
|
+
// The chip registers, color RAM and the cartridge I/O areas show only while $01 maps I/O in.
|
|
40
|
+
const io = found.address >= 0xd000 && found.address <= 0xdfff;
|
|
41
|
+
return {
|
|
42
|
+
...found,
|
|
43
|
+
address: hex(found.address),
|
|
44
|
+
...(found.mirrorOf === undefined ? {} : { mirrorOf: hex(found.mirrorOf) }),
|
|
45
|
+
...(found.entryStart === undefined ? {} : { entryStart: hex(found.entryStart) }),
|
|
46
|
+
...(io ? { visible: "when $01 shows I/O at $D000 (the default)" } : {}),
|
|
47
|
+
};
|
|
48
|
+
}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
case "decode": {
|
|
52
|
+
if (rest.length !== 2) throw new UsageError("decode takes a register and a value");
|
|
53
|
+
const register = number(rest[0]!, 0xffff, "the register");
|
|
54
|
+
const value = number(rest[1]!, 0xff, "the value");
|
|
55
|
+
const bank = values.bank === undefined ? undefined : number(values.bank, 0xff, "--bank");
|
|
56
|
+
try {
|
|
57
|
+
return { register: hex(register), value: hex(value, 2), name: lookup(register).name, ...decode(register, value, bank) };
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof RangeError) throw new UsageError(error.message);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
case "list": {
|
|
64
|
+
const lists: Record<string, Entry[]> = {
|
|
65
|
+
vic: IO[0]!.registers,
|
|
66
|
+
sid: IO[1]!.registers,
|
|
67
|
+
cia1: IO[2]!.registers,
|
|
68
|
+
cia2: IO[3]!.registers,
|
|
69
|
+
kernal: ROM,
|
|
70
|
+
system: SYSTEM,
|
|
71
|
+
};
|
|
72
|
+
const list = lists[rest[0] ?? ""];
|
|
73
|
+
if (list === undefined || rest.length !== 1) throw new UsageError(`list takes one of ${Object.keys(lists).join(", ")}`);
|
|
74
|
+
return { entries: list.map(show) };
|
|
75
|
+
}
|
|
76
|
+
default:
|
|
77
|
+
throw new UsageError(`unknown command ${command}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
await runScript(() => run(process.argv.slice(2)), { usage: USAGE });
|