@henols/c64-re-tools 2.3.0-rc.5 → 2.3.0-rc.6

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 (61) hide show
  1. package/package.json +1 -1
  2. package/skills/c64-assembler/SKILL.md +149 -78
  3. package/skills/c64-assembler/scripts/assembler.ts +18 -11
  4. package/skills/c64-basic/SKILL.md +90 -52
  5. package/skills/c64-basic/scripts/basic.ts +15 -6
  6. package/skills/c64-development/SKILL.md +46 -73
  7. package/skills/c64-disk/SKILL.md +145 -73
  8. package/skills/c64-disk/scripts/disk.ts +11 -6
  9. package/skills/c64-docs/SKILL.md +199 -118
  10. package/skills/c64-docs/references/page-types.md +3 -3
  11. package/skills/c64-docs/references/style.md +9 -13
  12. package/skills/c64-docs/scripts/docs.ts +39 -15
  13. package/skills/c64-docs/scripts/lib/links.ts +1 -1
  14. package/skills/c64-docs/scripts/lib/reference.ts +2 -2
  15. package/skills/c64-docs/scripts/lib/source-map.ts +2 -2
  16. package/skills/c64-export/SKILL.md +21 -45
  17. package/skills/c64-knowledge/SKILL.md +489 -233
  18. package/skills/c64-knowledge/scripts/knowledge.ts +31 -26
  19. package/skills/c64-memory-map/SKILL.md +131 -65
  20. package/skills/c64-memory-map/scripts/memory-map.ts +19 -11
  21. package/skills/c64-packer/SKILL.md +120 -72
  22. package/skills/c64-packer/scripts/packer.ts +10 -3
  23. package/skills/c64-provenance/SKILL.md +301 -173
  24. package/skills/c64-provenance/scripts/lib/library.ts +6 -6
  25. package/skills/c64-provenance/scripts/provenance.ts +85 -36
  26. package/skills/c64-reverse-engineering/SKILL.md +55 -72
  27. package/skills/c64-source/SKILL.md +316 -224
  28. package/skills/c64-source/scripts/lib/export.ts +9 -14
  29. package/skills/c64-source/scripts/lib/loader.ts +5 -5
  30. package/skills/c64-source/scripts/lib/source.ts +5 -5
  31. package/skills/c64-source/scripts/source.ts +106 -21
  32. package/skills/c64-static-analysis/SKILL.md +188 -112
  33. package/skills/c64-static-analysis/scripts/static-analysis.ts +29 -9
  34. package/skills/c64-testing/SKILL.md +272 -166
  35. package/skills/c64-testing/references/recording-format.md +11 -12
  36. package/skills/c64-testing/references/scenario-format.md +20 -5
  37. package/skills/c64-testing/scripts/lib/diff-files.ts +8 -8
  38. package/skills/c64-testing/scripts/lib/recording.ts +7 -7
  39. package/skills/c64-testing/scripts/lib/replay.ts +7 -7
  40. package/skills/c64-testing/scripts/lib/runs.ts +6 -7
  41. package/skills/c64-testing/scripts/lib/scenario.ts +12 -6
  42. package/skills/c64-testing/scripts/testing.ts +35 -15
  43. package/skills/c64-unpacker/SKILL.md +273 -127
  44. package/skills/c64-unpacker/scripts/lib/loads.ts +3 -3
  45. package/skills/c64-unpacker/scripts/unpacker.ts +70 -11
  46. package/skills/emulator/SKILL.md +12 -12
  47. package/src/errors.ts +22 -2
  48. package/src/host/vice/session.ts +1 -1
  49. package/src/host-client/entry-state.ts +1 -1
  50. package/src/host-client/image.ts +3 -3
  51. package/src/host-client/steps.ts +1 -1
  52. package/src/knowledge/expression.ts +1 -1
  53. package/src/knowledge/names.ts +2 -3
  54. package/src/knowledge/program.ts +2 -3
  55. package/src/knowledge/write.ts +2 -2
  56. package/src/mcp/inputs.ts +1 -1
  57. package/src/mcp/tools/input.ts +1 -1
  58. package/src/mcp/tools/media.ts +1 -1
  59. package/src/native/exomizer.ts +2 -2
  60. package/src/project.ts +2 -2
  61. package/src/script.ts +164 -75
@@ -1,224 +1,330 @@
1
1
  ---
2
2
  name: c64-testing
3
- description: Use this skill to test if a rebuilt or changed C64 program behaves as the original. It runs one scenario on the original and then on the rebuild in an emulator. It compares memory, registers, chip state and the screen with explicit rules, and gives PASS, FAIL or INCONCLUSIVE. It also makes a checklist for a human playtest. Use its run command to explore a program with many steps, for example to visit each room or level. A run keeps screens, coverage maps and snapshots as files. An expect step in a run compares memory and registers with expected values, for a new program or a fix that has no original. Use its record and replay commands to keep a long play session of the original and replay it on each rebuild. Do not use it to find the cause of a difference.
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.
4
4
  ---
5
5
 
6
- # c64-testing
6
+ # C64 testing
7
7
 
8
- ## Purpose
8
+ Use this script to test a rebuild or a changed C64 program against the original, or against expected values.
9
+ Use only the commands of the script. Do not compare machine states or replay play sessions in another way.
9
10
 
10
- Test if a rebuild or a changed program behaves as the original in a scenario. Test if a program has the expected values in a run. Give one result: PASS, FAIL or INCONCLUSIVE.
11
+ ```bash
12
+ node <skill>/scripts/testing.ts <command>
13
+ ```
11
14
 
12
- A PASS proves only the behavior that the scenario does and observes. It does not prove that the two programs are equal in all behavior.
15
+ `<skill>` is the base directory of this skill. Run the script with `node`. You can run it from any directory.
16
+ Each command in this skill, for example `test tests/moves-left.json`, goes in the place of `<command>`.
17
+ Each command prints one JSON envelope on stdout. See the section "JSON output".
18
+ To get the command list, run the script with no arguments.
13
19
 
