@henols/c64-re-tools 2.6.0-rc.9 → 2.6.0

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.
Files changed (68) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +3 -3
  3. package/skills/c64-assembler/scripts/assembler.ts +4 -3
  4. package/skills/c64-development/SKILL.md +3 -3
  5. package/skills/c64-docs/SKILL.md +5 -3
  6. package/skills/c64-docs/scripts/docs.ts +17 -4
  7. package/skills/c64-docs/scripts/lib/reference.ts +117 -31
  8. package/skills/c64-docs/scripts/lib/source-map.ts +14 -0
  9. package/skills/c64-knowledge/SKILL.md +8 -7
  10. package/skills/c64-knowledge/scripts/knowledge.ts +16 -9
  11. package/skills/c64-reverse-engineering/SKILL.md +9 -3
  12. package/skills/c64-source/SKILL.md +11 -8
  13. package/skills/c64-source/scripts/lib/export.ts +13 -2
  14. package/skills/c64-source/scripts/lib/loader.ts +51 -28
  15. package/skills/c64-source/scripts/lib/source.ts +24 -17
  16. package/skills/c64-source/scripts/source.ts +51 -36
  17. package/skills/c64-static-analysis/SKILL.md +23 -21
  18. package/skills/c64-static-analysis/scripts/lib/findings.ts +11 -11
  19. package/skills/c64-static-analysis/scripts/lib/instructions.ts +4 -4
  20. package/skills/c64-static-analysis/scripts/lib/macros.ts +3 -1
  21. package/skills/c64-static-analysis/scripts/static-analysis.ts +36 -27
  22. package/skills/c64-testing/SKILL.md +10 -3
  23. package/skills/c64-testing/references/recording-format.md +8 -2
  24. package/skills/c64-testing/references/scenario-format.md +4 -2
  25. package/skills/c64-testing/scripts/lib/recording.ts +193 -28
  26. package/skills/c64-testing/scripts/lib/replay.ts +31 -5
  27. package/skills/c64-testing/scripts/lib/runs.ts +7 -2
  28. package/skills/c64-testing/scripts/lib/scenario.ts +3 -3
  29. package/skills/c64-testing/scripts/testing.ts +23 -2
  30. package/skills/c64-unpacker/SKILL.md +4 -2
  31. package/skills/c64-unpacker/scripts/lib/stages.ts +18 -3
  32. package/skills/c64-unpacker/scripts/unpacker.ts +38 -6
  33. package/src/build-name.ts +9 -4
  34. package/src/c64.ts +1 -1
  35. package/src/host/main.ts +2 -2
  36. package/src/host/server.ts +3 -1
  37. package/src/host/tools/index.ts +1 -1
  38. package/src/host/vice/process.ts +34 -17
  39. package/src/host/vice/session.ts +55 -27
  40. package/src/host-client/steps.ts +4 -1
  41. package/src/host-client/tools.ts +1 -1
  42. package/src/knowledge/evidence.ts +66 -0
  43. package/src/knowledge/history.ts +5 -5
  44. package/src/knowledge/import.ts +12 -5
  45. package/src/knowledge/program.ts +81 -33
  46. package/src/knowledge/read.ts +3 -3
  47. package/src/knowledge/schema.ts +7 -7
  48. package/src/knowledge/start-screen.ts +2 -0
  49. package/src/knowledge/text.ts +28 -3
  50. package/src/knowledge/write.ts +6 -6
  51. package/src/mcp/tools/debug.ts +23 -21
  52. package/src/mcp/tools/memory.ts +12 -9
  53. package/src/native/c64run.ts +7 -4
  54. package/src/native/{ghidra → decompiler}/analyze.ts +17 -17
  55. package/src/native/{ghidra → decompiler}/language/c64rt_6510.slaspec +1 -1
  56. package/src/native/{ghidra → decompiler}/walk.ts +6 -6
  57. package/src/native/types.ts +25 -25
  58. package/src/opcodes.ts +1 -1
  59. package/src/reference-pages.ts +64 -0
  60. package/src/script.ts +1 -1
  61. package/tools/c64run.c +150 -4
  62. /package/src/native/{ghidra → decompiler}/c64rt-wasm.ts +0 -0
  63. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.cspec +0 -0
  64. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.ldefs +0 -0
  65. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.pspec +0 -0
  66. /package/src/native/{ghidra → decompiler}/language/c64rt_6510.sla +0 -0
  67. /package/src/native/{ghidra → decompiler}/pcode.ts +0 -0
  68. /package/src/native/{ghidra → decompiler}/wasm.ts +0 -0
