@henols/c64-re-tools 2.7.0 → 2.8.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +23 -38
  3. package/skills/c64-assembler/scripts/assembler.ts +114 -16
  4. package/skills/c64-basic/SKILL.md +11 -31
  5. package/skills/c64-basic/scripts/basic.ts +4 -1
  6. package/skills/c64-development/SKILL.md +2 -2
  7. package/skills/c64-disk/SKILL.md +11 -32
  8. package/skills/c64-docs/SKILL.md +27 -45
  9. package/skills/c64-docs/references/page-types.md +20 -18
  10. package/skills/c64-docs/references/style.md +10 -4
  11. package/skills/c64-docs/scripts/docs.ts +13 -2
  12. package/skills/c64-docs/scripts/lib/reference.ts +47 -5
  13. package/skills/c64-knowledge/SKILL.md +138 -267
  14. package/skills/c64-knowledge/references/batches.md +48 -0
  15. package/skills/c64-knowledge/references/coverage.md +29 -0
  16. package/skills/c64-knowledge/references/source-knowledge.md +72 -0
  17. package/skills/c64-knowledge/references/start-screen.md +44 -0
  18. package/skills/c64-knowledge/scripts/knowledge.ts +266 -61
  19. package/skills/c64-knowledge/scripts/lib/check.ts +133 -0
  20. package/skills/c64-knowledge/scripts/lib/listing.ts +72 -8
  21. package/skills/c64-memory-map/SKILL.md +11 -32
  22. package/skills/c64-packer/SKILL.md +11 -31
  23. package/skills/c64-provenance/SKILL.md +40 -62
  24. package/skills/c64-provenance/scripts/lib/leftovers.ts +8 -3
  25. package/skills/c64-provenance/scripts/provenance.ts +64 -55
  26. package/skills/c64-reverse-engineering/SKILL.md +20 -47
  27. package/skills/c64-reverse-engineering/references/comment-check.md +42 -0
  28. package/skills/c64-reverse-engineering/references/versions.md +47 -0
  29. package/skills/c64-source/SKILL.md +43 -235
  30. package/skills/c64-source/references/export.md +50 -0
  31. package/skills/c64-source/references/loader.md +78 -0
  32. package/skills/c64-source/references/source-format.md +46 -0
  33. package/skills/c64-source/scripts/lib/export.ts +20 -7
  34. package/skills/c64-source/scripts/lib/loader.ts +116 -104
  35. package/skills/c64-source/scripts/source.ts +62 -52
  36. package/skills/c64-static-analysis/SKILL.md +51 -52
  37. package/skills/c64-static-analysis/scripts/lib/coverage.ts +55 -2
  38. package/skills/c64-static-analysis/scripts/lib/idioms.ts +28 -9
  39. package/skills/c64-static-analysis/scripts/static-analysis.ts +69 -15
  40. package/skills/c64-testing/SKILL.md +77 -59
  41. package/skills/c64-testing/references/recording-format.md +5 -79
  42. package/skills/c64-testing/references/scenario-format.md +4 -12
  43. package/skills/c64-testing/scripts/lib/play.ts +16 -8
  44. package/skills/c64-testing/scripts/lib/recording.ts +76 -9
  45. package/skills/c64-testing/scripts/lib/replay.ts +14 -0
  46. package/skills/c64-testing/scripts/lib/runs.ts +112 -1
  47. package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
  48. package/skills/c64-testing/scripts/lib/start-screen.ts +27 -0
  49. package/skills/c64-testing/scripts/testing.ts +37 -15
  50. package/skills/c64-unpacker/SKILL.md +10 -30
  51. package/skills/emulator/SKILL.md +7 -36
  52. package/src/build-name.ts +12 -1
  53. package/src/knowledge/history.ts +8 -0
  54. package/src/knowledge/program.ts +73 -1
  55. package/src/knowledge/read.ts +46 -2
  56. package/src/knowledge/recording-files.ts +32 -0
  57. package/src/knowledge/schema.ts +3 -1
  58. package/src/knowledge/separate.ts +90 -3
  59. package/src/knowledge/start-screen.ts +99 -17
  60. package/src/knowledge/text.ts +2 -1
  61. package/src/knowledge/write.ts +15 -8
  62. package/src/loader.ts +167 -0
  63. package/src/native/c64run.ts +11 -0
  64. package/src/native/decompiler/analyze.ts +7 -6
  65. package/src/native/decompiler/walk.ts +32 -2
  66. package/src/native/dxa.ts +4 -4
  67. package/src/native/types.ts +32 -4
  68. package/src/script.ts +87 -17
  69. package/skills/c64-export/SKILL.md +0 -63
@@ -1,6 +1,6 @@
1
1
  # Recording format
2
2
 
3
- This file gives the format of a record file and of a recording folder. For the commands, see the sections ``### `record <record.json>` `` and ``### `replay <recording>` `` of `SKILL.md`.
3
+ This file gives the format of a record file. For the commands, see the sections ``### `record <record.json>` `` and ``### `replay <recording>` `` of `SKILL.md`.
4
4
 
5
5
  ## Record file
6
6
 
@@ -43,7 +43,7 @@ A record file has no `raster` target and no `condition`. `write` and `runUntil`
43
43
 
44
44
  | Step | Effect |
45
45
  |---|---|
46
- | `{ "frames": 300 }` | Run 300 frames (19656 cycles each). |
46
+ | `{ "frames": 300 }` | Run 300 frames. |
47
47
  | `{ "joystick": { "port": 2, "direction": "left", "fire": true } }` | Set a joystick. It stays in this state until the next joystick step. |
48
48
  | `{ "press": { "keys": "RUN\n" } }` | Press the keys of the keyboard matrix. Each tap holds its keys for 3 frames, then releases them for 3 frames. `frames` sets a different number, from 1 to 3000. |
49
49
  | `{ "type": { "mode": "text", "text": "RUN\n" } }` | Put at most 10 keys into the keyboard queue of the KERNAL, after the keys that wait there. |