14
- ## Inputs
20
+ ---
15
21
 
16
- - The original program and the rebuild: PRG files in the project.
17
- - The symbols of each side. For the original, the project knowledge. For the rebuild, the JSON output of the c64-assembler skill in a file.
18
- - A scenario file: the steps, the checkpoints and the observations. See [references/scenario-format.md](references/scenario-format.md).
22
+ ## Select the command
19
23
 
20
- ## Tools
24
+ | Goal | Command |
25
+ |---|---|
26
+ | Compare the rebuild with the original in a scenario | `test tests/moves-left.json` |
27
+ | Keep the screens and all differing bytes of a FAIL | `test tests/moves-left.json --out .c64-re-tools/local/results/moves-left` |
28
+ | Do many steps on one program and keep the results as files | `run .c64-re-tools/local/runs/rooms/run.json --out .c64-re-tools/local/runs/rooms` |
29
+ | Test a new program or a correction with expected values | `run tests/title.json --out .c64-re-tools/local/runs/title` |
30
+ | Record a play session of a person on the original | `record tests/record/start.json --out tests/recordings/play1 --play --joystick 1` |
31
+ | Record a session from steps only | `record tests/record/rooms.json --out tests/recordings/rooms` |
32
+ | Make sure that a recording replays on the original | `replay tests/recordings/rooms` |
33
+ | Compare the rebuild with a recording | `replay tests/recordings/rooms --checkpoint main_loop --state room --state lives --pin random_ptr:2 --rebuild build/game.prg --symbols build/game.json --out .c64-re-tools/local/results/rooms` |
34
+ | Find what changed between two snapshot files | `diff .c64-re-tools/local/runs/rooms/before.vsf .c64-re-tools/local/runs/rooms/after.vsf` |
35
+ | Find what changed between two observations of runs | `diff .c64-re-tools/local/runs/rooms/results.json:room0 .c64-re-tools/local/runs/rooms/results.json:room3` |
36
+ | Find what changed between two memory files of runs | `diff .c64-re-tools/local/runs/a/all.bin .c64-re-tools/local/runs/b/all.bin --gap 4` |
37
+ | Make a checklist for a human playtest | `checklist tests/moves-left.json --item 'FIRE starts the game.'` |
38
+
39
+ ## Programs, files and names
40
+
41
+ - The original program and the rebuild are PRG files in the project. The script refuses a disk, tape or cartridge image. Extract the program file from the image first.
42
+ - The original gets its names from the project knowledge. Give `"symbols": "knowledge"` for the original.
43
+ - The rebuild gets its names from the symbol file of its build. Build the rebuild with a symbol file that has all symbols, also the constants that the source does not use.
44
+ - You write the scenario file, the run file and the record file. Their formats are in the files of the section "Reference".
45
+ - `<recording>` is the `--out` folder of `record`.
46
+ - `--checkpoint` is a routine that the program executes one time in each pass of its game logic, for example the main loop. Do not use an interrupt handler. Get the name from the project knowledge.
47
+ - `--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.
48
+ - 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.
49
+ - `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.
50
+
51
+ ### Paths and the project folder
52
+
53
+ - Give each path relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
54
+ - If the working directory is not in a project, give `--project <folder>` to each command. If the working directory has projects below it, the script refuses and lists them.
55
+ - An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Put an address in single quotes in a shell.
56
+ - A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
57
+ - Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
58
+ - Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
59
+ - The script refuses an `--out` path in `.c64-re-tools/knowledge/` and the index of the knowledge. Change the project knowledge only with the commands that change it.
60
+ - The script refuses a folder where the command writes a file. It refuses a file where the command writes a folder.
61
+ - When a file is the evidence for a finding in the project knowledge, move it out of `.c64-re-tools/local/` first. The project knowledge refuses evidence in that folder.
62
+ - Do not move a coverage map after you put it into the project knowledge. The knowledge refers to the map by its path at that time.
63
+ - Put a run that is evidence in `runs/<name>/`, with its run file, its results and its snapshot files. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
64
+ - A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
21
65
 
22
- The script runs the scenario on the original and then on the rebuild. Before each side, it does a hard reset. The CPU then stops at the reset vector.
66
+ ## Flags
67
+
68
+ Each flag applies only to the commands in the table. On another command, the script refuses the flag.
69
+
70
+ | Flag | Command | Effect |
71
+ |---|---|---|
72
+ | `--out <dir>` | `test` | With a FAIL, write the files of the differences into this folder. No folder by default. |
73
+ | `--max-listed <n>` | `test` | List at most n differing bytes of each memory item. The default is 50. The count is always in the body. |
74
+ | `--out <dir>` | `run` | The folder for the files of the steps and `results.json`. Required. |
75
+ | `--out <dir>` | `record` | The recording folder, for example `tests/recordings/<name>`. Required. |
76
+ | `--play` | `record` | A person plays after the steps. Off by default. |
77
+ | `--joystick <1\|2>` | `record` | With `--play`: the joystick port at the start. The default is 2. |
78
+ | `--http-port <n>` | `record` | With `--play`: the port of the page. The default is 6465. |
79
+ | `--checkpoint <routine>` | `replay` | The routine of the checkpoints. Each entry of the routine is a checkpoint. The default is the comparison of the record file. |
80
+ | `--state <item>` | `replay` | A memory item to compare at each checkpoint. Give it again for each item. |
81
+ | `--pin <item>` | `replay` | Random state in RAM. At each checkpoint, the rebuild gets the values of the original there. Give it again for each item. |
82
+ | `--rebuild <prg>` | `replay` | The rebuild to compare with the original. Without it, the script replays only on the original. |
83
+ | `--symbols <file>` | `replay` | The symbol file of the rebuild. The default is the symbols of the recording. |
84
+ | `--out <dir>` | `replay` | With a FAIL, write the RAM of each side at the first different checkpoint into this folder. |
85
+ | `--gap <n>` | `diff` | Join changed ranges across at most n equal bytes. The default is 0. |
86
+ | `--max-listed <n>` | `diff` | List at most n items of each list. The default is 50. |
87
+ | `--ntsc` | `diff` | The snapshot files are of an NTSC machine. The default is PAL. |
88
+ | `--address <address>` | `diff` | The address of the first byte of a memory file of less than 64 KiB. The default is `$0000`. |
89
+ | `--out <file>` | `diff` | Also write all ranges and all changed registers to this file. |
90
+ | `--item <text>` | `checklist` | A line for this program. Give it again for each line. |
23
91
 
