@henols/c64-re-tools 2.6.0-rc.2 → 2.6.0-rc.4
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 +26 -12
- package/skills/c64-assembler/scripts/assembler.ts +24 -11
- package/skills/c64-knowledge/SKILL.md +31 -16
- package/skills/c64-knowledge/scripts/knowledge.ts +62 -33
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-reverse-engineering/SKILL.md +1 -1
- package/skills/c64-source/SKILL.md +51 -30
- package/skills/c64-source/scripts/lib/export.ts +76 -32
- package/skills/c64-source/scripts/lib/loader.ts +29 -9
- package/skills/c64-source/scripts/lib/source.ts +5 -16
- 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 +145 -46
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +2 -25
- package/skills/c64-testing/SKILL.md +3 -1
- package/skills/c64-testing/references/recording-format.md +1 -0
- package/skills/c64-testing/references/scenario-format.md +5 -3
- package/skills/c64-testing/scripts/lib/recording.ts +25 -8
- package/skills/c64-testing/scripts/lib/replay.ts +1 -1
- package/skills/c64-testing/scripts/lib/scenario.ts +14 -5
- package/skills/c64-unpacker/SKILL.md +4 -2
- package/skills/c64-unpacker/scripts/lib/loads.ts +33 -12
- package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/src/build-name.ts +47 -0
- package/src/c64.ts +21 -1
- package/src/host/vice/session.ts +6 -1
- package/src/knowledge/read.ts +5 -2
- package/src/knowledge/schema.ts +5 -3
- package/src/knowledge/start-screen.ts +68 -0
- package/src/knowledge/text.ts +1 -0
- package/src/knowledge/write.ts +22 -16
- package/src/native/acme.ts +1 -1
- package/src/platform.ts +30 -1
- package/src/script.ts +3 -3
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
; The loader includes this file in its copier, with the interrupts off. The
|
|
5
5
|
; code uses no stack and writes only the I/O area, the colour RAM and its own
|
|
6
6
|
; bytes: the copies wrote pages 0-3 of the entry state already.
|
|
7
|
-
; Set START_SCREEN = 0 in config.asm to start the program at once.
|
|
7
|
+
; Set START_SCREEN = 0 in config.asm to start the program at once. The start
|
|
8
|
+
; screen is part of the clean build only: a release and LEFTOVERS = 1 have none.
|
|
8
9
|
; loader.asm sets these values from the start screen of the knowledge:
|
|
9
10
|
; c64_source_ss_d011, c64_source_ss_d016, c64_source_ss_d018: the VIC-II mode
|
|
10
11
|
; c64_source_ss_bank: the VIC bank, as bits 0-1 of $dd00
|
|
@@ -19,8 +20,9 @@
|
|
|
19
20
|
; wait, so each read of the keyboard and the joysticks is done with SEI.
|
|
20
21
|
|
|
21
22
|
!ifndef START_SCREEN { START_SCREEN = 1 }
|
|
23
|
+
!ifndef LEFTOVERS { LEFTOVERS = 0 }
|
|
22
24
|
|
|
23
|
-
lda #START_SCREEN
|
|
25
|
+
lda #START_SCREEN & (1 - LEFTOVERS)
|
|
24
26
|
bne .on
|
|
25
27
|
jmp .end
|
|
26
28
|
.port !byte 0
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
13
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
14
|
-
import { basename, join, relative, sep } from "node:path";
|
|
14
|
+
import { basename, dirname, join, relative, sep } from "node:path";
|
|
15
15
|
|
|
16
16
|
import { isRefusal, Refusal } from "#src/errors.ts";
|
|
17
|
-
import {
|
|
17
|
+
import { buildName, symbolsPath } from "#src/build-name.ts";
|
|
18
|
+
import { type AddressRange, coverageSeedKinds, findHandoffs, formatC64Address, parseC64Address, parseTokenized, textToPetscii } from "#src/c64.ts";
|
|
18
19
|
import { autostartLoaded, RUN_LIMIT_FRAMES } from "#src/host-client/autostart.ts";
|
|
19
20
|
import { IO_RAM } from "#src/host-client/coverage.ts";
|
|
20
21
|
import { readImage, type Image } from "#src/host-client/image.ts";
|
|
@@ -33,7 +34,7 @@ import { assemble, symbolsFileText } from "#src/native/acme.ts";
|
|
|
33
34
|
import { analyze } from "#src/native/ghidra/analyze.ts";
|
|
34
35
|
import { localToolContext } from "#src/native/local.ts";
|
|
35
36
|
import { GHIDRA_LIMITS, type AssembledSymbol, type Diagnostic } from "#src/native/types.ts";
|
|
36
|
-
import { decode as decodeRegister, describeAddress, platformNames, platformNamesFor, romUseOfProgram } from "#src/platform.ts";
|
|
37
|
+
import { decode as decodeRegister, describeAddress, platformNames, platformNamesFor, romRanges, romUseOfProgram } from "#src/platform.ts";
|
|
37
38
|
import { ensureLocal, LOCAL_DIRECTORY, newProjectFolder, PROJECT_DIRECTORY, projectRoot, resolveProjectPath } from "#src/project.ts";
|
|
38
39
|
import { isoCet } from "#src/time.ts";
|
|
39
40
|
import { zipFiles } from "#src/zip.ts";
|
|
@@ -49,6 +50,7 @@ import {
|
|
|
49
50
|
startScreenPlan,
|
|
50
51
|
rasterLine,
|
|
51
52
|
loaderState,
|
|
53
|
+
loaderSymbols,
|
|
52
54
|
simulate,
|
|
53
55
|
START_SCREEN_CODE,
|
|
54
56
|
START_SCREEN_CONTINUE,
|
|
@@ -62,6 +64,7 @@ import {
|
|
|
62
64
|
type StartScreenPlan,
|
|
63
65
|
} from "./lib/loader.ts";
|
|
64
66
|
import { instructionWith, OPCODES } from "#src/opcodes.ts";
|
|
67
|
+
import { capturedColourRam } from "#src/knowledge/start-screen.ts";
|
|
65
68
|
import { planStage, STAGE_CODE_END, STAGE_FILE, STAGE_START, stageParts, stageText, type StageInput, type StagePart, type StagePlan } from "./lib/stage.ts";
|
|
66
69
|
import { freeName, planDrops, readmeText, rewriteTest } from "./lib/export.ts";
|
|
67
70
|
import { CONFIG_FILE, configText, configValues, entriesInData, entryOutsideImage, hasConfigFile, hasSwitchFile, layout, literalOperand, probeForms, render, switchesOf, type Layout, type PatchBlock, type Rendered, type SourceSwitch } from "./lib/source.ts";
|
|
@@ -141,6 +144,14 @@ function withAnalyzerNames(symbols: SymbolRow[], second: SymbolRow[]): SymbolRow
|
|
|
141
144
|
return [...symbols, ...added].sort((a, b) => a.address - b.address);
|
|
142
145
|
}
|
|
143
146
|
|
|
147
|
+
/** Where the CPU sees ROM in the image (romRanges): the entry, the routines, the code regions and `entries` stay code. */
|
|
148
|
+
function romOf(image: ProgramImage, knowledge: Pick<SourceKnowledge, "routines" | "regions">, entries: readonly number[], coverage: Uint8Array | undefined): AddressRange[] {
|
|
149
|
+
const inImage = (address: number) => image.segments.some((segment) => address >= segment.start && address <= segment.end);
|
|
150
|
+
const code = knowledge.regions.filter((region) => CODE_REGION_TYPES.includes(region.type) || region.type === "dual-use").map((region) => region.start);
|
|
151
|
+
const known = [...(image.entry === undefined ? [] : [image.entry]), ...entries, ...knowledge.routines, ...code];
|
|
152
|
+
return romRanges(coverage, image.state, (address) => (inImage(address) ? image.byteAt(address) : undefined), known);
|
|
153
|
+
}
|
|
154
|
+
|
|
144
155
|
/**
|
|
145
156
|
* Ghidra's instruction starts and lengths inside the image, seeded from the
|
|
146
157
|
* entry, from knowledge of any origin, and from the coverage: a run's flow
|
|
@@ -166,6 +177,8 @@ async function decode(image: ProgramImage, knowledge: Pick<SourceKnowledge, "rou
|
|
|
166
177
|
const dataRanges = knowledge.regions
|
|
167
178
|
.filter((region) => !CODE_REGION_TYPES.includes(region.type) && region.type !== "dual-use")
|
|
168
179
|
.flatMap((region) => image.segments.filter((segment) => region.start <= segment.end && segment.start <= region.end).map((segment) => ({ start: Math.max(region.start, segment.start), end: Math.min(region.end, segment.end) })));
|
|
180
|
+
// A JSR into ROM runs the ROM: the RAM bytes of the image under it are data, not the code of the call.
|
|
181
|
+
for (const range of romOf(image, knowledge, entries, coverage)) if (!dataRanges.some((data) => range.start <= data.end && data.start <= range.end)) dataRanges.push(range);
|
|
169
182
|
const { result } = await analyze(
|
|
170
183
|
{
|
|
171
184
|
imageKind: analyzedBytes(image).kind,
|
|
@@ -544,7 +557,7 @@ interface LoaderRunPlan {
|
|
|
544
557
|
/** The wait of the start screen and the code after it, when the loader has a start screen. */
|
|
545
558
|
startScreen?: { wait: number; continue: number };
|
|
546
559
|
/** The show stage of a start screen from a captured stage, which runs before the loader: its wait, the code after it, its VIC-II values and the bytes of the stage. */
|
|
547
|
-
stage?: { name: string; wait: number; continue: number; screen: StartScreenPlan; parts: StagePart[]; frames: number };
|
|
560
|
+
stage?: { name: string; wait: number; continue: number; screen: StartScreenPlan; parts: StagePart[]; colourRam?: Uint8Array; frames: number };
|
|
548
561
|
copierSource: number;
|
|
549
562
|
fileByte: (address: number) => number;
|
|
550
563
|
copierFrames: number;
|
|
@@ -571,7 +584,7 @@ async function runLoader(path: string, program: Buffer, plan: LoaderPlan, state:
|
|
|
571
584
|
// on each VICE, so the check lets it wait, then sets the PC to the code after the wait.
|
|
572
585
|
let screen: LoaderRun["startScreen"];
|
|
573
586
|
const screenDifferences: string[] = [];
|
|
574
|
-
const showScreen = async (at: { wait: number; continue: number }, wanted: StartScreenPlan, frames: number, copied: boolean, parts: readonly StagePart[] = []): Promise<LoaderRun | undefined> => {
|
|
587
|
+
const showScreen = async (at: { wait: number; continue: number }, wanted: StartScreenPlan, frames: number, copied: boolean, parts: readonly StagePart[] = [], colourRam?: Uint8Array): Promise<LoaderRun | undefined> => {
|
|
575
588
|
const labels = { wait: formatC64Address(at.wait), continue: formatC64Address(at.continue) };
|
|
576
589
|
const atWait = await client.runUntil({ target: { kind: "address", address: at.wait, space: "c64" }, timeoutFrames: frames });
|
|
577
590
|
if (!atWait.reached) return await stopped(atWait.pc, copied, `its start screen at ${labels.wait}`, parts.length === 0);
|
|
@@ -591,6 +604,12 @@ async function runLoader(path: string, program: Buffer, plan: LoaderPlan, state:
|
|
|
591
604
|
const wrong = part.body.findIndex((byte, offset) => ram[offset] !== byte);
|
|
592
605
|
if (wrong >= 0) screenDifferences.push(`the stage has $${ram[wrong]!.toString(16).padStart(2, "0")} at ${formatC64Address(part.start + wrong)}, not $${part.body[wrong]!.toString(16).padStart(2, "0")}`);
|
|
593
606
|
}
|
|
607
|
+
// The colour RAM of a captured stage: the first wrong colour.
|
|
608
|
+
if (colourRam !== undefined) {
|
|
609
|
+
const colours = Buffer.from((await client.ioRead(0xd800, colourRam.length)).data, "hex");
|
|
610
|
+
const wrong = colourRam.findIndex((value, offset) => (colours[offset]! & 0x0f) !== value);
|
|
611
|
+
if (wrong >= 0) screenDifferences.push(`the colour RAM has ${colours[wrong]! & 0x0f} at ${formatC64Address(0xd800 + wrong)}, not ${colourRam[wrong]}`);
|
|
612
|
+
}
|
|
594
613
|
screen = { shown: screenDifferences.length === before, waits: !held.reached, ...labels, ...(run.stage === undefined ? {} : { stage: run.stage.name }) };
|
|
595
614
|
if (held.reached) screenDifferences.push(`the start screen did not wait: it got to ${labels.continue} without a key or a fire button`);
|
|
596
615
|
if (!held.reached) await client.registersSet("c64", { pc: at.continue });
|
|
@@ -598,7 +617,7 @@ async function runLoader(path: string, program: Buffer, plan: LoaderPlan, state:
|
|
|
598
617
|
};
|
|
599
618
|
// The show stage of a captured stage runs before the loader.
|
|
600
619
|
if (run.stage !== undefined) {
|
|
601
|
-
const stop = await showScreen(run.stage, run.stage.screen, run.stage.frames, false, run.stage.parts);
|
|
620
|
+
const stop = await showScreen(run.stage, run.stage.screen, run.stage.frames, false, run.stage.parts, run.stage.colourRam);
|
|
602
621
|
if (stop !== undefined) return stop;
|
|
603
622
|
}
|
|
604
623
|
const copier = await client.runUntil({ target: { kind: "address", address: plan.copier, space: "c64" }, timeoutFrames: run.copierFrames });
|
|
@@ -687,11 +706,24 @@ function sourceMapText(rendered: Rendered, space: string, revision: string | nul
|
|
|
687
706
|
return `${head},\n"labels": [\n${labels.join(",\n")}\n],\n"items": [\n${items.join(",\n")}\n]}\n`;
|
|
688
707
|
}
|
|
689
708
|
|
|
690
|
-
/** The folder in .c64-re-tools/local/ where the check of the loader runs the new loader.
|
|
709
|
+
/** The folder in .c64-re-tools/local/ where the check of the loader runs the new loader program. */
|
|
691
710
|
const LOADER_CHECK_DIRECTORY = "loader-check";
|
|
692
711
|
|
|
693
|
-
/** The files of the loader. Only a run with --loader writes them, so only such a run removes them. */
|
|
694
|
-
const LOADER_FILES: ReadonlySet<string> = new Set(["loader.asm",
|
|
712
|
+
/** The source files of the loader. Only a run with --loader writes them, so only such a run removes them. */
|
|
713
|
+
const LOADER_FILES: ReadonlySet<string> = new Set(["loader.asm", START_SCREEN_FILE, STAGE_FILE]);
|
|
714
|
+
|
|
715
|
+
/** A loader program that generate wrote: its build name, as buildName gives it for loader.asm. */
|
|
716
|
+
const LOADER_PROGRAM = /^(clean|custom_[a-z0-9_]+|release_[A-Za-z0-9_]+)_loader\.prg$/;
|
|
717
|
+
|
|
718
|
+
/** The loader programs of earlier runs in `out`, with their symbols files. */
|
|
719
|
+
function loaderPrograms(out: string): string[] {
|
|
720
|
+
const directory = resolveProjectPath(out);
|
|
721
|
+
if (!existsSync(directory)) return [];
|
|
722
|
+
return readdirSync(directory)
|
|
723
|
+
.filter((name) => LOADER_PROGRAM.test(name))
|
|
724
|
+
.flatMap((name) => [`${out}/${name}`, symbolsPath(`${out}/${name}`)])
|
|
725
|
+
.filter((path) => existsSync(resolveProjectPath(path)));
|
|
726
|
+
}
|
|
695
727
|
|
|
696
728
|
/** The start of the line of loader.asm that gives the knowledge revision of the loader. */
|
|
697
729
|
const LOADER_REVISION = "Loader generated by c64-source from knowledge revision ";
|
|
@@ -710,16 +742,42 @@ function staleLoader(out: string, revision: string): { files: string[]; revision
|
|
|
710
742
|
const line = text.split(/\r?\n/).find((row) => row.startsWith(`; ${LOADER_REVISION}`));
|
|
711
743
|
const old = line?.slice(`; ${LOADER_REVISION}`.length).replace(/\.$/, "");
|
|
712
744
|
if (old === revision) return undefined;
|
|
713
|
-
const files = [...LOADER_FILES].filter((name) => existsSync(resolveProjectPath(`${out}/${name}`))).map((name) => `${out}/${name}`);
|
|
745
|
+
const files = [...[...LOADER_FILES].filter((name) => existsSync(resolveProjectPath(`${out}/${name}`))).map((name) => `${out}/${name}`), ...loaderPrograms(out)];
|
|
714
746
|
return { files, ...(old === undefined ? {} : { revision: old }) };
|
|
715
747
|
}
|
|
716
748
|
|
|
749
|
+
/** The line of a leftover file that gives its range. */
|
|
750
|
+
const LEFTOVER_RANGE = /^; Leftovers (\$[0-9a-f]{4})-(\$[0-9a-f]{4}):/m;
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* The leftovers of the earlier run: the ranges of its generated leftover
|
|
754
|
+
* files in `out`. Undefined when `out` has no generated main.asm, so there
|
|
755
|
+
* was no earlier run to compare with.
|
|
756
|
+
*/
|
|
757
|
+
function earlierLeftovers(out: string): AddressRange[] | undefined {
|
|
758
|
+
const directory = resolveProjectPath(out);
|
|
759
|
+
const main = join(directory, "main.asm");
|
|
760
|
+
if (!existsSync(main) || !readFileSync(main, "utf8").startsWith(GENERATED_MARK)) return undefined;
|
|
761
|
+
return readdirSync(directory)
|
|
762
|
+
.filter((name) => /^leftover_[0-9a-f]{4}\.asm$/.test(name))
|
|
763
|
+
.flatMap((name) => {
|
|
764
|
+
const found = LEFTOVER_RANGE.exec(readFileSync(join(directory, name), "utf8"));
|
|
765
|
+
return found === null ? [] : [{ start: parseC64Address(found[1]!), end: parseC64Address(found[2]!) }];
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/** The bytes of `ranges` that are not in `others`, as ranges in address order. */
|
|
770
|
+
function outside(ranges: readonly AddressRange[], others: readonly AddressRange[]): AddressRange[] {
|
|
771
|
+
return [...ranges].sort((a, b) => a.start - b.start).flatMap((range) => subtract(range, [...others]));
|
|
772
|
+
}
|
|
773
|
+
|
|
717
774
|
/**
|
|
718
775
|
* Removes the generated .asm files of an earlier run that this run does not
|
|
719
776
|
* write, and an earlier not_executed.json and source-map.json. An earlier
|
|
720
777
|
* loader.asm stays unless this run has --loader: a source of the user can
|
|
721
|
-
* include loader.asm. An earlier loader
|
|
722
|
-
* whose check ran replaces it. Other files stay. Gives the
|
|
778
|
+
* include loader.asm. An earlier loader program always stays: only a new
|
|
779
|
+
* loader program whose check ran replaces it. Other files stay. Gives the
|
|
780
|
+
* names it removed.
|
|
723
781
|
*/
|
|
724
782
|
function removeOldFiles(out: string, keep: ReadonlySet<string>, loaderRun: boolean): string[] {
|
|
725
783
|
const directory = resolveProjectPath(out);
|
|
@@ -827,7 +885,7 @@ async function buildSource(knowledge: SourceKnowledge, options: SourceOptions) {
|
|
|
827
885
|
|
|
828
886
|
let loader: LoaderPlan | undefined;
|
|
829
887
|
/** The build of main.asm that the loader loads: the switch values of the loader. */
|
|
830
|
-
let loaderMain: { program: Buffer; start: number } | undefined;
|
|
888
|
+
let loaderMain: { program: Buffer; start: number; symbols: AssembledSymbol[] } | undefined;
|
|
831
889
|
// An image without its entry has no program: the source is still written and checked, but the run fails.
|
|
832
890
|
const missingEntry = entryOutsideImage(image.entry, image.segments);
|
|
833
891
|
// A loader that cannot be planned does not stop the source: the source is written and checked, and the result says why.
|
|
@@ -839,7 +897,7 @@ async function buildSource(knowledge: SourceKnowledge, options: SourceOptions) {
|
|
|
839
897
|
else {
|
|
840
898
|
const program = main.program;
|
|
841
899
|
const start = main.start!;
|
|
842
|
-
loaderMain = { program, start };
|
|
900
|
+
loaderMain = { program, start, symbols: main.symbols ?? [] };
|
|
843
901
|
try {
|
|
844
902
|
const entryName = laid.names.get(image.entry!);
|
|
845
903
|
loader = planLoader({
|
|
@@ -934,9 +992,11 @@ async function buildLoader(
|
|
|
934
992
|
* of the stage whose switch default is not its base value is in, as in the
|
|
935
993
|
* default build. Pages 0-3 are left out: the unpacker of Exomizer uses them.
|
|
936
994
|
*/
|
|
937
|
-
async function stageBytes(row: StartScreenRow): Promise<StagePart[]> {
|
|
995
|
+
async function stageBytes(row: StartScreenRow): Promise<{ parts: StagePart[]; colourRam?: Uint8Array }> {
|
|
938
996
|
const stage = row.stage!;
|
|
939
997
|
const knowledge = readKnowledge(stage);
|
|
998
|
+
const colourRam = row.colourRam === true ? capturedColourRam(knowledge.program.state) : undefined;
|
|
999
|
+
if (row.colourRam === true && colourRam === undefined) throw new Refusal("not-found", `The start screen takes its colours from the colour RAM of the capture in ${stage}, and that capture has none. Capture the stage again while it shows the screen, and put it into the project knowledge with image --space ${stage}.`);
|
|
940
1000
|
const image = knowledge.program;
|
|
941
1001
|
const memory = Uint8Array.from(image.memory);
|
|
942
1002
|
const addresses = knowledge.symbols.map((symbol) => `${symbol.name} = ${formatC64Address(symbol.address)}`);
|
|
@@ -969,15 +1029,18 @@ async function stageBytes(row: StartScreenRow): Promise<StagePart[]> {
|
|
|
969
1029
|
if (last !== undefined && range.start <= last.end + 1) last.end = Math.max(last.end, range.end);
|
|
970
1030
|
else parts.push({ ...range });
|
|
971
1031
|
}
|
|
972
|
-
return parts.map((range) => ({ start: range.start, body: memory.slice(range.start, range.end + 1) }));
|
|
1032
|
+
return { parts: parts.map((range) => ({ start: range.start, body: memory.slice(range.start, range.end + 1) })), ...(colourRam === undefined ? {} : { colourRam }) };
|
|
973
1033
|
}
|
|
974
1034
|
|
|
975
|
-
/** What the show stage gives: loader
|
|
1035
|
+
/** What the show stage gives: the loader program, the source of the stage, and what its check needs. */
|
|
976
1036
|
interface BuiltStage {
|
|
977
1037
|
program: Buffer;
|
|
978
1038
|
text: string;
|
|
1039
|
+
/** The labels of the build of start_screen_stage.asm. */
|
|
1040
|
+
symbols: AssembledSymbol[];
|
|
979
1041
|
plan: StagePlan;
|
|
980
1042
|
parts: StagePart[];
|
|
1043
|
+
colourRam?: Uint8Array;
|
|
981
1044
|
packed: PackedLoader;
|
|
982
1045
|
wait: number;
|
|
983
1046
|
continue: number;
|
|
@@ -990,7 +1053,7 @@ interface BuiltStage {
|
|
|
990
1053
|
* is in memory before it starts. Refuses by name.
|
|
991
1054
|
*/
|
|
992
1055
|
async function buildStage(files: Array<{ name: string; text: string }>, laid: Layout, program: PackedLoader, row: StartScreenRow, values: ReadonlyMap<string, number>, header: string[], mark: string): Promise<BuiltStage> {
|
|
993
|
-
const stage = await stageBytes(row);
|
|
1056
|
+
const { parts: stage, colourRam } = await stageBytes(row);
|
|
994
1057
|
// The packed program, as RUN would start it: its unpacker unpacks it over the start screen after the wait.
|
|
995
1058
|
const inner: StagePart[] = [{ start: 0x0801, body: program.program.subarray(2) }];
|
|
996
1059
|
const screen = startScreenPlan(row);
|
|
@@ -999,6 +1062,7 @@ async function buildStage(files: Array<{ name: string; text: string }>, laid: La
|
|
|
999
1062
|
innerStart: 0x080d,
|
|
1000
1063
|
innerPort: 0x37,
|
|
1001
1064
|
stage,
|
|
1065
|
+
...(colourRam === undefined ? {} : { colourRam }),
|
|
1002
1066
|
row,
|
|
1003
1067
|
plan: screen,
|
|
1004
1068
|
settings: hasSwitchFile(laid) ? ['!source "switches.asm"'] : hasConfigFile(laid) ? ['!source "config.asm"'] : [],
|
|
@@ -1008,17 +1072,24 @@ async function buildStage(files: Array<{ name: string; text: string }>, laid: La
|
|
|
1008
1072
|
const support = [...withValues(files, laid, values).filter((file) => file.name === CONFIG_FILE || file.name === "switches.asm"), { name: START_SCREEN_FILE, text: START_SCREEN_CODE }];
|
|
1009
1073
|
const assembleStage = async (text: string) => {
|
|
1010
1074
|
const built = await assembleFiles([...support, { name: STAGE_FILE, text }], STAGE_FILE);
|
|
1011
|
-
if (built.program === undefined)
|
|
1075
|
+
if (built.program === undefined) {
|
|
1076
|
+
// The source that failed stays readable: --out keeps the files of the last good run.
|
|
1077
|
+
ensureLocal(projectRoot());
|
|
1078
|
+
const kept = `${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/${LOADER_CHECK_DIRECTORY}/${STAGE_FILE}`;
|
|
1079
|
+
mkdirSync(dirname(resolveProjectPath(kept)), { recursive: true });
|
|
1080
|
+
writeFileSync(resolveProjectPath(kept), `${mark}\n${text}`);
|
|
1081
|
+
throw new WireFailure("operation-failed", `${STAGE_FILE} does not assemble: ${built.diagnostics.map((diagnostic) => diagnostic.message).join("; ")}. The source that failed is ${kept}. This is a defect of the script.`);
|
|
1082
|
+
}
|
|
1012
1083
|
const labels = new Map((built.symbols ?? []).map((symbol) => [symbol.name, symbol.kind === "address" ? symbol.address : symbol.value]));
|
|
1013
1084
|
const label = (name: string) => {
|
|
1014
1085
|
const value = labels.get(name);
|
|
1015
1086
|
if (value === undefined) throw new WireFailure("operation-failed", `The build of ${STAGE_FILE} has no ${name} label. This is a defect of the script.`);
|
|
1016
1087
|
return value;
|
|
1017
1088
|
};
|
|
1018
|
-
return { program: built.program, label };
|
|
1089
|
+
return { program: built.program, symbols: built.symbols ?? [], label };
|
|
1019
1090
|
};
|
|
1020
|
-
// The size of the show code does not depend on its address: one build without a stash gives it.
|
|
1021
|
-
const probe = await assembleStage(stageText(input, 0x1000, []));
|
|
1091
|
+
// The size of the show code does not depend on its address: one build without a stash and without the parts gives it.
|
|
1092
|
+
const probe = await assembleStage(stageText({ ...input, stage: [] }, 0x1000, []));
|
|
1022
1093
|
input.codeSize = probe.label(STAGE_CODE_END) - probe.label(STAGE_START) - 2;
|
|
1023
1094
|
const plan = planStage(input);
|
|
1024
1095
|
const built = await assembleStage(plan.text);
|
|
@@ -1026,8 +1097,8 @@ async function buildStage(files: Array<{ name: string; text: string }>, laid: La
|
|
|
1026
1097
|
const parts = stageParts(input, plan, built.program, built.label);
|
|
1027
1098
|
const packed = await packParts(parts, plan.code, 0x37, "the loader and the start screen of the stage", "the show stage", localToolContext());
|
|
1028
1099
|
const end = 0x0801 + packed.program.length - 3;
|
|
1029
|
-
if (end > 0xcfff) throw new Refusal("invalid-input", `loader
|
|
1030
|
-
return { program: packed.program, text: `${mark}\n${plan.text}`, plan, parts: stage, packed, wait: built.label(START_SCREEN_WAIT), continue: built.label(START_SCREEN_CONTINUE), screen };
|
|
1100
|
+
if (end > 0xcfff) throw new Refusal("invalid-input", `The loader with the start screen of ${row.stage} would end at ${formatC64Address(end)}, after $cfff: loading it would write the I/O area. Capture the stage with less memory, so that its program holds only the start screen and the routine of the call.`);
|
|
1101
|
+
return { program: packed.program, text: `${mark}\n${plan.text}`, symbols: built.symbols, plan, parts: stage, ...(colourRam === undefined ? {} : { colourRam }), packed, wait: built.label(START_SCREEN_WAIT), continue: built.label(START_SCREEN_CONTINUE), screen };
|
|
1031
1102
|
}
|
|
1032
1103
|
|
|
1033
1104
|
/** The first line of each file that generate writes. */
|
|
@@ -1070,6 +1141,10 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1070
1141
|
const configured = [...laid.switches, ...(laid.startScreen ? [{ name: START_SCREEN_SWITCH, default: 1 }] : []), ...(laid.leftovers.length > 0 ? [{ name: LEFTOVERS_SWITCH, default: 0 }] : [])];
|
|
1071
1142
|
const kept = new Map(configured.flatMap((row) => (given.has(row.name) ? [[row.name, given.get(row.name)!] as const] : [])));
|
|
1072
1143
|
const notDefault = configured.flatMap((row) => (kept.has(row.name) && kept.get(row.name) !== row.default ? [{ name: row.name, value: kept.get(row.name)!, default: row.default }] : []));
|
|
1144
|
+
// The loader program has the name of its build: clean_loader with the defaults of config.asm.
|
|
1145
|
+
const loaderName = buildName("loader.asm", { values: kept, defaults: new Map(configured.map((row) => [row.name, row.default])) });
|
|
1146
|
+
// Read before the old files go: the leftovers of the earlier run, to tell what changed.
|
|
1147
|
+
const earlier = earlierLeftovers(out);
|
|
1073
1148
|
const removed = removeOldFiles(out, new Set(files.map((file) => file.name)), loaderWanted).map((name) => `${out}/${name}`);
|
|
1074
1149
|
const stale = loaderWanted || space !== DEFAULT_SPACE ? undefined : staleLoader(out, knowledge.revision);
|
|
1075
1150
|
const written: Written[] = withValues(files, laid, kept).map((file) => writeReported(`${out}/${file.name}`, file.text, { what: "--out" }));
|
|
@@ -1089,6 +1164,10 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1089
1164
|
const all = { revision: knowledge.revision, instructions: rendered.notExecuted.instructions, files, ranges: placed };
|
|
1090
1165
|
written.push(writeReported(`${out}/${NOT_EXECUTED_FILE}`, `${JSON.stringify(all, null, 2)}\n`, { what: "--out" }));
|
|
1091
1166
|
}
|
|
1167
|
+
// The leftovers that changed since the earlier run: the default build and the loader now leave out other bytes.
|
|
1168
|
+
const added = earlier === undefined ? [] : outside(laid.leftovers, earlier);
|
|
1169
|
+
const dropped = earlier === undefined ? [] : outside(earlier, laid.leftovers);
|
|
1170
|
+
const changed = added.length + dropped.length === 0 ? undefined : { added: added.map(showRange), removed: dropped.map(showRange) };
|
|
1092
1171
|
|
|
1093
1172
|
const output: Record<string, unknown> = {
|
|
1094
1173
|
out,
|
|
@@ -1124,8 +1203,10 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1124
1203
|
...(laid.leftovers.length === 0
|
|
1125
1204
|
? knowledge.coverage === undefined && space === DEFAULT_SPACE
|
|
1126
1205
|
? { leftovers: { bytes: 0, noCoverage: "The knowledge has no coverage, so no range is a leftover, and the default build and the loader have every byte of the program." } }
|
|
1127
|
-
:
|
|
1128
|
-
|
|
1206
|
+
: changed === undefined
|
|
1207
|
+
? {}
|
|
1208
|
+
: { leftovers: { bytes: 0, changed } }
|
|
1209
|
+
: { leftovers: { bytes: laid.leftovers.reduce((sum, range) => sum + range.end - range.start + 1, 0), ...listed(laid.leftovers, max, (range) => ({ ...showRange(range), bytes: range.end - range.start + 1, file: `leftover_${range.start.toString(16).padStart(4, "0")}.asm` })), ...(changed === undefined ? {} : { changed }) } }),
|
|
1129
1210
|
...(rendered.expressions.length === 0 && rendered.operandsAsNumbers.length === 0 ? {} : { operandExpressions: rendered.expressions.length }),
|
|
1130
1211
|
...(rendered.operandsAsNumbers.length === 0
|
|
1131
1212
|
? {}
|
|
@@ -1146,9 +1227,12 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1146
1227
|
patchesNotWritten: listed(laid.patchesNotWritten, max, (item) => ({ start: formatC64Address(item.start), end: formatC64Address(item.end), switch: item.switch, reason: item.reason })),
|
|
1147
1228
|
}),
|
|
1148
1229
|
};
|
|
1149
|
-
// A loader
|
|
1150
|
-
const loaderPath = `${out}
|
|
1151
|
-
const keptLoader = () =>
|
|
1230
|
+
// A loader program of an earlier run stays when this run checks no new one: it can be a committed file.
|
|
1231
|
+
const loaderPath = `${out}/${loaderName}.prg`;
|
|
1232
|
+
const keptLoader = () => {
|
|
1233
|
+
const earlier = loaderPrograms(out).filter((path) => path.endsWith(".prg"));
|
|
1234
|
+
return earlier.length === 0 ? {} : { kept: earlier };
|
|
1235
|
+
};
|
|
1152
1236
|
const notVerified = (fields: Record<string, unknown>) => ({ verified: false, ...fields, ...keptLoader() });
|
|
1153
1237
|
// The loader includes the source, so it is built only from a source that is identical to the image.
|
|
1154
1238
|
const notBuilt = (reason: string) => (state === undefined ? {} : { loader: notVerified({ reason: loaderRefused ?? reason }) });
|
|
@@ -1194,7 +1278,7 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1194
1278
|
const fileByte = (address: number) => copierBuild[2 + address - (loader.packed?.start ?? 0x0801)]!;
|
|
1195
1279
|
// A start screen of a captured stage: the show stage holds the packed program, as a cracktro holds the game.
|
|
1196
1280
|
const stageRow = knowledge.startScreen?.stage === undefined ? undefined : knowledge.startScreen;
|
|
1197
|
-
// The packed form: Exomizer packs the build of main.asm with the copier. Without Exomizer, or when its check fails, there is no new loader.
|
|
1281
|
+
// The packed form: Exomizer packs the build of main.asm with the copier. Without Exomizer, or when its check fails, there is no new loader program.
|
|
1198
1282
|
let packed: PackedLoader | undefined;
|
|
1199
1283
|
if (loader.packed !== undefined) {
|
|
1200
1284
|
try {
|
|
@@ -1215,11 +1299,11 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1215
1299
|
}
|
|
1216
1300
|
const program = stage?.program ?? packed?.program ?? copierBuild;
|
|
1217
1301
|
// The check runs the new loader from a scratch file. Only a loader whose check ran goes to --out, so a check
|
|
1218
|
-
// that cannot run (no host, or a host of another release) keeps the loader
|
|
1302
|
+
// that cannot run (no host, or a host of another release) keeps the loader program of an earlier run.
|
|
1219
1303
|
ensureLocal(projectRoot());
|
|
1220
1304
|
const scratch = `${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/${LOADER_CHECK_DIRECTORY}`;
|
|
1221
1305
|
mkdirSync(resolveProjectPath(scratch), { recursive: true });
|
|
1222
|
-
const checkPath = `${scratch}
|
|
1306
|
+
const checkPath = `${scratch}/${loaderName}.prg`;
|
|
1223
1307
|
writeFileSync(resolveProjectPath(checkPath), program);
|
|
1224
1308
|
// The unpack runs before the copier, or before the show stage, which then starts the loader.
|
|
1225
1309
|
const unpackFrames = (cycles: number | undefined) => (cycles === undefined ? LOADER_FRAMES : RUN_LIMIT_FRAMES + Math.ceil(cycles / PAL_FRAME_CYCLES));
|
|
@@ -1230,21 +1314,27 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1230
1314
|
return part.body[address - part.start]!;
|
|
1231
1315
|
};
|
|
1232
1316
|
const screenParts = stage === undefined ? [] : startScreenRanges(stageRow!).map(({ range }) => ({ start: range.start, body: Uint8Array.from({ length: range.end - range.start + 1 }, (_, offset) => stageByte(range.start + offset)) }));
|
|
1233
|
-
const stageRun = stage === undefined ? {} : { stage: { name: stageRow!.stage!, wait: stage.wait, continue: stage.continue, screen: stage.screen, parts: screenParts, frames: unpackFrames(stage.packed.cycles) + LOADER_FRAMES } };
|
|
1317
|
+
const stageRun = stage === undefined ? {} : { stage: { name: stageRow!.stage!, wait: stage.wait, continue: stage.continue, screen: stage.screen, parts: screenParts, ...(stage.colourRam === undefined ? {} : { colourRam: stage.colourRam }), frames: unpackFrames(stage.packed.cycles) + LOADER_FRAMES } };
|
|
1234
1318
|
let ran: LoaderRun;
|
|
1235
1319
|
try {
|
|
1236
1320
|
ran = await runLoader(checkPath, program, loader, state, { jump, copierSource, fileByte, copierFrames, ...(startScreen === undefined ? {} : { startScreen }), ...stageRun }, expected);
|
|
1237
1321
|
} catch (error) {
|
|
1238
1322
|
if (!isRefusal(error)) throw error;
|
|
1239
|
-
const what =
|
|
1240
|
-
return { output: { ...output, loader: notVerified({ reason: `The check of
|
|
1323
|
+
const what = loaderPrograms(out).length > 0 ? "kept the loader program of an earlier run" : "wrote no loader program";
|
|
1324
|
+
return { output: { ...output, loader: notVerified({ reason: `The check of ${loaderName}.prg did not run, so the script ${what}. ${error.message}` }) }, removed, failed: true };
|
|
1241
1325
|
} finally {
|
|
1242
1326
|
rmSync(resolveProjectPath(scratch), { recursive: true, force: true });
|
|
1243
1327
|
}
|
|
1244
|
-
|
|
1328
|
+
// A loader program of an earlier run with another build name goes: config.asm has other values now.
|
|
1329
|
+
for (const path of loaderPrograms(out).filter((item) => item !== loaderPath && item !== symbolsPath(loaderPath))) {
|
|
1330
|
+
rmSync(resolveProjectPath(path), { force: true });
|
|
1331
|
+
removed.push(path);
|
|
1332
|
+
}
|
|
1333
|
+
written.push(writeReported(loaderPath, program, { what: "--out" }), writeReported(symbolsPath(loaderPath), symbolsFileText(loaderSymbols(loaderMain.symbols, loaderBuilt.symbols, stage?.symbols ?? [])), { what: "--out" }));
|
|
1245
1334
|
if (stage !== undefined) written.push(writeReported(`${out}/${STAGE_FILE}`, stage.text, { what: "--out" }), writeReported(`${out}/${START_SCREEN_FILE}`, `${GENERATED_LINE}\n${START_SCREEN_CODE}`, { what: "--out" }));
|
|
1246
1335
|
output.loader = {
|
|
1247
1336
|
program: loaderPath,
|
|
1337
|
+
symbols: symbolsPath(loaderPath),
|
|
1248
1338
|
...(packed === undefined ? {} : { packed: { packedBytes: packed.packedBytes, unpackedBytes: packed.unpackedBytes } }),
|
|
1249
1339
|
...(stage === undefined
|
|
1250
1340
|
? {}
|
|
@@ -1276,15 +1366,21 @@ function exportValue(row: SourceSwitch): 0 | 1 {
|
|
|
1276
1366
|
|
|
1277
1367
|
const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
1278
1368
|
|
|
1279
|
-
/**
|
|
1280
|
-
|
|
1369
|
+
/**
|
|
1370
|
+
* The BASIC line that starts a PRG: its bytes, and the address of its first
|
|
1371
|
+
* SYS when the image holds it (the entry of a PRG without one in the
|
|
1372
|
+
* knowledge). Undefined when the first segment holds no BASIC line with a SYS.
|
|
1373
|
+
*/
|
|
1374
|
+
function basicStart(image: ProgramImage): { line: AddressRange; entry?: number } | undefined {
|
|
1281
1375
|
const first = image.segments[0];
|
|
1282
1376
|
if (first === undefined) return undefined;
|
|
1283
1377
|
const tokenized = parseTokenized(Uint8Array.from([first.start & 0xff, first.start >> 8, ...image.memory.subarray(first.start, first.end + 1)]));
|
|
1284
1378
|
if ("reason" in tokenized) return undefined;
|
|
1285
|
-
const sys = findHandoffs(tokenized.lines).find((handoff) => handoff.kind === "sys"
|
|
1286
|
-
|
|
1287
|
-
|
|
1379
|
+
const sys = findHandoffs(tokenized.lines).find((handoff) => handoff.kind === "sys");
|
|
1380
|
+
if (sys === undefined) return undefined;
|
|
1381
|
+
const line = { start: first.start, end: Math.min(first.end, tokenized.basicEnd - 1) };
|
|
1382
|
+
const address = "address" in sys ? sys.address : undefined;
|
|
1383
|
+
return address !== undefined && image.segments.some((segment) => address >= segment.start && address <= segment.end) ? { line, entry: address } : { line };
|
|
1288
1384
|
}
|
|
1289
1385
|
|
|
1290
1386
|
/** The parts of a region outside the holes. A part that is not the whole region has no element size: its length need not be a multiple of it. */
|
|
@@ -1323,9 +1419,10 @@ function freeRanges(knowledge: SourceKnowledge, memory: Uint8Array, instructions
|
|
|
1323
1419
|
for (const operand of knowledge.operands) {
|
|
1324
1420
|
const names = operand.symbol !== undefined ? [operand.symbol] : identifiers(operand.expression ?? "");
|
|
1325
1421
|
const targets = names.flatMap((item) => (addressOf.has(item) ? [(addressOf.get(item)! + (operand.symbol !== undefined ? operand.offset : 0)) & 0xffff] : []));
|
|
1326
|
-
|
|
1422
|
+
operandTargets.set(operand.address, targets);
|
|
1327
1423
|
}
|
|
1328
|
-
const
|
|
1424
|
+
const basic = basicStart(image);
|
|
1425
|
+
const entry = image.entry ?? basic?.entry;
|
|
1329
1426
|
return planDrops({
|
|
1330
1427
|
segments: image.segments,
|
|
1331
1428
|
memory,
|
|
@@ -1335,6 +1432,8 @@ function freeRanges(knowledge: SourceKnowledge, memory: Uint8Array, instructions
|
|
|
1335
1432
|
regions: effectiveRegions(knowledge.regions),
|
|
1336
1433
|
references: knowledge.references,
|
|
1337
1434
|
operandTargets,
|
|
1435
|
+
rom: romOf(image, knowledge, [], knowledge.coverage),
|
|
1436
|
+
...(basic === undefined ? {} : { basic: basic.line }),
|
|
1338
1437
|
changed: [...ranges.changed],
|
|
1339
1438
|
keep: [...ranges.keep],
|
|
1340
1439
|
drop: [...ranges.drop],
|
|
@@ -1564,7 +1663,7 @@ async function exportProject(call: Call): Promise<Record<string, unknown>> {
|
|
|
1564
1663
|
),
|
|
1565
1664
|
);
|
|
1566
1665
|
for (const file of exported.files) files.push(put(`src/${file.name}`, file.text));
|
|
1567
|
-
files.push(put(`baseline/${name}.prg`, baseline.program), put(`baseline/${name}.
|
|
1666
|
+
files.push(put(`baseline/${name}.prg`, baseline.program), put(symbolsPath(`baseline/${name}.prg`), symbolsFileText(shownSymbols)));
|
|
1568
1667
|
for (const test of tests) files.push(put(test.file, test.text));
|
|
1569
1668
|
ensureLocal(to);
|
|
1570
1669
|
const folder = basename(to);
|
|
@@ -1700,8 +1799,8 @@ await runScript({
|
|
|
1700
1799
|
options: {
|
|
1701
1800
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", help: "the folder for the source files, relative to the project folder", required: true },
|
|
1702
1801
|
entry: { ...OPTIONS.entry, multiple: true, help: "an address where code starts. The entry of the program, the routines and the code regions of the knowledge are entry points too" },
|
|
1703
|
-
space: { ...OPTIONS.space, help: "the knowledge space of the program: c64 (the default), drive8, or bank0 to bank255. --loader is for c64 only" },
|
|
1704
|
-
loader: { kind: "flag", help: "also write loader.asm and loader.prg
|
|
1802
|
+
space: { ...OPTIONS.space, help: "the knowledge space of the program: c64 (the default), drive8, loading, or bank0 to bank255. --loader is for c64 only" },
|
|
1803
|
+
loader: { kind: "flag", help: "also write loader.asm and the loader program <build>_loader.prg, clean_loader.prg with the defaults of config.asm, with its symbols in symbols/: the loader copies the segments into place, sets the entry state of the knowledge, and jumps to the entry. It is checked in the emulator. The loader leaves out the leftovers. When the check cannot run, the script keeps the loader program of an earlier run" },
|
|
1705
1804
|
"analyzer-names": { kind: "flag", help: "name an address that has no name of the user or the LLM, and no platform name, with its analyzer name" },
|
|
1706
1805
|
"max-listed": OPTIONS["max-listed"],
|
|
1707
1806
|
},
|
|
@@ -4,15 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import type { DatabaseSync } from "node:sqlite";
|
|
6
6
|
|
|
7
|
-
import { COVERAGE, coverageEntries, coverageSeedKinds, executedStarts } from "#src/c64.ts";
|
|
7
|
+
import { COVERAGE, coverageEntries, coverageSeedKinds, executedStarts, romOnlyRanges } from "#src/c64.ts";
|
|
8
8
|
|
|
9
|
-
export { coverageEntries, coverageSeedKinds, executedStarts };
|
|
10
|
-
import { FULL_COVERAGE } from "#src/host-client/coverage.ts";
|
|
9
|
+
export { coverageEntries, coverageSeedKinds, executedStarts, romOnlyRanges };
|
|
11
10
|
import { listRegions, type RegionRow } from "#src/knowledge/read.ts";
|
|
12
11
|
import { CODE_REGION_TYPES, DEFAULT_SPACE, isAnalyzer, isSemantic, type Space } from "#src/knowledge/schema.ts";
|
|
13
12
|
|
|
14
|
-
const FULL_MAP = FULL_COVERAGE;
|
|
15
|
-
|
|
16
13
|
/** The byte at an address of the analyzed image, or undefined outside it. */
|
|
17
14
|
export type ImageByte = (address: number) => number | undefined;
|
|
18
15
|
|
|
@@ -22,26 +19,6 @@ export function imageReader(bytes: Uint8Array, kind: "prg" | "flat64k"): ImageBy
|
|
|
22
19
|
return (address) => (address >= load && address - load + 2 < bytes.length ? bytes[address - load + 2] : undefined);
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
const ROM_ACCESS = COVERAGE.romRead | COVERAGE.romExecute;
|
|
26
|
-
const RAM_USE = COVERAGE.ramRead | COVERAGE.ramExecute;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The image bytes under ROM that the runs never used: the CPU read or ran the
|
|
30
|
-
* ROM there, and never read or ran the RAM. A JSR $FFE4 or an IRQ
|
|
31
|
-
* vector at $FFFE then leads into ROM, not into the leftover RAM bytes of a
|
|
32
|
-
* flat image, so the ranges are data for the analysis run.
|
|
33
|
-
*/
|
|
34
|
-
export function romOnlyRanges(map: Uint8Array, image: ImageByte): Array<{ start: number; end: number }> {
|
|
35
|
-
const ranges: Array<{ start: number; end: number }> = [];
|
|
36
|
-
for (let address = 0; address < FULL_MAP; address++) {
|
|
37
|
-
if ((map[address]! & ROM_ACCESS) === 0 || (map[address]! & RAM_USE) !== 0 || image(address) === undefined) continue;
|
|
38
|
-
const last = ranges.at(-1);
|
|
39
|
-
if (last !== undefined && last.end === address - 1) last.end = address;
|
|
40
|
-
else ranges.push({ start: address, end: address });
|
|
41
|
-
}
|
|
42
|
-
return ranges;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
22
|
/** Entry points from semantic knowledge beyond routines: the start of each code region, and each entry of a JMP table with its target. */
|
|
46
23
|
export function codeEntries(db: DatabaseSync | undefined, image: ImageByte, space: Space = DEFAULT_SPACE): number[] {
|
|
47
24
|
const entries: number[] = [];
|
|
@@ -30,7 +30,7 @@ To get the command list, run the script with no arguments.
|
|
|
30
30
|
| Record a play session of a person on the original | `record tests/record/start.json --out tests/recordings/play1 --play --joystick 1` |
|
|
31
31
|
| Record a session from steps only | `record tests/record/rooms.json --out tests/recordings/rooms` |
|
|
32
32
|
| Make sure that a recording replays on the original | `replay tests/recordings/rooms` |
|
|
33
|
-
| Compare the rebuild with a recording | `replay tests/recordings/rooms --checkpoint main_loop --state room --state lives --pin random_ptr:2 --rebuild build/
|
|
33
|
+
| Compare the rebuild with a recording | `replay tests/recordings/rooms --checkpoint main_loop --state room --state lives --pin random_ptr:2 --rebuild build/clean.prg --symbols build/symbols/clean.json --out .c64-re-tools/local/results/rooms` |
|
|
34
34
|
| Find what changed between two snapshot files | `diff .c64-re-tools/local/runs/rooms/before.vsf .c64-re-tools/local/runs/rooms/after.vsf` |
|
|
35
35
|
| Find what changed between two observations of runs | `diff .c64-re-tools/local/runs/rooms/results.json:room0 .c64-re-tools/local/runs/rooms/results.json:room3` |
|
|
36
36
|
| Find what changed between two memory files of runs | `diff .c64-re-tools/local/runs/a/all.bin .c64-re-tools/local/runs/b/all.bin --gap 4` |
|
|
@@ -233,6 +233,8 @@ The script first replays the recording on the original. The original must end th
|
|
|
233
233
|
`--checkpoint` and `--state` go together. `--pin` needs both of them. `--symbols` needs `--rebuild`. Give at most 16 `--state` and `--pin` items. Without `--checkpoint`, the script uses the comparison of the record file.
|
|
234
234
|
A `$` address is an address of the original. On the rebuild, it moves with the name before it.
|
|
235
235
|
|
|
236
|
+
A rebuild can be a loader with a start screen that RUN starts. If the symbols of the rebuild have `loader_start_screen_wait` and `loader_start_screen_continue`, the script runs the rebuild to the wait. Then it sets the PC to `loader_start_screen_continue`. The cycles before the wait do not count.
|
|
237
|
+
|
|
236
238
|
`body` holds `result`, `side`, `firstDifference`, `reason` and `files`. The section "Replay" of `references/recording-format.md` gives each field.
|
|
237
239
|
|
|
238
240
|
Do this for each result:
|
|
@@ -126,5 +126,6 @@ The body of the envelope of `replay` has these fields:
|
|
|
126
126
|
- `firstDifference`: on a FAIL, the checkpoint (1 is the first), the cycle on each side, and each state item that is different. An item has `address`, and the `original` and `rebuild` values as hex.
|
|
127
127
|
- `reason`: why the result is FAIL or INCONCLUSIVE.
|
|
128
128
|
- `movedSites`: the number of sites at a different address in the rebuild.
|
|
129
|
+
- `startScreen`: `skipped` when the rebuild went past the wait of its start screen.
|
|
129
130
|
- `idleReads`: the input reads of the rebuild that the recording had no value for. Such a read is at a site that the recording does not have, or after its end. Each got the fixed value `$FF` (joystick, keyboard, paddles) or `$00`. An input site that the site map did not find shows here.
|
|
130
131
|
- `files`: with `--out`, the RAM of each side at the first different checkpoint, `original-<n>.bin` and `rebuild-<n>.bin`.
|
|
@@ -8,7 +8,7 @@ A scenario is one JSON object in a project file.
|
|
|
8
8
|
{
|
|
9
9
|
"name": "player moves left",
|
|
10
10
|
"original": { "program": "original/game.prg", "symbols": "knowledge" },
|
|
11
|
-
"rebuild": { "program": "build/
|
|
11
|
+
"rebuild": { "program": "build/clean.prg", "symbols": "build/symbols/clean.json" },
|
|
12
12
|
"steps": [
|
|
13
13
|
{ "frames": 150 },
|
|
14
14
|
{ "load": true },
|
|
@@ -74,13 +74,15 @@ An `observe` step has a checkpoint name. A scenario can have each name only one
|
|
|
74
74
|
|
|
75
75
|
| Key | What the script compares |
|
|
76
76
|
|---|---|
|
|
77
|
-
| `memory` | A list of names, `$` addresses, or objects. An object has `address`, `size` (1 to 65536, default 1), `view` (`cpu` or `ram`, default `cpu`), `tolerance` (0 to 255, default 0) and `exclude`. The view `ram` reads the RAM under the ROMs and the I/O area. |
|
|
77
|
+
| `memory` | A list of names, `$` addresses, or objects. An object has `address`, `size` (1 to 65536, default 1), `view` (`cpu` or `ram`, default `cpu`), `tolerance` (0 to 255, default 0), `mask` and `exclude`. The view `ram` reads the RAM under the ROMs and the I/O area. |
|
|
78
78
|
| `registers` | A list of register names: `pc`, `a`, `x`, `y`, `sp`, `flags`. |
|
|
79
79
|
| `screen` | The screen of the rebuild against the screen of the original. `maxMismatchRatio` (default 0) is the largest permitted part of different pixels. `mask` is a list of rectangles (`x`, `y`, `width`, `height`) that the comparison does not include. |
|
|
80
80
|
| `vicii` | The VIC-II state: mode, screen address, scroll and colors. |
|
|
81
81
|
| `sprites` | A list of sprite numbers from 0 to 7. The script compares their position, color and flags. |
|
|
82
82
|
|
|
83
|
-
A `tolerance` is the largest permitted difference for each byte. A `mask` has at most 64 rectangles. A `mask` must not cover all of the screen: PAL is 384×272 pixels and NTSC is 384×247 pixels. A scenario can observe the screen at most at 64 checkpoints.
|
|
83
|
+
A `tolerance` is the largest permitted difference for each byte. A screen `mask` has at most 64 rectangles. A `mask` must not cover all of the screen: PAL is 384×272 pixels and NTSC is 384×247 pixels. A scenario can observe the screen at most at 64 checkpoints.
|
|
84
|
+
|
|
85
|
+
The `mask` of a memory object gives the bits that the comparison uses, as hex. It is one byte for all bytes of the range, for example `0f`, or one byte for each byte of the range. The comparison applies the mask first and then the `tolerance`. The colour RAM at $d800 has only 4 bits, and its other 4 bits are not stable. Thus observe the colour RAM with the mask `0f`.
|
|
84
86
|
|
|
85
87
|
`exclude` is a list of bytes in the observed range that the comparison does not include. Each has `address` and a `reason`, for example `{ "address": "$d01e", "reason": "latched sprite collision, not writable" }`. The result lists each excluded byte with its `address` and `reason`.
|
|
86
88
|
|