c64-ready 2.5.0 → 3.2.0

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 (105) hide show
  1. package/README.md +52 -1
  2. package/bin/admin.mjs +7 -1
  3. package/bin/agent.mjs +18 -0
  4. package/bin/headless.mjs +1 -1
  5. package/dist/assets/BeachHead-CuSwFD4k.js +1 -0
  6. package/dist/assets/ChuckieEgg-CPqBnAOF.js +1 -0
  7. package/dist/assets/ForbiddenForest-DsQ9jsc8.js +1 -0
  8. package/dist/assets/Galaga-Cutc3p9s.js +1 -0
  9. package/dist/assets/Gribbly-DdZ_hHFt.js +1 -0
  10. package/dist/assets/Hercules-vZYKm7GG.js +1 -0
  11. package/dist/assets/LegendOfWilf-CxSMOjsj.js +1 -0
  12. package/dist/assets/MariosCementFactory-z0IZ0q30.js +1 -0
  13. package/dist/assets/MoleAttack-buC6ChYy.js +1 -0
  14. package/dist/assets/MunchyWorm-D2Zv7i0Q.js +1 -0
  15. package/dist/assets/ParkPatrol-CVj7hyoB.js +1 -0
  16. package/dist/assets/PottyPigeon-0SYpIUBa.js +1 -0
  17. package/dist/assets/RainbowIslands-BjfmJB8z.js +1 -0
  18. package/dist/assets/Stix-BU-qUCeC.js +1 -0
  19. package/dist/assets/Tilt-C5KtKisF.js +1 -0
  20. package/dist/assets/UpNDown-CATRO7Mz.js +1 -0
  21. package/dist/assets/Uridium-DanS2KoH.js +1 -0
  22. package/dist/assets/VegetablesDeluxe-C41ViimS.js +1 -0
  23. package/dist/assets/index-B8DSjPqI.js +243 -0
  24. package/dist/assets/src-DX0rJQsE.js +1 -0
  25. package/dist/assets/src-_trgwTvp.js +2 -0
  26. package/dist/assets/string-utils-CMVABfx0.js +1 -0
  27. package/dist/index.html +1 -1
  28. package/dist-ts/emulator/c64-emulator.d.ts +2 -2
  29. package/dist-ts/emulator/c64-emulator.js +2 -2
  30. package/dist-ts/emulator/c64-keys.d.ts +69 -0
  31. package/dist-ts/emulator/c64-keys.d.ts.map +1 -0
  32. package/dist-ts/emulator/c64-keys.js +69 -0
  33. package/dist-ts/emulator/c64-keys.js.map +1 -0
  34. package/dist-ts/emulator/c64-wasm.d.ts +1 -1
  35. package/dist-ts/emulator/gamepad-mapping.d.ts +64 -0
  36. package/dist-ts/emulator/gamepad-mapping.d.ts.map +1 -0
  37. package/dist-ts/emulator/gamepad-mapping.js +154 -0
  38. package/dist-ts/emulator/gamepad-mapping.js.map +1 -0
  39. package/dist-ts/emulator/input.d.ts +27 -78
  40. package/dist-ts/emulator/input.d.ts.map +1 -1
  41. package/dist-ts/emulator/input.js +94 -215
  42. package/dist-ts/emulator/input.js.map +1 -1
  43. package/dist-ts/headless/audio-capture.d.ts +1 -1
  44. package/dist-ts/headless/c64-headless.d.ts +2 -2
  45. package/dist-ts/headless/c64-headless.js +4 -4
  46. package/dist-ts/headless/frame-capture.d.ts +1 -1
  47. package/dist-ts/headless/input-bridge.d.ts +1 -1
  48. package/dist-ts/player/c64-player.d.ts +21 -5
  49. package/dist-ts/player/c64-player.d.ts.map +1 -1
  50. package/dist-ts/player/c64-player.js +32 -5
  51. package/dist-ts/player/c64-player.js.map +1 -1
  52. package/dist-ts/player/canvas-renderer.d.ts +2 -2
  53. package/dist-ts/player/cheevos-dev.d.ts +65 -0
  54. package/dist-ts/player/cheevos-dev.d.ts.map +1 -0
  55. package/dist-ts/player/cheevos-dev.js +237 -0
  56. package/dist-ts/player/cheevos-dev.js.map +1 -0
  57. package/dist-ts/player/cheevos-tracker-panel.d.ts +21 -0
  58. package/dist-ts/player/cheevos-tracker-panel.d.ts.map +1 -0
  59. package/dist-ts/player/cheevos-tracker-panel.js +242 -0
  60. package/dist-ts/player/cheevos-tracker-panel.js.map +1 -0
  61. package/dist-ts/player/index.d.ts +10 -7
  62. package/dist-ts/player/index.d.ts.map +1 -1
  63. package/dist-ts/player/index.js +6 -4
  64. package/dist-ts/player/index.js.map +1 -1
  65. package/dist-ts/player/input-handler.d.ts +7 -3
  66. package/dist-ts/player/input-handler.d.ts.map +1 -1
  67. package/dist-ts/player/input-handler.js +24 -1
  68. package/dist-ts/player/input-handler.js.map +1 -1
  69. package/dist-ts/player/load-formats.d.ts +1 -1
  70. package/dist-ts/player/local-rom-store.d.ts +23 -0
  71. package/dist-ts/player/local-rom-store.d.ts.map +1 -0
  72. package/dist-ts/player/local-rom-store.js +87 -0
  73. package/dist-ts/player/local-rom-store.js.map +1 -0
  74. package/dist-ts/player/startup-params.d.ts +7 -0
  75. package/dist-ts/player/startup-params.d.ts.map +1 -0
  76. package/dist-ts/player/startup-params.js +47 -0
  77. package/dist-ts/player/startup-params.js.map +1 -0
  78. package/dist-ts/player/ui-controller.d.ts +23 -1
  79. package/dist-ts/player/ui-controller.d.ts.map +1 -1
  80. package/dist-ts/player/ui-controller.js +665 -1
  81. package/dist-ts/player/ui-controller.js.map +1 -1
  82. package/package.json +11 -4
  83. package/src/emulator/c64-keys.ts +68 -0
  84. package/src/emulator/gamepad-mapping.ts +212 -0
  85. package/src/emulator/input.ts +106 -209
  86. package/src/headless/agent-cli.mjs +825 -0
  87. package/src/headless/headless-cli.mjs +10 -4
  88. package/src/headless/input-server.mjs +92 -17
  89. package/src/headless/png.mjs +72 -0
  90. package/src/headless/webrtc-server.mjs +458 -34
  91. package/src/main.ts +197 -12
  92. package/src/player/c64-player.ts +58 -1
  93. package/src/player/cheevos-dev.ts +340 -0
  94. package/src/player/cheevos-tracker-panel.ts +309 -0
  95. package/src/player/index.ts +19 -0
  96. package/src/player/input-handler.ts +32 -0
  97. package/src/player/local-rom-store.ts +126 -0
  98. package/src/player/startup-params.ts +40 -0
  99. package/src/player/ui-controller.ts +751 -0
  100. package/src/player/ultimate-bridge.ts +161 -0
  101. package/src/player/ultimate-panel.ts +315 -0
  102. package/src/types/c64-cheevos.d.ts +6 -0
  103. package/dist/assets/index-BAsZcXuS.js +0 -178
  104. /package/dist/assets/{marked.esm--kBm026b.js → marked.esm-fTuuvbcB.js} +0 -0
  105. /package/dist/assets/{purify.es-BcoGFDcJ.js → purify.es-CRM-GE0Y.js} +0 -0