24
- ```
25
- node <skill>/scripts/testing.ts test tests/moves-left.json --out .c64-re-tools/local/results/moves-left
26
- node <skill>/scripts/testing.ts checklist tests/moves-left.json --item 'FIRE starts the game.'
27
- ```
28
-
29
- `testing.ts test` gives `result`: PASS, FAIL or INCONCLUSIVE. With `--out`, a FAIL writes files into that directory: both screens and the difference image for each screen difference, and `memory.json`. `memory.json` has all bytes of each memory item that differs, and each byte that differs. `files` in the result names them. A PASS writes no files. To keep the screens of a PASS, use a run (below).
92
+ ---
30
93
 
31
- `testing.ts checklist` gives a Markdown checklist for a human tester in `text`.
94
+ ## Compare and run
32
95
 
33
- Before the test starts, `testing.ts test` examines each file that the scenario names: the program and the symbols of each side, and each snapshot file. A missing file gives `not-found`. A program must be a PRG. The script refuses a disk, tape or cartridge image.
96
+ ### `test <scenario.json>`
34
97
 
35
- ### Runs
98
+ The script runs the scenario on the original and then on the rebuild. Before each side, it does a hard reset. The CPU then stops at the reset vector.
99
+ Before the test starts, the script examines the scenario and each file that it names. The section "Checks" of `references/scenario-format.md` gives each refusal.
36
100
 
37
- A run does steps on one program, with no comparison, and keeps the results as files. Use it for many steps. One run replaces many emulator calls, for example a visit to each room of a game.
101
+ `body` holds:
38
102
 
39
- ```
40
- node <skill>/scripts/testing.ts run .c64-re-tools/local/runs/rooms/run.json --out .c64-re-tools/local/runs/rooms
41
- ```
103
+ - `result`: `PASS`, `FAIL` or `INCONCLUSIVE`.
104
+ - `checkpoints`: the names of the checkpoints.
105
+ - `differences`: with a FAIL, each difference with its `checkpoint` and the item in `what`.
106
+ - A memory item gives `bytes`. `bytes.count` is the number of differing bytes. `bytes.listed` gives the first bytes, each with `address`, `original` and `rebuild`.
107
+ - Another item gives the `original` value and the `rebuild` value.
108
+ - `excluded`: each byte that an `exclude` left out of the comparison, with its `reason`.
109
+ - `files`: with `--out` and a FAIL, the files that the script wrote. These are both screens and the difference image for each screen difference. `memory.json` has all bytes of each memory item that differs, and each byte that differs.
110
+ - `reason`: with an INCONCLUSIVE, why the script could not compare.
42
111
 
43
- The run file gives where to start (a program, or a snapshot file), the steps, and optional symbols. A run file has no names unless it gives `"symbols": "knowledge"` or a JSON file of names. To go on from the live emulator, save its state with `c64_snapshot` action `save` and `out`, and start the run from that file. A run has the action steps of a scenario: `write`, `registers`, `joystick`, `type`, `frames` and `runUntil`. It also has these steps:
112
+ The pc and each address are `$xxxx`. Memory is lowercase hex. Other register values and chip values are decimal numbers.
44
113
 
