@henols/c64-re-tools 2.6.0-rc.8 → 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.
Files changed (35) hide show
  1. package/package.json +2 -2
  2. package/skills/c64-docs/SKILL.md +1 -1
  3. package/skills/c64-docs/scripts/docs.ts +6 -6
  4. package/skills/c64-knowledge/SKILL.md +2 -2
  5. package/skills/c64-source/SKILL.md +2 -2
  6. package/skills/c64-source/scripts/lib/source.ts +10 -0
  7. package/skills/c64-source/scripts/source.ts +15 -12
  8. package/skills/c64-static-analysis/SKILL.md +4 -2
  9. package/skills/c64-static-analysis/scripts/static-analysis.ts +15 -8
  10. package/skills/c64-testing/SKILL.md +1 -1
  11. package/skills/c64-testing/references/recording-format.md +11 -5
  12. package/skills/c64-testing/references/scenario-format.md +2 -3
  13. package/skills/c64-testing/scripts/lib/diff-files.ts +4 -18
  14. package/skills/c64-testing/scripts/lib/play.ts +39 -37
  15. package/skills/c64-testing/scripts/lib/recording.ts +21 -38
  16. package/skills/c64-testing/scripts/lib/runs.ts +2 -2
  17. package/skills/c64-testing/scripts/lib/scenario.ts +3 -5
  18. package/skills/c64-unpacker/SKILL.md +2 -1
  19. package/skills/c64-unpacker/scripts/lib/loads.ts +2 -2
  20. package/skills/emulator/SKILL.md +2 -5
  21. package/src/c64-keys.ts +98 -0
  22. package/src/host/vice/session.ts +82 -8
  23. package/src/host-client/steps.ts +17 -17
  24. package/src/host-client/vice-session.ts +7 -1
  25. package/src/knowledge/read.ts +9 -0
  26. package/src/mcp/inputs.ts +12 -0
  27. package/src/mcp/server.ts +1 -0
  28. package/src/mcp/tools/input.ts +38 -5
  29. package/src/native/c64run.ts +1 -1
  30. package/src/native/discover.ts +3 -3
  31. package/src/native/processes.ts +3 -3
  32. package/src/protocol/vice.ts +47 -0
  33. package/src/vsf.ts +98 -0
  34. package/tools/c64run.c +9 -12
  35. package/skills/c64-testing/scripts/lib/keys.ts +0 -36
package/src/mcp/server.ts CHANGED
@@ -35,6 +35,7 @@ export type ViceSessionApi = Pick<
35
35
  | "diskAttach"
36
36
  | "keyboard"
37
37
  | "joystick"
38
+ | "press"
38
39
  | "screenCapture"
39
40
  | "screenCompare"
40
41
  | "screenBaselines"
@@ -1,11 +1,13 @@
1
- // Input tools: c64_keyboard and c64_joystick.
1
+ // Input tools: c64_keyboard, c64_press and c64_joystick.
2
2
 
3
3
  import { z } from "zod";
4
4
 
5
- import { JOYSTICK_DIRECTIONS, MAX_KEYBOARD_BYTES } from "../../protocol/vice.ts";
5
+ import { formatC64Address } from "../../c64.ts";
6
+ import { keyTaps, MAX_PRESS_TAPS, MAX_TAP_KEYS, PRESS_FRAMES, type KeyTap } from "../../c64-keys.ts";
7
+ import { JOYSTICK_DIRECTIONS, MAX_KEYBOARD_BYTES, POINT_STOP_REASONS, RUN_STATES, SPACES } from "../../protocol/vice.ts";
6
8
  import { keyboardBytes } from "../../host-client/steps.ts";
7
9
  import { TOOL_INPUTS } from "../inputs.ts";
8
- import { defineTool } from "../server.ts";
10
+ import { AddressOutput, defineTool } from "../server.ts";
9
11
 
10
12
 