@@ -1,5 +1,5 @@
1
1
  // The c64-static-analysis script: analyzes the program in the knowledge
2
- // with DXA (fast first pass) or Ghidra (deeper), which it runs itself, seeded
2
+ // with DXA (fast first pass) or the decompiler (deeper), which it runs itself, seeded
3
3
  // from current knowledge and the coverage of the knowledge, and imports the
4
4
  // structural findings into .c64-re-tools/knowledge/.
5
5
 
@@ -9,19 +9,19 @@ import { WireFailure } from "#src/host-client/tools.ts";
9
9
  import { writeReported } from "#src/host-client/transfer.ts";
10
10
  import { knowledgeNames } from "#src/knowledge/names.ts";
11
11
  import { analyze as analyzeWithDxa } from "#src/native/dxa.ts";
12
- import { analyze as analyzeWithGhidra } from "#src/native/ghidra/analyze.ts";
12
+ import { analyze as analyzeWithDecompiler } from "#src/native/decompiler/analyze.ts";
13
13
  import { localToolContext } from "#src/native/local.ts";
14
- import { GHIDRA_LIMITS } from "#src/native/types.ts";
14
+ import { DECOMPILER_LIMITS } from "#src/native/types.ts";
15
15
  import { openForRead, withWrite } from "#src/knowledge/database.ts";
16
16
  import { analyzedBytes, operandImages, programCoverage, requireProgram } from "#src/knowledge/program.ts";
17
17
  import { applyBatch, type BatchOperation } from "#src/knowledge/write.ts";
18
- import { importFindings, runProvenance, type ImportConflict, type ImportContext, type ImportResult, type NormalizedFindings } from "#src/knowledge/import.ts";
18
+ import { importFindings, lastToolVersion, runProvenance, type ImportConflict, type ImportContext, type ImportResult, type NormalizedFindings } from "#src/knowledge/import.ts";
19
19
  import { currentRevision, listMacros, listMacroUses, listPatches, listReferences, listRegions, listSymbols } from "#src/knowledge/read.ts";
20
20
  import { DEFAULT_SPACE, SEMANTIC_ORIGINS, type Analyzer } from "#src/knowledge/schema.ts";
21
21
  import { platformNames, platformNamesFor, romUseOfProgram, type RomUse } from "#src/platform.ts";
22
22
  import { listed, OPTIONS, reply, runScript, UsageError, type Call } from "#src/script.ts";
23
23
  import { codeEntries, coverageConflicts, coverageEntries, coverageSeedKinds, executedStarts, imageReader, romOnlyRanges, type ImageByte } from "./lib/coverage.ts";
24
- import { dxaFindings, ghidraFindings, seedsFromKnowledge } from "./lib/findings.ts";
24
+ import { dxaFindings, decompilerFindings, seedsFromKnowledge } from "./lib/findings.ts";
25
25
  import { findIdioms } from "./lib/idioms.ts";
26
26
  import { instructionList } from "./lib/instructions.ts";
27
27
  import { CATALOGUE, findMacroUses, type MacroCandidate } from "./lib/macros.ts";
@@ -36,8 +36,13 @@ const ALL_NAMES = "a larger --max-listed. The project knowledge has all of them
36
36
  * analyzer data over executed code to classify, and macro candidates to write.
37
37
  * The envelope adds the sentence for a cut list.
38
38
  */