@@ -8,6 +8,20 @@ import {
8
8
  type JoystickInput,
9
9
  } from './constants';
10
10
  import type { JoystickPort } from './constants';
11
+ import { C64_KEY } from './c64-keys';
12
+ import {
13
+ GAMEPAD_BUTTONS,
14
+ GAMEPAD_DIRECTIONS,
15
+ outputId,
16
+ readGamepadState,
17
+ resolveGamepadMapping,
18
+ resolveOutputs,
19
+ restrictDirections,
20
+ type GamepadMapping,
21
+ type GamepadOutput,
22
+ type GamepadState,
23
+ type ResolvedGamepadMapping,
24
+ } from './gamepad-mapping';
11
25
 
12
26
  export const KEY_TO_JOYSTICK = {
13
27
  ArrowUp: JOYSTICK_DIRECTION.UP,
@@ -64,74 +78,7 @@ const DEFAULT_MIXED_EXTRA_JOYSTICK_KEYS: KeyboardJoystickMap = {
64
78
  // typed characters to the C64 keyboard matrix.
65
79
  // ---------------------------------------------------------------------------
66
80
 
67
- /** C64 keyboard matrix indices */
68
- export const C64_KEY = {
69
- ARROW_LEFT: 0,
70
- ONE: 1,
71
- TWO: 2,
72
- THREE: 3,
73
- FOUR: 4,
74
- FIVE: 5,
75
- SIX: 6,
76
- SEVEN: 7,
77
- EIGHT: 8,
78
- NINE: 9,
79
- ZERO: 10,
80
- PLUS: 11,
81
- MINUS: 12,
82
- POUND: 13,
83
- CLEAR_HOME: 14,
84
- INS_DEL: 15,
85
- CTRL: 16,
86
- Q: 17,
87
- W: 18,
88
- E: 19,
89
- R: 20,
90
- T: 21,
91
- Y: 22,
92
- U: 23,
93
- I: 24,
94
- O: 25,
95
- P: 26,
96
- AT: 27,
97
- STAR: 28,
98
- ARROW_UP: 29,
99
- RUN_STOP: 30,
100
- A: 31,
101
- S: 32,
102
- D: 33,
103
- F: 34,
104
- G: 35,
105
- H: 36,
106
- J: 37,
107
- K: 38,
108
- L: 39,
109
- COLON: 40,
110
- SEMICOLON: 41,
111
- EQUALS: 42,
112
- RETURN: 43,
113
- COMMODORE: 44,
114
- SHIFT_LEFT: 45,
115
- Z: 46,
116
- X: 47,
117
- C: 48,
118
- V: 49,
119
- B: 50,
120
- N: 51,
121
- M: 52,
122
- COMMA: 53,
123
- PERIOD: 54,
124
- SLASH: 55,
125
- SHIFT_RIGHT: 56,
126
- CURSOR_UP_DOWN: 57,
127
- CURSOR_LEFT_RIGHT: 58,
128
- SPACE: 59,
129
- F1: 60,
130
- F3: 61,
131
- F5: 62,
132
- F7: 63,
133
- RESTORE: 64,
134
- } as const;
81
+ export { C64_KEY } from './c64-keys';
135
82
 
136
83
  type C64KeyAction = { key: number; action: 'press' | 'release' };
137
84
 
@@ -506,27 +453,14 @@ export class EmulatorInput {
506
453
  private inputMode: InputMode = 'mixed';
507
454
  private updateFrame: number = -1;
508
455
  private gamepadIndex: number = -1;
509
- private gamepadPresses: Array<boolean> = [];
510
- /**
511
- * Ultimate 8bitdo axes:
512
- * [LeftX, LeftX, LeftUp, LeftDown, L2, RightX, RightX, RightUp, RightDown, R2, DpadX, DpadX, DpadY, DpadY]
513
- **/
514
- private gamepadAxes: Array<boolean> = [
515
- false,
516
- false,
517
- false,
518
- false,
519
- false,
520
- false,
521
- false,
522
- false,
523
- false,
524
- false,
525
- false,
526
- false,
527
- false,
528
- false,
529
- ];
456
+ private gamepadMapping: ResolvedGamepadMapping = resolveGamepadMapping();
457
+ // Controls held on the physical gamepad (plus Start) and on a virtual one, e.g. on-screen touch controls
458
+ private physicalGamepadState: GamepadState & { start?: boolean } = {};
459
+ private virtualGamepadState: GamepadState = {};
460
+ // Directions after the stick mode was applied, so 4-way can keep the one already held
461
+ private heldGamepadDirections: GamepadState = {};
462
+ // Emulator inputs currently held because of the gamepads, by outputId()
463
+ private heldGamepadOutputs = new Map<string, GamepadOutput>();
530
464
  private keyboardJoystickMap: KeyboardJoystickMap = { ...KEY_TO_JOYSTICK };
531
465
  private mixedJoystickMap: KeyboardJoystickMap = { ...MIXED_JOYSTICK_KEYS };
532
466
  private potFire2Pressed = false;
@@ -588,116 +522,53 @@ export class EmulatorInput {
588
522
  }
589
523
  const gp = gamepads[this.gamepadIndex];
590
524
  if (!gp) {
525
+ this.physicalGamepadState = {};
526
+ this.applyGamepadState();
591
527
  this.cancelUpdate();
592
528
  return;
593
529
  }
594
- if (gp.buttons) {
595
- for (let b = 0; b < gp.buttons.length; b++) {
596
- if (gp.buttons[b].pressed) {
597
- this.gamepadPresses[b] = true;
598
- console.log('Buttons Pressed', b, gp.buttons[b]);
599
- switch (b) {
600
- case 0:
601
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_FIRE_1);
602
- break;
603
- case 1:
604
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.UP);
605
- break;
606
- case 2:
607
- this.emulator.keyDown(C64_KEY.SPACE);
608
- break;
609
- case 3:
610
- //this.pushJoystickInput(JOYSTICK_FIRE_3);
611
- break;
612
- case 7:
613
- case 9:
614
- this.emulator.keyDown(C64_KEY.RUN_STOP);
615
- break;
616
- case 14:
617
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.LEFT);
618
- break;
619
- case 15:
620
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.RIGHT);
621
- break;
622
- case 12:
623
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.UP);
624
- break;
625
- case 13:
626
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.DOWN);
627
- break;
628
- }
629
- // this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.UP);
630
- } else if (!gp.buttons[b].pressed && this.gamepadPresses[b] === true) {
631
- this.gamepadPresses[b] = false;
632
- switch (b) {
633
- case 0:
634
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_FIRE_1);
635
- break;
636
- case 1:
637
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.UP);
638
- break;
639
- case 2:
640
- this.emulator.keyUp(C64_KEY.SPACE);
641
- //this.releaseJoystickInput(JOYSTICK_FIRE_2);
642
- break;
643
- case 3:
644
- //this.releaseJoystickInput(JOYSTICK_FIRE_3);
645
- break;
646
- case 7:
647
- case 9:
648
- this.emulator.keyUp(C64_KEY.RUN_STOP);
649
- break;
650
- case 14:
651
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.LEFT);
652
- break;
653
- case 15:
654
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.RIGHT);
655
- break;
656
- case 12:
657
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.UP);
658
- break;
659
- case 13:
660
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.DOWN);
661
- break;
662
- }
663
- // this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.UP);
664
- }
665
- }
666
- }
530
+ this.physicalGamepadState = readGamepadState(gp);
531
+ this.applyGamepadState();
667
532
 
