@henols/c64-re-tools 2.6.0-rc.3 → 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 +25 -11
- package/skills/c64-assembler/scripts/assembler.ts +23 -10
- package/skills/c64-packer/SKILL.md +1 -1
- package/skills/c64-source/SKILL.md +34 -27
- package/skills/c64-source/scripts/lib/export.ts +5 -4
- package/skills/c64-source/scripts/lib/loader.ts +6 -6
- package/skills/c64-source/scripts/lib/source.ts +2 -15
- package/skills/c64-source/scripts/lib/stage.ts +2 -2
- package/skills/c64-source/scripts/source.ts +80 -24
- package/skills/c64-testing/SKILL.md +1 -1
- package/skills/c64-testing/references/scenario-format.md +1 -1
- package/skills/c64-unpacker/SKILL.md +2 -0
- package/skills/c64-unpacker/scripts/lib/loads.ts +33 -12
- package/skills/c64-unpacker/scripts/unpacker.ts +5 -3
- package/src/build-name.ts +47 -0
- package/src/host/vice/session.ts +6 -1
- package/src/native/acme.ts +1 -1
package/package.json
CHANGED
|
@@ -27,10 +27,11 @@ To get the command list, run the script with no arguments.
|
|
|
27
27
|
| Build a source that includes files from a folder | `build src main.a --out build/game.prg --include lib` |
|
|
28
28
|
| Build a source that includes a file that you generated into a folder next to the source root | `build src boot.asm --out build/boot.prg --include ../build` |
|
|
29
29
|
| Build a source that sets no start address | `build src main.a --out build/game.prg --set-pc '$0801'` |
|
|
30
|
-
|
|
|
31
|
-
| Build
|
|
30
|
+
| Build a generated source with the values of `config.asm` | `build src main.asm` |
|
|
31
|
+
| Build the loader of a generated source | `build src loader.asm` |
|
|
32
|
+
| Check that the rebuild is identical to the program in the project knowledge | `build src main.asm --compare` |
|
|
33
|
+
| Build a release and check it against the file of that release | `build src main.asm --release ORIGINAL --compare` |
|
|
32
34
|
| Check the rebuild of a program in another space, for example the drive | `build src main.asm --out build/drive.prg --compare --space drive8` |
|
|
33
|
-
| Write the symbols of the rebuild to a file for a test run | `build src main.asm --out build/game.prg --out-symbols build/game.json` |
|
|
34
35
|
| List all symbols, also the constants that the source does not use | `build src main.a --out build/game.prg --all-symbols --max-listed 500` |
|
|
35
36
|
| Write only the bytes of the program, without the load address | `build src main.a --out build/game.bin --plain` |
|
|
36
37
|
|
|
@@ -42,7 +43,8 @@ To get the command list, run the script with no arguments.
|
|
|
42
43
|
- An include folder is a path relative to the source root, inside the project folder. It can be outside the source root, for example `--include ../build`.
|
|
43
44
|
- `<entry>` is the main source file, relative to the source root. It normally sets its start address, for example `* = $0801`. If it does not, give `--set-pc`.
|
|
44
45
|
- For a source that you generated from the project knowledge, the source root is the folder of that source. The entry is `main.asm`.
|
|
45
|
-
- `--out` is the path of the program, relative to the project folder.
|
|
46
|
+
- `--out` is the path of the program, relative to the project folder. Without `--out`, the script writes `build/<name>.prg`. See "Build names".
|
|
47
|
+
- The script writes the symbols of the program to `symbols/<name>.json` in the folder of the program, for example `build/symbols/clean.json`. Give this file to a test run as the symbols of the rebuild.
|
|
46
48
|
- Get the label of a release from the releases in the project knowledge. Record a release in the project knowledge before you build it.
|
|
47
49
|
- Before you use `--compare`, put the program bytes into the project knowledge.
|
|
48
50
|
- The target CPU is the 6510. The program is a C64 PRG, or the bytes only with `--plain`.
|
|
@@ -55,6 +57,19 @@ A source that you generated from the project knowledge has switches in `config.a
|
|
|
55
57
|
- To turn a switch on, change its value in `config.asm`, for example `TRAINER = 1`. Do not use `--define` for a switch. ACME then stops with `Symbol already defined`.
|
|
56
58
|
- With `--release <label>`, each switch has the value of that release. A release build does not read `config.asm`.
|
|
57
59
|
|
|
60
|
+
### Build names
|
|
61
|
+
|
|
62
|
+
Without `--out`, the name of the program tells what the build is:
|
|
63
|
+
|
|
64
|
+
| Build | Name |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `--release <label>` | `release_<label>.prg`, for example `release_ORIGINAL.prg` |
|
|
67
|
+
| Each value of `config.asm` is its default | `clean.prg` |
|
|
68
|
+
| A value of `config.asm` is not its default | `custom_<switches>.prg`, for example `custom_trainer.prg`. A switch that is off has `no_` before its name, for example `custom_no_start_screen.prg`. |
|
|
69
|
+
| A source without `config.asm` | the name of the entry, for example `main.prg` |
|
|
70
|
+
|
|
71
|
+
An entry other than `main.asm` adds its name, for example `clean_loader.prg` for `loader.asm`. With `--plain`, the extension is `.bin`. Do not give `--out` for a build of a generated source. Then the name always tells the build.
|
|
72
|
+
|
|
58
73
|
### Paths and the project folder
|
|
59
74
|
|
|
60
75
|
- Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
|
|
@@ -81,8 +96,8 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
81
96
|
|
|
82
97
|
| Flag | Command | Effect |
|
|
83
98
|
|---|---|---|
|
|
84
|
-
| `--out <file.prg>` | `build` |
|
|
85
|
-
| `--include <
|
|
99
|
+
| `--out <file.prg>` | `build` | The path of the program, relative to the project folder. The default is `build/<name>.prg`. See "Build names". |
|
|
100
|
+
| `--include <folder>` | `build` | An include folder: a path relative to the source root, inside the project folder. Give the flag again for each folder. The default is no include folder. |
|
|
86
101
|
| `--define NAME=VALUE` | `build` | An assembler symbol: an integer, also `$` and hex digits, or `true` or `false`. Give the flag again for each symbol. Do not use it for a switch. |
|
|
87
102
|
| `--set-pc <address>` | `build` | The start address when the source does not set one, for example `'$0801'`. |
|
|
88
103
|
| `--release <label>` | `build` | Build a release of the project knowledge. Each switch gets the value of that release. With `--compare`, the reference is the file of the release. |
|
|
@@ -91,7 +106,6 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
91
106
|
| `--plain` | `build` | Write only the bytes of the program, without the 2-byte load address. Off by default. |
|
|
92
107
|
| `--all-symbols` | `build` | List also the constants that the source does not use. Off by default. |
|
|
93
108
|
| `--max-listed <n>` | `build` | List at most `n` symbols. The default is 50. `symbols.count` always gives the count of all symbols. |
|
|
94
|
-
| `--out-symbols <file.json>` | `build` | Write the listed symbols to this file as `{"symbols": [...]}`. Without `--all-symbols`, the file does not have the constants that the source does not use. |
|
|
95
109
|
|
|
96
110
|
---
|
|
97
111
|
|
|
@@ -99,7 +113,7 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
99
113
|
|
|
100
114
|
### `build <source-root> <entry>`
|
|
101
115
|
|
|
102
|
-
Assembles the source and writes the program to `--out`.
|
|
116
|
+
Assembles the source and writes the program to `--out`, or to `build/<name>.prg`. It also writes the symbols to `symbols/<name>.json` in the folder of the program. Without `--all-symbols`, that file does not have the constants that the source does not use.
|
|
103
117
|
|
|
104
118
|
`body` holds:
|
|
105
119
|
|
|
@@ -112,7 +126,7 @@ Assembles the source and writes the program to `--out`.
|
|
|
112
126
|
- Kind `address` has a value in `loadRange`. It gives `address`.
|
|
113
127
|
- Kind `constant` has a value outside `loadRange`. It gives `value` as `$` and four or more hex digits. A label in a `!pseudopc` block can be a constant, because its value is the run address, not the load address.
|
|
114
128
|
- `used` is `false` when the source does not use the symbol.
|
|
115
|
-
- `symbolsFile`: the file
|
|
129
|
+
- `symbolsFile`: the symbols file, with `out`, `bytes` and `sha256`.
|
|
116
130
|
- `unusedConstants`: the count of the constants that the list does not include. It is not in the body with `--all-symbols`.
|
|
117
131
|
- `diagnostics`: each item has `severity` (`error`, `warning` or `note`), `file`, `line` and `message`. `file` is relative to the source root. A file in an include folder outside the source root starts with `../`. `file` and `line` are not in an item without a location in the source.
|
|
118
132
|
- `compare`: only with `--compare`. `identical` is `true` when each segment is identical. `segments` has one item for each segment of the reference program, with `start`, `end` and `result`:
|
|
@@ -125,7 +139,7 @@ Do as the result tells:
|
|
|
125
139
|
- `result` is `PASS`: the program is at `out`. To run or debug the program, load the file at `out` into the emulator.
|
|
126
140
|
- `result` is `FAIL` and `assembled` is `false`: the source has errors, and the script wrote no program. `hint` tells you to correct the source. Correct the source at the file and the line of each diagnostic. Then run `build` again.
|
|
127
141
|
- `result` is `FAIL` and `assembled` is `true`: the program is not identical to the reference. The script wrote the program. Read the first difference of each segment in `compare.segments`. Without `--release`, read the section "Switches" first.
|
|
128
|
-
- `hint` tells that `symbols` is cut: give a larger `--max-listed`, or
|
|
142
|
+
- `hint` tells that `symbols` is cut: give a larger `--max-listed`, or read the symbols file for the full list.
|
|
129
143
|
- Error `not-found` names the entry: give the main source file relative to the source root.
|
|
130
144
|
- Error `not-found` names an include folder: give `--include` a folder with files, relative to the source root.
|
|
131
145
|
- Error `invalid-input` names an include folder: the folder is outside the project folder. Give `--include` a folder inside the project folder.
|
|
@@ -135,7 +149,7 @@ Do as the result tells:
|
|
|
135
149
|
|
|
136
150
|
The script does not keep the diagnostics or the program in the project knowledge.
|
|
137
151
|
|
|
138
|
-
To compare runs of the rebuild with runs of the original, give the file
|
|
152
|
+
To compare runs of the rebuild with runs of the original, give the symbols file to the test run as the symbols of the rebuild. A symbol of the rebuild gives the address of a routine in the rebuild.
|
|
139
153
|
|
|
140
154
|
---
|
|
141
155
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The c64-assembler script: assembles project source with ACME, which it runs
|
|
2
2
|
// itself, and writes the program into the project.
|
|
3
3
|
|
|
4
|
+
import { type BuildKind, buildName, CONFIG_FILE, configValues, symbolsPath } from "#src/build-name.ts";
|
|
4
5
|
import { formatC64Address } from "#src/c64.ts";
|
|
5
6
|
import { Refusal } from "#src/errors.ts";
|
|
6
7
|
import { readImage } from "#src/host-client/image.ts";
|
|
@@ -8,8 +9,8 @@ import { readSourceTree, writeReported } from "#src/host-client/transfer.ts";
|
|
|
8
9
|
import { openForRead } from "#src/knowledge/database.ts";
|
|
9
10
|
import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
10
11
|
import { requireProgram } from "#src/knowledge/program.ts";
|
|
11
|
-
import { releaseLabeled } from "#src/knowledge/read.ts";
|
|
12
|
-
import { RELEASE_DEFINE } from "#src/knowledge/schema.ts";
|
|
12
|
+
import { listSwitches, releaseLabeled } from "#src/knowledge/read.ts";
|
|
13
|
+
import { LEFTOVERS_SWITCH, RELEASE_DEFINE, START_SCREEN_SWITCH, type Space } from "#src/knowledge/schema.ts";
|
|
13
14
|
import { assemble, showSymbol, symbolsFileText } from "#src/native/acme.ts";
|
|
14
15
|
import { localToolContext } from "#src/native/local.ts";
|
|
15
16
|
import type { AcmeParams, AssembledSymbol } from "#src/native/types.ts";
|
|
@@ -26,6 +27,16 @@ function parseDefine(text: string): [string, number | boolean] {
|
|
|
26
27
|
throw new UsageError(`--define ${match[1]} needs an integer or true/false, not ${value}`);
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
/** The default of each switch of a generated source: the knowledge gives them, the start screen is in and the leftovers are out. */
|
|
31
|
+
function switchDefaults(space: Space): Map<string, number> {
|
|
32
|
+
const db = openForRead();
|
|
33
|
+
try {
|
|
34
|
+
return new Map([[START_SCREEN_SWITCH, 1], [LEFTOVERS_SWITCH, 0], ...listSwitches(db, undefined, space).map((row) => [row.name, row.default] as const)]);
|
|
35
|
+
} finally {
|
|
36
|
+
db?.close();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
await runScript({
|
|
30
41
|
name: "assembler",
|
|
31
42
|
summary: "Assembles project source with ACME and writes the program into the project.",
|
|
@@ -39,8 +50,8 @@ await runScript({
|
|
|
39
50
|
{ name: "<entry>", help: "the main source file, relative to the source root" },
|
|
40
51
|
],
|
|
41
52
|
options: {
|
|
42
|
-
out: { ...OPTIONS.out, output: "file", value: "<file.prg>", help: "where to write the program, relative to the project folder
|
|
43
|
-
include: { kind: "text", value: "<
|
|
53
|
+
out: { ...OPTIONS.out, output: "file", value: "<file.prg>", help: "where to write the program, relative to the project folder. The default is build/<build>.prg: release_<label> with --release, else clean or custom_<switches> from config.asm, with _<entry> for an entry other than main.asm" },
|
|
54
|
+
include: { kind: "text", value: "<folder>", multiple: true, help: "an include folder: a path relative to the source root, inside the project folder" },
|
|
44
55
|
define: { kind: "text", value: "NAME=VALUE", multiple: true, help: "an assembler symbol: an integer ($hex allowed) or true/false" },
|
|
45
56
|
"set-pc": { kind: "address", value: "<address>", help: "the start address when the source sets none, for example '$0801'" },
|
|
46
57
|
release: { kind: "text", value: "<label>", help: `build a release of the knowledge: defines ${RELEASE_DEFINE}<label>=1, so each switch has the value of that release. With --compare, the reference is the file of the release` },
|
|
@@ -49,12 +60,10 @@ await runScript({
|
|
|
49
60
|
plain: { kind: "flag", help: "write the bytes only, without the 2-byte load address of a PRG" },
|
|
50
61
|
"all-symbols": { kind: "flag", help: "list also the constants that the source does not use" },
|
|
51
62
|
"max-listed": { ...OPTIONS["max-listed"], help: "list at most n symbols (default 50). The count is always given" },
|
|
52
|
-
"out-symbols": { kind: "path", output: "file", value: "<file.json>", help: "write the listed symbols to this project file as {\"symbols\": [...]}: the names of the rebuild for a test run. Without --all-symbols, the file does not have the constants that the source does not use" },
|
|
53
63
|
},
|
|
54
64
|
notes: "Symbol values are $ and at least four hex digits. Before --compare, put the program bytes into the project knowledge. Without --release, the build has the switch values of config.asm. With the defaults, this is the clean program, which is not the bytes of a release when a switch has a default that the base release does not have. Set a switch in config.asm, not with --define: ACME stops with Symbol already defined.",
|
|
55
65
|
run: async (call) => {
|
|
56
66
|
const [sourceRoot, entry] = [call.subject(0), call.subject(1)];
|
|
57
|
-
const out = call.string("out")!;
|
|
58
67
|
// Read the reference before ACME runs, so a project without it stops at once.
|
|
59
68
|
let program: Reference | undefined;
|
|
60
69
|
const label = call.string("release");
|
|
@@ -77,19 +86,22 @@ await runScript({
|
|
|
77
86
|
const setPc = call.address("set-pc");
|
|
78
87
|
const { contents, ...tree } = readSourceTree(sourceRoot, call.strings("include"));
|
|
79
88
|
if (!tree.files.some((file) => file.path === (tree.sourceDir === "" ? entry : `${tree.sourceDir}/${entry}`))) throw new Refusal("not-found", `${entry} is not a file in ${sourceRoot}. Give the main source file relative to the source root.`);
|
|
89
|
+
// The name of the build tells what it is: the release, or the switch values of config.asm.
|
|
90
|
+
const config = tree.files.findIndex((file) => file.path === (tree.sourceDir === "" ? CONFIG_FILE : `${tree.sourceDir}/${CONFIG_FILE}`));
|
|
91
|
+
const kind: BuildKind | undefined = label !== undefined ? { release: label } : config < 0 ? undefined : { values: configValues(contents[config]!.toString("utf8")), defaults: switchDefaults(call.space) };
|
|
92
|
+
const plain = call.flag("plain");
|
|
93
|
+
const out = call.string("out") ?? `build/${buildName(entry, kind)}.${plain ? "bin" : "prg"}`;
|
|
80
94
|
const params: AcmeParams = { ...tree, entrySource: entry, defines: { ...releaseDefine, ...Object.fromEntries(call.strings("define").map(parseDefine)) }, ...(setPc === undefined ? {} : { setPc }) };
|
|
81
95
|
|
|
82
96
|
const { result, attachments } = await assemble(params, contents, localToolContext());
|
|
83
97
|
if (!result.assembled) return reply({ result: "FAIL", assembled: false, diagnostics: result.diagnostics }, { hint: "The source has errors, and no program was written. Correct the source at the file and the line of each diagnostic. Then run build again." });
|
|
84
|
-
const plain = call.flag("plain");
|
|
85
98
|
const written = writeReported(out, plain ? attachments![0]!.subarray(2) : attachments![0]!, { what: "--out" });
|
|
86
99
|
const range = result.loadRange!;
|
|
87
100
|
const compared = program === undefined ? undefined : compareBuild(attachments![0]!, program);
|
|
88
101
|
// An include file of platform names gives many constants that the program does not use.
|
|
89
102
|
const all = call.flag("all-symbols");
|
|
90
103
|
const shown = result.symbols!.filter((symbol) => all || symbol.kind === "address" || symbol.used);
|
|
91
|
-
const
|
|
92
|
-
const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, "a larger --max-listed, or --out-symbols <file.json> for the whole list");
|
|
104
|
+
const symbols = listedItems(shown, call.count("max-listed")!, showSymbol, `a larger --max-listed, or read ${symbolsPath(out)}`);
|
|
93
105
|
// A build that differs from its reference is a failed check.
|
|
94
106
|
const different = compared !== undefined && !compared.identical;
|
|
95
107
|
const hints = [
|
|
@@ -104,7 +116,8 @@ await runScript({
|
|
|
104
116
|
...(plain ? { plain: true } : {}),
|
|
105
117
|
loadRange: { start: formatC64Address(range.start), end: formatC64Address(range.end), bytes: range.bytes },
|
|
106
118
|
symbols,
|
|
107
|
-
|
|
119
|
+
// The symbols of the program for a test run, in symbols/ next to it.
|
|
120
|
+
symbolsFile: writeReported(symbolsPath(out), symbolsFileText(shown), { what: "--out" }),
|
|
108
121
|
...(all ? {} : { unusedConstants: result.symbols!.length - shown.length }),
|
|
109
122
|
diagnostics: result.diagnostics,
|
|
110
123
|
...(compared === undefined ? {} : { compare: compared }),
|
|
@@ -25,7 +25,7 @@ To get the command list, run the script with no arguments.
|
|
|
25
25
|
|---|---|
|
|
26
26
|
| Pack a BASIC program at `$0801` that starts with `SYS` | `pack build/game.prg --out build/game-packed.prg` |
|
|
27
27
|
| Pack a program that starts at a known address | `pack build/main.prg --entry '$0400' --out build/release.prg` |
|
|
28
|
-
| Merge more PRG files into one packed program | `pack build/
|
|
28
|
+
| Merge more PRG files into one packed program | `pack build/clean_loader.prg build/clean.prg --entry '$0400' --out build/clean_packed.prg` |
|
|
29
29
|
| Start the program with RAM in place of the BASIC and KERNAL ROMs | `pack build/game.prg --exit-memory '$35' --out build/game-packed.prg` |
|
|
30
30
|
|
|
31
31
|
---
|
|
@@ -72,10 +72,10 @@ Each flag applies only to the commands in the table. On another command, the scr
|
|
|
72
72
|
|
|
73
73
|
| Flag | Command | Effect |
|
|
74
74
|
|---|---|---|
|
|
75
|
-
| `--out <dir>` | `generate` | The folder for the source files. It is necessary. The script writes over the files of an earlier run. It removes a generated `.asm` file that this run does not write. A run without `--loader` keeps `loader.asm`,
|
|
75
|
+
| `--out <dir>` | `generate` | The folder for the source files. It is necessary. The script writes over the files of an earlier run. It removes a generated `.asm` file that this run does not write. A run without `--loader` keeps `loader.asm`, the loader program, `start_screen.asm` and `start_screen_stage.asm` of an earlier run. `staleLoader` tells when they are of another knowledge revision. |
|
|
76
76
|
| `--entry <address>` | `generate` | An address where code starts. Give the flag again for more addresses. There is no default. |
|
|
77
77
|
| `--space <space>` | `generate` | The knowledge space: `c64`, `drive8`, `loading`, or `bank0` to `bank255`. The default is `c64`. `--loader` and the platform names apply only to `c64`. The coverage is the coverage of the space. |
|
|
78
|
-
| `--loader` | `generate` | Also write `loader.asm` and
|
|
78
|
+
| `--loader` | `generate` | Also write `loader.asm` and the loader program, and `start_screen.asm` when the knowledge has a start screen. A start screen of a captured stage also gives `start_screen_stage.asm`. The script writes the loader program only after the check of the new loader ran. Else the loader program of an earlier run stays. It needs a capture in the knowledge. The default is no loader. |
|
|
79
79
|
| `--analyzer-names` | `generate` | Name an address without a name of the user or the LLM, and without a platform name, with its analyzer name, for example `FUN_17e2`. Without the flag, the source makes its own name, for example `l_17e2`. |
|
|
80
80
|
| `--to <folder>` | `export` | The folder of the new project. It is necessary. The script also writes `<folder>.zip` beside the folder. |
|
|
81
81
|
| `--name <name>` | `export` | The name of `baseline/<name>.prg` and `build/<name>.prg`. The default is the name of the folder. |
|
|
@@ -110,7 +110,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
110
110
|
- `asBytes`: the instructions that the source has as bytes.
|
|
111
111
|
- `notExecuted`: with coverage, the count of instructions that no run executed, and their ranges. `rest` names `not_executed.json`, which has all the ranges. Each range there has its source `file` and the `routine` before it.
|
|
112
112
|
- `unusedModules`: modules whose start is in no segment of the program. Often the program does not hold the code that the knowledge describes.
|
|
113
|
-
- `leftovers`: the bytes that nothing uses, with `bytes` and each range with its `file`. See "The leftovers". `noCoverage` tells that the knowledge has no coverage, so no range is a leftover.
|
|
113
|
+
- `leftovers`: the bytes that nothing uses, with `bytes` and each range with its `file`. See "The leftovers". `noCoverage` tells that the knowledge has no coverage, so no range is a leftover. `changed` gives the ranges that are `added` to the leftovers and `removed` from them since the earlier run in `--out`.
|
|
114
114
|
- `operandExpressions`: the count of instructions with an operand expression.
|
|
115
115
|
- `operandsAsNumbers`: each operand expression that the source has as a number, with its `address`, `expression` and `reason`.
|
|
116
116
|
- `macroUses`: the count of macro uses in the source.
|
|
@@ -118,7 +118,7 @@ To make the source better, change the project knowledge. Then generate again.
|
|
|
118
118
|
- `patchesNotWritten`: each patch that the source does not have, with its range, `switch` and `reason`.
|
|
119
119
|
- `switches`, `default`, `releases`: the checks of the switches. See "Switches and releases".
|
|
120
120
|
- `loader`: the check of the loader. See "The loader".
|
|
121
|
-
- `staleLoader`: a run without `--loader` kept `loader.asm` and
|
|
121
|
+
- `staleLoader`: a run without `--loader` kept `loader.asm` and the loader program of another knowledge revision. `files` gives the files. `revision` gives the revision of `loader.asm`. Without `revision`, `loader.asm` does not give one. `noEntryState: true` tells that the knowledge has no entry state for a new loader.
|
|
122
122
|
|
|
123
123
|
`result` is `FAIL` for each of these:
|
|
124
124
|
|
|
@@ -200,9 +200,10 @@ A leftover is a range of the program that nothing uses: unused code, old copies
|
|
|
200
200
|
- `main.asm` builds a leftover file only when `LEFTOVERS` is 1. When it is 0, the build skips the bytes. Thus the addresses after the range do not change.
|
|
201
201
|
- `config.asm` has `LEFTOVERS = 0`. Thus the default build is the clean program, without the leftovers.
|
|
202
202
|
- Each release has `LEFTOVERS = 1`. Thus the build of a release gives the bytes of its file.
|
|
203
|
-
-
|
|
203
|
+
- The loader program never has the leftovers. The loader does not copy them, and the memory there keeps the bytes that were in it before.
|
|
204
204
|
- Without coverage, no range is a leftover. Put the coverage of the runs into the project knowledge. Then generate again.
|
|
205
|
-
-
|
|
205
|
+
- When `leftovers.changed` has ranges, the default build and the loader program now leave out other bytes. A test that observes the `added` bytes on the loader program gets other values there. Fill the `added` ranges in the test of the leftovers. In a test that compares them, exclude them with the reason that they are leftovers.
|
|
206
|
+
- A leftover can be wrong when the coverage does not show a use. For example, the VIC-II reads a range, or the program reads a range before it writes it. Then a test of the loader program fails. Record the region in the project knowledge, or put the coverage of more runs into it. Do not change the source.
|
|
206
207
|
|
|
207
208
|
#### Switches and releases
|
|
208
209
|
|
|
@@ -244,7 +245,14 @@ Build the program from the source in these ways:
|
|
|
244
245
|
|
|
245
246
|
#### The loader
|
|
246
247
|
|
|
247
|
-
`--loader` writes `loader.asm` and assembles it to
|
|
248
|
+
`--loader` writes `loader.asm` and assembles it to the loader program. The name of the loader program tells its build:
|
|
249
|
+
|
|
250
|
+
- `clean_loader.prg`: each value of `config.asm` is its default. This is the clean program.
|
|
251
|
+
- `custom_<switches>_loader.prg`: the names of the switches that are not at their default. A switch that is off has `no_` before its name, for example `custom_no_start_screen_loader.prg`.
|
|
252
|
+
|
|
253
|
+
The symbols of the loader program are in `symbols/<name>.json`, for example `symbols/clean_loader.json`. They hold the labels of `loader.asm`, `main.asm` and `start_screen_stage.asm`. Give this file to a test of the loader program as its symbols. When the name changes, the script removes the loader program of the earlier run and its symbols.
|
|
254
|
+
|
|
255
|
+
The loader does these steps:
|
|
248
256
|
|
|
249
257
|
1. `10 SYS 2061` starts it.
|
|
250
258
|
2. It stops the interrupts and makes all RAM visible. It moves its copier to two free pages.
|
|
@@ -258,27 +266,26 @@ The copy table, the copier and the jump use labels, not numbers. `loader_from_xx
|
|
|
258
266
|
|
|
259
267
|
The loader changes the free stack byte below the stack pointer (`stackByte`). It does not set the SID, the time of day of the CIAs, the CIA interrupt flags or the interrupt registers of the VIC-II. A program that reads SID voice 3 for random numbers can thus give a different result. A start screen writes the colour RAM, and the loader does not set it again. When you compare the original and the rebuild, observe after the program sets its own random numbers.
|
|
260
268
|
|
|
261
|
-
The script builds and checks
|
|
269
|
+
The script builds and checks the loader program with the values of `config.asm`. With the defaults, the loader program is the clean program: no copy protection, all corrections and no leftovers. The entry state is the state of the base release. For a loader of a release, build `loader.asm` with the build option `--release <label>`. That loader also does not have the leftovers.
|
|
262
270
|
|
|
263
271
|
The start screen:
|
|
264
272
|
|
|
265
273
|
- The start screen needs the VIC-II values of the entry state. Its screen, bitmap, charset and colours must be in a segment of the program, or in a captured stage. See "The start screen of a captured stage".
|
|
266
274
|
- With a start screen, the copier uses three pages, not two.
|
|
267
|
-
- The start screen is part of the clean build only.
|
|
275
|
+
- The start screen is part of the clean build only. The loader program always shows it. A release build has no start screen, and `LEFTOVERS = 1` also turns it off.
|
|
268
276
|
- To start the program at once, set `START_SCREEN = 0` in `config.asm`, and assemble `loader.asm`. Do not define `START_SCREEN` on the command line of the build: `config.asm` sets it.
|
|
269
|
-
- A test that runs
|
|
270
|
-
- `loader.json` is the symbol file of `loader.prg`. It holds the labels of `loader.asm`, `main.asm` and `start_screen_stage.asm`. Give it to a test of `loader.prg` as its symbols.
|
|
277
|
+
- A test that runs the loader program stops at the start screen, because the emulator cannot press a key of the keyboard matrix. Run until `loader_start_screen_wait`. Then set the PC to `loader_start_screen_continue`.
|
|
271
278
|
|
|
272
279
|
`loader` holds these fields:
|
|
273
280
|
|
|
274
281
|
- `program`, the `copies` in their order, `copier` and `stackByte`.
|
|
275
|
-
- `verified: true`: the check ran
|
|
282
|
+
- `verified: true`: the check ran the loader program to its jump to the entry. There, the memory, $00/$01, the registers and the VIC-II are equal to the entry state. The raster line and the CIA values are also equal. An interrupt can run right at the entry, as in the original program.
|
|
276
283
|
- `limits`: each CIA value that the loader cannot set as it was at the entry. An old capture has no CIA values. Then capture the program again at its entry point.
|
|
277
284
|
- `startScreen`: with a start screen, `shown: true` when the VIC-II had the values of the start screen, and `waits: true` when the start screen waited without a key. `wait` and `continue` are the addresses of the wait and of the code after it. The check sets the PC to `continue`, and then runs the loader to its jump.
|
|
278
|
-
- `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in
|
|
279
|
-
- `stage`: the show stage of a start screen of a captured stage. It has the `space` of the stage and the address of the show `code`. It also has the `bytes` of the stage in
|
|
280
|
-
- When the check of
|
|
281
|
-
- `kept`: when the result has no new
|
|
285
|
+
- `packed`: `packedBytes` and `unpackedBytes` of the packed form. With a start screen of a captured stage, this is the packed program in the loader program.
|
|
286
|
+
- `stage`: the show stage of a start screen of a captured stage. It has the `space` of the stage and the address of the show `code`. It also has the `bytes` of the stage in the loader program, the `stash` copies, `packedBytes` and `unpackedBytes`. `startScreen.stage` names the space.
|
|
287
|
+
- When the check of the loader program cannot run, the script does not write a loader program. The loader program of an earlier run stays as it was. `loader.asm` is new. `reason` tells why the check did not run.
|
|
288
|
+
- `kept`: when the result has no new loader program, the paths of the loader programs of an earlier run. They are not of this source.
|
|
282
289
|
|
|
283
290
|
Do these actions when `verified` is `false`:
|
|
284
291
|
|
|
@@ -289,7 +296,7 @@ Do these actions when `verified` is `false`:
|
|
|
289
296
|
| `reason` that the source does not assemble | Correct the source first. The loader includes the source. |
|
|
290
297
|
| `reason` about the start screen | Correct the start screen in the project knowledge, or capture the program again with the start screen in memory. If the start screen is not necessary, remove it from the project knowledge. |
|
|
291
298
|
| `reason` about the show stage | If the reason names the coverage of the stage, run the stage with coverage. Put the map into the project knowledge in the space of the stage. If the memory is too small, capture the stage again with less memory. If a tool is missing, stop the task and give the message to the user. If `start_screen_stage.asm` does not assemble, stop the task and give the reason to the user. The reason names the file in `.c64-re-tools/local/` with the source that failed. |
|
|
292
|
-
| `reason` that the check of
|
|
299
|
+
| `reason` that the check of the loader program did not run | Stop the task and give the reason to the user. When the user tells you that the emulator is available, run the same command again. |
|
|
293
300
|
| `differences` | The loader ran. The list gives the bytes and the registers that are not equal. |
|
|
294
301
|
| `stop` | The loader did not get to its copier or its jump. `stop` gives the address and `port`, the value of $01. `history` gives the last 16 instructions. `cause` gives the first byte of the copier or of a copy that is not correct. |
|
|
295
302
|
|
|
@@ -300,8 +307,8 @@ Often the loading stage of a program shows a picture that is not in memory at th
|
|
|
300
307
|
The loader then always has the packed form, and the start screen is a program of its own in front of it:
|
|
301
308
|
|
|
302
309
|
1. Exomizer packs the program with the copier. This is the packed loader.
|
|
303
|
-
2. Exomizer packs the packed loader, the bytes of the stage and the show code into
|
|
304
|
-
3. When
|
|
310
|
+
2. Exomizer packs the packed loader, the bytes of the stage and the show code into the loader program.
|
|
311
|
+
3. When the loader program starts, Exomizer unpacks these parts. The program stays packed. The bytes of the packed loader under the stage go to a stash in free memory.
|
|
305
312
|
4. The show code shows the start screen with `start_screen.asm`. With a call, it sets $01 to $37, starts the interrupts and calls the routine.
|
|
306
313
|
5. It waits for a key or a fire button, as the start screen in the program does.
|
|
307
314
|
6. It stops the interrupts and the sound, and it stops the screen. It sets the CIA timers as RUN leaves them.
|
|
@@ -310,26 +317,26 @@ The loader then always has the packed form, and the start screen is a program of
|
|
|
310
317
|
The program is packed while the screen shows. Thus the picture and the tune have more free memory.
|
|
311
318
|
|
|
312
319
|
- The script puts everything in memory. It does not matter where the stage keeps its bytes, if the memory has enough room.
|
|
313
|
-
-
|
|
320
|
+
- The loader program has only the bytes of the stage that the start screen uses. These are the screen, the bitmap and the charset. With a call, they are also each byte of the stage that is not free from the call, as in "The free ranges". A call thus needs the coverage of the stage.
|
|
314
321
|
- With colours from the colour RAM of the capture, the show code holds the 1000 colours. It copies them to the colour RAM.
|
|
315
322
|
- The patches of the stage are in at the defaults of their switches. Thus a patch under a switch can remove the text of a crack from the picture.
|
|
316
|
-
- `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make
|
|
323
|
+
- `start_screen_stage.asm` holds the show code and the bytes of the stage. Do not edit it. To make the loader program again, run `generate --loader`.
|
|
317
324
|
- The show stage needs Exomizer. The show code needs free memory in $0400-$9fff or $c000-$cfff. When the memory is too small, the reason gives the largest free ranges.
|
|
318
|
-
- The check runs
|
|
325
|
+
- The check runs the loader program to `loader_start_screen_wait` of the show stage. There, it compares the VIC-II with the start screen, the screen bytes in memory with the stage, and the colour RAM with the capture. Then it sets the PC to `loader_start_screen_continue`, and it checks the loader as usual.
|
|
319
326
|
|
|
320
327
|
#### The packed loader
|
|
321
328
|
|
|
322
329
|
A loader file that loads into $d000 or higher writes the I/O area. When the program is too large for one loader file, `loader.asm` has the packed form:
|
|
323
330
|
|
|
324
331
|
- `loader.asm` holds only the copier and the bytes below $0400. The segments at $0400 and higher are not in `loader.asm`. Between its free ranges, `loader.asm` holds the bytes of the program.
|
|
325
|
-
-
|
|
332
|
+
- The loader program is the build of `main.asm` from $0400 and the build of `loader.asm`, packed into one file. Where the two builds overlap, the loader program has the bytes of `loader.asm`.
|
|
326
333
|
- The jump to the entry uses the address of the entry, not its label.
|
|
327
334
|
|
|
328
335
|
To make the packed loader for other switch values, do these steps:
|
|
329
336
|
|
|
330
|
-
1. Assemble `main.asm`
|
|
331
|
-
2. Assemble `loader.asm` to `build/
|
|
332
|
-
3. Pack the two files into `build/
|
|
337
|
+
1. Assemble `main.asm` without an output path. The build name of the program tells the switch values, for example `build/custom_trainer.prg`. The leftovers are $00 in this build.
|
|
338
|
+
2. Assemble `loader.asm` without an output path, for example to `build/custom_trainer_loader.prg`. This is the copier.
|
|
339
|
+
3. Pack the two files into `build/custom_trainer_packed.prg`. The start address is the copier address in the comment at the start of `loader.asm`. The memory configuration at the exit is `$34`.
|
|
333
340
|
|
|
334
341
|
These steps do not work when a segment starts below $0400. They also do not work when a patch is between the free ranges of `loader.asm`. In these cases, use `generate --loader` for the base release.
|
|
335
342
|
|
|
@@ -440,7 +447,7 @@ tests/ the tests of the project, changed for the new program
|
|
|
440
447
|
5. Record names, comments, regions and modules in the project knowledge.
|
|
441
448
|
6. Run `generate` again. Do steps 4 to 6 again until the source is clear.
|
|
442
449
|
7. Assemble `main.asm` to a program. This is the default build. For a release, give the build option `--release <label>`.
|
|
443
|
-
8. For an unpacked program, run `generate` with `--loader` at the end. Compare
|
|
450
|
+
8. For an unpacked program, run `generate` with `--loader` at the end. Compare the loader program with the original program in a test.
|
|
444
451
|
9. To start a new program from the rebuild, run `export`.
|
|
445
452
|
|
|
446
453
|
---
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// tells what stays. Without coverage nothing becomes free by itself.
|
|
11
11
|
|
|
12
12
|
import { type AddressRange, COVERAGE, formatC64Address, pointerTableEntries, POINTER_TABLE_TYPES, type PointerTableType } from "#src/c64.ts";
|
|
13
|
+
import { symbolsPath } from "#src/build-name.ts";
|
|
13
14
|
import { Refusal } from "#src/errors.ts";
|
|
14
15
|
import { NO_FALL_THROUGH, type Root, separate } from "#src/knowledge/separate.ts";
|
|
15
16
|
import type { RegionType } from "#src/knowledge/schema.ts";
|
|
@@ -420,7 +421,7 @@ export function rewriteTest(text: string, name: string, symbols: ReadonlyMap<str
|
|
|
420
421
|
if (inside(address, free)) return { reason: `it names ${location}, which is in a free range` };
|
|
421
422
|
} else if (!symbols.has(location)) return { reason: `it names ${location}, which the exported program does not have` };
|
|
422
423
|
}
|
|
423
|
-
const side = (program: string) => ({ program: `${program}.prg`, symbols: `${program}.
|
|
424
|
+
const side = (program: string) => ({ program: `${program}.prg`, symbols: symbolsPath(`${program}.prg`) });
|
|
424
425
|
if (scenario) {
|
|
425
426
|
// Both sides are the exported program now: a step of the original alone (for example a key for its intro) goes, and a step of the rebuild alone runs on both sides.
|
|
426
427
|
const { original: _original, rebuild: _rebuild, steps, ...rest } = test;
|
|
@@ -432,7 +433,7 @@ export function rewriteTest(text: string, name: string, symbols: ReadonlyMap<str
|
|
|
432
433
|
return { kind: "scenario", text: `${JSON.stringify({ ...rest, original: side(`baseline/${name}`), rebuild: side(`build/${name}`), steps: both }, null, 2)}\n` };
|
|
433
434
|
}
|
|
434
435
|
const start = test.start as Record<string, unknown>;
|
|
435
|
-
const symbolsFile = test.symbols === undefined || test.symbols === "none" ? {} : { symbols: `build/${name}.
|
|
436
|
+
const symbolsFile = test.symbols === undefined || test.symbols === "none" ? {} : { symbols: symbolsPath(`build/${name}.prg`) };
|
|
436
437
|
return { kind: "run", text: `${JSON.stringify({ ...test, start: { ...start, program: `build/${name}.prg` }, ...symbolsFile }, null, 2)}\n` };
|
|
437
438
|
}
|
|
438
439
|
|
|
@@ -460,7 +461,7 @@ export function readmeText(input: ReadmeInput): string {
|
|
|
460
461
|
"",
|
|
461
462
|
"## Build",
|
|
462
463
|
"",
|
|
463
|
-
`Assemble \`src/${input.entryFile}\` to \`build/${name}.prg\`, with its symbols in
|
|
464
|
+
`Assemble \`src/${input.entryFile}\` to \`build/${name}.prg\`, with its symbols in \`${symbolsPath(`build/${name}.prg`)}\`.`,
|
|
464
465
|
input.entryFile === "main.asm"
|
|
465
466
|
? "Compare the build with the program in the project knowledge: the source must give that program."
|
|
466
467
|
: "Assemble `src/main.asm` to `.c64-re-tools/local/program.prg`, and compare it with the program in the project knowledge: the source must give that program.",
|
|
@@ -492,7 +493,7 @@ export function readmeText(input: ReadmeInput): string {
|
|
|
492
493
|
"## Files",
|
|
493
494
|
"",
|
|
494
495
|
`- \`src/\`: the source. You own it now: change it as you like.`,
|
|
495
|
-
`- \`baseline/${name}.prg\` and
|
|
496
|
+
`- \`baseline/${name}.prg\` and \`${symbolsPath(`baseline/${name}.prg`)}\`: the exported program and its symbols, the reference of the scenarios.`,
|
|
496
497
|
"- `tests/`: the tests.",
|
|
497
498
|
"- `.c64-re-tools/knowledge/`: the names, comments and memory map of the exported program. They do not follow your changes to the source.",
|
|
498
499
|
"",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// screen in the knowledge, the copier shows it after the copies and waits for
|
|
12
12
|
// a key or a fire button: the code is start-screen.asm, the same for each program.
|
|
13
13
|
// The loader loads the segments without the leftovers: the ranges of the
|
|
14
|
-
// source that nothing uses are not in loader.
|
|
14
|
+
// source that nothing uses are not in the loader program.
|
|
15
15
|
|
|
16
16
|
import { readFileSync } from "node:fs";
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
@@ -651,7 +651,7 @@ const SHOWN_FREE = 8;
|
|
|
651
651
|
/**
|
|
652
652
|
* The packed form of the loader, for an image too large for one loader file:
|
|
653
653
|
* Exomizer packs the build of main.asm (from $0400) and the build of
|
|
654
|
-
* loader.asm into loader
|
|
654
|
+
* loader.asm into the loader program, which starts at the copier with all RAM
|
|
655
655
|
* visible ($01 = $34). loader.asm holds only the copier, in one free range,
|
|
656
656
|
* and the bytes of pages $0002-$03ff, in pieces in the free ranges: the
|
|
657
657
|
* unpacker of Exomizer uses the zero page and $0334-$03ff, so the copier
|
|
@@ -689,7 +689,7 @@ function planPacked(input: LoaderInput, blocks: Block[], cia: ReturnType<typeof
|
|
|
689
689
|
const lines: string[] = [
|
|
690
690
|
...input.header.map((line) => `; ${line}`),
|
|
691
691
|
"; The image is too large for one loader file, so this is the packed form. Exomizer packs the",
|
|
692
|
-
`; build of main.asm and the build of this file into loader
|
|
692
|
+
`; build of main.asm and the build of this file into the loader program, with --entry '${formatC64Address(copier)}' and --exit-memory '$34'.`,
|
|
693
693
|
"; The unpacker of Exomizer uses the zero page and $0334-$03ff, so the copier writes pages $0002-$03ff after the unpack.",
|
|
694
694
|
"",
|
|
695
695
|
"!cpu 6510",
|
|
@@ -815,7 +815,7 @@ function placePacked(free: AddressRange[], low: Parameters<typeof placePieces>[1
|
|
|
815
815
|
|
|
816
816
|
/** What Exomizer makes of a packed loader. */
|
|
817
817
|
export interface PackedLoader {
|
|
818
|
-
/** loader
|
|
818
|
+
/** The loader program: it loads at $0801 and starts with RUN. */
|
|
819
819
|
program: Buffer;
|
|
820
820
|
packedBytes: number;
|
|
821
821
|
unpackedBytes: number;
|
|
@@ -993,7 +993,7 @@ function vicLines(state: EntryState, earlier: number): string[] {
|
|
|
993
993
|
}
|
|
994
994
|
|
|
995
995
|
/**
|
|
996
|
-
* The symbols of loader
|
|
996
|
+
* The symbols of the loader program: the labels of the build of loader.asm, which
|
|
997
997
|
* includes main.asm, and of start_screen_stage.asm when the loader has a show
|
|
998
998
|
* stage. A test takes one symbols file. Refuses a name with two values.
|
|
999
999
|
*/
|
|
@@ -1003,7 +1003,7 @@ export function loaderSymbols(...builds: ReadonlyArray<readonly AssembledSymbol[
|
|
|
1003
1003
|
for (const symbol of builds.flat()) {
|
|
1004
1004
|
const known = byName.get(symbol.name);
|
|
1005
1005
|
if (known !== undefined && valueOf(known) !== valueOf(symbol)) {
|
|
1006
|
-
throw new WireFailure("operation-failed", `The builds of loader
|
|
1006
|
+
throw new WireFailure("operation-failed", `The builds of the loader program give ${symbol.name} two values, ${valueOf(known)} and ${valueOf(symbol)}. This is a defect of the script.`);
|
|
1007
1007
|
}
|
|
1008
1008
|
// An address in one build can be outside the load range of the other build, where it is a constant.
|
|
1009
1009
|
const kept = known === undefined || (known.kind === "constant" && symbol.kind === "address") ? symbol : known;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// each release has it, the default build does not, and the loader never
|
|
15
15
|
// loads it.
|
|
16
16
|
|
|
17
|
+
import { CONFIG_FILE, configValues } from "#src/build-name.ts";
|
|
17
18
|
import { type AddressRange, COVERAGE, formatC64Address, formatC64Byte, POINTER_TABLE_TYPES, pointerTableEntries, type PointerTableType } from "#src/c64.ts";
|
|
18
19
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
19
20
|
import { identifiers, operandText, replaceIdentifiers, type OperandExpression } from "#src/knowledge/expression.ts";
|
|
@@ -930,21 +931,7 @@ export const hasSwitchFile = (layout: Pick<Layout, "switches" | "releases" | "le
|
|
|
930
931
|
/** True when the source has config.asm: the knowledge has switches or a start screen, or the source has leftovers. */
|
|
931
932
|
export const hasConfigFile = (layout: Pick<Layout, "switches" | "startScreen" | "leftovers">) => layout.switches.length > 0 || layout.startScreen || layout.leftovers.length > 0;
|
|
932
933
|
|
|
933
|
-
|
|
934
|
-
export const CONFIG_FILE = "config.asm";
|
|
935
|
-
|
|
936
|
-
/** A value line of config.asm: NAME = 0 or NAME = 1. */
|
|
937
|
-
const CONFIG_VALUE = /^\s*([A-Z][A-Z0-9_]*)\s*=\s*([01])\s*(?:;.*)?$/;
|
|
938
|
-
|
|
939
|
-
/** The values of the switches in a config.asm text, by name. Lines that are not a value line are not read. */
|
|
940
|
-
export function configValues(text: string): Map<string, 0 | 1> {
|
|
941
|
-
const values = new Map<string, 0 | 1>();
|
|
942
|
-
for (const line of text.split(/\r?\n/)) {
|
|
943
|
-
const match = CONFIG_VALUE.exec(line);
|
|
944
|
-
if (match !== null) values.set(match[1]!, match[2] === "1" ? 1 : 0);
|
|
945
|
-
}
|
|
946
|
-
return values;
|
|
947
|
-
}
|
|
934
|
+
export { CONFIG_FILE, configValues };
|
|
948
935
|
|
|
949
936
|
/**
|
|
950
937
|
* config.asm: the value of each switch as a plain assignment, grouped by
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// the loader as it is in memory before it starts (the plain loader file, or
|
|
4
4
|
// the parts of the packed form), the bytes of the stage that the start screen
|
|
5
5
|
// uses at their own addresses, the bytes of the loader that those cover in a
|
|
6
|
-
// stash, and the show code into one loader.
|
|
6
|
+
// stash, and the show code into one loader program. The show code shows the
|
|
7
7
|
// screen with start-screen.asm, calls the routine of the stage, waits for a
|
|
8
8
|
// key or a fire button, stops the interrupts of the stage, sets the CIAs as
|
|
9
9
|
// RUN leaves them, copies the stash back and starts the loader.
|
|
@@ -143,7 +143,7 @@ export function stageText(input: StageInput, code: number, stash: StagePlan["sta
|
|
|
143
143
|
const { row } = input;
|
|
144
144
|
const lines = [
|
|
145
145
|
...input.header.map((line) => `; ${line}`),
|
|
146
|
-
`; The show stage of the start screen from ${row.stage}: Exomizer packs it with the loader into loader
|
|
146
|
+
`; The show stage of the start screen from ${row.stage}: Exomizer packs it with the loader into the loader program, with --entry '${formatC64Address(code)}'.`,
|
|
147
147
|
"; It shows the start screen, waits for a key or a fire button, copies back the bytes of the loader that the stage covers, and starts the loader.",
|
|
148
148
|
"",
|
|
149
149
|
"!cpu 6510",
|
|
@@ -14,7 +14,8 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync
|
|
|
14
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";
|
|
@@ -705,14 +706,24 @@ function sourceMapText(rendered: Rendered, space: string, revision: string | nul
|
|
|
705
706
|
return `${head},\n"labels": [\n${labels.join(",\n")}\n],\n"items": [\n${items.join(",\n")}\n]}\n`;
|
|
706
707
|
}
|
|
707
708
|
|
|
708
|
-
/** 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. */
|
|
709
710
|
const LOADER_CHECK_DIRECTORY = "loader-check";
|
|
710
711
|
|
|
711
|
-
/** The
|
|
712
|
-
const
|
|
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]);
|
|
713
714
|
|
|
714
|
-
/**
|
|
715
|
-
const
|
|
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
|
+
}
|
|
716
727
|
|
|
717
728
|
/** The start of the line of loader.asm that gives the knowledge revision of the loader. */
|
|
718
729
|
const LOADER_REVISION = "Loader generated by c64-source from knowledge revision ";
|
|
@@ -731,16 +742,42 @@ function staleLoader(out: string, revision: string): { files: string[]; revision
|
|
|
731
742
|
const line = text.split(/\r?\n/).find((row) => row.startsWith(`; ${LOADER_REVISION}`));
|
|
732
743
|
const old = line?.slice(`; ${LOADER_REVISION}`.length).replace(/\.$/, "");
|
|
733
744
|
if (old === revision) return undefined;
|
|
734
|
-
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)];
|
|
735
746
|
return { files, ...(old === undefined ? {} : { revision: old }) };
|
|
736
747
|
}
|
|
737
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
|
+
|
|
738
774
|
/**
|
|
739
775
|
* Removes the generated .asm files of an earlier run that this run does not
|
|
740
776
|
* write, and an earlier not_executed.json and source-map.json. An earlier
|
|
741
777
|
* loader.asm stays unless this run has --loader: a source of the user can
|
|
742
|
-
* include loader.asm. An earlier loader
|
|
743
|
-
* 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.
|
|
744
781
|
*/
|
|
745
782
|
function removeOldFiles(out: string, keep: ReadonlySet<string>, loaderRun: boolean): string[] {
|
|
746
783
|
const directory = resolveProjectPath(out);
|
|
@@ -995,7 +1032,7 @@ async function stageBytes(row: StartScreenRow): Promise<{ parts: StagePart[]; co
|
|
|
995
1032
|
return { parts: parts.map((range) => ({ start: range.start, body: memory.slice(range.start, range.end + 1) })), ...(colourRam === undefined ? {} : { colourRam }) };
|
|
996
1033
|
}
|
|
997
1034
|
|
|
998
|
-
/** 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. */
|
|
999
1036
|
interface BuiltStage {
|
|
1000
1037
|
program: Buffer;
|
|
1001
1038
|
text: string;
|
|
@@ -1060,7 +1097,7 @@ async function buildStage(files: Array<{ name: string; text: string }>, laid: La
|
|
|
1060
1097
|
const parts = stageParts(input, plan, built.program, built.label);
|
|
1061
1098
|
const packed = await packParts(parts, plan.code, 0x37, "the loader and the start screen of the stage", "the show stage", localToolContext());
|
|
1062
1099
|
const end = 0x0801 + packed.program.length - 3;
|
|
1063
|
-
if (end > 0xcfff) throw new Refusal("invalid-input", `loader
|
|
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.`);
|
|
1064
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 };
|
|
1065
1102
|
}
|
|
1066
1103
|
|
|
@@ -1104,6 +1141,10 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1104
1141
|
const configured = [...laid.switches, ...(laid.startScreen ? [{ name: START_SCREEN_SWITCH, default: 1 }] : []), ...(laid.leftovers.length > 0 ? [{ name: LEFTOVERS_SWITCH, default: 0 }] : [])];
|
|
1105
1142
|
const kept = new Map(configured.flatMap((row) => (given.has(row.name) ? [[row.name, given.get(row.name)!] as const] : [])));
|
|
1106
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);
|
|
1107
1148
|
const removed = removeOldFiles(out, new Set(files.map((file) => file.name)), loaderWanted).map((name) => `${out}/${name}`);
|
|
1108
1149
|
const stale = loaderWanted || space !== DEFAULT_SPACE ? undefined : staleLoader(out, knowledge.revision);
|
|
1109
1150
|
const written: Written[] = withValues(files, laid, kept).map((file) => writeReported(`${out}/${file.name}`, file.text, { what: "--out" }));
|
|
@@ -1123,6 +1164,10 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1123
1164
|
const all = { revision: knowledge.revision, instructions: rendered.notExecuted.instructions, files, ranges: placed };
|
|
1124
1165
|
written.push(writeReported(`${out}/${NOT_EXECUTED_FILE}`, `${JSON.stringify(all, null, 2)}\n`, { what: "--out" }));
|
|
1125
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) };
|
|
1126
1171
|
|
|
1127
1172
|
const output: Record<string, unknown> = {
|
|
1128
1173
|
out,
|
|
@@ -1158,8 +1203,10 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1158
1203
|
...(laid.leftovers.length === 0
|
|
1159
1204
|
? knowledge.coverage === undefined && space === DEFAULT_SPACE
|
|
1160
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." } }
|
|
1161
|
-
:
|
|
1162
|
-
|
|
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 }) } }),
|
|
1163
1210
|
...(rendered.expressions.length === 0 && rendered.operandsAsNumbers.length === 0 ? {} : { operandExpressions: rendered.expressions.length }),
|
|
1164
1211
|
...(rendered.operandsAsNumbers.length === 0
|
|
1165
1212
|
? {}
|
|
@@ -1180,9 +1227,12 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1180
1227
|
patchesNotWritten: listed(laid.patchesNotWritten, max, (item) => ({ start: formatC64Address(item.start), end: formatC64Address(item.end), switch: item.switch, reason: item.reason })),
|
|
1181
1228
|
}),
|
|
1182
1229
|
};
|
|
1183
|
-
// A loader
|
|
1184
|
-
const loaderPath = `${out}
|
|
1185
|
-
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
|
+
};
|
|
1186
1236
|
const notVerified = (fields: Record<string, unknown>) => ({ verified: false, ...fields, ...keptLoader() });
|
|
1187
1237
|
// The loader includes the source, so it is built only from a source that is identical to the image.
|
|
1188
1238
|
const notBuilt = (reason: string) => (state === undefined ? {} : { loader: notVerified({ reason: loaderRefused ?? reason }) });
|
|
@@ -1228,7 +1278,7 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1228
1278
|
const fileByte = (address: number) => copierBuild[2 + address - (loader.packed?.start ?? 0x0801)]!;
|
|
1229
1279
|
// A start screen of a captured stage: the show stage holds the packed program, as a cracktro holds the game.
|
|
1230
1280
|
const stageRow = knowledge.startScreen?.stage === undefined ? undefined : knowledge.startScreen;
|
|
1231
|
-
// 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.
|
|
1232
1282
|
let packed: PackedLoader | undefined;
|
|
1233
1283
|
if (loader.packed !== undefined) {
|
|
1234
1284
|
try {
|
|
@@ -1249,11 +1299,11 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1249
1299
|
}
|
|
1250
1300
|
const program = stage?.program ?? packed?.program ?? copierBuild;
|
|
1251
1301
|
// The check runs the new loader from a scratch file. Only a loader whose check ran goes to --out, so a check
|
|
1252
|
-
// 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.
|
|
1253
1303
|
ensureLocal(projectRoot());
|
|
1254
1304
|
const scratch = `${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/${LOADER_CHECK_DIRECTORY}`;
|
|
1255
1305
|
mkdirSync(resolveProjectPath(scratch), { recursive: true });
|
|
1256
|
-
const checkPath = `${scratch}
|
|
1306
|
+
const checkPath = `${scratch}/${loaderName}.prg`;
|
|
1257
1307
|
writeFileSync(resolveProjectPath(checkPath), program);
|
|
1258
1308
|
// The unpack runs before the copier, or before the show stage, which then starts the loader.
|
|
1259
1309
|
const unpackFrames = (cycles: number | undefined) => (cycles === undefined ? LOADER_FRAMES : RUN_LIMIT_FRAMES + Math.ceil(cycles / PAL_FRAME_CYCLES));
|
|
@@ -1270,15 +1320,21 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
1270
1320
|
ran = await runLoader(checkPath, program, loader, state, { jump, copierSource, fileByte, copierFrames, ...(startScreen === undefined ? {} : { startScreen }), ...stageRun }, expected);
|
|
1271
1321
|
} catch (error) {
|
|
1272
1322
|
if (!isRefusal(error)) throw error;
|
|
1273
|
-
const what =
|
|
1274
|
-
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 };
|
|
1275
1325
|
} finally {
|
|
1276
1326
|
rmSync(resolveProjectPath(scratch), { recursive: true, force: true });
|
|
1277
1327
|
}
|
|
1278
|
-
|
|
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" }));
|
|
1279
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" }));
|
|
1280
1335
|
output.loader = {
|
|
1281
1336
|
program: loaderPath,
|
|
1337
|
+
symbols: symbolsPath(loaderPath),
|
|
1282
1338
|
...(packed === undefined ? {} : { packed: { packedBytes: packed.packedBytes, unpackedBytes: packed.unpackedBytes } }),
|
|
1283
1339
|
...(stage === undefined
|
|
1284
1340
|
? {}
|
|
@@ -1607,7 +1663,7 @@ async function exportProject(call: Call): Promise<Record<string, unknown>> {
|
|
|
1607
1663
|
),
|
|
1608
1664
|
);
|
|
1609
1665
|
for (const file of exported.files) files.push(put(`src/${file.name}`, file.text));
|
|
1610
|
-
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)));
|
|
1611
1667
|
for (const test of tests) files.push(put(test.file, test.text));
|
|
1612
1668
|
ensureLocal(to);
|
|
1613
1669
|
const folder = basename(to);
|
|
@@ -1744,7 +1800,7 @@ await runScript({
|
|
|
1744
1800
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", help: "the folder for the source files, relative to the project folder", required: true },
|
|
1745
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" },
|
|
1746
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" },
|
|
1747
|
-
loader: { kind: "flag", help: "also write loader.asm and loader.prg
|
|
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" },
|
|
1748
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" },
|
|
1749
1805
|
"max-listed": OPTIONS["max-listed"],
|
|
1750
1806
|
},
|
|
@@ -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` |
|
|
@@ -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 },
|
|
@@ -61,6 +61,7 @@ Each step has one of these kinds:
|
|
|
61
61
|
- `{ "frames": 50 }` runs 1 to 30000 frames.
|
|
62
62
|
- `{ "runUntil": { "target": { "kind": "address", "address": "main_loop" }, "timeoutFrames": 300 } }` runs until the target. The target kinds are `address`, `memory` and `raster`. `timeoutFrames` is 1 to 30000. The default is 3000.
|
|
63
63
|
- `{ "capture": "level1" }` captures a part. Only `loads` takes this step. Give each capture step a different name of 1 to 64 letters, digits, dots, underscores or hyphens.
|
|
64
|
+
- `{ "save": "at-call" }` writes the machine state to `<out>/at-call.vsf`. Only `loads` takes this step. A run of the program can start from this snapshot file, for example at the call of a routine of a loading stage. Give each save step a different name.
|
|
64
65
|
|
|
65
66
|
An address in a step can be a name. The script refuses an unknown name before the program runs. The message gives the file and the step.
|
|
66
67
|
|
|
@@ -231,6 +232,7 @@ A segment is a block of RAM from `$0400` that the program changed after the capt
|
|
|
231
232
|
|
|
232
233
|
- `loaded`: true when a capture has a segment.
|
|
233
234
|
- `captures`: one item for each capture step, with `capture`, `out`, `files`, `removed`, `pc`, `segments`, `excluded`, `differsFromReset`, `smallChanges` and `drive`.
|
|
235
|
+
- `saved`: one item for each save step, with `save`, `file` and `pc`.
|
|
234
236
|
- `smallChanges`: the count of changed bytes in blocks that are smaller than `--min-block`.
|
|
235
237
|
- `keyWait: true`: the CPU was in the KERNAL wait for a key, at READY or at an INPUT statement.
|
|
236
238
|
- `drive`: the name of the drive file, with `--drive`.
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// The loads command of c64-unpacker: one capture for each part of a
|
|
2
|
-
// multi-load program. The steps file has action steps
|
|
3
|
-
// capture writes what the C64 side changed since the previous
|
|
4
|
-
// image with its entry state, and with --drive the drive RAM as
|
|
5
|
-
// knowledge space drive8.
|
|
2
|
+
// multi-load program. The steps file has action steps, capture steps and save
|
|
3
|
+
// steps; a capture writes what the C64 side changed since the previous
|
|
4
|
+
// capture as an image with its entry state, and with --drive the drive RAM as
|
|
5
|
+
// a PRG for knowledge space drive8. A save writes the machine state as a
|
|
6
|
+
// snapshot file, which a run can start from. No tool guesses where a load
|
|
7
|
+
// ends: the steps decide.
|
|
6
8
|
|
|
7
9
|
import { type AddressRange, COVERAGE, formatC64Address } from "#src/c64.ts";
|
|
8
10
|
import { Refusal } from "#src/errors.ts";
|
|
@@ -17,9 +19,9 @@ import { entryStateFile, json, machineState, readRam, readyState, removeStaleFil
|
|
|
17
19
|
import { FIRST_SEGMENT_ADDRESS } from "./stages.ts";
|
|
18
20
|
|
|
19
21
|
|
|
20
|
-
export type LoadStep = ActionStep | { capture: string };
|
|
22
|
+
export type LoadStep = ActionStep | { capture: string } | { save: string };
|
|
21
23
|
|
|
22
|
-
/** A capture name: letters, digits, dots, underscores or hyphens. */
|
|
24
|
+
/** A capture or save name: letters, digits, dots, underscores or hyphens. */
|
|
23
25
|
const NAME = /^[A-Za-z0-9._-]{1,64}$/;
|
|
24
26
|
/** The drive RAM of a 1541. */
|
|
25
27
|
const DRIVE_RAM = 0x0800;
|
|
@@ -28,7 +30,7 @@ const KERNAL_LOAD = 0xffd5;
|
|
|
28
30
|
/** The KERNAL loop that waits for a key at READY. or at an INPUT statement. */
|
|
29
31
|
const KERNAL_KEY_WAIT = { start: 0xe5cd, end: 0xe5d5 };
|
|
30
32
|
|
|
31
|
-
/** Reads and checks the steps file of loads: action steps with $ addresses, and capture steps with new names. */
|
|
33
|
+
/** Reads and checks the steps file of loads: action steps with $ addresses, and capture and save steps with new names. */
|
|
32
34
|
export function readLoadSteps(path: string): LoadStep[] {
|
|
33
35
|
let value: unknown;
|
|
34
36
|
try {
|
|
@@ -42,9 +44,17 @@ export function readLoadSteps(path: string): LoadStep[] {
|
|
|
42
44
|
};
|
|
43
45
|
if (!Array.isArray(value) || value.length === 0) return fail("the steps are a JSON list with at least one step");
|
|
44
46
|
const names = new Set<string>();
|
|
47
|
+
const saves = new Set<string>();
|
|
45
48
|
value.forEach((step: unknown, index) => {
|
|
46
49
|
const at = `step ${index + 1}`;
|
|
47
50
|
if (!isObject(step)) return fail(`${at} must be an object`);
|
|
51
|
+
if ("save" in step) {
|
|
52
|
+
if (Object.keys(step).length !== 1) fail(`${at}: a save step has only save`);
|
|
53
|
+
if (typeof step.save !== "string" || !NAME.test(step.save)) fail(`${at}: save needs a name of 1 to 64 letters, digits, dots, underscores or hyphens`);
|
|
54
|
+
if (saves.has(step.save as string)) fail(`${at}: the save name ${step.save as string} is used before`);
|
|
55
|
+
saves.add(step.save as string);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
48
58
|
if ("capture" in step) {
|
|
49
59
|
if (Object.keys(step).length !== 1) fail(`${at}: a capture step has only capture`);
|
|
50
60
|
if (typeof step.capture !== "string" || !NAME.test(step.capture)) fail(`${at}: capture needs a name of 1 to 64 letters, digits, dots, underscores or hyphens`);
|
|
@@ -54,14 +64,14 @@ export function readLoadSteps(path: string): LoadStep[] {
|
|
|
54
64
|
}
|
|
55
65
|
const kinds = Object.keys(step).filter((key) => (ACTION_STEP_KINDS as readonly string[]).includes(key));
|
|
56
66
|
if (kinds.length > 1) return fail(`${at} has ${kinds.length} step kinds: ${kinds.join(", ")}. Give each one its own step`);
|
|
57
|
-
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...VICE_STEP_KINDS, "capture"].join(", ")}`);
|
|
67
|
+
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...VICE_STEP_KINDS, "capture", "save"].join(", ")}`);
|
|
58
68
|
// The step with its defaults filled in, as the shared schema of the action steps gives it.
|
|
59
69
|
const checked = checkActionStep(kinds[0] as ActionStepKind, step, at, fail);
|
|
60
70
|
// Its names resolve now: an unknown name stops the call before the emulator starts.
|
|
61
71
|
checkStepNames([checked], knowledgeAt(), `--steps ${path}`, index + 1);
|
|
62
72
|
(value as unknown[])[index] = checked;
|
|
63
73
|
});
|
|
64
|
-
if (names.size === 0) fail("the steps have no capture step");
|
|
74
|
+
if (names.size === 0 && saves.size === 0) fail("the steps have no capture step and no save step");
|
|
65
75
|
return value as LoadStep[];
|
|
66
76
|
}
|
|
67
77
|
|
|
@@ -149,12 +159,23 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
const captures: Array<Record<string, unknown>> = [];
|
|
162
|
+
const saved: Array<Record<string, unknown>> = [];
|
|
152
163
|
for (const [index, step] of options.steps.entries()) {
|
|
164
|
+
if ("save" in step) {
|
|
165
|
+
// The machine state as a snapshot file: a run starts from it, for example at the call of a loading stage.
|
|
166
|
+
if ((await client.status()).state === "running") await client.execution({ action: "pause", space: "c64" });
|
|
167
|
+
await client.snapshot({ action: "save", name: "loads-save" });
|
|
168
|
+
const path = `${options.out}/${step.save}.vsf`;
|
|
169
|
+
const file = writeReported(path, await client.snapshotExport("loads-save"), { what: "--out" });
|
|
170
|
+
await client.snapshot({ action: "remove", name: "loads-save" });
|
|
171
|
+
saved.push({ save: step.save, file, pc: formatC64Address((await client.registersGet("c64")).pc) });
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
153
174
|
if (!("capture" in step)) {
|
|
154
175
|
const notReached = await runActionStep(client, step, knowledgeAt());
|
|
155
176
|
if (notReached !== undefined && "runUntil" in step) {
|
|
156
177
|
const reason = `Step ${index + 1} did not reach its target in ${step.runUntil.timeoutFrames} frames. It stopped by ${notReached.stopReason} at ${formatC64Address(notReached.pc)}.`;
|
|
157
|
-
return { output: { loaded: false, reason, captures }, failed: true };
|
|
178
|
+
return { output: { loaded: false, reason, captures, ...(saved.length === 0 ? {} : { saved }) }, failed: true };
|
|
158
179
|
}
|
|
159
180
|
continue;
|
|
160
181
|
}
|
|
@@ -226,9 +247,9 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
226
247
|
if (captures.length > 0 && captures.every((capture) => (capture.segments as unknown[]).length === 0)) {
|
|
227
248
|
const waits = captures.some((capture) => capture.keyWait === true) ? " The C64 waited for a key at READY. or at an INPUT statement, so the load ended or did not start." : "";
|
|
228
249
|
const reason = `No capture has a segment: the program changed no block of RAM from ${formatC64Address(FIRST_SEGMENT_ADDRESS)} on.${waits}`;
|
|
229
|
-
return { output: { loaded: false, reason, captures }, failed: true };
|
|
250
|
+
return { output: { loaded: false, reason, captures, ...(saved.length === 0 ? {} : { saved }) }, failed: true };
|
|
230
251
|
}
|
|
231
|
-
return { output: { loaded: true, captures }, failed: false };
|
|
252
|
+
return { output: { loaded: true, captures, ...(saved.length === 0 ? {} : { saved }) }, failed: false };
|
|
232
253
|
} finally {
|
|
233
254
|
await client.close();
|
|
234
255
|
}
|
|
@@ -642,7 +642,9 @@ function loaded(call: Call, { output, failed }: { output: Record<string, unknown
|
|
|
642
642
|
if (failed) return result;
|
|
643
643
|
const out = call.string("out")!;
|
|
644
644
|
const drive = call.flag("drive") ? ` Put the drive RAM ${out}/<name>/drive8.prg into the project knowledge in the space drive8.` : "";
|
|
645
|
-
|
|
645
|
+
const captures = (output.captures as unknown[]).length === 0 ? "" : `Put the capture ${out}/<name>/image.json of the part that you work on into the project knowledge.${drive}`;
|
|
646
|
+
const saved = output.saved === undefined ? "" : `A run of the program can start from a snapshot file ${out}/<name>.vsf.`;
|
|
647
|
+
return reply(result, { hint: [captures, saved].filter((text) => text !== "").join(" ") });
|
|
646
648
|
}
|
|
647
649
|
|
|
648
650
|
const COMMANDS: CommandSpec[] = [
|
|
@@ -702,10 +704,10 @@ const COMMANDS: CommandSpec[] = [
|
|
|
702
704
|
},
|
|
703
705
|
{
|
|
704
706
|
name: "loads",
|
|
705
|
-
summary: "Runs a multi-load program with the steps file. Each capture step {\"capture\": \"<name>\"} writes <dir>/<name>/ with image.bin, image.json, entry_state.json and a PRG for each block that the C64 side changed since the previous capture.",
|
|
707
|
+
summary: "Runs a multi-load program with the steps file. Each capture step {\"capture\": \"<name>\"} writes <dir>/<name>/ with image.bin, image.json, entry_state.json and a PRG for each block that the C64 side changed since the previous capture. Each save step {\"save\": \"<name>\"} writes the machine state to <dir>/<name>.vsf.",
|
|
706
708
|
subjects: [{ name: "<program>", help: "a PRG, or a disk, tape or cartridge image, relative to the project folder" }],
|
|
707
709
|
options: {
|
|
708
|
-
steps: { ...STEPS, required: true, help: "action steps and
|
|
710
|
+
steps: { ...STEPS, required: true, help: "action steps, capture steps and save steps (JSON)" },
|
|
709
711
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", required: true, help: "the folder for the captures, relative to the project folder" },
|
|
710
712
|
drive: { kind: "flag", help: "also write the 2 KiB drive RAM as drive8.prg, for knowledge space drive8" },
|
|
711
713
|
"min-block": { kind: "count", value: "<bytes>", min: 1, max: 0x10000, default: 64, help: "write a changed block of at least this many bytes (default 64)" },
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// The name of a build: the file name tells what kind of build a program is.
|
|
2
|
+
// A release build is release_<label>. A build of config.asm is clean when each
|
|
3
|
+
// switch has its default, else custom_ with each switch that differs: its
|
|
4
|
+
// name when it is on, no_<name> when it is off. A build of an entry other
|
|
5
|
+
// than main.asm adds the entry, for example clean_loader. A source without
|
|
6
|
+
// config.asm and without a release keeps the name of its entry. The symbols
|
|
7
|
+
// of a build go into symbols/ next to the program, so the program folder
|
|
8
|
+
// holds only programs.
|
|
9
|
+
|
|
10
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
11
|
+
|
|
12
|
+
/** The file with the value of each switch. The user edits it, and generate keeps the values. */
|
|
13
|
+
export const CONFIG_FILE = "config.asm";
|
|
14
|
+
|
|
15
|
+
/** A value line of config.asm: NAME = 0 or NAME = 1. */
|
|
16
|
+
const CONFIG_VALUE = /^\s*([A-Z][A-Z0-9_]*)\s*=\s*([01])\s*(?:;.*)?$/;
|
|
17
|
+
|
|
18
|
+
/** The values of the switches in a config.asm text, by name. Lines that are not a value line are not read. */
|
|
19
|
+
export function configValues(text: string): Map<string, 0 | 1> {
|
|
20
|
+
const values = new Map<string, 0 | 1>();
|
|
21
|
+
for (const line of text.split(/\r?\n/)) {
|
|
22
|
+
const match = CONFIG_VALUE.exec(line);
|
|
23
|
+
if (match !== null) values.set(match[1]!, match[2] === "1" ? 1 : 0);
|
|
24
|
+
}
|
|
25
|
+
return values;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** What a build is made of: a release, or the values of config.asm with the default of each switch (0 when the defaults do not have it). */
|
|
29
|
+
export type BuildKind = { release: string } | { values: ReadonlyMap<string, number>; defaults: ReadonlyMap<string, number> };
|
|
30
|
+
|
|
31
|
+
/** The name of a build of `entry`, without an extension. */
|
|
32
|
+
export function buildName(entry: string, kind: BuildKind | undefined): string {
|
|
33
|
+
const base = basename(entry, extname(entry));
|
|
34
|
+
if (kind === undefined) return base;
|
|
35
|
+
let type: string;
|
|
36
|
+
if ("release" in kind) type = `release_${kind.release}`;
|
|
37
|
+
else {
|
|
38
|
+
const changed = [...kind.values].filter(([name, value]) => value !== (kind.defaults.get(name) ?? 0)).map(([name, value]) => (value === 0 ? `no_${name}` : name).toLowerCase());
|
|
39
|
+
type = changed.length === 0 ? "clean" : `custom_${changed.join("_")}`;
|
|
40
|
+
}
|
|
41
|
+
return base === "main" ? type : `${type}_${base}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The symbols file of a program: symbols/<name>.json in the folder of the program. */
|
|
45
|
+
export function symbolsPath(program: string): string {
|
|
46
|
+
return join(dirname(program), "symbols", `${basename(program, extname(program))}.json`).split("\\").join("/");
|
|
47
|
+
}
|
package/src/host/vice/session.ts
CHANGED
|
@@ -1402,7 +1402,12 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
1402
1402
|
() => true,
|
|
1403
1403
|
() => false,
|
|
1404
1404
|
);
|
|
1405
|
-
if (!kept)
|
|
1405
|
+
if (!kept) {
|
|
1406
|
+
throw new WireFailure(
|
|
1407
|
+
"machine-state-lost",
|
|
1408
|
+
"The emulator did not restore this snapshot file, and the machine state from before the restore is lost. A snapshot file restores only in the emulator version and with the machine settings that saved it. Make the snapshot again in this emulator version, and load the program again.",
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1406
1411
|
if (error instanceof WireFailure) throw error;
|
|
1407
1412
|
throw new WireFailure(
|
|
1408
1413
|
"invalid-input",
|
package/src/native/acme.ts
CHANGED
|
@@ -19,7 +19,7 @@ export function showSymbol(symbol: AssembledSymbol) {
|
|
|
19
19
|
: { name: symbol.name, kind: "constant", value: `$${symbol.value.toString(16).padStart(4, "0")}`, used: symbol.used };
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/** The text of a symbols file (
|
|
22
|
+
/** The text of a symbols file (symbols/<build>.json next to the program): the symbols of a build, which c64-testing reads for the names of a program. */
|
|
23
23
|
export const symbolsFileText = (symbols: readonly AssembledSymbol[]) => `${JSON.stringify({ symbols: symbols.map(showSymbol) }, null, 1)}\n`;
|
|
24
24
|
|
|
25
25
|
const PROGRAM = "program.prg";
|