@henols/c64-re-tools 2.8.0-rc.5 → 2.8.0-rc.7
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 +1 -1
- package/skills/c64-assembler/scripts/assembler.ts +78 -24
- package/skills/c64-docs/scripts/docs.ts +31 -10
- package/skills/c64-knowledge/SKILL.md +4 -3
- package/skills/c64-knowledge/scripts/knowledge.ts +31 -12
- package/skills/c64-packer/scripts/packer.ts +9 -2
- package/skills/c64-provenance/SKILL.md +1 -1
- package/skills/c64-provenance/scripts/lib/runtime.ts +5 -16
- package/skills/c64-source/references/loader.md +8 -7
- package/skills/c64-source/scripts/lib/loader.ts +4 -111
- package/skills/c64-source/scripts/source.ts +49 -78
- package/skills/c64-static-analysis/SKILL.md +2 -2
- package/skills/c64-static-analysis/scripts/lib/coverage.ts +56 -4
- package/skills/c64-static-analysis/scripts/static-analysis.ts +32 -21
- package/skills/c64-testing/SKILL.md +6 -0
- package/skills/c64-testing/scripts/lib/play.ts +8 -7
- package/skills/c64-testing/scripts/lib/recording.ts +218 -12
- package/skills/c64-testing/scripts/lib/replay.ts +7 -3
- package/skills/c64-testing/scripts/lib/runs.ts +5 -1
- package/skills/c64-testing/scripts/lib/scenario.ts +4 -0
- package/skills/c64-testing/scripts/testing.ts +24 -11
- package/skills/c64-unpacker/SKILL.md +6 -4
- package/skills/c64-unpacker/scripts/lib/loads.ts +4 -2
- package/skills/c64-unpacker/scripts/lib/machine.ts +128 -5
- package/skills/c64-unpacker/scripts/lib/stages.ts +5 -1
- package/skills/c64-unpacker/scripts/unpacker.ts +13 -12
- package/skills/emulator/SKILL.md +2 -2
- package/src/host/vice/adapter.ts +2 -1
- package/src/host-client/image.ts +33 -4
- package/src/host-client/tools.ts +1 -1
- package/src/host-client/transfer.ts +48 -26
- package/src/host-client/vice-session.ts +15 -0
- package/src/knowledge/database.ts +72 -19
- package/src/knowledge/import.ts +31 -8
- package/src/knowledge/names.ts +2 -2
- package/src/knowledge/program.ts +67 -7
- package/src/knowledge/schema.ts +6 -0
- package/src/knowledge/start-screen.ts +55 -2
- package/src/knowledge/write.ts +18 -12
- package/src/loader.ts +101 -33
- package/src/mcp/output.ts +13 -12
- package/src/mcp/server.ts +33 -22
- package/src/mcp/tools/debug.ts +21 -24
- package/src/mcp/tools/media.ts +27 -27
- package/src/mcp/tools/memory.ts +13 -17
- package/src/mcp/tools/video.ts +10 -12
- package/src/native/c64run.ts +39 -1
- package/src/native/decompiler/analyze.ts +1 -1
- package/src/native/dxa.ts +2 -2
- package/src/native/types.ts +26 -7
- package/src/program-code.ts +4 -2
- package/src/project.ts +224 -71
- package/src/protocol/vice.ts +5 -3
- package/src/script.ts +60 -15
- package/{skills/c64-source/scripts/lib → src}/stage.ts +142 -11
- package/tools/c64run.c +18 -5
|
@@ -13,7 +13,7 @@ import { knowledgeNames } from "#src/knowledge/names.ts";
|
|
|
13
13
|
import { analyze as analyzeWithDxa } from "#src/native/dxa.ts";
|
|
14
14
|
import { analyze as analyzeWithDecompiler } from "#src/native/decompiler/analyze.ts";
|
|
15
15
|
import { localToolContext } from "#src/native/local.ts";
|
|
16
|
-
import { DECOMPILER_LIMITS, type RefusedSeed, type SeedReport } from "#src/native/types.ts";
|
|
16
|
+
import { DECOMPILER_LIMITS, DXA_LIMITS, type RefusedSeed, type SeedReport } from "#src/native/types.ts";
|
|
17
17
|
import { openForRead, withRead, withWrite } from "#src/knowledge/database.ts";
|
|
18
18
|
import { analyzedBytes, operandImages, programCoverage, requireProgram } from "#src/knowledge/program.ts";
|
|
19
19
|
import { applyBatch, type BatchOperation } from "#src/knowledge/write.ts";
|
|
@@ -22,7 +22,7 @@ import { currentRevision, listMacros, listMacroUses, listPatches, listReferences
|
|
|
22
22
|
import { CODE_REGION_TYPES, DEFAULT_SPACE, SEMANTIC_ORIGINS, type Analyzer } from "#src/knowledge/schema.ts";
|
|
23
23
|
import { platformAddresses, platformNames, platformNamesFor, romUseOfProgram, type RomUse } from "#src/platform.ts";
|
|
24
24
|
import { listed, OPTIONS, reply, runScript, UsageError, type Call } from "#src/script.ts";
|
|
25
|
-
import { codeEntries, coverageConflicts, imageReader, writtenNotExecuted, explainGaps, type GapReason, type ImageByte } from "./lib/coverage.ts";
|
|
25
|
+
import { codeEntries, coverageConflicts, imageReader, referenceTargets, withoutOverlaps, writtenNotExecuted, explainGaps, type GapReason, type ImageByte } from "./lib/coverage.ts";
|
|
26
26
|
import { decidedFromKnowledge, dxaFindings, decompilerFindings, seedsFromKnowledge } from "./lib/findings.ts";
|
|
27
27
|
import { findIdioms } from "./lib/idioms.ts";
|
|
28
28
|
import { instructionList } from "./lib/instructions.ts";
|
|
@@ -311,28 +311,34 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
311
311
|
// Idiom tables and the RAM under ROM that the runs never used are data for this run too; semantic data ranges come first.
|
|
312
312
|
// A range with an entry point of the knowledge or --entry in it is left out: that code stays code.
|
|
313
313
|
const fromRom = coverage === undefined ? [] : romOnlyRanges(coverage, byteAt).filter((range) => !known.some((entry) => entry >= range.start && entry <= range.end));
|
|
314
|
+
const limits = analyzer === "dxa" ? DXA_LIMITS : DECOMPILER_LIMITS;
|
|
314
315
|
const dataRanges = [...seeds.dataRanges];
|
|
315
316
|
for (const range of [...idioms.dataRanges, ...fromRom]) if (!dataRanges.some((seed) => range.start <= seed.end && range.end >= seed.start)) dataRanges.push(range);
|
|
316
|
-
seeds.dataRanges = dataRanges.slice(0,
|
|
317
|
-
// Knowledge routines and --entry first, then code regions and JMP tables, then idioms, then coverage,
|
|
318
|
-
//
|
|
319
|
-
// DECOMPILER_LIMITS.codeStarts (8192) coverage flow starts that are code
|
|
320
|
-
// The decompiler takes the coverage as code starts without a function.
|
|
321
|
-
// that it reaches by fall-through from another seed, for example the
|
|
317
|
+
seeds.dataRanges = dataRanges.slice(0, limits.dataRanges);
|
|
318
|
+
// Knowledge routines and --entry first, then code regions and JMP tables, then idioms, then coverage, then for DXA the
|
|
319
|
+
// jump and call targets of the knowledge, up to the seed bound of the analyzer: at most 1024 entry points for the decompiler
|
|
320
|
+
// and 8192 for DXA, and for the decompiler at most DECOMPILER_LIMITS.codeStarts (8192) coverage flow starts that are code
|
|
321
|
+
// in a routine. coverageSeeds gives what was used. The decompiler takes the coverage as code starts without a function.
|
|
322
|
+
// DXA has one list, without the coverage starts that it reaches by fall-through from another seed, for example the
|
|
323
|
+
// instruction after a JSR. Each target stays a seed: DXA drops routes that fall-through would show as reached.
|
|
324
|
+
const targets = analyzer === "dxa" ? referenceTargets(reader, analyzer, inProgram, { data: seeds.dataRanges, dualUse: idioms.findings.regions.filter((region) => region.type === "dual-use") }, space) : [];
|
|
322
325
|
const fallThrough = (from: readonly number[]) => (coverage === undefined ? new Set<number>() : dxaFallThrough(from, coverage, inProgram, seeds.dataRanges));
|
|
323
326
|
const reached = analyzer === "dxa" ? fallThrough([...known, ...idioms.entryPoints, ...fromCoverage]) : new Set<number>();
|
|
324
327
|
const kinds = analyzer === "dxa" || coverage === undefined ? { routines: fromCoverage.filter((entry) => !reached.has(entry)), codeStarts: [] } : coverageSeedKinds(coverage, inProgram);
|
|
325
|
-
const ordered = [...new Set([...known, ...idioms.entryPoints, ...kinds.routines])];
|
|
326
|
-
seeds.entryPoints = ordered.slice(0,
|
|
327
|
-
const
|
|
328
|
-
const
|
|
328
|
+
const ordered = [...new Set([...known, ...idioms.entryPoints, ...kinds.routines, ...targets])];
|
|
329
|
+
seeds.entryPoints = ordered.slice(0, limits.entryPoints).sort((a, b) => a - b);
|
|
330
|
+
const seeded = new Set(seeds.entryPoints);
|
|
331
|
+
const allCodeStarts = kinds.codeStarts.filter((entry) => !seeded.has(entry));
|
|
332
|
+
const codeStarts = allCodeStarts.slice(0, limits.codeStarts);
|
|
329
333
|
// The seeds over the limits of the analyzer: it never sees them.
|
|
330
|
-
const cut = { analyzer, entryPoints: ordered.slice(
|
|
334
|
+
const cut = { analyzer, entryPoints: ordered.slice(limits.entryPoints), codeStarts: allCodeStarts.slice(limits.codeStarts), dataRanges: dataRanges.slice(limits.dataRanges) };
|
|
331
335
|
const overLimit = { entryPoints: cut.entryPoints.length, codeStarts: cut.codeStarts.length, dataRanges: cut.dataRanges.length };
|
|
332
|
-
const
|
|
336
|
+
const usedRanges = new Set(seeds.dataRanges);
|
|
337
|
+
const romUsed = fromRom.filter((range) => usedRanges.has(range)).length;
|
|
333
338
|
// DXA also decodes a coverage start that it did not get, when a seed that it got reaches the start by fall-through.
|
|
334
339
|
const followed = analyzer === "dxa" ? fallThrough(seeds.entryPoints) : new Set<number>();
|
|
335
|
-
const
|
|
340
|
+
const started = new Set(codeStarts);
|
|
341
|
+
const coverageUsed = fromCoverage.filter((entry) => seeded.has(entry) || started.has(entry) || followed.has(entry)).length;
|
|
336
342
|
// Platform names are C64 names: drive code and banks get none.
|
|
337
343
|
const platform = space === DEFAULT_SPACE ? platformNames() : [];
|
|
338
344
|
/** The analyzer version of the last analysis of these bytes: a new version can change the findings by itself. */
|
|
@@ -398,21 +404,24 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
398
404
|
/**
|
|
399
405
|
* The result from the knowledge after both imports: the fields of both
|
|
400
406
|
* analyzers around the fields that only one gives (`gaps` after the
|
|
401
|
-
* coverage, `tail` after the idioms), and the hint.
|
|
407
|
+
* coverage, `tail` after the idioms), and the hint. A seed that the
|
|
408
|
+
* analysis refused because of a known overlap is not a refused seed: it
|
|
409
|
+
* is no fault of the knowledge. Read after the idioms, which write dual-use regions.
|
|
402
410
|
*/
|
|
403
411
|
const resultOf = (
|
|
404
412
|
db: DatabaseSync | undefined,
|
|
405
|
-
run: { toolVersion: string | undefined; imported: ReturnType<typeof record>; report: SeedReport;
|
|
413
|
+
run: { toolVersion: string | undefined; imported: ReturnType<typeof record>; report: SeedReport; given: Record<string, number>; overLimit: Record<string, number>; found: ReturnType<typeof idiomsResult>; gaps?: Record<string, unknown>; tail: Record<string, unknown> },
|
|
406
414
|
) => {
|
|
407
415
|
const runOnWritten = coverage === undefined ? [] : writtenNotExecuted(db, analyzer, coverage, space);
|
|
408
416
|
const { factsOf, ...found } = run.found;
|
|
417
|
+
const refused = withoutOverlaps(run.report.refused, listRegions(db, undefined, "dual-use", undefined, space));
|
|
409
418
|
const body = {
|
|
410
419
|
analyzer,
|
|
411
420
|
...(run.toolVersion === undefined ? {} : { analyzerVersion: run.toolVersion }),
|
|
412
421
|
...(space === DEFAULT_SPACE ? {} : { space }),
|
|
413
422
|
...run.imported,
|
|
414
423
|
conflicts: run.imported.conflicts.map((conflict) => showConflictFacts(conflict, analyzer, factsOf, max)),
|
|
415
|
-
seeds: run.
|
|
424
|
+
seeds: seedsResult(run.given, run.overLimit, { ...run.report, refused }, max),
|
|
416
425
|
...coverageResult(db),
|
|
417
426
|
...run.gaps,
|
|
418
427
|
...(runOnWritten.length === 0 ? {} : { writtenNotExecuted: listed(runOnWritten, max, showWritten) }),
|
|
@@ -425,7 +434,7 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
425
434
|
macros: { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision },
|
|
426
435
|
version: { now: run.toolVersion, last: lastVersion, revision: run.imported.revision },
|
|
427
436
|
retiredReferences: run.imported.changes.references.retired,
|
|
428
|
-
guards: { refused: toCorrect(
|
|
437
|
+
guards: { refused: toCorrect(refused, entries), writtenNotExecuted: runOnWritten.length },
|
|
429
438
|
cut,
|
|
430
439
|
});
|
|
431
440
|
};
|
|
@@ -449,7 +458,8 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
449
458
|
toolVersion: result.toolVersion,
|
|
450
459
|
imported,
|
|
451
460
|
report,
|
|
452
|
-
|
|
461
|
+
given: { entryPoints: seeds.entryPoints.length, dataRanges: seeds.dataRanges.length },
|
|
462
|
+
overLimit: { entryPoints: overLimit.entryPoints, dataRanges: overLimit.dataRanges },
|
|
453
463
|
found: idiomsResult(db, idiomsImported),
|
|
454
464
|
tail: {
|
|
455
465
|
coverage: result.coverage.map(formatC64RangeFields),
|
|
@@ -483,7 +493,8 @@ async function analyze(call: Call): Promise<unknown> {
|
|
|
483
493
|
toolVersion: result.toolVersion,
|
|
484
494
|
imported,
|
|
485
495
|
report,
|
|
486
|
-
|
|
496
|
+
given: { entryPoints: seeds.entryPoints.length, codeStarts: codeStarts.length, dataRanges: seeds.dataRanges.length },
|
|
497
|
+
overLimit,
|
|
487
498
|
found,
|
|
488
499
|
gaps: coverage === undefined ? {} : { coverageGaps: listed(explained, max, showGap, "a larger --max-listed") },
|
|
489
500
|
tail: {
|
|
@@ -229,11 +229,14 @@ The script does the steps of the record file on the reference program. Then it w
|
|
|
229
229
|
- `coverageFrom`: the `frame` and the `pc` where the coverage map starts. `null` when the coverage did not start.
|
|
230
230
|
- `reason`: with a FAIL, why the session did not complete.
|
|
231
231
|
- `evidence`: only when the project knowledge gives a file of `--out` as evidence, and this record changed the file. Each item has the `file`, its `state` and the `revisions` that give the file.
|
|
232
|
+
- `entryStateDiffers`: the ranges of `$0002`-`$03ff` where the program at its entry has other bytes than the entry state of the project knowledge. The script compares only when it examines the entry. The script does not compare the free part of the stack page. It does not compare the KERNAL bytes that change by time alone: the jiffy clock and the cursor blink. It does not compare the load pointer at `$00ac`-`$00ad`, which the start sets. When no byte is different, the body has no `entryStateDiffers`.
|
|
233
|
+
- `entryState`: a note in place of `entryStateDiffers`. The program came to its entry during the input of the session. Input is a key, a joystick that is not centered, or the keys of a `type` step. A new capture cannot remove that difference. Do not capture again for it.
|
|
232
234
|
|
|
233
235
|
Do this for each result:
|
|
234
236
|
|
|
235
237
|
- `PASS`: for a folder in `tests/recordings/`, `hint` tells you to commit the folder and to add its coverage map to the project knowledge as coverage. Git ignores `.c64-re-tools/local/`, thus the project knowledge must not name a file in it. For a folder there, `hint` tells you to record again with `--out tests/recordings/<name>`. `nextAction` replays the recording on the reference. Run it to make sure that the recording replays.
|
|
236
238
|
- `PASS`, and `hint` names a step that "ran before the program came to its entry", or tells that "the program did not come to its entry". The entry is the entry in the project knowledge, where the loader of a rebuild starts the program. Thus `replay` on a rebuild with a loader gives `INCONCLUSIVE`. A `replay` on the reference, or on a rebuild without a loader, can use the recording. For a rebuild with a loader, make the steps of the record file start after the entry. Make the session continue until the program runs from its entry. Then record the session again. The script examines the entry only when `symbols` of the record file is `knowledge` or `none`.
|
|
239
|
+
- `PASS` with `entryStateDiffers`: the input of the record file before the entry is not the input of the capture of the program. The loader of a rebuild writes the entry state of the capture. Thus a replay on that rebuild starts from a different state. Capture the program again with the input of the record file before the entry. Then put the capture into the project knowledge, and generate the loader again.
|
|
237
240
|
- `PASS` with `evidence`: you recorded into the folder of an earlier recording. Put the new coverage map into the project knowledge as coverage, as `hint` tells. It replaces the map of the earlier recording. For another file in `evidence`, examine the facts of its revisions against the new recording.
|
|
238
241
|
- `FAIL` after a cancel on the page: `hint` tells you to ask the user what to do. Do not record a session from steps in place of the session of the user.
|
|
239
242
|
- Another `FAIL`: `reason` names the step that did not complete. Examples are a `runUntil` step that did not get to its target, and a `type` step with too many keys. Change the step, then run `record` again.
|
|
@@ -286,6 +289,8 @@ A `$` address is an address of the reference. On the rebuild, it moves with the
|
|
|
286
289
|
- `movedSites`: the number of input sites at a different address in the rebuild.
|
|
287
290
|
- `startScreen`: `skipped` when the rebuild started after its start screen.
|
|
288
291
|
- `idleReads`: the number of input reads of the rebuild that the recording had no value for.
|
|
292
|
+
- `entryStateDiffers`: only for a rebuild with a loader. The ranges of `$0002`-`$03ff` where the reference at its entry has other bytes than the rebuild at its entry. The loader of the rebuild wrote these bytes. The script does not compare the free part of the stack page. It does not compare the KERNAL bytes that change by time alone: the jiffy clock and the cursor blink. It does not compare the load pointer at `$00ac`-`$00ad`, which the start sets. When no byte is different, the body has no `entryStateDiffers`.
|
|
293
|
+
- `entryState`: a note in place of `entryStateDiffers`. The program came to its entry during the input of the session. Input is a key, a joystick that is not centered, or the keys of a `type` step. A new capture cannot remove that difference. Do not capture again for it.
|
|
289
294
|
- `files`: with `--out` and a FAIL, the RAM of each side at the first different checkpoint.
|
|
290
295
|
- `screen`: with `--screen`, the PNG file of the screen of the reference at the end of the session.
|
|
291
296
|
|
|
@@ -296,6 +301,7 @@ Do this for each result:
|
|
|
296
301
|
- `PASS`: each checkpoint of the rebuild has the state of the reference. Without `--rebuild`, the recording replays on the reference.
|
|
297
302
|
- `FAIL` with `--out`: `files` has the RAM of each side at the first different checkpoint. `nextAction` compares the two files with `diff`. Then examine the first different state item in the emulator.
|
|
298
303
|
- `FAIL` without `--out`: `hint` tells you to give `--out`. A FAIL where an enemy or an event is different, but the input is the same, often shows that a `--pin` is missing.
|
|
304
|
+
- A result with `entryStateDiffers`: the rebuild starts from a different state than the reference. A FAIL can come from this difference. Capture the program again with the input of the record file before the entry. Then put the capture into the project knowledge, generate the loader again, and replay again.
|
|
299
305
|
- `FAIL` with no `firstDifference`: the rebuild did not get to all checkpoints. `reason` gives the number. When the rebuild has the names of the recording, `hint` tells you to give `--symbols`. Else examine the rebuild in the emulator after its last checkpoint.
|
|
300
306
|
- `INCONCLUSIVE`: `reason` gives the cause:
|
|
301
307
|
- "does not reproduce": the reference does not end the session with the recorded state. Record the session again.
|
|
@@ -223,10 +223,10 @@ const RESTORE = Symbol("restore");
|
|
|
223
223
|
* undefined: the recording is complete. Cancel gives CANCELLED, and a RESTORE
|
|
224
224
|
* that fails gives its reason. No frame runs after End or Cancel.
|
|
225
225
|
*/
|
|
226
|
-
export async function play(core: Pick<C64RunSession, "command" | "status">, options: PlayOptions): Promise<string | undefined> {
|
|
226
|
+
export async function play(core: Pick<C64RunSession, "command" | "status" | "key" | "joy">, options: PlayOptions): Promise<string | undefined> {
|
|
227
227
|
const palette = (await core.command("palette")).split(" ").slice(1).join(" ");
|
|
228
228
|
const viewers = new Set<ServerResponse>();
|
|
229
|
-
const pending: Array<
|
|
229
|
+
const pending: Array<{ code: number; down: boolean } | typeof RESTORE> = [];
|
|
230
230
|
let mask = 0;
|
|
231
231
|
let port = options.joystick;
|
|
232
232
|
let reason: string | undefined;
|
|
@@ -270,7 +270,7 @@ export async function play(core: Pick<C64RunSession, "command" | "status">, opti
|
|
|
270
270
|
const keys = (url.searchParams.get("keys") ?? "").split(",").map((key) => (/^\d{1,2}$/.test(key) ? Number(key) : -1));
|
|
271
271
|
if (!keys.every((key) => PAGE_KEYS.has(key))) return void response.writeHead(400).end();
|
|
272
272
|
const state = url.searchParams.get("down") === "1" ? "down" : "up";
|
|
273
|
-
if (phase === "playing") for (const key of keys) pending.push(
|
|
273
|
+
if (phase === "playing") for (const key of keys) pending.push({ code: 0x80 + key, down: state === "down" });
|
|
274
274
|
answer(phase === "playing");
|
|
275
275
|
} else if (request.method === "POST" && url.pathname === "/restore") {
|
|
276
276
|
if (phase === "playing") pending.push(RESTORE);
|
|
@@ -302,15 +302,16 @@ export async function play(core: Pick<C64RunSession, "command" | "status">, opti
|
|
|
302
302
|
await leftWaiting;
|
|
303
303
|
while (phase === "playing") {
|
|
304
304
|
const started = Date.now();
|
|
305
|
-
const
|
|
305
|
+
const masks: [number, number] = port === 1 ? [mask, 0] : [0, mask];
|
|
306
|
+
const joy = masks.join(" ");
|
|
306
307
|
if (joy !== sent) {
|
|
307
|
-
await core.
|
|
308
|
+
await core.joy(...masks);
|
|
308
309
|
sent = joy;
|
|
309
310
|
}
|
|
310
311
|
while (pending.length > 0 && phase === "playing") {
|
|
311
312
|
const next = pending.shift()!;
|
|
312
313
|
if (next !== RESTORE) {
|
|
313
|
-
await core.
|
|
314
|
+
await core.key(next.code, next.down);
|
|
314
315
|
continue;
|
|
315
316
|
}
|
|
316
317
|
const failed = await options.restore();
|
|
@@ -332,7 +333,7 @@ export async function play(core: Pick<C64RunSession, "command" | "status">, opti
|
|
|
332
333
|
await new Promise((resolve) => setTimeout(resolve, Math.max(0, FRAME_MS - (Date.now() - started))));
|
|
333
334
|
}
|
|
334
335
|
} finally {
|
|
335
|
-
await core.
|
|
336
|
+
await core.joy(0, 0);
|
|
336
337
|
for (const viewer of viewers) viewer.end();
|
|
337
338
|
await new Promise((resolve) => server.close(resolve));
|
|
338
339
|
}
|
|
@@ -9,16 +9,19 @@
|
|
|
9
9
|
// state can be chosen at replay time, with the names that the knowledge has then.
|
|
10
10
|
|
|
11
11
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
12
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
12
13
|
|
|
13
14
|
import { Refusal } from "#src/errors.ts";
|
|
14
|
-
import { c64AddressOf, COVERAGE, formatC64Address, hexWord, parseC64Address } from "#src/c64.ts";
|
|
15
|
+
import { type AddressRange, c64AddressOf, COVERAGE, formatC64Address, formatC64RangeFields, hexWord, inRanges, parseC64Address, rangesWhere } from "#src/c64.ts";
|
|
15
16
|
import { keyTaps, type KeyTap } from "#src/c64-keys.ts";
|
|
16
17
|
import { READY_FRAMES } from "#src/host-client/entry-state.ts";
|
|
17
18
|
import { ACTION_STEP_KINDS, checkActionStep, keyboardBytes, stepKind, type ActionStep, type Location } from "#src/host-client/steps.ts";
|
|
18
19
|
import { isInteger, isObject } from "#src/host-client/tools.ts";
|
|
19
20
|
import { readProjectFile, readProjectJson, type Written } from "#src/host-client/transfer.ts";
|
|
21
|
+
import { entryMemory, programImage } from "#src/knowledge/program.ts";
|
|
20
22
|
import { RECORDING_FILES } from "#src/knowledge/recording-files.ts";
|
|
21
23
|
import { LOADER_JUMP, startScreenLabels } from "#src/knowledge/start-screen.ts";
|
|
24
|
+
import { refuseAbsoluteInFile } from "#src/project.ts";
|
|
22
25
|
import { sha256 } from "#src/knowledge/text.ts";
|
|
23
26
|
import { PAL_FRAME_CYCLES, type C64RunSession, type CoreStatus } from "#src/native/c64run.ts";
|
|
24
27
|
import type { Workspace } from "#src/native/staging.ts";
|
|
@@ -135,6 +138,18 @@ export interface Recording {
|
|
|
135
138
|
/** The cycles of the session, and the state hash at its end (RAM from $0002 and colour RAM). */
|
|
136
139
|
ticks: number;
|
|
137
140
|
hash: string;
|
|
141
|
+
/**
|
|
142
|
+
* The cycles of the input (see trackInput): keys down, a joystick that is not centered, typed keys in the queue,
|
|
143
|
+
* and each press step to the end of its frames. None without input.
|
|
144
|
+
*/
|
|
145
|
+
input?: TickSpan[];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** The cycles from `from` up to `to`. `typed`: the keys of a type step, which are input only while the KERNAL queue holds keys. */
|
|
149
|
+
export interface TickSpan {
|
|
150
|
+
from: number;
|
|
151
|
+
to: number;
|
|
152
|
+
typed?: true;
|
|
138
153
|
}
|
|
139
154
|
|
|
140
155
|
/** Steps that are input or time: the replay gives the program the reads that they caused, and does not do them again. */
|
|
@@ -144,8 +159,10 @@ const QUEUE = 0x0277;
|
|
|
144
159
|
const QUEUE_LENGTH = 0x00c6;
|
|
145
160
|
const QUEUE_SIZE = 10;
|
|
146
161
|
|
|
147
|
-
/** The key code of the replay core for a matrix place: 80 + the place.
|
|
148
|
-
const coreKey = (place: number) =>
|
|
162
|
+
/** The key code of the replay core for a matrix place: 80 + the place. */
|
|
163
|
+
const coreKey = (place: number) => 0x80 + place;
|
|
164
|
+
/** The key code of RESTORE in the replay core. */
|
|
165
|
+
const RESTORE_KEY = 0xff;
|
|
149
166
|
|
|
150
167
|
/** The joystick mask of the replay core: 1 up, 2 down, 4 left, 8 right, $10 fire. */
|
|
151
168
|
export function joystickMask(direction: Extract<ActionStep, { joystick: unknown }>["joystick"]["direction"], fire: boolean): number {
|
|
@@ -197,6 +214,8 @@ export function readRecordFile(path: string): RecordFile {
|
|
|
197
214
|
if (typeof value.name !== "string" || value.name === "") fail("name must be a short text");
|
|
198
215
|
if (typeof value.program !== "string" || value.program === "") fail("program must be a PRG file in the project");
|
|
199
216
|
if (value.symbols !== undefined && typeof value.symbols !== "string") fail('symbols must be "knowledge", "none" or a JSON file');
|
|
217
|
+
refuseAbsoluteInFile(value.program, "program", fail);
|
|
218
|
+
refuseAbsoluteInFile(value.symbols, "symbols", fail);
|
|
200
219
|
if (value.load !== undefined && typeof value.load !== "boolean") fail("load must be true or false");
|
|
201
220
|
if ((value.checkpoint === undefined) !== (value.state === undefined)) fail("give checkpoint and state together, or neither: a replay can give them");
|
|
202
221
|
if (value.checkpoint !== undefined && (typeof value.checkpoint !== "string" || value.checkpoint === "")) fail("checkpoint must be the name or $ address of a routine");
|
|
@@ -263,6 +282,8 @@ export function readRecording(folder: string): Recording {
|
|
|
263
282
|
if (!isObject(value) || value.format !== RECORDING_FORMAT) return fail(`it is not a recording of format ${RECORDING_FORMAT}`);
|
|
264
283
|
for (const key of ["name", "program", "sha256", "symbols", "hash"]) if (typeof value[key] !== "string") fail(`${key} is missing`);
|
|
265
284
|
for (const key of ["inputs", "events", "sites"]) if (!Array.isArray(value[key])) fail(`${key} is missing`);
|
|
285
|
+
refuseAbsoluteInFile(value.program, "program", fail);
|
|
286
|
+
refuseAbsoluteInFile(value.symbols, "symbols", fail);
|
|
266
287
|
if (!isInteger(value.ticks, 1, Number.MAX_SAFE_INTEGER)) fail("ticks is missing");
|
|
267
288
|
// A recording that does not check is refused, never replayed wrong.
|
|
268
289
|
const remedy = "Record the session again with record";
|
|
@@ -273,6 +294,9 @@ export function readRecording(folder: string): Recording {
|
|
|
273
294
|
checkState(compare.state, where);
|
|
274
295
|
if (compare.pin !== undefined) checkState(compare.pin, where, "pin");
|
|
275
296
|
}
|
|
297
|
+
if (value.input !== undefined && (!Array.isArray(value.input) || !value.input.every((span) => isObject(span) && isInteger(span.from, 0, Number.MAX_SAFE_INTEGER) && isInteger(span.to, 0, Number.MAX_SAFE_INTEGER) && (span.typed === undefined || span.typed === true)))) {
|
|
298
|
+
fail(`input must be a list of { from, to } cycles. ${remedy}`);
|
|
299
|
+
}
|
|
276
300
|
(value.events as unknown[]).forEach((event, index) => {
|
|
277
301
|
const at = `event ${index + 1}`;
|
|
278
302
|
const where = (message: string): never => fail(`${message}. ${remedy}`);
|
|
@@ -338,8 +362,15 @@ export function siteMap(sites: RecordedSite[], from: Map<string, number>, to: Ma
|
|
|
338
362
|
return moved;
|
|
339
363
|
}
|
|
340
364
|
|
|
365
|
+
/** Pages 0-3 of RAM and the stack pointer of a program at its entry. */
|
|
366
|
+
export interface EntryRam {
|
|
367
|
+
sp: number;
|
|
368
|
+
/** $0000-$03ff. */
|
|
369
|
+
ram: Uint8Array;
|
|
370
|
+
}
|
|
371
|
+
|
|
341
372
|
/** Where the reference came to the entry that the loader of a rebuild jumps to. */
|
|
342
|
-
export interface EntryPoint {
|
|
373
|
+
export interface EntryPoint extends EntryRam {
|
|
343
374
|
/** The tick of the first opcode fetch at the entry. */
|
|
344
375
|
tick: number;
|
|
345
376
|
/**
|
|
@@ -365,6 +396,12 @@ async function markEntry(core: C64RunSession, entry: number) {
|
|
|
365
396
|
const answer = /tick=(\d+) phase=([0-9a-f]+)/.exec(await core.command("marked"));
|
|
366
397
|
return answer === null ? undefined : { tick: Number(answer[1]), phase: answer[2]! };
|
|
367
398
|
};
|
|
399
|
+
/** Pages 0-3 and the stack pointer at the mark, which came. */
|
|
400
|
+
const memory = async (): Promise<EntryRam> => {
|
|
401
|
+
const answer = /s=([0-9a-f]{2}) ram=([0-9a-f]{2048})/.exec(await core.command("marked-ram"));
|
|
402
|
+
if (answer === null) throw new Refusal("operation-failed", "c64run marked-ram gave no memory at the mark");
|
|
403
|
+
return { sp: Number.parseInt(answer[1]!, 16), ram: Uint8Array.from(Buffer.from(answer[2]!, "hex")) };
|
|
404
|
+
};
|
|
368
405
|
let came: { tick: number; phase: string } | undefined;
|
|
369
406
|
let eventsBefore = 0;
|
|
370
407
|
return {
|
|
@@ -374,10 +411,10 @@ async function markEntry(core: C64RunSession, entry: number) {
|
|
|
374
411
|
came = await marked();
|
|
375
412
|
if (came === undefined) eventsBefore = index + 1;
|
|
376
413
|
},
|
|
377
|
-
/** Where the program came to the entry, or undefined when it did not come to it. */
|
|
378
|
-
async end(): Promise<{ tick: number; phase: string; eventsBefore: number } | undefined> {
|
|
414
|
+
/** Where the program came to the entry, with its memory there, or undefined when it did not come to it. */
|
|
415
|
+
async end(): Promise<({ tick: number; phase: string; eventsBefore: number } & EntryRam) | undefined> {
|
|
379
416
|
came ??= await marked();
|
|
380
|
-
return came === undefined ? undefined : { ...came, eventsBefore };
|
|
417
|
+
return came === undefined ? undefined : { ...came, eventsBefore, ...(await memory()) };
|
|
381
418
|
},
|
|
382
419
|
};
|
|
383
420
|
}
|
|
@@ -393,6 +430,137 @@ export function eventBeforeEntry(events: readonly RecordedEvent[], eventsBefore:
|
|
|
393
430
|
return `${what} ran before the program came to its entry ${formatC64Address(entry)}. A rebuild with a loader has no point for it. Make the steps of the record file start after the entry`;
|
|
394
431
|
}
|
|
395
432
|
|
|
433
|
+
/** The memory that the loader of a rebuild writes at an entry: $0002-$03ff of the program of the knowledge at its entry, and its stack pointer. */
|
|
434
|
+
export interface LoaderEntryState {
|
|
435
|
+
sp: number;
|
|
436
|
+
/** The parts of $0002-$03ff that the loader writes. */
|
|
437
|
+
written: AddressRange[];
|
|
438
|
+
byteAt: (address: number) => number;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** Pages 0-3 without the CPU port: the memory of the entry state check. */
|
|
442
|
+
const LOW_PAGES: AddressRange = { start: 0x0002, end: 0x03ff };
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* The entry state of the knowledge at `entry`, as the loader of a rebuild writes it ($0002-$03ff: the segments there,
|
|
446
|
+
* and the pages that the entry state has). Undefined when the knowledge has no entry state, one at another entry, one
|
|
447
|
+
* without a stack pointer, or when the loader writes nothing of $0002-$03ff.
|
|
448
|
+
*/
|
|
449
|
+
export function loaderEntryState(db: DatabaseSync | undefined, entry: number): LoaderEntryState | undefined {
|
|
450
|
+
const image = programImage(db);
|
|
451
|
+
if (image?.state === undefined || image.entry !== entry) return undefined;
|
|
452
|
+
const sp = isObject(image.state.registers) ? image.state.registers.sp : undefined;
|
|
453
|
+
if (!isInteger(sp, 0, 0xff)) return undefined;
|
|
454
|
+
const memory = entryMemory(image);
|
|
455
|
+
const written = memory.segments.flatMap((segment) => (segment.end < LOW_PAGES.start || segment.start > LOW_PAGES.end ? [] : [{ start: Math.max(segment.start, LOW_PAGES.start), end: Math.min(segment.end, LOW_PAGES.end) }]));
|
|
456
|
+
return written.length === 0 ? undefined : { sp, written, byteAt: memory.byteAt };
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* The bytes that the entry state check does not compare: the bytes of the KERNAL that its interrupt and its screen
|
|
461
|
+
* editor change by time alone, and the bytes that the start of the program sets in another way in the emulator of a
|
|
462
|
+
* capture than in the replay core. These bytes differ also with the same input, and no new capture makes them the
|
|
463
|
+
* same. The bytes of the keyboard scan ($91, $c5, $cb, $f5/$f6, $028b/$028c) change with the input, and the check
|
|
464
|
+
* compares them.
|
|
465
|
+
*/
|
|
466
|
+
const UNCOMPARED_BYTES: readonly AddressRange[] = [
|
|
467
|
+
// The jiffy clock: each interrupt counts it up.
|
|
468
|
+
{ start: 0x00a0, end: 0x00a2 },
|
|
469
|
+
// The load of the emulator sets them to the start of the BASIC text; the start of the replay core puts the program into RAM without them.
|
|
470
|
+
{ start: 0x00ac, end: 0x00ad },
|
|
471
|
+
// $cd: the interrupts to the next blink of the cursor. $ce: the character under the cursor at the last blink.
|
|
472
|
+
// $cf: the blink phase. A key that the editor takes ends the blink at the phase that the time gave.
|
|
473
|
+
{ start: 0x00cd, end: 0x00cf },
|
|
474
|
+
// The colour under the cursor at the last blink.
|
|
475
|
+
{ start: 0x0287, end: 0x0287 },
|
|
476
|
+
];
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Where a program at its entry differs from the entry state that the loader of a rebuild writes: the ranges of $0002-$03ff
|
|
480
|
+
* with other bytes. The free part of the stack page, from $0100 up to the stack pointer of either state, holds no state,
|
|
481
|
+
* and the bytes of UNCOMPARED_BYTES are not compared.
|
|
482
|
+
*/
|
|
483
|
+
export function entryStateDiffers(program: EntryRam, loader: LoaderEntryState): AddressRange[] {
|
|
484
|
+
const free = 0x0100 + Math.max(program.sp, loader.sp);
|
|
485
|
+
const compared = (address: number) => inRanges(loader.written, address) && (address < 0x0100 || address > free) && !inRanges(UNCOMPARED_BYTES, address);
|
|
486
|
+
return rangesWhere((address) => compared(address) && program.ram[address] !== loader.byteAt(address));
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* The spans of the input of a session: from the input that starts while no input is held to the end of the last one.
|
|
491
|
+
* Input is a key down (a press step, the play, RESTORE) and a joystick that is not centered (a joystick step, the
|
|
492
|
+
* play): the key() and joy() of the core report each one with its tick. `typed` starts a typed span for the keys of a
|
|
493
|
+
* type step, and `settle` ends it when the KERNAL queue is empty; it can end late, so the queue at the entry decides
|
|
494
|
+
* (entryStateCheck). `cover` makes the key spans from `from` on one span up to `to`, for the frames of a step. `spans`
|
|
495
|
+
* closes a span that is still open at `end`, and ends the tracking.
|
|
496
|
+
*/
|
|
497
|
+
export function trackInput(core: Pick<C64RunSession, "onInput" | "peek" | "status">): {
|
|
498
|
+
typed: (tick: number) => void;
|
|
499
|
+
settle: () => Promise<void>;
|
|
500
|
+
cover: (from: number, to: number) => void;
|
|
501
|
+
spans: (end: number) => TickSpan[];
|
|
502
|
+
} {
|
|
503
|
+
const down = new Set<number>();
|
|
504
|
+
let joystick = false;
|
|
505
|
+
const spans: TickSpan[] = [];
|
|
506
|
+
const typedSpans: TickSpan[] = [];
|
|
507
|
+
let typedFrom: number | undefined;
|
|
508
|
+
let since: number | undefined;
|
|
509
|
+
const held = () => down.size > 0 || joystick;
|
|
510
|
+
const change = (tick: number, update: () => void) => {
|
|
511
|
+
const before = held();
|
|
512
|
+
update();
|
|
513
|
+
if (!before && held()) since = tick;
|
|
514
|
+
else if (before && !held()) {
|
|
515
|
+
spans.push({ from: since!, to: tick });
|
|
516
|
+
since = undefined;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
core.onInput((input, tick) =>
|
|
520
|
+
change(tick, () => {
|
|
521
|
+
if (input.kind === "joy") joystick = input.masks.some((mask) => mask !== 0);
|
|
522
|
+
else if (input.down) down.add(input.code);
|
|
523
|
+
else down.delete(input.code);
|
|
524
|
+
}),
|
|
525
|
+
);
|
|
526
|
+
const settle = async () => {
|
|
527
|
+
if (typedFrom === undefined || (await core.peek(QUEUE_LENGTH, 1))[0] !== 0) return;
|
|
528
|
+
typedSpans.push({ from: typedFrom, to: (await core.status("status")).tick, typed: true });
|
|
529
|
+
typedFrom = undefined;
|
|
530
|
+
};
|
|
531
|
+
const cover = (from: number, to: number) => {
|
|
532
|
+
const later = spans.filter((span) => span.from >= from);
|
|
533
|
+
const earlier = spans.filter((span) => span.from < from);
|
|
534
|
+
// An input that is still held (a joystick) carries the step: its open span starts at the step.
|
|
535
|
+
if (since !== undefined) since = Math.min(since, from);
|
|
536
|
+
else if (later.length > 0) earlier.push({ from, to: Math.max(to, ...later.map((span) => span.to)) });
|
|
537
|
+
else return;
|
|
538
|
+
spans.splice(0, spans.length, ...earlier);
|
|
539
|
+
};
|
|
540
|
+
const end = (at: number) => {
|
|
541
|
+
core.onInput(undefined);
|
|
542
|
+
const open = [...(since === undefined ? [] : [{ from: since, to: at }]), ...(typedFrom === undefined ? [] : [{ from: typedFrom, to: at, typed: true as const }])];
|
|
543
|
+
return [...spans, ...typedSpans, ...open].sort((a, b) => a.from - b.from);
|
|
544
|
+
};
|
|
545
|
+
return { typed: (tick) => (typedFrom ??= tick), settle, cover, spans: end };
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** The note in place of the entry state check when the program came to its entry during the input. */
|
|
549
|
+
export const ENTRY_DURING_INPUT = "not compared: the program came to its entry during the input of the session";
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* The entry state check of a program at its entry (`tick`) against the entry state that the loader writes: the
|
|
553
|
+
* differing ranges, or nothing when all bytes are the same. A capture stops at the first arrival after its steps, so
|
|
554
|
+
* at an entry during the input (`input`) it holds a later state, which no new capture changes: then only the note.
|
|
555
|
+
* A typed span counts only when the KERNAL queue at the entry still holds keys.
|
|
556
|
+
*/
|
|
557
|
+
export function entryStateCheck(program: EntryRam & { tick: number }, input: readonly TickSpan[], loader: LoaderEntryState): { entryStateDiffers?: Array<{ start: string; end: string }>; entryState?: string } {
|
|
558
|
+
const during = (span: TickSpan) => program.tick >= span.from && program.tick < span.to && (span.typed !== true || program.ram[QUEUE_LENGTH] !== 0);
|
|
559
|
+
if (input.some(during)) return { entryState: ENTRY_DURING_INPUT };
|
|
560
|
+
const differs = entryStateDiffers(program, loader);
|
|
561
|
+
return differs.length === 0 ? {} : { entryStateDiffers: differs.map(formatC64RangeFields) };
|
|
562
|
+
}
|
|
563
|
+
|
|
396
564
|
/**
|
|
397
565
|
* A loader with a start screen that RUN starts waits for a key or a fire button that the recording does not have:
|
|
398
566
|
* the rebuild goes on after the wait, as the check of the loader does. Gives the tick of the wait, a problem, or
|
|
@@ -490,9 +658,9 @@ async function doAction(core: C64RunSession, step: ActionStep | RestoreAction, a
|
|
|
490
658
|
if ("restore" in step) {
|
|
491
659
|
// The NMI line is low while RESTORE is down: hold it as a press step holds a key.
|
|
492
660
|
const tick = (await core.status("status")).tick;
|
|
493
|
-
await core.
|
|
661
|
+
await core.key(RESTORE_KEY, true);
|
|
494
662
|
await core.status("run " + (tick + KEY_FRAMES * PAL_FRAME_CYCLES));
|
|
495
|
-
await core.
|
|
663
|
+
await core.key(RESTORE_KEY, false);
|
|
496
664
|
} else if ("write" in step) {
|
|
497
665
|
await core.write(at.data(step.write.address), Buffer.from(step.write.data, "hex"));
|
|
498
666
|
} else if ("type" in step) {
|
|
@@ -542,6 +710,8 @@ export interface RecordOutcome {
|
|
|
542
710
|
reason?: string;
|
|
543
711
|
/** With an entry: why a rebuild with a loader cannot replay the recording, as replay finds it on the reference. */
|
|
544
712
|
loaderProblem?: string;
|
|
713
|
+
/** With an entry that the program came to: its pages 0-3 and its stack pointer there, and the cycle of its arrival. */
|
|
714
|
+
entryRam?: EntryRam & { tick: number };
|
|
545
715
|
}
|
|
546
716
|
|
|
547
717
|
/**
|
|
@@ -559,6 +729,23 @@ export async function record(
|
|
|
559
729
|
input?: (core: C64RunSession, restore: () => Promise<string | undefined>) => Promise<string | undefined>,
|
|
560
730
|
entry?: number,
|
|
561
731
|
): Promise<RecordOutcome> {
|
|
732
|
+
try {
|
|
733
|
+
return await recordSession(core, file, workspace, input, entry);
|
|
734
|
+
} finally {
|
|
735
|
+
// The input listener of the session ends with the record, also when the record fails.
|
|
736
|
+
core.onInput(undefined);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
async function recordSession(
|
|
741
|
+
core: C64RunSession,
|
|
742
|
+
file: RecordFile,
|
|
743
|
+
workspace: Workspace,
|
|
744
|
+
input: Parameters<typeof record>[3],
|
|
745
|
+
entry: number | undefined,
|
|
746
|
+
): Promise<RecordOutcome> {
|
|
747
|
+
// Every key and joystick goes through key() and joy() of the core: the steps, the play and a RESTORE.
|
|
748
|
+
const tracked = trackInput(core);
|
|
562
749
|
const prg = readProjectFile(file.program).bytes;
|
|
563
750
|
const same = (address: number) => address;
|
|
564
751
|
const at = sideAddresses(namesOf(file.symbols), "reference", { code: same, data: same });
|
|
@@ -619,32 +806,38 @@ export async function record(
|
|
|
619
806
|
await core.status(`run ${tick + step.frames * PAL_FRAME_CYCLES}`);
|
|
620
807
|
} else if ("joystick" in step) {
|
|
621
808
|
masks[step.joystick.port - 1] = joystickMask(step.joystick.direction, step.joystick.fire ?? false);
|
|
622
|
-
await core.
|
|
809
|
+
await core.joy(masks[0]!, masks[1]!);
|
|
623
810
|
} else if ("press" in step) {
|
|
624
811
|
const hold = step.press.frames * PAL_FRAME_CYCLES;
|
|
812
|
+
const start = tick;
|
|
625
813
|
for (const tap of keyTaps(step.press.keys) as KeyTap[]) {
|
|
626
|
-
for (const place of tap.keys) await core.
|
|
814
|
+
for (const place of tap.keys) await core.key(coreKey(place), true);
|
|
627
815
|
// RESTORE is no read: an event at the next read of the program, with the keys of the tap down.
|
|
628
816
|
if (tap.restore) reason = await runEvent({ restore: true }, index + 1);
|
|
629
817
|
if (reason !== undefined) break;
|
|
630
818
|
tick = (await core.status("status")).tick;
|
|
631
819
|
await core.status(`run ${(tick += hold)}`);
|
|
632
|
-
for (const place of tap.keys) await core.
|
|
820
|
+
for (const place of tap.keys) await core.key(coreKey(place), false);
|
|
633
821
|
await core.status(`run ${(tick += hold)}`);
|
|
634
822
|
// Frames ran: the next RESTORE is no event right after an event.
|
|
635
823
|
afterEvent = false;
|
|
636
824
|
}
|
|
825
|
+
// A press step is key input to the end of its frames, as the steps of a capture end there.
|
|
826
|
+
tracked.cover(start, (await core.status("status")).tick);
|
|
637
827
|
if (reason !== undefined) {
|
|
638
828
|
reason = `step ${index + 1}: RESTORE: ${reason}`;
|
|
639
829
|
break;
|
|
640
830
|
}
|
|
641
831
|
} else {
|
|
642
832
|
reason = await runEvent(step, index + 1);
|
|
833
|
+
// The keys of a type step are input from the start of the step until the KERNAL took them from its queue.
|
|
834
|
+
if ("type" in step && reason === undefined) tracked.typed(tick);
|
|
643
835
|
if (reason !== undefined) {
|
|
644
836
|
reason = `step ${index + 1}: ${reason}`;
|
|
645
837
|
break;
|
|
646
838
|
}
|
|
647
839
|
}
|
|
840
|
+
await tracked.settle();
|
|
648
841
|
afterEvent = event;
|
|
649
842
|
}
|
|
650
843
|
// The play runs frames before each RESTORE: a RESTORE never runs where an event of the steps ended.
|
|
@@ -662,6 +855,8 @@ export async function record(
|
|
|
662
855
|
? `the program did not come to its entry ${formatC64Address(entry)} in the session, where the loader of a rebuild jumps. Make the session go on until the program runs from its entry`
|
|
663
856
|
: eventBeforeEntry(events, came.eventsBefore, entry);
|
|
664
857
|
const end = await core.status("status");
|
|
858
|
+
await tracked.settle();
|
|
859
|
+
const spans = tracked.spans(end.tick);
|
|
665
860
|
const sites = (await core.command("sites")).split(" ").slice(2).map((entry): RecordedSite => {
|
|
666
861
|
const [where, reads, kind] = entry.split(":");
|
|
667
862
|
const [site, addr] = where!.split("/");
|
|
@@ -683,6 +878,7 @@ export async function record(
|
|
|
683
878
|
sites,
|
|
684
879
|
ticks: end.tick,
|
|
685
880
|
hash: end.hash,
|
|
881
|
+
...(spans.length === 0 ? {} : { input: spans }),
|
|
686
882
|
};
|
|
687
883
|
return {
|
|
688
884
|
recording,
|
|
@@ -691,6 +887,7 @@ export async function record(
|
|
|
691
887
|
...(from === null ? {} : { coverageFrom: { tick: Number(from[1]), pc: Number.parseInt(from[2]!, 16) } }),
|
|
692
888
|
...(reason === undefined ? {} : { reason }),
|
|
693
889
|
...(loaderProblem === undefined ? {} : { loaderProblem }),
|
|
890
|
+
...(came === undefined ? {} : { entryRam: { sp: came.sp, ram: came.ram, tick: came.tick } }),
|
|
694
891
|
};
|
|
695
892
|
}
|
|
696
893
|
|
|
@@ -710,6 +907,8 @@ export interface SideRun {
|
|
|
710
907
|
problem?: string;
|
|
711
908
|
/** True when the rebuild went on after the wait of its start screen. */
|
|
712
909
|
startScreenSkipped?: boolean;
|
|
910
|
+
/** The rebuild with a `handover`: its pages 0-3 and its stack pointer at its entry, as its loader left them. */
|
|
911
|
+
entryRam?: EntryRam;
|
|
713
912
|
/** The reference with an `entry`: where it came to that entry, when it came to it. */
|
|
714
913
|
entryPoint?: EntryPoint;
|
|
715
914
|
/**
|
|
@@ -795,6 +994,7 @@ export async function replaySide(
|
|
|
795
994
|
// A pc key counts the opcode fetches from the start, also those of the code before the entry: the unpacker of
|
|
796
995
|
// the reference, or the loader of the rebuild. The rebuild counts again from the jump of its loader, without those of the reference.
|
|
797
996
|
const { handover } = options;
|
|
997
|
+
let entryRam: EntryRam | undefined;
|
|
798
998
|
if (problem === undefined && handover !== undefined) {
|
|
799
999
|
const jump = own.get(LOADER_JUMP)!;
|
|
800
1000
|
if ((await core.status(`run-pc ${hexWord(jump)} ${limit}`)).word !== "reached") problem = `the rebuild did not come to the jump of its loader at ${formatC64Address(jump)}`;
|
|
@@ -803,6 +1003,7 @@ export async function replaySide(
|
|
|
803
1003
|
const reached = await core.status(`run-pc ${hexWord(handover.entry)} ${limit}`);
|
|
804
1004
|
if (reached.word !== "reached") problem = `the rebuild did not come to its entry at ${formatC64Address(handover.entry)}`;
|
|
805
1005
|
else {
|
|
1006
|
+
entryRam = { sp: reached.s, ram: await core.peek(0, 0x400) };
|
|
806
1007
|
// The loader sets the entry state of the capture, but the phase of the frame and of the CIA timers at the entry
|
|
807
1008
|
// depends on how the reference started: the rebuild waits at its entry for the beam position of the reference, and
|
|
808
1009
|
// gets its CIA timers and interrupt state there. A program that starts its timers without a load keeps that phase.
|
|
@@ -870,6 +1071,7 @@ export async function replaySide(
|
|
|
870
1071
|
...(problem === undefined ? {} : { problem }),
|
|
871
1072
|
...(screenSkipped ? { startScreenSkipped: true } : {}),
|
|
872
1073
|
...(entryPoint === undefined ? {} : { entryPoint }),
|
|
1074
|
+
...(entryRam === undefined ? {} : { entryRam }),
|
|
873
1075
|
...(ram === undefined ? {} : { ram }),
|
|
874
1076
|
};
|
|
875
1077
|
}
|
|
@@ -920,6 +1122,10 @@ export interface ReplayResult {
|
|
|
920
1122
|
movedSites?: number;
|
|
921
1123
|
/** Input reads of the rebuild that the recording had no value for: they got the idle value. */
|
|
922
1124
|
idleReads?: number;
|
|
1125
|
+
/** A rebuild with a loader: where the reference at its entry differs from the entry state that the loader writes. */
|
|
1126
|
+
entryStateDiffers?: Array<{ start: string; end: string }>;
|
|
1127
|
+
/** A rebuild with a loader: why the entry state is not compared. */
|
|
1128
|
+
entryState?: string;
|
|
923
1129
|
files?: Written[];
|
|
924
1130
|
/** The screen of the reference at the end of the session (--screen). */
|
|
925
1131
|
screen?: Written;
|