45
- | Step | Effect |
46
- |---|---|
47
- | `{ "snapshot": ".c64-re-tools/local/snapshots/room0.vsf" }` | Restore a snapshot file. |
48
- | `{ "save": "room3" }` | Write the state now to `room3.vsf` in the output directory. |
49
- | `{ "screen": "room3" }` | Write the screen to `room3.png`. |
50
- | `{ "coverage": "room3" }` | Write the coverage map since the start or the last coverage step to `room3.bin`, then clear the map. Add the map to the knowledge with `coverage` of the c64-knowledge skill. |
51
- | `{ "observe": "room3", "memory": ["$c100"], "registers": true }` | Record memory, registers, `vicii` or `sprites` in `results.json`. |
52
- | `{ "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. A point has the `kind` `exec`, `read` or `write`, a `start` and an optional `end`. `maxHits` limits the hits. |
53
- | `{ "observe": "all3", "memory": "all" }` | Write all 64 KiB of RAM to `all3.bin`, also the RAM under the ROMs and the I/O area. |
54
- | `{ "expect": "title", "memory": [{ "address": "$0400", "text": "HELLO" }], "registers": { "a": 0 } }` | Compare memory and registers with the expected values. `data` gives hex bytes, `text` gives screen codes. `mask` compares only some bits. A value that is not equal does not stop the run. |
114
+ Do this for each result:
55
115
 
56
- Each step that writes a file must have its own file name. The script refuses a run where two steps write the same file, for example `{ "coverage": "x" }` and `{ "observe": "x", "memory": "all" }`, which both write `x.bin`. The script also examines the start program and each snapshot file before the run starts.
116
+ - `PASS`: all observations are equal, or the differences are in the allowed tolerance. A PASS proves only the behavior that the scenario does and observes. A PASS writes no files. To keep the screens of a PASS, do a run.
117
+ - `FAIL`: `hint` tells you to examine the first difference in the emulator at its checkpoint. Without `--out`, `hint` also tells you to give `--out`.
118
+ - `INCONCLUSIVE`: this is not a failure of the program. Do not report a FAIL. `hint` tells you to correct the cause. Then run `test` again. `reason` gives the cause:
119
+ - `step N (kind): ...`: the step failed on one side.
120
+ - "did not reach the checkpoint": one side did not get to the checkpoint in the frame limit. Find the reason in the emulator.
121
+ - "has no symbol": one side has no symbol with that name. Add the name to the project knowledge or to the source of the rebuild.
122
+ - "no emulator" or "could not run": the emulator failed. Give `reason` to the user.
57
123
 
58
- A memory item can have `"view": "ram"`. Then it reads the RAM under the ROMs and the I/O area, for example code at `$e000` under the KERNAL. The default view `cpu` reads as the CPU sees memory. An item larger than 4096 bytes goes into its own `.bin` file, and `results.json` gives the file name.
124
+ Traps:
59
125
 
60
- See [references/scenario-format.md](references/scenario-format.md), section Runs. `result` is PASS when all steps ran and each `expect` step passed. It is FAIL when a step did not run, and `reason` tells why. It is also FAIL when an `expect` step found a value that is not equal. Then `failedExpectations` names the steps, and `expectations` gives the expected and the actual values. A long run can need more time than one shell call. Then run it in the background.
126
+ - A FAIL with only a `screen` difference: add `vicii` or `sprites` to the observation. Then you find the chip state that is different.
127
+ - A program that uses random numbers: set the random seed with a `write` step on both sides. If you cannot set it, observe only values that do not depend on the random numbers.
128
+ - The two sides start differently, for example the original after a cracked intro. Give a `side` to the steps that only one side needs. Then make the memory the same with a `normalize` step.
129
+ - `normalize` needs the entry state of a capture in the project knowledge. If the knowledge has no capture, the script refuses. Then capture the unpacked program at its entry point, and put the capture image into the project knowledge.
130
+ - The frame counts of the sides are different by one frame. The sides got to the same address at different raster positions. Do not synchronize on an interrupt handler. Synchronize on a value that the interrupt changes, with a `runUntil` step with a `memory` target. Or use an `address` target with a `raster` condition.
131
+ - A byte cannot be the same on both sides, for example a read-only collision register. Use `exclude` with the reason. Do not use `exclude` to hide a real difference.
132
+ - Do not add a mask or a tolerance only to make a test pass. A tolerance must have a reason in the behavior of the program.
133
+ - `invalid-input` or `not-found` that names a step or a file: correct the scenario file or the file as `hint` tells. Then run `test` again.
61
134
 
62
- ### Recordings
135
+ ### `run <run.json>`
63
136
 
64
- A recording keeps a session of the original program, for example a play through some rooms of a game. A replay gives the same input to a rebuild and compares the game state. Make the recordings early, before you change the program. A recording needs no names. Its coverage also helps the static analysis.
137
+ The script does the steps of the run file on one program, with no comparison. It writes the files of the steps and `results.json` into `--out`. One run replaces many emulator calls, for example a visit to each room of a game.
138
+ The run starts from a program or from a snapshot file. To continue from the state of the emulator, save that state to a snapshot file in the emulator. Then start the run from that file.
139
+ Before the run starts, the script examines the run file, each file that it names and each name of the steps. The section "Checks" of `references/scenario-format.md` gives each refusal.
65
140
 
66
- The emulator tools cannot examine the C64 of a recording or a replay. That C64 has no disk drive. The program must be a PRG file.
141
+ `body` holds:
67
142
 
68
- 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. Make a scripted recording only for a part that the sessions of the user do not have, or when the user cannot play.
143
+ - `result`: `PASS` when all steps ran and each `expect` step passed. Else `FAIL`.
144
+ - `completed`, `steps` and `done`: if the run completed, the number of steps, and the number of steps that ran.
145
+ - `reason`: why a step did not run.
146
+ - `pc`: the pc at the end of the run.
147
+ - `files`: each file that the run wrote.
148
+ - `observations`: the names of the observations. `results.json` in `--out` has their values.
149
+ - `expectations`: for each `expect` step, `pass`, `count` and at most 16 `mismatches` with the expected and the actual value.
150
+ - `failedExpectations`: the names of the `expect` steps that did not pass.
151
+ - `traces`: for each `trace` step, its file, the count of hits, the frames and why the trace ended.
69
152
 
70
- ```
71
- node <skill>/scripts/testing.ts record tests/record/start.json --out tests/recordings/play1 --play --joystick 1
72
- ```
153
+ With a FAIL, `hint` tells you to read `reason` or `failedExpectations`. A value that is not equal does not stop the run.
73
154
 
74
- - With `--play`, a person plays the program after the steps of the record file. The steps can start the program, for example a key for an intro.
75
- - The script writes the address of a page to stderr. Give the address to the user.
76
- - The page shows the screen after the steps. The C64 is frozen until the user presses Enter or clicks Start. Tell the user to read the screen first.
77
- - Give `--joystick` the port that the program reads: port 2 is `$DC00`, and port 1 is `$DC01`. Find the port in the code or in the knowledge. If you do not know the port, use 2. Tell the user that F9 changes the port.
78
- - The page has the full C64 keyboard and the joystick. F10 changes the arrow keys and space between the joystick and the C64 keys. A gamepad is always the joystick. See the key maps in [references/recording-format.md](references/recording-format.md).
79
- - RESTORE (Page Up) is not a read. The recording keeps it as an event, and the replay presses it again at the same read.
80
- - End (F12) stops the C64 and freezes the screen. Then the script writes the recording folder. Run the script in the background.
81
- - Cancel (F11) stops the session. The script writes no folder and gives `recorded: false` with the reason. Then ask the user what to do. Do not make a scripted recording in its place.
155
+ Traps:
82
156
 
83
- A scripted recording has only steps. See [references/recording-format.md](references/recording-format.md). The steps are `frames`, `joystick`, `press`, `type`, `write`, `registers` and `runUntil` with an `address` or `memory` target. `press` pushes keys of the keyboard matrix. `type` puts at most 10 keys into the keyboard queue of the KERNAL.
157
+ - A long run can need more time than one shell call. Then run the command in the background.
158
+ - Add each coverage map of a run to the project knowledge as coverage.
84
159
 
85
- ```
86
- node <skill>/scripts/testing.ts record tests/record/rooms.json --out tests/recordings/rooms
87
- node <skill>/scripts/testing.ts replay tests/recordings/rooms --checkpoint main_loop --state room --state lives --pin random_ptr:2 --rebuild build/game.prg --symbols build/game.json
88
- ```
160
+ ---
89
161
 
90
- - `testing.ts record` writes the recording folder. `result` is PASS when it recorded the session, and FAIL when the session did not complete. `executed` gives the instructions in the coverage map.
91
- - `testing.ts replay` first replays the recording on the original. The original must end the session with the recorded state. Then the script replays the recording on the rebuild and compares the state at each checkpoint.
92
- - `--checkpoint` gives a routine, and `--state` gives each memory item to compare. Use the names that the knowledge has at the time of the replay. A `$` address is an address of the original. On the rebuild, it moves with the name before it.
93
- - `result` of the replay is PASS, FAIL or INCONCLUSIVE. A FAIL gives the first checkpoint that is different and the state items that are different.
94
- - With `--out`, a FAIL writes the RAM of the two sides at that checkpoint. Compare the two files with `testing.ts diff`.
95
- - Without `--rebuild`, `testing.ts replay` only replays the recording on the original.
162
+ ## Recordings
96
163
 
97
- A checkpoint is one entry of a routine. Use a routine that the program executes one time in each pass of its game logic, for example the main loop. Do not use an interrupt handler.
164
+ A recording keeps a session of the original program, for example a play through some rooms of a game. A replay gives the same input to a rebuild and compares the game state. A recording needs no names.
98
165
 
99
- The input is the reads of the joystick ports and the keyboard matrix. It is also the reads of the four SID registers that a program can read: the paddles, the noise of voice 3 and its envelope. It is also the reads of `$DE00`-`$DFFF`, where a C64 without a cartridge gives the last byte on the bus. On a replay, the n-th read of each instruction gets the value of the n-th read in the recording. Thus a rebuild with different timing gets the same input and the same SID random numbers. A `press`, `joystick` or `frames` step is input. A `type`, `write`, `registers` or `runUntil` step is not input. The replay does that step again at the same read of the program.
166
+ - Make the recordings early, before you change the program.
167
+ - 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.
168
+ - Record a session from steps only for a part that the sessions of the user do not have, or when the user cannot play.
169
+ - 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.
170
+ - A finding that a recording shows can go into the project knowledge. Give the `recording.json` of the recording as its test evidence.
171
+ - The C64 of a recording has no disk drive. For a program that loads more files from a disk, use a scenario with `test`.
172
+ - The emulator cannot examine the C64 of a recording or a replay.
100
173
 
101
- A replay is deterministic. A replay has no random source and no clock: the same recording gives the same session, to the cycle. Sometimes the recording has no value for a read of an input. Then the read gets a fixed value: `$FF` for the joystick, keyboard and paddle registers, `$00` for the others. `idleReads` in the result counts these reads on the rebuild. On the original, such a read makes the result INCONCLUSIVE.
174
+ A replay is deterministic. The same recording gives the same session, to the cycle. The n-th read of an input at each instruction gets the value of the n-th read in the recording. Thus a rebuild with different timing gets the same input, also the same random values from the SID.
102
175
 
103
176
  Control each source of random numbers:
104
177
 
105
178
  - A program that reads a seed from the SID gets the recorded value. You do not need to do more.
106
179
  - A program that reads a seed from the raster line or a CIA timer: add the address to `inputs` of the record file. Do this only when the program does not wait in a loop on that address.
107
- - A program that keeps its random state in RAM: give that state with `--pin`. An example is a pointer into a random table that moves each frame. At each checkpoint, the rebuild gets the values of the original there. A FAIL where an enemy or an event is different, but the input is the same, often shows that a pin is missing.
180
+ - A program that keeps its random state in RAM: give that state with `--pin` of `replay`. An example is a pointer into a random table that moves each frame.
108
181
 
109
- Put a `runUntil` step with the checkpoint routine before a `registers` step. A `registers` step that sets the pc during an interrupt stops the program.
182
+ ### `record <record.json>`
110
183
 
111
- Commit the recording folder with the scenarios. A recording is not knowledge.
184
+ The script does the steps of the record file on the original program. Then it writes the recording folder into `--out`: `recording.json`, `reads.txt` and `coverage.bin`. The program must be a PRG file.
112
185
 
113
- ### Differences
186
+ `body` holds:
114
187
 
115
- ```
116
- node <skill>/scripts/testing.ts diff .c64-re-tools/local/runs/rooms/before.vsf .c64-re-tools/local/runs/rooms/after.vsf
117
- node <skill>/scripts/testing.ts diff .c64-re-tools/local/runs/rooms/results.json:room0 .c64-re-tools/local/runs/rooms/results.json:room3
118
- ```
188
+ - `result`: `PASS` when the script recorded the session. `FAIL` when the session did not complete.
189
+ - `recorded`: `true` or `false`.
190
+ - `out` and `files`: the recording folder and its files.
191
+ - `frames`, `inputSites` and `events`: the length of the session, the number of instructions that read input, and the number of events.
192
+ - `executed`: the number of instructions in the coverage map.
193
+ - `reason`: with a FAIL, why the session did not complete.
119
194
 
120
- `testing.ts diff` tells what changed between two states of one kind. Use it in place of your own compare script.
195
+ Do this for each result:
121
196
 
122
- - Two snapshot files: the changed ranges of the RAM and of the colour RAM, and the changed VIC-II, CIA, SID and CPU registers.
123
- - Two memory files of a run: the changed ranges. For a file of less than 64 KiB, `--address` gives the address of its first byte.
124
- - Two observations of runs, also of one run: the changed memory items and registers. `compared` gives the count of items that both observations have. With `compared: 0`, `reason` tells what each observation has. Then the diff compared nothing, and the observations are not equal.
197
+ - `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.
198
+ - `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.
199
+ - 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.
200
+ - `executed` is 0: the program never read its input from RAM, so the coverage map is empty. The recording can still replay.
125
201
 
126
- For two snapshot files, `$00` and `$01` are the CPU port of the snapshot: the direction register and the data register. They are not the RAM under the port. `--ntsc` is only for snapshot files, and `--address` is only for memory files. The script refuses these options for the other kinds.
202
+ With `--play`, a person plays the program after the steps. The steps can start the program, for example a key for an intro.
127
203
 
128
- `registers` gives each changed register and chip value. `cpu.pc` is a `$` address. Each CPU flag is `cpu.flags.<flag>`, for example `cpu.flags.c`, with `true` or `false`.
204
+ - The script writes the address of a page to stderr. Give the address to the user.
205
+ - The page shows the screen after the steps. The C64 is frozen until the user pushes Enter or clicks Start. Tell the user to read the screen first.
206
+ - Tell the user that F9 changes the joystick port.
207
+ - The page has the full C64 keyboard and the joystick. F10 changes the arrow keys and space between the joystick and the C64 keys. A gamepad is always the joystick. The key maps are in `references/recording-format.md`.
208
+ - End (F12) stops the C64 and freezes the screen. Then the script writes the recording folder. Run the command in the background.
209
+ - Cancel (F11) stops the session. The script writes no folder.
129
210
 
130
- The script refuses a snapshot that does not restore. An example is a PAL snapshot with `--ntsc`. Give `--ntsc` only for snapshots of an NTSC machine.
211
+ Traps:
131
212
 
132
- `--gap N` joins ranges across N equal bytes. `--out` writes all ranges and all changed registers to a project file. The file uses the names of the result.
213
+ - Put a `runUntil` step with the checkpoint routine before a `registers` step. A `registers` step that sets the pc during an interrupt stops the program.
214
+ - A record file has no `raster` target and no `condition`. The script refuses them.
133
215
 
134
- ### Calling the script
216
+ ### `replay <recording>`
135
217
 
136
- - Call a script as `node <skill>/scripts/<script>.ts <command> [subjects] [options]`. The command comes first.
137
- - `<script>.ts --help` lists the commands. `<script>.ts <command> --help` gives the subjects and the options of one command. The help is JSON: `{"text": "..."}`.
138
- - An address is `$` and 1 to 4 hex digits, for example `'$c000'` or `'$fb'`, or a name. A name is a symbol, else an analyzer name that only one analyzer gives. Quote an address in a shell.
139
- - A range is `<start>-<end>`, for example `'$c000-$cfff'`. In a JSON file, a range is `start` and `end`.
140
- - Bytes in a JSON file are hex in a field `data`, for example `"data": "a900"`.
141
- - The script examines each `--out` path before it starts work. It refuses a path in `.c64-re-tools/knowledge/` and the index of the knowledge, because only c64-knowledge writes them. It refuses a folder where the command writes a file, and a file where the command writes a folder.
142
- - The result is one JSON object on one line. A file that the script writes shows as `{"out", "bytes", "sha256"}`. A list shows as `{"count", "listed"}`, and `rest` tells where to get the rest of a long list.
143
- - An error is `{"error": {"code": "...", "message": "..."}}`. The message tells what is wrong and what to do.
144
- - The exit status is 0 for done or PASS, 1 for FAIL, 2 for an error and 3 for INCONCLUSIVE.
218
+ The script first replays the recording on the original. The original must end the session with the recorded state. With `--rebuild`, the script then replays the recording on the rebuild and compares the state at each checkpoint. Without `--rebuild`, it replays only on the original.
145
219
 
146
- ### Project folder
220
+ `--checkpoint` and `--state` go together. `--pin` needs both of them. `--symbols` needs `--rebuild`. Give at most 16 `--state` and `--pin` items. Without `--checkpoint`, the script uses the comparison of the record file.
221
+ A `$` address is an address of the original. On the rebuild, it moves with the name before it.
147
222
 
148
- - Paths are relative to the project folder. The project folder is the nearest folder at or above the working directory that holds `.c64-re-tools/`.
149
- - If the working directory is not in a project and has projects below it, the script refuses and lists them. Then give `--project <folder>` to each script.
150
- - Write each file that you make for your work in `.c64-re-tools/local/` of the project. Git ignores that folder. Examples are results, batches, step files, runs, snapshots and memory dumps.
151
- - Move a file out of `.c64-re-tools/local/` only when it is the evidence for a finding. Move it before you give it to `--evidence test:<file>` or `--evidence file:<file>` of c64-knowledge. These two refuse a file in `.c64-re-tools/local/`.
152
- - Do not move a coverage map after `coverage` of c64-knowledge imported it. `--evidence coverage:<map>` names the map by its path at the import. The knowledge keeps the coverage and the SHA-256 of the map, so the evidence stays valid.
153
- - Put a run that is evidence in `runs/<name>/`, with its run file, its results and the snapshot files that it uses. Change the paths in the run file to the new paths. Then git keeps them, and another person can do the run again.
154
- - A shell redirect (`>`) is relative to the working directory, not to the project folder. From the folder above the project, write `<folder>/.c64-re-tools/local/result.json`.
223
+ `body` holds `result`, `side`, `firstDifference`, `reason` and `files`. The section "Replay" of `references/recording-format.md` gives each field.
224
+
225
+ Do this for each result:
226
+
227
+ - `PASS`: each checkpoint of the rebuild has the state of the original. Without `--rebuild`, the recording replays on the original.
228
+ - `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.
229
+ - `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.
230
+ - `FAIL` with no `firstDifference`: the rebuild did not get to all checkpoints. `reason` gives the number. Examine the rebuild in the emulator after its last checkpoint.
231
+ - `INCONCLUSIVE`: `reason` gives the cause:
232
+ - "does not reproduce": the original does not end the session with the recorded state. Record the session again.
233
+ - "never came to the checkpoint": the original did not execute the checkpoint routine in the session. Give another routine.
234
+ - "is not the program of the recording": the program file changed after the recording. Record the session again.
235
+
236
+ Traps:
237
+
238
+ - `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.
239
+ - The script refuses a recording of version 2.0 with `invalid-input`. Record the session again.
240
+
241
+ ---
242
+
243
+ ## Other commands
244
+
245
+ ### `diff <a> <b>`
246
+
247
+ The script tells what changed between two states of one kind. Use it in place of your own compare script.
248
+
249
+ `body` holds `a` and `b`, and the parts that apply to the kind of state:
250
+
251
+ - `memory`: the changed ranges of the RAM. `changedBytes` is the number of changed bytes. Each range in `listed` has `start`, `end`, and the bytes `a` and `b`.
252
+ - `colorRam`: with two snapshot files, the changed ranges of the colour RAM.
253
+ - `registers`: each changed register and chip value, with `name`, `a` and `b`. `cpu.pc` is a `$` address. Each CPU flag is `cpu.flags.<flag>`, for example `cpu.flags.c`, with `true` or `false`.
254
+ - `observed`: with two observations, each changed memory item.
255
+ - `compared`: with two observations, the count of items that both observations have. With `compared: 0`, `reason` tells what each observation has. Then the diff compared nothing, and the observations are not equal.
256
+ - `out`, `bytes` and `sha256`: with `--out`, the file. It uses the field names of the body.
257
+
258
+ Traps:
259
+
260
+ - With two snapshot files, `$00` and `$01` are the CPU port of the snapshot: the direction register and the data register. They are not the RAM under the port.
261
+ - `--ntsc` is only for snapshot files. `--address` is only for memory files. The script refuses them for the other kinds.
262
+ - The script refuses a snapshot file that does not restore. An example is a PAL snapshot with `--ntsc`. Give `--ntsc` only for snapshots of an NTSC machine.
263
+
264
+ ### `checklist <scenario.json>...`
265
+
266
+ The script makes a checklist for a human tester. `body.text` is the checklist in Markdown. It has a line for each checkpoint of the scenarios, each `--item`, and the behavior that only a person can judge.
267
+ Give the checklist to the human tester. Do not put the results of the playtest into the project knowledge.
268
+
269
+ ---
155
270
 
