@henols/c64-re-tools 2.6.0-rc.7 → 2.6.0-rc.9
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 -2
- package/skills/c64-docs/SKILL.md +1 -1
- package/skills/c64-docs/scripts/docs.ts +6 -6
- package/skills/c64-knowledge/SKILL.md +3 -3
- package/skills/c64-knowledge/scripts/knowledge.ts +2 -0
- package/skills/c64-knowledge/scripts/lib/listing.ts +18 -3
- package/skills/c64-reverse-engineering/SKILL.md +1 -1
- package/skills/c64-source/SKILL.md +7 -7
- package/skills/c64-source/scripts/lib/source.ts +10 -0
- package/skills/c64-source/scripts/source.ts +32 -27
- package/skills/c64-static-analysis/SKILL.md +5 -3
- package/skills/c64-static-analysis/scripts/lib/instructions.ts +22 -20
- package/skills/c64-static-analysis/scripts/static-analysis.ts +16 -16
- package/skills/c64-testing/SKILL.md +2 -1
- package/skills/c64-testing/references/recording-format.md +17 -3
- package/skills/c64-testing/references/scenario-format.md +2 -3
- package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
- package/skills/c64-testing/scripts/lib/play.ts +39 -41
- package/skills/c64-testing/scripts/lib/recording.ts +21 -29
- package/skills/c64-testing/scripts/lib/runs.ts +2 -2
- package/skills/c64-testing/scripts/lib/scenario.ts +3 -5
- package/skills/c64-unpacker/SKILL.md +2 -1
- package/skills/c64-unpacker/scripts/lib/loads.ts +2 -2
- package/skills/emulator/SKILL.md +2 -5
- package/src/c64-keys.ts +98 -0
- package/src/cli/main.ts +1 -1
- package/src/host/vice/session.ts +82 -8
- package/src/host-client/steps.ts +17 -17
- package/src/host-client/tools.ts +1 -1
- package/src/host-client/vice-session.ts +7 -1
- package/src/knowledge/read.ts +25 -1
- package/src/mcp/inputs.ts +12 -0
- package/src/mcp/server.ts +1 -0
- package/src/mcp/tools/input.ts +38 -5
- package/src/native/c64run.ts +1 -1
- package/src/native/discover.ts +3 -3
- package/src/native/ghidra/analyze.ts +74 -63
- package/src/native/ghidra/c64rt-wasm.ts +4 -0
- package/src/native/ghidra/language/c64rt_6510.sla +0 -0
- package/src/native/ghidra/pcode.ts +222 -0
- package/src/native/ghidra/walk.ts +205 -0
- package/src/native/ghidra/wasm.ts +98 -0
- package/src/native/processes.ts +4 -4
- package/src/native/types.ts +2 -2
- package/src/project.ts +4 -3
- package/src/protocol/vice.ts +47 -0
- package/src/script.ts +1 -1
- package/src/vsf.ts +98 -0
- package/tools/c64run.c +9 -12
- package/tools/install-container.sh +1 -2
- package/src/native/ghidra/index.ts +0 -170
- package/src/native/ghidra/scripts/C64Export.java +0 -274
- package/src/native/ghidra/scripts/C64Prepare.java +0 -66
- package/tools/install-ghidra.sh +0 -40
|
@@ -42,6 +42,7 @@ To get the command list, run the script with no arguments.
|
|
|
42
42
|
- The original gets its names from the project knowledge. Give `"symbols": "knowledge"` for the original.
|
|
43
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
44
|
- You write the scenario file, the run file and the record file. Their formats are in the files of the section "Reference".
|
|
45
|
+
- A file in `tests/` is a scenario or a run file with expected values. Give a scenario to `test` and a run file to `run`. `test` refuses a run file.
|
|
45
46
|
- `<recording>` is the `--out` folder of `record`.
|
|
46
47
|
- `--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
48
|
- `--state` and `--pin` take a name or a `$` address, with `:size` for more than one byte, for example `room:2`. Use the names that the project knowledge has at the time of the replay.
|
|
@@ -250,7 +251,7 @@ Do this for each result:
|
|
|
250
251
|
|
|
251
252
|
Traps:
|
|
252
253
|
|
|
253
|
-
- `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.
|
|
254
|
+
- `idleReads` counts the input reads of the rebuild that the recording had no value for. On the original, such a read makes the result INCONCLUSIVE. The rebuild can read input where the original does not, for example in its loader before the start screen. Such reads do not change a PASS of the rebuild.
|
|
254
255
|
- The script refuses a recording of version 2.0 with `invalid-input`. Record the session again.
|
|
255
256
|
|
|
256
257
|
---
|
|
@@ -37,7 +37,7 @@ A record file is one JSON object in a project file.
|
|
|
37
37
|
The steps have the form of the steps of a scenario. Two steps behave differently:
|
|
38
38
|
|
|
39
39
|
- `type` puts at most 10 keys into the keyboard queue of the KERNAL. It is an event: a replay does it again.
|
|
40
|
-
- `press` pushes keys of the keyboard matrix. It is input.
|
|
40
|
+
- `press` pushes keys of the keyboard matrix. It is input.
|
|
41
41
|
|
|
42
42
|
A record file has no `raster` target and no `condition`. `write` and `runUntil` have only the space `c64`.
|
|
43
43
|
|
|
@@ -45,19 +45,33 @@ A record file has no `raster` target and no `condition`. `write` and `runUntil`
|
|
|
45
45
|
|---|---|
|
|
46
46
|
| `{ "frames": 300 }` | Run 300 frames (19656 cycles each). |
|
|
47
47
|
| `{ "joystick": { "port": 2, "direction": "left", "fire": true } }` | Set a joystick. It stays in this state until the next joystick step. |
|
|
48
|
-
| `{ "press": "RUN\n" }` | Press
|
|
48
|
+
| `{ "press": { "keys": "RUN\n" } }` | Press the keys of the keyboard matrix. Each tap holds its keys for 3 frames, then releases them for 3 frames. `frames` sets a different number, from 1 to 3000. |
|
|
49
49
|
| `{ "type": { "mode": "text", "text": "RUN\n" } }` | Put at most 10 keys into the keyboard queue of the KERNAL, after the keys that wait there. |
|
|
50
50
|
| `{ "write": { "address": "next_room", "data": "01" } }` | Write bytes into RAM. |
|
|
51
51
|
| `{ "registers": { "pc": "change_room", "a": 16 } }` | Set registers at the next instruction. `pc` continues the program at that address. |
|
|
52
52
|
| `{ "runUntil": { "target": { "kind": "address", "address": "main_loop" }, "timeoutFrames": 300 } }` | Run until the CPU gets to an address. |
|
|
53
53
|
| `{ "runUntil": { "target": { "kind": "memory", "address": "room", "operator": "eq", "value": 2 }, "timeoutFrames": 600 } }` | Run until a byte compares true with `value`. The script reads the byte at the end of each frame. |
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
Each character of `keys` is one tap. a to z press the same keys as A to Z. `\n` presses RETURN. A character with SHIFT, for example `!`, also presses the left SHIFT.
|
|
56
|
+
|
|
57
|
+
The program runs while a `press` step taps its keys. An event in these frames is past when the next step starts. After a `press` step, run until an address that the program gets to later. For example, after F1 starts a game, run until the main loop of the game, not until the routine that starts the game.
|
|
58
|
+
|
|
59
|
+
A key without a character has its name in braces, in upper or lower case. `{STOP}` is RUN/STOP, and `{CBM}` is the Commodore key. The names are:
|
|
60
|
+
|
|
61
|
+
- `{F1}` to `{F8}`, `{RETURN}`, `{SPACE}`, `{DEL}`, `{INST}`, `{HOME}`, `{CLR}`
|
|
62
|
+
- `{STOP}`, `{RUN}`, `{RESTORE}`, `{CTRL}`, `{CBM}`, `{LSHIFT}`, `{RSHIFT}`
|
|
63
|
+
- `{UP}`, `{DOWN}`, `{LEFT}`, `{RIGHT}`, `{POUND}`, `{UPARROW}`, `{LEFTARROW}`
|
|
64
|
+
|
|
65
|
+
`{F2}`, `{F4}`, `{F6}`, `{F8}`, `{RUN}`, `{CLR}`, `{INST}`, `{UP}` and `{LEFT}` also press the left SHIFT.
|
|
66
|
+
|
|
67
|
+
To hold keys together in one tap, join them with `+` in braces. For example, `{ "press": { "keys": "{LSHIFT+CBM}" } }` holds the left SHIFT and the Commodore key together. One tap holds at most 4 keys. RESTORE counts as a key.
|
|
56
68
|
|
|
57
69
|
The keyboard queue of the KERNAL holds 10 keys. If the keys of a `type` step and the keys that wait in the queue do not fit, the session stops. A program that reads the keyboard hardware does not see the keys of a `type` step. Use `press` for that program.
|
|
58
70
|
|
|
59
71
|
`joystick`, `press` and `frames` steps are input and time. The recording keeps their effect in the reads, so a replay does not do these steps again.
|
|
60
72
|
|
|
73
|
+
RESTORE starts an NMI and is not a read. The recording keeps each RESTORE of a `press` step as an event of that step. The replay presses RESTORE again at the same read of the program.
|
|
74
|
+
|
|
61
75
|
`type`, `write`, `registers` and `runUntil` steps are events. The recording keeps a point in the program for each event. The point is the next read at the input site with the most reads. That site is not in ROM. A replay does the event again at the same read. An event that comes directly after another event runs at once after that event.
|
|
62
76
|
|
|
63
77
|
## Play
|
|
@@ -46,8 +46,9 @@ Before the first step of each side, the script does a hard reset. The CPU stops
|
|
|
46
46
|
| `{ "write": { "address": "seed", "data": "0102" } }` | Write 1 to 4096 bytes into memory. Optional: `space` (`c64` or `drive8`, default `c64`) and `view` (`cpu` or `ram`, default `cpu`). |
|
|
47
47
|
| `{ "registers": { "pc": "start", "a": 0, "flags": { "i": true } } }` | Set registers: `pc`, `a`, `x`, `y`, `sp` and `flags` (`n`, `v`, `b`, `d`, `i`, `z`, `c`). Only `pc` can be a name. |
|
|
48
48
|
| `{ "joystick": { "port": 2, "direction": "left", "fire": true } }` | Set a joystick. `fire` is `false` by default. The joystick stays in this state until the next joystick step. |
|
|
49
|
-
| `{ "type": { "mode": "text", "text": "RUN\n" } }` | Put at most 1024 keys into the keyboard queue of the KERNAL. A program that reads the keyboard hardware does not see them. |
|
|
49
|
+
| `{ "type": { "mode": "text", "text": "RUN\n" } }` | Put at most 1024 keys into the keyboard queue of the KERNAL. A program that reads the keyboard hardware does not see them. Use `press` for that program. |
|
|
50
50
|
| `{ "type": { "mode": "petscii", "bytes": [147] } }` | Put PETSCII codes from 1 to 255 into the keyboard queue of the KERNAL. Use it for keys that mode `text` does not have. |
|
|
51
|
+
| `{ "press": { "keys": "{F1}" } }` | Press keys of the keyboard matrix and RESTORE. A program that reads the keyboard hardware sees them. Each tap holds its keys for 3 frames, then releases them for 3 frames. Optional: `frames` from 1 to 3000. The keys are the same as the keys of a `press` step of a record file. |
|
|
51
52
|
| `{ "runUntil": { "target": { "kind": "address", "address": "main_loop" }, "timeoutFrames": 600 } }` | Run until the CPU gets to an address. |
|
|
52
53
|
| `{ "runUntil": { "target": { "kind": "memory", "address": "game_state", "operator": "eq", "value": 2 }, "timeoutFrames": 600 } }` | Run until a write to the byte makes the comparison with `value` true. `operator` is `eq`, `ne`, `lt`, `lte`, `gt` or `gte`. The run does not stop for a byte that is already true at the start. It also does not stop for a register that the hardware changes, for example `$d012`. For a raster line, use a `raster` target. |
|
|
53
54
|
| `{ "runUntil": { "target": { "kind": "raster", "line": 250 }, "timeoutFrames": 5 } }` | Run until the raster beam gets to a line (0 to 311 for PAL, 0 to 262 for NTSC). Optional: `cycle` from 0 to 64. |
|
|
@@ -62,8 +63,6 @@ A `condition` has the `kind` `register`, `memory` or `raster`. A `register` cond
|
|
|
62
63
|
|
|
63
64
|
`timeoutFrames` is from 1 to 30000, and 3000 by default. A `runUntil` that does not get to its target in `timeoutFrames` frames makes the result INCONCLUSIVE.
|
|
64
65
|
|
|
65
|
-
A scenario has no `press` step. Only a record file has `press` for keys of the keyboard matrix.
|
|
66
|
-
|
|
67
66
|
Each step except `observe` can have `"side": "original"` or `"side": "rebuild"`. Then only that side does the step. Use it when only one side needs a step, for example a key for the intro of the original. An `observe` step has no `side`, because it compares both sides.
|
|
68
67
|
|
|
69
68
|
Each side finds a name in its own symbols.
|
|
@@ -10,8 +10,9 @@ import { isObject } from "#src/host-client/steps.ts";
|
|
|
10
10
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
11
11
|
import { readProjectFile, writeReported } from "#src/host-client/transfer.ts";
|
|
12
12
|
import { readMemoryInParts, ViceSessionClient } from "#src/host-client/vice-session.ts";
|
|
13
|
-
import { checkSnapshotFile
|
|
13
|
+
import { checkSnapshotFile } from "#src/media.ts";
|
|
14
14
|
import { listed, UsageError } from "#src/script.ts";
|
|
15
|
+
import { snapshotModule } from "#src/vsf.ts";
|
|
15
16
|
import { diffStates, type ChangedRange, type MachineState } from "./diff.ts";
|
|
16
17
|
|
|
17
18
|
type Kind = "snapshot" | "memory" | "observation";
|
|
@@ -58,29 +59,14 @@ function cpuValues(registers: Record<string, unknown>): Record<string, number |
|
|
|
58
59
|
return values;
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
/** The size of the header of a module in a VICE snapshot file: the name (16 bytes), the version (2 bytes) and the size (4 bytes). */
|
|
62
|
-
const MODULE_HEADER = 22;
|
|
63
|
-
const VSF_VERSION = "VICE Version\x1a";
|
|
64
|
-
|
|
65
62
|
/**
|
|
66
63
|
* The data of the C64MEM module of a VICE snapshot file: the data and the
|
|
67
64
|
* direction register of the CPU port, the cartridge lines (2 bytes), then
|
|
68
65
|
* the 64 KiB of RAM. Undefined when the file has no such module.
|
|
69
66
|
*/
|
|
70
67
|
function c64Memory(file: Uint8Array): Buffer | undefined {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
// The magic, the version (2 bytes) and the machine name (16 bytes); a newer VICE adds its own version (8 bytes).
|
|
74
|
-
let at = VSF_SIGNATURE.length + 2 + 16;
|
|
75
|
-
if (bytes.subarray(at, at + VSF_VERSION.length).toString("latin1") === VSF_VERSION) at += VSF_VERSION.length + 8;
|
|
76
|
-
while (at + MODULE_HEADER <= bytes.length) {
|
|
77
|
-
const name = bytes.subarray(at, at + 16).toString("latin1").replace(/\0+$/, "");
|
|
78
|
-
const size = bytes.readUInt32LE(at + 18);
|
|
79
|
-
if (size < MODULE_HEADER) return undefined;
|
|
80
|
-
if (name === "C64MEM") return at + MODULE_HEADER + 4 + 0x10000 <= bytes.length ? bytes.subarray(at + MODULE_HEADER, at + MODULE_HEADER + 4 + 0x10000) : undefined;
|
|
81
|
-
at += size;
|
|
82
|
-
}
|
|
83
|
-
return undefined;
|
|
68
|
+
const data = snapshotModule(Buffer.from(file), "C64MEM")?.data;
|
|
69
|
+
return data !== undefined && data.length >= 4 + 0x10000 ? data.subarray(0, 4 + 0x10000) : undefined;
|
|
84
70
|
}
|
|
85
71
|
|
|
86
72
|
/** The 64 KiB of C64 RAM that a VICE snapshot file holds, also the RAM under the CPU port at $00/$01. Undefined when the file has no C64MEM module. */
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { createServer, type ServerResponse } from "node:http";
|
|
10
10
|
|
|
11
|
+
import { keyTaps, type KeyTap } from "#src/c64-keys.ts";
|
|
11
12
|
import { PAL_FRAME_CYCLES, type C64RunSession } from "#src/native/c64run.ts";
|
|
12
13
|
|
|
13
14
|
const FRAME_MS = 20;
|
|
@@ -26,50 +27,46 @@ export interface PlayOptions {
|
|
|
26
27
|
restore: () => Promise<string | undefined>;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
/** The key codes of the replay core: chips c64.h, and 11, 12 and 5e of c64run. */
|
|
30
|
-
const C64 = {
|
|
31
|
-
del: 0x01, clr: 0x02, stop: 0x03, leftArrow: 0x04, run: 0x07, csrLeft: 0x08, csrRight: 0x09, csrDown: 0x0a, csrUp: 0x0b,
|
|
32
|
-
home: 0x0c, return: 0x0d, ctrl: 0x0e, cbm: 0x0f, inst: 0x10, leftShift: 0x11, rightShift: 0x12, space: 0x20, upArrow: 0x5e, pound: 0x7e,
|
|
33
|
-
} as const;
|
|
34
|
-
const F_KEYS = [0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8];
|
|
35
30
|
const LETTERS = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"];
|
|
36
31
|
const DIGITS = [..."0123456789"];
|
|
37
|
-
const
|
|
32
|
+
const F_KEYS = [1, 2, 3, 4, 5, 6, 7, 8].map((number) => `{F${number}}`);
|
|
33
|
+
/** The matrix places of one key, as a press step names it: a character, or a name in braces. */
|
|
34
|
+
const places = (key: string) => (keyTaps(key) as KeyTap[])[0]!.keys;
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
|
-
* The key maps of the page. Each one maps a KeyboardEvent property to
|
|
41
|
-
* The symbolic map (event.key) gives the character on the PC key;
|
|
42
|
-
* map (event.code) gives the C64 key at the place of the PC key, with each SHIFT alone.
|
|
37
|
+
* The key maps of the page. Each one maps a KeyboardEvent property to the matrix places
|
|
38
|
+
* that go down together. The symbolic map (event.key) gives the character on the PC key;
|
|
39
|
+
* the positional map (event.code) gives the C64 key at the place of the PC key, with each SHIFT alone.
|
|
43
40
|
*/
|
|
44
41
|
export const KEY_MAPS = {
|
|
45
42
|
/** event.code, in both maps. */
|
|
46
|
-
both: { Tab:
|
|
43
|
+
both: { Tab: places("{CTRL}"), AltLeft: places("{CBM}") },
|
|
47
44
|
/** event.code, when the arrow keys and space are keyboard keys. */
|
|
48
|
-
arrows: { ArrowUp:
|
|
45
|
+
arrows: { ArrowUp: places("{UP}"), ArrowDown: places("{DOWN}"), ArrowLeft: places("{LEFT}"), ArrowRight: places("{RIGHT}"), Space: places(" ") },
|
|
49
46
|
/** event.code */
|
|
50
47
|
positional: {
|
|
51
|
-
...Object.fromEntries(LETTERS.map((letter) => ["Key" + letter,
|
|
52
|
-
...Object.fromEntries(DIGITS.map((digit) => ["Digit" + digit,
|
|
53
|
-
...Object.fromEntries(F_KEYS.map((key, index) => ["F" + (index + 1), key])),
|
|
54
|
-
Backquote:
|
|
55
|
-
BracketLeft:
|
|
56
|
-
Escape:
|
|
57
|
-
ShiftLeft:
|
|
58
|
-
} as Record<string, number>,
|
|
48
|
+
...Object.fromEntries(LETTERS.map((letter) => ["Key" + letter, places(letter)])),
|
|
49
|
+
...Object.fromEntries(DIGITS.map((digit) => ["Digit" + digit, places(digit)])),
|
|
50
|
+
...Object.fromEntries(F_KEYS.map((key, index) => ["F" + (index + 1), places(key)])),
|
|
51
|
+
Backquote: places("{LEFTARROW}"), Minus: places("+"), Equal: places("-"), Insert: places("{POUND}"), Home: places("{HOME}"), Backspace: places("{DEL}"),
|
|
52
|
+
BracketLeft: places("@"), BracketRight: places("*"), Delete: places("{UPARROW}"),
|
|
53
|
+
Escape: places("{STOP}"), Semicolon: places(":"), Quote: places(";"), Backslash: places("="), Enter: places("{RETURN}"),
|
|
54
|
+
ShiftLeft: places("{LSHIFT}"), ShiftRight: places("{RSHIFT}"), Comma: places(","), Period: places("."), Slash: places("/"),
|
|
55
|
+
} as Record<string, number[]>,
|
|
59
56
|
/** event.key; a-z are the C64 letters, A-Z the letters with SHIFT. */
|
|
60
57
|
symbolic: {
|
|
61
|
-
...Object.fromEntries(LETTERS.flatMap((letter) => [[letter.toLowerCase(),
|
|
62
|
-
...Object.fromEntries([...DIGITS, ..."+-.:@,*;=/!\"#$%&'()[]<>?"].map((character) => [character,
|
|
63
|
-
...Object.fromEntries(F_KEYS.map((key, index) => ["F" + (index + 1), key])),
|
|
64
|
-
"£":
|
|
65
|
-
Enter:
|
|
66
|
-
} as Record<string, number>,
|
|
58
|
+
...Object.fromEntries(LETTERS.flatMap((letter) => [[letter.toLowerCase(), places(letter)], [letter, places(`{LSHIFT+${letter}}`)]])),
|
|
59
|
+
...Object.fromEntries([...DIGITS, ..."+-.:@,*;=/!\"#$%&'()[]<>?"].map((character) => [character, places(character)])),
|
|
60
|
+
...Object.fromEntries(F_KEYS.map((key, index) => ["F" + (index + 1), places(key)])),
|
|
61
|
+
"£": places("{POUND}"), "^": places("{UPARROW}"), "`": places("{LEFTARROW}"),
|
|
62
|
+
Enter: places("{RETURN}"), Backspace: places("{DEL}"), Delete: places("{DEL}"), Insert: places("{INST}"), Home: places("{HOME}"), Escape: places("{STOP}"),
|
|
63
|
+
} as Record<string, number[]>,
|
|
67
64
|
/** event.key with SHIFT held, in the symbolic map. */
|
|
68
|
-
symbolicShift: { Home:
|
|
65
|
+
symbolicShift: { Home: places("{CLR}"), Backspace: places("{INST}"), Escape: places("{RUN}"), F1: places("{F2}"), F3: places("{F4}"), F5: places("{F6}"), F7: places("{F8}") } as Record<string, number[]>,
|
|
69
66
|
};
|
|
70
67
|
|
|
71
|
-
/** The
|
|
72
|
-
const PAGE_KEYS = new Set(Object.values(KEY_MAPS).flatMap((map) => Object.values(map)));
|
|
68
|
+
/** The matrix places that the page can send: every place of the key maps. */
|
|
69
|
+
const PAGE_KEYS = new Set(Object.values(KEY_MAPS).flatMap((map) => Object.values(map).flat()));
|
|
73
70
|
|
|
74
71
|
const PAGE = String.raw`<!doctype html>
|
|
75
72
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
@@ -100,7 +97,7 @@ const BITS = { ArrowUp: 1, ArrowDown: 2, ArrowLeft: 4, ArrowRight: 8, Space: 16
|
|
|
100
97
|
const $ = (id) => document.getElementById(id);
|
|
101
98
|
const canvas = $("screen"), context = canvas.getContext("2d"), state = $("state");
|
|
102
99
|
let palette = [], image = context.createImageData(392, 272), frames = 0, phase = "connecting", port = 2, arrows = "joystick", keyMap = "symbolic", sent = -1;
|
|
103
|
-
// The
|
|
100
|
+
// The matrix places of each PC key that is down (by event.code), and the joystick keys that are down.
|
|
104
101
|
const pressed = new Map(), stick = new Set();
|
|
105
102
|
// One request at a time, so that the core gets each key down before its key up.
|
|
106
103
|
let queue = Promise.resolve();
|
|
@@ -120,7 +117,7 @@ function show() {
|
|
|
120
117
|
else state.textContent = phase;
|
|
121
118
|
}
|
|
122
119
|
function releaseAll() {
|
|
123
|
-
for (const
|
|
120
|
+
for (const keys of pressed.values()) send("key?keys=" + keys.join(",") + "&down=0");
|
|
124
121
|
pressed.clear();
|
|
125
122
|
stick.clear();
|
|
126
123
|
}
|
|
@@ -180,19 +177,19 @@ function key(event, down) {
|
|
|
180
177
|
}
|
|
181
178
|
if (arrows === "joystick" && event.code in BITS) { event.preventDefault(); down ? stick.add(event.code) : stick.delete(event.code); return; }
|
|
182
179
|
if (!down) {
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
180
|
+
const keys = pressed.get(event.code);
|
|
181
|
+
if (keys === undefined) return;
|
|
185
182
|
event.preventDefault();
|
|
186
183
|
pressed.delete(event.code);
|
|
187
|
-
send("key?
|
|
184
|
+
send("key?keys=" + keys.join(",") + "&down=0");
|
|
188
185
|
return;
|
|
189
186
|
}
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
187
|
+
const keys = c64Key(event);
|
|
188
|
+
if (keys === undefined) return;
|
|
192
189
|
event.preventDefault();
|
|
193
190
|
if (event.repeat || phase !== "playing" || pressed.has(event.code)) return;
|
|
194
|
-
pressed.set(event.code,
|
|
195
|
-
send("key?
|
|
191
|
+
pressed.set(event.code, keys);
|
|
192
|
+
send("key?keys=" + keys.join(",") + "&down=1");
|
|
196
193
|
}
|
|
197
194
|
addEventListener("keydown", (event) => key(event, true));
|
|
198
195
|
addEventListener("keyup", (event) => key(event, false));
|
|
@@ -262,9 +259,10 @@ export async function play(core: Pick<C64RunSession, "command" | "status">, opti
|
|
|
262
259
|
if (phase === "playing") mask = Number(url.searchParams.get("mask")) & 0x1f;
|
|
263
260
|
answer(phase === "playing");
|
|
264
261
|
} else if (request.method === "POST" && url.pathname === "/key") {
|
|
265
|
-
const
|
|
266
|
-
if (!PAGE_KEYS.has(key)) return void response.writeHead(400).end();
|
|
267
|
-
|
|
262
|
+
const keys = (url.searchParams.get("keys") ?? "").split(",").map((key) => (/^\d{1,2}$/.test(key) ? Number(key) : -1));
|
|
263
|
+
if (!keys.every((key) => PAGE_KEYS.has(key))) return void response.writeHead(400).end();
|
|
264
|
+
const state = url.searchParams.get("down") === "1" ? "down" : "up";
|
|
265
|
+
if (phase === "playing") for (const key of keys) pending.push("key " + (0x80 + key).toString(16) + " " + state);
|
|
268
266
|
answer(phase === "playing");
|
|
269
267
|
} else if (request.method === "POST" && url.pathname === "/restore") {
|
|
270
268
|
if (phase === "playing") pending.push(RESTORE);
|
|
@@ -13,6 +13,7 @@ import { readFileSync, writeFileSync } from "node:fs";
|
|
|
13
13
|
|
|
14
14
|
import { isRefusal, Refusal } from "#src/errors.ts";
|
|
15
15
|
import { c64AddressOf, formatC64Address, parseC64Address } from "#src/c64.ts";
|
|
16
|
+
import { keyTaps, type KeyTap } from "#src/c64-keys.ts";
|
|
16
17
|
import { READY_FRAMES } from "#src/host-client/entry-state.ts";
|
|
17
18
|
import { ACTION_STEP_KINDS, checkActionStep, isInteger, isObject, keyboardBytes, renamedField, stepKind, type ActionStep, type Location } from "#src/host-client/steps.ts";
|
|
18
19
|
import { readProjectFile, type Written } from "#src/host-client/transfer.ts";
|
|
@@ -138,20 +139,8 @@ const QUEUE_SIZE = 10;
|
|
|
138
139
|
|
|
139
140
|
const hex = (address: number) => address.toString(16).padStart(4, "0");
|
|
140
141
|
|
|
141
|
-
/** The
|
|
142
|
-
const
|
|
143
|
-
...[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 +-.:@,*;=/!\"#$%&'()[]<>?"].map((character) => [character, character.charCodeAt(0)] as [string, number]),
|
|
144
|
-
["\n", 0x0d],
|
|
145
|
-
]);
|
|
146
|
-
|
|
147
|
-
/** The key codes of a text; a-z type as A-Z, as the C64 shows them after power-on. */
|
|
148
|
-
export function keyCodes(text: string): number[] {
|
|
149
|
-
return [...text.replace(/\r\n?/g, "\n")].map((character) => {
|
|
150
|
-
const code = KEY_CODES.get(character.toUpperCase());
|
|
151
|
-
if (code === undefined) throw new Refusal("invalid-input", `press cannot press ${JSON.stringify(character)} on the C64 keyboard`);
|
|
152
|
-
return code;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
142
|
+
/** The key code of the replay core for a matrix place: 80 + the place. RESTORE is ff. */
|
|
143
|
+
const coreKey = (place: number) => (0x80 + place).toString(16);
|
|
155
144
|
|
|
156
145
|
/** The joystick mask of the replay core: 1 up, 2 down, 4 left, 8 right, $10 fire. */
|
|
157
146
|
export function joystickMask(direction: Extract<ActionStep, { joystick: unknown }>["joystick"]["direction"], fire: boolean): number {
|
|
@@ -226,7 +215,7 @@ export function readRecordFile(path: string): RecordFile {
|
|
|
226
215
|
if (!Array.isArray(value.steps) || value.steps.length === 0) fail("steps must be a list with at least one step");
|
|
227
216
|
const steps = (value.steps as unknown[]).map((raw, index) => {
|
|
228
217
|
const at = `step ${index + 1}`;
|
|
229
|
-
const step = checkActionStep(stepKind(raw, ACTION_STEP_KINDS, at, fail), raw as Record<string, unknown>, at, fail
|
|
218
|
+
const step = checkActionStep(stepKind(raw, ACTION_STEP_KINDS, at, fail), raw as Record<string, unknown>, at, fail);
|
|
230
219
|
checkCoreStep(step, at, fail);
|
|
231
220
|
return step;
|
|
232
221
|
});
|
|
@@ -245,14 +234,6 @@ export function readRecordFile(path: string): RecordFile {
|
|
|
245
234
|
/** What the replay core cannot do of a step that is right for VICE: it has the C64 alone, no raster wait and no conditions. */
|
|
246
235
|
function checkCoreStep(step: ActionStep, at: string, fail: (message: string) => never): void {
|
|
247
236
|
if ("write" in step && step.write.space !== "c64") fail(`${at}: a recording has the C64 alone, not ${step.write.space}`);
|
|
248
|
-
if ("press" in step) {
|
|
249
|
-
try {
|
|
250
|
-
keyCodes(step.press);
|
|
251
|
-
} catch (error) {
|
|
252
|
-
if (isRefusal(error)) fail(`${at}: ${error.message}`);
|
|
253
|
-
throw error;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
237
|
if ("type" in step) {
|
|
257
238
|
const keys = keyboardBytes(step.type);
|
|
258
239
|
if (typeof keys !== "string" && keys.length > QUEUE_SIZE) fail(`${at}: the KERNAL keyboard queue holds ${QUEUE_SIZE} keys; give more type steps, or press for keys of the keyboard matrix`);
|
|
@@ -298,7 +279,7 @@ export function readRecording(folder: string): Recording {
|
|
|
298
279
|
const named = typeof event.step === "number" ? `${at} (step ${event.step})` : at;
|
|
299
280
|
if (event.action.restore === true && Object.keys(event.action).length === 1) return;
|
|
300
281
|
// The action with the defaults filled in, as the record file gave it.
|
|
301
|
-
event.action = checkActionStep(stepKind(event.action, ACTION_STEP_KINDS, named, where), event.action, named, where
|
|
282
|
+
event.action = checkActionStep(stepKind(event.action, ACTION_STEP_KINDS, named, where), event.action, named, where);
|
|
302
283
|
});
|
|
303
284
|
return value as unknown as Recording;
|
|
304
285
|
}
|
|
@@ -523,11 +504,22 @@ export async function record(
|
|
|
523
504
|
masks[step.joystick.port - 1] = joystickMask(step.joystick.direction, step.joystick.fire ?? false);
|
|
524
505
|
await core.command(`joy ${masks[0]!.toString(16)} ${masks[1]!.toString(16)}`);
|
|
525
506
|
} else if ("press" in step) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
await core.
|
|
529
|
-
|
|
530
|
-
await
|
|
507
|
+
const hold = step.press.frames * PAL_FRAME_CYCLES;
|
|
508
|
+
for (const tap of keyTaps(step.press.keys) as KeyTap[]) {
|
|
509
|
+
for (const place of tap.keys) await core.command(`key ${coreKey(place)} down`);
|
|
510
|
+
// RESTORE is no read: an event at the next read of the program, with the keys of the tap down.
|
|
511
|
+
if (tap.restore) reason = await runEvent({ restore: true }, index + 1);
|
|
512
|
+
if (reason !== undefined) break;
|
|
513
|
+
tick = (await core.status("status")).tick;
|
|
514
|
+
await core.status(`run ${(tick += hold)}`);
|
|
515
|
+
for (const place of tap.keys) await core.command(`key ${coreKey(place)} up`);
|
|
516
|
+
await core.status(`run ${(tick += hold)}`);
|
|
517
|
+
// Frames ran: the next RESTORE is no event right after an event.
|
|
518
|
+
afterEvent = false;
|
|
519
|
+
}
|
|
520
|
+
if (reason !== undefined) {
|
|
521
|
+
reason = `step ${index + 1}: RESTORE: ${reason}`;
|
|
522
|
+
break;
|
|
531
523
|
}
|
|
532
524
|
} else {
|
|
533
525
|
reason = await runEvent(step, index + 1);
|
|
@@ -9,7 +9,7 @@ import { screenText } from "#src/graphics.ts";
|
|
|
9
9
|
import { runProgram } from "#src/host-client/autostart.ts";
|
|
10
10
|
import { isRefusal, Refusal } from "#src/errors.ts";
|
|
11
11
|
import { readCoverage } from "#src/host-client/coverage.ts";
|
|
12
|
-
import { ACTION_STEP_KINDS, checkActionStep, checkLocation, checkStepNames, isInteger, isObject, refuseOldStep, renamedField, runActionStep,
|
|
12
|
+
import { ACTION_STEP_KINDS, checkActionStep, checkLocation, checkStepNames, isInteger, isObject, refuseOldStep, renamedField, runActionStep, type ActionStep, type ActionStepKind } from "#src/host-client/steps.ts";
|
|
13
13
|
import { readPrg } from "#src/host-client/image.ts";
|
|
14
14
|
import { MAX_MEMORY_READ, MAX_TRACE_FRAMES, MAX_TRACE_HITS, MAX_TRACE_POINTS, TRACE_KINDS, WireFailure, type TraceHit, type TraceKind } from "#src/host-client/tools.ts";
|
|
15
15
|
import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
|
|
@@ -131,7 +131,7 @@ function readRun(path: string): Run {
|
|
|
131
131
|
if (!isObject(step)) return fail(`${at} must be an object`);
|
|
132
132
|
const kinds = "observe" in step ? ["observe"] : "expect" in step ? ["expect"] : "trace" in step ? ["trace"] : Object.keys(step).filter((key) => (ACTION_STEP_KINDS as readonly string[]).includes(key) || (OWN_KINDS as readonly string[]).includes(key));
|
|
133
133
|
if (kinds.length > 1) return fail(`${at} has ${kinds.length} step kinds: ${kinds.join(", ")}. Give each one its own step`);
|
|
134
|
-
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...
|
|
134
|
+
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...ACTION_STEP_KINDS, ...OWN_KINDS].join(", ")}`);
|
|
135
135
|
const kind = kinds[0]!;
|
|
136
136
|
refuseOldStep(kind, step, at, fail);
|
|
137
137
|
const allowed = kind === "observe" ? OBSERVE_KEYS : kind === "expect" ? EXPECT_KEYS : kind === "trace" ? TRACE_KEYS : [kind];
|
|
@@ -7,7 +7,7 @@ import { isRefusal, Refusal } from "#src/errors.ts";
|
|
|
7
7
|
import { c64AddressOf, formatC64Address, formatSprite, formatVicii, parseC64Address } from "#src/c64.ts";
|
|
8
8
|
import { MAX_BASELINES, MAX_MASK_RECTANGLES, maskCoversFrame, WireFailure } from "#src/host-client/tools.ts";
|
|
9
9
|
import { LOAD_LIMIT_FRAMES, RUN_LIMIT_FRAMES, runProgram } from "#src/host-client/autostart.ts";
|
|
10
|
-
import { ACTION_STEP_KINDS, checkActionStep, checkLocation, isInteger, isObject, refuseOldStep, renamedField, runActionStep,
|
|
10
|
+
import { ACTION_STEP_KINDS, checkActionStep, checkLocation, isInteger, isObject, refuseOldStep, renamedField, runActionStep, type ActionStep, type ActionStepKind, type Location } from "#src/host-client/steps.ts";
|
|
11
11
|
import { applyEntryState, parseEntryState } from "#src/host-client/entry-state.ts";
|
|
12
12
|
import { readPrg } from "#src/host-client/image.ts";
|
|
13
13
|
import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
|
|
@@ -52,7 +52,7 @@ type StepBody =
|
|
|
52
52
|
| { autostart: true }
|
|
53
53
|
| { snapshot: string }
|
|
54
54
|
| { normalize: true }
|
|
55
|
-
|
|
|
55
|
+
| ActionStep
|
|
56
56
|
| { observe: string; memory?: Array<Location | MemoryObservation>; registers?: ObservedRegister[]; screen?: ScreenPolicy; vicii?: boolean; sprites?: number[] };
|
|
57
57
|
|
|
58
58
|
/** A step; with side, only that side does it. An observe step has no side: it compares both. */
|
|
@@ -108,8 +108,6 @@ export interface ScenarioResult {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
const STEP_KINDS = ["reset", "load", "autostart", "snapshot", "normalize", ...ACTION_STEP_KINDS, "observe"];
|
|
111
|
-
/** The step kinds that a scenario runs: press is for the replay core only. */
|
|
112
|
-
const SHOWN_KINDS = ["reset", "load", "autostart", "snapshot", "normalize", ...VICE_STEP_KINDS, "observe"];
|
|
113
111
|
|
|
114
112
|
/** The keys of a scenario file: all but videoStandard are required. */
|
|
115
113
|
const SCENARIO_KEYS = ["name", "original", "rebuild", "steps", "videoStandard"];
|
|
@@ -156,7 +154,7 @@ export function readScenario(path: string): Scenario {
|
|
|
156
154
|
// An observe step names what it observes with "memory" and "registers" too.
|
|
157
155
|
const kinds = "observe" in step ? ["observe"] : Object.keys(step).filter((key) => STEP_KINDS.includes(key));
|
|
158
156
|
if (kinds.length > 1) return fail(`${at} has ${kinds.length} step kinds: ${kinds.join(", ")}. Give each one its own step`);
|
|
159
|
-
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${
|
|
157
|
+
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${STEP_KINDS.join(", ")}`);
|
|
160
158
|
const kind = kinds[0]!;
|
|
161
159
|
refuseOldStep(kind, step, at, fail);
|
|
162
160
|
const allowed = [...(STEP_KEYS[kind] ?? [kind]), ...(kind === "observe" ? [] : ["side"])];
|
|
@@ -58,6 +58,7 @@ Each step has one of these kinds:
|
|
|
58
58
|
- `{ "registers": { "pc": "start", "a": 1 } }` sets registers. Only `pc` takes a name.
|
|
59
59
|
- `{ "joystick": { "port": 2, "direction": "up", "fire": false } }` sets a joystick.
|
|
60
60
|
- `{ "type": { "mode": "text", "text": "RUN\n" } }` or `{ "type": { "mode": "petscii", "bytes": [147] } }` puts keys in the keyboard queue of the KERNAL.
|
|
61
|
+
- `{ "press": { "keys": "{F1}" } }` presses keys of the keyboard matrix. Each character is one tap. A name in braces is a key without a character, for example `{STOP}` or `{RESTORE}`. `+` in braces holds keys together, for example `{LSHIFT+CBM}`. `frames` is 1 to 3000, and 3 by default.
|
|
61
62
|
- `{ "frames": 50 }` runs 1 to 30000 frames.
|
|
62
63
|
- `{ "runUntil": { "target": { "kind": "address", "address": "main_loop" }, "timeoutFrames": 300 } }` runs until the target. The target kinds are `address`, `memory` and `raster`. `timeoutFrames` is 1 to 30000. The default is 3000.
|
|
63
64
|
- `{ "capture": "level1" }` captures a part. Only `loads` takes this step. Give each capture step a different name of 1 to 64 letters, digits, dots, underscores or hyphens.
|
|
@@ -65,7 +66,7 @@ Each step has one of these kinds:
|
|
|
65
66
|
|
|
66
67
|
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.
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
A program that reads the keyboard matrix does not see the keys of a `type` step. Use a `press` step for that program. A wait for any key that reads all keyboard columns can end without a key.
|
|
69
70
|
|
|
70
71
|
The script refuses a step in an old form. The message gives the step to write.
|
|
71
72
|
|
|
@@ -10,7 +10,7 @@ import { type AddressRange, COVERAGE, formatC64Address } from "#src/c64.ts";
|
|
|
10
10
|
import { Refusal } from "#src/errors.ts";
|
|
11
11
|
import { autostartLoaded, LOAD_LIMIT_FRAMES, RUN_LIMIT_FRAMES, typeRun } from "#src/host-client/autostart.ts";
|
|
12
12
|
import { IO_RAM, markIoRamWrites, readCoverage } from "#src/host-client/coverage.ts";
|
|
13
|
-
import { ACTION_STEP_KINDS, checkActionStep, checkStepNames, isObject, runActionStep,
|
|
13
|
+
import { ACTION_STEP_KINDS, checkActionStep, checkStepNames, isObject, runActionStep, type ActionStep, type ActionStepKind } from "#src/host-client/steps.ts";
|
|
14
14
|
import { knowledgeAt } from "#src/knowledge/names.ts";
|
|
15
15
|
import { WireFailure } from "#src/host-client/tools.ts";
|
|
16
16
|
import { readProjectFile, writeReported, type Written } from "#src/host-client/transfer.ts";
|
|
@@ -64,7 +64,7 @@ export function readLoadSteps(path: string): LoadStep[] {
|
|
|
64
64
|
}
|
|
65
65
|
const kinds = Object.keys(step).filter((key) => (ACTION_STEP_KINDS as readonly string[]).includes(key));
|
|
66
66
|
if (kinds.length > 1) return fail(`${at} has ${kinds.length} step kinds: ${kinds.join(", ")}. Give each one its own step`);
|
|
67
|
-
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...
|
|
67
|
+
if (kinds.length !== 1) return fail(`${at} must have exactly one of ${[...ACTION_STEP_KINDS, "capture", "save"].join(", ")}`);
|
|
68
68
|
// The step with its defaults filled in, as the shared schema of the action steps gives it.
|
|
69
69
|
const checked = checkActionStep(kinds[0] as ActionStepKind, step, at, fail);
|
|
70
70
|
// Its names resolve now: an unknown name stops the call before the emulator starts.
|
package/skills/emulator/SKILL.md
CHANGED
|
@@ -43,7 +43,7 @@ Use only the MCP tools. Each MCP session has its own machine. Nothing else can c
|
|
|
43
43
|
| Chips of the machine | `c64_vicii`, `c64_sprite`, `c64_cia`, `c64_sid` |
|
|
44
44
|
| Screen image, screen compare | `c64_screen` |
|
|
45
45
|
| Several of these from one moment | `c64_observe` |
|
|
46
|
-
| Keyboard, joystick | `c64_keyboard`, `c64_joystick` |
|
|
46
|
+
| Keyboard, joystick | `c64_keyboard`, `c64_press`, `c64_joystick` |
|
|
47
47
|
| Program and disk media | `c64_autostart`, `c64_program_load`, `c64_disk_attach` |
|
|
48
48
|
| Machine state to go back to, also in a later session | `c64_snapshot` |
|
|
49
49
|
|
|
@@ -73,10 +73,7 @@ Before a risky experiment, save the state with `c64_snapshot`. Restore it to try
|
|
|
73
73
|
|
|
74
74
|
### Input that the tools cannot give
|
|
75
75
|
|
|
76
|
-
Some programs read input in a way that the input tools cannot give. The tool description tells when. Then
|
|
77
|
-
|
|
78
|
-
- Open the window and ask the user to give the input.
|
|
79
|
-
- Record a test session with a `press` step.
|
|
76
|
+
Some programs read input in a way that the input tools cannot give. The tool description tells when. Then open the window and ask the user to give the input.
|
|
80
77
|
|
|
81
78
|
Do not change the program to make it accept the input.
|
|
82
79
|
|
package/src/c64-keys.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// The keys of the C64 keyboard matrix and RESTORE. A key is its place in the
|
|
2
|
+
// matrix: row * 8 + column, where the row is the line of CIA 1 port A that
|
|
3
|
+
// the scan drives low and the column the bit of port B that reads low. The
|
|
4
|
+
// press of VICE and of the replay core, and the play page, use these numbers.
|
|
5
|
+
|
|
6
|
+
/** A press of keys that go down together and up together. `keys` are matrix places, without repeats, in rising order. */
|
|
7
|
+
export interface KeyTap {
|
|
8
|
+
keys: number[];
|
|
9
|
+
restore: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The keys that a tap holds at most, RESTORE included: the replay core has no more. */
|
|
13
|
+
export const MAX_TAP_KEYS = 4;
|
|
14
|
+
/** The taps of one press at most. */
|
|
15
|
+
export const MAX_PRESS_TAPS = 64;
|
|
16
|
+
/** The frames that a tap holds its keys, and then waits with all keys up, when the press gives no frames. */
|
|
17
|
+
export const PRESS_FRAMES = 3;
|
|
18
|
+
/** The frames of a tap at most: one minute of PAL frames. */
|
|
19
|
+
export const MAX_PRESS_FRAMES = 3000;
|
|
20
|
+
|
|
21
|
+
/** The matrix, row by row (port A line 0 to 7), column 0 to 7 in each row. A name has more than one character. */
|
|
22
|
+
const MATRIX = [
|
|
23
|
+
["DEL", "RETURN", "RIGHT", "F7", "F1", "F3", "F5", "DOWN"],
|
|
24
|
+
["3", "W", "A", "4", "Z", "S", "E", "LSHIFT"],
|
|
25
|
+
["5", "R", "D", "6", "C", "F", "T", "X"],
|
|
26
|
+
["7", "Y", "G", "8", "B", "H", "U", "V"],
|
|
27
|
+
["9", "I", "J", "0", "M", "K", "O", "N"],
|
|
28
|
+
["+", "P", "L", "-", ".", ":", "@", ","],
|
|
29
|
+
["POUND", "*", ";", "HOME", "RSHIFT", "=", "UPARROW", "/"],
|
|
30
|
+
["1", "LEFTARROW", "CTRL", "2", "SPACE", "CBM", "Q", "STOP"],
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/** The matrix place of each key. */
|
|
34
|
+
export const MATRIX_KEYS: Readonly<Record<string, number>> = Object.fromEntries(MATRIX.flatMap((row, line) => row.map((key, column) => [key, line * 8 + column])));
|
|
35
|
+
|
|
36
|
+
const LSHIFT = MATRIX_KEYS.LSHIFT!;
|
|
37
|
+
|
|
38
|
+
/** The names that press a key with the left SHIFT: the second function of the key. */
|
|
39
|
+
const SHIFTED_NAMES: Readonly<Record<string, string>> = { F2: "F1", F4: "F3", F6: "F5", F8: "F7", UP: "DOWN", LEFT: "RIGHT", INST: "DEL", CLR: "HOME", RUN: "STOP" };
|
|
40
|
+
/** The characters that a key gives with SHIFT. */
|
|
41
|
+
const SHIFTED_CHARACTERS: Readonly<Record<string, string>> = { "!": "1", '"': "2", "#": "3", $: "4", "%": "5", "&": "6", "'": "7", "(": "8", ")": "9", "[": ":", "]": ";", "<": ",", ">": ".", "?": "/" };
|
|
42
|
+
|
|
43
|
+
/** The names in braces, in the order that a refusal lists them. */
|
|
44
|
+
export const KEY_NAMES = [
|
|
45
|
+
...["F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8"],
|
|
46
|
+
...["RETURN", "SPACE", "DEL", "INST", "HOME", "CLR", "STOP", "RUN", "RESTORE", "CTRL", "CBM", "LSHIFT", "RSHIFT"],
|
|
47
|
+
...["UP", "DOWN", "LEFT", "RIGHT", "POUND", "UPARROW", "LEFTARROW"],
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/** The matrix places of one key: a name, or one character. Undefined when the C64 has no such key. RESTORE has no place: it gives []. */
|
|
51
|
+
function placesOf(key: string): number[] | undefined {
|
|
52
|
+
const upper = key.toUpperCase();
|
|
53
|
+
if (upper === "RESTORE") return [];
|
|
54
|
+
if (key === "\n") return [MATRIX_KEYS.RETURN!];
|
|
55
|
+
if (key === " ") return [MATRIX_KEYS.SPACE!];
|
|
56
|
+
const shifted = SHIFTED_NAMES[upper] ?? SHIFTED_CHARACTERS[key];
|
|
57
|
+
if (shifted !== undefined) return [LSHIFT, MATRIX_KEYS[shifted]!];
|
|
58
|
+
// A character is its own key; a name has more than one character.
|
|
59
|
+
const place = key.length === 1 || KEY_NAMES.includes(upper) ? MATRIX_KEYS[upper] : undefined;
|
|
60
|
+
return place === undefined ? undefined : [place];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The taps of a text, or why it has no taps. Each character is one tap, and
|
|
65
|
+
* a-z press the same keys as A-Z. A key without a character has its name in
|
|
66
|
+
* braces, for example {F1}. Names joined with + in braces are one tap that
|
|
67
|
+
* holds the keys together, for example {LSHIFT+CBM} or {STOP+RESTORE}.
|
|
68
|
+
*/
|
|
69
|
+
export function keyTaps(text: string): KeyTap[] | string {
|
|
70
|
+
const taps: KeyTap[] = [];
|
|
71
|
+
for (const part of text.replace(/\r\n?/g, "\n").match(/\{[^{}]*\}|[^]/g) ?? []) {
|
|
72
|
+
const keys = part.length > 1 ? part.slice(1, -1).split("+") : [part];
|
|
73
|
+
const places = new Set<number>();
|
|
74
|
+
let restore = false;
|
|
75
|
+
for (const key of keys) {
|
|
76
|
+
const found = key === "" ? undefined : placesOf(key);
|
|
77
|
+
if (found === undefined) {
|
|
78
|
+
if (part.length === 1) return `the C64 keyboard has no key ${JSON.stringify(part)}`;
|
|
79
|
+
return `there is no key ${key === "" ? part : `{${key}}`}. The keys in braces are ${KEY_NAMES.map((name) => `{${name}}`).join(", ")}, and each character key, for example {CTRL+3}. + joins the keys of one tap, for example {LSHIFT+CBM}`;
|
|
80
|
+
}
|
|
81
|
+
if (key.toUpperCase() === "RESTORE") restore = true;
|
|
82
|
+
for (const place of found) places.add(place);
|
|
83
|
+
}
|
|
84
|
+
const count = places.size + (restore ? 1 : 0);
|
|
85
|
+
if (count > MAX_TAP_KEYS) return `${part} holds ${count} keys, and one tap holds at most ${MAX_TAP_KEYS} keys, RESTORE included`;
|
|
86
|
+
taps.push({ keys: [...places].sort((a, b) => a - b), restore });
|
|
87
|
+
}
|
|
88
|
+
if (taps.length === 0) return "give at least one key";
|
|
89
|
+
if (taps.length > MAX_PRESS_TAPS) return `one press has at most ${MAX_PRESS_TAPS} taps. This text has ${taps.length}`;
|
|
90
|
+
return taps;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The 8 rows of the matrix with `keys` down: bit n of row r is the key at column n. */
|
|
94
|
+
export function matrixRows(keys: readonly number[]): number[] {
|
|
95
|
+
const rows = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
96
|
+
for (const key of keys) rows[key >> 3]! |= 1 << (key & 7);
|
|
97
|
+
return rows;
|
|
98
|
+
}
|
package/src/cli/main.ts
CHANGED
|
@@ -31,7 +31,7 @@ project folder below the root uses that install; a project is a folder with
|
|
|
31
31
|
through npx. The Host Runtime runs on the machine with VICE: start it there
|
|
32
32
|
with npx -y --package=${PACKAGE.name}@${PACKAGE.tag} c64-re-tools-host.
|
|
33
33
|
It runs VICE and the tools that come with it (c1541, petcat). The skill
|
|
34
|
-
scripts run ACME, DXA, Exomizer
|
|
34
|
+
scripts run ACME, DXA, Exomizer and c64run in the dev container.`;
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
/** Runs the AP SDK CLI. Writes its error output to stderr and returns its exit status and its report. */
|