@henols/c64-re-tools 2.3.0-rc.1 → 2.3.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -3
- package/skills/c64-assembler/SKILL.md +4 -6
- package/skills/c64-basic/SKILL.md +2 -4
- package/skills/c64-development/SKILL.md +3 -3
- package/skills/c64-disk/SKILL.md +3 -7
- package/skills/c64-docs/SKILL.md +2 -4
- package/skills/c64-export/SKILL.md +4 -4
- package/skills/c64-knowledge/SKILL.md +3 -3
- package/skills/c64-memory-map/SKILL.md +1 -3
- package/skills/c64-packer/SKILL.md +9 -11
- package/skills/c64-packer/scripts/packer.ts +2 -20
- package/skills/c64-provenance/SKILL.md +18 -7
- package/skills/c64-provenance/scripts/lib/compare.ts +144 -16
- package/skills/c64-provenance/scripts/provenance.ts +37 -8
- package/skills/c64-reverse-engineering/SKILL.md +3 -3
- package/skills/c64-source/SKILL.md +37 -18
- package/skills/c64-source/scripts/lib/loader.ts +281 -43
- package/skills/c64-source/scripts/source.ts +37 -9
- package/skills/c64-static-analysis/SKILL.md +4 -4
- package/skills/c64-testing/SKILL.md +13 -13
- package/skills/c64-testing/references/recording-format.md +1 -1
- package/skills/c64-testing/references/scenario-format.md +3 -3
- package/skills/c64-testing/scripts/lib/play.ts +4 -4
- package/skills/c64-testing/scripts/testing.ts +1 -1
- package/skills/c64-unpacker/SKILL.md +12 -12
- package/skills/c64-unpacker/scripts/lib/loads.ts +17 -4
- package/skills/c64-unpacker/scripts/unpacker.ts +15 -3
- package/skills/emulator/SKILL.md +3 -3
- package/src/cli/cleanup.ts +30 -0
- package/src/cli/main.ts +5 -1
- package/src/compare.ts +18 -0
- package/src/host-client/coverage.ts +26 -0
- package/src/mcp/tools/machine.ts +2 -2
- package/README.md +0 -143
|
@@ -17,9 +17,9 @@ A PASS proves only the behavior that the scenario does and observes. It does not
|
|
|
17
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
18
|
- A scenario file: the steps, the checkpoints and the observations. See [references/scenario-format.md](references/scenario-format.md).
|
|
19
19
|
|
|
20
|
-
## Tools
|
|
20
|
+
## Tools
|
|
21
21
|
|
|
22
|
-
The script
|
|
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.
|
|
23
23
|
|
|
24
24
|
```
|
|
25
25
|
node <skill>/scripts/testing.ts test tests/moves-left.json --out .c64-re-tools/local/results/moves-left
|
|
@@ -30,7 +30,7 @@ node <skill>/scripts/testing.ts checklist tests/moves-left.json --item 'FIRE sta
|
|
|
30
30
|
|
|
31
31
|
`testing.ts checklist` gives a Markdown checklist for a human tester in `text`.
|
|
32
32
|
|
|
33
|
-
Before the
|
|
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.
|
|
34
34
|
|
|
35
35
|
### Runs
|
|
36
36
|
|
|
@@ -53,7 +53,7 @@ The run file gives where to start (a program, or a snapshot file), the steps, an
|
|
|
53
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
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. |
|
|
55
55
|
|
|
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
|
|
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.
|
|
57
57
|
|
|
58
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.
|
|
59
59
|
|
|
@@ -63,7 +63,7 @@ See [references/scenario-format.md](references/scenario-format.md), section Runs
|
|
|
63
63
|
|
|
64
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.
|
|
65
65
|
|
|
66
|
-
|
|
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.
|
|
67
67
|
|
|
68
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.
|
|
69
69
|
|
|
@@ -72,7 +72,7 @@ node <skill>/scripts/testing.ts record tests/record/start.json --out tests/recor
|
|
|
72
72
|
```
|
|
73
73
|
|
|
74
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.
|
|
75
|
+
- The script writes the address of a page to stderr. Give the address to the user.
|
|
76
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
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
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).
|
|
@@ -98,7 +98,7 @@ A checkpoint is one entry of a routine. Use a routine that the program executes
|
|
|
98
98
|
|
|
99
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.
|
|
100
100
|
|
|
101
|
-
A replay is deterministic.
|
|
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.
|
|
102
102
|
|
|
103
103
|
Control each source of random numbers:
|
|
104
104
|
|
|
@@ -119,7 +119,7 @@ node <skill>/scripts/testing.ts diff .c64-re-tools/local/runs/rooms/results.json
|
|
|
119
119
|
|
|
120
120
|
`testing.ts diff` tells what changed between two states of one kind. Use it in place of your own compare script.
|
|
121
121
|
|
|
122
|
-
- Two snapshot files: the
|
|
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
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
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.
|
|
125
125
|
|
|
@@ -127,7 +127,7 @@ For two snapshot files, `$00` and `$01` are the CPU port of the snapshot: the di
|
|
|
127
127
|
|
|
128
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`.
|
|
129
129
|
|
|
130
|
-
The script refuses a snapshot that does not restore
|
|
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.
|
|
131
131
|
|
|
132
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.
|
|
133
133
|
|
|
@@ -197,19 +197,19 @@ PASS, FAIL or INCONCLUSIVE, the checkpoints and the smallest differences that ex
|
|
|
197
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
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
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
|
|
201
|
-
- `installation-incomplete
|
|
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
202
|
- A FAIL with only a `screen` difference: add `vicii` or `sprites` to the observation to find which chip state is different.
|
|
203
203
|
- 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.
|
|
204
204
|
- 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.
|
|
205
205
|
- 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.
|
|
206
|
-
- INCONCLUSIVE, "does not reproduce": the original does not end the session with the recorded state. Record the session again
|
|
206
|
+
- INCONCLUSIVE, "does not reproduce": the original does not end the session with the recorded state. Record the session again.
|
|
207
207
|
- INCONCLUSIVE, "never came to the checkpoint": the original did not execute the checkpoint routine in the session. Give another routine.
|
|
208
208
|
- INCONCLUSIVE, "is not the program of the recording": the program file changed after the recording. Record the session again.
|
|
209
209
|
- 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.
|
|
210
210
|
- 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.
|
|
211
211
|
- 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.
|
|
212
|
-
- A program that loads more files from a disk:
|
|
212
|
+
- A program that loads more files from a disk: a recording has no disk drive. Use a test scenario in the emulator.
|
|
213
213
|
- 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.
|
|
214
214
|
|
|
215
215
|
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.
|
|
@@ -101,7 +101,7 @@ The page sends input only between Start and End. The input of the page goes into
|
|
|
101
101
|
|
|
102
102
|
A site is the address of the instruction that reads. The values are hex. `<from>` and `<count>` are decimal.
|
|
103
103
|
|
|
104
|
-
`testing.ts replay` checks `recording.json` before the replay
|
|
104
|
+
`testing.ts replay` checks `recording.json` before the replay starts. A recording of version 2.0 can have events or a comparison in the old form, for example `"at"` in place of `"address"`. The script refuses it with `invalid-input`. The message names the event, the old field and the form to write. Record the session again.
|
|
105
105
|
|
|
106
106
|
## Replay
|
|
107
107
|
|
|
@@ -156,11 +156,11 @@ Example: visit two rooms from the same start.
|
|
|
156
156
|
|
|
157
157
|
## Checks
|
|
158
158
|
|
|
159
|
-
The script checks the scenario before it
|
|
159
|
+
The script checks the scenario before it does a step. A step with an unknown key or a wrong value stops the script with `invalid-input`. The message names the step.
|
|
160
160
|
|
|
161
|
-
The script also examines each file before it
|
|
161
|
+
The script also examines each file before it does a step: the program and the symbols of each side, and each snapshot file. A missing file stops the script with `not-found`. A program that is not a PRG, for example a disk image, stops the script with `invalid-input`. A snapshot file that does not start with the signature of a VICE snapshot file also stops the script with `invalid-input`. The message names the step and the file.
|
|
162
162
|
|
|
163
|
-
A run also examines each name of its steps before it
|
|
163
|
+
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.
|
|
164
164
|
|
|
165
165
|
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`.
|
|
166
166
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// A person plays the program in the replay core: a page
|
|
2
|
-
// the screen and sends the keyboard and gamepad. The machine is frozen at the
|
|
1
|
+
// A person plays the program in the replay core: a page shows the screen and sends the keyboard and gamepad. The machine is frozen at the
|
|
3
2
|
// start screen until Start on the page; then the core runs one frame each
|
|
4
3
|
// 20 ms. End freezes it again and the recording is saved; Cancel ends the
|
|
5
4
|
// session without one. The reads of the program keep the input, so the
|
|
6
5
|
// recording needs nothing from the page. RESTORE is no read: it is an event
|
|
7
|
-
// of the recording (see record in recording.ts).
|
|
6
|
+
// of the recording (see record in recording.ts). The page listens on every
|
|
7
|
+
// address: in a dev container, a forward of the port from the host needs that.
|
|
8
8
|
|
|
9
9
|
import { createServer, type ServerResponse } from "node:http";
|
|
10
10
|
|
|
@@ -287,7 +287,7 @@ export async function play(core: Pick<C64RunSession, "command" | "status">, opti
|
|
|
287
287
|
response.writeHead(404).end();
|
|
288
288
|
}
|
|
289
289
|
});
|
|
290
|
-
await new Promise<void>((resolve) => server.listen(options.httpPort, "
|
|
290
|
+
await new Promise<void>((resolve) => server.listen(options.httpPort, "0.0.0.0", resolve));
|
|
291
291
|
const address = server.address();
|
|
292
292
|
options.ready("http://localhost:" + (typeof address === "object" && address !== null ? address.port : options.httpPort) + "/");
|
|
293
293
|
let tick = (await core.status("status")).tick;
|
|
@@ -76,7 +76,7 @@ async function recordCommand(call: Call): Promise<Record<string, unknown>> {
|
|
|
76
76
|
const person = playing
|
|
77
77
|
? (session: C64RunSession, restore: () => Promise<string | undefined>) => {
|
|
78
78
|
const ready = (url: string) =>
|
|
79
|
-
process.stderr.write("Open " + url + ". The start screen is frozen. Enter or Start begins the play, F12 or End saves the recording, F11 or Cancel ends without one. F9 changes the joystick port.\n");
|
|
79
|
+
process.stderr.write("Open " + url + ". In a dev container, forward port " + new URL(url).port + " to this computer first. The start screen is frozen. Enter or Start begins the play, F12 or End saves the recording, F11 or Cancel ends without one. F9 changes the joystick port.\n");
|
|
80
80
|
return play(session, { httpPort, joystick, ready, restore });
|
|
81
81
|
}
|
|
82
82
|
: undefined;
|
|
@@ -16,7 +16,7 @@ This skill does not change project knowledge.
|
|
|
16
16
|
- The program: a PRG file, relative to the project folder. `inspect`, `trace`, `stages` and `capture` refuse a disk, tape or cartridge image. For such an image, use `loads`, or get the PRG with `disk.ts read` of the c64-disk skill.
|
|
17
17
|
- For a capture: the address where the unpacked program starts, and the directory for the result.
|
|
18
18
|
|
|
19
|
-
## Tools
|
|
19
|
+
## Tools
|
|
20
20
|
|
|
21
21
|
```
|
|
22
22
|
node <skill>/scripts/unpacker.ts inspect original/game.prg
|
|
@@ -26,14 +26,14 @@ node <skill>/scripts/unpacker.ts capture original/game.prg --until '$c000' --out
|
|
|
26
26
|
node <skill>/scripts/unpacker.ts loads original/game.d64 --steps .c64-re-tools/local/parts.json --out .c64-re-tools/local/parts --drive
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
`inspect` examines the file
|
|
29
|
+
`inspect` examines the file and does not run the program. `trace`, `stages`, `capture` and `loads` run the program. `trace` runs the program and finds the memory that the program wrote and then executed. `stages` runs the program and finds each stage: a decruncher, an intro, a copier, and then the program. For each stage it gives the entry, the frames, the written memory (`wrote`) and the entry of the next stage (`next`). `wrote` lists each block that the stage wrote, also a small block. `capture` stops the program when the CPU gets to the `--until` address. In `stages` and `capture`, a `frames` step and a `runUntil` step to an address without a condition count as run time. `stages` refuses a different `runUntil` step.
|
|
30
30
|
|
|
31
31
|
| Option | Meaning |
|
|
32
32
|
|---|---|
|
|
33
33
|
| `--until '$c000'` | `capture`: the address where the unpacked program starts. The capture stops there after the steps. To capture a later arrival at the address, add a `runUntil` step to an address after the first arrival. |
|
|
34
34
|
| `--out .c64-re-tools/local/capture` | `capture` and `loads`: the folder for the result, relative to the project folder. |
|
|
35
35
|
| `--range '$c000-$cfff'` | `capture` only: write this range as the one segment. Without it, the segments are the blocks that the stages wrote. The range must hold the `--until` address. |
|
|
36
|
-
| `--exclude '$a000-$a9ff'` | `capture`
|
|
36
|
+
| `--exclude '$a000-$a9ff'` | `capture` and `loads`: remove this range from the segments. You can give it more than once. `image.json` lists the ranges in `excluded`. For `capture`, the range must not hold the `--until` address. |
|
|
37
37
|
| `--timeout-frames 3000` | `capture` only: how many frames the program can run before the capture stops (default 3000). |
|
|
38
38
|
| `--frames 3000` | `trace` and `stages`: how many frames the program runs (default 3000). |
|
|
39
39
|
| `--entry '$c000'` | `trace`, `stages` and `capture`: start the program at this address. Without it, the script types RUN. A file that is not a BASIC program at `$0801` needs it. |
|
|
@@ -43,9 +43,9 @@ node <skill>/scripts/unpacker.ts loads original/game.d64 --steps .c64-re-tools/l
|
|
|
43
43
|
| `--min-block 64` | `loads` only: the smallest block of changed memory that becomes a segment (default 64). The result counts smaller changes as `smallChanges`. |
|
|
44
44
|
| `--min-stage 64` | `stages` and `capture`: the smallest block of written memory that starts a new stage when the CPU executes it (default 64). It does not change `wrote` or the segments. |
|
|
45
45
|
|
|
46
|
-
The capture reads RAM, also the RAM under the ROMs and the I/O area. The script refuses an option that the command does not use. It refuses a wrong `--range` or `--exclude` before the
|
|
46
|
+
The capture reads RAM, also the RAM under the ROMs and the I/O area. A segment can be in the RAM under the I/O area at `$d000`-`$dfff`. The script refuses an option that the command does not use. It refuses a wrong `--range` or `--exclude` before the program runs.
|
|
47
47
|
|
|
48
|
-
A steps file is a JSON list of steps. Each step has the input of the MCP tool of the same action. An address in a step can be a name. The script refuses an unknown name before the
|
|
48
|
+
A steps file is a JSON list of steps. Each step has the input of the MCP tool of the same action. An address in a step can be a name. The script refuses an unknown name before the program runs. The message gives the file and the step. For example, wait 50 frames and type a space:
|
|
49
49
|
|
|
50
50
|
```json
|
|
51
51
|
[{ "frames": 50 }, { "type": { "mode": "text", "text": " " } }]
|
|
@@ -120,7 +120,7 @@ The scripts refuse a step in the form of version 2.0, for example `{ "runUntil":
|
|
|
120
120
|
|
|
121
121
|
## Multi-load programs
|
|
122
122
|
|
|
123
|
-
A multi-load program loads more parts from the disk while it runs, for example one part for each level. Use `loads` to capture each part. The program can be a PRG, or a disk, tape or cartridge image
|
|
123
|
+
A multi-load program loads more parts from the disk while it runs, for example one part for each level. Use `loads` to capture each part. The program can be a PRG, or a disk, tape or cartridge image. `loads` starts a PRG with RUN. Thus the PRG must have a BASIC start line. For a PRG without a BASIC start line, use `capture` with `--entry`.
|
|
124
124
|
|
|
125
125
|
1. Write a steps file. Put a `capture` step after each point where a part is in memory, for example:
|
|
126
126
|
|
|
@@ -134,12 +134,12 @@ A multi-load program loads more parts from the disk while it runs, for example o
|
|
|
134
134
|
]
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
2. Run `loads` with the steps file and a directory in `--out`. Add `--drive` when the program has its own drive code, for example a fast loader.
|
|
137
|
+
2. Run `loads` with the steps file and a directory in `--out`. Add `--drive` when the program has its own drive code, for example a fast loader. Add `--exclude` for each range of a loader, an intro or a loading picture that the program does not read. The script removes these ranges from the segments of each capture.
|
|
138
138
|
3. Each capture writes `<out>/<name>/` with `image.bin`, `image.json`, `entry_state.json` and a PRG for each segment. It removes the segment PRGs and the `drive8.prg` of an earlier capture that the new `image.json` does not list. A segment is a block of RAM from `$0400` that the program changed after the capture before. The first capture also has the program itself.
|
|
139
139
|
4. Put the part that you work on into the knowledge with `image <out>/<name>/image.json` of the c64-knowledge skill.
|
|
140
140
|
5. With `--drive`, `drive8.prg` is the drive RAM at `$0000`-`$07ff`. Put it into the knowledge with `image <out>/<name>/drive8.prg --space drive8`. Then analyze it with c64-static-analysis and `--space drive8`.
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
No tool gives coverage of drive code.
|
|
143
143
|
|
|
144
144
|
## Knowledge
|
|
145
145
|
|
|
@@ -160,16 +160,16 @@ For `loads`: `captures`, with the name, the PC, the segments, `differsFromReset`
|
|
|
160
160
|
|
|
161
161
|
## Failure and conflicts
|
|
162
162
|
|
|
163
|
-
- `traced: false` or `followed: false`: the
|
|
164
|
-
- `traced: false` or `followed: false` with `stopReason`: the CPU stopped before the frames ran, for example at a JAM instruction. `pc` gives the address. Make sure that `--entry` is the start of the code that the file holds at that time, and that the steps
|
|
163
|
+
- `traced: false` or `followed: false`: the C64 did not load the program into memory in the time limit. The reason gives the load address. Make sure that the file is a PRG that the C64 can load.
|
|
164
|
+
- `traced: false` or `followed: false` with `stopReason`: the CPU stopped before the frames ran, for example at a JAM instruction. `pc` gives the address. Make sure that `--entry` is the start of the code that the file holds at that time, and that the steps have no error.
|
|
165
165
|
- `captured: false`: the program did not get to the address in the time limit. The reason tells where it stopped. Find a better address with the emulator skill, or give more frames. If it stopped in a key wait, give `--steps` with a `type` step.
|
|
166
166
|
- A step did not reach its target: the reason names the step. Change the step or give it more frames.
|
|
167
167
|
- `loaded: false` with an empty `captures` and the reason `BASIC ran no program line`: the PRG has no BASIC start line. Use `capture` with `--entry`.
|
|
168
|
-
- `loaded: false` and no capture has a segment: the program did not load a part, or it did not start. `keyWait: true` on a capture tells that the C64 waited for a key at the READY prompt or at an INPUT statement. For a tape image, read `emulatorFlaw`.
|
|
168
|
+
- `loaded: false` and no capture has a segment: the program did not load a part, or it did not start. `keyWait: true` on a capture tells that the C64 waited for a key at the READY prompt or at an INPUT statement. For a tape image, read `emulatorFlaw`. It names a known flaw of the emulator that can stop a tape load. Give it to the user.
|
|
169
169
|
- Do not name a packer from weak evidence. The script never names one.
|
|
170
170
|
- Some programs unpack in more than one stage. Run `stages` to find each stage. Capture at the entry of the last stage. Make sure that it is the application and not a second unpacker.
|
|
171
171
|
- `not-found` or `invalid-input`: a path or an argument is wrong. Read the message.
|
|
172
|
-
- `installation-incomplete
|
|
172
|
+
- `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.
|
|
173
173
|
|
|
174
174
|
## Handoffs
|
|
175
175
|
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// image with its entry state, and with --drive the drive RAM as a PRG for
|
|
5
5
|
// knowledge space drive8. No tool guesses where a load ends: the steps decide.
|
|
6
6
|
|
|
7
|
-
import { COVERAGE, formatC64Address } from "#src/c64.ts";
|
|
7
|
+
import { type AddressRange, COVERAGE, formatC64Address } from "#src/c64.ts";
|
|
8
8
|
import { autostartLoaded, LOAD_LIMIT_FRAMES, RUN_LIMIT_FRAMES, typeRun } from "#src/host-client/autostart.ts";
|
|
9
|
-
import { readCoverage } from "#src/host-client/coverage.ts";
|
|
9
|
+
import { IO_RAM, markIoRamWrites, readCoverage } from "#src/host-client/coverage.ts";
|
|
10
10
|
import { ACTION_STEP_KINDS, checkActionStep, checkStepNames, isObject, runActionStep, VICE_STEP_KINDS, type ActionStep, type ActionStepKind } from "#src/host-client/steps.ts";
|
|
11
11
|
import { knowledgeAt } from "#src/knowledge/names.ts";
|
|
12
12
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
@@ -88,6 +88,17 @@ export function changedBlocks(before: Uint8Array, after: Uint8Array, map: Uint8A
|
|
|
88
88
|
return blocks.filter((block) => block.changed).map(({ start, end, bytes }) => ({ start, end, bytes }));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The blocks of a capture: the changed blocks, also in the RAM under the I/O
|
|
93
|
+
* area, which the map gives as I/O writes. An excluded range holds no write,
|
|
94
|
+
* so it cuts the blocks and counts in no small change. Changes `map`.
|
|
95
|
+
*/
|
|
96
|
+
export function captureBlocks(before: Uint8Array, after: Uint8Array, map: Uint8Array, writesKnown: boolean, exclude: readonly AddressRange[]): Array<{ start: number; end: number; bytes: number }> {
|
|
97
|
+
markIoRamWrites(map, before.subarray(IO_RAM.start, IO_RAM.end + 1), after.subarray(IO_RAM.start, IO_RAM.end + 1));
|
|
98
|
+
for (const range of exclude) map.fill(0, range.start, range.end + 1);
|
|
99
|
+
return changedBlocks(before, after, map, 16, writesKnown);
|
|
100
|
+
}
|
|
101
|
+
|
|
91
102
|
const hex4 = (value: number) => value.toString(16).padStart(4, "0");
|
|
92
103
|
|
|
93
104
|
/**
|
|
@@ -96,7 +107,7 @@ const hex4 = (value: number) => value.toString(16).padStart(4, "0");
|
|
|
96
107
|
* `drive` the drive RAM as drive8.prg. Blocks below `minBlock` bytes are
|
|
97
108
|
* counted, not written: a game changes its variables all the time.
|
|
98
109
|
*/
|
|
99
|
-
export async function loads(program: string, options: { out: string; steps: LoadStep[]; drive: boolean; minBlock: number }): Promise<{ output: Record<string, unknown>; failed: boolean }> {
|
|
110
|
+
export async function loads(program: string, options: { out: string; steps: LoadStep[]; drive: boolean; minBlock: number; exclude: AddressRange[] }): Promise<{ output: Record<string, unknown>; failed: boolean }> {
|
|
100
111
|
const client = await ViceSessionClient.open({ videoStandard: "pal" });
|
|
101
112
|
try {
|
|
102
113
|
// A clean machine at the READY prompt shows what the program changed at each capture. The run goes on after a capture, so it is read first.
|
|
@@ -159,7 +170,7 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
159
170
|
for (let address = load; address < Math.min(0x10000, load + loadedProgram.length - 2); address++) map[address]! |= COVERAGE.ramWrite;
|
|
160
171
|
loadedProgram = undefined;
|
|
161
172
|
}
|
|
162
|
-
const blocks =
|
|
173
|
+
const blocks = captureBlocks(previous, memory, map, writesKnown, options.exclude);
|
|
163
174
|
const segments = blocks.filter((block) => block.end - block.start + 1 >= options.minBlock);
|
|
164
175
|
const small = blocks.filter((block) => !segments.includes(block)).reduce((sum, block) => sum + block.bytes, 0);
|
|
165
176
|
const state = await machineState(client);
|
|
@@ -186,6 +197,7 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
186
197
|
capture: step.capture,
|
|
187
198
|
entry: formatC64Address(registers.pc),
|
|
188
199
|
segments: segments.map((segment, at) => ({ ...showRange(segment), file: files[at] })),
|
|
200
|
+
...(options.exclude.length === 0 ? {} : { excluded: options.exclude.map(showRange) }),
|
|
189
201
|
vectors,
|
|
190
202
|
image: "image.bin",
|
|
191
203
|
...(drive === undefined ? {} : { drive }),
|
|
@@ -204,6 +216,7 @@ export async function loads(program: string, options: { out: string; steps: Load
|
|
|
204
216
|
pc: formatC64Address(registers.pc),
|
|
205
217
|
...(keyWait ? { keyWait: true } : {}),
|
|
206
218
|
segments: segments.map(showRange),
|
|
219
|
+
...(options.exclude.length === 0 ? {} : { excluded: options.exclude.map(showRange) }),
|
|
207
220
|
differsFromReset: entry.differsFromReset,
|
|
208
221
|
...(small === 0 ? {} : { smallChanges: small }),
|
|
209
222
|
...(drive === undefined ? {} : { drive: drive.file }),
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { type AddressRange, COVERAGE, EXECUTE, formatC64Address, READ, WRITE } from "#src/c64.ts";
|
|
10
10
|
import { autostartLoaded, LOAD_LIMIT_FRAMES, RUN_LIMIT_FRAMES, typeRun } from "#src/host-client/autostart.ts";
|
|
11
|
-
import { readCoverage, writtenBlocks } from "#src/host-client/coverage.ts";
|
|
11
|
+
import { IO_RAM, markIoRamWrites, readCoverage, writtenBlocks } from "#src/host-client/coverage.ts";
|
|
12
12
|
import { readActionSteps, runActionStep, type ActionStep } from "#src/host-client/steps.ts";
|
|
13
13
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
14
14
|
import { readPrg } from "#src/host-client/image.ts";
|
|
@@ -226,6 +226,14 @@ async function follow(
|
|
|
226
226
|
const basic = basicStart(bytes);
|
|
227
227
|
const notStarted = await startLoaded(client, program, bytes, options.entry);
|
|
228
228
|
if (notStarted !== undefined) return { stages: [], frames: 0, reached: false, failed: notStarted };
|
|
229
|
+
// The map gives a write to the RAM under the I/O area as an I/O write: a compare of that RAM at each stage end finds them.
|
|
230
|
+
const readIoRam = () => readRam(client, IO_RAM.start, IO_RAM.end - IO_RAM.start + 1);
|
|
231
|
+
let ioRam = await readIoRam();
|
|
232
|
+
const markIoRam = async (map: Uint8Array) => {
|
|
233
|
+
const now = await readIoRam();
|
|
234
|
+
markIoRamWrites(map, ioRam, now);
|
|
235
|
+
ioRam = now;
|
|
236
|
+
};
|
|
229
237
|
// The frames of each step end where a scenario's do: the first step counts from RUN, a later one from where it starts.
|
|
230
238
|
let anchor: { line: number; cycle: number } | undefined = await rasterAt(client);
|
|
231
239
|
const framed = () => (anchor === undefined ? {} : { anchor });
|
|
@@ -244,6 +252,7 @@ async function follow(
|
|
|
244
252
|
let stage = { map: new Uint8Array(0x10000), own: new Set<number>(), called: [] as AddressRange[] };
|
|
245
253
|
const startStage = async (next: number, last: Uint8Array) => {
|
|
246
254
|
mergeMaps(stage.map, last);
|
|
255
|
+
await markIoRam(stage.map);
|
|
247
256
|
found.push({ entry, firstFrame, frames: total - firstFrame, wrote: stageWrote(stage.map), next });
|
|
248
257
|
entry = next;
|
|
249
258
|
firstFrame = total;
|
|
@@ -434,6 +443,7 @@ async function follow(
|
|
|
434
443
|
else reached = await trackTo(options.until, left);
|
|
435
444
|
await client.snapshot({ action: "remove", name: STAGE_SNAPSHOT }).catch(() => undefined);
|
|
436
445
|
mergeMaps(stage.map, await readCoverage(client));
|
|
446
|
+
await markIoRam(stage.map);
|
|
437
447
|
found.push({ entry, firstFrame, frames: total - firstFrame, wrote: stageWrote(stage.map) });
|
|
438
448
|
return { stages: found, frames: total, reached, ...(halted === undefined ? {} : { halted }) };
|
|
439
449
|
}
|
|
@@ -562,6 +572,7 @@ const PROGRAM = { name: "<program>", help: "a PRG file, relative to the project
|
|
|
562
572
|
const FRAMES: OptionSpec = { ...OPTIONS.frames, max: 30_000, default: 3000, help: "run the program for n frames (default 3000)" };
|
|
563
573
|
const ENTRY: OptionSpec = { ...OPTIONS.entry, help: "start the program here in place of RUN" };
|
|
564
574
|
const STEPS: OptionSpec = { ...OPTIONS.steps, help: "action steps (JSON) that run right after the program starts, for example to press a key in an intro or to get through a menu" };
|
|
575
|
+
const EXCLUDE: OptionSpec = { kind: "range", value: "<start>-<end>", multiple: true, help: "a range to leave out of the segments, for example bytes that a crack left and the program never reads" };
|
|
565
576
|
const MIN_STAGE: OptionSpec = { kind: "count", value: "<bytes>", min: 1, max: 0x10000, default: 64, help: "a stage starts when the CPU executes a block of at least this many bytes that the stage before wrote (default 64)" };
|
|
566
577
|
|
|
567
578
|
/** The result of a command: PASS, or FAIL with the reason. */
|
|
@@ -611,7 +622,7 @@ const COMMANDS: CommandSpec[] = [
|
|
|
611
622
|
until: { kind: "address", value: "<address>", required: true, help: "the unpacked entry point" },
|
|
612
623
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", required: true, help: "the folder for the capture, relative to the project folder" },
|
|
613
624
|
range: { ...OPTIONS.range, help: "one segment in place of the found ones" },
|
|
614
|
-
exclude:
|
|
625
|
+
exclude: EXCLUDE,
|
|
615
626
|
"timeout-frames": { ...OPTIONS["timeout-frames"], max: 30_000, default: 3000, help: "stop the wait for --until after n frames (default 3000)" },
|
|
616
627
|
entry: ENTRY,
|
|
617
628
|
steps: STEPS,
|
|
@@ -639,8 +650,9 @@ const COMMANDS: CommandSpec[] = [
|
|
|
639
650
|
out: { ...OPTIONS.out, output: "folder", value: "<dir>", required: true, help: "the folder for the captures, relative to the project folder" },
|
|
640
651
|
drive: { kind: "flag", help: "also write the 2 KiB drive RAM as drive8.prg, for knowledge space drive8" },
|
|
641
652
|
"min-block": { kind: "count", value: "<bytes>", min: 1, max: 0x10000, default: 64, help: "write a changed block of at least this many bytes (default 64)" },
|
|
653
|
+
exclude: EXCLUDE,
|
|
642
654
|
},
|
|
643
|
-
run: async (call) => outcome(await loads(call.subject(0), { out: call.string("out")!, steps: readLoadSteps(call.string("steps")!), drive: call.flag("drive"), minBlock: call.count("min-block")
|
|
655
|
+
run: async (call) => outcome(await loads(call.subject(0), { out: call.string("out")!, steps: readLoadSteps(call.string("steps")!), drive: call.flag("drive"), minBlock: call.count("min-block")!, exclude: call.ranges("exclude") })),
|
|
644
656
|
},
|
|
645
657
|
];
|
|
646
658
|
|
package/skills/emulator/SKILL.md
CHANGED
|
@@ -21,7 +21,7 @@ The MCP server knows the machine and the emulator. Its instructions, its tool de
|
|
|
21
21
|
|
|
22
22
|
A tool takes addresses, not names. The server instructions give the address format. Get the address of a name with `knowledge.ts at <name>` of the c64-knowledge skill.
|
|
23
23
|
|
|
24
|
-
## Tools
|
|
24
|
+
## Tools
|
|
25
25
|
|
|
26
26
|
Use only the MCP tools. Each MCP session has its own machine. Nothing else can change that machine.
|
|
27
27
|
|
|
@@ -91,7 +91,7 @@ The emulator has no window. When the user must type, play or look at the machine
|
|
|
91
91
|
3. Wait until the user tells you that they finished.
|
|
92
92
|
4. Close the window with `c64_window` action `close`.
|
|
93
93
|
|
|
94
|
-
The result field `notCarried` names the data that the
|
|
94
|
+
The result field `notCarried` names the data that the open or the close cleared.
|
|
95
95
|
|
|
96
96
|
## Knowledge
|
|
97
97
|
|
|
@@ -120,7 +120,7 @@ If you cannot get the machine into the necessary state, say which state you coul
|
|
|
120
120
|
|
|
121
121
|
An error is `{"error": {"code": "...", "message": "..."}}`. The message tells what is wrong and what to do. Obey the message. These rules also apply:
|
|
122
122
|
|
|
123
|
-
- `installation-incomplete
|
|
123
|
+
- `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.
|
|
124
124
|
- `machine-unavailable` with a message that names a pause or a dialog in the window: do not send more operations. Give the message to the user. When the user tells you that the emulator runs again, do the operation again.
|
|
125
125
|
- `machine-unavailable` for a different cause: wait a few seconds. Then do the operation again one time. If you get the same error again, stop the task. Tell the user to restart the c64-re-tools MCP server, and wait for the user.
|
|
126
126
|
- `machine-state-lost`: do not use results from before the error. Do what the message tells. Then read the machine state again.
|
package/src/cli/cleanup.ts
CHANGED
|
@@ -177,6 +177,36 @@ export function tidyAfterUninstall(items: readonly InstallItem[], scope: Scope,
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
/**
|
|
181
|
+
* After an install or update: deletes the files of the items that the
|
|
182
|
+
* earlier install made and this one no longer has, for example a skill that
|
|
183
|
+
* a version renamed, then the directories that they leave empty. Only the
|
|
184
|
+
* harnesses that this install wrote count, and an MCP item never goes: its
|
|
185
|
+
* file holds other servers too. A file that this install also wrote stays.
|
|
186
|
+
* Returns the names of the removed items.
|
|
187
|
+
*/
|
|
188
|
+
export function removeDroppedItems(before: readonly InstallItem[], scope: Scope, cwd = process.cwd()): string[] {
|
|
189
|
+
const root = scopeRoot(scope, cwd);
|
|
190
|
+
const absolute = (file: string) => (isAbsolute(file) ? file : resolve(root, file));
|
|
191
|
+
const after = installedItems(scope, undefined, cwd);
|
|
192
|
+
const key = (item: InstallItem) => `${item.harness}/${item.kind}/${item.name}`;
|
|
193
|
+
const kept = new Set(after.map(key));
|
|
194
|
+
const harnesses = new Set(after.map((item) => item.harness));
|
|
195
|
+
const keptFiles = new Set(after.flatMap((item) => item.files.map(absolute)));
|
|
196
|
+
const dropped = before.filter((item) => item.kind !== "mcp" && harnesses.has(item.harness) && !kept.has(key(item)));
|
|
197
|
+
const directories = new Set<string>();
|
|
198
|
+
for (const item of dropped) {
|
|
199
|
+
for (const file of item.files.map(absolute)) {
|
|
200
|
+
if (keptFiles.has(file) || !isWithin(root, file)) continue;
|
|
201
|
+
if (existsSync(file)) unlinkSync(file);
|
|
202
|
+
directories.add(dirname(file));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Deepest first, so a parent is tried after its children.
|
|
206
|
+
for (const directory of [...directories].sort((a, b) => b.length - a.length)) removeEmptyDirectories(directory, root);
|
|
207
|
+
return [...new Set(dropped.map((item) => item.name))];
|
|
208
|
+
}
|
|
209
|
+
|
|
180
210
|
const ANSI = new RegExp(String.fromCharCode(27) + "\\[[0-9;]*m", "g");
|
|
181
211
|
|
|
182
212
|
/** AP SDK's report without its Windsurf MCP line and that line's detail, for when the CLI undid that item. */
|
package/src/cli/main.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { localToolStatus } from "../native/status.ts";
|
|
|
13
13
|
import { isRefusal } from "../errors.ts";
|
|
14
14
|
import { startTrace } from "../trace.ts";
|
|
15
15
|
import { runApSdk } from "./ap-sdk.ts";
|
|
16
|
-
import { installedItems, parseTargets, tidyAfterUninstall, undoWindsurfProjectMcp, windsurfBefore, withoutWindsurfMcp
|
|
16
|
+
import { installedItems, parseTargets, removeDroppedItems, tidyAfterUninstall, type Scope, undoWindsurfProjectMcp, windsurfBefore, withoutWindsurfMcp } from "./cleanup.ts";
|
|
17
17
|
import { hostStatusLines, installedLines, toolLines } from "./status.ts";
|
|
18
18
|
|
|
19
19
|
const HELP = `c64-re-tools: Commodore 64 reverse engineering and development
|
|
@@ -86,11 +86,15 @@ async function main(argv: string[]): Promise<number> {
|
|
|
86
86
|
case "install":
|
|
87
87
|
case "update": {
|
|
88
88
|
const before = windsurfBefore();
|
|
89
|
+
const earlier = installedItems(scope, targets);
|
|
89
90
|
const { code, output } = await apSdk("install", flags);
|
|
90
91
|
// A project install leaves the home directory as it was.
|
|
91
92
|
const note = scope === "project" && (targets === undefined || targets.includes("windsurf")) ? undoWindsurfProjectMcp(before) : undefined;
|
|
92
93
|
process.stdout.write(note === undefined ? output : withoutWindsurfMcp(output));
|
|
93
94
|
if (note !== undefined) console.log(` ${note}\n`);
|
|
95
|
+
// A skill that this version renamed or dropped must not stay next to the new ones.
|
|
96
|
+
const removed = code === 0 ? removeDroppedItems(earlier, scope) : [];
|
|
97
|
+
if (removed.length > 0) console.log(` Removed, because this version no longer has them: ${removed.join(", ")}\n`);
|
|
94
98
|
return code;
|
|
95
99
|
}
|
|
96
100
|
case "uninstall": {
|
package/src/compare.ts
CHANGED
|
@@ -47,3 +47,21 @@ export function compareBuild(prg: Uint8Array, program: Reference): { identical:
|
|
|
47
47
|
});
|
|
48
48
|
return { identical: checks.every((check) => check.result === "identical"), segments: checks };
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
/** PRG files merged in load order, as the reference of a check: a later file wins where two overlap. */
|
|
52
|
+
export function mergedPrograms(programs: ReadonlyArray<{ start: number; body: Uint8Array }>): Reference {
|
|
53
|
+
const memory = new Uint8Array(0x10000);
|
|
54
|
+
const loaded = new Uint8Array(0x10000);
|
|
55
|
+
for (const { start, body } of programs) {
|
|
56
|
+
memory.set(body, start);
|
|
57
|
+
loaded.fill(1, start, start + body.length);
|
|
58
|
+
}
|
|
59
|
+
const segments: Array<{ start: number; end: number }> = [];
|
|
60
|
+
for (let address = 0; address < 0x10000; address++) {
|
|
61
|
+
if (loaded[address] === 0) continue;
|
|
62
|
+
const last = segments.at(-1);
|
|
63
|
+
if (last !== undefined && last.end === address - 1) last.end = address;
|
|
64
|
+
else segments.push({ start: address, end: address });
|
|
65
|
+
}
|
|
66
|
+
return { segments, byteAt: (address) => memory[address]! };
|
|
67
|
+
}
|
|
@@ -19,6 +19,32 @@ export async function readCoverage(session: Pick<ViceSessionClient, "memmap">, s
|
|
|
19
19
|
return map;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/** The I/O area. VICE maps every write there as an I/O write, also one with the RAM banked in by $01. */
|
|
23
|
+
export const IO_RAM = { start: 0xd000, end: 0xdfff } as const;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Marks the RAM writes under the I/O area in a map from $0000, from two reads
|
|
27
|
+
* of that RAM. The RAM there changes only by a write with the I/O area banked
|
|
28
|
+
* out. A run of written or changed bytes is RAM written when one byte of it
|
|
29
|
+
* changed: a byte written with the value that was there is part of it too.
|
|
30
|
+
* A run of register writes changes no RAM. `before` and `after` hold $d000-$dfff.
|
|
31
|
+
*/
|
|
32
|
+
export function markIoRamWrites(map: Uint8Array, before: Uint8Array, after: Uint8Array): void {
|
|
33
|
+
const size = IO_RAM.end - IO_RAM.start + 1;
|
|
34
|
+
const written = (offset: number) => before[offset] !== after[offset] || (map[IO_RAM.start + offset]! & (COVERAGE.ioWrite | COVERAGE.ramWrite)) !== 0;
|
|
35
|
+
for (let start = 0; start < size; ) {
|
|
36
|
+
if (!written(start)) {
|
|
37
|
+
start++;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
let end = start;
|
|
41
|
+
let changed = false;
|
|
42
|
+
for (; end < size && written(end); end++) changed ||= before[end] !== after[end];
|
|
43
|
+
if (changed) for (let offset = start; offset < end; offset++) map[IO_RAM.start + offset]! |= COVERAGE.ramWrite;
|
|
44
|
+
start = end;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
22
48
|
/** Runs of RAM that a program wrote, at least `minimum` bytes each, in a map from $0000. */
|
|
23
49
|
export function writtenBlocks(map: Uint8Array, minimum: number): CodeRange[] {
|
|
24
50
|
const blocks: CodeRange[] = [];
|
package/src/mcp/tools/machine.ts
CHANGED
|
@@ -53,7 +53,7 @@ export const c64Window = defineTool({
|
|
|
53
53
|
name: "c64_window",
|
|
54
54
|
title: "Emulator window",
|
|
55
55
|
description:
|
|
56
|
-
"Show the C64 in a window
|
|
56
|
+
"Show the C64 in a window, or hide it again. The emulator has no window until you open one. " +
|
|
57
57
|
"Open the window when the user must type, play or look at the C64. Then tell the user. Wait until the user tells you that they finished. " +
|
|
58
58
|
"Then close the window. The machine, the disk in drive 8, breakpoints, watchpoints, joysticks, warp mode and c64_timing go along. " +
|
|
59
59
|
"The run state of the machine does not change. The result names the data that does not go along (notCarried). " +
|
|
@@ -98,7 +98,7 @@ export const c64Warp = defineTool({
|
|
|
98
98
|
name: "c64_warp",
|
|
99
99
|
title: "Warp mode",
|
|
100
100
|
description:
|
|
101
|
-
"Turn warp mode on or off. In warp mode the C64 runs as fast as
|
|
101
|
+
"Turn warp mode on or off. In warp mode the C64 runs as fast as possible. " +
|
|
102
102
|
"Warp mode does not change what the C64 does. This does not change the run state of the machine.",
|
|
103
103
|
inputSchema: z.object({ enabled: z.boolean().describe("true turns warp mode on") }).strict(),
|
|
104
104
|
outputSchema: z.object({ enabled: z.boolean() }),
|