39
- function withHint(body: Record<string, unknown>, conflicts: number, coverageConflicts: number, macros: { candidates: number; applied: boolean; revision: string | null | undefined }) {
39
+ function withHint(body: Record<string, unknown>, conflicts: number, coverageConflicts: number, macros: { candidates: number; applied: boolean; revision: string | null | undefined }, version: { now: string | undefined; last: string | undefined; revision: string | null }, retiredReferences: number) {
40
40
  const hints: string[] = [];
41
+ if (version.revision !== null && version.now !== undefined && version.last !== undefined && version.now !== version.last) {
42
+ hints.push(`The last analysis of this program used ${version.last}. Thus a change in revision ${version.revision} can come from the new analyzer version, and not from the program or the project knowledge.`);
43
+ }
44
+ // A leftover is data that no reference reads: a retired reference can make one.
45
+ if (retiredReferences > 0) hints.push("The analysis retired references. A data range that only a retired reference used can be a leftover now. Generate the source again, and examine the leftovers that changed.");
41
46
  if (conflicts > 0) hints.push("The analysis and the project knowledge disagree at each place in conflicts. Find the correct answer in the emulator. Then correct the project knowledge.");
42
47
  if (coverageConflicts > 0) hints.push("The coverage shows executed code in each range of coverageConflicts. Classify each range as code, or as dual-use when its bytes are also data, in the project knowledge.");
43
48
  if (typeof macros.revision === "string") hints.push("The project knowledge has the macro candidates now. Generate the source again.");
@@ -175,15 +180,15 @@ async function analyze(call: Call): Promise<unknown> {
175
180
  const decompile = call.addresses("decompile");
176
181
  if (decompile.length > 32) throw new UsageError("--decompile takes at most 32 routines");
177
182
  const max = call.count("max-listed")!;
178
- const analyzer = call.string("analyzer") as "dxa" | "ghidra";
183
+ const analyzer = call.string("analyzer") as "dxa" | "decompiler";
179
184
  const listingPath = call.string("out-listing");
180
185
  const instructionsPath = call.string("out-instructions");
181
186
  const applyMacros = call.flag("apply-macros");
182
187
  const skip = new Set(call.addresses("skip"));
183
188
  if (skip.size > 0 && !applyMacros) throw new UsageError("--skip works only with --apply-macros: it names a macro candidate that the run does not write");
184
- if (analyzer === "dxa" && decompile.length > 0) throw new UsageError("--decompile works only with --analyzer ghidra");
185
- if (analyzer === "ghidra" && listingPath !== undefined) throw new UsageError("--out-listing works only with --analyzer dxa");
186
- if (analyzer === "dxa" && instructionsPath !== undefined) throw new UsageError("--out-instructions works only with --analyzer ghidra");
189
+ if (analyzer === "dxa" && decompile.length > 0) throw new UsageError("--decompile works only with --analyzer decompiler");
190
+ if (analyzer === "decompiler" && listingPath !== undefined) throw new UsageError("--out-listing works only with --analyzer dxa");
191
+ if (analyzer === "dxa" && instructionsPath !== undefined) throw new UsageError("--out-instructions works only with --analyzer decompiler");
187
192
  const space = call.space;
188
193
  const reader = openForRead();
189
194
  const program = requireProgram(reader, space);
@@ -203,25 +208,27 @@ async function analyze(call: Call): Promise<unknown> {
203
208
  const revision = currentRevision(reader);
204
209
  const seeds = seedsFromKnowledge(reader, entries, space, executed.executed);
205
210
  // Knowledge routines and --entry first, then code regions and JMP tables, then idioms, then coverage, up to the seed bound:
206
- // at most GHIDRA_LIMITS.entryPoints (1024) entry points for both analyzers, and for Ghidra at most
207
- // GHIDRA_LIMITS.codeStarts (8192) coverage flow starts that are code in a routine. coverageSeeds gives what was used.
211
+ // at most DECOMPILER_LIMITS.entryPoints (1024) entry points for both analyzers, and for the decompiler at most
212
+ // DECOMPILER_LIMITS.codeStarts (8192) coverage flow starts that are code in a routine. coverageSeeds gives what was used.
208
213
  const fromCoverage = coverage === undefined ? [] : coverageEntries(coverage, inProgram);
209
214
  const known = [...seeds.entryPoints, ...codeEntries(reader, byteAt, space)];
210
- // Ghidra takes the coverage as code starts without a function; DXA has one list.
215
+ // The decompiler takes the coverage as code starts without a function; DXA has one list.
211
216
  const kinds = analyzer === "dxa" || coverage === undefined ? { routines: fromCoverage, codeStarts: [] } : coverageSeedKinds(coverage, inProgram);
212
217
  const ordered = [...new Set([...known, ...idioms.entryPoints, ...kinds.routines])];
213
- seeds.entryPoints = ordered.slice(0, GHIDRA_LIMITS.entryPoints).sort((a, b) => a - b);
214
- const codeStarts = kinds.codeStarts.filter((entry) => !seeds.entryPoints.includes(entry)).slice(0, GHIDRA_LIMITS.codeStarts);
218
+ seeds.entryPoints = ordered.slice(0, DECOMPILER_LIMITS.entryPoints).sort((a, b) => a - b);
219
+ const codeStarts = kinds.codeStarts.filter((entry) => !seeds.entryPoints.includes(entry)).slice(0, DECOMPILER_LIMITS.codeStarts);
215
220
  // Idiom tables and the RAM under ROM that the runs never used are data for this run too; semantic data ranges come first.
216
221
  // A range with an entry point of the knowledge or --entry in it is left out: that code stays code.
217
222
  const fromRom = coverage === undefined ? [] : romOnlyRanges(coverage, byteAt).filter((range) => !known.some((entry) => entry >= range.start && entry <= range.end));
218
223
  const dataRanges = [...seeds.dataRanges];
219
224
  for (const range of [...idioms.dataRanges, ...fromRom]) if (!dataRanges.some((seed) => range.start <= seed.end && range.end >= seed.start)) dataRanges.push(range);
220
- seeds.dataRanges = dataRanges.slice(0, GHIDRA_LIMITS.dataRanges);
225
+ seeds.dataRanges = dataRanges.slice(0, DECOMPILER_LIMITS.dataRanges);
221
226
  const romUsed = fromRom.filter((range) => seeds.dataRanges.includes(range)).length;
222
227
  const coverageUsed = fromCoverage.filter((entry) => seeds.entryPoints.includes(entry) || codeStarts.includes(entry)).length;
223
228
  // Platform names are C64 names: drive code and banks get none.
224
229
  const platform = space === DEFAULT_SPACE ? platformNames() : [];
230
+ /** The analyzer version of the last analysis of these bytes: a new version can change the findings by itself. */
231
+ const lastVersion = reader === undefined ? undefined : lastToolVersion(reader, analyzer, bytes);
225
232
  reader?.close();
226
233
  /** Imports the idioms as their own revision, after the analyzer's, and gives their part of the result. */
227
234
  const idiomsResult = () => {
@@ -298,6 +305,7 @@ async function analyze(call: Call): Promise<unknown> {
298
305
  const found = idiomsResult();
299
306
  const body = {
300
307
  analyzer: "dxa",
308
+ ...(result.toolVersion === undefined ? {} : { analyzerVersion: result.toolVersion }),
301
309
  ...(space === DEFAULT_SPACE ? {} : { space }),
302
310
  ...found,
303
311
  ...coverageResult(),
@@ -307,13 +315,13 @@ async function analyze(call: Call): Promise<unknown> {
307
315
  labels: listed(result.labels, max, (label) => ({ address: formatC64Address(label.address), name: label.name }), ALL_NAMES),
308
316
  ...(written === undefined ? {} : { listing: written }),
309
317
  };
310
- return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision });
318
+ return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision }, { now: result.toolVersion, last: lastVersion, revision: imported.revision }, imported.changes.references.retired);
311
319
  }
312
320
 
313
- const { result } = await analyzeWithGhidra({ imageKind, ...seeds, codeStarts, decompile }, bytes, localToolContext());
314
- // Executed instruction starts that Ghidra did not decode: the instruction list and the source miss them.
321
+ const { result } = await analyzeWithDecompiler({ imageKind, ...seeds, codeStarts, decompile }, bytes, localToolContext());
322
+ // Executed instruction starts that the decompiler did not decode: the instruction list and the source miss them.
315
323
  const decoded = new Set(result.instructions.map((instruction) => instruction.address));
316
- const imported = record({ ...ghidraFindings(result), space, ...executed }, revision, "Ghidra analysis of the program", runProvenance(bytes, result.toolVersion));
324
+ const imported = record({ ...decompilerFindings(result), space, ...executed }, revision, "Decompiler analysis of the program", runProvenance(bytes, result.toolVersion));
317
325
  const found = idiomsResult();
318
326
  // A start inside a dual-use region is a known overlap, for example the second instruction of a BIT skip: one list cannot hold both.
319
327
  // Read after the idioms, which write those regions.
@@ -327,7 +335,8 @@ async function analyze(call: Call): Promise<unknown> {
327
335
  instructions = { count: list.length, ...writeReported(instructionsPath, `${JSON.stringify(list, null, 1)}\n`, { what: "--out-instructions" }) };
328
336
  }
329
337
  const body = {
330
- analyzer: "ghidra",
338
+ analyzer: "decompiler",
339
+ ...(result.toolVersion === undefined ? {} : { analyzerVersion: result.toolVersion }),
331
340
  ...(space === DEFAULT_SPACE ? {} : { space }),
332
341
  ...(instructions === undefined ? {} : { instructions }),
333
342
  ...found,
@@ -341,29 +350,29 @@ async function analyze(call: Call): Promise<unknown> {
341
350
  ? {}
342
351
  : { notDecompiled: result.notDecompiled!.map((item) => ({ entry: formatC64Address(item.entry), reason: item.reason })) }),
343
352
  };
344
- return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision });
353
+ return withHint(body, imported.conflicts.length + found.idioms.conflicts.length, body.coverageConflicts?.length ?? 0, { candidates: found.idioms.candidates.macros.count, applied: applyMacros, revision: found.idioms.candidates.macros.revision }, { now: result.toolVersion, last: lastVersion, revision: imported.revision }, imported.changes.references.retired);
345
354
  }