668
- if (gp.axes[0] <= -0.5 || gp.axes[6] <= -0.5) {
669
- this.gamepadAxes[0] = true;
670
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.LEFT);
671
- } else if (this.gamepadAxes[0] === true) {
672
- this.gamepadAxes[0] = false;
673
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.LEFT);
674
- }
533
+ this.updateFrame = requestAnimationFrame(this.step.bind(this));
534
+ }
675
535
 
676
- if (gp.axes[0] >= 0.5 || gp.axes[6] >= 0.5) {
677
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.RIGHT);
678
- this.gamepadAxes[1] = true;
679
- } else if (this.gamepadAxes[1] === true) {
680
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.RIGHT);
681
- this.gamepadAxes[1] = false;
536
+ /** Holds exactly the emulator inputs that the physical and virtual gamepads map to right now */
537
+ private applyGamepadState(): void {
538
+ const physical = this.physicalGamepadState;
539
+ const virtual = this.virtualGamepadState;
540
+ const combined: GamepadState = {};
541
+ for (const control of [...GAMEPAD_DIRECTIONS, ...GAMEPAD_BUTTONS]) {
542
+ combined[control] = !!physical[control] || !!virtual[control];
682
543
  }
683
544
 
684
- if (gp.axes[1] <= -0.5 || gp.axes[7] <= -0.5) {
685
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.UP);
686
- this.gamepadAxes[2] = true;
687
- } else if (this.gamepadAxes[2] === true) {
688
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.UP);
689
- this.gamepadAxes[2] = false;
690
- }
545
+ const directions = restrictDirections(
546
+ combined,
547
+ this.gamepadMapping.stick,
548
+ this.heldGamepadDirections,
549
+ );
550
+ this.heldGamepadDirections = directions;
551
+ const outputs = resolveOutputs({ ...combined, ...directions }, this.gamepadMapping);
552
+ // Start is always RUN/STOP
553
+ if (physical.start) outputs.set(outputId({ key: C64_KEY.RUN_STOP }), { key: C64_KEY.RUN_STOP });
691
554
 
