@henols/c64-re-tools 2.5.0-rc.1 → 2.5.1-rc.1
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 -1
- package/skills/c64-basic/SKILL.md +2 -1
- package/skills/c64-development/SKILL.md +1 -1
- package/skills/c64-disk/SKILL.md +2 -1
- package/skills/c64-docs/SKILL.md +2 -1
- package/skills/c64-knowledge/SKILL.md +41 -10
- package/skills/c64-knowledge/scripts/knowledge.ts +48 -18
- package/skills/c64-memory-map/SKILL.md +2 -1
- package/skills/c64-packer/SKILL.md +2 -1
- package/skills/c64-provenance/SKILL.md +2 -1
- package/skills/c64-reverse-engineering/SKILL.md +6 -3
- package/skills/c64-source/SKILL.md +57 -14
- package/skills/c64-source/scripts/lib/loader.ts +47 -18
- package/skills/c64-source/scripts/lib/source.ts +47 -14
- package/skills/c64-source/scripts/lib/stage.ts +273 -0
- package/skills/c64-source/scripts/lib/start-screen.asm +28 -2
- package/skills/c64-source/scripts/source.ts +391 -118
- package/skills/c64-static-analysis/SKILL.md +2 -1
- package/skills/c64-testing/SKILL.md +2 -1
- package/skills/c64-unpacker/SKILL.md +4 -2
- package/skills/c64-unpacker/scripts/lib/machine.ts +7 -3
- package/src/cli/main.ts +4 -2
- package/src/cli/status.ts +0 -1
- package/src/knowledge/read.ts +11 -1
- package/src/knowledge/schema.ts +13 -3
- package/src/knowledge/start-screen.ts +64 -0
- package/src/knowledge/text.ts +3 -0
- package/src/knowledge/write.ts +42 -7
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// FAIL.
|
|
11
11
|
|
|
12
12
|
import { createHash } from "node:crypto";
|
|
13
|
-
import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { basename, join, relative, sep } from "node:path";
|
|
15
15
|
|
|
16
16
|
import { isRefusal, Refusal } from "#src/errors.ts";
|
|
@@ -26,8 +26,8 @@ import { conflicts } from "#src/knowledge/conflicts.ts";
|
|
|
26
26
|
import { openForRead, withWrite } from "#src/knowledge/database.ts";
|
|
27
27
|
import { identifiers } from "#src/knowledge/expression.ts";
|
|
28
28
|
import { analyzedBytes, memoryRows, programCoverage, requireProgram, type ProgramImage } from "#src/knowledge/program.ts";
|
|
29
|
-
import { ANALYZER_NAME_ORDER, baseValue, currentRevision, currentStartScreen, startScreenRanges, listAnalyzerNames, listComments, listMacros, listMacroUses, listModules, listOperands, listPatches, listReferences, listRegions, listReleases, listSpaces, listSwitches, listSymbols, type ReleaseRow, type SymbolRow } from "#src/knowledge/read.ts";
|
|
30
|
-
import { CODE_REGION_TYPES, DEFAULT_SPACE, isSemantic, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
|
|
29
|
+
import { ANALYZER_NAME_ORDER, baseValue, currentRevision, currentStartScreen, startScreenRanges, type StartScreenRow, listAnalyzerNames, listComments, listMacros, listMacroUses, listModules, listOperands, listPatches, listReferences, listRegions, listReleases, listSpaces, listSwitches, listSymbols, type ReleaseRow, type SymbolRow } from "#src/knowledge/read.ts";
|
|
30
|
+
import { CODE_REGION_TYPES, DEFAULT_SPACE, isSemantic, LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
|
|
31
31
|
import { subtract, write } from "#src/knowledge/write.ts";
|
|
32
32
|
import { assemble, symbolsFileText } from "#src/native/acme.ts";
|
|
33
33
|
import { analyze } from "#src/native/ghidra/analyze.ts";
|
|
@@ -44,7 +44,9 @@ import {
|
|
|
44
44
|
LOADER_JUMP,
|
|
45
45
|
loaderLimits,
|
|
46
46
|
packLoader,
|
|
47
|
+
packParts,
|
|
47
48
|
planLoader,
|
|
49
|
+
startScreenPlan,
|
|
48
50
|
rasterLine,
|
|
49
51
|
loaderState,
|
|
50
52
|
simulate,
|
|
@@ -57,8 +59,11 @@ import {
|
|
|
57
59
|
type EntryState,
|
|
58
60
|
type LoaderPlan,
|
|
59
61
|
type PackedLoader,
|
|
62
|
+
type StartScreenPlan,
|
|
60
63
|
} from "./lib/loader.ts";
|
|
61
64
|
import { instructionWith, OPCODES } from "#src/opcodes.ts";
|
|
65
|
+
import { capturedColourRam } from "#src/knowledge/start-screen.ts";
|
|
66
|
+
import { planStage, STAGE_CODE_END, STAGE_FILE, STAGE_START, stageParts, stageText, type StageInput, type StagePart, type StagePlan } from "./lib/stage.ts";
|
|
62
67
|
import { freeName, planDrops, readmeText, rewriteTest } from "./lib/export.ts";
|
|
63
68
|
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";
|
|
64
69
|
|
|
@@ -90,8 +95,8 @@ function readKnowledge(space: Space, analyzerNames = false) {
|
|
|
90
95
|
return {
|
|
91
96
|
revision: currentRevision(db),
|
|
92
97
|
program: requireProgram(db, space),
|
|
93
|
-
// The coverage
|
|
94
|
-
coverage:
|
|
98
|
+
// The coverage of the space: a run of the C64, or of a captured stage that coverage put into that space.
|
|
99
|
+
coverage: programCoverage(db, space)?.map,
|
|
95
100
|
symbols: analyzerNames ? withAnalyzerNames(symbols, second) : symbols,
|
|
96
101
|
// Analyzer routines are entry points for the decode, also without --analyzer-names.
|
|
97
102
|
routines: [...symbols, ...second].filter((symbol) => symbol.kind === "routine").map((symbol) => symbol.address),
|
|
@@ -429,7 +434,7 @@ function compareBuilds(built: Assembled, ranges: readonly AddressRange[], base:
|
|
|
429
434
|
* from config.asm: a define of a switch is an error, because config.asm also
|
|
430
435
|
* gives it a value. A switch without a value has its default.
|
|
431
436
|
*/
|
|
432
|
-
function withValues(files: Array<{ name: string; text: string }>, laid: Pick<Layout, "switches" | "patches" | "startScreen">, values: ReadonlyMap<string, number>): Array<{ name: string; text: string }> {
|
|
437
|
+
function withValues(files: Array<{ name: string; text: string }>, laid: Pick<Layout, "switches" | "patches" | "startScreen" | "leftovers">, values: ReadonlyMap<string, number>): Array<{ name: string; text: string }> {
|
|
433
438
|
return files.map((file) => (file.name === CONFIG_FILE ? { ...file, text: configText(laid, values) } : file));
|
|
434
439
|
}
|
|
435
440
|
|
|
@@ -524,8 +529,8 @@ interface LoaderRun {
|
|
|
524
529
|
verified: boolean;
|
|
525
530
|
differences: string[];
|
|
526
531
|
stop?: { pc: string; port: string; cause?: string; history: string[] };
|
|
527
|
-
/** The start screen: shown with its VIC-II values, and still waiting after START_SCREEN_FRAMES frames. */
|
|
528
|
-
startScreen?: { shown: boolean; waits: boolean; wait: string; continue: string };
|
|
532
|
+
/** The start screen: shown with its VIC-II values, and still waiting after START_SCREEN_FRAMES frames. A start screen of a stage also has the bytes of the stage. */
|
|
533
|
+
startScreen?: { shown: boolean; waits: boolean; wait: string; continue: string; stage?: string };
|
|
529
534
|
}
|
|
530
535
|
|
|
531
536
|
/** The frames that the check of the loader lets the start screen wait without a key. */
|
|
@@ -539,12 +544,14 @@ interface LoaderRunPlan {
|
|
|
539
544
|
jump: number;
|
|
540
545
|
/** The wait of the start screen and the code after it, when the loader has a start screen. */
|
|
541
546
|
startScreen?: { wait: number; continue: number };
|
|
547
|
+
/** 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. */
|
|
548
|
+
stage?: { name: string; wait: number; continue: number; screen: StartScreenPlan; parts: StagePart[]; colourRam?: Uint8Array; frames: number };
|
|
542
549
|
copierSource: number;
|
|
543
550
|
fileByte: (address: number) => number;
|
|
544
551
|
copierFrames: number;
|
|
545
552
|
}
|
|
546
553
|
|
|
547
|
-
async function runLoader(path: string, program: Buffer, plan: LoaderPlan,
|
|
554
|
+
async function runLoader(path: string, program: Buffer, plan: LoaderPlan, state: EntryState, run: LoaderRunPlan, expected: (address: number) => number): Promise<LoaderRun> {
|
|
548
555
|
const { jump, copierSource, fileByte } = run;
|
|
549
556
|
const client = await ViceSessionClient.open({ videoStandard: "pal" });
|
|
550
557
|
try {
|
|
@@ -552,37 +559,60 @@ async function runLoader(path: string, program: Buffer, plan: LoaderPlan, image:
|
|
|
552
559
|
if (!(await autostartLoaded(client, path, program))) return { verified: false, differences: ["The loader was not in memory after autostart."] };
|
|
553
560
|
await client.keyboard(textToPetscii("RUN\n"));
|
|
554
561
|
// A stop before the copier or the jump gives $01, the last instructions and the first byte that is not as planned.
|
|
555
|
-
|
|
562
|
+
// Before the show stage moves on, the copier is not in place yet: then the stop has no cause from it.
|
|
563
|
+
const stopped = async (pc: number, copied: boolean, what: string, loaderRan = true): Promise<LoaderRun> => {
|
|
556
564
|
const ram = await readRam(client, 0x0000, 0x10000);
|
|
557
565
|
const port = Buffer.from((await client.memoryRead({ address: 0x0001, size: 1, space: "c64", view: "cpu" })).data, "hex")[0]!;
|
|
558
566
|
const history = (await client.cpuHistory({ limit: STOP_HISTORY, space: "c64" })).entries.map((entry) => `${formatC64Address(entry.address)} ${entry.text}`);
|
|
559
|
-
const cause = stopCause(ram, plan, copierSource, fileByte, copied, expected);
|
|
567
|
+
const cause = loaderRan ? stopCause(ram, plan, copierSource, fileByte, copied, expected) : undefined;
|
|
560
568
|
const port01 = `$${port.toString(16).padStart(2, "0")}`;
|
|
561
569
|
return { verified: false, differences: [`The loader did not get to ${what}; it stopped at ${formatC64Address(pc)}.`], stop: { pc: formatC64Address(pc), port: port01, ...(cause === undefined ? {} : { cause }), history } };
|
|
562
570
|
};
|
|
563
|
-
const copier = await client.runUntil({ target: { kind: "address", address: plan.copier, space: "c64" }, timeoutFrames: run.copierFrames });
|
|
564
|
-
if (!copier.reached) return await stopped(copier.pc, false, `its copier at ${formatC64Address(plan.copier)}`);
|
|
565
571
|
// The start screen waits for a key or a fire button. The emulator cannot press a key of the keyboard matrix
|
|
566
572
|
// on each VICE, so the check lets it wait, then sets the PC to the code after the wait.
|
|
567
573
|
let screen: LoaderRun["startScreen"];
|
|
568
574
|
const screenDifferences: string[] = [];
|
|
569
|
-
|
|
570
|
-
const labels = { wait: formatC64Address(
|
|
571
|
-
const atWait = await client.runUntil({ target: { kind: "address", address:
|
|
572
|
-
if (!atWait.reached) return await stopped(atWait.pc,
|
|
573
|
-
const held = await client.runUntil({ target: { kind: "address", address:
|
|
575
|
+
const showScreen = async (at: { wait: number; continue: number }, wanted: StartScreenPlan, frames: number, copied: boolean, parts: readonly StagePart[] = [], colourRam?: Uint8Array): Promise<LoaderRun | undefined> => {
|
|
576
|
+
const labels = { wait: formatC64Address(at.wait), continue: formatC64Address(at.continue) };
|
|
577
|
+
const atWait = await client.runUntil({ target: { kind: "address", address: at.wait, space: "c64" }, timeoutFrames: frames });
|
|
578
|
+
if (!atWait.reached) return await stopped(atWait.pc, copied, `its start screen at ${labels.wait}`, parts.length === 0);
|
|
579
|
+
const held = await client.runUntil({ target: { kind: "address", address: at.continue, space: "c64" }, timeoutFrames: START_SCREEN_FRAMES });
|
|
574
580
|
const vic = Buffer.from((await client.ioRead(0xd000, 0x2f)).data, "hex");
|
|
575
581
|
const bank = 3 - (Buffer.from((await client.ioRead(0xdd00, 1)).data, "hex")[0]! & 0x03);
|
|
576
|
-
const
|
|
582
|
+
const before = screenDifferences.length;
|
|
577
583
|
const shown: Array<[number, number]> = [[0x11, wanted.d011], [0x15, 0], [0x16, wanted.d016], [0x18, wanted.d018], [0x20, wanted.border], [0x21, wanted.background]];
|
|
578
584
|
for (const [register, value] of shown) {
|
|
579
585
|
const mask = VIC_DISPLAY_REGISTERS.find((item) => item.register === register)!.mask;
|
|
580
586
|
if ((vic[register]! & mask) !== (value & mask)) screenDifferences.push(`the start screen has ${formatC64Address(0xd000 + register)} = $${(vic[register]! & mask).toString(16).padStart(2, "0")}, not $${(value & mask).toString(16).padStart(2, "0")}`);
|
|
581
587
|
}
|
|
582
588
|
if (bank !== wanted.bank) screenDifferences.push(`the start screen is in VIC bank ${bank}, not ${wanted.bank}`);
|
|
583
|
-
screen
|
|
589
|
+
// The bytes of the screen of a stage: the first wrong byte of each part.
|
|
590
|
+
for (const part of parts) {
|
|
591
|
+
const ram = await readRam(client, part.start, part.body.length);
|
|
592
|
+
const wrong = part.body.findIndex((byte, offset) => ram[offset] !== byte);
|
|
593
|
+
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")}`);
|
|
594
|
+
}
|
|
595
|
+
// The colour RAM of a captured stage: the first wrong colour.
|
|
596
|
+
if (colourRam !== undefined) {
|
|
597
|
+
const colours = Buffer.from((await client.ioRead(0xd800, colourRam.length)).data, "hex");
|
|
598
|
+
const wrong = colourRam.findIndex((value, offset) => (colours[offset]! & 0x0f) !== value);
|
|
599
|
+
if (wrong >= 0) screenDifferences.push(`the colour RAM has ${colours[wrong]! & 0x0f} at ${formatC64Address(0xd800 + wrong)}, not ${colourRam[wrong]}`);
|
|
600
|
+
}
|
|
601
|
+
screen = { shown: screenDifferences.length === before, waits: !held.reached, ...labels, ...(run.stage === undefined ? {} : { stage: run.stage.name }) };
|
|
584
602
|
if (held.reached) screenDifferences.push(`the start screen did not wait: it got to ${labels.continue} without a key or a fire button`);
|
|
585
|
-
if (!held.reached) await client.registersSet("c64", { pc:
|
|
603
|
+
if (!held.reached) await client.registersSet("c64", { pc: at.continue });
|
|
604
|
+
return undefined;
|
|
605
|
+
};
|
|
606
|
+
// The show stage of a captured stage runs before the loader.
|
|
607
|
+
if (run.stage !== undefined) {
|
|
608
|
+
const stop = await showScreen(run.stage, run.stage.screen, run.stage.frames, false, run.stage.parts, run.stage.colourRam);
|
|
609
|
+
if (stop !== undefined) return stop;
|
|
610
|
+
}
|
|
611
|
+
const copier = await client.runUntil({ target: { kind: "address", address: plan.copier, space: "c64" }, timeoutFrames: run.copierFrames });
|
|
612
|
+
if (!copier.reached) return await stopped(copier.pc, false, `its copier at ${formatC64Address(plan.copier)}`);
|
|
613
|
+
if (run.startScreen !== undefined && plan.startScreen !== undefined) {
|
|
614
|
+
const stop = await showScreen(run.startScreen, plan.startScreen, LOADER_FRAMES, true);
|
|
615
|
+
if (stop !== undefined) return stop;
|
|
586
616
|
}
|
|
587
617
|
const atJump = await client.runUntil({ target: { kind: "address", address: jump, space: "c64" }, timeoutFrames: LOADER_FRAMES });
|
|
588
618
|
if (!atJump.reached) return await stopped(atJump.pc, true, `its jump to the entry at ${formatC64Address(jump)}`);
|
|
@@ -595,8 +625,9 @@ async function runLoader(path: string, program: Buffer, plan: LoaderPlan, image:
|
|
|
595
625
|
const differences: string[] = [];
|
|
596
626
|
const byte = (value: number) => `$${value.toString(16).padStart(2, "0")}`;
|
|
597
627
|
const differ = (what: string, got: number, wanted: number) => got !== wanted && differences.push(`${what} is ${byte(got)}, not ${byte(wanted)}`);
|
|
598
|
-
|
|
599
|
-
|
|
628
|
+
// The leftovers are not loaded: only the loaded ranges have the bytes of the build.
|
|
629
|
+
for (const part of plan.loaded) {
|
|
630
|
+
for (let address = Math.max(part.start, 2); address <= part.end; address++) differ(formatC64Address(address), memory[address]!, expected(address));
|
|
600
631
|
}
|
|
601
632
|
for (let address = 2; address < 0x400; address++) if (address !== plan.stackByte) differ(formatC64Address(address), memory[address]!, state.pages[address]!);
|
|
602
633
|
differ("$00", port[0]!, state.port[0]);
|
|
@@ -663,8 +694,11 @@ function sourceMapText(rendered: Rendered, space: string, revision: string | nul
|
|
|
663
694
|
return `${head},\n"labels": [\n${labels.join(",\n")}\n],\n"items": [\n${items.join(",\n")}\n]}\n`;
|
|
664
695
|
}
|
|
665
696
|
|
|
697
|
+
/** The folder in .c64-re-tools/local/ where the check of the loader runs the new loader.prg. */
|
|
698
|
+
const LOADER_CHECK_DIRECTORY = "loader-check";
|
|
699
|
+
|
|
666
700
|
/** The files of the loader. Only a run with --loader writes them, so only such a run removes them. */
|
|
667
|
-
const LOADER_FILES: ReadonlySet<string> = new Set(["loader.asm", "loader.prg", START_SCREEN_FILE]);
|
|
701
|
+
const LOADER_FILES: ReadonlySet<string> = new Set(["loader.asm", "loader.prg", START_SCREEN_FILE, STAGE_FILE]);
|
|
668
702
|
|
|
669
703
|
/** The start of the line of loader.asm that gives the knowledge revision of the loader. */
|
|
670
704
|
const LOADER_REVISION = "Loader generated by c64-source from knowledge revision ";
|
|
@@ -690,8 +724,9 @@ function staleLoader(out: string, revision: string): { files: string[]; revision
|
|
|
690
724
|
/**
|
|
691
725
|
* Removes the generated .asm files of an earlier run that this run does not
|
|
692
726
|
* write, and an earlier not_executed.json and source-map.json. An earlier
|
|
693
|
-
* loader.asm
|
|
694
|
-
*
|
|
727
|
+
* loader.asm stays unless this run has --loader: a source of the user can
|
|
728
|
+
* include loader.asm. An earlier loader.prg always stays: only a new loader.prg
|
|
729
|
+
* whose check ran replaces it. Other files stay. Gives the names it removed.
|
|
695
730
|
*/
|
|
696
731
|
function removeOldFiles(out: string, keep: ReadonlySet<string>, loaderRun: boolean): string[] {
|
|
697
732
|
const directory = resolveProjectPath(out);
|
|
@@ -702,7 +737,7 @@ function removeOldFiles(out: string, keep: ReadonlySet<string>, loaderRun: boole
|
|
|
702
737
|
const name = entry.name;
|
|
703
738
|
const path = join(directory, name);
|
|
704
739
|
if (LOADER_FILES.has(name) && !loaderRun) continue;
|
|
705
|
-
const old = name ===
|
|
740
|
+
const old = name === NOT_EXECUTED_FILE || name === SOURCE_MAP_FILE || (name.endsWith(".asm") && !keep.has(name) && readFileSync(path, "utf8").startsWith(GENERATED_MARK));
|
|
706
741
|
if (!old) continue;
|
|
707
742
|
rmSync(path, { force: true });
|
|
708
743
|
removed.push(name);
|
|
@@ -732,6 +767,10 @@ interface SourceOptions {
|
|
|
732
767
|
loaderHeader?: string[];
|
|
733
768
|
/** The source of an export: no config.asm, so START_SCREEN has the default of start_screen.asm. */
|
|
734
769
|
exported?: boolean;
|
|
770
|
+
/** Put the free ranges of the program into leftover files, which only LEFTOVERS = 1 builds. */
|
|
771
|
+
leftovers?: boolean;
|
|
772
|
+
/** The switch values of the build that the loader loads. The default is `values`. */
|
|
773
|
+
loaderValues?: ReadonlyMap<string, number>;
|
|
735
774
|
}
|
|
736
775
|
|
|
737
776
|
/**
|
|
@@ -747,6 +786,7 @@ async function buildSource(knowledge: SourceKnowledge, options: SourceOptions) {
|
|
|
747
786
|
const romUse = romUseOfProgram(coverage, image.state);
|
|
748
787
|
const platform = platformNamesFor(romUse);
|
|
749
788
|
const { instructions, dataOnly } = options.decoded ?? (await decode(image, knowledge, options.entries, coverage));
|
|
789
|
+
const leftovers = options.leftovers === true && !dataOnly ? leftoversOf(knowledge, instructions) : [];
|
|
750
790
|
const laid = layout({
|
|
751
791
|
segments: image.segments,
|
|
752
792
|
byteAt: image.byteAt,
|
|
@@ -764,50 +804,23 @@ async function buildSource(knowledge: SourceKnowledge, options: SourceOptions) {
|
|
|
764
804
|
macros: knowledge.macros,
|
|
765
805
|
macroUses: knowledge.macroUses,
|
|
766
806
|
startScreen: knowledge.startScreen !== undefined && options.exported !== true,
|
|
807
|
+
leftovers,
|
|
767
808
|
...(coverage === undefined || !options.notExecutedMarks ? {} : { coverage }),
|
|
768
809
|
// The platform names are C64 names: drive code and banks get none. A ROM that the program does not use gives none.
|
|
769
810
|
...(space === DEFAULT_SPACE ? { platform, platformLeftOut: leftOutNames(platform), describe: describeAddress, decode: decodeRegister, io: IO_RAM } : {}),
|
|
770
811
|
});
|
|
771
812
|
const asBytes = await probe(laid);
|
|
772
813
|
const { header } = options;
|
|
773
|
-
let loader: LoaderPlan | undefined;
|
|
774
|
-
// An image without its entry has no program: the source is still written and checked, but the run fails.
|
|
775
|
-
const missingEntry = entryOutsideImage(image.entry, image.segments);
|
|
776
|
-
// A loader that cannot be planned does not stop the source: the source is written and checked, and the result says why.
|
|
777
|
-
const { state } = options;
|
|
778
|
-
let loaderRefused: string | undefined = state === undefined ? undefined : missingEntry;
|
|
779
|
-
if (state !== undefined && missingEntry === undefined) {
|
|
780
|
-
const segments = image.segments.map((segment) => ({ ...segment, files: laid.pieces.filter((piece) => piece.start >= segment.start && piece.start <= segment.end).map((piece) => piece.file) }));
|
|
781
|
-
try {
|
|
782
|
-
const entryName = laid.names.get(image.entry!);
|
|
783
|
-
loader = planLoader({
|
|
784
|
-
segments,
|
|
785
|
-
byteAt: image.byteAt,
|
|
786
|
-
state,
|
|
787
|
-
entry: image.entry!,
|
|
788
|
-
...(entryName === undefined ? {} : { entryName }),
|
|
789
|
-
switches: hasSwitchFile(laid),
|
|
790
|
-
config: hasConfigFile(laid),
|
|
791
|
-
macros: laid.macros.length > 0,
|
|
792
|
-
header: options.loaderHeader ?? [],
|
|
793
|
-
...(knowledge.startScreen === undefined ? {} : { startScreen: knowledge.startScreen }),
|
|
794
|
-
});
|
|
795
|
-
} catch (error) {
|
|
796
|
-
if (!isRefusal(error)) throw error;
|
|
797
|
-
loaderRefused = error.message;
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
814
|
// With a mark, every file starts with it.
|
|
801
815
|
const { mark } = options;
|
|
802
816
|
const marked = (list: Array<{ name: string; text: string }>) => (mark === undefined ? list : list.map((file) => (file.name === CONFIG_FILE ? file : { ...file, text: `${mark}\n${file.text}` })));
|
|
803
817
|
const markLines = mark === undefined ? 0 : 1;
|
|
804
|
-
const loaderFiles = loader === undefined ? [] : [{ name: "loader.asm", text: loader.text }, ...(loader.startScreen === undefined ? [] : [{ name: START_SCREEN_FILE, text: START_SCREEN_CODE }])];
|
|
805
818
|
const numbers = new Map<number, string>();
|
|
806
819
|
const asInstructions = new Map<number, string>();
|
|
807
820
|
let rendered = render(laid, asBytes, header, numbers, asInstructions);
|
|
808
821
|
if (laid.macroUses.size > 0) for (const [start, reason] of await probeUses(laid, rendered, image)) asInstructions.set(start, reason);
|
|
809
822
|
if (asInstructions.size > 0) rendered = render(laid, asBytes, header, numbers, asInstructions);
|
|
810
|
-
let files = marked(
|
|
823
|
+
let files = marked(rendered.files);
|
|
811
824
|
let built = await assembleFiles(withValues(files, laid, options.values), "main.asm");
|
|
812
825
|
for (let round = 0; round < ROUNDS && (rendered.expressions.length > 0 || rendered.uses.length > 0); round++) {
|
|
813
826
|
const blamed = blame(rendered, built, image, markLines);
|
|
@@ -815,22 +828,84 @@ async function buildSource(knowledge: SourceKnowledge, options: SourceOptions) {
|
|
|
815
828
|
for (const [address, reason] of blamed.numbers) numbers.set(address, reason);
|
|
816
829
|
for (const [start, reason] of blamed.uses) asInstructions.set(start, reason);
|
|
817
830
|
rendered = render(laid, asBytes, header, numbers, asInstructions);
|
|
818
|
-
files = marked(
|
|
831
|
+
files = marked(rendered.files);
|
|
819
832
|
built = await assembleFiles(withValues(files, laid, options.values), "main.asm");
|
|
820
833
|
}
|
|
821
|
-
|
|
834
|
+
|
|
835
|
+
let loader: LoaderPlan | undefined;
|
|
836
|
+
/** The build of main.asm that the loader loads: the switch values of the loader. */
|
|
837
|
+
let loaderMain: { program: Buffer; start: number } | undefined;
|
|
838
|
+
// An image without its entry has no program: the source is still written and checked, but the run fails.
|
|
839
|
+
const missingEntry = entryOutsideImage(image.entry, image.segments);
|
|
840
|
+
// A loader that cannot be planned does not stop the source: the source is written and checked, and the result says why.
|
|
841
|
+
const { state } = options;
|
|
842
|
+
let loaderRefused: string | undefined = state === undefined ? undefined : missingEntry;
|
|
843
|
+
if (state !== undefined && missingEntry === undefined) {
|
|
844
|
+
const main = options.loaderValues === undefined ? built : await assembleFiles(withValues(files, laid, options.loaderValues), "main.asm");
|
|
845
|
+
if (main.program === undefined) loaderRefused = "The source does not assemble with the switch values of the loader.";
|
|
846
|
+
else {
|
|
847
|
+
const program = main.program;
|
|
848
|
+
const start = main.start!;
|
|
849
|
+
loaderMain = { program, start };
|
|
850
|
+
try {
|
|
851
|
+
const entryName = laid.names.get(image.entry!);
|
|
852
|
+
loader = planLoader({
|
|
853
|
+
segments: loadedParts(laid, image.segments),
|
|
854
|
+
byteAt: (address) => program[2 + address - start]!,
|
|
855
|
+
state,
|
|
856
|
+
entry: image.entry!,
|
|
857
|
+
...(entryName === undefined ? {} : { entryName }),
|
|
858
|
+
switches: hasSwitchFile(laid),
|
|
859
|
+
config: hasConfigFile(laid),
|
|
860
|
+
macros: laid.macros.length > 0,
|
|
861
|
+
header: options.loaderHeader ?? [],
|
|
862
|
+
// A start screen of a stage shows before the loader, in the show stage, while the program is still packed: the copier has none.
|
|
863
|
+
...(knowledge.startScreen === undefined || knowledge.startScreen.stage !== undefined ? {} : { startScreen: knowledge.startScreen }),
|
|
864
|
+
...(knowledge.startScreen?.stage === undefined ? {} : { packed: true }),
|
|
865
|
+
});
|
|
866
|
+
} catch (error) {
|
|
867
|
+
if (!isRefusal(error)) throw error;
|
|
868
|
+
loaderRefused = error.message;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
if (loader !== undefined) files = [...files, ...marked([{ name: "loader.asm", text: loader.text }, ...(loader.startScreen === undefined ? [] : [{ name: START_SCREEN_FILE, text: START_SCREEN_CODE }])])];
|
|
873
|
+
return { romUse, instructions, dataOnly, laid, rendered, files, built, loader, loaderMain, missingEntry, loaderRefused };
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** The ranges that the loader loads, each with its files: the segments without the leftovers. */
|
|
877
|
+
function loadedParts(laid: Pick<Layout, "pieces">, segments: readonly AddressRange[]): Array<AddressRange & { files: string[] }> {
|
|
878
|
+
const parts: Array<AddressRange & { files: string[] }> = [];
|
|
879
|
+
for (const segment of segments) {
|
|
880
|
+
let open: (AddressRange & { files: string[] }) | undefined;
|
|
881
|
+
for (const piece of laid.pieces.filter((item) => item.start >= segment.start && item.start <= segment.end)) {
|
|
882
|
+
if (piece.leftover) {
|
|
883
|
+
open = undefined;
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
if (open === undefined) {
|
|
887
|
+
open = { start: piece.start, end: piece.end, files: [piece.file] };
|
|
888
|
+
parts.push(open);
|
|
889
|
+
} else {
|
|
890
|
+
open.end = piece.end;
|
|
891
|
+
open.files.push(piece.file);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
return parts;
|
|
822
896
|
}
|
|
823
897
|
|
|
824
898
|
/**
|
|
825
899
|
* Assembles loader.asm with the switch values and simulates its copies: the
|
|
826
|
-
* loader as it loads, then every copy in its order, byte by byte.
|
|
827
|
-
*
|
|
900
|
+
* loader as it loads, then every copy in its order, byte by byte. `main` is
|
|
901
|
+
* the build of main.asm with the same values: the loaded ranges must get its
|
|
902
|
+
* bytes. A layout other than the plan is a defect of the script.
|
|
828
903
|
*/
|
|
829
904
|
async function buildLoader(
|
|
830
905
|
files: Array<{ name: string; text: string }>,
|
|
831
906
|
laid: Layout,
|
|
832
907
|
loader: LoaderPlan,
|
|
833
|
-
|
|
908
|
+
main: { program: Buffer; start: number },
|
|
834
909
|
state: EntryState,
|
|
835
910
|
values: ReadonlyMap<string, number>,
|
|
836
911
|
): Promise<{ program: Buffer; symbols: AssembledSymbol[]; jump: number; copierSource: number; expected: (address: number) => number; startScreen?: { wait: number; continue: number } } | { diagnostics: Diagnostic[] }> {
|
|
@@ -839,7 +914,7 @@ async function buildLoader(
|
|
|
839
914
|
const program = loaderBuilt.program;
|
|
840
915
|
const memory = new Int16Array(0x10000).fill(-1);
|
|
841
916
|
program.subarray(2).forEach((byte, offset) => (memory[loaderBuilt.start! + offset] = byte));
|
|
842
|
-
const expected = (address: number) => (
|
|
917
|
+
const expected = (address: number) => (loader.loaded.some((part) => address >= part.start && address <= part.end) ? main.program[2 + address - main.start]! : state.pages[address]!);
|
|
843
918
|
const wrongPacking = loader.blocks.find((block) => {
|
|
844
919
|
for (let address = block.range.start; address <= block.range.end; address++) if (memory[block.packedAt + address - block.range.start] !== block.bytes(address)) return true;
|
|
845
920
|
return false;
|
|
@@ -859,6 +934,113 @@ async function buildLoader(
|
|
|
859
934
|
return { program, symbols: loaderBuilt.symbols ?? [], jump, copierSource: symbolValue(COPIER_SOURCE), expected, ...(startScreen === undefined ? {} : { startScreen }) };
|
|
860
935
|
}
|
|
861
936
|
|
|
937
|
+
/**
|
|
938
|
+
* The bytes of a captured stage that its start screen uses: the parts of the
|
|
939
|
+
* screen, and with a call every byte of the stage that is not free when the
|
|
940
|
+
* call is the entry (freeRanges, from the coverage of the stage). Each patch
|
|
941
|
+
* of the stage whose switch default is not its base value is in, as in the
|
|
942
|
+
* default build. Pages 0-3 are left out: the unpacker of Exomizer uses them.
|
|
943
|
+
*/
|
|
944
|
+
async function stageBytes(row: StartScreenRow): Promise<{ parts: StagePart[]; colourRam?: Uint8Array }> {
|
|
945
|
+
const stage = row.stage!;
|
|
946
|
+
const knowledge = readKnowledge(stage);
|
|
947
|
+
const colourRam = row.colourRam === true ? capturedColourRam(knowledge.program.state) : undefined;
|
|
948
|
+
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}.`);
|
|
949
|
+
const image = knowledge.program;
|
|
950
|
+
const memory = Uint8Array.from(image.memory);
|
|
951
|
+
const addresses = knowledge.symbols.map((symbol) => `${symbol.name} = ${formatC64Address(symbol.address)}`);
|
|
952
|
+
for (const patch of knowledge.patches) {
|
|
953
|
+
const owner = knowledge.switches.find((item) => item.name === patch.switch);
|
|
954
|
+
if (owner === undefined || owner.default === owner.base) continue;
|
|
955
|
+
const length = patch.end - patch.start + 1;
|
|
956
|
+
const text = ["!cpu 6510", ...addresses, `* = ${formatC64Address(patch.start)}`, ...patch.code.split(/\r?\n/), `!fill ${length} - (* - ${formatC64Address(patch.start)}), $ea`].join("\n");
|
|
957
|
+
const built = await assembleFiles([{ name: "patch.asm", text: `${text}\n` }], "patch.asm");
|
|
958
|
+
if (built.program === undefined || built.start !== patch.start || built.program.length - 2 !== length) {
|
|
959
|
+
throw new Refusal("invalid-input", `The patch of ${patch.switch} at ${formatC64Address(patch.start)}-${formatC64Address(patch.end)} in ${stage} does not assemble to ${length} bytes: ${built.diagnostics.map((diagnostic) => diagnostic.message).join("; ") || "it is longer than its range"}. Correct the patch in the project knowledge.`);
|
|
960
|
+
}
|
|
961
|
+
memory.set(built.program.subarray(2), patch.start);
|
|
962
|
+
}
|
|
963
|
+
const screen = startScreenRanges(row).map((part) => part.range);
|
|
964
|
+
let ranges = screen;
|
|
965
|
+
if (row.call !== undefined) {
|
|
966
|
+
if (knowledge.coverage === undefined) {
|
|
967
|
+
throw new Refusal("not-found", `The start screen calls ${formatC64Address(row.call)} of ${stage}, and the knowledge has no coverage in ${stage}. Run the stage with coverage while it calls ${formatC64Address(row.call)} and plays, and put the map into the project knowledge with coverage --space ${stage}. Then generate again.`);
|
|
968
|
+
}
|
|
969
|
+
// The call is the entry of the stage: what it does not reach and its run did not touch stays out.
|
|
970
|
+
const called = { ...knowledge, program: { ...image, entry: row.call } };
|
|
971
|
+
const { instructions } = await decode(called.program, called, [row.call], knowledge.coverage);
|
|
972
|
+
const free = leftoversOf(called, instructions, screen);
|
|
973
|
+
ranges = [...screen, ...image.segments.flatMap((segment) => subtract(segment, free))];
|
|
974
|
+
}
|
|
975
|
+
const parts: AddressRange[] = [];
|
|
976
|
+
for (const range of ranges.map((item) => ({ start: Math.max(item.start, 0x0400), end: item.end })).filter((item) => item.start <= item.end).sort((a, b) => a.start - b.start)) {
|
|
977
|
+
const last = parts.at(-1);
|
|
978
|
+
if (last !== undefined && range.start <= last.end + 1) last.end = Math.max(last.end, range.end);
|
|
979
|
+
else parts.push({ ...range });
|
|
980
|
+
}
|
|
981
|
+
return { parts: parts.map((range) => ({ start: range.start, body: memory.slice(range.start, range.end + 1) })), ...(colourRam === undefined ? {} : { colourRam }) };
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/** What the show stage gives: loader.prg, the source of the stage, and what its check needs. */
|
|
985
|
+
interface BuiltStage {
|
|
986
|
+
program: Buffer;
|
|
987
|
+
text: string;
|
|
988
|
+
plan: StagePlan;
|
|
989
|
+
parts: StagePart[];
|
|
990
|
+
colourRam?: Uint8Array;
|
|
991
|
+
packed: PackedLoader;
|
|
992
|
+
wait: number;
|
|
993
|
+
continue: number;
|
|
994
|
+
screen: StartScreenPlan;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
/**
|
|
998
|
+
* Builds the show stage of a start screen from a captured stage: plans it,
|
|
999
|
+
* assembles start_screen_stage.asm and packs it with the loader as the loader
|
|
1000
|
+
* is in memory before it starts. Refuses by name.
|
|
1001
|
+
*/
|
|
1002
|
+
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> {
|
|
1003
|
+
const { parts: stage, colourRam } = await stageBytes(row);
|
|
1004
|
+
// The packed program, as RUN would start it: its unpacker unpacks it over the start screen after the wait.
|
|
1005
|
+
const inner: StagePart[] = [{ start: 0x0801, body: program.program.subarray(2) }];
|
|
1006
|
+
const screen = startScreenPlan(row);
|
|
1007
|
+
const input: StageInput = {
|
|
1008
|
+
inner,
|
|
1009
|
+
innerStart: 0x080d,
|
|
1010
|
+
innerPort: 0x37,
|
|
1011
|
+
stage,
|
|
1012
|
+
...(colourRam === undefined ? {} : { colourRam }),
|
|
1013
|
+
row,
|
|
1014
|
+
plan: screen,
|
|
1015
|
+
settings: hasSwitchFile(laid) ? ['!source "switches.asm"'] : hasConfigFile(laid) ? ['!source "config.asm"'] : [],
|
|
1016
|
+
header,
|
|
1017
|
+
codeSize: 0,
|
|
1018
|
+
};
|
|
1019
|
+
const support = [...withValues(files, laid, values).filter((file) => file.name === CONFIG_FILE || file.name === "switches.asm"), { name: START_SCREEN_FILE, text: START_SCREEN_CODE }];
|
|
1020
|
+
const assembleStage = async (text: string) => {
|
|
1021
|
+
const built = await assembleFiles([...support, { name: STAGE_FILE, text }], STAGE_FILE);
|
|
1022
|
+
if (built.program === undefined) throw new WireFailure("operation-failed", `${STAGE_FILE} does not assemble: ${built.diagnostics.map((diagnostic) => diagnostic.message).join("; ")}. This is a defect of the script.`);
|
|
1023
|
+
const labels = new Map((built.symbols ?? []).map((symbol) => [symbol.name, symbol.kind === "address" ? symbol.address : symbol.value]));
|
|
1024
|
+
const label = (name: string) => {
|
|
1025
|
+
const value = labels.get(name);
|
|
1026
|
+
if (value === undefined) throw new WireFailure("operation-failed", `The build of ${STAGE_FILE} has no ${name} label. This is a defect of the script.`);
|
|
1027
|
+
return value;
|
|
1028
|
+
};
|
|
1029
|
+
return { program: built.program, label };
|
|
1030
|
+
};
|
|
1031
|
+
// The size of the show code does not depend on its address: one build without a stash gives it.
|
|
1032
|
+
const probe = await assembleStage(stageText(input, 0x1000, []));
|
|
1033
|
+
input.codeSize = probe.label(STAGE_CODE_END) - probe.label(STAGE_START) - 2;
|
|
1034
|
+
const plan = planStage(input);
|
|
1035
|
+
const built = await assembleStage(plan.text);
|
|
1036
|
+
if (built.label(STAGE_START) !== plan.code || built.label(STAGE_CODE_END) - plan.code !== input.codeSize + 6 * plan.stash.length + 2) throw new WireFailure("operation-failed", `The build of ${STAGE_FILE} does not have the planned layout. This is a defect of the script.`);
|
|
1037
|
+
const parts = stageParts(input, plan, built.program, built.label);
|
|
1038
|
+
const packed = await packParts(parts, plan.code, 0x37, "the loader and the start screen of the stage", "the show stage", localToolContext());
|
|
1039
|
+
const end = 0x0801 + packed.program.length - 3;
|
|
1040
|
+
if (end > 0xcfff) throw new Refusal("invalid-input", `loader.prg 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.`);
|
|
1041
|
+
return { program: packed.program, text: `${mark}\n${plan.text}`, plan, parts: stage, ...(colourRam === undefined ? {} : { colourRam }), packed, wait: built.label(START_SCREEN_WAIT), continue: built.label(START_SCREEN_CONTINUE), screen };
|
|
1042
|
+
}
|
|
1043
|
+
|
|
862
1044
|
/** The first line of each file that generate writes. */
|
|
863
1045
|
const GENERATED_LINE = `${GENERATED_MARK}. Do not edit: change the knowledge and generate again.`;
|
|
864
1046
|
|
|
@@ -876,24 +1058,27 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
876
1058
|
}
|
|
877
1059
|
// Read the entry state before the long steps, so a bad state stops the run at once.
|
|
878
1060
|
const state = loaderWanted ? loaderState(image.state, "the entry state of the knowledge") : undefined;
|
|
879
|
-
// Every build that is compared with the program is the build of the base release: each switch at its base value.
|
|
880
|
-
const baseValues = new Map(knowledge.switches.map((row) => [row.name, row.base]));
|
|
1061
|
+
// Every build that is compared with the program is the build of the base release: each switch at its base value, with the leftovers.
|
|
1062
|
+
const baseValues = new Map<string, number>([...knowledge.switches.map((row) => [row.name, row.base] as const), [LEFTOVERS_SWITCH, 1]]);
|
|
1063
|
+
// config.asm keeps the value of each switch that it already has: the user sets the switches there. The loader loads that build.
|
|
1064
|
+
const configPath = resolveProjectPath(`${out}/${CONFIG_FILE}`);
|
|
1065
|
+
const given = existsSync(configPath) ? configValues(readFileSync(configPath, "utf8")) : new Map<string, 0 | 1>();
|
|
1066
|
+
const configNames = new Set([...knowledge.switches.map((row) => row.name), START_SCREEN_SWITCH, LEFTOVERS_SWITCH]);
|
|
1067
|
+
const loaderValues = new Map([...given].filter(([name]) => configNames.has(name)));
|
|
881
1068
|
const header = [`Generated by c64-source from knowledge revision ${knowledge.revision}${space === DEFAULT_SPACE ? "" : ` in space ${space}`}.`, "Change names, comments, regions and modules in knowledge, then generate again."];
|
|
882
1069
|
const loaderHeader = [`${LOADER_REVISION}${knowledge.revision}.`, "It copies the segments into place, sets the entry state and jumps to the entry."];
|
|
883
|
-
const { romUse, dataOnly, laid, rendered, files, built, loader, missingEntry, loaderRefused } = await buildSource(knowledge, {
|
|
1070
|
+
const { romUse, dataOnly, laid, rendered, files, built, loader, loaderMain, missingEntry, loaderRefused } = await buildSource(knowledge, {
|
|
884
1071
|
space,
|
|
885
1072
|
entries,
|
|
886
1073
|
header,
|
|
887
1074
|
mark: GENERATED_LINE,
|
|
888
1075
|
values: baseValues,
|
|
889
1076
|
notExecutedMarks: true,
|
|
890
|
-
|
|
1077
|
+
leftovers: true,
|
|
1078
|
+
...(state === undefined ? {} : { state, loaderHeader, loaderValues }),
|
|
891
1079
|
});
|
|
892
|
-
//
|
|
893
|
-
const
|
|
894
|
-
const given = existsSync(configPath) ? configValues(readFileSync(configPath, "utf8")) : new Map<string, 0 | 1>();
|
|
895
|
-
// START_SCREEN is a switch of the start screen, with the default 1.
|
|
896
|
-
const configured = [...laid.switches, ...(laid.startScreen ? [{ name: START_SCREEN_SWITCH, default: 1 }] : [])];
|
|
1080
|
+
// START_SCREEN is a switch of the start screen, with the default 1. LEFTOVERS has the default 0: the default build is the clean program.
|
|
1081
|
+
const configured = [...laid.switches, ...(laid.startScreen ? [{ name: START_SCREEN_SWITCH, default: 1 }] : []), ...(laid.leftovers.length > 0 ? [{ name: LEFTOVERS_SWITCH, default: 0 }] : [])];
|
|
897
1082
|
const kept = new Map(configured.flatMap((row) => (given.has(row.name) ? [[row.name, given.get(row.name)!] as const] : [])));
|
|
898
1083
|
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 }] : []));
|
|
899
1084
|
const removed = removeOldFiles(out, new Set(files.map((file) => file.name)), loaderWanted).map((name) => `${out}/${name}`);
|
|
@@ -946,6 +1131,12 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
946
1131
|
notExecuted: { instructions: rendered.notExecuted.instructions, ...listed(rendered.notExecuted.ranges, max, showRange, `${out}/${NOT_EXECUTED_FILE}`) },
|
|
947
1132
|
}),
|
|
948
1133
|
...(laid.unusedModules.length === 0 ? {} : { unusedModules: laid.unusedModules.map((module) => ({ start: formatC64Address(module.start), file: module.file })) }),
|
|
1134
|
+
// The bytes that nothing uses: in leftover files, which the default build and the loader leave out.
|
|
1135
|
+
...(laid.leftovers.length === 0
|
|
1136
|
+
? knowledge.coverage === undefined && space === DEFAULT_SPACE
|
|
1137
|
+
? { 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." } }
|
|
1138
|
+
: {}
|
|
1139
|
+
: { 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` })) } }),
|
|
949
1140
|
...(rendered.expressions.length === 0 && rendered.operandsAsNumbers.length === 0 ? {} : { operandExpressions: rendered.expressions.length }),
|
|
950
1141
|
...(rendered.operandsAsNumbers.length === 0
|
|
951
1142
|
? {}
|
|
@@ -966,8 +1157,12 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
966
1157
|
patchesNotWritten: listed(laid.patchesNotWritten, max, (item) => ({ start: formatC64Address(item.start), end: formatC64Address(item.end), switch: item.switch, reason: item.reason })),
|
|
967
1158
|
}),
|
|
968
1159
|
};
|
|
1160
|
+
// A loader.prg of an earlier run stays when this run checks no new one: it can be a committed file.
|
|
1161
|
+
const loaderPath = `${out}/loader.prg`;
|
|
1162
|
+
const keptLoader = () => (existsSync(resolveProjectPath(loaderPath)) ? { kept: loaderPath } : {});
|
|
1163
|
+
const notVerified = (fields: Record<string, unknown>) => ({ verified: false, ...fields, ...keptLoader() });
|
|
969
1164
|
// The loader includes the source, so it is built only from a source that is identical to the image.
|
|
970
|
-
const notBuilt = (reason: string) => (state === undefined ? {} : { loader: {
|
|
1165
|
+
const notBuilt = (reason: string) => (state === undefined ? {} : { loader: notVerified({ reason: loaderRefused ?? reason }) });
|
|
971
1166
|
if (built.program === undefined) {
|
|
972
1167
|
return { output: { ...output, check: { identical: false, diagnostics: built.diagnostics.slice(0, MAX_DIAGNOSTICS) }, ...notBuilt("The source does not assemble, and the loader includes it.") }, removed, failed: true };
|
|
973
1168
|
}
|
|
@@ -985,9 +1180,10 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
985
1180
|
if (switches.length > 0) output.switches = switches;
|
|
986
1181
|
// The default build: the patches of each switch whose default is not its base value are in, and nothing else changes.
|
|
987
1182
|
let defaultFailed = false;
|
|
988
|
-
if (laid.switches.length > 0) {
|
|
1183
|
+
if (laid.switches.length > 0 || laid.leftovers.length > 0) {
|
|
989
1184
|
const changed = laid.switches.filter((row) => row.default !== row.base);
|
|
990
|
-
|
|
1185
|
+
// The default build also leaves out the leftovers.
|
|
1186
|
+
const ranges = [...changed.flatMap((row) => withPatches.get(row.name) ?? []), ...laid.leftovers];
|
|
991
1187
|
const built = await checkBuild(withValues(files, laid, new Map()), ranges, baseBuild);
|
|
992
1188
|
output.default = { in: changed.map((row) => row.name), ...built };
|
|
993
1189
|
defaultFailed = built.result !== "fits";
|
|
@@ -998,43 +1194,81 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
998
1194
|
if (releases.length > 0) output.releases = releases;
|
|
999
1195
|
const releasesFailed = releases.some((item) => item.result !== "identical" && (item.base || item.result !== "layout differs"));
|
|
1000
1196
|
const sourceFailed = laid.patchesNotWritten.length > 0 || switches.some((item) => item.result !== "fits") || defaultFailed || releasesFailed;
|
|
1001
|
-
if (loaderRefused !== undefined) return { output: { ...output, loader: {
|
|
1002
|
-
if (loader === undefined || state === undefined) return { output, removed, failed: missingEntry !== undefined || sourceFailed };
|
|
1197
|
+
if (loaderRefused !== undefined) return { output: { ...output, loader: notVerified({ reason: loaderRefused }) }, removed, failed: true };
|
|
1198
|
+
if (loader === undefined || loaderMain === undefined || state === undefined) return { output, removed, failed: missingEntry !== undefined || sourceFailed };
|
|
1003
1199
|
|
|
1004
|
-
// The
|
|
1005
|
-
const loaderBuilt = await buildLoader(files, laid, loader,
|
|
1006
|
-
if ("diagnostics" in loaderBuilt) return { output: { ...output, loader: {
|
|
1200
|
+
// The loader loads the build with the values of config.asm, without the leftovers. The entry state is the state of the base release.
|
|
1201
|
+
const loaderBuilt = await buildLoader(files, laid, loader, loaderMain, state, loaderValues);
|
|
1202
|
+
if ("diagnostics" in loaderBuilt) return { output: { ...output, loader: notVerified({ reason: "loader.asm does not assemble.", diagnostics: loaderBuilt.diagnostics }) }, removed, failed: true };
|
|
1007
1203
|
const { jump, copierSource, expected, startScreen } = loaderBuilt;
|
|
1008
1204
|
const copierBuild = loaderBuilt.program;
|
|
1009
1205
|
const fileByte = (address: number) => copierBuild[2 + address - (loader.packed?.start ?? 0x0801)]!;
|
|
1010
|
-
//
|
|
1206
|
+
// A start screen of a captured stage: the show stage holds the packed program, as a cracktro holds the game.
|
|
1207
|
+
const stageRow = knowledge.startScreen?.stage === undefined ? undefined : knowledge.startScreen;
|
|
1208
|
+
// 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.prg.
|
|
1011
1209
|
let packed: PackedLoader | undefined;
|
|
1012
1210
|
if (loader.packed !== undefined) {
|
|
1013
1211
|
try {
|
|
1014
|
-
packed = await packLoader(
|
|
1212
|
+
packed = await packLoader(loaderMain.program, copierBuild, loader, localToolContext());
|
|
1015
1213
|
} catch (error) {
|
|
1016
1214
|
if (!isRefusal(error)) throw error;
|
|
1017
|
-
return { output: { ...output, loader: {
|
|
1215
|
+
return { output: { ...output, loader: notVerified({ reason: `loader.asm has the packed form, and the pack with Exomizer failed. ${error.message}` }) }, removed, failed: true };
|
|
1018
1216
|
}
|
|
1019
1217
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1218
|
+
let stage: BuiltStage | undefined;
|
|
1219
|
+
if (stageRow !== undefined) {
|
|
1220
|
+
try {
|
|
1221
|
+
stage = await buildStage(files, laid, packed!, stageRow, loaderValues, loaderHeader, GENERATED_LINE);
|
|
1222
|
+
} catch (error) {
|
|
1223
|
+
if (!isRefusal(error)) throw error;
|
|
1224
|
+
return { output: { ...output, loader: notVerified({ reason: `The show stage of the start screen from ${stageRow.stage} cannot be built. ${error.message}` }) }, removed, failed: true };
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
const program = stage?.program ?? packed?.program ?? copierBuild;
|
|
1228
|
+
// The check runs the new loader from a scratch file. Only a loader whose check ran goes to --out, so a check
|
|
1229
|
+
// that cannot run (no host, or a host of another release) keeps the loader.prg of an earlier run.
|
|
1230
|
+
ensureLocal(projectRoot());
|
|
1231
|
+
const scratch = `${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/${LOADER_CHECK_DIRECTORY}`;
|
|
1232
|
+
mkdirSync(resolveProjectPath(scratch), { recursive: true });
|
|
1233
|
+
const checkPath = `${scratch}/loader.prg`;
|
|
1234
|
+
writeFileSync(resolveProjectPath(checkPath), program);
|
|
1235
|
+
// The unpack runs before the copier, or before the show stage, which then starts the loader.
|
|
1236
|
+
const unpackFrames = (cycles: number | undefined) => (cycles === undefined ? LOADER_FRAMES : RUN_LIMIT_FRAMES + Math.ceil(cycles / PAL_FRAME_CYCLES));
|
|
1237
|
+
const copierFrames = packed === undefined ? RUN_LIMIT_FRAMES : unpackFrames(packed.cycles);
|
|
1238
|
+
// The check compares the bytes of the screen of the stage: a routine of the stage can change its other bytes.
|
|
1239
|
+
const stageByte = (address: number) => {
|
|
1240
|
+
const part = stage!.parts.find((item) => address >= item.start && address < item.start + item.body.length)!;
|
|
1241
|
+
return part.body[address - part.start]!;
|
|
1242
|
+
};
|
|
1243
|
+
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)) }));
|
|
1244
|
+
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 } };
|
|
1025
1245
|
let ran: LoaderRun;
|
|
1026
1246
|
try {
|
|
1027
|
-
ran = await runLoader(
|
|
1247
|
+
ran = await runLoader(checkPath, program, loader, state, { jump, copierSource, fileByte, copierFrames, ...(startScreen === undefined ? {} : { startScreen }), ...stageRun }, expected);
|
|
1028
1248
|
} catch (error) {
|
|
1029
|
-
// A loader.prg without its check does not stay: it looks like a checked loader.
|
|
1030
|
-
rmSync(resolveProjectPath(loaderPath), { force: true });
|
|
1031
|
-
written.splice(written.findIndex((file) => file.out === loaderPath), 1);
|
|
1032
1249
|
if (!isRefusal(error)) throw error;
|
|
1033
|
-
|
|
1250
|
+
const what = existsSync(resolveProjectPath(loaderPath)) ? "kept the loader.prg of an earlier run" : "wrote no loader.prg";
|
|
1251
|
+
return { output: { ...output, loader: notVerified({ reason: `The check of loader.prg did not run, so the script ${what}. ${error.message}` }) }, removed, failed: true };
|
|
1252
|
+
} finally {
|
|
1253
|
+
rmSync(resolveProjectPath(scratch), { recursive: true, force: true });
|
|
1034
1254
|
}
|
|
1255
|
+
written.push(writeReported(loaderPath, program, { what: "--out" }));
|
|
1256
|
+
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" }));
|
|
1035
1257
|
output.loader = {
|
|
1036
1258
|
program: loaderPath,
|
|
1037
1259
|
...(packed === undefined ? {} : { packed: { packedBytes: packed.packedBytes, unpackedBytes: packed.unpackedBytes } }),
|
|
1260
|
+
...(stage === undefined
|
|
1261
|
+
? {}
|
|
1262
|
+
: {
|
|
1263
|
+
stage: {
|
|
1264
|
+
space: stageRow!.stage,
|
|
1265
|
+
code: formatC64Address(stage.plan.code),
|
|
1266
|
+
bytes: stage.parts.reduce((sum, part) => sum + part.body.length, 0),
|
|
1267
|
+
stash: stage.plan.stash.map((item) => ({ from: formatC64Address(item.at), to: `${formatC64Address(item.target.start)}-${formatC64Address(item.target.end)}` })),
|
|
1268
|
+
packedBytes: stage.packed.packedBytes,
|
|
1269
|
+
unpackedBytes: stage.packed.unpackedBytes,
|
|
1270
|
+
},
|
|
1271
|
+
}),
|
|
1038
1272
|
copies: loader.copies.map((copy) => ({ what: copy.what, to: `${formatC64Address(copy.target.start)}-${formatC64Address(copy.target.end)}` })),
|
|
1039
1273
|
copier: formatC64Address(loader.copier),
|
|
1040
1274
|
stackByte: formatC64Address(loader.stackByte),
|
|
@@ -1081,6 +1315,61 @@ function effectiveRegions(regions: SourceKnowledge["regions"]): SourceKnowledge[
|
|
|
1081
1315
|
return [...semantic, ...regions.filter((region) => !isSemantic(region.origin)).flatMap((region) => clipped(region, holes))].sort((a, b) => a.start - b.start);
|
|
1082
1316
|
}
|
|
1083
1317
|
|
|
1318
|
+
/** The names and the four-digit hex addresses that the code of a patch has: a switch can go to them, so they stay. */
|
|
1319
|
+
function patchTargets(code: string, addressOf: ReadonlyMap<string, number>): number[] {
|
|
1320
|
+
const words = code.replace(/;.*$/gm, "").match(/\$[0-9a-fA-F]{4}\b|[A-Za-z_][A-Za-z0-9_]*/g) ?? [];
|
|
1321
|
+
return words.flatMap((word) => (word.startsWith("$") ? [Number.parseInt(word.slice(1), 16)] : addressOf.has(word) ? [addressOf.get(word)!] : []));
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
/**
|
|
1325
|
+
* The free ranges of a program: code that no run executed and that nothing
|
|
1326
|
+
* reaches, and data that no run touched and that nothing names (planDrops).
|
|
1327
|
+
* The export makes them $00; generate makes them the leftovers. `memory` and
|
|
1328
|
+
* `instructions` are of the build that the ranges are free in.
|
|
1329
|
+
*/
|
|
1330
|
+
function freeRanges(knowledge: SourceKnowledge, memory: Uint8Array, instructions: ReadonlyMap<number, number>, ranges: { changed: readonly AddressRange[]; keep: readonly AddressRange[]; drop: readonly AddressRange[] }) {
|
|
1331
|
+
const image = knowledge.program;
|
|
1332
|
+
const addressOf = new Map(knowledge.symbols.map((symbol) => [symbol.name, symbol.address]));
|
|
1333
|
+
const operandTargets = new Map<number, number[]>();
|
|
1334
|
+
for (const operand of knowledge.operands) {
|
|
1335
|
+
const names = operand.symbol !== undefined ? [operand.symbol] : identifiers(operand.expression ?? "");
|
|
1336
|
+
const targets = names.flatMap((item) => (addressOf.has(item) ? [(addressOf.get(item)! + (operand.symbol !== undefined ? operand.offset : 0)) & 0xffff] : []));
|
|
1337
|
+
if (targets.length > 0) operandTargets.set(operand.address, targets);
|
|
1338
|
+
}
|
|
1339
|
+
const entry = image.entry ?? basicEntry(image);
|
|
1340
|
+
return planDrops({
|
|
1341
|
+
segments: image.segments,
|
|
1342
|
+
memory,
|
|
1343
|
+
...(entry === undefined ? {} : { entry }),
|
|
1344
|
+
instructions,
|
|
1345
|
+
...(knowledge.coverage === undefined ? {} : { coverage: knowledge.coverage }),
|
|
1346
|
+
regions: effectiveRegions(knowledge.regions),
|
|
1347
|
+
references: knowledge.references,
|
|
1348
|
+
operandTargets,
|
|
1349
|
+
changed: [...ranges.changed],
|
|
1350
|
+
keep: [...ranges.keep],
|
|
1351
|
+
drop: [...ranges.drop],
|
|
1352
|
+
routines: knowledge.symbols.filter((symbol) => symbol.kind === "routine"),
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* The leftovers of generate: the free ranges of the program as it is. The
|
|
1358
|
+
* start screen in the program, the patches, the macro uses, what the code of a
|
|
1359
|
+
* patch names and the ranges of `keep` stay, so each switch builds with
|
|
1360
|
+
* LEFTOVERS = 0.
|
|
1361
|
+
*/
|
|
1362
|
+
function leftoversOf(knowledge: SourceKnowledge, instructions: ReadonlyMap<number, number>, kept: readonly AddressRange[] = []): AddressRange[] {
|
|
1363
|
+
const image = knowledge.program;
|
|
1364
|
+
const inImage = (range: AddressRange) => image.segments.some((segment) => range.start >= segment.start && range.end <= segment.end);
|
|
1365
|
+
const addressOf = new Map(knowledge.symbols.map((symbol) => [symbol.name, symbol.address]));
|
|
1366
|
+
const screenParts = knowledge.startScreen === undefined || knowledge.startScreen.stage !== undefined ? [] : startScreenRanges(knowledge.startScreen).map((part) => part.range);
|
|
1367
|
+
const named = knowledge.patches.flatMap((patch) => patchTargets(patch.code, addressOf)).map((address) => ({ start: address, end: address }));
|
|
1368
|
+
const keep = [...screenParts, ...kept, ...knowledge.macroUses, ...named].map((range) => ({ start: range.start, end: range.end })).filter(inImage);
|
|
1369
|
+
const changed = knowledge.patches.map((patch) => ({ start: patch.start, end: patch.end })).filter(inImage);
|
|
1370
|
+
return freeRanges(knowledge, image.memory, instructions, { changed, keep, drop: [] }).free.map((range) => ({ start: range.start, end: range.end }));
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1084
1373
|
/** Every file in a folder with its path in it, with / between the parts, in path order. `skip` leaves out a folder by its path. */
|
|
1085
1374
|
function filesIn(root: string, skip: (path: string) => boolean, folder = ""): Array<{ path: string; bytes: Buffer }> {
|
|
1086
1375
|
const found: Array<{ path: string; bytes: Buffer }> = [];
|
|
@@ -1120,7 +1409,10 @@ async function exportProject(call: Call): Promise<Record<string, unknown>> {
|
|
|
1120
1409
|
db?.close();
|
|
1121
1410
|
}
|
|
1122
1411
|
})();
|
|
1123
|
-
const
|
|
1412
|
+
const read = readKnowledge(DEFAULT_SPACE);
|
|
1413
|
+
// The export has only the space c64: a start screen of a captured stage stays out with that space.
|
|
1414
|
+
const stageLeftOut = read.startScreen?.stage;
|
|
1415
|
+
const knowledge = stageLeftOut === undefined ? read : { ...read, startScreen: undefined };
|
|
1124
1416
|
const image = knowledge.program;
|
|
1125
1417
|
// The VIC-II reads the start screen, and the coverage does not show those reads: it stays.
|
|
1126
1418
|
const screenParts = knowledge.startScreen === undefined ? [] : startScreenRanges(knowledge.startScreen).map((part) => part.range);
|
|
@@ -1165,29 +1457,8 @@ async function exportProject(call: Call): Promise<Record<string, unknown>> {
|
|
|
1165
1457
|
const decoded = await decode(bakedImage, knowledge, [], knowledge.coverage);
|
|
1166
1458
|
|
|
1167
1459
|
// 4. The free ranges.
|
|
1168
|
-
const addressOf = new Map(knowledge.symbols.map((symbol) => [symbol.name, symbol.address]));
|
|
1169
|
-
const operandTargets = new Map<number, number[]>();
|
|
1170
|
-
for (const operand of knowledge.operands) {
|
|
1171
|
-
const names = operand.symbol !== undefined ? [operand.symbol] : identifiers(operand.expression ?? "");
|
|
1172
|
-
const targets = names.flatMap((item) => (addressOf.has(item) ? [(addressOf.get(item)! + (operand.symbol !== undefined ? operand.offset : 0)) & 0xffff] : []));
|
|
1173
|
-
if (targets.length > 0) operandTargets.set(operand.address, targets);
|
|
1174
|
-
}
|
|
1175
1460
|
const regions = effectiveRegions(knowledge.regions);
|
|
1176
|
-
const
|
|
1177
|
-
const plan = planDrops({
|
|
1178
|
-
segments: image.segments,
|
|
1179
|
-
memory,
|
|
1180
|
-
...(entry === undefined ? {} : { entry }),
|
|
1181
|
-
instructions: decoded.instructions,
|
|
1182
|
-
...(knowledge.coverage === undefined ? {} : { coverage: knowledge.coverage }),
|
|
1183
|
-
regions,
|
|
1184
|
-
references: knowledge.references,
|
|
1185
|
-
operandTargets,
|
|
1186
|
-
changed,
|
|
1187
|
-
keep,
|
|
1188
|
-
drop,
|
|
1189
|
-
routines: knowledge.symbols.filter((symbol) => symbol.kind === "routine"),
|
|
1190
|
-
});
|
|
1461
|
+
const plan = freeRanges(knowledge, memory, decoded.instructions, { changed, keep, drop });
|
|
1191
1462
|
const free = plan.free;
|
|
1192
1463
|
const inFree = (address: number) => free.some((range) => address >= range.start && address <= range.end);
|
|
1193
1464
|
const overlapsAny = (start: number, end: number, ranges: readonly AddressRange[]) => ranges.some((range) => start <= range.end && range.start <= end);
|
|
@@ -1251,7 +1522,7 @@ async function exportProject(call: Call): Promise<Record<string, unknown>> {
|
|
|
1251
1522
|
if (state !== undefined) {
|
|
1252
1523
|
if (exported.loader === undefined) return { result: "FAIL", stage: "loader", reason: exported.loaderRefused ?? "The loader could not be planned." };
|
|
1253
1524
|
if (exported.loader.packed !== undefined) return { result: "FAIL", stage: "loader", reason: "The program is too large for one loader file, and export does not make the packed form of the loader." };
|
|
1254
|
-
const loaderBuilt = await buildLoader(exported.files, exported.laid, exported.loader,
|
|
1525
|
+
const loaderBuilt = await buildLoader(exported.files, exported.laid, exported.loader, exported.loaderMain!, state, new Map());
|
|
1255
1526
|
if ("diagnostics" in loaderBuilt) return { result: "FAIL", stage: "loader", reason: "loader.asm does not assemble. This is a defect of the script.", diagnostics: loaderBuilt.diagnostics };
|
|
1256
1527
|
baseline = { program: loaderBuilt.program, symbols: loaderBuilt.symbols, entryFile: "loader.asm" };
|
|
1257
1528
|
loaderOutput = {
|
|
@@ -1329,6 +1600,7 @@ async function exportProject(call: Call): Promise<Record<string, unknown>> {
|
|
|
1329
1600
|
knowledge: kept,
|
|
1330
1601
|
tests: { written: tests.map((test) => test.file), leftOut: listed(testsLeftOut, max, (item) => item) },
|
|
1331
1602
|
...(spacesLeftOut.length === 0 ? {} : { spacesLeftOut }),
|
|
1603
|
+
...(stageLeftOut === undefined ? {} : { startScreenLeftOut: `The start screen is of the captured stage in ${stageLeftOut}, and the export has only the space c64.` }),
|
|
1332
1604
|
...(exported.rendered.operandsAsNumbers.length === 0 ? {} : { operandsAsNumbers: listed(exported.rendered.operandsAsNumbers, max, (item) => ({ address: formatC64Address(item.address), expression: item.expression, reason: item.reason })) }),
|
|
1333
1605
|
...(exported.rendered.macrosAsInstructions.length === 0 ? {} : { macrosAsInstructions: listed(exported.rendered.macrosAsInstructions, max, (item) => ({ start: formatC64Address(item.start), end: formatC64Address(item.end), macro: item.macro, reason: item.reason })) }),
|
|
1334
1606
|
};
|
|
@@ -1384,6 +1656,7 @@ function generateReply(call: Call, body: Record<string, unknown>): Reply {
|
|
|
1384
1656
|
again = true;
|
|
1385
1657
|
}
|
|
1386
1658
|
if ((body.loader as { verified?: boolean } | undefined)?.verified === false) steps.push("The loader is not verified. Read loader.reason, loader.differences and loader.stop.");
|
|
1659
|
+
if ((body.leftovers as { noCoverage?: string } | undefined)?.noCoverage !== undefined && call.flag("loader")) steps.push("To leave out the bytes that nothing uses, put the coverage of the runs into the project knowledge. Then generate again.");
|
|
1387
1660
|
if (body.dataOnly !== undefined) {
|
|
1388
1661
|
steps.push("The source has only data. If the space has code, give --entry, or record a code region in the project knowledge.");
|
|
1389
1662
|
again = true;
|
|
@@ -1438,8 +1711,8 @@ await runScript({
|
|
|
1438
1711
|
options: {
|
|
1439
1712
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", help: "the folder for the source files, relative to the project folder", required: true },
|
|
1440
1713
|
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" },
|
|
1441
|
-
space: { ...OPTIONS.space, help: "the knowledge space of the program: c64 (the default), drive8, or bank0 to bank255.
|
|
1442
|
-
loader: { kind: "flag", help: "also write loader.asm and loader.prg: 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. When the check cannot run, the script
|
|
1714
|
+
space: { ...OPTIONS.space, help: "the knowledge space of the program: c64 (the default), drive8, or bank0 to bank255. --loader is for c64 only" },
|
|
1715
|
+
loader: { kind: "flag", help: "also write loader.asm and loader.prg: 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.prg of an earlier run" },
|
|
1443
1716
|
"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" },
|
|
1444
1717
|
"max-listed": OPTIONS["max-listed"],
|
|
1445
1718
|
},
|