346
355
 
347
356
  await runScript({
348
357
  name: "static-analysis",
349
- summary: "Analyzes the program in the knowledge with DXA or Ghidra, seeded from the knowledge and its coverage, and imports the structural findings into the knowledge.",
358
+ summary: "Analyzes the program in the knowledge with DXA or the decompiler, seeded from the knowledge and its coverage, and imports the structural findings into the knowledge.",
350
359
  names: knowledgeNames,
351
360
  commands: [
352
361
  {
353
362
  name: "analyze",
354
363
  summary: "Runs the analyzer over the program in the knowledge and imports what it finds as one revision, then the 6502 idioms as a second one.",
355
364
  options: {
356
- analyzer: { kind: "choice", value: "<dxa|ghidra>", choices: ["dxa", "ghidra"], default: "ghidra", help: "dxa (a fast first pass) or ghidra (deeper, the default)" },
365
+ analyzer: { kind: "choice", value: "<dxa|decompiler>", choices: ["dxa", "decompiler"], default: "decompiler", help: "dxa (a fast first pass) or decompiler (deeper, the default)" },
357
366
  entry: { ...OPTIONS.entry, multiple: true, help: "an entry point of the program" },
358
- decompile: { kind: "address", value: "<address>", multiple: true, help: "ghidra: a routine to decompile, at most 32" },
367
+ decompile: { kind: "address", value: "<address>", multiple: true, help: "decompiler: a routine to decompile, at most 32" },
359
368
  space: OPTIONS.space,
360
369
  "max-listed": { ...OPTIONS["max-listed"], help: "list at most n labels, functions or candidates (default 50, 0 for none). The counts are always given, and the knowledge has all labels and functions" },
361
370
  "out-listing": { kind: "path", output: "file", value: "<file>", help: "dxa: write the disassembly listing to this project file" },
362
- "out-instructions": { kind: "path", output: "file", value: "<file>", help: "ghidra: write every instruction (address, bytes, mnemonic, mode, operand, target, executed) to this project file as JSON" },
371
+ "out-instructions": { kind: "path", output: "file", value: "<file>", help: "decompiler: write every instruction (address, bytes, mnemonic, mode, operand, target, executed) to this project file as JSON" },
363
372
  "apply-macros": { kind: "flag", help: "write the macro candidates (the macros and their uses) to the project knowledge as one revision of the LLM" },
364
373
  skip: { kind: "address", value: "<address>", multiple: true, help: "with --apply-macros: the start of a macro candidate that is not correct. The run does not write it" },
365
374
  },
366
- notes: "The program and the coverage come from the project knowledge: put them into the project knowledge first. The executed code of the coverage gives entry points. Routine symbols in the knowledge are entry points too. Ghidra needs at least one entry point. DXA finds the SYS of a BASIC start by itself.",
375
+ notes: "The program and the coverage come from the project knowledge: put them into the project knowledge first. The executed code of the coverage gives entry points. Routine symbols in the knowledge are entry points too. The decompiler needs at least one entry point. DXA finds the SYS of a BASIC start by itself.",
367
376
  run: analyze,
368
377
  },
369
378
  ],
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: c64-testing
3
- description: Tests if a rebuilt or changed C64 program behaves as the original, or if a program has the expected values. It runs a scenario on the original and on the rebuild in an emulator. It compares memory, registers, chip state and the screen with explicit rules, and gives PASS, FAIL or INCONCLUSIVE. Use it when you must show that a rebuild or a correction keeps the behavior of the original. Use it to do many steps on one program and keep the screens, coverage maps, traces and snapshots as files. Use it to test a new program or a correction with expected values. Use it to record a play session of the original and replay it on each rebuild. Use it to find what changed between two machine states, and to make a checklist for a human playtest. It does not find the cause of a difference. It does not build the program.
3
+ description: Tests if a rebuilt or changed C64 program behaves as the original, or if a program has the expected values. It runs a scenario on the original and on the rebuild in an emulator. It compares memory, registers, chip state and the screen with explicit rules, and gives PASS, FAIL or INCONCLUSIVE. Use it when you must show that a rebuild or a correction keeps the behavior of the original. Use it to do many steps on one program and keep the screens, coverage maps, traces and snapshots as files. Use it to test a new program or a correction with expected values. Use it to record a play session of the original and replay it on the default build of the rebuild. Use it to find what changed between two machine states, and to make a checklist for a human playtest. It does not find the cause of a difference. It does not build the program.
4
4
  ---
5
5
 
6
6
  # C64 testing
@@ -48,6 +48,7 @@ To get the command list, run the script with no arguments.
48
48
  - `--state` and `--pin` take a name or a `$` address, with `:size` for more than one byte, for example `room:2`. Use the names that the project knowledge has at the time of the replay.
49
49
  - The joystick port of `--joystick` is the port that the program reads. Port 2 is `$DC00`, and port 1 is `$DC01`. Find the port in the code or in the project knowledge. If you do not know the port, use 2.
50
50
  - `diff` takes two states of one kind. A state is a snapshot file (`.vsf`), a memory file (`.bin`) of a run, or an observation of a run (`results.json:<name>`). A `save` step of a run writes a snapshot file. A snapshot save in the emulator also writes one.
51
+ - Each command starts its own emulator. Thus many commands can run at the same time. For example, other commands can run while a long `record` runs in the background.
51
52
 
52
53
  ### Paths and the project folder
53
54
 
@@ -178,6 +179,8 @@ A recording keeps a session of the original program, for example a play through
178
179
  - Make the recordings early, before you change the program.
179
180
  - Ask the user to play first. Tell the user which parts of the program the recordings must have, for example each room, a fight and a lost life.
180
181
  - Record a session from steps only for a part that the sessions of the user do not have, or when the user cannot play.
182
+ - Replay each recording on the default build. Do not replay a release build or a build with a switch that is not at its default.
183
+ - When the generated source has a loader, the default build is `build/clean_loader.prg`. Give `--symbols build/symbols/clean_loader.json` with it. Else the default build is `build/clean.prg`, with `--symbols build/symbols/clean.json`.
181
184
  - Commit the recording folder with the scenarios. Do not put a recording into the project knowledge. Do not put test results, screenshots or playtest results into it.
182
185
  - A finding that a recording shows can go into the project knowledge. Give the `recording.json` of the recording as its test evidence.
183
186
  - The C64 of a recording has no disk drive. For a program that loads more files from a disk, use a scenario with `test`.
@@ -204,10 +207,12 @@ The script does the steps of the record file on the original program. Then it wr
204
207
  - `executed`: the number of instructions in the coverage map.
205
208
  - `coverageFrom`: the `frame` and the `pc` where the coverage map starts. `null` when the coverage did not start.
206
209
  - `reason`: with a FAIL, why the session did not complete.
210
+ - `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.
207
211
 
208
212
  Do this for each result:
209
213
 
210
- - `PASS`: `hint` tells you to commit the folder and to add its `coverage.bin` to the project knowledge as coverage. `nextAction` replays the recording on the original. Run it to make sure that the recording replays.
214
+ - `PASS`: for a folder in `tests/recordings/`, `hint` tells you to commit the folder and to add its `coverage.bin` 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 original. Run it to make sure that the recording replays.
215
+ - `PASS` with `evidence`: you recorded into the folder of an earlier recording. Put the new `coverage.bin` into the project knowledge as coverage. It replaces the map of the earlier recording. For another file in `evidence`, examine the facts of its revisions against the new recording.
211
216
  - `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.
212
217
  - 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.
213
218
  - `coverageFrom` is `null` and `executed` is 0: the coverage did not start, so the coverage map is empty. The recording can still replay.
@@ -236,6 +241,8 @@ A `$` address is an address of the original. On the rebuild, it moves with the n
236
241
 
237
242
  A rebuild can be a loader with a start screen that RUN starts. If the symbols of the rebuild have `loader_start_screen_wait` and `loader_start_screen_continue`, the script runs the rebuild to the wait. Then it sets the PC to `loader_start_screen_continue`. The cycles before the wait do not count.
238
243
 
244
+ A rebuild can be the loader program of a generated source. Give its symbols. Then the replay counts from the entry of the program, where the loader jumps to. The checkpoints of both sides start at that entry. At the entry, the rebuild gets the raster position, the CIA timers and the interrupt state of the original. The loader cannot set them as the original has them in the replay. A runUntil step to an address does not count the code of the loader, or the code that the original runs before that entry. If another step of the recording runs before the entry, the result is INCONCLUSIVE. Then start the steps of the record file after the entry.
245
+
239
246
  `body` holds `result`, `side`, `firstDifference`, `reason` and `files`. The section "Replay" of `references/recording-format.md` gives each field.
240
247
 
241
248
  Do this for each result:
@@ -252,7 +259,7 @@ Do this for each result:
252
259
  Traps:
253
260
 
254
261
  - `idleReads` counts the input reads of the rebuild that the recording had no value for. On the original, such a read makes the result INCONCLUSIVE. The rebuild can read input where the original does not, for example in its loader before the start screen. Such reads do not change a PASS of the rebuild.
255
- - The script refuses a recording of version 2.0 with `invalid-input`. Record the session again.
262
+ - The script refuses a recording of an older version in an old form with `invalid-input`. Record the session again.
256
263
 
257
264
  ---
258
265
 
@@ -72,7 +72,13 @@ The keyboard queue of the KERNAL holds 10 keys. If the keys of a `type` step and
72
72
 
73
73
  RESTORE starts an NMI and is not a read. The recording keeps each RESTORE of a `press` step as an event of that step. The replay presses RESTORE again at the same read of the program.
74
74
 
75
- `type`, `write`, `registers` and `runUntil` steps are events. The recording keeps a point in the program for each event. The point is the next read at the input site with the most reads. That site is not in ROM. A replay does the event again at the same read. An event that comes directly after another event runs at once after that event.
75
+ `type`, `write`, `registers` and `runUntil` steps are events. The recording keeps a point in the program for each event. A replay does the event again at the same point:
76
+
77
+ - A `runUntil` step to an address: the point is the number of times that the CPU got to that address. This step does not need an input read.
78
+ - An event that comes directly after another event runs at once after that event.
79
+ - Each other event: the point is the next read at the input site with the most reads. That site is not in ROM. If the program does not read input in 600 frames, the session stops.
80
+
81
+ Some parts of a program read no input, for example an intro or a bonus screen. To do an event in such a part, put a `runUntil` step to an address before the event.
76
82
 
77
83
  ## Play
78
84
 
@@ -121,7 +127,7 @@ The page sends input only between Start and End. The input of the page goes into
121
127
 
122
128
  A site is the address of the instruction that reads. The values are hex. `<from>` and `<count>` are decimal.
123
129
 
124
- `replay` examines `recording.json` before the replay starts. A recording of version 2.0 can have events or a comparison in the old form, for example `"at"` in place of `"address"`. The script refuses it with `invalid-input`. The message names the event, the old field and the form to write. Record the session again.
130
+ `replay` examines `recording.json` before the replay starts. A recording of an older version can have events or a comparison in an old form. For example, `"at"` is in place of `"address"`, or a `runUntil` step to an address has no count of the CPU at its target. The script refuses such a recording with `invalid-input`, and the message names the event. Record the session again.
125
131
 
126
132
  ## Replay
127
133
 
@@ -57,6 +57,8 @@ Before the first step of each side, the script does a hard reset. The CPU stops
57
57
  | `{ "normalize": true }` | Write pages 0 to 3 and `$00`/`$01` from the entry state in the project knowledge. The entry state comes from a capture of the unpacked program. Then both sides have the same zero page, stack and KERNAL work area. |
58
58
  | `{ "observe": "moved", ... }` | Record a checkpoint. |
59
59
 
60
+ The `timeoutFrames` of a `runUntil` step is from 1 to 30000. The default is 3000. For a longer wait, put `frames` steps before the `runUntil` step.
61
+
60
62
  The `port` of a joystick is 1 or 2. The `direction` is `center`, `up`, `down`, `left`, `right`, `up-left`, `up-right`, `down-left` or `down-right`.
61
63
 
62
64
  A `condition` has the `kind` `register`, `memory` or `raster`. A `register` condition has `register` (`a`, `x`, `y` or `sp`), `operator` and `value`. A `memory` condition has `address`, `operator` and `value`. A `raster` condition has `line` and an optional `cycle`.
@@ -95,7 +97,7 @@ A run file is one JSON object in a project file. It has:
95
97
  - `start`: required. `{ "program": "game.prg" }` to autostart a program with a BASIC start line, `{ "program": "game.prg", "load": true }` to load it with the CPU stopped (set `pc` in a step), or `{ "snapshot": ".c64-re-tools/local/snapshots/room0.vsf" }`.
96
98
  - `symbols`: optional, `knowledge`, `none` (default), or a JSON file as for a subject. Without `symbols`, a run has no names: give `"symbols": "knowledge"` to use the names of the knowledge.
97
99
  - `videoStandard`: optional, `pal` (default) or `ntsc`.
98
- - `steps`: required. At least one step. The steps `write`, `registers`, `joystick`, `type`, `frames` and `runUntil` of a scenario, and the run steps `snapshot`, `save`, `screen`, `coverage`, `trace`, `observe` and `expect`.
100
+ - `steps`: required. At least one step. The steps `write`, `registers`, `joystick`, `type`, `press`, `frames` and `runUntil` of a scenario, and the run steps `snapshot`, `save`, `screen`, `coverage`, `trace`, `observe` and `expect`.
99
101
 
100
102
  The run steps have these effects:
101
103
 
@@ -112,7 +114,7 @@ The run steps have these effects:
112
114
 
113
115
  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.
114
116
 
115
- 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.
117
+ 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. In a run, the screen is not a key of `observe`. Write it with a `screen` step, for example `{ "screen": "room3" }`.
116
118
 
117
119
  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 `$`. `results.json` gives the file name.
118
120