c64-ready 2.4.0 → 3.1.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.
- package/README.md +32 -0
- package/bin/admin.mjs +7 -1
- package/bin/headless.mjs +1 -1
- package/dist/assets/BeachHead-CuSwFD4k.js +1 -0
- package/dist/assets/ChuckieEgg-CPqBnAOF.js +1 -0
- package/dist/assets/ForbiddenForest-DsQ9jsc8.js +1 -0
- package/dist/assets/Galaga-Cutc3p9s.js +1 -0
- package/dist/assets/Gribbly-DdZ_hHFt.js +1 -0
- package/dist/assets/Hercules-vZYKm7GG.js +1 -0
- package/dist/assets/LegendOfWilf-CxSMOjsj.js +1 -0
- package/dist/assets/MariosCementFactory-z0IZ0q30.js +1 -0
- package/dist/assets/MoleAttack-buC6ChYy.js +1 -0
- package/dist/assets/MunchyWorm-D2Zv7i0Q.js +1 -0
- package/dist/assets/ParkPatrol-CVj7hyoB.js +1 -0
- package/dist/assets/PottyPigeon-0SYpIUBa.js +1 -0
- package/dist/assets/RainbowIslands-BjfmJB8z.js +1 -0
- package/dist/assets/Stix-BU-qUCeC.js +1 -0
- package/dist/assets/Tilt-C5KtKisF.js +1 -0
- package/dist/assets/UpNDown-CATRO7Mz.js +1 -0
- package/dist/assets/Uridium-DanS2KoH.js +1 -0
- package/dist/assets/VegetablesDeluxe-C41ViimS.js +1 -0
- package/dist/assets/index-B8DSjPqI.js +243 -0
- package/dist/assets/src-DX0rJQsE.js +1 -0
- package/dist/assets/src-_trgwTvp.js +2 -0
- package/dist/assets/string-utils-CMVABfx0.js +1 -0
- package/dist/index.html +1 -1
- package/dist-ts/emulator/c64-keys.d.ts +69 -0
- package/dist-ts/emulator/c64-keys.d.ts.map +1 -0
- package/dist-ts/emulator/c64-keys.js +69 -0
- package/dist-ts/emulator/c64-keys.js.map +1 -0
- package/dist-ts/emulator/gamepad-mapping.d.ts +64 -0
- package/dist-ts/emulator/gamepad-mapping.d.ts.map +1 -0
- package/dist-ts/emulator/gamepad-mapping.js +154 -0
- package/dist-ts/emulator/gamepad-mapping.js.map +1 -0
- package/dist-ts/emulator/input.d.ts +24 -75
- package/dist-ts/emulator/input.d.ts.map +1 -1
- package/dist-ts/emulator/input.js +93 -214
- package/dist-ts/emulator/input.js.map +1 -1
- package/dist-ts/player/c64-player.d.ts +25 -0
- package/dist-ts/player/c64-player.d.ts.map +1 -1
- package/dist-ts/player/c64-player.js +77 -1
- package/dist-ts/player/c64-player.js.map +1 -1
- package/dist-ts/player/cheevos-dev.d.ts +65 -0
- package/dist-ts/player/cheevos-dev.d.ts.map +1 -0
- package/dist-ts/player/cheevos-dev.js +237 -0
- package/dist-ts/player/cheevos-dev.js.map +1 -0
- package/dist-ts/player/cheevos-tracker-panel.d.ts +21 -0
- package/dist-ts/player/cheevos-tracker-panel.d.ts.map +1 -0
- package/dist-ts/player/cheevos-tracker-panel.js +242 -0
- package/dist-ts/player/cheevos-tracker-panel.js.map +1 -0
- package/dist-ts/player/index.d.ts +3 -0
- package/dist-ts/player/index.d.ts.map +1 -1
- package/dist-ts/player/index.js +2 -0
- package/dist-ts/player/index.js.map +1 -1
- package/dist-ts/player/input-handler.d.ts +12 -1
- package/dist-ts/player/input-handler.d.ts.map +1 -1
- package/dist-ts/player/input-handler.js +46 -1
- package/dist-ts/player/input-handler.js.map +1 -1
- package/dist-ts/player/local-rom-store.d.ts +23 -0
- package/dist-ts/player/local-rom-store.d.ts.map +1 -0
- package/dist-ts/player/local-rom-store.js +87 -0
- package/dist-ts/player/local-rom-store.js.map +1 -0
- package/dist-ts/player/startup-params.d.ts +7 -0
- package/dist-ts/player/startup-params.d.ts.map +1 -0
- package/dist-ts/player/startup-params.js +47 -0
- package/dist-ts/player/startup-params.js.map +1 -0
- package/dist-ts/player/ui-controller.d.ts +22 -0
- package/dist-ts/player/ui-controller.d.ts.map +1 -1
- package/dist-ts/player/ui-controller.js +666 -1
- package/dist-ts/player/ui-controller.js.map +1 -1
- package/package.json +2 -1
- package/src/emulator/c64-keys.ts +68 -0
- package/src/emulator/gamepad-mapping.ts +212 -0
- package/src/emulator/input.ts +106 -209
- package/src/headless/headless-cli.mjs +10 -4
- package/src/headless/input-server.mjs +92 -17
- package/src/headless/webrtc-server.mjs +344 -22
- package/src/main.ts +177 -12
- package/src/player/c64-player.ts +96 -1
- package/src/player/cheevos-dev.ts +340 -0
- package/src/player/cheevos-tracker-panel.ts +309 -0
- package/src/player/index.ts +19 -0
- package/src/player/input-handler.ts +63 -1
- package/src/player/local-rom-store.ts +126 -0
- package/src/player/startup-params.ts +40 -0
- package/src/player/ui-controller.ts +741 -0
- package/src/types/c64-cheevos.d.ts +6 -0
- package/dist/assets/index-Dxuihfdi.js +0 -177
- /package/dist/assets/{marked.esm--kBm026b.js → marked.esm-fTuuvbcB.js} +0 -0
- /package/dist/assets/{purify.es-BcoGFDcJ.js → purify.es-CRM-GE0Y.js} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** C64 keyboard matrix indices */
|
|
2
|
+
export const C64_KEY = {
|
|
3
|
+
ARROW_LEFT: 0,
|
|
4
|
+
ONE: 1,
|
|
5
|
+
TWO: 2,
|
|
6
|
+
THREE: 3,
|
|
7
|
+
FOUR: 4,
|
|
8
|
+
FIVE: 5,
|
|
9
|
+
SIX: 6,
|
|
10
|
+
SEVEN: 7,
|
|
11
|
+
EIGHT: 8,
|
|
12
|
+
NINE: 9,
|
|
13
|
+
ZERO: 10,
|
|
14
|
+
PLUS: 11,
|
|
15
|
+
MINUS: 12,
|
|
16
|
+
POUND: 13,
|
|
17
|
+
CLEAR_HOME: 14,
|
|
18
|
+
INS_DEL: 15,
|
|
19
|
+
CTRL: 16,
|
|
20
|
+
Q: 17,
|
|
21
|
+
W: 18,
|
|
22
|
+
E: 19,
|
|
23
|
+
R: 20,
|
|
24
|
+
T: 21,
|
|
25
|
+
Y: 22,
|
|
26
|
+
U: 23,
|
|
27
|
+
I: 24,
|
|
28
|
+
O: 25,
|
|
29
|
+
P: 26,
|
|
30
|
+
AT: 27,
|
|
31
|
+
STAR: 28,
|
|
32
|
+
ARROW_UP: 29,
|
|
33
|
+
RUN_STOP: 30,
|
|
34
|
+
A: 31,
|
|
35
|
+
S: 32,
|
|
36
|
+
D: 33,
|
|
37
|
+
F: 34,
|
|
38
|
+
G: 35,
|
|
39
|
+
H: 36,
|
|
40
|
+
J: 37,
|
|
41
|
+
K: 38,
|
|
42
|
+
L: 39,
|
|
43
|
+
COLON: 40,
|
|
44
|
+
SEMICOLON: 41,
|
|
45
|
+
EQUALS: 42,
|
|
46
|
+
RETURN: 43,
|
|
47
|
+
COMMODORE: 44,
|
|
48
|
+
SHIFT_LEFT: 45,
|
|
49
|
+
Z: 46,
|
|
50
|
+
X: 47,
|
|
51
|
+
C: 48,
|
|
52
|
+
V: 49,
|
|
53
|
+
B: 50,
|
|
54
|
+
N: 51,
|
|
55
|
+
M: 52,
|
|
56
|
+
COMMA: 53,
|
|
57
|
+
PERIOD: 54,
|
|
58
|
+
SLASH: 55,
|
|
59
|
+
SHIFT_RIGHT: 56,
|
|
60
|
+
CURSOR_UP_DOWN: 57,
|
|
61
|
+
CURSOR_LEFT_RIGHT: 58,
|
|
62
|
+
SPACE: 59,
|
|
63
|
+
F1: 60,
|
|
64
|
+
F3: 61,
|
|
65
|
+
F5: 62,
|
|
66
|
+
F7: 63,
|
|
67
|
+
RESTORE: 64,
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=c64-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"c64-keys.js","sourceRoot":"","sources":["../../src/emulator/c64-keys.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,UAAU,EAAE,CAAC;IACb,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,CAAC;IACN,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;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EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,EAAE,EAAE,EAAE;IACN,OAAO,EAAE,EAAE;CACH,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { type JoystickInput } from './constants.js';
|
|
2
|
+
/** Stick directions, from the D-pad, the left stick or a virtual (on-screen) stick */
|
|
3
|
+
export type GamepadDirection = 'up' | 'down' | 'left' | 'right';
|
|
4
|
+
/** Remappable buttons, named after the standard gamepad layout (Xbox style) */
|
|
5
|
+
export type GamepadButton = 'a' | 'b' | 'x' | 'y' | 'lb' | 'rb' | 'lt' | 'rt';
|
|
6
|
+
export type GamepadControl = GamepadDirection | GamepadButton;
|
|
7
|
+
/**
|
|
8
|
+
* - '8way' — diagonals allowed (default)
|
|
9
|
+
* - '4way' — one direction at a time; a diagonal keeps the direction already held
|
|
10
|
+
* - '2way' — left and right only
|
|
11
|
+
*/
|
|
12
|
+
export type StickMode = '8way' | '4way' | '2way';
|
|
13
|
+
export type JoystickAction = 'up' | 'down' | 'left' | 'right' | 'fire';
|
|
14
|
+
/** What a control does: a joystick input, a C64 keyboard matrix key (see C64_KEY), or nothing (null) */
|
|
15
|
+
export type ControlAction = {
|
|
16
|
+
joystick: JoystickAction;
|
|
17
|
+
} | {
|
|
18
|
+
key: number;
|
|
19
|
+
} | null;
|
|
20
|
+
export interface GamepadMapping {
|
|
21
|
+
stick?: StickMode;
|
|
22
|
+
/** Unlisted directions keep their default action */
|
|
23
|
+
directions?: Partial<Record<GamepadDirection, ControlAction>>;
|
|
24
|
+
/** Unlisted buttons keep their default action */
|
|
25
|
+
buttons?: Partial<Record<GamepadButton, ControlAction>>;
|
|
26
|
+
}
|
|
27
|
+
export type ResolvedGamepadMapping = {
|
|
28
|
+
stick: StickMode;
|
|
29
|
+
directions: Record<GamepadDirection, ControlAction>;
|
|
30
|
+
buttons: Record<GamepadButton, ControlAction>;
|
|
31
|
+
};
|
|
32
|
+
/** Which controls are held. Missing controls count as released. */
|
|
33
|
+
export type GamepadState = Partial<Record<GamepadControl, boolean>>;
|
|
34
|
+
export declare const GAMEPAD_DIRECTIONS: GamepadDirection[];
|
|
35
|
+
export declare const GAMEPAD_BUTTONS: GamepadButton[];
|
|
36
|
+
/** Standard mapping button indices (https://w3c.github.io/gamepad/#remapping) */
|
|
37
|
+
export declare const STANDARD_BUTTON_INDEX: Record<GamepadButton | 'start' | GamepadDirection, number>;
|
|
38
|
+
/** The mapping c64-ready has always used: A fires, B is up, X is Space and RT is RUN/STOP */
|
|
39
|
+
export declare const DEFAULT_GAMEPAD_MAPPING: ResolvedGamepadMapping;
|
|
40
|
+
/** Fills in defaults and drops anything invalid, so the result can be used as is */
|
|
41
|
+
export declare function resolveGamepadMapping(mapping?: GamepadMapping | null): ResolvedGamepadMapping;
|
|
42
|
+
/**
|
|
43
|
+
* Reads a standard-mapping gamepad into named controls.
|
|
44
|
+
* Directions come from the D-pad buttons, the left stick, or axes 6/7 (D-pads reported as axes, e.g. 8BitDo).
|
|
45
|
+
*/
|
|
46
|
+
export declare function readGamepadState(gamepad: Gamepad): GamepadState & {
|
|
47
|
+
start: boolean;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Limits held directions to the stick mode.
|
|
51
|
+
* In 4-way mode a diagonal keeps whichever axis was already held (`previous`), else it goes horizontal.
|
|
52
|
+
*/
|
|
53
|
+
export declare function restrictDirections(state: GamepadState, mode: StickMode, previous?: GamepadState): Record<GamepadDirection, boolean>;
|
|
54
|
+
/** An emulator input to hold: a joystick bit on the active port, or a keyboard matrix key */
|
|
55
|
+
export type GamepadOutput = {
|
|
56
|
+
joystick: JoystickInput;
|
|
57
|
+
} | {
|
|
58
|
+
key: number;
|
|
59
|
+
};
|
|
60
|
+
/** Stable id for an output, so two controls mapped to the same thing hold it once */
|
|
61
|
+
export declare const outputId: (output: GamepadOutput) => string;
|
|
62
|
+
/** The emulator inputs to hold for these (already direction-restricted) controls */
|
|
63
|
+
export declare function resolveOutputs(state: GamepadState, mapping: ResolvedGamepadMapping): Map<string, GamepadOutput>;
|
|
64
|
+
//# sourceMappingURL=gamepad-mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gamepad-mapping.d.ts","sourceRoot":"","sources":["../../src/emulator/gamepad-mapping.ts"],"names":[],"mappings":"AACA,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEtF,sFAAsF;AACtF,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhE,+EAA+E;AAC/E,MAAM,MAAM,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE9E,MAAM,MAAM,cAAc,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAE9D;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjD,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAEvE,wGAAwG;AACxG,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,cAAc,CAAA;CAAE,GAAG;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC;AAElF,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,oDAAoD;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAC,CAAC;IAC9D,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;CACzD;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,E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a,CAAC,CAY5B"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { C64_KEY } from './c64-keys.js';
|
|
2
|
+
import { JOYSTICK_DIRECTION, JOYSTICK_FIRE_1 } from './constants.js';
|
|
3
|
+
export const GAMEPAD_DIRECTIONS = ['up', 'down', 'left', 'right'];
|
|
4
|
+
export const GAMEPAD_BUTTONS = ['a', 'b', 'x', 'y', 'lb', 'rb', 'lt', 'rt'];
|
|
5
|
+
/** Standard mapping button indices (https://w3c.github.io/gamepad/#remapping) */
|
|
6
|
+
export const STANDARD_BUTTON_INDEX = {
|
|
7
|
+
a: 0,
|
|
8
|
+
b: 1,
|
|
9
|
+
x: 2,
|
|
10
|
+
y: 3,
|
|
11
|
+
lb: 4,
|
|
12
|
+
rb: 5,
|
|
13
|
+
lt: 6,
|
|
14
|
+
rt: 7,
|
|
15
|
+
start: 9,
|
|
16
|
+
up: 12,
|
|
17
|
+
down: 13,
|
|
18
|
+
left: 14,
|
|
19
|
+
right: 15,
|
|
20
|
+
};
|
|
21
|
+
const STICK_THRESHOLD = 0.5;
|
|
22
|
+
/** The mapping c64-ready has always used: A fires, B is up, X is Space and RT is RUN/STOP */
|
|
23
|
+
export const DEFAULT_GAMEPAD_MAPPING = Object.freeze({
|
|
24
|
+
stick: '8way',
|
|
25
|
+
directions: Object.freeze({
|
|
26
|
+
up: { joystick: 'up' },
|
|
27
|
+
down: { joystick: 'down' },
|
|
28
|
+
left: { joystick: 'left' },
|
|
29
|
+
right: { joystick: 'right' },
|
|
30
|
+
}),
|
|
31
|
+
buttons: Object.freeze({
|
|
32
|
+
a: { joystick: 'fire' },
|
|
33
|
+
b: { joystick: 'up' },
|
|
34
|
+
x: { key: C64_KEY.SPACE },
|
|
35
|
+
y: null,
|
|
36
|
+
lb: null,
|
|
37
|
+
rb: null,
|
|
38
|
+
lt: null,
|
|
39
|
+
rt: { key: C64_KEY.RUN_STOP },
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
const STICK_MODES = ['8way', '4way', '2way'];
|
|
43
|
+
const JOYSTICK_ACTIONS = ['up', 'down', 'left', 'right', 'fire'];
|
|
44
|
+
const C64_KEY_CODES = new Set(Object.values(C64_KEY));
|
|
45
|
+
function normaliseAction(action, fallback) {
|
|
46
|
+
if (action === undefined)
|
|
47
|
+
return fallback;
|
|
48
|
+
if (action === null)
|
|
49
|
+
return null;
|
|
50
|
+
if (typeof action !== 'object')
|
|
51
|
+
return fallback;
|
|
52
|
+
const { joystick, key } = action;
|
|
53
|
+
if (JOYSTICK_ACTIONS.includes(joystick))
|
|
54
|
+
return { joystick: joystick };
|
|
55
|
+
if (typeof key === 'number' && C64_KEY_CODES.has(key))
|
|
56
|
+
return { key };
|
|
57
|
+
return fallback;
|
|
58
|
+
}
|
|
59
|
+
/** Fills in defaults and drops anything invalid, so the result can be used as is */
|
|
60
|
+
export function resolveGamepadMapping(mapping) {
|
|
61
|
+
const base = DEFAULT_GAMEPAD_MAPPING;
|
|
62
|
+
const stick = STICK_MODES.includes(mapping?.stick)
|
|
63
|
+
? mapping.stick
|
|
64
|
+
: base.stick;
|
|
65
|
+
const directions = {};
|
|
66
|
+
for (const direction of GAMEPAD_DIRECTIONS) {
|
|
67
|
+
directions[direction] = normaliseAction(mapping?.directions?.[direction], base.directions[direction]);
|
|
68
|
+
}
|
|
69
|
+
const buttons = {};
|
|
70
|
+
for (const button of GAMEPAD_BUTTONS) {
|
|
71
|
+
buttons[button] = normaliseAction(mapping?.buttons?.[button], base.buttons[button]);
|
|
72
|
+
}
|
|
73
|
+
return { stick, directions, buttons };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Reads a standard-mapping gamepad into named controls.
|
|
77
|
+
* Directions come from the D-pad buttons, the left stick, or axes 6/7 (D-pads reported as axes, e.g. 8BitDo).
|
|
78
|
+
*/
|
|
79
|
+
export function readGamepadState(gamepad) {
|
|
80
|
+
const pressed = (index) => !!gamepad.buttons?.[index]?.pressed;
|
|
81
|
+
const axis = (index) => gamepad.axes?.[index] ?? 0;
|
|
82
|
+
const state = {
|
|
83
|
+
up: pressed(STANDARD_BUTTON_INDEX.up) ||
|
|
84
|
+
axis(1) <= -STICK_THRESHOLD ||
|
|
85
|
+
axis(7) <= -STICK_THRESHOLD,
|
|
86
|
+
down: pressed(STANDARD_BUTTON_INDEX.down) ||
|
|
87
|
+
axis(1) >= STICK_THRESHOLD ||
|
|
88
|
+
axis(7) >= STICK_THRESHOLD,
|
|
89
|
+
left: pressed(STANDARD_BUTTON_INDEX.left) ||
|
|
90
|
+
axis(0) <= -STICK_THRESHOLD ||
|
|
91
|
+
axis(6) <= -STICK_THRESHOLD,
|
|
92
|
+
right: pressed(STANDARD_BUTTON_INDEX.right) ||
|
|
93
|
+
axis(0) >= STICK_THRESHOLD ||
|
|
94
|
+
axis(6) >= STICK_THRESHOLD,
|
|
95
|
+
start: pressed(STANDARD_BUTTON_INDEX.start),
|
|
96
|
+
};
|
|
97
|
+
for (const button of GAMEPAD_BUTTONS)
|
|
98
|
+
state[button] = pressed(STANDARD_BUTTON_INDEX[button]);
|
|
99
|
+
return state;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Limits held directions to the stick mode.
|
|
103
|
+
* In 4-way mode a diagonal keeps whichever axis was already held (`previous`), else it goes horizontal.
|
|
104
|
+
*/
|
|
105
|
+
export function restrictDirections(state, mode, previous = {}) {
|
|
106
|
+
let up = !!state.up && !state.down;
|
|
107
|
+
let down = !!state.down && !state.up;
|
|
108
|
+
let left = !!state.left && !state.right;
|
|
109
|
+
let right = !!state.right && !state.left;
|
|
110
|
+
if (mode === '2way') {
|
|
111
|
+
up = false;
|
|
112
|
+
down = false;
|
|
113
|
+
}
|
|
114
|
+
else if (mode === '4way' && (up || down) && (left || right)) {
|
|
115
|
+
const keepVertical = (up && !!previous.up) || (down && !!previous.down);
|
|
116
|
+
const keepHorizontal = (left && !!previous.left) || (right && !!previous.right);
|
|
117
|
+
if (keepVertical && !keepHorizontal) {
|
|
118
|
+
left = false;
|
|
119
|
+
right = false;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
up = false;
|
|
123
|
+
down = false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { up, down, left, right };
|
|
127
|
+
}
|
|
128
|
+
const JOYSTICK_BITS = {
|
|
129
|
+
up: JOYSTICK_DIRECTION.UP,
|
|
130
|
+
down: JOYSTICK_DIRECTION.DOWN,
|
|
131
|
+
left: JOYSTICK_DIRECTION.LEFT,
|
|
132
|
+
right: JOYSTICK_DIRECTION.RIGHT,
|
|
133
|
+
fire: JOYSTICK_FIRE_1,
|
|
134
|
+
};
|
|
135
|
+
/** Stable id for an output, so two controls mapped to the same thing hold it once */
|
|
136
|
+
export const outputId = (output) => 'joystick' in output ? `j${output.joystick}` : `k${output.key}`;
|
|
137
|
+
/** The emulator inputs to hold for these (already direction-restricted) controls */
|
|
138
|
+
export function resolveOutputs(state, mapping) {
|
|
139
|
+
const outputs = new Map();
|
|
140
|
+
const add = (action) => {
|
|
141
|
+
if (!action)
|
|
142
|
+
return;
|
|
143
|
+
const output = 'joystick' in action ? { joystick: JOYSTICK_BITS[action.joystick] } : { key: action.key };
|
|
144
|
+
outputs.set(outputId(output), output);
|
|
145
|
+
};
|
|
146
|
+
for (const direction of GAMEPAD_DIRECTIONS)
|
|
147
|
+
if (state[direction])
|
|
148
|
+
add(mapping.directions[direction]);
|
|
149
|
+
for (const button of GAMEPAD_BUTTONS)
|
|
150
|
+
if (state[button])
|
|
151
|
+
add(mapping.buttons[button]);
|
|
152
|
+
return outputs;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=gamepad-mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gamepad-mapping.js","sourceRoot":"","sources":["../../src/emulator/gamepad-mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE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AAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC;QAC5F,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC,CAAC;IACF,KAAK,MAAM,SAAS,IAAI,kBAAkB;QACxC,IAAI,KAAK,CAAC,SAAS,CAAC;YAAE,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;IAC3D,KAAK,MAAM,MAAM,IAAI,eAAe;QAAE,IAAI,KAAK,CAAC,MAAM,CAAC;YAAE,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACtF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { C64Emulator } from './c64-emulator.js';
|
|
2
2
|
import { type JoystickInput } from './constants.js';
|
|
3
3
|
import type { JoystickPort } from './constants.js';
|
|
4
|
+
import { type GamepadMapping, type GamepadState, type ResolvedGamepadMapping } from './gamepad-mapping.js';
|
|
4
5
|
export declare const KEY_TO_JOYSTICK: {
|
|
5
6
|
readonly ArrowUp: 1;
|
|
6
7
|
readonly ArrowDown: 2;
|
|
@@ -29,74 +30,7 @@ export type InputMode = 'joystick' | 'keyboard' | 'mixed';
|
|
|
29
30
|
* C64 keyboard matrix in mixed mode.
|
|
30
31
|
*/
|
|
31
32
|
export declare const MIXED_JOYSTICK_KEYS: KeyboardJoystickMap;
|
|
32
|
-
|
|
33
|
-
export declare const C64_KEY: {
|
|
34
|
-
readonly ARROW_LEFT: 0;
|
|
35
|
-
readonly ONE: 1;
|
|
36
|
-
readonly TWO: 2;
|
|
37
|
-
readonly THREE: 3;
|
|
38
|
-
readonly FOUR: 4;
|
|
39
|
-
readonly FIVE: 5;
|
|
40
|
-
readonly SIX: 6;
|
|
41
|
-
readonly SEVEN: 7;
|
|
42
|
-
readonly EIGHT: 8;
|
|
43
|
-
readonly NINE: 9;
|
|
44
|
-
readonly ZERO: 10;
|
|
45
|
-
readonly PLUS: 11;
|
|
46
|
-
readonly MINUS: 12;
|
|
47
|
-
readonly POUND: 13;
|
|
48
|
-
readonly CLEAR_HOME: 14;
|
|
49
|
-
readonly INS_DEL: 15;
|
|
50
|
-
readonly CTRL: 16;
|
|
51
|
-
readonly Q: 17;
|
|
52
|
-
readonly W: 18;
|
|
53
|
-
readonly E: 19;
|
|
54
|
-
readonly R: 20;
|
|
55
|
-
readonly T: 21;
|
|
56
|
-
readonly Y: 22;
|
|
57
|
-
readonly U: 23;
|
|
58
|
-
readonly I: 24;
|
|
59
|
-
readonly O: 25;
|
|
60
|
-
readonly P: 26;
|
|
61
|
-
readonly AT: 27;
|
|
62
|
-
readonly STAR: 28;
|
|
63
|
-
readonly ARROW_UP: 29;
|
|
64
|
-
readonly RUN_STOP: 30;
|
|
65
|
-
readonly A: 31;
|
|
66
|
-
readonly S: 32;
|
|
67
|
-
readonly D: 33;
|
|
68
|
-
readonly F: 34;
|
|
69
|
-
readonly G: 35;
|
|
70
|
-
readonly H: 36;
|
|
71
|
-
readonly J: 37;
|
|
72
|
-
readonly K: 38;
|
|
73
|
-
readonly L: 39;
|
|
74
|
-
readonly COLON: 40;
|
|
75
|
-
readonly SEMICOLON: 41;
|
|
76
|
-
readonly EQUALS: 42;
|
|
77
|
-
readonly RETURN: 43;
|
|
78
|
-
readonly COMMODORE: 44;
|
|
79
|
-
readonly SHIFT_LEFT: 45;
|
|
80
|
-
readonly Z: 46;
|
|
81
|
-
readonly X: 47;
|
|
82
|
-
readonly C: 48;
|
|
83
|
-
readonly V: 49;
|
|
84
|
-
readonly B: 50;
|
|
85
|
-
readonly N: 51;
|
|
86
|
-
readonly M: 52;
|
|
87
|
-
readonly COMMA: 53;
|
|
88
|
-
readonly PERIOD: 54;
|
|
89
|
-
readonly SLASH: 55;
|
|
90
|
-
readonly SHIFT_RIGHT: 56;
|
|
91
|
-
readonly CURSOR_UP_DOWN: 57;
|
|
92
|
-
readonly CURSOR_LEFT_RIGHT: 58;
|
|
93
|
-
readonly SPACE: 59;
|
|
94
|
-
readonly F1: 60;
|
|
95
|
-
readonly F3: 61;
|
|
96
|
-
readonly F5: 62;
|
|
97
|
-
readonly F7: 63;
|
|
98
|
-
readonly RESTORE: 64;
|
|
99
|
-
};
|
|
33
|
+
export { C64_KEY } from './c64-keys.js';
|
|
100
34
|
type C64KeyAction = {
|
|
101
35
|
key: number;
|
|
102
36
|
action: 'press' | 'release';
|
|
@@ -113,12 +47,11 @@ export declare class EmulatorInput {
|
|
|
113
47
|
private inputMode;
|
|
114
48
|
private updateFrame;
|
|
115
49
|
private gamepadIndex;
|
|
116
|
-
private
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
private gamepadAxes;
|
|
50
|
+
private gamepadMapping;
|
|
51
|
+
private physicalGamepadState;
|
|
52
|
+
private virtualGamepadState;
|
|
53
|
+
private heldGamepadDirections;
|
|
54
|
+
private heldGamepadOutputs;
|
|
122
55
|
private keyboardJoystickMap;
|
|
123
56
|
private mixedJoystickMap;
|
|
124
57
|
private potFire2Pressed;
|
|
@@ -132,7 +65,12 @@ export declare class EmulatorInput {
|
|
|
132
65
|
attach(): void;
|
|
133
66
|
detach(): void;
|
|
134
67
|
private step;
|
|
68
|
+
/** Holds exactly the emulator inputs that the physical and virtual gamepads map to right now */
|
|
69
|
+
private applyGamepadState;
|
|
70
|
+
private pushGamepadOutput;
|
|
71
|
+
private releaseGamepadOutput;
|
|
135
72
|
private cancelUpdate;
|
|
73
|
+
/** Lets go of everything the gamepads hold, physical and virtual */
|
|
136
74
|
private releaseAllGamepadButtons;
|
|
137
75
|
private findConnectedGamepadIndex;
|
|
138
76
|
private handleGamepadDisconnected;
|
|
@@ -154,6 +92,17 @@ export declare class EmulatorInput {
|
|
|
154
92
|
isJoystickKeyCode(code: string): boolean;
|
|
155
93
|
setActiveGamepadIndex(index: number): void;
|
|
156
94
|
getActiveGamepadIndex(): number;
|
|
95
|
+
/**
|
|
96
|
+
* Changes what the gamepad controls do: the stick mode, and the joystick input or C64 key for
|
|
97
|
+
* each direction and button. Unlisted controls keep their defaults; null/undefined restores all
|
|
98
|
+
* defaults. Applies to both the physical and the virtual gamepad.
|
|
99
|
+
*/
|
|
100
|
+
setGamepadMapping(mapping?: GamepadMapping | null): void;
|
|
101
|
+
getGamepadMapping(): ResolvedGamepadMapping;
|
|
102
|
+
/**
|
|
103
|
+
* Sets the controls held on a virtual gamepad, e.g. on-screen touch controls. They go through
|
|
104
|
+
* the same mapping as the physical gamepad, combined with it.
|
|
105
|
+
*/
|
|
106
|
+
setVirtualGamepadState(state: GamepadState): void;
|
|
157
107
|
}
|
|
158
|
-
export {};
|
|
159
108
|
//# sourceMappingURL=input.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/emulator/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAML,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,eAAe;;;;;;CAMlB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAEhE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,MAAM,OAAO,eAAe,CAE3B,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,mBASjC,CAAC;AAaF,
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/emulator/input.ts"],"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