@@ -68,84 +68,10 @@ To hold keys together in one tap, join them with `+` in braces. For example, `{
68
68
 
69
69
  The keyboard queue of the KERNAL holds 10 keys. If the keys of a `type` step and the keys that wait in the queue do not fit, the session stops. A program that reads the keyboard hardware does not see the keys of a `type` step. Use `press` for that program.
70
70
 
71
- `joystick`, `press` and `frames` steps are input and time. The recording keeps their effect in the reads, so a replay does not do these steps again.
71
+ `joystick`, `press` and `frames` steps are input and time. The recording keeps the input that the program read, so a replay does not do these steps again.
72
72
 
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.
73
+ RESTORE starts an NMI and is not an input read. A replay presses each RESTORE of a `press` step again at the same point 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. 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.
75
+ `type`, `write`, `registers` and `runUntil` steps are events. A replay does each event again at the same point of the program. A `runUntil` step to an address needs no input. Another event needs an input read of the program.
80
76
 
81
77
  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.
82
-
83
- ## Play
84
-
85
- With `--play`, `record` does the steps, then a person plays. The page on `http://localhost:<port>/` (`--http-port`) shows the screen at 50 frames each second. It has no sound.
86
-
87
- | Button | Key | Effect |
88
- |---|---|---|
89
- | Start | Enter, on the start screen | The C64 runs. Before Start, the page shows the screen after the steps, and the C64 is frozen. The time before Start is not in the recording. |
90
- | End and save | F12 | The C64 stops at the frame on the page, and the screen stays frozen. The script writes the recording folder. |
91
- | Cancel | F11 | The session stops before or during the play. The script writes no folder and gives `recorded: false`. |
92
- | Port | F9 | The joystick goes to the other port. `--joystick` gives the first port. |
93
- | Arrows | F10 | The arrow keys and space change between the joystick and the C64 keys. At the start, they are the joystick. |
94
- | Keys | | The keyboard changes between the symbolic map (the default) and the positional map. |
95
-
96
- The buttons are in one row above the screen.
97
-
98
- | Page input | C64 input |
99
- |---|---|
100
- | Arrow keys and space, when they are the joystick | The joystick: directions and fire. |
101
- | A gamepad | The joystick: the left stick or the cross for directions, button 1 or 2 for fire. |
102
- | Arrow keys and space, when they are C64 keys | CRSR up, down, left and right, and SPACE. |
103
- | Escape, Shift+Escape | RUN/STOP, RUN |
104
- | Page Up | RESTORE |
105
- | Tab, left Alt | CTRL, C= |
106
- | Home, Shift+Home | CLR/HOME, CLR |
107
- | Backspace, Shift+Backspace | INST/DEL, INST |
108
- | F1-F8 | F1-F8 |
109
-
110
- In the symbolic map, a key gives the character on the PC key. a-z give the C64 letters, and A-Z give the letters with SHIFT. The digits and the symbols give the same characters. `£` gives the pound key, `^` gives the up arrow, and the backquote gives the left arrow.
111
-
112
- In the positional map, a key gives the C64 key at the same place on the keyboard. Each SHIFT key is a C64 SHIFT key, also alone. The C64 keys `+ - @ * : ; =` are on the PC keys `- = [ ] ; ' \`. Insert gives the pound key, Delete gives the up arrow, and the backquote gives the left arrow. Use the positional map when the program reads SHIFT alone or a key with SHIFT.
113
-
114
- Ctrl and Cmd are not C64 keys. They keep their function in the browser.
115
-
116
- The page sends input only between Start and End. The input of the page goes into the reads, as the input of the steps does. RESTORE starts an NMI and is not a read. The recording keeps each RESTORE as an event without a step number. The replay presses RESTORE again at the same read of the program.
117
-
118
- ## Recording folder
119
-
120
- `record` writes these files into the `--out` folder:
121
-
122
- | File | Content |
123
- |---|---|
124
- | `recording.json` | The program and its SHA-256, the symbols, and the comparison of the record file. Also the inputs, the events, the input sites, the cycles of the session and the state hash at its end. |
125
- | `reads.txt` | One line `<site> <addr> <from> <value>` for each change of the value at a site. From the read with the index `<from>`, the reads at `<site>` from `<addr>` get `<value>`. One line `end <site> <addr> <count>` for each site gives its number of reads. |
126
- | `coverage.bin` | The coverage map of the session: 65536 bytes, one for each address, in the format of the coverage maps of the emulator. It starts where the key `coverage` of the record file tells. The code before that point has no marks. |
127
-
128
- A site is the address of the instruction that reads. The values are hex. `<from>` and `<count>` are decimal.
129
-
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.
131
-
132
- ## Replay
133
-
134
- `replay` replays the recording on the reference program first. The session must end with the recorded cycles and state hash. Else the result is INCONCLUSIVE. With `--rebuild`, `replay` then replays the recording on the rebuild. At each checkpoint, the rebuild first gets the pinned values of the reference. Then the script compares the state. The cycles can be different.
135
-
136
- A recording without names (`symbols` is `none`) takes the names of the project knowledge at the time of the replay.
137
-
138
- For the rebuild, the script finds each name with the names of the rebuild (`--symbols`). A `$` address is an address of the reference. It moves with the name before it in the reference: the script finds the same name in the rebuild and adds the same offset. Code moves with a code label, and data with any name. A site in ROM does not move. Give a state item a name, or the state moves with the code before it.
139
-
140
- The body of the envelope of `replay` has these fields:
141
-
142
- - `result`: PASS, FAIL or INCONCLUSIVE.
143
- - `side`: `reference` for the check of the reference only, `rebuild` with `--rebuild`.
144
- - `checkpoint`: the routine of the comparison.
145
- - `checkpoints` and `compared`: the checkpoints of the reference, and the checkpoints of the rebuild that were the same.
146
- - `firstDifference`: on a FAIL, the checkpoint (1 is the first), the cycle on each side, and each state item that is different. An item has `address`, and the `reference` and `rebuild` values as hex.
147
- - `reason`: why the result is FAIL or INCONCLUSIVE.
148
- - `movedSites`: the number of sites at a different address in the rebuild.
149
- - `startScreen`: `skipped` when the rebuild went past the wait of its start screen.
150
- - `idleReads`: the input reads of the rebuild that the recording had no value for. Such a read is at a site that the recording does not have, or after its end. Each got the fixed value `$FF` (joystick, keyboard, paddles) or `$00`. An input site that the site map did not find shows here.
151
- - `files`: with `--out`, the RAM of each side at the first different checkpoint, `reference-<n>.bin` and `rebuild-<n>.bin`.
@@ -57,14 +57,12 @@ 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.
60
+ The `timeoutFrames` of a `runUntil` step is from 1 to 30000. The default is 3000. A `runUntil` step that does not get to its target in `timeoutFrames` frames makes the result INCONCLUSIVE. For a longer wait, put `frames` steps before the `runUntil` step.
61
61
 
62
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`.
63
63
 
