@henols/c64-re-tools 2.6.0-rc.4 → 2.6.0-rc.6
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 +2 -2
- package/skills/c64-assembler/scripts/assembler.ts +4 -5
- package/skills/c64-development/SKILL.md +1 -1
- package/skills/c64-docs/SKILL.md +4 -4
- package/skills/c64-docs/scripts/docs.ts +3 -3
- 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 +26 -17
- package/skills/c64-knowledge/scripts/knowledge.ts +26 -41
- 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 +6 -6
- package/skills/c64-source/SKILL.md +15 -15
- package/skills/c64-source/scripts/lib/source.ts +9 -9
- package/skills/c64-source/scripts/source.ts +79 -65
- package/skills/c64-static-analysis/SKILL.md +4 -4
- package/skills/c64-static-analysis/scripts/static-analysis.ts +26 -33
- package/src/build-name.ts +3 -0
- package/src/knowledge/program.ts +44 -1
- package/src/knowledge/read.ts +3 -7
- package/src/knowledge/schema.ts +33 -9
- package/src/knowledge/text.ts +4 -2
- package/src/knowledge/write.ts +47 -14
- package/src/project.ts +13 -1
|
@@ -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
|
|
|
@@ -91,8 +91,8 @@ Do the stages in this sequence. Go to the next stage only when its exit check is
|
|
|
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 |
|
|
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
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. Each release with the result `layout differs` is a version with a project of its own, or an exception in the answer. See "Versions of one program". |
|
|
97
97
|
| 10. Build and test | Build the base release into `build/`, and compare it with the original. Build the default build. Run the test scenarios in `tests/`. Replay each recording on the rebuild. For each replay, give the checkpoint routine, the state and the random state with the names of stage 7. | 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. |
|
|
@@ -105,7 +105,7 @@ After stage 7, save each routine that other programs can have to the routine lib
|
|
|
105
105
|
### Deliverables of a full rebuild
|
|
106
106
|
|
|
107
107
|
- `.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
|
|
108
|
+
- the files of the program in `original/`, as the user gave them
|
|
109
109
|
- the generated source
|
|
110
110
|
- the built program and the loader
|
|
111
111
|
- the test scenarios
|
|
@@ -121,7 +121,7 @@ All other files that you made are not deliverables. Keep them in `.c64-re-tools/
|
|
|
121
121
|
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
122
|
|
|
123
123
|
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
|
|
124
|
+
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
125
|
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
126
|
4. Open questions: what the evidence does not explain.
|
|
127
127
|
|
|
@@ -142,7 +142,7 @@ tools/ scripts for the formats of this program only
|
|
|
142
142
|
README.md the entry page of the documentation
|
|
143
143
|
```
|
|
144
144
|
|
|
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.
|
|
145
|
+
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
146
|
|
|
147
147
|
If the project has a layout, use that layout.
|
|
148
148
|
|
|
@@ -72,7 +72,7 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
72
72
|
|
|
73
73
|
| Flag | Command | Effect |
|
|
74
74
|
|---|---|---|
|
|
75
|
-
| `--out <dir>` | `generate` | The folder for the source files. It is necessary. The script writes over the files of an earlier run. It removes a generated `.asm` file that this run does not write. A run without `--loader` keeps `loader.asm`, the loader program, `start_screen.asm` and `start_screen_stage.asm` of an earlier run. `staleLoader` tells when they are of another knowledge revision. |
|
|
75
|
+
| `--out <dir>` | `generate` | The folder for the source files. It is necessary. The script writes over the files of an earlier run. It removes a generated `.asm` file that this run does not write, also in a folder of `--out`. A folder with a generated `main.asm` is the source of another space, and it stays. A run without `--loader` keeps `loader.asm`, the loader program, `start_screen.asm` and `start_screen_stage.asm` of an earlier run. `staleLoader` tells when they are of another knowledge revision. |
|
|
76
76
|
| `--entry <address>` | `generate` | An address where code starts. Give the flag again for more addresses. There is no default. |
|
|
77
77
|
| `--space <space>` | `generate` | The knowledge space: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. `--loader` and the platform names apply only to `c64`. The coverage is the coverage of the space. |
|
|
78
78
|
| `--loader` | `generate` | Also write `loader.asm` and the loader program, and `start_screen.asm` when the knowledge has a start screen. A start screen of a captured stage also gives `start_screen_stage.asm`. The script writes the loader program only after the check of the new loader ran. Else the loader program of an earlier run stays. It needs a capture in the knowledge. The default is no loader. |
|
|
@@ -89,7 +89,8 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
89
89
|
|
|
90
90
|
### `generate --out <dir>`
|
|
91
91
|
|
|
92
|
-
The command writes the source files
|
|
92
|
+
The command writes the source files in `--out`. Then it checks them.
|
|
93
|
+
The folder `--out` gets only source files. The command writes `source-map.json` and `not_executed.json` in `.c64-re-tools/local/generated/<dir>/`. Git ignores this folder.
|
|
93
94
|
The same knowledge always gives the same source.
|
|
94
95
|
Do not edit the generated files. The next run writes over them. The values in `config.asm` are the one exception.
|
|
95
96
|
To make the source better, change the project knowledge. Then generate again.
|
|
@@ -97,7 +98,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
97
98
|
`body` holds these fields:
|
|
98
99
|
|
|
99
100
|
- `result`: `PASS` when every check passes, else `FAIL`.
|
|
100
|
-
- `files`: the files
|
|
101
|
+
- `files`: the files that the command wrote, each with `out`, `bytes` and `sha256`. `sourceMap` names `source-map.json`.
|
|
101
102
|
- `removed`: the files of an earlier run that the script removed.
|
|
102
103
|
- `instructions`, `dataBytes` and `undecodedBytes`.
|
|
103
104
|
- `labels`: `named` labels from the knowledge, and `generated` labels `l_xxxx`.
|
|
@@ -126,7 +127,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
126
127
|
- The entry is in no segment of the program.
|
|
127
128
|
- A patch is in `patchesNotWritten`.
|
|
128
129
|
- A switch or the default build does not fit.
|
|
129
|
-
- A release does not give its
|
|
130
|
+
- A release does not give its bytes. A release with `layout differs` does not give `FAIL`. But the base release must be `identical`.
|
|
130
131
|
- The loader is not verified.
|
|
131
132
|
|
|
132
133
|
`hint` gives the action for each finding. When a change of the project knowledge corrects a finding, `nextAction` is the same `generate` command. Run it after the change. A `PASS` without findings gives a `hint` and no `nextAction`.
|
|
@@ -151,7 +152,7 @@ Do these actions for the findings:
|
|
|
151
152
|
#### The source files
|
|
152
153
|
|
|
153
154
|
- `main.asm` sets the address of each segment. It includes the files in address order.
|
|
154
|
-
- Each module in the knowledge is one file. A module starts at its address. It stops at the next module or at the end of its segment. Without modules, each segment is one file, `segment_xxxx.asm`.
|
|
155
|
+
- Each module in the knowledge is one file. A module starts at its address. It stops at the next module or at the end of its segment. The file of a module can be in a folder, for example `music/driver.asm`. Without modules, each segment is one file, `segments/segment_xxxx.asm`.
|
|
155
156
|
- `constants.asm` holds the names of addresses outside the program, for example `EXTCOL = $d020`. It also holds the register names in the program, for example `RASTER = $d012`. The names are in groups by memory area, in address order. Drive code and banks have one group only.
|
|
156
157
|
- The side comment of a constant is the knowledge comment of the address. Without a comment, it is the platform meaning. When the knowledge name is not the platform name, the platform name comes first. For an I/O mirror without a meaning, the comment gives the register that the mirror repeats.
|
|
157
158
|
- After the side comment, `Used:` counts how the source uses the name. The kinds are `read`, `written`, `modified`, `called`, `jumped to`, `jumped through`, `branched to`, `pointer`, `address`, `table` and `macro argument`. `address` is an immediate operand expression. `table` is an entry in a table of addresses.
|
|
@@ -160,7 +161,7 @@ Do these actions for the findings:
|
|
|
160
161
|
- When the knowledge has a start screen, `config.asm` also has `START_SCREEN = 1`. Set it to 0 to start the program at once. Then assemble `loader.asm` again.
|
|
161
162
|
- `start_screen.asm` is the code that shows the start screen and waits. It is the same for each program. `loader.asm` gives it the values of the start screen.
|
|
162
163
|
- `switches.asm` holds each release of the knowledge. `main.asm` and `loader.asm` include it first. The script writes it only when the knowledge has switches or releases, or when the source has leftovers. For each release, a block `!ifdef RELEASE_<label>` gives each switch the value of that release.
|
|
163
|
-
- `leftover_xxxx.asm` holds a range of leftovers. See "The leftovers".
|
|
164
|
+
- `leftovers/leftover_xxxx.asm` holds a range of leftovers. See "The leftovers".
|
|
164
165
|
- `macros.asm` holds the macros of the knowledge. `main.asm` and `loader.asm` include it.
|
|
165
166
|
|
|
166
167
|
#### Names in the source
|
|
@@ -196,10 +197,10 @@ Do these actions for the findings:
|
|
|
196
197
|
|
|
197
198
|
A leftover is a range of the program that nothing uses: unused code, old copies and old data. The script finds the leftovers from the coverage, as the export finds its free ranges (see "The free ranges"). The start screen, the patches, the macro uses and the addresses that the code of a patch names are never leftovers.
|
|
198
199
|
|
|
199
|
-
- Each range of leftovers is a file `leftover_xxxx.asm`. When a range cuts a module, the module continues after the range in `<module>_xxxx.asm
|
|
200
|
+
- Each range of leftovers is a file `leftovers/leftover_xxxx.asm`. When a range cuts a module, the module continues after the range in `<module>_xxxx.asm`, in the folder of the module. The module in the knowledge does not change.
|
|
200
201
|
- `main.asm` builds a leftover file only when `LEFTOVERS` is 1. When it is 0, the build skips the bytes. Thus the addresses after the range do not change.
|
|
201
202
|
- `config.asm` has `LEFTOVERS = 0`. Thus the default build is the clean program, without the leftovers.
|
|
202
|
-
- Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of
|
|
203
|
+
- Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of the release.
|
|
203
204
|
- The loader program never has the leftovers. The loader does not copy them, and the memory there keeps the bytes that were in it before.
|
|
204
205
|
- Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
|
|
205
206
|
- When `leftovers.changed` has ranges, the default build and the loader program now leave out other bytes. A test that observes the `added` bytes on the loader program gets other values there. Fill the `added` ranges in the test of the leftovers. In a test that compares them, exclude them with the reason that they are leftovers.
|
|
@@ -214,7 +215,7 @@ The command does these checks. They use the defaults and the values of the knowl
|
|
|
214
215
|
1. `check`: the build of the base release must give the program byte by byte. In this build, each switch has its base value, and `LEFTOVERS` is 1.
|
|
215
216
|
2. `switches`: each switch alone at its other value. The build must have the same length as the base release. It can change bytes only in the patches of the switch.
|
|
216
217
|
3. `default`: the default build. It must have the same length. It can change bytes only in the patches of the switches in `default.in` and in the leftovers.
|
|
217
|
-
4. `releases`: each release, built with `RELEASE_<label>=1`, against the
|
|
218
|
+
4. `releases`: each release, built with `RELEASE_<label>=1`, against the bytes of the release in the project knowledge.
|
|
218
219
|
|
|
219
220
|
Each item of `switches` has `name`, `kind`, `default`, `base`, `define` and the patches.
|
|
220
221
|
|
|
@@ -226,12 +227,11 @@ Each item of `switches` has `name`, `kind`, `default`, `base`, `define` and the
|
|
|
226
227
|
|
|
227
228
|
`default` has `in`, `result` and `changedBytes`, as in `switches`. When `default` has `overflow` and the message `turn on one of them`, two alternatives are in the default build. Give one of the switches the default of the base release.
|
|
228
229
|
|
|
229
|
-
Each item of `releases` has `label`, `base`, `
|
|
230
|
+
Each item of `releases` has `label`, `base`, `define` and `result`:
|
|
230
231
|
|
|
231
|
-
- `identical`: the build gives the bytes of the
|
|
232
|
+
- `identical`: the build gives the bytes of the release.
|
|
232
233
|
- `different`: the release has bytes that no patch gives. Compare the release with the program. Then record a switch and a patch for each difference.
|
|
233
234
|
- `layout differs`: the release has other segments than the program. Patches cannot move code. This result does not fail the run.
|
|
234
|
-
- `file changed`: the file is not the file that the knowledge recorded. Put back the file, or record the release again in the project knowledge.
|
|
235
235
|
- `does not assemble`: read the ACME diagnostics.
|
|
236
236
|
|
|
237
237
|
The script writes a patch only when its range is complete items of one file. A patch cannot cut an instruction. Its switch name cannot be a name of the source.
|
|
@@ -245,12 +245,12 @@ Build the program from the source in these ways:
|
|
|
245
245
|
|
|
246
246
|
#### The loader
|
|
247
247
|
|
|
248
|
-
`--loader` writes `loader.asm`
|
|
248
|
+
`--loader` writes `loader.asm` in `--out`. It assembles `loader.asm` to the loader program in `build/`. Git ignores `build/`. The name of the loader program tells its build:
|
|
249
249
|
|
|
250
250
|
- `clean_loader.prg`: each value of `config.asm` is its default. This is the clean program.
|
|
251
251
|
- `custom_<switches>_loader.prg`: the names of the switches that are not at their default. A switch that is off has `no_` before its name, for example `custom_no_start_screen_loader.prg`.
|
|
252
252
|
|
|
253
|
-
The symbols of the loader program are in `symbols/<name>.json`, for example `symbols/clean_loader.json`. They hold the labels of `loader.asm`, `main.asm` and `start_screen_stage.asm`. Give this file to a test of the loader program as its symbols. When the name changes, the script removes the loader program of the earlier run and its symbols.
|
|
253
|
+
The symbols of the loader program are in `build/symbols/<name>.json`, for example `build/symbols/clean_loader.json`. They hold the labels of `loader.asm`, `main.asm` and `start_screen_stage.asm`. Give this file to a test of the loader program as its symbols. When the name changes, the script removes the loader program of the earlier run and its symbols.
|
|
254
254
|
|
|
255
255
|
The loader does these steps:
|
|
256
256
|
|
|
@@ -422,7 +422,7 @@ The entry is the entry of the knowledge. Without it, the entry is the address of
|
|
|
422
422
|
|
|
423
423
|
```text
|
|
424
424
|
README.md the steps to build and test, the free ranges and the origin
|
|
425
|
-
src/ main.asm, constants.asm, macros.asm, the modules and loader.asm
|
|
425
|
+
src/ main.asm, constants.asm, macros.asm, the modules in their folders and loader.asm
|
|
426
426
|
baseline/<name>.prg the exported program, and baseline/<name>.json with its symbols
|
|
427
427
|
tests/ the tests of the project, changed for the new program
|
|
428
428
|
.c64-re-tools/knowledge/ the knowledge of the new program
|
|
@@ -18,7 +18,7 @@ import { CONFIG_FILE, configValues } from "#src/build-name.ts";
|
|
|
18
18
|
import { type AddressRange, COVERAGE, formatC64Address, formatC64Byte, POINTER_TABLE_TYPES, pointerTableEntries, type PointerTableType } from "#src/c64.ts";
|
|
19
19
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
20
20
|
import { identifiers, operandText, replaceIdentifiers, type OperandExpression } from "#src/knowledge/expression.ts";
|
|
21
|
-
import { type CommentPlacement, isAnalyzer, isGeneratedFile, LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Origin, type RegionType, type SwitchKind } from "#src/knowledge/schema.ts";
|
|
21
|
+
import { type CommentPlacement, isAnalyzer, isGeneratedFile, LEFTOVER_FOLDER, LEFTOVERS_SWITCH, SEGMENT_FOLDER, RELEASE_DEFINE, START_SCREEN_SWITCH, type Origin, type RegionType, type SwitchKind } from "#src/knowledge/schema.ts";
|
|
22
22
|
import type { Area } from "#src/platform.ts";
|
|
23
23
|
import { hasZeroPageForm, instructionWith, labelProblem, MODE_LENGTH, OPCODES, takesAddress, USE_KINDS, useKind, type UseKind } from "#src/opcodes.ts";
|
|
24
24
|
|
|
@@ -96,7 +96,6 @@ export interface SourceSwitch {
|
|
|
96
96
|
/** A release: the build with RELEASE_<label> gives each switch the value of this release. */
|
|
97
97
|
export interface SourceRelease {
|
|
98
98
|
label: string;
|
|
99
|
-
file: string;
|
|
100
99
|
base: boolean;
|
|
101
100
|
comment?: string;
|
|
102
101
|
}
|
|
@@ -331,23 +330,24 @@ export function layout(input: SourceInput): Layout {
|
|
|
331
330
|
const end = bounds[index + 1]! - 1;
|
|
332
331
|
const segmentTitle = `Segment ${formatC64Address(segment.start)}-${formatC64Address(segment.end)}`;
|
|
333
332
|
if (leftovers.some((range) => range.start === start)) {
|
|
334
|
-
pieces.push({ start, end, file:
|
|
333
|
+
pieces.push({ start, end, file: `${LEFTOVER_FOLDER}/leftover_${hex(start)}.asm`, title: `Leftovers ${formatC64Address(start)}-${formatC64Address(end)}: ${end - start + 1} bytes that nothing uses. Only LEFTOVERS = 1 builds them.`, segmentStart: index === 0, leftover: true, items: [] });
|
|
335
334
|
continue;
|
|
336
335
|
}
|
|
337
|
-
// A module that leftovers cut goes on in a file of its own after them: <module>_xxxx.asm.
|
|
336
|
+
// A module that leftovers cut goes on in a file of its own after them, in its folder: <module>_xxxx.asm.
|
|
338
337
|
const module = modules.find((row) => row.start === start);
|
|
339
338
|
const holder = module ?? modules.filter((row) => row.start >= segment.start && row.start < start).at(-1);
|
|
340
339
|
const title = (text: string | undefined) => text?.replace(/\s*\r?\n\s*/g, " ");
|
|
341
|
-
const file = module?.file ?? (holder === undefined ?
|
|
340
|
+
const file = module?.file ?? (holder === undefined ? `${SEGMENT_FOLDER}/segment_${hex(start)}.asm` : `${holder.file.replace(/\.asm$/i, "")}_${hex(start)}.asm`);
|
|
342
341
|
const named = module === undefined && holder !== undefined ? `${title(holder.title) ?? holder.file}, from ${formatC64Address(start)}` : title(module?.title);
|
|
343
342
|
pieces.push({ start, end, file, title: named ?? segmentTitle, segmentStart: index === 0, leftover: false, items: [] });
|
|
344
343
|
}
|
|
345
344
|
}
|
|
345
|
+
// In any letter case: the file systems of macOS and Windows ignore it.
|
|
346
346
|
const files = new Map<string, number>();
|
|
347
347
|
for (const piece of pieces) {
|
|
348
|
-
const other = files.get(piece.file);
|
|
348
|
+
const other = files.get(piece.file.toLowerCase());
|
|
349
349
|
if (other !== undefined) throw new WireFailure("invalid-input", `The file ${piece.file} is used at ${formatC64Address(other)} and at ${formatC64Address(piece.start)}. Give the module another file.`);
|
|
350
|
-
files.set(piece.file, piece.start);
|
|
350
|
+
files.set(piece.file.toLowerCase(), piece.start);
|
|
351
351
|
}
|
|
352
352
|
|
|
353
353
|
for (const piece of pieces) {
|
|
@@ -971,7 +971,7 @@ export function configText(layout: Pick<Layout, "switches" | "patches" | "startS
|
|
|
971
971
|
out.push(
|
|
972
972
|
"",
|
|
973
973
|
"; Leftovers: off by default",
|
|
974
|
-
`${LEFTOVERS_SWITCH} = ${values.get(LEFTOVERS_SWITCH) ?? 0} ; ${bytes} bytes in ${layout.leftovers.length}
|
|
974
|
+
`${LEFTOVERS_SWITCH} = ${values.get(LEFTOVERS_SWITCH) ?? 0} ; ${bytes} bytes in ${layout.leftovers.length} ${layout.leftovers.length === 1 ? "file" : "files"} in ${LEFTOVER_FOLDER}/ that nothing uses. 1 builds them, so main.asm gives the bytes of the program. Each release has them. The loader never loads them`,
|
|
975
975
|
);
|
|
976
976
|
}
|
|
977
977
|
return `${out.join("\n")}\n`;
|
|
@@ -989,7 +989,7 @@ function switchesText(layout: Layout): string {
|
|
|
989
989
|
"; then each switch has the value of that release, and the build does not read config.asm.",
|
|
990
990
|
];
|
|
991
991
|
for (const release of layout.releases) {
|
|
992
|
-
out.push("", `; ${release.label}${release.base ? " (the program of the knowledge)" : ""}
|
|
992
|
+
out.push("", `; ${release.label}${release.base ? " (the program of the knowledge)" : ""}${release.comment === undefined ? "" : `: ${release.comment.replace(/\s*\r?\n\s*/g, " ")}`}`);
|
|
993
993
|
out.push(`!ifdef ${RELEASE_DEFINE}${release.label} {`);
|
|
994
994
|
for (const row of layout.switches) out.push(`${INDENT}${row.name} = ${row.releases.includes(release.label) ? 1 : 0}`);
|
|
995
995
|
if (layout.leftovers.length > 0) out.push(`${INDENT}${LEFTOVERS_SWITCH} = 1`);
|