11
13
  export const c64Keyboard = defineTool({
@@ -14,7 +16,7 @@ export const c64Keyboard = defineTool({
14
16
  description:
15
17
  `Type up to ${MAX_KEYBOARD_BYTES} keys into the C64 keyboard queue. The C64 reads them while it runs. ` +
16
18
  "Only a program that reads keys through the KERNAL sees them. A program that reads the keyboard hardware directly does not see them. Many games do that. " +
17
- "No tool presses one key of the keyboard matrix. For one specific key, ask the user to press it in the window, or play a record file with a press step. " +
19
+ "For keys that a program reads from the keyboard hardware, use c64_press. " +
18
20
  'Mode text types text, for example "RUN\\n". Letters of either case type the normal (unshifted) key. A line break types RETURN. ' +
19
21
  "Mode petscii types PETSCII codes 1 to 255 in bytes, for example [147] to clear the screen. " +
20
22
  "While c64_autostart loads a program, this tool refuses keys: see c64_autostart. " +
@@ -29,6 +31,37 @@ export const c64Keyboard = defineTool({
29
31
  },
30
32
  });
31
33
 
34
+ export const c64Press = defineTool({
35
+ name: "c64_press",
36
+ title: "Press keys of the C64 keyboard",
37
+ description:
38
+ "Press keys of the C64 keyboard matrix, and RESTORE. A program that reads the keyboard hardware directly sees these keys. Many games do that. " +
39
+ "Each character of keys is one tap: the key goes down, then up. Letters of either case press the same key. A line break presses RETURN. " +
40
+ "A key without a character has its name in braces: {F1} to {F8}, {RETURN}, {SPACE}, {DEL}, {INST}, {HOME}, {CLR}, {STOP}, {RUN} and {RESTORE}. " +
41
+ "The other names are {CTRL}, {CBM}, {LSHIFT}, {RSHIFT}, {UP}, {DOWN}, {LEFT}, {RIGHT}, {POUND}, {UPARROW} and {LEFTARROW}. " +
42
+ "{F2}, {RUN}, {CLR}, {INST}, {UP} and {LEFT} also press the left SHIFT. " +
43
+ `Join keys with + in braces to hold them together in one tap, for example {LSHIFT+CBM}, {CTRL+3} or {STOP+RESTORE}. One tap holds at most ${MAX_TAP_KEYS} keys, RESTORE included. One call has at most ${MAX_PRESS_TAPS} taps. ` +
44
+ `Each tap holds its keys for frames frames (default ${PRESS_FRAMES}). Then all keys are up for frames frames. The machine runs during the taps, and it runs again after them when it ran before. ` +
45
+ "A breakpoint, watchpoint or JAM stops the taps early. Then stopReason tells why, taps tells how many taps were complete, and the machine stays stopped. All keys are up at the end. " +
46
+ "The CPU history starts again at each tap. " +
47
+ "To type text through the KERNAL keyboard queue, use c64_keyboard.",
48
+ inputSchema: TOOL_INPUTS.press,
49
+ outputSchema: z.object({
50
+ taps: z.number().int().min(0).max(MAX_PRESS_TAPS).describe("the taps that were complete"),
51
+ state: z.enum(RUN_STATES),
52
+ stopReason: z.enum(POINT_STOP_REASONS).optional().describe("why the taps stopped early"),
53
+ pc: AddressOutput.optional(),
54
+ pointId: z.number().int().min(1).optional().describe("the id of the breakpoint or watchpoint that stopped the taps"),
55
+ space: z.enum(SPACES).optional().describe("the CPU that stopped, c64 or drive8. pc is the address in that space"),
56
+ }),
57
+ readOnly: false,
58
+ async run(input, session) {
59
+ // The schema checked the keys: keyTaps gives taps here.
60
+ const { pc, ...result } = await session.press(keyTaps(input.keys) as KeyTap[], input.frames);
61
+ return { ...result, ...(pc === undefined ? {} : { pc: formatC64Address(pc) }) };
62
+ },
63
+ });
64
+
32
65
  export const c64Joystick = defineTool({
33
66
  name: "c64_joystick",
34
67
  title: "Move a joystick",
@@ -44,4 +77,4 @@ export const c64Joystick = defineTool({
44
77
  },
45
78
  });
46
79
 
47
- export const inputTools = [c64Keyboard, c64Joystick];
80
+ export const inputTools = [c64Keyboard, c64Press, c64Joystick];
@@ -12,7 +12,7 @@ import type { SupervisedProcess } from "./processes.ts";
12
12
  import type { ToolContext } from "./run.ts";
13
13
 
14
14
  /** The command protocol that this module speaks; c64run --version and version name it. */
15
- export const C64RUN_PROTOCOL = 3;
15
+ export const C64RUN_PROTOCOL = 4;
16
16
 
17
17
  /** CPU cycles in one PAL frame: 312 lines of 63 cycles. */
18
18
  export const PAL_FRAME_CYCLES = 19_656;
@@ -99,8 +99,8 @@ export function viceVersionOf(text: string): ViceVersion | undefined {
99
99
  return { major: Number(match[1]), minor: Number(match[2]), ...(match[3] === undefined ? {} : { revision: Number(match[3]) }) };
100
100
  }
101
101
 
102
- /** What a VICE flaw stops from working: joystick input, or the load of a tape image. */
103
- export type ViceFeature = "joystick" | "tape";
102
+ /** What a VICE flaw stops from working: joystick input, the load of a tape image, or keys of the keyboard matrix. */
103
+ export type ViceFeature = "joystick" | "tape" | "keyboard";
104
104
 
105
105
  /** A known VICE flaw: the text for the person at the host, and what it stops from working. */
106
106
  export interface ViceFlaw {
@@ -120,7 +120,7 @@ const VICE_FLAWS = [
120
120
  {
121
121
  upTo: { major: 3, minor: 10 },
122
122
  fixedRevision: 45971,
123
- breaks: ["joystick", "tape"],
123
+ breaks: ["joystick", "tape", "keyboard"],
124
124
  text:
125
125
  "VICE 3.10 and older hold bits 5-7 of CIA 1 ports A and B low with the joystick device that c64-re-tools uses (VICE bug #2202). " +
126
126
  "$DC00 and $DC01 read $1F with no input. A program that waits for one key of the keyboard matrix (for example LDA $DC01 / CMP #$EF for SPACE) waits forever. " +
@@ -350,7 +350,7 @@ export class ProcessSupervisor {
350
350
  } catch {
351
351
  // The leader has ended already.
352
352
  }
353
- await Promise.race([exited, sleep(this.#graceMs)]);
353
+ await Promise.race([exited, sleep(this.#graceMs, undefined, { ref: false })]);
354
354
  if (!hasExited(child)) throw new Refusal("operation-failed", `process ${pid} did not end${failure === undefined ? "" : `: ${failure}`}`);
355
355
  return;
356
356
  }
@@ -362,7 +362,7 @@ export class ProcessSupervisor {
362
362
  }
363
363
  }
364
364
  // A group of zombies counts as gone before Node reaps the leader and reports its exit;
365
- // stopped means that Node has seen that exit.
366
- await Promise.race([exited, sleep(KILL_WAIT_MS)]);
365
+ // stopped means that Node has seen that exit. The limit does not keep this process running.
366
+ await Promise.race([exited, sleep(KILL_WAIT_MS, undefined, { ref: false })]);
367
367
  }
368
368
  }
@@ -1,5 +1,6 @@
1
1
  // The VICE-session operations of the Host Runtime wire: their vocabulary, shapes and validators.
2
2
 
3
+ import { MAX_PRESS_FRAMES, MAX_PRESS_TAPS, MAX_TAP_KEYS, type KeyTap } from "../c64-keys.ts";
3
4
  import { invalid, isInteger, isObject, isOneOf, onlyFields, ProtocolError, VIDEO_STANDARDS, type VideoStandard } from "./messages.ts";
4
5
 
5
6
  export const SPACES = ["c64", "drive8"] as const;
@@ -475,6 +476,20 @@ export interface ExecutionResult {
475
476
  space?: "c64" | "drive8";
476
477
  }
477
478
 
479
+ /**
480
+ * The end of a press: `taps` taps were done. A breakpoint, watchpoint or JAM
481
+ * can stop the taps early; then `stopReason` tells which, and the machine
482
+ * stays stopped. All keys are up again in both cases.
483
+ */
484
+ export interface PressResult {
485
+ taps: number;
486
+ state: RunState;
487
+ stopReason?: PointStopReason;
488
+ pc?: number;
489
+ pointId?: number;
490
+ space?: "c64" | "drive8";
491
+ }
492
+
478
493
  /** c64_run_until targets. */
479
494
  export type RunTarget =
480
495
  | { kind: "address"; address: number; space: Space; condition?: Condition }
@@ -528,6 +543,8 @@ export interface ViceOperations {
528
543
  /** `data`: PETSCII bytes as lowercase hex. */
529
544
  keyboard: { params: { data: string }; result: { queuedBytes: number } };
530
545
  joystick: { params: JoystickState; result: JoystickState };
546
+ /** Each tap holds its keys for `frames` frames, then waits `frames` frames with all keys up. */
547
+ press: { params: { taps: KeyTap[]; frames: number }; result: PressResult };
531
548
  breakpoint: { params: BreakpointParams; result: Breakpoint | PointRemoved | { breakpoints: Breakpoint[] } };
532
549
  watchpoint: { params: WatchpointParams; result: Watchpoint | PointRemoved | { watchpoints: Watchpoint[] } };
533
550
  cpuHistory: { params: { limit: number; space: Space }; result: { entries: HistoryEntry[] } };
@@ -589,6 +606,7 @@ export const VICE_OPERATIONS = [
589
606
  "reset",
590
607
  "keyboard",
591
608
  "joystick",
609
+ "press",
592
610
  "breakpoint",
593
611
  "watchpoint",
594
612
  "screenCapture",
@@ -915,6 +933,24 @@ export function validateViceParams<O extends ViceOperation>(op: O, params: unkno
915
933
  if (/^(?:..)*?00/.test(params.data)) invalid("PETSCII byte 0 cannot be typed");
916
934
  return { data: params.data } as ViceOperations[O]["params"];
917
935
  }
936
+ case "press": {
937
+ onlyFields(params, ["taps", "frames"]);
938
+ if (!Array.isArray(params.taps) || params.taps.length === 0 || params.taps.length > MAX_PRESS_TAPS) invalid(`taps must be a list of 1 to ${MAX_PRESS_TAPS} taps`);
939
+ const taps = (params.taps as unknown[]).map((tap): KeyTap => {
940
+ if (!isObject(tap)) invalid("each tap must be an object with keys and restore");
941
+ onlyFields(tap, ["keys", "restore"], "a tap");
942
+ const { keys, restore } = tap;
943
+ if (!Array.isArray(keys) || !keys.every((key, index) => isInteger(key, 0, 63) && (index === 0 || key > (keys[index - 1] as number)))) {
944
+ invalid("keys of a tap must be matrix places from 0 to 63, each once, in rising order");
945
+ }
946
+ if (typeof restore !== "boolean") invalid("restore of a tap must be true or false");
947
+ const count = keys.length + (restore ? 1 : 0);
948
+ if (count === 0 || count > MAX_TAP_KEYS) invalid(`a tap holds 1 to ${MAX_TAP_KEYS} keys, RESTORE included`);
949
+ return { keys: keys as number[], restore };
950
+ });
951
+ if (!isInteger(params.frames, 1, MAX_PRESS_FRAMES)) invalid(`frames must be a whole number from 1 to ${MAX_PRESS_FRAMES}`);
952
+ return { taps, frames: params.frames } as ViceOperations[O]["params"];
953
+ }
918
954
  case "joystick": {
919
955
  onlyFields(params, ["port", "direction", "fire"]);
920
956
  if (params.port !== 1 && params.port !== 2) invalid("port must be 1 or 2");
@@ -1206,6 +1242,17 @@ export function validateViceResult<O extends ViceOperation>(op: O, value: unknow
1206
1242
  if (!isInteger(value.queuedBytes, 1, MAX_KEYBOARD_BYTES)) throw new ProtocolError("keyboard result is malformed");
1207
1243
  break;
1208
1244
  }
1245
+ case "press": {
1246
+ const ok =
1247
+ isInteger(value.taps, 0, MAX_PRESS_TAPS) &&
1248
+ isOneOf(RUN_STATES, value.state) &&
1249
+ (value.stopReason === undefined || isOneOf(POINT_STOP_REASONS, value.stopReason)) &&
1250
+ (value.pc === undefined || isInteger(value.pc, 0, 0xffff)) &&
1251
+ (value.pointId === undefined || isInteger(value.pointId, 1, Number.MAX_SAFE_INTEGER)) &&
1252
+ (value.space === undefined || isOneOf(SPACES, value.space));
1253
+ if (!ok) throw new ProtocolError("press result is malformed");
1254
+ break;
1255
+ }
1209
1256
  case "breakpoint": {
1210
1257
  const ok = Array.isArray(value.breakpoints) ? value.breakpoints.every(isBreakpoint) : isRemoved(value) || isBreakpoint(value);
1211
1258
  if (!ok) throw new ProtocolError("breakpoint result is malformed");
package/src/vsf.ts ADDED
@@ -0,0 +1,98 @@
1
+ // The modules of a VICE snapshot file (.vsf), and the two changes that press
2
+ // keys in it: the keyboard matrix and a RESTORE. VICE saves a module as its
3
+ // name (16 bytes), its version (major, minor), its size with this header
4
+ // (4 bytes) and its data; every number is little-endian.
5
+
6
+ import { hasSignature, VSF_SIGNATURE } from "./media.ts";
7
+
8
+ /** The size of the header of a module: the name (16 bytes), the version (2 bytes) and the size (4 bytes). */
9
+ const MODULE_HEADER = 22;
10
+ const VSF_VERSION = "VICE Version\x1a";
11
+
12
+ export interface SnapshotModule {
13
+ major: number;
14
+ minor: number;
15
+ /** The data of the module: a view into the file, so a change to it changes the file. */
16
+ data: Buffer;
17
+ }
18
+
19
+ /** The module `name` of a snapshot file. Undefined when the file is no snapshot or has no such module. */
20
+ export function snapshotModule(file: Buffer, name: string): SnapshotModule | undefined {
21
+ if (!hasSignature("vsf", file)) return undefined;
22
+ // The magic, the version (2 bytes) and the machine name (16 bytes); a newer VICE adds its own version (8 bytes).
23
+ let at = VSF_SIGNATURE.length + 2 + 16;
24
+ if (file.subarray(at, at + VSF_VERSION.length).toString("latin1") === VSF_VERSION) at += VSF_VERSION.length + 8;
25
+ while (at + MODULE_HEADER <= file.length) {
26
+ const size = file.readUInt32LE(at + 18);
27
+ if (size < MODULE_HEADER || at + size > file.length) return undefined;
28
+ if (file.subarray(at, at + 16).toString("latin1").replace(/\0+$/, "") === name) {
29
+ return { major: file[at + 16]!, minor: file[at + 17]!, data: file.subarray(at + MODULE_HEADER, at + size) };
30
+ }
31
+ at += size;
32
+ }
33
+ return undefined;
34
+ }
35
+
36
+ /** VICE's keyboard module: keyarr (16 rows) and rev_keyarr (8 columns), each a DWORD. */
37
+ const KEYBOARD = { name: "KEYBOARD", major: 1, minor: 1, size: (16 + 8) * 4 };
38
+
39
+ /**
40
+ * The CPU module of x64sc. VICE r46088 renamed MAINCPU 1.4 to MAINC64CPU 1.5;
41
+ * the data is the same: the clock (8 bytes), A, X, Y, SP, PC (2), P, five
42
+ * DWORDs, five clocks (irq_clk, nmi_clk, ...), then nirq, nnmi and
43
+ * global_pending_int, then two clocks.
44
+ */
45
+ const CPU = [
46
+ { name: "MAINC64CPU", major: 1, minor: 5 },
47
+ { name: "MAINCPU", major: 1, minor: 4 },
48
+ ];
49
+ const CPU_SIZE = 103;
50
+ const NMI_CLK = 43;
51
+ const NNMI = 79;
52
+ const PENDING = 83;
53
+ /** IK_NMI of global_pending_int. */
54
+ const PENDING_NMI = 1;
55
+
56
+ /** A module of a version that the patch knows, or why there is none. */
57
+ function known(file: Buffer, versions: Array<{ name: string; major: number; minor: number }>, size: number): Buffer | string {
58
+ for (const version of versions) {
59
+ const module = snapshotModule(file, version.name);
60
+ if (module === undefined) continue;
61
+ if (module.major !== version.major || module.minor !== version.minor || module.data.length < size) {
62
+ return `the snapshot has ${version.name} ${module.major}.${module.minor} with ${module.data.length} bytes, and c64-re-tools knows ${version.major}.${version.minor} with ${size}`;
63
+ }
64
+ return module.data;
65
+ }
66
+ return `the snapshot has no module ${versions.map((version) => version.name).join(" or ")}`;
67
+ }
68
+
69
+ /**
70
+ * Sets the keyboard matrix of a snapshot file: bit n of rows[r] is the key at
71
+ * row r, column n. Gives why it cannot, for a snapshot of another layout.
72
+ */
73
+ export function setSnapshotMatrix(file: Buffer, rows: readonly number[]): string | undefined {
74
+ const data = known(file, [KEYBOARD], KEYBOARD.size);
75
+ if (typeof data === "string") return data;
76
+ for (let row = 0; row < 16; row++) data.writeUInt32LE(rows[row] ?? 0, row * 4);
77
+ for (let column = 0; column < 8; column++) {
78
+ let lines = 0;
79
+ for (let row = 0; row < 8; row++) if (((rows[row] ?? 0) >> column) & 1) lines |= 1 << row;
80
+ data.writeUInt32LE(lines, 64 + column * 4);
81
+ }
82
+ return undefined;
83
+ }
84
+
85
+ /**
86
+ * Presses RESTORE in a snapshot file, as VICE does: an NMI from now on, unless
87
+ * another source holds the NMI line or an NMI is pending already, which gives
88
+ * no new edge. Gives why it cannot, for a snapshot of another layout.
89
+ */
90
+ export function pressSnapshotRestore(file: Buffer): string | undefined {
91
+ const data = known(file, CPU, CPU_SIZE);
92
+ if (typeof data === "string") return data;
93
+ const pending = data.readUInt32LE(PENDING);
94
+ if (data.readUInt32LE(NNMI) !== 0 || (pending & PENDING_NMI) !== 0) return undefined;
95
+ data.writeUInt32LE(pending | PENDING_NMI, PENDING);
96
+ data.writeBigUInt64LE(data.readBigUInt64LE(0), NMI_CLK);
97
+ return undefined;
98
+ }
package/tools/c64run.c CHANGED
@@ -27,11 +27,9 @@
27
27
  #include "systems/c1541.h"
28
28
  #include "systems/c64.h"
29
29
 
30
- #define C64RUN_PROTOCOL 3
31
- // Keys that chips has no code for: each SHIFT alone, and the up arrow.
32
- #define C64RUN_KEY_LSHIFT 0x11
33
- #define C64RUN_KEY_RSHIFT 0x12
34
- #define C64RUN_KEY_UPARROW 0x5E
30
+ #define C64RUN_PROTOCOL 4
31
+ // The key code of matrix place 0 (row 0, column 0); place n has code 0x80 + n.
32
+ #define C64RUN_KEY_PLACE 0x80
35
33
  #ifndef CHIPS_COMMIT
36
34
  #define CHIPS_COMMIT "unknown"
37
35
  #endif
@@ -335,10 +333,9 @@ static const char* init(const char* romdir) {
335
333
  .chars = { .ptr = rom[2], .size = 0x1000 },
336
334
  },
337
335
  });
338
- // The matrix positions (column, line) of the keys that chips has no code for.
339
- kbd_register_key(&sys.kbd, C64RUN_KEY_LSHIFT, 7, 1, 0);
340
- kbd_register_key(&sys.kbd, C64RUN_KEY_RSHIFT, 4, 6, 0);
341
- kbd_register_key(&sys.kbd, C64RUN_KEY_UPARROW, 6, 6, 0);
336
+ // One code for each place of the matrix: place row * 8 + column, where the row is the
337
+ // line of CIA 1 port A and the column the bit of port B (chips: column, line).
338
+ for (int place = 0; place < 64; place++) kbd_register_key(&sys.kbd, C64RUN_KEY_PLACE + place, place & 7, place >> 3, 0);
342
339
  const uint16_t vector = rom[0][0x1FFC] | (rom[0][0x1FFD] << 8);
343
340
  for (int i = 0; i < 3; i++) free(rom[i]);
344
341
  pins = sys.pins;
@@ -536,11 +533,11 @@ int main(int argc, char** argv) {
536
533
  c64_joystick(&sys, (uint8_t)j1, (uint8_t)j2);
537
534
  printf("ok\n");
538
535
  } else if (!strcmp(cmd, "key")) {
539
- // key <code hex> down|up: a key of the keyboard matrix; the code is ASCII as
540
- // chips maps it (A-Z, 0-9, space 20, return 0d, ...); shifted keys press SHIFT.
541
- // 11 and 12 are the left and right SHIFT alone, 5e the up arrow, ff RESTORE (NMI).
536
+ // key <code hex> down|up: 80 + place is the key at matrix place row * 8 + column
537
+ // (80-bf), ff is RESTORE (NMI). chips holds at most 4 keys at once.
542
538
  unsigned code;
543
539
  if (sscanf(a1, "%x", &code) != 1 || (strcmp(a2, "down") && strcmp(a2, "up"))) { printf("err key: give a code and down or up\n"); continue; }
540
+ if ((code < C64RUN_KEY_PLACE || code >= C64RUN_KEY_PLACE + 64) && code != C64_KEY_RESTORE) { printf("err key: give 80-bf (a matrix place) or ff (RESTORE)\n"); continue; }
544
541
  if (!strcmp(a2, "down")) c64_key_down(&sys, (int)code);
545
542
  else {
546
543
  // chips releases a key in kbd_update, after its sticky time: one call
@@ -1,36 +0,0 @@
1
- // The keys of the keyboard matrix that the replay core presses: the key codes
2
- // of chips c64.h, and 11, 12 and 5e of c64run. The play page and the press
3
- // step of a record file use the same codes.
4
-
5
- /** The key codes of the keys that have no character of their own. */
6
- export const C64_KEYS = {
7
- del: 0x01, clr: 0x02, stop: 0x03, leftArrow: 0x04, run: 0x07, csrLeft: 0x08, csrRight: 0x09, csrDown: 0x0a, csrUp: 0x0b,
8
- home: 0x0c, return: 0x0d, ctrl: 0x0e, cbm: 0x0f, inst: 0x10, leftShift: 0x11, rightShift: 0x12, space: 0x20, upArrow: 0x5e, pound: 0x7e,
9
- } as const;
10
-
11
- /** F1 to F8: F2, F4, F6 and F8 press SHIFT with the key. */
12
- export const F_KEYS = [0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8];
13
-
14
- /** The keys that a press step names in braces, for example {F1}. */
15
- export const NAMED_KEYS: Readonly<Record<string, number>> = {
16
- ...Object.fromEntries(F_KEYS.map((key, index) => [`F${index + 1}`, key])),
17
- RETURN: C64_KEYS.return,
18
- SPACE: C64_KEYS.space,
19
- DEL: C64_KEYS.del,
20
- INST: C64_KEYS.inst,
21
- HOME: C64_KEYS.home,
22
- CLR: C64_KEYS.clr,
23
- STOP: C64_KEYS.stop,
24
- RUN: C64_KEYS.run,
25
- CTRL: C64_KEYS.ctrl,
26
- CBM: C64_KEYS.cbm,
27
- LSHIFT: C64_KEYS.leftShift,
28
- RSHIFT: C64_KEYS.rightShift,
29
- UP: C64_KEYS.csrUp,
30
- DOWN: C64_KEYS.csrDown,
31
- LEFT: C64_KEYS.csrLeft,
32
- RIGHT: C64_KEYS.csrRight,
33
- POUND: C64_KEYS.pound,
34
- UPARROW: C64_KEYS.upArrow,
35
- LEFTARROW: C64_KEYS.leftArrow,
36
- };