64
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`.
65
65
 
66
- `timeoutFrames` is from 1 to 30000, and 3000 by default. A `runUntil` that does not get to its target in `timeoutFrames` frames makes the result INCONCLUSIVE.
67
-
68
66
  Each step except `observe` can have `"side": "reference"` or `"side": "rebuild"`. Then only that side does the step. Use it when only one side needs a step, for example a key for the intro of the reference. An `observe` step has no `side`, because it compares both sides.
69
67
 
70
68
  Each side finds a name in its own symbols.
@@ -112,13 +110,11 @@ The run steps have these effects:
112
110
  | `{ "trace": "d011", "points": [{ "kind": "write", "start": "$d011" }], "frames": 100 }` | Record each hit of the points for 100 frames in `d011.json`: the instruction, its registers, and the raster line and cycle. |
113
111
  | `{ "expect": "title", "memory": [{ "address": "$0400", "text": "HELLO" }] }` | Compare memory and registers with the expected values. See the section "Expected values". |
114
112
 
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.
116
-
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" }`.
113
+ 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. A trace that a breakpoint, a watchpoint or a JAM ends also ends the run.
118
114
 
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.
115
+ In a run, an `observe` step can have `memory`, `registers`, `vicii` and `sprites`. A memory item has only `address`, `size` (1 to 65536) and `view`. `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" }`.
120
116
 
121
- A name in `save`, `screen`, `coverage`, `observe` and `expect` 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 expectations, the files and the steps done. If a `runUntil` step did not reach its target, it also tells why the run stopped.
117
+ A name in `save`, `screen`, `coverage`, `observe` and `expect` has 1 to 64 letters, digits, dots, underscores or hyphens. The files go into the `--out` folder.
122
118
 
123
119
  ### Expected values
124
120
 
@@ -150,8 +146,6 @@ A memory item has at most 4096 bytes.
150
146
 
151
147
  `registers` has the fields of a `registers` step: `pc`, `a`, `x`, `y`, `sp` and `flags`. Only `pc` can be a name.
152
148
 
153
- A value that is not equal does not stop the run. The later steps run. `results.json` and the result have `expectations`. For each step, it gives `pass` and the count of values that are not equal. It also lists at most 16 of them, with the expected and the actual value. `failedExpectations` names each step that did not pass. The result is FAIL when an expectation did not pass.
154
-
155
149
  Example: visit two rooms from the same start.
156
150
 
