fork/GramFirmware

git clone https://git.julia.blue/fork/GramFirmware

CarVacrebase to configurator818d962

gram
3.8 KiB119 linesraw
1#include "modes/extra/MultiVersus.hpp"
2
3#define ANALOG_STICK_MIN 0
4#define ANALOG_STICK_NEUTRAL 128
5#define ANALOG_STICK_MAX 255
6
7MultiVersus::MultiVersus() : ControllerMode() {}
8
9void MultiVersus::UpdateDigitalOutputs(const InputState &inputs, OutputState &outputs) {
10    // Bind X and Y to "jump" in-game.
11    outputs.x = inputs.rf2;
12    outputs.y = inputs.rf6;
13
14    outputs.start = !inputs.lt2 && inputs.mb1;
15
16    // Select, MS, or MY + Start for "Reset" in the Lab. Not supported by GameCube adapter.
17    outputs.select = inputs.mb3 || inputs.rf8 || (inputs.lt2 && inputs.mb1);
18
19    // Home not supported by GameCube adapter.
20    outputs.home = inputs.mb2;
21
22    // L or Nunchuk Z = LT. Bind to "dodge" in-game.
23    if (inputs.nunchuk_connected) {
24        outputs.triggerLDigital = inputs.nunchuk_z;
25    } else {
26        outputs.triggerLDigital = inputs.lf4;
27    }
28
29    // R = RT. Can be bound to "pickup item" or left unbound.
30    outputs.triggerRDigital = inputs.rf5;
31
32    if (!inputs.lt1) {
33        // Bind A to "attack" in-game.
34        outputs.a = inputs.rt1;
35
36        // Bind B to "special" in-game.
37        outputs.b = inputs.rf1;
38
39        // Z = RB. Bind to "dodge" in-game.
40        outputs.buttonR = inputs.rf3;
41
42        // LS = LB. Not supported by GameCube adapter.
43        outputs.buttonL = inputs.rf7;
44    }
45
46    // MX activates a layer for "neutral" binds. Uses D-Pad buttons.
47    if (inputs.lt1 && !inputs.lt2) {
48        // MX + A = D-Pad Left. Bind to "neutral attack" in-game.
49        outputs.dpadLeft = inputs.rt1;
50
51        // MX + B = D-Pad Right. Bind to "neutral special" in-game.
52        outputs.dpadRight = inputs.rf1;
53
54        // MX + Z = D-Pad Down. Bind to "neutral evade" in-game.
55        outputs.dpadDown = inputs.rf3;
56
57        // MX + LS = D-Pad Up. Bind to "taunt 1" in-game.
58        outputs.dpadUp = inputs.rf7;
59    }
60
61    // MY activates C-Stick to D-Pad conversion.
62    if (inputs.lt2 && !inputs.lt1) {
63        outputs.dpadLeft = inputs.rt3;
64        outputs.dpadRight = inputs.rt5;
65        outputs.dpadDown = inputs.rt2;
66        outputs.dpadUp = inputs.rt4;
67    }
68}
69
70void MultiVersus::UpdateAnalogOutputs(const InputState &inputs, OutputState &outputs) {
71    // Coordinate calculations to make modifier handling simpler.
72    UpdateDirections(
73        inputs.lf3, // Left
74        inputs.lf1, // Right
75        inputs.lf2, // Down
76        inputs.rf4, // Up
77        inputs.rt3, // C-Left
78        inputs.rt5, // C-Right
79        inputs.rt2, // C-Down
80        inputs.rt4, // C-Up
81        ANALOG_STICK_MIN,
82        ANALOG_STICK_NEUTRAL,
83        ANALOG_STICK_MAX,
84        outputs
85    );
86
87    if (inputs.lt2 && !inputs.lt1) {
88        // MY slows down the cursor for easier menu navigation.
89        // Menu cursor speed can also be turned down in-game under "Interface" settings.
90        // 128 ± 76 results in the slowest cursor that still actuates directional inputs in-game.
91        outputs.leftStickX = ANALOG_STICK_NEUTRAL + directions.x * 76;
92        outputs.leftStickY = ANALOG_STICK_NEUTRAL + directions.y * 76;
93
94        if (directions.diagonal) {
95            // Maintain a consistent cursor velocity when MY is held.
96            // ⌊76 × √2/2⌋ = 53
97            outputs.leftStickX = ANALOG_STICK_NEUTRAL + directions.x * 53;
98            outputs.leftStickY = ANALOG_STICK_NEUTRAL + directions.y * 53;
99        }
100
101        // Also shut off C-Stick for D-Pad conversion.
102        outputs.rightStickX = ANALOG_STICK_NEUTRAL;
103        outputs.rightStickY = ANALOG_STICK_NEUTRAL;
104    }
105
106    if (outputs.triggerLDigital) {
107        outputs.triggerLAnalog = 140;
108    }
109
110    if (outputs.triggerRDigital) {
111        outputs.triggerRAnalog = 140;
112    }
113
114    // Nunchuk overrides left stick.
115    if (inputs.nunchuk_connected) {
116        outputs.leftStickX = inputs.nunchuk_x;
117        outputs.leftStickY = inputs.nunchuk_y;
118    }
119}