@henols/c64-re-tools 2.6.0-rc.13 → 2.6.0-rc.15
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 +3 -3
- package/skills/c64-assembler/scripts/assembler.ts +4 -3
- package/skills/c64-docs/SKILL.md +1 -1
- package/skills/c64-docs/scripts/lib/reference.ts +29 -7
- package/skills/c64-docs/scripts/lib/source-map.ts +14 -0
- package/skills/c64-knowledge/SKILL.md +5 -5
- package/skills/c64-knowledge/scripts/knowledge.ts +11 -3
- package/skills/c64-source/SKILL.md +2 -2
- package/skills/c64-source/scripts/lib/export.ts +1 -1
- package/skills/c64-source/scripts/lib/loader.ts +2 -0
- package/skills/c64-source/scripts/lib/source.ts +4 -4
- package/skills/c64-source/scripts/source.ts +22 -17
- package/skills/c64-static-analysis/SKILL.md +21 -20
- package/skills/c64-static-analysis/scripts/lib/findings.ts +11 -11
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +4 -4
- package/skills/c64-static-analysis/scripts/static-analysis.ts +28 -26
- package/skills/c64-testing/scripts/testing.ts +5 -3
- package/src/build-name.ts +9 -4
- package/src/c64.ts +1 -1
- package/src/host/tools/index.ts +1 -1
- package/src/host-client/tools.ts +1 -1
- package/src/knowledge/import.ts +5 -5
- package/src/knowledge/program.ts +1 -1
- package/src/knowledge/read.ts +3 -3
- package/src/knowledge/schema.ts +3 -3
- package/src/native/c64run.ts +1 -1
- package/src/native/{ghidra → decompiler}/analyze.ts +17 -17
- package/src/native/{ghidra → decompiler}/language/c64rt_6510.slaspec +1 -1
- package/src/native/{ghidra → decompiler}/walk.ts +6 -6
- package/src/native/types.ts +25 -25
- package/src/opcodes.ts +1 -1
- package/src/script.ts +1 -1
- package/tools/c64run.c +8 -1
- /package/src/native/{ghidra → decompiler}/c64rt-wasm.ts +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.cspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.ldefs +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.pspec +0 -0
- /package/src/native/{ghidra → decompiler}/language/c64rt_6510.sla +0 -0
- /package/src/native/{ghidra → decompiler}/pcode.ts +0 -0
- /package/src/native/{ghidra → decompiler}/wasm.ts +0 -0
package/src/native/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Types of the native tools that skill scripts run directly (ACME, DXA,
|
|
2
|
-
//
|
|
2
|
+
// the decompiler), and the checks of their complete results. The skill script runs
|
|
3
3
|
// these tools itself: nothing here crosses the Host Runtime wire. Bytes
|
|
4
4
|
// (a program, an image, a listing) go next to these values as attachments.
|
|
5
5
|
|
|
@@ -43,14 +43,14 @@ export interface AcmeResult {
|
|
|
43
43
|
export const IMAGE_KINDS = ["prg", "flat64k"] as const;
|
|
44
44
|
export type ImageKind = (typeof IMAGE_KINDS)[number];
|
|
45
45
|
|
|
46
|
-
export const
|
|
46
|
+
export const DECOMPILER_LIMITS = { entryPoints: 1024, codeStarts: 8192, dataRanges: 1024, labels: 4096, decompile: 32, decompiledChars: 16_000, decompiledTotalChars: 128_000 } as const;
|
|
47
47
|
|
|
48
|
-
/** The
|
|
49
|
-
export interface
|
|
48
|
+
/** The analysis. Its image is given next to these fields: a PRG, or 64 KiB from $0000. */
|
|
49
|
+
export interface DecompilerParams {
|
|
50
50
|
imageKind: ImageKind;
|
|
51
51
|
/** Seeds from current knowledge. */
|
|
52
52
|
entryPoints: number[];
|
|
53
|
-
/** Executed instruction starts that
|
|
53
|
+
/** Executed instruction starts that the decompiler disassembles without making a function: a branch target is no routine. */
|
|
54
54
|
codeStarts?: number[];
|
|
55
55
|
dataRanges: Array<{ start: number; end: number }>;
|
|
56
56
|
labels: Array<{ address: number; name: string }>;
|
|
@@ -58,7 +58,7 @@ export interface GhidraParams {
|
|
|
58
58
|
decompile: number[];
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export interface
|
|
61
|
+
export interface DecompilerInstruction {
|
|
62
62
|
address: number;
|
|
63
63
|
/** Lowercase hex, 1 to 3 bytes. */
|
|
64
64
|
bytes: string;
|
|
@@ -69,7 +69,7 @@ export interface GhidraInstruction {
|
|
|
69
69
|
flows: number[];
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export interface
|
|
72
|
+
export interface DecompilerResult {
|
|
73
73
|
coverage: Array<{ start: number; end: number }>;
|
|
74
74
|
functions: Array<{ entry: number; name: string; nameSource: "seed" | "generated" | "native" }>;
|
|
75
75
|
regions: Array<{ start: number; end: number; classification: "code" | "data" }>;
|
|
@@ -77,30 +77,30 @@ export interface GhidraResult {
|
|
|
77
77
|
decompilations: Array<{ entry: number; text: string; truncated: boolean }>;
|
|
78
78
|
/** Requested routines without decompiled code, with the decompiler's reason. */
|
|
79
79
|
notDecompiled?: Array<{ entry: number; reason: string }>;
|
|
80
|
-
/** Every instruction in the coverage, as
|
|
81
|
-
instructions:
|
|
80
|
+
/** Every instruction in the coverage, as the decompiler decoded it. */
|
|
81
|
+
instructions: DecompilerInstruction[];
|
|
82
82
|
/** Which categories are complete inside the coverage; private to the importer. */
|
|
83
83
|
completeness: { functions: boolean; regions: boolean; references: boolean };
|
|
84
84
|
/** The version of the Ghidra port that made the result, for example "ghidra-decompiler 2.1.0". */
|
|
85
85
|
toolVersion?: string;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
/** Refuses a DXA or
|
|
88
|
+
/** Refuses a DXA or decompiler request with more seeds or decompilations than the request bounds allow, by name. */
|
|
89
89
|
export function checkRequestBounds(params: DxaParams & { decompile?: number[]; codeStarts?: number[] }): void {
|
|
90
90
|
const bounds = [
|
|
91
|
-
["entry points", params.entryPoints.length,
|
|
92
|
-
["code starts", params.codeStarts?.length ?? 0,
|
|
93
|
-
["data ranges", params.dataRanges.length,
|
|
94
|
-
["labels", params.labels.length,
|
|
95
|
-
["routines to decompile", params.decompile?.length ?? 0,
|
|
91
|
+
["entry points", params.entryPoints.length, DECOMPILER_LIMITS.entryPoints],
|
|
92
|
+
["code starts", params.codeStarts?.length ?? 0, DECOMPILER_LIMITS.codeStarts],
|
|
93
|
+
["data ranges", params.dataRanges.length, DECOMPILER_LIMITS.dataRanges],
|
|
94
|
+
["labels", params.labels.length, DECOMPILER_LIMITS.labels],
|
|
95
|
+
["routines to decompile", params.decompile?.length ?? 0, DECOMPILER_LIMITS.decompile],
|
|
96
96
|
] as const;
|
|
97
97
|
for (const [name, count, limit] of bounds) {
|
|
98
98
|
if (count > limit) throw new WireFailure("invalid-input", `The request has ${count} ${name}. Give at most ${limit} ${name}.`);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
/** The DXA analysis: the same image and seeds as
|
|
103
|
-
export type DxaParams = Omit<
|
|
102
|
+
/** The DXA analysis: the same image and seeds as the decompiler, without decompilation. */
|
|
103
|
+
export type DxaParams = Omit<DecompilerParams, "decompile" | "codeStarts">;
|
|
104
104
|
|
|
105
105
|
export interface DxaResult {
|
|
106
106
|
coverage: Array<{ start: number; end: number }>;
|
|
@@ -129,11 +129,11 @@ function fail(message: string): never {
|
|
|
129
129
|
const isList = (value: unknown): value is unknown[] => Array.isArray(value);
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
* Checks a complete
|
|
132
|
+
* Checks a complete decompiler result: every field typed and in range, every
|
|
133
133
|
* function, region and reference source inside the coverage, regions sorted
|
|
134
134
|
* and without overlap. Throws an Error naming the first problem.
|
|
135
135
|
*/
|
|
136
|
-
export function
|
|
136
|
+
export function checkDecompilerResult(value: unknown): DecompilerResult {
|
|
137
137
|
if (!isObject(value)) fail("not an object");
|
|
138
138
|
const { coverage, functions, regions, references, decompilations, notDecompiled, completeness, toolVersion, instructions } = value;
|
|
139
139
|
if (!isList(coverage) || coverage.length === 0) fail("no coverage");
|
|
@@ -179,16 +179,16 @@ export function checkGhidraResult(value: unknown): GhidraResult {
|
|
|
179
179
|
if (!isObject(reference) || !isInteger(reference.from, 0, 0xffff) || !isInteger(reference.to, 0, 0xffff) || !isOneOf(REFERENCE_KINDS, reference.type)) fail("bad reference");
|
|
180
180
|
if (!covered(reference.from)) fail("a reference source lies outside the coverage");
|
|
181
181
|
}
|
|
182
|
-
if (!isList(decompilations) || decompilations.length >
|
|
182
|
+
if (!isList(decompilations) || decompilations.length > DECOMPILER_LIMITS.decompile) fail("bad decompilations");
|
|
183
183
|
let total = 0;
|
|
184
184
|
for (const item of decompilations) {
|
|
185
185
|
if (!isObject(item) || !isInteger(item.entry, 0, 0xffff) || typeof item.text !== "string" || typeof item.truncated !== "boolean") fail("bad decompilation");
|
|
186
|
-
if (item.text.length >
|
|
186
|
+
if (item.text.length > DECOMPILER_LIMITS.decompiledChars) fail("a decompilation is too long");
|
|
187
187
|
total += item.text.length;
|
|
188
188
|
}
|
|
189
|
-
if (total >
|
|
189
|
+
if (total > DECOMPILER_LIMITS.decompiledTotalChars) fail("the decompilations are too long together");
|
|
190
190
|
if (notDecompiled !== undefined) {
|
|
191
|
-
if (!isList(notDecompiled) || notDecompiled.length >
|
|
191
|
+
if (!isList(notDecompiled) || notDecompiled.length > DECOMPILER_LIMITS.decompile) fail("bad list of routines that were not decompiled");
|
|
192
192
|
for (const item of notDecompiled) {
|
|
193
193
|
if (!isObject(item) || !isInteger(item.entry, 0, 0xffff) || typeof item.reason !== "string" || item.reason.length > 1000) fail("bad routine that was not decompiled");
|
|
194
194
|
}
|
|
@@ -196,7 +196,7 @@ export function checkGhidraResult(value: unknown): GhidraResult {
|
|
|
196
196
|
if (!isObject(completeness) || typeof completeness.functions !== "boolean" || typeof completeness.regions !== "boolean" || typeof completeness.references !== "boolean") fail("no completeness");
|
|
197
197
|
if (!isToolVersion(toolVersion)) fail("bad tool version");
|
|
198
198
|
// Every field is checked: the object is the result as it is.
|
|
199
|
-
return value as unknown as
|
|
199
|
+
return value as unknown as DecompilerResult;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
@@ -249,7 +249,7 @@ export function imageRange(kind: ImageKind, image: Uint8Array): { start: number;
|
|
|
249
249
|
* it, and the data ranges cut to it. A data range that holds an entry point
|
|
250
250
|
* is left out, so that the entry point is disassembled.
|
|
251
251
|
*/
|
|
252
|
-
export function seedsInside(params: Pick<
|
|
252
|
+
export function seedsInside(params: Pick<DecompilerParams, "entryPoints" | "dataRanges" | "codeStarts">, start: number, end: number): { entryPoints: number[]; codeStarts: number[]; dataRanges: DecompilerParams["dataRanges"] } {
|
|
253
253
|
const inside = (address: number) => address >= start && address <= end;
|
|
254
254
|
const entryPoints = params.entryPoints.filter(inside);
|
|
255
255
|
const codeStarts = (params.codeStarts ?? []).filter(inside);
|
package/src/opcodes.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The ACME spelling of each 6510 opcode: the mnemonic and the addressing
|
|
2
|
-
// mode, undocumented opcodes included.
|
|
2
|
+
// mode, undocumented opcodes included. The decompiler gives the instruction
|
|
3
3
|
// boundaries; this table gives the text. Where several opcodes share one
|
|
4
4
|
// spelling, ACME writes only one of them: the generator finds those with a
|
|
5
5
|
// probe and writes the others as bytes.
|
package/src/script.ts
CHANGED
|
@@ -129,7 +129,7 @@ export const OPTIONS = {
|
|
|
129
129
|
"timeout-frames": { kind: "count", value: "<n>", help: "stop a wait after this number of video frames", min: 1, max: 1_000_000 },
|
|
130
130
|
"max-listed": { kind: "count", value: "<n>", help: "list at most n items of each list (default 50). The counts are always given", min: 0, max: 100_000, default: 50 },
|
|
131
131
|
symbols: { kind: "path", value: "<file>", help: "the symbols of a build: the symbols file of the assembler, or a JSON map of name to $ address" },
|
|
132
|
-
origin: { kind: "text", value: "<origin>", help: "user, llm, dxa,
|
|
132
|
+
origin: { kind: "text", value: "<origin>", help: "user, llm, dxa, decompiler, heuristic, semantic (user and llm) or analyzer (dxa, decompiler and heuristic), or a comma list" },
|
|
133
133
|
reason: { kind: "text", value: "<text>", help: "why: kept with the revision" },
|
|
134
134
|
evidence: { kind: "text", value: "<kind:ref>", help: "what the change rests on: coverage:<map>, test:<file>, file:<file> or note:<text>", multiple: true },
|
|
135
135
|
"expect-revision": { kind: "text", value: "<revision>", help: "refuse the write when the knowledge changed after this revision" },
|
package/tools/c64run.c
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
#include "systems/c1541.h"
|
|
28
28
|
#include "systems/c64.h"
|
|
29
29
|
|
|
30
|
-
#define C64RUN_PROTOCOL
|
|
30
|
+
#define C64RUN_PROTOCOL 5
|
|
31
31
|
// The key code of matrix place 0 (row 0, column 0); place n has code 0x80 + n.
|
|
32
32
|
#define C64RUN_KEY_PLACE 0x80
|
|
33
33
|
#ifndef CHIPS_COMMIT
|
|
@@ -241,6 +241,13 @@ static void tick(void) {
|
|
|
241
241
|
if (sample_file && addr == sample_pc && decoded) sample();
|
|
242
242
|
if (coverage_armed_pc && addr == coverage_pc && decoded) { coverage_armed_pc = 0; coverage_start(addr); }
|
|
243
243
|
}
|
|
244
|
+
if (read && !sync && decoded && sys.io_mapped && (addr & 0xFF0F) == 0xDC00) {
|
|
245
|
+
// chips gives port A of CIA 1 only joystick 2. A key also pulls its line of port A
|
|
246
|
+
// low while port B drives its column low: the scan from port B that some games use.
|
|
247
|
+
const m6526_port_t* pb = &sys.cia_1.pb;
|
|
248
|
+
const uint8_t low_columns = (uint8_t)~(pb->reg | ~pb->ddr);
|
|
249
|
+
if (low_columns) M6502_SET_DATA(pins, M6502_GET_DATA(pins) & (uint8_t)~kbd_test_lines(&sys.kbd, low_columns));
|
|
250
|
+
}
|
|
244
251
|
if (read && !sync && decoded && sys.io_mapped && (addr & 0xF000) == 0xD000 && input_addr[addr & 0x0FFF]) {
|
|
245
252
|
input_read(last_sync_pc, addr);
|
|
246
253
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|