156
271
  ## Workflow
157
272
 
158
273
  1. Write the scenario file. Start the steps with a frame count, for example `{ "frames": 150 }`. Each side starts at the reset vector, and the C64 needs these frames to start.
159
- 2. Use symbol names, for example `player_x`, not fixed addresses. Each side finds the name in its own symbols. Use a `$` address only when both programs use the same address.
274
+ 2. Use symbol names, for example `player_x`, not `$` addresses. Each side finds the name in its own symbols. Use a `$` address only when both programs use the same address.
160
275
  3. Make each checkpoint a condition, for example a `runUntil` step with an `address` target at a routine. Do not wait for a time.
161
- 4. Write the symbol file of the rebuild with `--out-symbols build/game.json` of c64-assembler `build`. Give `--all-symbols`, so that the file also has the constants that the source does not use.
162
- 5. Run `testing.ts test`.
163
- 6. Read the result:
164
- - `PASS`: all observations are equal, or the differences are in the allowed tolerance.
165
- - `FAIL`: `differences` lists each difference with the checkpoint and the item. A memory item gives `bytes`: the count of the bytes that differ, and the first of these bytes. Each byte has the address, the original value and the rebuild value. `--max-listed` sets how many bytes it lists (default 50). `memory.json` in `--out` has all of them. Another item gives the original value and the rebuild value.
166
- - Each value has one form. The pc and each address are `$xxxx`. Memory is lowercase hex. Other register values and chip values are decimal numbers.
167
- - `INCONCLUSIVE`: `reason` tells why the script could not compare. This is not a failure of the program.
168
- 7. For a FAIL, examine the first difference with the emulator skill.
169
-
170
- ## Knowledge
171
-
172
- Read:
173
- - the symbols of the original from the project knowledge.
174
-
175
- Automatic write:
176
- - none.
177
-
178
- Write with c64-knowledge:
179
- - the coverage of a recording: `knowledge.ts coverage tests/recordings/<name>/coverage.bin`.
180
- - a finding that a recording shows, with `--evidence test:tests/recordings/<name>/recording.json`.
181
-
182
- Do not store:
183
- - test results
184
- - screenshots
185
- - playtest results
186
- - recordings.
187
-
188
- ## Result
189
-
190
- PASS, FAIL or INCONCLUSIVE, the checkpoints and the smallest differences that explain a FAIL.
191
-
192
- ## Failure and conflicts
193
-
194
- - `invalid-input`: the scenario file has an error. The message names the step. Change the step and run the test again.
195
- - INCONCLUSIVE, `step N (kind): ...`: the step failed on one side. `reason` names the step and why.
196
- - `invalid-input` that names the 2.0 form: a step, a memory item or a recording has a form of version 2.0. An example is `"at"` in place of `"address"`. The message gives the form to write. Change the file. Record a recording of version 2.0 again.
197
- - `not-found` before the run: a file of the scenario or the run file is missing, for example the rebuild program. Build the rebuild, or change the path.
198
- - INCONCLUSIVE, "did not reach the checkpoint": one side did not reach the checkpoint in the frame limit. Find the reason with the emulator skill. Do not report a FAIL.
199
- - INCONCLUSIVE, "has no symbol": one side has no symbol with that name. Add the name to the knowledge or to the rebuild source.
200
- - INCONCLUSIVE, "no emulator" or "could not run": the emulator failed. Tell the user the message.
201
- - `installation-incomplete` or `machine-unavailable`: stop the task. Give the message to the user and wait for the user. Do not install, start or change a tool yourself. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script.
202
- - `not-implemented`: the tool does not work in this setup. Give the message to the user. Do not use that tool or step again in this task.
203
- - A FAIL with only a `screen` difference: add `vicii` or `sprites` to the observation to find which chip state is different.
204
- - A program that uses random numbers: set the random seed with a `write` step on both sides. If that is not possible, observe only values that do not depend on the random numbers.
205
- - The two sides start differently, for example the original after a cracked intro. Give the steps that only one side needs a `side`. Then make the memory the same with a `normalize` step. It writes the entry state of the capture in the knowledge.
206
- - Frame counts drift by one frame between the sides: the sides got to the same address at different raster positions. Do not sync on an IRQ handler. Sync on a value that the IRQ changes, with a `runUntil` `memory` target. Or sync on an `address` target with a `raster` condition.
207
- - INCONCLUSIVE, "does not reproduce": the original does not end the session with the recorded state. Record the session again.
208
- - INCONCLUSIVE, "never came to the checkpoint": the original did not execute the checkpoint routine in the session. Give another routine.
209
- - INCONCLUSIVE, "is not the program of the recording": the program file changed after the recording. Record the session again.
210
- - A record result FAIL with `recorded` false: `reason` names the step that did not complete. Examples are a `runUntil` that did not reach its target, and a `type` step with too many keys. Change the step.
211
- - A record result with `executed` 0: the program never read its input from RAM, so the coverage map is empty. The recording can still replay.
212
- - A FAIL from a replay: compare the two RAM files of `--out` with `testing.ts diff`. Then examine the first different state item with the emulator skill.
213
- - A program that loads more files from a disk: a recording has no disk drive. Use a test scenario in the emulator.
214
- - A byte that cannot be the same on both sides, for example a read-only collision register: use `exclude` with the reason. Do not use `exclude` to hide a real difference.
215
-
216
- Do not add a mask or a tolerance only to make a test pass. A tolerance must have a reason in the behavior of the program.
217
-
218
- ## Handoffs
219
-
220
- - Find the cause of a difference → emulator
221
- - Find the code that causes it → c64-static-analysis
222
- - Rebuild after a correction → c64-assembler
223
- - Write or change a program, with expect steps as its tests → c64-development
224
- - Record a confirmed conclusion → c64-knowledge
276
+ 4. Build the rebuild with a symbol file that has all symbols.
277
+ 5. Run `test`.
278
+ 6. Read `body.result`, and do the action of the section of `test`.
279
+ 7. For a FAIL, examine the first difference in the emulator. Find the code that causes the difference.
280
+ 8. After a correction, build the rebuild again. Then run `test` again.
281
+ 9. Record each conclusion that a test proves in the project knowledge.
282
+
283
+ ---
284
+
285
+ ## JSON output
286
+
287
+ Each command prints one JSON envelope on one line on stdout. Notes go to stderr.
288
+
289
+ On success, the exit code is 0:
290
+
291
+ ```json
292
+ {"ok": true, "command": "<command>", "body": {}, "hint": "...", "nextAction": "..."}
293
+ ```
294
+
295
+ On failure, the exit code is 2:
296
+
297
+ ```json
298
+ {"ok": false, "command": "<command>", "code": "<code>", "error": "...", "hint": "...", "nextAction": "..."}
299
+ ```
300
+
301
+ - `body` holds the result. The section of each command gives the fields of its body.
302
+ - A check gives its verdict in `body.result`: `PASS`, `FAIL` or `INCONCLUSIVE`. The exit code is 0 for each verdict. Thus read `body.result`, not the exit code.
303
+ - `error` is one sentence. It tells what is wrong.
304
+ - `hint` tells what to do or what to examine. Read it before your next step. Some envelopes have no `hint`.
305
+ - `nextAction` is a full command line. It runs from any directory. Run it when it agrees with your task. Some envelopes have no `nextAction`.
306
+ - `code` does not change between versions. Do the action for the code:
307
+
308
+ | `code` | Action |
309
+ |---|---|
310
+ | `installation-incomplete`, `machine-unavailable` | Stop the task. Give `error` and `hint` to the user and wait for the user. Do not install, start or change a tool. Do not make a replacement for the tool, for example your own disk parser, disassembler or emulator script. |
311
+ | `invalid-input`, `not-found` | Correct the call as `hint` tells. Then run the command again. |
312
+ | `operation-failed` | Give `error` and `hint` to the user. |
313
+ | Another code | Do as `hint` tells. |
314
+
315
+ These fields have the same meaning in each body:
316
+
317
+ | Field | Meaning |
318
+ |---|---|
319
+ | `out`, `bytes`, `sha256` | A file that the command wrote: its path, its size and its SHA-256. |
320
+ | `count`, `listed`, `rest` | A list. `count` is the number of items. `listed` holds the first items, at most `--max-listed`. `rest` tells how to get the other items. |
321
+
322
+ To get the command list, run the script with no arguments. The envelope has `command: "help"`, and `body.commands` gives the name, the summary and the synopsis of each command.
323
+ To get the subjects and the flags of one command, run `<command> --help`. Then `body.subjects` and `body.options` give them.
324
+
325
+ ---
326
+
327
+ ## Reference
328
+
329
+ - `references/scenario-format.md`: the scenario file of `test` and the run file of `run`. It gives each step, each observation, the expected values, and the checks before a test or a run.
330
+ - `references/recording-format.md`: the record file of `record`, the play page and its key maps, and the files of a recording folder. It also gives the fields of the body of `replay`.