@henols/c64-re-tools 2.1.3 → 2.1.5
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/README.md +3 -3
- package/package.json +2 -1
- package/skills/c64-assembler/SKILL.md +1 -1
- package/skills/c64-assembler/scripts/assembler.ts +2 -2
- package/skills/c64-docs/SKILL.md +1 -1
- package/skills/c64-docs/scripts/docs.ts +5 -3
- package/skills/c64-emulator/SKILL.md +2 -0
- package/skills/c64-knowledge/SKILL.md +1 -0
- package/skills/c64-memory-map/SKILL.md +1 -1
- package/skills/c64-memory-map/scripts/memory-map.ts +4 -2
- package/skills/c64-provenance/SKILL.md +1 -1
- package/skills/c64-provenance/scripts/lib/compare.ts +12 -0
- package/skills/c64-provenance/scripts/lib/library.ts +7 -2
- package/skills/c64-provenance/scripts/provenance.ts +13 -7
- package/skills/c64-source/SKILL.md +2 -1
- package/skills/c64-source/scripts/source.ts +31 -15
- package/skills/c64-static-analysis/scripts/lib/findings.ts +24 -2
- package/skills/c64-testing/references/scenario-format.md +2 -0
- package/skills/c64-testing/scripts/lib/runs.ts +1 -1
- package/skills/c64-testing/scripts/lib/scenario.ts +4 -3
- package/skills/c64-testing/scripts/testing.ts +1 -1
- package/skills/c64-unpacker/SKILL.md +3 -2
- package/skills/c64-unpacker/scripts/lib/loads.ts +5 -2
- package/src/host/vice/session.ts +22 -2
- package/src/host-client/vice-session.ts +3 -3
- package/src/knowledge/write.ts +46 -1
- package/src/mcp/tools/media.ts +3 -4
- package/src/media.ts +3 -0
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +2 -2
- package/src/project.ts +6 -2
- package/src/script.ts +9 -1
- package/tools/c64run.c +655 -0
- package/tools/install-chips.sh +66 -0
- package/tools/install-container.sh +61 -0
- package/tools/install-dxa.sh +336 -0
- package/tools/install-ghidra.sh +40 -0
package/README.md
CHANGED
|
@@ -54,9 +54,9 @@ npx -y --package=@henols/c64-re-tools@latest c64-re-tools-host
|
|
|
54
54
|
|
|
55
55
|
### Dev container
|
|
56
56
|
|
|
57
|
-
This is the preferred way. The container gets Node.js 24, ACME, dxa, Java 21, Ghidra and c64run
|
|
58
|
-
installs the toolkit
|
|
59
|
-
|
|
57
|
+
This is the preferred way. The container gets Node.js 24, ACME, dxa, Java 21, Ghidra and c64run.
|
|
58
|
+
At each start it installs the newest toolkit of the channel into the project,
|
|
59
|
+
with the tools of that version, so the tools and the skills always match. Add to `.devcontainer/devcontainer.json`:
|
|
60
60
|
|
|
61
61
|
```json
|
|
62
62
|
"features": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@henols/c64-re-tools",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "Agent-friendly Commodore 64 engineering toolkit for reverse engineering, debugging, development and testing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Henrik Olsson",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"!src/**/*.test.ts",
|
|
24
24
|
"!src/**/*.testkit.ts",
|
|
25
25
|
"skills/",
|
|
26
|
+
"tools/",
|
|
26
27
|
"distribution/package.ts",
|
|
27
28
|
"distribution/plugin.ts",
|
|
28
29
|
"LICENSE",
|
|
@@ -35,7 +35,7 @@ node <skill>/scripts/assembler.ts build src main.a --out build/game.prg
|
|
|
35
35
|
| `--plain` | Write only the bytes of the program, without the 2-byte load address of a PRG. `loadRange` still tells where the bytes go. |
|
|
36
36
|
| `--all-symbols` | List all symbols. Without it, the list does not include the constants that the source does not use. `unusedConstants` gives their count. |
|
|
37
37
|
| `--max-listed 200` | Show at most 200 symbols in the result. The default is 50. `symbols.count` gives the count of all symbols. |
|
|
38
|
-
| `--out-symbols build/game.json` | Write
|
|
38
|
+
| `--out-symbols build/game.json` | Write the symbols to this file as `{"symbols": [...]}`. Without `--all-symbols`, the file does not have the constants that the source does not use. Give this file to the c64-testing skill as the symbols of the rebuild. |
|
|
39
39
|
|
|
40
40
|
The script copies the full source root. Put all files that the program includes under it. Version control directories stay out.
|
|
41
41
|
|
|
@@ -54,7 +54,7 @@ await runScript({
|
|
|
54
54
|
plain: { kind: "flag", help: "write the bytes only, without the 2-byte load address of a PRG" },
|
|
55
55
|
"all-symbols": { kind: "flag", help: "list also the constants that the source does not use" },
|
|
56
56
|
"max-listed": { ...OPTIONS["max-listed"], help: "list at most n symbols (default 50). The count is always given" },
|
|
57
|
-
"out-symbols": { kind: "path", output: "file", value: "<file.json>", help: "write
|
|
57
|
+
"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 c64-testing. Without --all-symbols, the file does not have the constants that the source does not use" },
|
|
58
58
|
},
|
|
59
59
|
notes: "Symbol values are $ and at least four hex digits. Put the program into the knowledge with knowledge.ts image of the c64-knowledge skill before --compare.",
|
|
60
60
|
run: async (call) => {
|
|
@@ -101,7 +101,7 @@ await runScript({
|
|
|
101
101
|
...written,
|
|
102
102
|
...(plain ? { plain: true } : {}),
|
|
103
103
|
loadRange: { start: formatC64Address(range.start), end: formatC64Address(range.end), bytes: range.bytes },
|
|
104
|
-
symbols: listedItems(shown, call.count("max-listed")!, showSymbol, "a larger --max-listed, or --out-symbols <file.json> for
|
|
104
|
+
symbols: listedItems(shown, call.count("max-listed")!, showSymbol, "a larger --max-listed, or --out-symbols <file.json> for the whole list"),
|
|
105
105
|
...(symbolsPath === undefined ? {} : { symbolsFile: writeReported(symbolsPath, `${JSON.stringify({ symbols: shown.map(showSymbol) }, null, 1)}\n`, { what: "--out-symbols" }) }),
|
|
106
106
|
...(all ? {} : { unusedConstants: result.symbols!.length - shown.length }),
|
|
107
107
|
diagnostics: result.diagnostics,
|
package/skills/c64-docs/SKILL.md
CHANGED
|
@@ -38,7 +38,7 @@ node <skill>/scripts/docs.ts link README.md docs --source src --check
|
|
|
38
38
|
| `--source src` | `docs.ts link`: the source directory of c64-source. The command reads `src/source-map.json`. |
|
|
39
39
|
| `--out docs/reference` | The directory of the reference. `docs.ts generate` writes only there. It refuses to start when the directory holds a page that it did not write. |
|
|
40
40
|
| `README.md docs` | The pages of the documentation: `.md` files and directories. `docs.ts link` reads each file and every `.md` file below each directory. It changes only the pages that you wrote. It checks the pages of the reference. |
|
|
41
|
-
| `--reference <dir>` | The directory of the reference for `docs.ts link`. The default is the `reference` directory
|
|
41
|
+
| `--reference <dir>` | The directory of the reference for `docs.ts link`. The default is the first `reference` directory in a given directory or beside a given page, for example `docs/reference`. |
|
|
42
42
|
| `--check` | `docs.ts link` writes nothing. `result` is `FAIL` when a link is not up to date or a page has a problem. |
|
|
43
43
|
| `--max-listed 20` | List at most this number of items in each list. The default is 50. |
|
|
44
44
|
|
|
@@ -169,7 +169,9 @@ function link(call: Call): Record<string, unknown> {
|
|
|
169
169
|
const directories = given.filter((path) => !path.endsWith(".md") || isDirectory(path));
|
|
170
170
|
const map = readSourceMap(call.string("source")!);
|
|
171
171
|
const givenReference = call.string("reference");
|
|
172
|
-
|
|
172
|
+
// The default reference: the reference/ folder in a given folder, or beside a given page.
|
|
173
|
+
const besides = given.map((path) => (directories.includes(path) ? path : posix.dirname(path)));
|
|
174
|
+
const reference = givenReference === undefined ? besides.map((path) => posix.join(path, "reference")).find((path) => isDirectory(path)) : posix.normalize(givenReference);
|
|
173
175
|
const problems: Problem[] = [];
|
|
174
176
|
const db = openForRead();
|
|
175
177
|
let symbols;
|
|
@@ -279,7 +281,7 @@ function link(call: Call): Record<string, unknown> {
|
|
|
279
281
|
for (const problem of problems) byKind[problem.kind] = (byKind[problem.kind] ?? 0) + 1;
|
|
280
282
|
const output: Record<string, unknown> = {
|
|
281
283
|
pages: pages.length,
|
|
282
|
-
...(reference === undefined ? { reference: "none: run docs.ts generate for links to the entries" } : { reference }),
|
|
284
|
+
...(reference === undefined ? { reference: "none: no reference/ folder is in or beside the given pages. Give --reference <dir>, or run docs.ts generate for links to the entries" } : { reference }),
|
|
283
285
|
...(check ? { notUpToDate: { links, pages: changedPages } } : { linked: { links, pages: changedPages } }),
|
|
284
286
|
problems: { byKind, ...listed(problems, call.count("max-listed")!, (problem) => ({ at: `${problem.page}:${problem.line}`, kind: problem.kind, message: problem.message })) },
|
|
285
287
|
};
|
|
@@ -312,7 +314,7 @@ await runScript({
|
|
|
312
314
|
subjects: [{ name: "<page>", help: ".md files and folders of the documentation, relative to the project folder, for example README.md docs. link reads each file and every .md file below each folder", list: true }],
|
|
313
315
|
options: {
|
|
314
316
|
source: { ...SOURCE, required: true },
|
|
315
|
-
reference: { kind: "path", value: "<dir>", help: "the reference pages of docs.ts generate. The default is the reference/ folder
|
|
317
|
+
reference: { kind: "path", value: "<dir>", help: "the reference pages of docs.ts generate. The default is the first reference/ folder in a given folder or beside a given page" },
|
|
316
318
|
check: { kind: "flag", help: "write nothing. FAIL when a link is not up to date or a page has a problem" },
|
|
317
319
|
"max-listed": OPTIONS["max-listed"],
|
|
318
320
|
},
|
|
@@ -81,6 +81,8 @@ Write operations need a stopped CPU. Stop the CPU with `c64_execution` action `p
|
|
|
81
81
|
|
|
82
82
|
A cartridge from `c64_autostart` stays in the C64 through every reset, as on a real C64. `c64_status` gives `cartridge: true` while the C64 has it, and `cartridge: false` when it does not. `c64_autostart` of a file that is not a cartridge removes the cartridge first. `c64_autostart` also sets both joysticks to the center first. `joysticksCentred` gives the ports that it changed.
|
|
83
83
|
|
|
84
|
+
`c64_autostart` returns while the load continues. The emulator turns warp on until it types RUN. A key in that time stops the autostart, so `c64_keyboard` refuses it. Run frames with `advance-frames` until `c64_status` gives `warp: false`. Then type.
|
|
85
|
+
|
|
84
86
|
Step, next and until-return work only in space `c64`. The emulator cannot stop the disk drive CPU after one instruction. To find when the drive executes an address, use `c64_run_until` with an address target in space `drive8`, or a breakpoint in space `drive8`. The drive can execute a few more instructions before it stops. The computer completes its current instruction. The `pc` in the result is the drive address where it stopped. `space` in the result is `drive8`. A breakpoint or a watchpoint in space `drive8` that stops `advance-frames` gives the same `pc` and `space`. `c64_status` also gives them. A memory target or a memory condition tests only space `c64`.
|
|
85
87
|
|
|
86
88
|
`c64_keyboard` puts keys in the keyboard queue of the KERNAL. A program that reads the keyboard matrix directly does not see them. Many games do this. No MCP tool presses a key of the keyboard matrix. For such a program:
|
|
@@ -237,6 +237,7 @@ A patch is ACME code that replaces a range of the program when the build defines
|
|
|
237
237
|
- A switch name is upper case, for example `CRACK` or `TRAINER`. It cannot be the name of a symbol or a platform name.
|
|
238
238
|
- Many patches can have the same switch. The c64-source skill builds each switch on its own. It does not build two switches together.
|
|
239
239
|
- The code must fit in the range. NOP ($EA) fills the bytes after the code. `--nop` gives a range of NOP only.
|
|
240
|
+
- `patch` refuses code that is longer than the range when each line is a 6510 instruction, `!byte`, `!word`, `!fill` or a comment. `patch` does not check the length of other code, for example code with a label or a macro. It does not assemble the code. `generate` of the c64-source skill builds each switch and does these checks. `switches[].result` is `overflow` for code that is longer than its range, and `does not assemble` for code that ACME refuses.
|
|
240
241
|
- `--code` gives the code as text. `--code-file` reads the code from a project file. The code can use the labels and the macros of the source, and local labels with a dot, for example `.skip`.
|
|
241
242
|
- The braces in the code must be pairs, because the source puts the code inside `{ }`.
|
|
242
243
|
- A patch cannot overlap another patch or a macro use. A patch with the same start and the same switch replaces the patch. A patch of another switch at the same start gives the error `conflict`.
|
|
@@ -30,7 +30,7 @@ node <skill>/scripts/memory-map.ts export --out src/hw.asm
|
|
|
30
30
|
| Command | Result |
|
|
31
31
|
|---|---|
|
|
32
32
|
| `at <address> ...` | For each address: `kind` (`platform` or `application`), the area, the name and the meaning. |
|
|
33
|
-
| `decode <register> <value>` | The meaning of the value. Use `--bank` with the value of `$DD00` to get the addresses for `$D018`. The decoders are for `$01`, `$D010`, `$D011`, `$D015` to `$D01F`, `$D016`, `$D018`, `$DC0D`, `$DD00` and `$DD0D`. |
|
|
33
|
+
| `decode <register> <value>` | The meaning of the value. Use `--bank` with the value of `$DD00` to get the addresses for `$D018`. The other registers refuse `--bank`. The decoders are for `$01`, `$D010`, `$D011`, `$D015` to `$D01F`, `$D016`, `$D018`, `$DC0D`, `$DD00` and `$DD0D`. |
|
|
34
34
|
| `list <vic\|sid\|cia1\|cia2\|kernal\|system>` | The entries of that group as a list: `count` and `listed`. `--max-listed` limits `listed`. The default is 50. |
|
|
35
35
|
| `export --out <file>` | Writes all platform names to a project file as an ACME include: one line for each name, with its meaning as a comment. A zero-page name is `NAME = $xx`. Other names are `NAME = $xxxx`. |
|
|
36
36
|
|
|
@@ -69,11 +69,13 @@ await runScript({
|
|
|
69
69
|
{ name: "<register>", help: "the register, as an address or a platform name: $0001, $d011 (SCROLY), $d016, $d018, $d010, $d015-$d01f, $dc0d, $dd00 or $dd0d" },
|
|
70
70
|
{ name: "<value>", help: "the value of the register: $ and hex, decimal, or % and binary, 0 to 255" },
|
|
71
71
|
],
|
|
72
|
-
options: { bank: { kind: "number", value: "<value>", help: "the value of $dd00, for the VIC-II bank of a $d018 value", max: 0xff } },
|
|
72
|
+
options: { bank: { kind: "number", value: "<value>", help: "the value of $dd00, for the VIC-II bank of a $d018 value. Only for $d018", max: 0xff } },
|
|
73
73
|
run: (call) => {
|
|
74
74
|
const register = call.parseAddress(call.subject(0), "<register>");
|
|
75
75
|
const value = call.parseNumber(call.subject(1), "<value>", 0, 0xff);
|
|
76
|
-
|
|
76
|
+
const bank = call.count("bank");
|
|
77
|
+
if (bank !== undefined && register !== 0xd018) throw new UsageError(`--bank works only with $d018 (VMCSB), not with ${formatC64Address(register)}. Remove --bank`);
|
|
78
|
+
return { register: formatC64Address(register), value: formatC64Byte(value), name: lookup(register).name, ...decode(register, value, bank) };
|
|
77
79
|
},
|
|
78
80
|
},
|
|
79
81
|
{
|
|
@@ -193,7 +193,7 @@ Record a confirmed conclusion as a normal comment, region or symbol with the c64
|
|
|
193
193
|
|
|
194
194
|
## Result
|
|
195
195
|
|
|
196
|
-
The differing ranges with the bytes of each release and the groups that agree, and the share of identical bytes. `common` gives the ranges where all releases have bytes. `releases` gives the segments and the `shift` of each release. With `--frames`, each difference also has `runtime`, and `run` tells if each release started, or why not.
|
|
196
|
+
The differing ranges with the bytes of each release and the groups that agree, and the share of identical bytes. `identicalShare` has 3 decimals. It is 1 only when no byte differs. `identicalBytes` and `differingBytes` give the counts. `common` gives the ranges where all releases have bytes. `releases` gives the segments and the `shift` of each release. With `--frames`, each difference also has `runtime`, and `run` tells if each release started, or why not.
|
|
197
197
|
|
|
198
198
|
For `leftovers`: the lists of findings, with `entry`, `roots` and the number of `stages`. `noStages` and `noCoverage` tell which knowledge is missing. Without a root, `roots` tells why `deadCode` is empty.
|
|
199
199
|
|
|
@@ -39,6 +39,18 @@ const JOIN_GAP = 4;
|
|
|
39
39
|
|
|
40
40
|
export const covers = (release: Release, address: number) => release.segments.some((segment) => address >= segment.start && address <= segment.end);
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The share of identical bytes with 3 decimals. It is 1 only when no byte
|
|
44
|
+
* differs, and 0 only when no byte is identical: a rounded share must not hide
|
|
45
|
+
* one differing or one identical byte.
|
|
46
|
+
*/
|
|
47
|
+
export function identicalShare(identical: number, differing: number): number {
|
|
48
|
+
const compared = identical + differing;
|
|
49
|
+
if (compared === 0 || identical === 0) return 0;
|
|
50
|
+
if (differing === 0) return 1;
|
|
51
|
+
return Math.min(0.999, Math.max(0.001, Number((identical / compared).toFixed(3))));
|
|
52
|
+
}
|
|
53
|
+
|
|
42
54
|
/** The ranges where every release has bytes, inside from..to. */
|
|
43
55
|
export function commonRanges(releases: Release[], from = 0x0000, to = 0xffff): AddressRange[] {
|
|
44
56
|
const ranges: AddressRange[] = [];
|
|
@@ -14,7 +14,7 @@ import { formatC64Address, instructionLength } from "#src/c64.ts";
|
|
|
14
14
|
import { evaluate, identifiers, operandText } from "#src/knowledge/expression.ts";
|
|
15
15
|
import type { CommentRow, OperandRow, ReferenceRow, RegionRow, SymbolRow } from "#src/knowledge/read.ts";
|
|
16
16
|
import { COMMENT_PLACEMENTS, type CommentPlacement, isSemantic, OPERAND_SELECTS, type OperandSelect, REFERENCE_KINDS, type ReferenceKind, REGION_TYPES, type RegionType, SYMBOL_KINDS, type SymbolKind } from "#src/knowledge/schema.ts";
|
|
17
|
-
import { checkOutputPath, isInside, PROJECT_DIRECTORY } from "#src/project.ts";
|
|
17
|
+
import { checkOutputPath, isInside, knowledgePart, PROJECT_DIRECTORY } from "#src/project.ts";
|
|
18
18
|
|
|
19
19
|
/** A routine shorter than this is not saved and not searched: its bytes occur by chance. */
|
|
20
20
|
export const MIN_ROUTINE = 16;
|
|
@@ -305,7 +305,12 @@ function checkLibraryOutput(path: string, root: string): void {
|
|
|
305
305
|
for (const [base, target] of [[root, path], [realRoot, real]] as const) {
|
|
306
306
|
if (isInside(base, target)) {
|
|
307
307
|
// A project path shows with "/" on every system, as the messages give it.
|
|
308
|
-
|
|
308
|
+
const shown = relative(base, target).split(sep).join("/") || ".";
|
|
309
|
+
const part = knowledgePart(shown);
|
|
310
|
+
if (part !== undefined) {
|
|
311
|
+
throw new Refusal("invalid-input", `--library: ${shown} is in ${part}, the knowledge of the project. Only the c64-knowledge skill writes it: a write there destroys the knowledge. Give a library folder beside the projects, for example ../library.`);
|
|
312
|
+
}
|
|
313
|
+
checkOutputPath(shown, "folder", { root: base, what: "--library" });
|
|
309
314
|
return;
|
|
310
315
|
}
|
|
311
316
|
}
|
|
@@ -43,7 +43,7 @@ import { platformNames } from "#src/platform.ts";
|
|
|
43
43
|
import { projectRoot } from "#src/project.ts";
|
|
44
44
|
import { knowledgeAt, knowledgeNames } from "#src/knowledge/names.ts";
|
|
45
45
|
import { listed, OPTIONS, runScript, UsageError, type Call, type CommandSpec } from "#src/script.ts";
|
|
46
|
-
import { compareReleases, shiftSuggestion, suggestShifts, type Release } from "./lib/compare.ts";
|
|
46
|
+
import { compareReleases, identicalShare, shiftSuggestion, suggestShifts, type Release } from "./lib/compare.ts";
|
|
47
47
|
import { findRoutine, libraryFolder, readLibrary, routineFrom, saveRoutine, suggest } from "./lib/library.ts";
|
|
48
48
|
import { watchRelease, type Start } from "./lib/runtime.ts";
|
|
49
49
|
import { findLeftovers } from "./lib/leftovers.ts";
|
|
@@ -107,7 +107,7 @@ async function compare(call: Call): Promise<unknown> {
|
|
|
107
107
|
const shifts = new Map<number, number>();
|
|
108
108
|
for (const text of call.strings("shift")) {
|
|
109
109
|
const match = /^(\d+):([+-]?\d+)$/.exec(text);
|
|
110
|
-
if (match === null) throw new UsageError(`--shift must be <release
|
|
110
|
+
if (match === null) throw new UsageError(`--shift must be <release>:<bytes>, for example 2:-256, not ${text}`);
|
|
111
111
|
if (Number(match[1]) < 1 || Number(match[1]) > positionals.length) {
|
|
112
112
|
throw new UsageError(`--shift ${text}: there is no release ${match[1]}. This compare has ${positionals.length} releases: give a release number from 1 to ${positionals.length}`);
|
|
113
113
|
}
|
|
@@ -122,13 +122,12 @@ async function compare(call: Call): Promise<unknown> {
|
|
|
122
122
|
const releases = loaded.map((item) => item.release);
|
|
123
123
|
const range = call.range("range");
|
|
124
124
|
const comparison = compareReleases(releases, range === undefined ? {} : { from: range.start, to: range.end });
|
|
125
|
-
const
|
|
126
|
-
const identicalShare = compared === 0 ? 0 : comparison.identicalBytes / compared;
|
|
125
|
+
const share = identicalShare(comparison.identicalBytes, comparison.differingBytes);
|
|
127
126
|
// A poor match at the load addresses can mean that the releases are placed differently.
|
|
128
127
|
// Each release gets its best shifts: data that stayed can outvote code that moved, so one is not enough.
|
|
129
128
|
const applied = loaded.map((item) => item.shift);
|
|
130
129
|
const suggestions =
|
|
131
|
-
|
|
130
|
+
share < 0.5
|
|
132
131
|
? releases.slice(1).flatMap((release, index) =>
|
|
133
132
|
suggestShifts(releases[0]!, release).map((found) => {
|
|
134
133
|
const suggestion = shiftSuggestion(releases, applied, index + 1, found);
|
|
@@ -170,7 +169,7 @@ async function compare(call: Call): Promise<unknown> {
|
|
|
170
169
|
common: comparison.common.map((range) => ({ start: formatC64Address(range.start), end: formatC64Address(range.end) })),
|
|
171
170
|
identicalBytes: comparison.identicalBytes,
|
|
172
171
|
differingBytes: comparison.differingBytes,
|
|
173
|
-
identicalShare:
|
|
172
|
+
identicalShare: share,
|
|
174
173
|
differences: comparison.differences.map((difference, index) => ({
|
|
175
174
|
start: formatC64Address(difference.start),
|
|
176
175
|
end: formatC64Address(difference.end),
|
|
@@ -464,7 +463,14 @@ const COMMANDS: CommandSpec[] = [
|
|
|
464
463
|
summary: "Compares releases byte by byte, in their common ranges, and suggests shifts when they are placed differently.",
|
|
465
464
|
subjects: [{ name: "<release>", help: "knowledge (the program in the knowledge), a PRG at its load address, or an image.json of the c64-unpacker skill with the entry_state.json beside it. Two or more", list: true }],
|
|
466
465
|
options: {
|
|
467
|
-
shift: {
|
|
466
|
+
shift: {
|
|
467
|
+
kind: "text",
|
|
468
|
+
value: "<release>:<bytes>",
|
|
469
|
+
multiple: true,
|
|
470
|
+
help: "move a release (1 is the first) by a number of bytes, for example 2:-256",
|
|
471
|
+
// A bare number is the bytes: the example puts it after a release.
|
|
472
|
+
example: (given) => `2:${given !== undefined && /^-\d+$/.test(given) ? given : "-256"}`,
|
|
473
|
+
},
|
|
468
474
|
range: { ...OPTIONS.range, help: "compare only the addresses from start to end" },
|
|
469
475
|
frames: { ...OPTIONS.frames, max: MAX_EXECUTION_COUNT, help: "run each release in its own emulator for n frames, and give each listed difference its first access and whether it changed" },
|
|
470
476
|
steps: { ...OPTIONS.steps, help: "with --frames: action steps (JSON) to run before the frames" },
|
|
@@ -31,7 +31,7 @@ node <skill>/scripts/source.ts generate --out src --loader
|
|
|
31
31
|
|
|
32
32
|
| Option | Meaning |
|
|
33
33
|
|---|---|
|
|
34
|
-
| `--out src` | The directory for the source files. The script writes over the files that it generated before. |
|
|
34
|
+
| `--out src` | The directory for the source files. The script writes over the files that it generated before. It removes a generated `.asm` file that this run does not write. A run without `--loader` keeps `loader.asm` and `loader.prg` of an earlier run. |
|
|
35
35
|
| `--entry '$080d'` | An entry point for Ghidra. Use it again for more entry points. The entry of the program, the routines and the code regions in the knowledge are entry points too. |
|
|
36
36
|
| `--analyzer-names` | Name an address that has no symbol and no platform name with its analyzer name, for example `FUN_17e2`. The order is heuristic, Ghidra, then DXA. Without it, the source makes its own names, for example `l_17e2`. |
|
|
37
37
|
| `--space drive8` | Generate the source of drive code or a cartridge bank from the knowledge of that space. The coverage, `--loader` and the platform names are only for `c64`. |
|
|
@@ -143,6 +143,7 @@ Do not store:
|
|
|
143
143
|
|
|
144
144
|
- `result`: `PASS` when every check passes, else `FAIL`.
|
|
145
145
|
- `files`: the files that the script wrote in `--out`, each with `out`, `bytes` and `sha256`. `sourceMap` names `source-map.json`.
|
|
146
|
+
- `removed`: the files of an earlier run that the script removed from `--out` and did not write again.
|
|
146
147
|
- `instructions`, `dataBytes` and `undecodedBytes`.
|
|
147
148
|
- `labels`: `named` labels from the knowledge and `generated` labels `l_xxxx`.
|
|
148
149
|
- `entriesInData`: each `--entry` in a data region of the knowledge, with the `region` and its `origin`. Ghidra does not decode an entry in a data region.
|
|
@@ -504,7 +504,6 @@ const NOT_EXECUTED_FILE = "not_executed.json";
|
|
|
504
504
|
/** The line of each name and address in the source, for links from the documentation. */
|
|
505
505
|
const SOURCE_MAP_FILE = "source-map.json";
|
|
506
506
|
|
|
507
|
-
/** Removes the .asm files of an earlier run that this run does not write, and an earlier loader.prg and not_executed.json; other files stay. */
|
|
508
507
|
/**
|
|
509
508
|
* source-map.json: the line of each name and of each address that the
|
|
510
509
|
* files write, after the mark line. One entry per line of the file, so a diff
|
|
@@ -517,19 +516,33 @@ function sourceMapText(rendered: Rendered, space: string, revision: string | nul
|
|
|
517
516
|
return `${head},\n"labels": [\n${labels.join(",\n")}\n],\n"items": [\n${items.join(",\n")}\n]}\n`;
|
|
518
517
|
}
|
|
519
518
|
|
|
520
|
-
|
|
519
|
+
/** The files of the loader. Only a run with --loader writes them, so only such a run removes them. */
|
|
520
|
+
const LOADER_FILES: ReadonlySet<string> = new Set(["loader.asm", "loader.prg"]);
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Removes the generated .asm files of an earlier run that this run does not
|
|
524
|
+
* write, and an earlier not_executed.json and source-map.json. An earlier
|
|
525
|
+
* loader.asm and loader.prg stay unless this run has --loader: a source of the
|
|
526
|
+
* user can include loader.asm. Other files stay. Gives the names it removed.
|
|
527
|
+
*/
|
|
528
|
+
function removeOldFiles(out: string, keep: ReadonlySet<string>, loaderRun: boolean): string[] {
|
|
521
529
|
const directory = resolveProjectPath(out);
|
|
522
|
-
if (!existsSync(directory)) return;
|
|
530
|
+
if (!existsSync(directory)) return [];
|
|
531
|
+
const removed: string[] = [];
|
|
523
532
|
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
524
533
|
if (!entry.isFile()) continue;
|
|
525
534
|
const name = entry.name;
|
|
526
535
|
const path = join(directory, name);
|
|
527
|
-
if (
|
|
528
|
-
|
|
536
|
+
if (LOADER_FILES.has(name) && !loaderRun) continue;
|
|
537
|
+
const old = name === "loader.prg" || name === NOT_EXECUTED_FILE || name === SOURCE_MAP_FILE || (name.endsWith(".asm") && !keep.has(name) && readFileSync(path, "utf8").startsWith(GENERATED_MARK));
|
|
538
|
+
if (!old) continue;
|
|
539
|
+
rmSync(path, { force: true });
|
|
540
|
+
removed.push(name);
|
|
529
541
|
}
|
|
542
|
+
return removed;
|
|
530
543
|
}
|
|
531
544
|
|
|
532
|
-
async function generate(call: Call): Promise<{ output: Record<string, unknown>; failed: boolean }> {
|
|
545
|
+
async function generate(call: Call): Promise<{ output: Record<string, unknown>; failed: boolean; removed: string[] }> {
|
|
533
546
|
const out = call.string("out")!;
|
|
534
547
|
const entries = call.addresses("entry");
|
|
535
548
|
const max = call.count("max-listed")!;
|
|
@@ -603,7 +616,7 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
603
616
|
files = marked([...rendered.files, ...loaderFiles]);
|
|
604
617
|
built = await assembleFiles(files, "main.asm");
|
|
605
618
|
}
|
|
606
|
-
removeOldFiles(out, new Set(files.map((file) => file.name)));
|
|
619
|
+
const removed = removeOldFiles(out, new Set(files.map((file) => file.name)), loaderWanted).map((name) => `${out}/${name}`);
|
|
607
620
|
const written: Written[] = files.map((file) => writeReported(`${out}/${file.name}`, file.text, { what: "--out" }));
|
|
608
621
|
written.push(writeReported(`${out}/${SOURCE_MAP_FILE}`, sourceMapText(rendered, space, knowledge.revision, files), { what: "--out" }));
|
|
609
622
|
const showRange = (range: AddressRange) => ({ start: formatC64Address(range.start), end: formatC64Address(range.end) });
|
|
@@ -671,21 +684,21 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
671
684
|
// The loader includes the source, so it is built only from a source that is identical to the image.
|
|
672
685
|
const notBuilt = (reason: string) => (state === undefined ? {} : { loader: { verified: false, reason: loaderRefused ?? reason } });
|
|
673
686
|
if (built.program === undefined) {
|
|
674
|
-
return { output: { ...output, check: { identical: false, diagnostics: built.diagnostics.slice(0, MAX_DIAGNOSTICS) }, ...notBuilt("The source does not assemble, and the loader includes it.") }, failed: true };
|
|
687
|
+
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 };
|
|
675
688
|
}
|
|
676
689
|
const checked = check(built.program, built.start!, image);
|
|
677
690
|
output.check = checked;
|
|
678
|
-
if (!checked.identical) return { output: { ...output, ...notBuilt("The source does not assemble to the image, and the loader includes it.") }, failed: true };
|
|
691
|
+
if (!checked.identical) return { output: { ...output, ...notBuilt("The source does not assemble to the image, and the loader includes it.") }, removed, failed: true };
|
|
679
692
|
// Each switch on alone, against the default build; combinations are not built.
|
|
680
693
|
const switches: SwitchCheck[] = [];
|
|
681
694
|
for (const [name, patches] of switchesOf(laid)) switches.push(await checkSwitch(name, patches, files, { program: built.program, start: built.start! }, laid.names));
|
|
682
695
|
if (switches.length > 0) output.switches = switches;
|
|
683
696
|
const sourceFailed = laid.patchesNotWritten.length > 0 || switches.some((item) => item.result !== "fits");
|
|
684
|
-
if (loaderRefused !== undefined) return { output: { ...output, loader: { verified: false, reason: loaderRefused } }, failed: true };
|
|
685
|
-
if (loader === undefined || state === undefined) return { output, failed: missingEntry !== undefined || sourceFailed };
|
|
697
|
+
if (loaderRefused !== undefined) return { output: { ...output, loader: { verified: false, reason: loaderRefused } }, removed, failed: true };
|
|
698
|
+
if (loader === undefined || state === undefined) return { output, removed, failed: missingEntry !== undefined || sourceFailed };
|
|
686
699
|
|
|
687
700
|
const loaderBuilt = await assembleFiles(files, "loader.asm");
|
|
688
|
-
if (loaderBuilt.program === undefined) return { output: { ...output, loader: { verified: false, reason: "loader.asm does not assemble.", diagnostics: loaderBuilt.diagnostics.slice(0, MAX_DIAGNOSTICS) } }, failed: true };
|
|
701
|
+
if (loaderBuilt.program === undefined) return { output: { ...output, loader: { verified: false, reason: "loader.asm does not assemble.", diagnostics: loaderBuilt.diagnostics.slice(0, MAX_DIAGNOSTICS) } }, removed, failed: true };
|
|
689
702
|
const program = loaderBuilt.program;
|
|
690
703
|
// The simulation: the loader in memory as it loads, then every copy in its order, byte by byte.
|
|
691
704
|
const memory = new Int16Array(0x10000).fill(-1);
|
|
@@ -718,7 +731,7 @@ async function generate(call: Call): Promise<{ output: Record<string, unknown>;
|
|
|
718
731
|
// What the loader cannot set as it was at the entry.
|
|
719
732
|
...(loaderLimits(loader).length === 0 ? {} : { limits: loaderLimits(loader) }),
|
|
720
733
|
};
|
|
721
|
-
return { output, failed: !ran.verified || sourceFailed };
|
|
734
|
+
return { output, removed, failed: !ran.verified || sourceFailed };
|
|
722
735
|
}
|
|
723
736
|
|
|
724
737
|
await runScript({
|
|
@@ -739,8 +752,11 @@ await runScript({
|
|
|
739
752
|
},
|
|
740
753
|
notes: "The program, its entry state and the coverage come from the knowledge: put them in with knowledge.ts image and coverage of the c64-knowledge skill. Code that no imported run executed is marked and listed, and <dir>/not_executed.json has all of its ranges. Without --analyzer-names, an address without a name gets a name of the source, for example l_17e2.",
|
|
741
754
|
run: async (call) => {
|
|
742
|
-
const { output, failed } = await generate(call);
|
|
743
|
-
|
|
755
|
+
const { output, failed, removed } = await generate(call);
|
|
756
|
+
// A file of an earlier run that this run removed and did not write again.
|
|
757
|
+
const written = new Set((output.files as Written[]).map((file) => file.out));
|
|
758
|
+
const gone = removed.filter((path) => !written.has(path));
|
|
759
|
+
return { result: failed ? "FAIL" : "PASS", ...output, ...(gone.length === 0 ? {} : { removed: gone }) };
|
|
744
760
|
},
|
|
745
761
|
},
|
|
746
762
|
],
|
|
@@ -48,7 +48,28 @@ export function seedsFromKnowledge(db: DatabaseSync | undefined, extraEntryPoint
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* The 6510 opcodes with a low nibble of 1 or 3 use (zp,x) or (zp),y, also the
|
|
52
|
+
* undocumented ones. Ghidra gives such an instruction a reference to the target
|
|
53
|
+
* that it computes from the pointer value at the entry state: a guess, because
|
|
54
|
+
* the program sets the pointer at run time. Only the reference to the pointer
|
|
55
|
+
* itself (zp or zp+1) is a fact.
|
|
56
|
+
*/
|
|
57
|
+
function guessedIndirectTarget(instructions: GhidraResult["instructions"]): (reference: { from: number; to: number }) => boolean {
|
|
58
|
+
const pointers = new Map<number, number>();
|
|
59
|
+
for (const instruction of instructions) {
|
|
60
|
+
const opcode = Number.parseInt(instruction.bytes.slice(0, 2), 16);
|
|
61
|
+
if (instruction.bytes.length === 4 && ((opcode & 0x0f) === 0x01 || (opcode & 0x0f) === 0x03)) pointers.set(instruction.address, Number.parseInt(instruction.bytes.slice(2, 4), 16));
|
|
62
|
+
}
|
|
63
|
+
return (reference) => {
|
|
64
|
+
const pointer = pointers.get(reference.from);
|
|
65
|
+
return pointer !== undefined && reference.to !== pointer && reference.to !== ((pointer + 1) & 0xff);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Ghidra's result as normalized findings. A reference from a (zp,x) or (zp),y
|
|
71
|
+
* instruction to a computed target is not a finding (see guessedIndirectTarget).
|
|
72
|
+
* A function named by an echoed seed
|
|
52
73
|
* stays in the snapshot: its address holds the seed's semantic symbol, which
|
|
53
74
|
* the importer never replaces, so the name keeps its owner,
|
|
54
75
|
* and a code/data disagreement with that symbol is still reported.
|
|
@@ -64,6 +85,7 @@ export function ghidraFindings(result: GhidraResult): NormalizedFindings {
|
|
|
64
85
|
// A function that branches and jumps reach, and no call, is a place in a routine: a label.
|
|
65
86
|
const called = new Set(result.references.filter((reference) => reference.type === "call").map((reference) => reference.to));
|
|
66
87
|
const jumped = new Set(result.references.filter((reference) => reference.type === "jump").map((reference) => reference.to));
|
|
88
|
+
const guessed = guessedIndirectTarget(result.instructions);
|
|
67
89
|
const kindOf = (fn: GhidraResult["functions"][number]) => (jumped.has(fn.entry) && !called.has(fn.entry) ? ("label" as const) : ("routine" as const));
|
|
68
90
|
return {
|
|
69
91
|
analyzer: "ghidra",
|
|
@@ -71,7 +93,7 @@ export function ghidraFindings(result: GhidraResult): NormalizedFindings {
|
|
|
71
93
|
authoritative: { symbols: result.completeness.functions, regions: result.completeness.regions, references: result.completeness.references },
|
|
72
94
|
symbols: result.functions.map((fn) => ({ address: fn.entry, name: nameOf(fn), kind: kindOf(fn) })),
|
|
73
95
|
regions: result.regions.map((region) => ({ start: region.start, end: region.end, type: region.classification === "code" ? ("code" as const) : ("bytes" as const) })),
|
|
74
|
-
references: result.references.map((reference) => ({ from: reference.from, to: reference.to, kind: reference.type })),
|
|
96
|
+
references: result.references.filter((reference) => !guessed(reference)).map((reference) => ({ from: reference.from, to: reference.to, kind: reference.type })),
|
|
75
97
|
};
|
|
76
98
|
}
|
|
77
99
|
|
|
@@ -96,6 +96,8 @@ A run file (for `testing.ts run`) has:
|
|
|
96
96
|
|
|
97
97
|
A `trace` step has a name, `points` (1 to 8), `frames` (1 to 3000) and an optional `maxHits` (at most 20000). A point has `kind` (`exec`, `read` or `write`), `start` and an optional `end`. The step writes `<name>.json` with each hit. `results.json` gives the file, the count of hits, the frames and why the trace ended. A trace that a breakpoint, a watchpoint or a JAM ends also ends the run.
|
|
98
98
|
|
|
99
|
+
In a run, an `observe` step can have `memory`, `registers`, `vicii` and `sprites`. `registers` and `vicii` are `true` or `false`, not a list. `"registers": true` gives all registers. A scenario takes a list of register names, a run does not. `sprites` is a list of sprite numbers from 0 to 7.
|
|
100
|
+
|
|
99
101
|
In a run, a memory item has `address`, `size` (1 to 65536) and `view`. An item larger than 4096 bytes goes into the file `<observe>-<address>.bin`, without the `$`. `"memory": "all"` writes all 64 KiB of RAM to `<observe>.bin`.
|
|
100
102
|
|
|
101
103
|
A name in `save`, `screen`, `coverage` and `observe` has 1 to 64 letters, digits, dots, underscores or hyphens. The files go into the `--out` directory, with `results.json`. It has the observations, the files and the steps done. If a `runUntil` step did not reach its target, it also tells why the run stopped.
|
|
@@ -152,7 +152,7 @@ function readRun(path: string): Run {
|
|
|
152
152
|
if (step.memory !== undefined && step.memory !== "all" && (!Array.isArray(step.memory) || !step.memory.every(memoryItem))) {
|
|
153
153
|
fail(`${at}: memory is "all", or a list of names, $ addresses, or objects with address, size (1 to 65536) and view (cpu or ram)`);
|
|
154
154
|
}
|
|
155
|
-
if (step.registers !== undefined && typeof step.registers !== "boolean") fail(`${at}: registers must be true or false`);
|
|
155
|
+
if (step.registers !== undefined && typeof step.registers !== "boolean") fail(`${at}: registers must be true or false in a run. true gives all registers. A list of register names is for a scenario`);
|
|
156
156
|
if (step.vicii !== undefined && typeof step.vicii !== "boolean") fail(`${at}: vicii must be true or false`);
|
|
157
157
|
if (step.sprites !== undefined && (!Array.isArray(step.sprites) || !step.sprites.every((sprite) => isInteger(sprite, 0, 7)))) fail(`${at}: sprites is a list of numbers from 0 to 7`);
|
|
158
158
|
});
|
|
@@ -307,15 +307,16 @@ const PROGRAM_REMEDY = "A scenario program is a PRG. Get the PRG out of the disk
|
|
|
307
307
|
* program and the symbols of each side, and each snapshot file. A missing
|
|
308
308
|
* file is not-found; a program that is no PRG, a symbols file with no names
|
|
309
309
|
* and a snapshot step whose file is no VICE snapshot file are invalid-input.
|
|
310
|
-
* A refusal
|
|
310
|
+
* A refusal starts with the scenario file, as the other scenario errors do,
|
|
311
|
+
* and names the field or the step. Gives the names of each side.
|
|
311
312
|
*/
|
|
312
|
-
export function scenarioNames(scenario: Scenario): Map<Side, Map<string, number>> {
|
|
313
|
+
export function scenarioNames(scenario: Scenario, path: string): Map<Side, Map<string, number>> {
|
|
313
314
|
const names = new Map<Side, Map<string, number>>();
|
|
314
315
|
const named = <T>(field: string, read: () => T): T => {
|
|
315
316
|
try {
|
|
316
317
|
return read();
|
|
317
318
|
} catch (error) {
|
|
318
|
-
if (isRefusal(error)) throw new Refusal(error.code,
|
|
319
|
+
if (isRefusal(error)) throw new Refusal(error.code, `scenario ${path}: ${field}: ${error.message}`);
|
|
319
320
|
throw error;
|
|
320
321
|
}
|
|
321
322
|
};
|
|
@@ -38,7 +38,7 @@ async function test(call: Call): Promise<ScenarioResult> {
|
|
|
38
38
|
const scenario = readScenario(call.subject(0));
|
|
39
39
|
const out = call.string("out");
|
|
40
40
|
// Every file of the scenario is checked before the emulator starts.
|
|
41
|
-
const names = scenarioNames(scenario);
|
|
41
|
+
const names = scenarioNames(scenario, call.subject(0));
|
|
42
42
|
let client: ViceSessionClient;
|
|
43
43
|
try {
|
|
44
44
|
client = await ViceSessionClient.open({ videoStandard: scenario.videoStandard ?? "pal" });
|
|
@@ -117,7 +117,7 @@ The scripts refuse a step in the form of version 2.0, for example `{ "runUntil":
|
|
|
117
117
|
|
|
118
118
|
## Multi-load programs
|
|
119
119
|
|
|
120
|
-
A multi-load program loads more parts from the disk while it runs, for example one part for each level. Use `loads` to capture each part. The program can be a PRG, or a disk, tape or cartridge image that VICE starts.
|
|
120
|
+
A multi-load program loads more parts from the disk while it runs, for example one part for each level. Use `loads` to capture each part. The program can be a PRG, or a disk, tape or cartridge image that VICE starts. `loads` starts a PRG with RUN. Thus the PRG must have a BASIC start line. For a PRG without a BASIC start line, use `capture` with `--entry`.
|
|
121
121
|
|
|
122
122
|
1. Write a steps file. Put a `capture` step after each point where a part is in memory, for example:
|
|
123
123
|
|
|
@@ -161,7 +161,8 @@ For `loads`: `captures`, with the name, the PC, the segments, `differsFromReset`
|
|
|
161
161
|
- `traced: false` or `followed: false` with `stopReason`: the CPU stopped before the frames ran, for example at a JAM instruction. `pc` gives the address. Make sure that `--entry` is the start of the code that the file holds at that time, and that the steps are correct.
|
|
162
162
|
- `captured: false`: the program did not get to the address in the time limit. The reason tells where it stopped. Find a better address with the c64-emulator skill, or give more frames. If it stopped in a key wait, give `--steps` with a `type` step.
|
|
163
163
|
- A step did not reach its target: the reason names the step. Change the step or give it more frames.
|
|
164
|
-
- `loaded: false`
|
|
164
|
+
- `loaded: false` with an empty `captures` and the reason `BASIC ran no program line`: the PRG has no BASIC start line. Use `capture` with `--entry`.
|
|
165
|
+
- `loaded: false` and no capture has a segment: the program did not load a part, or it did not start. `keyWait: true` on a capture tells that the C64 waited for a key at the READY prompt or at an INPUT statement. For a tape image, read `emulatorFlaw`. A known VICE flaw can stop a tape load. Tell the user to install the latest VICE.
|
|
165
166
|
- Do not name a packer from weak evidence. The script never names one.
|
|
166
167
|
- Some programs unpack in more than one stage. Run `stages` to find each stage. Capture at the entry of the last stage. Make sure that it is the application and not a second unpacker.
|
|
167
168
|
- `not-found` or `invalid-input`: a path or an argument is wrong. Read the message.
|
|
@@ -111,7 +111,7 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
111
111
|
let emulatorFlaw: string | undefined;
|
|
112
112
|
if (program.toLowerCase().endsWith(".prg")) {
|
|
113
113
|
const { bytes } = readProjectFile(program);
|
|
114
|
-
if (!(await autostartLoaded(client, program, bytes))) return { output: { loaded: false, reason: `The program was not in memory after ${LOAD_LIMIT_FRAMES} frames
|
|
114
|
+
if (!(await autostartLoaded(client, program, bytes))) return { output: { loaded: false, reason: `The program was not in memory after ${LOAD_LIMIT_FRAMES} frames.`, captures: [] }, failed: true };
|
|
115
115
|
// The RAM before RUN, without the program, so the first capture holds the program too.
|
|
116
116
|
previous = await readRam(client, 0x0000, 0x10000);
|
|
117
117
|
const load = bytes[0]! | (bytes[1]! << 8);
|
|
@@ -119,7 +119,10 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
119
119
|
loadedProgram = bytes;
|
|
120
120
|
await client.memmap({ action: "clear" });
|
|
121
121
|
// RUN as c64-testing types it: the steps start at the same time as a scenario's.
|
|
122
|
-
if (!(await typeRun(client)))
|
|
122
|
+
if (!(await typeRun(client))) {
|
|
123
|
+
const reason = `After RUN, BASIC ran no program line in ${RUN_LIMIT_FRAMES} frames. loads starts a PRG with RUN, so it needs a program with a BASIC start line, for example 10 SYS 2061. For a PRG without a BASIC start, use capture with --entry.`;
|
|
124
|
+
return { output: { loaded: false, reason, captures: [] }, failed: true };
|
|
125
|
+
}
|
|
123
126
|
} else {
|
|
124
127
|
// A disk, tape or cartridge: VICE loads and starts it. The RAM test of the KERNAL puts back what it writes.
|
|
125
128
|
previous = await readRam(client, 0x0000, 0x10000);
|
package/src/host/vice/session.ts
CHANGED
|
@@ -214,6 +214,8 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
214
214
|
* disk drive was busy, so a save here is refused.
|
|
215
215
|
*/
|
|
216
216
|
#atResetStop = false;
|
|
217
|
+
/** Warp as the user set it: VICE also turns warp on by itself while an autostart loads. */
|
|
218
|
+
#userWarp = false;
|
|
217
219
|
/** The CPU that the last run stopped in, when it was the drive: status then gives the drive's pc. */
|
|
218
220
|
#stopSpace: "c64" | "drive8" = "c64";
|
|
219
221
|
/** VICE records no CPU history after a JAM until the next reset. */
|
|
@@ -459,6 +461,13 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
459
461
|
return this.#reset(params as ViceOperations["reset"]["params"]);
|
|
460
462
|
case "keyboard": {
|
|
461
463
|
const bytes = Buffer.from((params as ViceOperations["keyboard"]["params"]).data, "hex");
|
|
464
|
+
// VICE turns warp on for an autostart and off when it types RUN. A key in between ends the autostart with no message.
|
|
465
|
+
if (this.#autostarting && !this.#userWarp && (await this.#observe(() => this.#machine.warp()))) {
|
|
466
|
+
throw new WireFailure(
|
|
467
|
+
"operation-failed",
|
|
468
|
+
"The autostart still loads the program, and a key now stops it before RUN. Run frames with c64_execution advance-frames until c64_status gives warp false, then type.",
|
|
469
|
+
);
|
|
470
|
+
}
|
|
462
471
|
await this.#observe(() => this.#machine.feedKeyboard(bytes));
|
|
463
472
|
return { queuedBytes: bytes.length, ...(this.#inputFlaw === undefined ? {} : { emulatorFlaw: this.#inputFlaw }) };
|
|
464
473
|
}
|
|
@@ -553,6 +562,7 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
553
562
|
case "warp": {
|
|
554
563
|
const { enabled } = params as ViceOperations["warp"]["params"];
|
|
555
564
|
await this.#observe(() => this.#machine.setWarp(enabled));
|
|
565
|
+
this.#userWarp = enabled;
|
|
556
566
|
return { enabled };
|
|
557
567
|
}
|
|
558
568
|
case "window":
|
|
@@ -645,14 +655,16 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
645
655
|
}
|
|
646
656
|
const count = params.count ?? 1;
|
|
647
657
|
this.#atResetStop = false;
|
|
658
|
+
// The stop event of the step tells that it ended, and which point stopped it. A long step
|
|
659
|
+
// in warp can answer before it ends; a ping then would stop it early and leave the rest in VICE.
|
|
660
|
+
const stopped = this.#nextStop(this.#stepLimitMs);
|
|
648
661
|
try {
|
|
649
662
|
await this.#machine.step(count, params.action === "next", this.#stepLimitMs);
|
|
650
663
|
} catch (error) {
|
|
651
664
|
if (error instanceof MonitorTimeoutError) throw new StepTimeout(stepNotEnded(params.action, count, this.#stepLimitMs), error);
|
|
652
665
|
throw error;
|
|
653
666
|
}
|
|
654
|
-
|
|
655
|
-
await this.#machine.stop();
|
|
667
|
+
if ((await stopped) === undefined) await this.#machine.stop();
|
|
656
668
|
this.#state = "stopped";
|
|
657
669
|
const point = this.#stepStoppedByPoint();
|
|
658
670
|
// A point stops the step early: VICE does not tell how many instructions ran.
|
|
@@ -793,6 +805,14 @@ export class ViceSession implements ViceSessionHandle {
|
|
|
793
805
|
let frames = 0;
|
|
794
806
|
const startPc = await this.#pc();
|
|
795
807
|
if (await this.#jamAt(startPc)) return { hits, frames, end: "jam", pc: startPc };
|
|
808
|
+
// VICE checks no checkpoint at the pc that it resumes from: an exec point there gets its first hit here.
|
|
809
|
+
for (const [index, point] of params.points.entries()) {
|
|
810
|
+
if (point.kind === "exec" && point.start <= startPc && startPc <= point.end) {
|
|
811
|
+
hits.push(await this.#traceHit(index, "exec", 0));
|
|
812
|
+
if (hits.length >= params.maxHits) return { hits, frames, end: "hits", pc: startPc };
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
796
816
|
let clockPc = startPc;
|
|
797
817
|
const clock = await this.#machine.addCheckpoint({ start: 0x0000, end: 0xffff, operation: 0x04, space: "c64" });
|
|
798
818
|
try {
|