692
- if (gp.axes[1] >= 0.5 || gp.axes[7] >= 0.5) {
693
- this.emulator.joystickPush(this.joystickPort, JOYSTICK_DIRECTION.DOWN);
694
- this.gamepadAxes[3] = true;
695
- } else if (this.gamepadAxes[3] === true) {
696
- this.emulator.joystickRelease(this.joystickPort, JOYSTICK_DIRECTION.DOWN);
697
- this.gamepadAxes[3] = false;
555
+ for (const [id, output] of this.heldGamepadOutputs) {
556
+ if (!outputs.has(id)) this.releaseGamepadOutput(output);
698
557
  }
558
+ for (const [id, output] of outputs) {
559
+ if (!this.heldGamepadOutputs.has(id)) this.pushGamepadOutput(output);
560
+ }
561
+ this.heldGamepadOutputs = outputs;
562
+ }
699
563
 
700
- this.updateFrame = requestAnimationFrame(this.step.bind(this));
564
+ private pushGamepadOutput(output: GamepadOutput): void {
565
+ if ('joystick' in output) this.emulator.joystickPush(this.joystickPort, output.joystick);
566
+ else this.emulator.keyDown(output.key);
567
+ }
568
+
569
+ private releaseGamepadOutput(output: GamepadOutput): void {
570
+ if ('joystick' in output) this.emulator.joystickRelease(this.joystickPort, output.joystick);
571
+ else this.emulator.keyUp(output.key);
701
572
  }