157
151
  ```json
@@ -182,6 +176,4 @@ The script also examines each file before it does a step: the program and the sy
182
176
 
183
177
  A run also examines each name of its steps before it does a step. An unknown name stops the run with `invalid-input`, and the message names the step. In a scenario, a side that does not have a name gives INCONCLUSIVE, and `reason` names the step.
184
178
 
185
- A step in the form of version 2.0 stops the script with `invalid-input`. The message names the old field and gives the step to write. For example, the script refuses `{ "runUntil": { "at": "main_loop" }, "timeoutFrames": 300 }` and gives `{"runUntil": {"target": {"kind": "address", "address": "main_loop"}, "timeoutFrames": 300}}`. A memory item with `at` gets the same refusal: write `address`.
186
-
187
179
  In a run, two steps must not write the same file name. The script refuses such a run before it starts. Names that differ only in upper and lower case are the same name.
@@ -77,19 +77,27 @@ canvas{image-rendering:pixelated;width:min(784px,100%);aspect-ratio:392/272;back
77
77
  button{font:inherit;font-size:12px;padding:3px 8px}
78
78
  .row{display:flex;flex-wrap:wrap;gap:6px;align-items:center;justify-content:center}
79
79
  .gap{width:12px}
80
- table{border-collapse:collapse;font-size:13px}td{padding:2px 10px;border-top:1px solid #333}
80
+ table{border-collapse:collapse;font-size:13px;max-width:784px}th{text-align:left;padding:2px 10px}td{padding:2px 10px;border-top:1px solid #333;vertical-align:top}
81
81
  </style></head><body>
82
82
  <div class="row"><button id="start" disabled>Start (Enter)</button><button id="end" disabled>End and save (F12)</button><button id="cancel" disabled>Cancel (F11)</button><span class="gap"></span><button id="port">Port 2 (F9)</button><button id="arrows">Arrows: joystick (F10)</button><button id="map">Keys: symbolic</button></div>
83
83
  <canvas id="screen" width="392" height="272"></canvas>
84
84
  <div id="state">connecting</div>
85
85
  <table>
86
- <tr><td>Start, End, Cancel</td><td>Enter (on the start screen), F12, F11</td></tr>
87
- <tr><td>Joystick</td><td>arrow keys and space (when F10 sets joystick), or a gamepad</td></tr>
88
- <tr><td>RUN/STOP, RESTORE</td><td>Esc, Page Up</td></tr>
89
- <tr><td>CTRL, C=</td><td>Tab, left Alt</td></tr>
90
- <tr><td>CLR/HOME, INST/DEL</td><td>Home, Backspace</td></tr>
91
- <tr><td>Symbolic map</td><td>the characters on the PC keys; £, ^ (up arrow) and the backquote (left arrow)</td></tr>
92
- <tr><td>Positional map</td><td>the C64 keys at the places of the PC keys; each SHIFT alone; Insert £, Delete up arrow, the backquote left arrow</td></tr>
86
+ <tr><th>Page</th><th>C64</th></tr>
87
+ <tr><td>Start, End and save, Cancel</td><td>Enter (on the start screen), F12, F11. The time before Start is not in the recording. End freezes the screen and the script saves the recording. Cancel saves none.</td></tr>
88
+ <tr><td>Port, Arrows, Keys</td><td>F9 changes the joystick port. F10 changes the arrow keys and space between the joystick (at the start) and the C64 keys. Keys changes between the symbolic map (the default) and the positional map.</td></tr>
89
+ <tr><td>Arrow keys and space as the joystick</td><td>the joystick: directions and fire</td></tr>
90
+ <tr><td>A gamepad</td><td>the joystick: the left stick or the cross for directions, button 1 or 2 for fire</td></tr>
91
+ <tr><td>Arrow keys and space as C64 keys</td><td>CRSR up, down, left and right, and SPACE</td></tr>
92
+ <tr><td>Escape, Shift+Escape</td><td>RUN/STOP, RUN</td></tr>
93
+ <tr><td>Page Up</td><td>RESTORE</td></tr>
94
+ <tr><td>Tab, left Alt</td><td>CTRL, C=</td></tr>
95
+ <tr><td>Home, Shift+Home</td><td>CLR/HOME, CLR</td></tr>
96
+ <tr><td>Backspace, Shift+Backspace</td><td>INST/DEL, INST</td></tr>
97
+ <tr><td>F1-F8</td><td>F1-F8</td></tr>
98
+ <tr><td>Symbolic map</td><td>the character on the PC key: a-z are the C64 letters, A-Z the letters with SHIFT, and the digits and the symbols the same characters. £ is the pound key, ^ the up arrow, and the backquote the left arrow.</td></tr>
99
+ <tr><td>Positional map</td><td>the C64 key at the place of the PC key. Each SHIFT key is a C64 SHIFT key, also alone. The C64 keys + - @ * : ; = are on the PC keys - = [ ] ; ' \. Insert is the pound key, Delete the up arrow, and the backquote the left arrow. Use it when the program reads SHIFT alone or a key with SHIFT.</td></tr>
100
+ <tr><td>Ctrl, Cmd</td><td>no C64 key: they keep their function in the browser</td></tr>
93
101
  </table>
94
102
  <script>
95
103
  const KEYS = __KEYS__;
@@ -12,14 +12,16 @@ import { createHash } from "node:crypto";
12
12
  import { readFileSync, writeFileSync } from "node:fs";
13
13
 
14
14
  import { isRefusal, Refusal } from "#src/errors.ts";
15
- import { c64AddressOf, formatC64Address, parseC64Address } from "#src/c64.ts";
15
+ import { c64AddressOf, COVERAGE, formatC64Address, parseC64Address } from "#src/c64.ts";
16
16
  import { keyTaps, type KeyTap } from "#src/c64-keys.ts";
17
17
  import { READY_FRAMES } from "#src/host-client/entry-state.ts";
18
18
  import { ACTION_STEP_KINDS, checkActionStep, isInteger, isObject, keyboardBytes, renamedField, stepKind, type ActionStep, type Location } from "#src/host-client/steps.ts";
19
19
  import { readProjectFile, type Written } from "#src/host-client/transfer.ts";
20
- import { LOADER_JUMP, START_SCREEN_CONTINUE, START_SCREEN_WAIT } from "#src/knowledge/start-screen.ts";
20
+ import { RECORDING_FILES } from "#src/knowledge/recording-files.ts";
21
+ import { LOADER_JUMP, startScreenLabels } from "#src/knowledge/start-screen.ts";
21
22
  import { PAL_FRAME_CYCLES, type C64RunSession, type CoreStatus } from "#src/native/c64run.ts";
22
23
  import type { Workspace } from "#src/native/staging.ts";
24
+ import { listed } from "#src/script.ts";
23
25
  import { namesOf, type Outcome } from "./scenario.ts";
24
26
 
25
27
  export const RECORDING_FORMAT = 1;
@@ -134,7 +136,7 @@ export interface Recording {
134
136
  hash: string;
135
137
  }
136
138
 
137
- export const RECORDING_FILES = { recording: "recording.json", reads: "reads.txt", coverage: "coverage.bin" } as const;
139
+ export { RECORDING_FILES };
138
140
 
139
141
  /** Steps that are input or time: the replay gives the program the reads that they caused, and does not do them again. */
140
142
  const INPUT_KINDS = new Set(["joystick", "press", "frames"]);
@@ -381,12 +383,11 @@ export interface EntryPoint {
381
383
  * undefined when the rebuild has no start screen.
382
384
  */
383
385
  async function passStartScreen(core: C64RunSession, own: Map<string, number>, limit: number): Promise<number | string | undefined> {
384
- const wait = own.get(START_SCREEN_WAIT);
385
- const resume = own.get(START_SCREEN_CONTINUE);
386
- if (wait === undefined || resume === undefined) return undefined;
387
- const reached = await core.status(`run-pc ${hex(wait)} ${limit}`);
388
- if (reached.word !== "reached") return `the rebuild did not come to the wait of its start screen at ${formatC64Address(wait)}`;
389
- await core.status(`goto ${hex(resume)}`);
386
+ const labels = startScreenLabels(own);
387
+ if (labels === undefined) return undefined;
388
+ const reached = await core.status(`run-pc ${hex(labels.wait)} ${limit}`);
389
+ if (reached.word !== "reached") return `the rebuild did not come to the wait of its start screen at ${formatC64Address(labels.wait)}`;
390
+ await core.status(`goto ${hex(labels.continue)}`);
390
391
  return reached.tick;
391
392
  }
392
393
 
@@ -894,4 +895,70 @@ export interface ReplayResult {
894
895
  /** Input reads of the rebuild that the recording had no value for: they got the idle value. */
895
896
  idleReads?: number;
896
897
  files?: Written[];
898
+ /** The screen of the reference at the end of the session (--screen). */
899
+ screen?: Written;
900
+ }
901
+
902
+ /** An input site of a recording: the instruction that reads, the address that it reads, its reads, and how often the value changed. */
903
+ export interface InputSite {
904
+ site: Location;
905
+ address: Location;
906
+ reads: number;
907
+ changes: number;
908
+ }
909
+
910
+ /** What `show` gives of a recording folder: the program, the session, the input sites and the coverage counts. */
911
+ export interface RecordingSummary {
912
+ recording: string;
913
+ name: string;
914
+ program: string;
915
+ symbols: string;
916
+ load: boolean;
917
+ checkpoint?: Location;
918
+ state?: StateItem[];
919
+ pin?: StateItem[];
920
+ inputs: string[];
921
+ frames: number;
922
+ events: number;
923
+ inputSites: { count: number; listed: InputSite[]; rest?: string };
924
+ /** The RAM addresses that the session executed, read and wrote, from the start of the coverage map. */
925
+ coverage: { executed: number; read: number; written: number };
926
+ /** The test evidence of a finding that the recording shows: the --evidence value of a knowledge write. */
927
+ evidence: string;
928
+ }
929
+
930
+ /**
931
+ * What a recording folder holds, without a replay: recording.json, the value
932
+ * changes of each site in reads.txt (each line `<site> <addr> <from> <value>`
933
+ * after the first read is a change), and the counts of coverage.bin.
934
+ */
935
+ export function showRecording(folder: string, max: number): RecordingSummary {
936
+ const recording = readRecording(folder);
937
+ const changes = new Map<string, number>();
938
+ for (const line of readProjectFile(`${folder}/${RECORDING_FILES.reads}`).bytes.toString("utf8").split("\n")) {
939
+ const [site, addr, from] = line.split(" ");
940
+ if (site === undefined || site === "end" || addr === undefined || from === undefined || Number(from) === 0) continue;
941
+ const key = `${site} ${addr}`;
942
+ changes.set(key, (changes.get(key) ?? 0) + 1);
943
+ }
944
+ const sites = recording.sites
945
+ .map((site): InputSite => ({ site: site.site, address: site.addr, reads: site.reads, changes: changes.get(`${hex(parseC64Address(site.site))} ${hex(parseC64Address(site.addr))}`) ?? 0 }))
946
+ .sort((a, b) => parseC64Address(a.site) - parseC64Address(b.site) || parseC64Address(a.address) - parseC64Address(b.address));
947
+ const map = readProjectFile(`${folder}/${RECORDING_FILES.coverage}`).bytes;
948
+ const count = (bit: number) => map.reduce((total, byte) => total + ((byte & bit) === 0 ? 0 : 1), 0);
949
+ const compare = recording.compare;
950
+ return {
951
+ recording: folder,
952
+ name: recording.name,
953
+ program: recording.program,
954
+ symbols: recording.symbols,
955
+ load: recording.load,
956
+ ...(compare === undefined ? {} : { checkpoint: compare.checkpoint, state: compare.state, ...(compare.pin === undefined ? {} : { pin: compare.pin }) }),
957
+ inputs: recording.inputs,
958
+ frames: Math.round(recording.ticks / PAL_FRAME_CYCLES),
959
+ events: recording.events.length,
960
+ inputSites: listed(sites, max),
961
+ coverage: { executed: count(COVERAGE.ramExecute), read: count(COVERAGE.ramRead), written: count(COVERAGE.ramWrite) },
962
+ evidence: `test:${folder}/${RECORDING_FILES.recording}`,
963
+ };
897
964
  }
@@ -10,6 +10,7 @@ import { isRefusal, Refusal } from "#src/errors.ts";
10
10
  import { readPrg } from "#src/host-client/image.ts";
11
11
  import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
12
12
  import { formatC64Address } from "#src/c64.ts";
13
+ import { encodePng } from "#src/graphics.ts";
13
14
  import { LOADER_JUMP } from "#src/knowledge/start-screen.ts";
14
15
  import { C64RunSession } from "#src/native/c64run.ts";
15
16
  import { localToolContext } from "#src/native/local.ts";
@@ -28,6 +29,8 @@ export interface ReplayOptions {
28
29
  rebuild?: string;
29
30
  symbols?: string;
30
31
  out?: string;
32
+ /** A PNG file for the screen of the reference at the end of the session. */
33
+ screen?: string;
31
34
  }
32
35
 
33
36
  /** Replays the recording on the reference, and with `rebuild` on the rebuild: PASS, FAIL or INCONCLUSIVE. */
@@ -41,6 +44,7 @@ export async function replay(values: ReplayOptions): Promise<ReplayResult> {
41
44
  const given: Comparison | undefined =
42
45
  values.checkpoint === undefined ? undefined : { checkpoint: values.checkpoint, state: values.state.map((item) => parseStateItem(item, "--state")), ...(values.pin.length === 0 ? {} : { pin: values.pin.map((item) => parseStateItem(item, "--pin")) }) };
43
46
  const compare = given ?? recording.compare;
47
+ let screen: Written | undefined;
44
48
  if (values.rebuild !== undefined && compare === undefined) throw new UsageError("The recording has no checkpoint and state for --rebuild. Give --checkpoint and --state.");
45
49
  const result = (outcome: ReplayResult["result"], side: ReplayResult["side"], fields: Partial<ReplayResult> = {}): ReplayResult => ({
46
50
  result: outcome,
@@ -49,6 +53,7 @@ export async function replay(values: ReplayOptions): Promise<ReplayResult> {
49
53
  ...(compare === undefined ? {} : { checkpoint: compare.checkpoint }),
50
54
  checkpoints: 0,
51
55
  compared: 0,
56
+ ...(screen === undefined ? {} : { screen }),
52
57
  ...fields,
53
58
  });
54
59
  // The files of the rebuild are checked before the replay core starts.
@@ -73,6 +78,10 @@ export async function replay(values: ReplayOptions): Promise<ReplayResult> {
73
78
  const side = (subject: ReplaySubject, options: Parameters<typeof replaySide>[5]) => replaySide(core, recording, folder, subject, workspace, options);
74
79
  const rebuildSymbols = values.symbols ?? referenceSymbols;
75
80
  // A rebuild with a generated loader starts the program where its loader jumps to. The reference comes to that entry by the same name.
81
+ // The checkpoints of both sides count from that entry, and at the entry the rebuild gets the raster position, the CIA timers and
82
+ // the interrupt state of the reference, which the loader cannot set as the reference has them. A runUntil to an address counts
83
+ // neither the code of the loader nor the code of the reference before the entry; another event before the entry has no point in
84
+ // the rebuild, and the result is INCONCLUSIVE.
76
85
  let loader: { entry: number; reference: number } | undefined;
77
86
  if (values.rebuild !== undefined && !recording.load && namesOf(rebuildSymbols).has(LOADER_JUMP)) {
78
87
  const entry = await loaderEntry(core, recording, { side: "rebuild", program: values.rebuild, symbols: rebuildSymbols });
@@ -88,6 +97,11 @@ export async function replay(values: ReplayOptions): Promise<ReplayResult> {
88
97
  if (self.end.tick !== recording.ticks || self.end.hash !== recording.hash) {
89
98
  return result("INCONCLUSIVE", "reference", { reason: "the recording does not reproduce on the reference: the state at its end is different; record the session again with this version of the toolkit" });
90
99
  }
100
+ // The core is still at the end of the session: the rebuild side starts it again.
101
+ if (values.screen !== undefined) {
102
+ const shot = await core.screen();
103
+ screen = writeReported(values.screen, encodePng(shot.frame, shot.palette), { what: "--screen" });
104
+ }
91
105
  const expected = self.samples;
92
106
  if (compare !== undefined && expected.length === 0) return result("INCONCLUSIVE", "reference", { reason: `the reference never came to the checkpoint ${compare.checkpoint} in the session` });
93
107
  if (values.rebuild === undefined) return result("PASS", "reference", { checkpoints: expected.length });
@@ -4,6 +4,9 @@
4
4
  // side, no comparison with another program: an expect step checks the memory
5
5
  // and registers against the values that the run file gives.
6
6
 
7
+ import { existsSync } from "node:fs";
8
+ import { posix } from "node:path";
9
+
7
10
  import { formatC64Address, formatC64Byte, formatSprite, formatVicii, parseC64Address } from "#src/c64.ts";
8
11
  import { screenText } from "#src/graphics.ts";
9
12
  import { runProgram } from "#src/host-client/autostart.ts";
@@ -15,7 +18,9 @@ import { MAX_MEMORY_READ, MAX_TRACE_FRAMES, MAX_TRACE_HITS, MAX_TRACE_POINTS, TR
15
18
  import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
16
19
  import { readMemoryInParts, ViceSessionClient } from "#src/host-client/vice-session.ts";
17
20
  import { checkSnapshotFile } from "#src/media.ts";
21
+ import { checkOutputPath, LOCAL_DIRECTORY, PROJECT_DIRECTORY, projectRelative, resolveProjectPath } from "#src/project.ts";
18
22
  import { namesOf } from "./scenario.ts";
23
+ import { passStartScreen } from "./start-screen.ts";
19
24
 
20
25
  type RunStep =
21
26
  | ActionStep
@@ -335,6 +340,7 @@ export async function runFile(path: string, out: string): Promise<{ output: Reco
335
340
  const client = await ViceSessionClient.open({ videoStandard: run.videoStandard ?? "pal" });
336
341
  let done = 0;
337
342
  let reason: string | undefined;
343
+ let startScreen: "skipped" | "none" = "none";
338
344
  try {
339
345
  await client.reset({ mode: "hard", run: false });
340
346
  if ("snapshot" in run.start) {
@@ -345,6 +351,11 @@ export async function runFile(path: string, out: string): Promise<{ output: Reco
345
351
  } else {
346
352
  const failed = await runProgram(client, run.start.program, readProjectFile(run.start.program).bytes);
347
353
  if (failed !== undefined) reason = failed === "not-loaded" ? "The program was not in memory after autostart." : "The program did not start after RUN; it needs a BASIC start line.";
354
+ else {
355
+ const screen = await passStartScreen(client, symbols);
356
+ if (typeof screen === "object") reason = `${screen.problem[0]!.toUpperCase()}${screen.problem.slice(1)}.`;
357
+ else startScreen = screen;
358
+ }
348
359
  }
349
360
  await client.memmap({ action: "clear" });
350
361
  for (const step of reason === undefined ? run.steps : []) {
@@ -421,14 +432,114 @@ export async function runFile(path: string, out: string): Promise<{ output: Reco
421
432
  done,
422
433
  ...(reason === undefined ? {} : { reason }),
423
434
  pc: formatC64Address(pc),
435
+ ...(startScreen === "skipped" ? { startScreen } : {}),
424
436
  files: [...files],
425
437
  observations,
426
438
  ...(expectations.length === 0 ? {} : { expectations, failedExpectations }),
427
439
  ...(Object.keys(traces).length === 0 ? {} : { traces }),
428
440
  };
429
441
  write("results.json", Buffer.from(`${JSON.stringify(results, null, 2)}\n`));
430
- return { output: { ...results, files: written, observations: Object.keys(observations), out }, failed: reason !== undefined || failedExpectations.length > 0 };
442
+ return { output: { ...results, files: written, out }, failed: reason !== undefined || failedExpectations.length > 0 };
431
443
  } finally {
432
444
  await client.close();
433
445
  }
434
446
  }
447
+
448
+ /** The name of the run file in a kept run, and the folder of the files that it starts from. */
449
+ const KEPT_RUN = "run.json";
450
+ const KEPT_INPUTS = "inputs";
451
+ /** A file name that a run wrote into --out: no folder, no "." or "..". */
452
+ const RESULT_FILE = /^(?!\.\.?$)[A-Za-z0-9._-]+$/;
453
+
454
+ /** A path of a run file that keep changed: the field, the old path and the new path. */
455
+ export interface KeptPath {
456
+ field: string;
457
+ from: string;
458
+ to: string;
459
+ }
460
+
461
+ /**
462
+ * Keeps a run as evidence in a folder that git keeps: the run file as
463
+ * run.json, results.json and each file that the run wrote into `out`, and
464
+ * each file in .c64-re-tools/local/ that the run file starts from (the
465
+ * program, the snapshot, the symbols and the snapshot steps) in inputs/. The
466
+ * run file gets the new paths of those files only; another path stays as it
467
+ * is. All files are read before the first write, and the target must not
468
+ * exist, so a refusal leaves nothing behind.
469
+ */
470
+ export function keepRun(path: string, out: string, target: string): { out: string; files: Written[]; paths: KeptPath[] } {
471
+ const run = readRun(path);
472
+ const raw = JSON.parse(readProjectFile(path).bytes.toString("utf8")) as { start: Record<string, unknown>; symbols?: unknown; steps: Array<Record<string, unknown>> };
473
+ const kept = projectRelative(target);
474
+ if (kept === PROJECT_DIRECTORY || kept.startsWith(`${PROJECT_DIRECTORY}/`)) {
475
+ throw new Refusal("invalid-input", `${target} is in ${PROJECT_DIRECTORY}/, and git does not keep a run there. Give a new folder outside it, for example runs/${run.name.replace(/[^A-Za-z0-9._-]+/g, "_")}.`);
476
+ }
477
+ if (existsSync(resolveProjectPath(kept))) throw new Refusal("conflict", `${target} exists. Give a new folder, or remove the old folder first.`);
478
+ checkOutputPath(kept, "folder", { what: target });
479
+ const results = (() => {
480
+ const file = `${out}/results.json`;
481
+ let value: unknown;
482
+ try {
483
+ value = JSON.parse(readProjectFile(file).bytes.toString("utf8"));
484
+ } catch (error) {
485
+ if (isRefusal(error) && error.code === "not-found") throw new Refusal("not-found", `${out} has no results.json. Give the --out folder of a run of ${path}.`);
486
+ if (isRefusal(error)) throw error;
487
+ throw new Refusal("invalid-input", `${file} is not JSON: ${(error as Error).message}`);
488
+ }
489
+ if (!isObject(value) || value.name !== run.name || !Array.isArray(value.files) || !value.files.every((name) => typeof name === "string" && RESULT_FILE.test(name))) {
490
+ throw new Refusal("invalid-input", `${file} is not the result of the run ${run.name}. Give the --out folder of a run of ${path}.`);
491
+ }
492
+ return { file, names: value.files as string[] };
493
+ })();
494
+ if (results.names.includes(KEPT_RUN)) throw new Refusal("invalid-input", `the run wrote ${out}/${KEPT_RUN}, which is the name of the run file in a kept run. Give the step that writes it another name, and run again.`);
495
+ // The files of the project that the run file names in the local folder: each one once, in inputs/ with its own name.
496
+ const local = `${PROJECT_DIRECTORY}/${LOCAL_DIRECTORY}/`;
497
+ const inputs = new Map<string, { to: string; bytes: Buffer }>();
498
+ const used = new Set<string>();
499
+ const paths: KeptPath[] = [];
500
+ const keep = (field: string, file: unknown): string | undefined => {
501
+ if (typeof file !== "string" || file === "knowledge" || file === "none") return undefined;
502
+ let from: string;
503
+ try {
504
+ from = projectRelative(file);
505
+ } catch (error) {
506
+ // A path into another project of the group is not in this local folder.
507
+ if (isRefusal(error)) return undefined;
508
+ throw error;
509
+ }
510
+ if (!from.startsWith(local)) return undefined;
511
+ let input = inputs.get(from);
512
+ if (input === undefined) {
513
+ let bytes: Buffer;
514
+ try {
515
+ bytes = readProjectFile(file).bytes;
516
+ } catch (error) {
517
+ if (isRefusal(error)) throw new Refusal(error.code, `run ${path}: ${field}: ${error.message}`);
518
+ throw error;
519
+ }
520
+ const name = posix.basename(from);
521
+ const extension = posix.extname(name);
522
+ let unique = name;
523
+ for (let count = 2; used.has(unique.toLowerCase()); count++) unique = `${name.slice(0, name.length - extension.length)}-${count}${extension}`;
524
+ used.add(unique.toLowerCase());
525
+ input = { to: `${kept}/${KEPT_INPUTS}/${unique}`, bytes };
526
+ inputs.set(from, input);
527
+ }
528
+ paths.push({ field, from: file, to: input.to });
529
+ return input.to;
530
+ };
531
+ const moved = (holder: Record<string, unknown>, key: string, field: string) => {
532
+ const to = keep(field, holder[key]);
533
+ if (to !== undefined) holder[key] = to;
534
+ };
535
+ moved(raw.start, "program", "start.program");
536
+ moved(raw.start, "snapshot", "start.snapshot");
537
+ moved(raw as Record<string, unknown>, "symbols", "symbols");
538
+ raw.steps.forEach((step, index) => {
539
+ if (isObject(step) && "snapshot" in step) moved(step, "snapshot", `step ${index + 1}: snapshot`);
540
+ });
541
+ const outputs = [results.file, ...results.names.map((name) => `${out}/${name}`)].map((file) => ({ to: `${kept}/${posix.basename(file)}`, bytes: readProjectFile(file).bytes }));
542
+ const files = [...inputs.values(), ...outputs].map((file) => writeReported(file.to, file.bytes, { what: target }));
543
+ files.push(writeReported(`${kept}/${KEPT_RUN}`, `${JSON.stringify(raw, null, 1)}\n`, { what: target }));
544
+ return { out: kept, files, paths };
545
+ }
@@ -18,6 +18,7 @@ import { nameTable } from "#src/knowledge/names.ts";
18
18
  import { DEFAULT_SPACE } from "#src/knowledge/schema.ts";
19
19
  import { programImage } from "#src/knowledge/program.ts";
20
20
  import { listed } from "#src/script.ts";
21
+ import { passStartScreen } from "./start-screen.ts";
21
22
 
22
23
  export type Side = "reference" | "rebuild";
23
24
  export const SIDES: Side[] = ["reference", "rebuild"];
@@ -392,16 +393,20 @@ export function baselineName(checkpoint: number, label: string): string {
392
393
  return `test-${checkpoint}-${label}`.replace(/[^A-Za-z0-9._-]/g, "_").slice(0, 64);
393
394
  }
394
395
 
395
- /** Autostart that returns only when the program runs (runProgram), or INCONCLUSIVE with the reason. */
396
- async function startProgram(client: ViceSessionClient, program: string, side: Side): Promise<void> {
396
+ /**
397
+ * Autostart that returns only when the program runs (runProgram), and after the
398
+ * start screen of a loader program (passStartScreen), or INCONCLUSIVE with the reason.
399
+ */
400
+ async function startProgram(client: ViceSessionClient, program: string, side: Side, symbols: Map<string, number>): Promise<void> {
397
401
  const failed = await runProgram(client, program, readProjectFile(program).bytes);
398
402
  if (failed === "not-loaded") throw new Inconclusive(`the ${side} program was not in memory after ${LOAD_LIMIT_FRAMES} frames of autostart`);
399
403
  if (failed === "not-started") throw new Inconclusive(`the ${side} program did not start within ${RUN_LIMIT_FRAMES} frames of RUN; autostart runs only a program with a BASIC start line`);
404
+ const screen = await passStartScreen(client, symbols);
405
+ if (typeof screen === "object") throw new Inconclusive(`the ${side} side: ${screen.problem}`);
400
406
  }
401
407
 
402
408
  async function runSide(client: ViceSessionClient, scenario: Scenario, side: Side, symbols: Map<string, number>, files: boolean): Promise<Map<string, Observation>> {
403
409
  const observations = new Map<string, Observation>();
404
- const at = (location: Location) => resolve(location, symbols, side);
405
410
  // Each side starts from a hard reset, stopped at the reset vector, with the control ports released.
406
411
  await client.reset({ mode: "hard", run: false });
407
412
  for (const port of [1, 2] as const) {
@@ -416,7 +421,7 @@ async function runSide(client: ViceSessionClient, scenario: Scenario, side: Side
416
421
  for (const [index, step] of scenario.steps.entries()) {
417
422
  if (step.side !== undefined && step.side !== side) continue;
418
423
  try {
419
- checkpoint = await runStep(client, scenario, side, step, at, checkpoint, files, observations);
424
+ checkpoint = await runStep(client, scenario, side, step, symbols, checkpoint, files, observations);
420
425
  } catch (error) {
421
426
  // The step in the reason or the message: the scenario file has many steps.
422
427
  const where = `step ${index + 1} (${stepKindOf(step)})`;
@@ -433,8 +438,9 @@ async function runSide(client: ViceSessionClient, scenario: Scenario, side: Side
433
438
  const stepKindOf = (step: Step) => Object.keys(step).find((key) => STEP_KINDS.includes(key)) ?? "step";
434
439
 
435
440
  /** Runs one step of one side. Gives the number of the last checkpoint. */
436
- async function runStep(client: ViceSessionClient, scenario: Scenario, side: Side, step: Step, at: (location: Location) => number, last: number, files: boolean, observations: Map<string, Observation>): Promise<number> {
441
+ async function runStep(client: ViceSessionClient, scenario: Scenario, side: Side, step: Step, symbols: Map<string, number>, last: number, files: boolean, observations: Map<string, Observation>): Promise<number> {
437
442
  const subject = scenario[side];
443
+ const at = (location: Location) => resolve(location, symbols, side);
438
444
  let checkpoint = last;
439
445
  // Observe first: an observe step may also carry "registers" or "memory".
440
446
  if ("observe" in step) {
@@ -484,7 +490,7 @@ async function runStep(client: ViceSessionClient, scenario: Scenario, side: Side
484
490
  } else if ("load" in step) {
485
491
  await client.programLoad({ path: subject.program });
486
492
  } else if ("autostart" in step) {
487
- await startProgram(client, subject.program, side);
493
+ await startProgram(client, subject.program, side, symbols);
488
494
  } else if ("snapshot" in step) {
489
495
  await client.snapshotRestore(readProjectFile(step.snapshot).bytes);
490
496
  } else if ("normalize" in step) {
@@ -0,0 +1,27 @@
1
+ // The start screen of a loader program in VICE: the loader of a generated
2
+ // source shows it and waits for a key or a fire button that no step of a run
3
+ // or a scenario gives. Not each VICE can press a key of the keyboard matrix,
4
+ // so test and run let the program come to the wait, then set the PC to the
5
+ // code after the wait, as the check of the loader does. The replay core does
6
+ // the same in recording.ts.
7
+
8
+ import { formatC64Address } from "#src/c64.ts";
9
+ import type { ViceSessionClient } from "#src/host-client/vice-session.ts";
10
+ import { startScreenLabels } from "#src/knowledge/start-screen.ts";
11
+
12
+ /** The frames from RUN to the wait: the copies or the unpack of the loader, then the screen. */
13
+ export const START_SCREEN_FRAMES = 3000;
14
+
15
+ /**
16
+ * Goes past the start screen of a program whose symbols have the labels of a
17
+ * shown start screen. "skipped" when it went past, "none" when the program
18
+ * shows no start screen, or the problem when the program did not come to the wait.
19
+ */
20
+ export async function passStartScreen(client: Pick<ViceSessionClient, "runUntil" | "registersSet">, symbols: ReadonlyMap<string, number>): Promise<"skipped" | "none" | { problem: string }> {
21
+ const labels = startScreenLabels(symbols);
22
+ if (labels === undefined) return "none";
23
+ const reached = await client.runUntil({ target: { kind: "address", address: labels.wait, space: "c64" }, timeoutFrames: START_SCREEN_FRAMES });
24
+ if (!reached.reached) return { problem: `the program did not come to the wait of its start screen at ${formatC64Address(labels.wait)} in ${START_SCREEN_FRAMES} frames; it stopped at ${formatC64Address(reached.pc)}` };
25
+ await client.registersSet("c64", { pc: labels.continue });
26
+ return "skipped";
27
+ }