@henols/c64-re-tools 2.6.0-rc.1 → 2.6.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/skills/c64-assembler/SKILL.md +27 -13
- package/skills/c64-assembler/scripts/assembler.ts +26 -14
- package/skills/c64-development/SKILL.md +2 -2
- package/skills/c64-docs/SKILL.md +4 -4
- package/skills/c64-docs/scripts/docs.ts +7 -7
- package/skills/c64-docs/scripts/lib/reference.ts +3 -3
- package/skills/c64-docs/scripts/lib/source-map.ts +9 -4
- package/skills/c64-knowledge/SKILL.md +59 -35
- package/skills/c64-knowledge/scripts/knowledge.ts +75 -59
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-provenance/SKILL.md +11 -10
- package/skills/c64-provenance/scripts/lib/library.ts +16 -16
- package/skills/c64-provenance/scripts/provenance.ts +33 -23
- package/skills/c64-reverse-engineering/SKILL.md +17 -11
- package/skills/c64-source/SKILL.md +73 -48
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +33 -10
- package/skills/c64-source/scripts/lib/source.ts +24 -25
- package/skills/c64-source/scripts/lib/stage.ts +11 -5
- package/skills/c64-source/scripts/lib/start-screen.asm +4 -2
- package/skills/c64-source/scripts/source.ts +243 -124
- package/skills/c64-static-analysis/SKILL.md +7 -5
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -43
- package/skills/c64-testing/SKILL.md +5 -2
- package/skills/c64-testing/references/recording-format.md +18 -3
- package/skills/c64-testing/references/scenario-format.md +7 -6
- package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
- package/skills/c64-testing/scripts/lib/play.ts +39 -41
- package/skills/c64-testing/scripts/lib/recording.ts +46 -37
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/runs.ts +2 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +17 -10
- package/skills/c64-unpacker/SKILL.md +6 -3
- package/skills/c64-unpacker/scripts/lib/loads.ts +34 -13
- package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/skills/emulator/SKILL.md +7 -12
- package/src/build-name.ts +50 -0
- package/src/c64-keys.ts +98 -0
- package/src/c64.ts +21 -1
- package/src/cli/main.ts +3 -29
- package/src/host/main.ts +1 -1
- package/src/host/tools/index.ts +1 -6
- package/src/host/vice/session.ts +88 -9
- package/src/host-client/steps.ts +17 -17
- package/src/host-client/tools.ts +2 -7
- package/src/host-client/vice-session.ts +7 -1
- package/src/knowledge/program.ts +44 -1
- package/src/knowledge/read.ts +33 -10
- package/src/knowledge/schema.ts +37 -11
- package/src/knowledge/start-screen.ts +68 -0
- package/src/knowledge/text.ts +5 -2
- package/src/knowledge/write.ts +69 -30
- package/src/mcp/inputs.ts +12 -0
- package/src/mcp/server.ts +1 -1
- package/src/mcp/tools/input.ts +38 -5
- package/src/mcp/tools/machine.ts +3 -42
- package/src/mcp/tools/media.ts +1 -1
- package/src/native/acme.ts +1 -1
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +3 -3
- package/src/native/dxa.ts +12 -1
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +4 -4
- package/src/native/types.ts +2 -2
- package/src/platform.ts +30 -1
- package/src/project.ts +17 -4
- package/src/protocol/tools.ts +1 -45
- package/src/protocol/vice.ts +47 -0
- package/src/script.ts +3 -3
- package/src/vsf.ts +98 -0
- package/tools/c64run.c +9 -12
- package/tools/install-container.sh +1 -2
- package/src/cli/status.ts +0 -127
- package/src/host/tools/status.ts +0 -47
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/src/native/status.ts +0 -135
- package/tools/install-ghidra.sh +0 -40
|
@@ -34,7 +34,7 @@ To get the command list, run the script with no arguments.
|
|
|
34
34
|
| Save a module of the program as a routine of the library | `routine '$1000' --library ../library` |
|
|
35
35
|
| Save a range of the program as a routine with a name | `routine '$1000-$1026' --name play --library ../library` |
|
|
36
36
|
| Find the routines of the library in the program | `match --library ../library` |
|
|
37
|
-
| Write the names of the found routines
|
|
37
|
+
| Write the names of the found routines to the project knowledge | `match --library ../library --apply` |
|
|
38
38
|
|
|
39
39
|
---
|
|
40
40
|
|
|
@@ -86,7 +86,8 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
86
86
|
| `--min-block <n>` | `compare` | With `--align`: the minimum number of bytes in a block, from 8. The default is 16. |
|
|
87
87
|
| `--frames <n>` | `compare` | Run each release for `n` frames, and give each listed difference its runtime evidence. The default is no run. |
|
|
88
88
|
| `--steps <file>` | `compare` | With `--frames`: run the action steps of this file before the frames. The default is no steps. |
|
|
89
|
-
| `--out <file>` | `separate`, `leftovers
|
|
89
|
+
| `--out <file>` | `separate`, `leftovers` | Write all items to this file. The default is no file. |
|
|
90
|
+
| `--apply` | `match` | Write the changes to the project knowledge as one revision of the LLM. Without it, `match` writes nothing. |
|
|
90
91
|
| `--max-listed <n>` | `separate`, `leftovers`, `match` | List at most `n` items of each list. The default is 50. `count` always gives the full number. |
|
|
91
92
|
| `--min-text <n>` | `leftovers` | The minimum number of characters in a text, from 4. The default is 8. A short text, for example a group name, can need 6. |
|
|
92
93
|
| `--library <folder>` | `routine`, `match` | Required. The library folder. |
|
|
@@ -265,9 +266,9 @@ Finds each routine of the library in the program of the project knowledge.
|
|
|
265
266
|
- `library` and `routines`: the library folder and the number of routines in it.
|
|
266
267
|
- `matches`: each item has `routine`, `start`, `end` and `shift`. `shift` is the address in the program minus the address in the library.
|
|
267
268
|
- `differing` in each match: each operand that addresses something outside the routine and that is different. It gives the value in the `library` and in the `program`. Examine each one. For example, the program can use other variables or another SID voice.
|
|
268
|
-
- `
|
|
269
|
+
- `changes`: with matches. `writes` lists the writes for the project knowledge. `known` counts the writes that the project knowledge has already. `leftOut` lists the writes that the script left out, and why. `check` lists each comment of `writes` that gives an address outside its routine. Each item has `routine`, `address`, `comment` and the `outside` addresses. Such an address can be different in this program. With `--apply`, `revision` gives the revision of the changes.
|
|
269
270
|
|
|
270
|
-
The
|
|
271
|
+
The changes have the names, regions, comments, references and operand expressions of each routine at its address in the program. The script leaves out a write in these conditions:
|
|
271
272
|
|
|
272
273
|
- The program has a user or LLM row at that place.
|
|
273
274
|
- The program uses the name at another address.
|
|
@@ -275,14 +276,14 @@ The batch has the names, regions, comments, references and operand expressions o
|
|
|
275
276
|
- The routine occurs more than one time, and the script did not choose this copy.
|
|
276
277
|
- The script left out the name that an operand expression uses, or the expression does not give the operand in the program.
|
|
277
278
|
|
|
278
|
-
A routine can occur more than one time. Then the script finds the nearest routines before and after it in the library that occur only one time. The script writes the names at the copy that has the shift of one of these routines. If no copy or more than one copy has such a shift, the script writes no names for the routine. Then `
|
|
279
|
+
A routine can occur more than one time. Then the script finds the nearest routines before and after it in the library that occur only one time. The script writes the names at the copy that has the shift of one of these routines. If no copy or more than one copy has such a shift, the script writes no names for the routine. Then `changes.leftOut` gives each copy with the reason `ambiguous`.
|
|
279
280
|
|
|
280
|
-
An address `$xxxx` in a comment moves with the routine when the address is in the routine. An address outside the routine does not move, and `
|
|
281
|
+
An address `$xxxx` in a comment moves with the routine when the address is in the routine. An address outside the routine does not move, and `changes.check` gives the comment.
|
|
281
282
|
|
|
282
283
|
`hint` and `nextAction`:
|
|
283
284
|
|
|
284
|
-
- Without `--
|
|
285
|
-
-
|
|
285
|
+
- Without `--apply`, with writes: `nextAction` runs `match` with `--apply`. Examine `differing` of each match, `changes.writes` and `changes.leftOut` first.
|
|
286
|
+
- When `changes.check` has comments, `hint` tells you to examine them after the write. Correct each comment that is different in the project knowledge.
|
|
286
287
|
- No match: `hint` tells that a packed program can hold a routine in a packed form. Unpack the program, put it into the project knowledge, and run `match` again.
|
|
287
288
|
|
|
288
289
|
Traps:
|
|
@@ -333,8 +334,8 @@ Traps:
|
|
|
333
334
|
1. Put the program into the project knowledge, and name the routine there.
|
|
334
335
|
2. Run `routine`. Read `leftOut`.
|
|
335
336
|
3. In another project, put the program into the project knowledge. Run `match`.
|
|
336
|
-
4.
|
|
337
|
-
5.
|
|
337
|
+
4. Read `changes.writes` and `changes.leftOut`. Run `match` with `--apply`.
|
|
338
|
+
5. Examine the comments in `changes.check`. Correct each comment that is different in the project knowledge.
|
|
338
339
|
|
|
339
340
|
---
|
|
340
341
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// with one <name>.json for each routine, outside every project. A routine holds
|
|
3
3
|
// its bytes, which of its bytes move with it, and its knowledge at offsets from
|
|
4
4
|
// its start, so match finds it in another program at another address and
|
|
5
|
-
// suggests its names there as
|
|
5
|
+
// suggests its names there as writes of the knowledge. Nothing here writes knowledge.
|
|
6
6
|
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -468,7 +468,7 @@ export interface ProgramKnowledge {
|
|
|
468
468
|
referenceSuppressed: (reference: { from: number; to: number; kind: ReferenceKind }) => boolean;
|
|
469
469
|
}
|
|
470
470
|
|
|
471
|
-
/** One
|
|
471
|
+
/** One change of match, as the result shows it: a write of the knowledge with its addresses as $ text. */
|
|
472
472
|
export type BatchWrite = Record<string, string | number> & { op: string };
|
|
473
473
|
|
|
474
474
|
export interface Skipped {
|
|
@@ -478,7 +478,7 @@ export interface Skipped {
|
|
|
478
478
|
reason: string;
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
-
/** A comment of the
|
|
481
|
+
/** A comment of the changes that names an address outside its routine: that address can be different in the program. */
|
|
482
482
|
export interface Check {
|
|
483
483
|
routine: string;
|
|
484
484
|
address: string;
|
|
@@ -487,7 +487,7 @@ export interface Check {
|
|
|
487
487
|
}
|
|
488
488
|
|
|
489
489
|
export interface Suggestions {
|
|
490
|
-
|
|
490
|
+
writes: BatchWrite[];
|
|
491
491
|
/** Writes that the program already has. */
|
|
492
492
|
known: number;
|
|
493
493
|
leftOut: Skipped[];
|
|
@@ -554,7 +554,7 @@ function movedComment(text: string, routine: Routine, shift: number): { text: st
|
|
|
554
554
|
|
|
555
555
|
/**
|
|
556
556
|
* The names, regions, comments, references and operand expressions of each
|
|
557
|
-
* matched routine at its program addresses, as
|
|
557
|
+
* matched routine at its program addresses, as writes of the knowledge. A write that
|
|
558
558
|
* the program already has is counted as known. A write that would replace a
|
|
559
559
|
* user or LLM row, take a name that the program uses elsewhere, undo a
|
|
560
560
|
* removal, or give an operand that is not in the image, is left out with the
|
|
@@ -564,12 +564,12 @@ function movedComment(text: string, routine: Routine, shift: number): { text: st
|
|
|
564
564
|
* is in `check`.
|
|
565
565
|
*/
|
|
566
566
|
export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[] }>, program: ProgramKnowledge, image: Searched, platform: ReadonlyMap<string, number>): Suggestions {
|
|
567
|
-
const
|
|
567
|
+
const writes: BatchWrite[] = [];
|
|
568
568
|
const leftOut: Skipped[] = [];
|
|
569
569
|
const check: Check[] = [];
|
|
570
570
|
let known = 0;
|
|
571
571
|
const show = formatC64Address;
|
|
572
|
-
/** The names that are at their place after the
|
|
572
|
+
/** The names that are at their place after the changes: written here or known. */
|
|
573
573
|
const placed = new Map<string, number>();
|
|
574
574
|
const symbolsHere = new Map<number, string>();
|
|
575
575
|
const regionsHere: Array<{ start: number; end: number }> = [];
|
|
@@ -591,11 +591,11 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
|
|
|
591
591
|
placed.set(symbol.name, address);
|
|
592
592
|
} else if (existing !== undefined && semantic(existing)) skip(address, "rename", `the program names it ${existing.name} (${existing.origin})`);
|
|
593
593
|
else if (elsewhere !== undefined && elsewhere.address !== address) skip(address, "rename", `the program uses the name ${symbol.name} at ${show(elsewhere.address)}`);
|
|
594
|
-
else if (placed.has(symbol.name) && placed.get(symbol.name) !== address) skip(address, "rename", `the
|
|
595
|
-
else if (symbolsHere.has(address)) skip(address, "rename", `the
|
|
594
|
+
else if (placed.has(symbol.name) && placed.get(symbol.name) !== address) skip(address, "rename", `the changes give the name ${symbol.name} to ${show(placed.get(symbol.name)!)}`);
|
|
595
|
+
else if (symbolsHere.has(address)) skip(address, "rename", `the changes name it ${symbolsHere.get(address)}`);
|
|
596
596
|
else if (program.symbolSuppressed(address)) skip(address, "rename", "a removal of a name holds there");
|
|
597
597
|
else {
|
|
598
|
-
|
|
598
|
+
writes.push({ op: "rename", address: show(address), name: symbol.name, kind: symbol.kind });
|
|
599
599
|
placed.set(symbol.name, address);
|
|
600
600
|
symbolsHere.set(address, symbol.name);
|
|
601
601
|
}
|
|
@@ -609,10 +609,10 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
|
|
|
609
609
|
else if (overlapping.some(semantic)) {
|
|
610
610
|
const other = overlapping.find(semantic)!;
|
|
611
611
|
skip(start, "classify", `the program has the ${other.type} region ${show(other.start)}-${show(other.end)} (${other.origin})`);
|
|
612
|
-
} else if (regionsHere.some((item) => item.start <= end && item.end >= start)) skip(start, "classify", "the
|
|
612
|
+
} else if (regionsHere.some((item) => item.start <= end && item.end >= start)) skip(start, "classify", "the changes classify an overlapping range");
|
|
613
613
|
else if (program.regionSuppressed(start, end)) skip(start, "classify", "a removal of a region holds there");
|
|
614
614
|
else {
|
|
615
|
-
|
|
615
|
+
writes.push({ op: "classify", start: show(start), end: show(end), type: region.type, ...(region.element === undefined ? {} : { element: region.element }) });
|
|
616
616
|
regionsHere.push({ start, end });
|
|
617
617
|
}
|
|
618
618
|
}
|
|
@@ -624,7 +624,7 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
|
|
|
624
624
|
if (existing?.text === text) known++;
|
|
625
625
|
else if (existing !== undefined) skip(address, "comment", `the program has a ${comment.placement} comment there (${existing.origin})`);
|
|
626
626
|
else {
|
|
627
|
-
|
|
627
|
+
writes.push({ op: "comment", address: show(address), placement: comment.placement, text });
|
|
628
628
|
if (outside.length > 0) check.push({ routine: routine.name, address: show(address), comment: text, outside });
|
|
629
629
|
}
|
|
630
630
|
}
|
|
@@ -633,7 +633,7 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
|
|
|
633
633
|
const wanted = { from: at(reference.from), to: at(reference.to), kind: reference.kind };
|
|
634
634
|
if (program.referencesFrom(wanted.from).some((item) => item.to === wanted.to && item.kind === wanted.kind)) known++;
|
|
635
635
|
else if (program.referenceSuppressed(wanted)) skip(wanted.from, "reference", "a removal of this reference holds");
|
|
636
|
-
else
|
|
636
|
+
else writes.push({ op: "reference", from: show(wanted.from), to: show(wanted.to), kind: wanted.kind });
|
|
637
637
|
}
|
|
638
638
|
|
|
639
639
|
const own = new Set(routine.symbols.map((symbol) => symbol.name));
|
|
@@ -660,7 +660,7 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
|
|
|
660
660
|
skip(address, "operand", problem);
|
|
661
661
|
continue;
|
|
662
662
|
}
|
|
663
|
-
|
|
663
|
+
writes.push({
|
|
664
664
|
op: "operand",
|
|
665
665
|
address: show(address),
|
|
666
666
|
select: operand.select,
|
|
@@ -670,7 +670,7 @@ export function suggest(found: ReadonlyArray<{ routine: Routine; matches: Match[
|
|
|
670
670
|
});
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
|
-
return {
|
|
673
|
+
return { writes, known, leftOut, check };
|
|
674
674
|
}
|
|
675
675
|
|
|
676
676
|
/** Why the expression is not the operand of the instruction at `address` in the image, or undefined when it is. */
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { basename } from "node:path";
|
|
12
12
|
|
|
13
|
-
import { type AddressRange, c64AddressOf, formatC64Address } from "#src/c64.ts";
|
|
13
|
+
import { type AddressRange, c64AddressOf, formatC64Address, parseC64Address } from "#src/c64.ts";
|
|
14
14
|
import { Refusal } from "#src/errors.ts";
|
|
15
15
|
import { parseEntryState, type EntryState } from "#src/host-client/entry-state.ts";
|
|
16
16
|
import { readImage } from "#src/host-client/image.ts";
|
|
@@ -18,8 +18,9 @@ import { readActionSteps, type ActionStep } from "#src/host-client/steps.ts";
|
|
|
18
18
|
import { MAX_EXECUTION_COUNT } from "#src/host-client/tools.ts";
|
|
19
19
|
import { writeReported } from "#src/host-client/transfer.ts";
|
|
20
20
|
import { ViceSessionClient } from "#src/host-client/vice-session.ts";
|
|
21
|
-
import { openForRead } from "#src/knowledge/database.ts";
|
|
22
|
-
import { programCoverage, requireProgram } from "#src/knowledge/program.ts";
|
|
21
|
+
import { openForRead, withWrite } from "#src/knowledge/database.ts";
|
|
22
|
+
import { operandImages, programCoverage, requireProgram } from "#src/knowledge/program.ts";
|
|
23
|
+
import { applyBatch, type BatchOperation } from "#src/knowledge/write.ts";
|
|
23
24
|
import {
|
|
24
25
|
commentsAt,
|
|
25
26
|
currentRevision,
|
|
@@ -38,13 +39,13 @@ import {
|
|
|
38
39
|
symbolNamed,
|
|
39
40
|
symbolSuppressed,
|
|
40
41
|
} from "#src/knowledge/read.ts";
|
|
41
|
-
import { CODE_REGION_TYPES, SEMANTIC_ORIGINS } from "#src/knowledge/schema.ts";
|
|
42
|
+
import { CODE_REGION_TYPES, DEFAULT_SPACE, SEMANTIC_ORIGINS } from "#src/knowledge/schema.ts";
|
|
42
43
|
import { platformNames } from "#src/platform.ts";
|
|
43
44
|
import { projectRoot } from "#src/project.ts";
|
|
44
45
|
import { knowledgeAt, knowledgeNames } from "#src/knowledge/names.ts";
|
|
45
46
|
import { listed, OPTIONS, reply, runScript, UsageError, type Call, type CommandSpec } from "#src/script.ts";
|
|
46
47
|
import { align, compareReleases, identicalShare, shiftSuggestion, suggestShifts, type Release } from "./lib/compare.ts";
|
|
47
|
-
import { findRoutine, libraryFolder, readLibrary, routineFrom, saveRoutine, suggest } from "./lib/library.ts";
|
|
48
|
+
import { findRoutine, libraryFolder, readLibrary, routineFrom, saveRoutine, suggest, type BatchWrite } from "./lib/library.ts";
|
|
48
49
|
import { watchRelease, type Start } from "./lib/runtime.ts";
|
|
49
50
|
import { findLeftovers } from "./lib/leftovers.ts";
|
|
50
51
|
import { separate, type Root } from "#src/knowledge/separate.ts";
|
|
@@ -462,10 +463,14 @@ function routineCommand(call: Call): unknown {
|
|
|
462
463
|
}
|
|
463
464
|
}
|
|
464
465
|
|
|
465
|
-
/**
|
|
466
|
+
/**
|
|
467
|
+
* match: finds the routines of the library in the program of the knowledge,
|
|
468
|
+
* and shows the changes that give the program their names. With --apply it
|
|
469
|
+
* writes the changes to the knowledge as one revision.
|
|
470
|
+
*/
|
|
466
471
|
function matchCommand(call: Call): unknown {
|
|
467
472
|
const library = call.string("library")!;
|
|
468
|
-
const
|
|
473
|
+
const apply = call.flag("apply");
|
|
469
474
|
const max = call.count("max-listed")!;
|
|
470
475
|
const list = <T>(items: T[]) => listed(items, max);
|
|
471
476
|
const routines = readLibrary(libraryFolder(library, { create: false, cwd: projectRoot() }));
|
|
@@ -493,13 +498,7 @@ function matchCommand(call: Call): unknown {
|
|
|
493
498
|
const result: Record<string, unknown> = { library, routines: routines.length, matches: list(matches) };
|
|
494
499
|
const noMatch = "No routine of the library is in the program. A packed program can hold a routine in a packed form. Unpack the program, put the unpacked program into the project knowledge, and run match again.";
|
|
495
500
|
const withNote = (shown: unknown, hint: string) => [cutNote(shown, undefined), hint].filter((part) => part !== undefined).join(" ");
|
|
496
|
-
if (
|
|
497
|
-
if (matches.length === 0) return reply(result, { hint: noMatch });
|
|
498
|
-
return reply(result, {
|
|
499
|
-
hint: withNote(result, "Examine differing of each match. Then nextAction writes the names of the found routines as a batch of changes."),
|
|
500
|
-
nextAction: call.next("match", "--library", library, "--out", ".c64-re-tools/local/match.json"),
|
|
501
|
-
});
|
|
502
|
-
}
|
|
501
|
+
if (matches.length === 0) return reply(result, { hint: noMatch });
|
|
503
502
|
const db = openForRead();
|
|
504
503
|
let suggestions: ReturnType<typeof suggest>;
|
|
505
504
|
try {
|
|
@@ -522,14 +521,25 @@ function matchCommand(call: Call): unknown {
|
|
|
522
521
|
} finally {
|
|
523
522
|
db?.close();
|
|
524
523
|
}
|
|
525
|
-
const {
|
|
526
|
-
const
|
|
527
|
-
const body = { ...result,
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
if (
|
|
531
|
-
|
|
532
|
-
|
|
524
|
+
const { writes, known, leftOut, check } = suggestions;
|
|
525
|
+
const changes: Record<string, unknown> = { writes: list(writes), known, leftOut: list(leftOut), check: list(check) };
|
|
526
|
+
const body = { ...result, changes };
|
|
527
|
+
if (writes.length === 0) return reply(body, { hint: withNote(body, "There are no changes. The project knowledge has the names of the found routines already, or changes.leftOut tells why the script left out a write.") });
|
|
528
|
+
const review = check.length === 0 ? "" : " Then examine changes.check: each comment there gives an address outside its routine, which can be different in this program. Correct such a comment in the project knowledge.";
|
|
529
|
+
if (!apply) {
|
|
530
|
+
return reply(body, { hint: withNote(body, `Examine differing of each match, and changes.writes and changes.leftOut. Then nextAction writes the changes to the project knowledge.${review}`), nextAction: call.next("match", "--library", library, "--apply") });
|
|
531
|
+
}
|
|
532
|
+
const platformNamed = new Map(platformNames().map((entry) => [entry.name, entry.address]));
|
|
533
|
+
const applied = withWrite((write) => applyBatch(write, { origin: "llm", description: `Names of the routines of the library ${library}`, image: operandImages(write, platformNamed) }, writes.map(toOperation)));
|
|
534
|
+
changes.revision = applied.revision;
|
|
535
|
+
return reply(body, { hint: withNote(body, `The project knowledge has the changes in revision ${applied.revision}.${review}`) });
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** A change of match as a write of the knowledge: its addresses as numbers, in the C64 space. */
|
|
539
|
+
function toOperation(write: BatchWrite): BatchOperation {
|
|
540
|
+
const parsed: Record<string, unknown> = { ...write, space: DEFAULT_SPACE };
|
|
541
|
+
for (const key of ["address", "start", "end", "from", "to"]) if (typeof write[key] === "string") parsed[key] = parseC64Address(write[key]);
|
|
542
|
+
return parsed as unknown as BatchOperation;
|
|
533
543
|
}
|
|
534
544
|
|
|
535
545
|
const LIBRARY = { kind: "text", value: "<folder>", required: true, help: "the library: a plain folder of routine files beside the projects, relative to the project folder, for example ../library" } as const;
|
|
@@ -589,7 +599,7 @@ const COMMANDS: CommandSpec[] = [
|
|
|
589
599
|
summary: "Finds each routine of the library in the program of the knowledge: the opcodes and other fixed bytes equal, and the addresses into the routine moved by one shift.",
|
|
590
600
|
options: {
|
|
591
601
|
library: { ...LIBRARY, help: "the library folder, relative to the project folder, for example ../library" },
|
|
592
|
-
|
|
602
|
+
apply: { kind: "flag", help: "write the changes to the project knowledge as one revision of the LLM. Without it, the result only shows the changes" },
|
|
593
603
|
"max-listed": OPTIONS["max-listed"],
|
|
594
604
|
},
|
|
595
605
|
run: matchCommand,
|
|
@@ -27,7 +27,7 @@ Do the specialist work of each task as that task tells. Do not do it in another
|
|
|
27
27
|
- One repository can hold several programs, with one project folder for each program. Work on one project at a time.
|
|
28
28
|
- Write all files in the project folder. Do not write files at the root of the repository.
|
|
29
29
|
- A subagent can have no emulator tools. Give it its experiments as test run files. Many test runs can go at the same time. The emulator tools are for the main session only.
|
|
30
|
-
- To name a large program with more agents at the same time, give each agent one range of addresses. Each agent writes a batch of knowledge changes with its owner range. Then join the batches of the agents, and
|
|
30
|
+
- To name a large program with more agents at the same time, give each agent one range of addresses. Each agent writes a batch of knowledge changes with its owner range. Then join the batches of the agents, and write them to the project knowledge as one revision.
|
|
31
31
|
- Do not write a build script or a merge script. The generation of the source writes and assembles the loader. The project knowledge joins the batches.
|
|
32
32
|
- Do not write a script that makes a deliverable again, for example a capture, copy or replay script. Commit the deliverable.
|
|
33
33
|
|
|
@@ -37,7 +37,7 @@ These rules apply to each rebuild:
|
|
|
37
37
|
|
|
38
38
|
- Do not keep a cracktro. A capture of a packed program starts at the last stage, so the code of a cracktro is not in the program. When the capture has data of a cracktro that the program does not read, capture again and exclude that range.
|
|
39
39
|
- Keep the start screen of the program, for example the loading picture of the publisher. Keep its bytes in the capture, and record the start screen in the project knowledge. The loader of the rebuild then shows it and waits for a key or a fire button. Do not keep a screen of a crack, for example a picture, an intro or a credit screen of a crack group.
|
|
40
|
-
- When the start screen is only in a stage of the loading, capture that stage while it shows the screen. Put the capture into the project knowledge in
|
|
40
|
+
- When the start screen is only in a stage of the loading, capture that stage while it shows the screen. Put the capture into the project knowledge in the space `loading`. Then record the start screen of that stage. Keep its tune: record the routine that starts the tune as the call of the start screen.
|
|
41
41
|
- A release can change the start screen, for example with the text of a crack. Then stop and ask the user how to deal with it. Do not decide alone.
|
|
42
42
|
- Keep all other bytes: unused bytes, dead code, old copies, texts and leftovers of the development. Record each one as a region with a comment. Do not remove them. The source keeps them, and the build of each release has them. The default build and the loader do not have them.
|
|
43
43
|
- Do not write a file of the rebuild by hand, for example a boot file, a packed picture or a script that changes bytes. Record each change in the project knowledge, and generate the source.
|
|
@@ -85,30 +85,36 @@ Do the stages in this sequence. Go to the next stage only when its exit check is
|
|
|
85
85
|
|
|
86
86
|
| Stage | Work | Exit check |
|
|
87
87
|
|---|---|---|
|
|
88
|
-
| 1. Acceptance | Ask the user for the criteria of the rebuild. Offer these criteria:
|
|
88
|
+
| 1. Acceptance | Ask the user for the criteria of the rebuild. Offer these criteria: a base release that is identical to the original, and a passed replay of the default build. Also offer a replay of each recording, test scenarios and a list of the code that no run executed. Also offer documentation of the flows, tables, formats and graphics. | The user gave the criteria. |
|
|
89
89
|
| 2. Get | List the disk image. Extract the start file into `original/`. | The start file is in the project. |
|
|
90
90
|
| 3. Start | Find the SYS address of the BASIC start. | You have the entry address. |
|
|
91
91
|
| 4. Unpack | Examine the program for a packer. Trace it and find its stages. Capture a packed program into `.c64-re-tools/local/`. When a segment is the data of a cracktro and the program does not read it, capture again and exclude that range. Put the capture, or the PRG of a program without a packer, into the project knowledge. | The program in the project knowledge has the segments and the entry. |
|
|
92
92
|
| 5. Run | First, record. Ask the user to play each part that the scope names, in a recording session. Tell the user which parts. Record a part yourself only when the sessions of the user do not have it. Put the recordings in `tests/recordings/`. Then run the parts that a recording cannot have, in the emulator or as test runs. Write a coverage map for each part into `.c64-re-tools/local/`. Add the maps and the `coverage.bin` of each recording to the project knowledge. | The program in the project knowledge has a coverage map for each part that the scope names. |
|
|
93
93
|
| 6. Analyze | Analyze the program statically. The analysis reads the program and the coverage from the project knowledge. | No coverage conflict is open. |
|
|
94
|
-
| 7. Name | If the workspace has a routine library, match the program against it.
|
|
95
|
-
| 8. Releases and switches |
|
|
96
|
-
| 9. Generate | Generate the source from the project knowledge into `src`. For an unpacked program, also generate the loader. | The result of the generation is PASS.
|
|
97
|
-
| 10. Build and test | Build the base release into `build/`, and compare it with the original. Build the default build.
|
|
94
|
+
| 7. Name | If the workspace has a routine library, match the program against it. Write the names of the matches to the project knowledge. Then name each routine in the scope and give it a comment. Find the platform addresses in the memory map of the C64. Record the modules. Put the modules of one part of the program in one folder, for example `music/`, `irq/` or `graphics/`. When the scope has hundreds of routines, ask the user which routines to name. The source gives the other routines an `l_xxxx` label. | Each routine that the user selected has a name and a comment. |
|
|
95
|
+
| 8. Releases and switches | Record the original file, or the capture of it, as the base release in the project knowledge. The project knowledge keeps the bytes of each release. Record each other release. Compare the releases. Find the leftovers. Record a switch for each copy protection, trainer, cheat, crack change and correction. Record a patch for each range of a switch. Record each leftover as a region with a comment. | The project knowledge lists each switch. Each difference between the releases is in a patch, or the answer gives it as an exception. |
|
|
96
|
+
| 9. Generate | Generate the source from the project knowledge into `src`. For an unpacked program, also generate the loader. | The result of the generation is PASS. A release whose code is at other addresses is a version with a project of its own, or an exception in the answer. See "Versions of one program". |
|
|
97
|
+
| 10. Build and test | Build the base release into `build/`, and compare it with the original. Build the default build. Replay one recording on the default build. For each replay, give the checkpoint routine, the state and the random state with the names of stage 7. Then do only the tests that the next paragraph gives. | The criteria of stage 1 are true. |
|
|
98
98
|
| 11. Document | When the criteria ask for documentation, generate it into `README.md` and `docs/`. For versions in a group folder, also write the shared pages of the group folder. Then link the pages. | The link check of the documentation gives PASS. |
|
|
99
99
|
| 12. Hand over | Find each file that you made outside `.c64-re-tools/local/` and that is not a deliverable. Move it into `.c64-re-tools/local/`. Then give the answer (below). | Each file that you made outside `.c64-re-tools/local/` is a deliverable. |
|
|
100
100
|
|
|
101
101
|
In stage 5, make the recordings before you change the program. A recording needs no names, and its coverage gives the analysis of stage 6 more code. If you cannot get to a part of the program, ask the user how to get to it. Do stages 7 to 9 again until the source is clear. Each generation writes the source again.
|
|
102
102
|
|
|
103
|
+
In stage 10, a base release that is identical to the original proves the source. Do not test the base release more. The default build is different from the base release only in its patches, its leftovers and its loader. Thus test only these differences:
|
|
104
|
+
|
|
105
|
+
- When a patch of the default build changes code that a run executed, replay each recording of the part that has that code. A copy protection check is an example.
|
|
106
|
+
- Write a test scenario only for a test that a replay cannot do. Examples are a program that loads more files from a disk, and a criterion of the user.
|
|
107
|
+
- Do the other tests of stage 1 only when the user selected them.
|
|
108
|
+
|
|
103
109
|
After stage 7, save each routine that other programs can have to the routine library of the workspace. Examples are a music driver, a decruncher and a loader. Ask the user before you make a library.
|
|
104
110
|
|
|
105
111
|
### Deliverables of a full rebuild
|
|
106
112
|
|
|
107
113
|
- `.c64-re-tools/knowledge/` with the program, its entry state, the coverage, the names, the regions, the comments, the modules, the releases, the switches and the patches
|
|
108
|
-
- the
|
|
114
|
+
- the files of the program in `original/`, as the user gave them
|
|
109
115
|
- the generated source
|
|
110
116
|
- the built program and the loader
|
|
111
|
-
- the test scenarios
|
|
117
|
+
- the test scenarios, if you wrote them
|
|
112
118
|
- the recordings in `tests/recordings/`
|
|
113
119
|
- the documentation in `README.md` and `docs/`, when the criteria ask for it
|
|
114
120
|
- the runs in `runs/` that the knowledge gives as evidence
|
|
@@ -121,7 +127,7 @@ All other files that you made are not deliverables. Keep them in `.c64-re-tools/
|
|
|
121
127
|
Give the user a short answer at the end. Do not write a report file. Write a report file only when the user asks for it. The knowledge, `docs/` and the scenarios keep the durable results. The answer has:
|
|
122
128
|
|
|
123
129
|
1. Each criterion of stage 1 and its result, and each exception that the user accepted.
|
|
124
|
-
2. The count of the code ranges that no run executed. The ranges are in
|
|
130
|
+
2. The count of the code ranges that no run executed. The ranges are in `.c64-re-tools/local/generated/src/not_executed.json` for the source in `src/`.
|
|
125
131
|
3. The switches: the name, the kind and the default of each, and the releases that have it on. Also a copy protection that a crack removed and that no release has.
|
|
126
132
|
4. Open questions: what the evidence does not explain.
|
|
127
133
|
|
|
@@ -142,7 +148,7 @@ tools/ scripts for the formats of this program only
|
|
|
142
148
|
README.md the entry page of the documentation
|
|
143
149
|
```
|
|
144
150
|
|
|
145
|
-
Commit each folder of the layout other than `build/`, and `.c64-re-tools/knowledge/`. The knowledge holds the program, the entry state and the coverage, so the project needs no other folder for them. Put all other files that you make in `.c64-re-tools/local/`, also the captures and the coverage maps after you put them into the knowledge. Do not let git ignore a folder of the layout other than `build/`. Do not change the `.gitignore` files of the project.
|
|
151
|
+
Commit each folder of the layout other than `build/`, and `.c64-re-tools/knowledge/`. The knowledge holds the program, the entry state, the bytes of each release and the coverage, so the project needs no other folder for them. Put all other files that you make in `.c64-re-tools/local/`, also the captures and the coverage maps after you put them into the knowledge. Do not let git ignore a folder of the layout other than `build/`. Do not change the `.gitignore` files of the project.
|
|
146
152
|
|
|
147
153
|
If the project has a layout, use that layout.
|
|
148
154
|
|