702
573
 
703
574
  private cancelUpdate(): void {
@@ -706,27 +577,13 @@ export class EmulatorInput {
706
577
  this.gamepadIndex = -1;
707
578
  }
708
579
 
580
+ /** Lets go of everything the gamepads hold, physical and virtual */
709
581
  private releaseAllGamepadButtons(): void {
710
- if (!this.gamepadPresses.some(Boolean)) return;
711
-
712
- const buttonToInput: Partial<Record<number, JoystickInput>> = {
713
- 0: JOYSTICK_FIRE_1,
714
- 2: JOYSTICK_FIRE_2,
715
- 3: JOYSTICK_FIRE_3,
716
- 12: JOYSTICK_DIRECTION.UP,
717
- 13: JOYSTICK_DIRECTION.DOWN,
718
- 14: JOYSTICK_DIRECTION.LEFT,
719
- 15: JOYSTICK_DIRECTION.RIGHT,
720
- };
721
-
722
- for (const [button, input] of Object.entries(buttonToInput)) {
723
- if (!input) continue;
724
- if (this.gamepadPresses[Number(button)] === true) {
725
- this.releaseJoystickInput(input);
726
- }
727
- }
728
-
729
- this.gamepadPresses = [];
582
+ this.physicalGamepadState = {};
583
+ this.virtualGamepadState = {};
584
+ this.heldGamepadDirections = {};
585
+ for (const output of this.heldGamepadOutputs.values()) this.releaseGamepadOutput(output);
586
+ this.heldGamepadOutputs = new Map();
730
587
  }
731
588
 
732
589
  private findConnectedGamepadIndex(excludeIndex?: number): number {
@@ -789,6 +646,8 @@ export class EmulatorInput {
789
646
  }
790
647
 
791
648
  private handleKeyDown(event: KeyboardEvent): void {
649
+ if (isEditableEventTarget(event.target)) return;
650
+
792
651
  if (this.inputMode === 'keyboard') {
793
652
  // Pure keyboard mode — all keys go to C64 matrix, no joystick
794
653
  const acts = domKeyToC64Actions(event.key, event.shiftKey, 'keydown');
@@ -836,6 +695,8 @@ export class EmulatorInput {
836
695
  }
837
696
 
838
697
  private handleKeyUp(event: KeyboardEvent): void {
698
+ if (isEditableEventTarget(event.target)) return;
699
+
839
700
  if (this.inputMode === 'keyboard') {
840
701
  const acts = domKeyToC64Actions(event.key, event.shiftKey, 'keyup');
841
702
  if (acts.length > 0) {
@@ -986,4 +847,40 @@ export class EmulatorInput {
986
847
  getActiveGamepadIndex(): number {
987
848
  return this.gamepadIndex;
988
849
  }
850
+
851
+ /**
852
+ * Changes what the gamepad controls do: the stick mode, and the joystick input or C64 key for
853
+ * each direction and button. Unlisted controls keep their defaults; null/undefined restores all
854
+ * defaults. Applies to both the physical and the virtual gamepad.
855
+ */
856
+ setGamepadMapping(mapping?: GamepadMapping | null): void {
857
+ this.gamepadMapping = resolveGamepadMapping(mapping);
858
+ this.heldGamepadDirections = {};
859
+ this.applyGamepadState();
860
+ }
861
+
862
+ getGamepadMapping(): ResolvedGamepadMapping {
863
+ return this.gamepadMapping;
864
+ }
865
+
866
+ /**
867
+ * Sets the controls held on a virtual gamepad, e.g. on-screen touch controls. They go through
868
+ * the same mapping as the physical gamepad, combined with it.
869
+ */
870
+ setVirtualGamepadState(state: GamepadState): void {
871
+ this.virtualGamepadState = { ...state };
872
+ this.applyGamepadState();
873
+ }
874
+ }
875
+
876
+ function isEditableEventTarget(target: EventTarget | null): boolean {
877
+ if (!(target instanceof Element)) return false;
878
+ if (target instanceof HTMLInputElement) {
879
+ return target.type !== 'button' && target.type !== 'checkbox' && target.type !== 'radio';
880
+ }
881
+ return (
882
+ target instanceof HTMLTextAreaElement ||
883
+ target instanceof HTMLSelectElement ||
884
+ (target instanceof HTMLElement && target.isContentEditable)
885
+ );
989
886
  }