|
14 | 14 |
|
15 | 15 | namespace { |
16 | 16 | // this is rounding down since >> 1 throws away the least significant bit, but if its a power of two it is spot on |
17 | | - constexpr unsigned BITL_REVERSE(unsigned x) { |
| 17 | + constexpr unsigned long BITL_REVERSE(unsigned long x) { |
18 | 18 | return x == 1 ? 0 : 1 + BITL_REVERSE(x >> 1); |
19 | 19 | } |
20 | 20 | }; // namespace |
21 | 21 |
|
22 | 22 | //using C enum (not enum class) on purpose |
23 | 23 | enum JOYCON { |
24 | 24 |
|
25 | | - JOYCON_A = BITL_REVERSE(HidNpadButton_A), |
26 | | - JOYCON_B = BITL_REVERSE(HidNpadButton_B), |
27 | | - JOYCON_X = BITL_REVERSE(HidNpadButton_X), |
28 | | - JOYCON_Y = BITL_REVERSE(HidNpadButton_Y), |
29 | | - |
30 | | - JOYCON_PLUS = BITL_REVERSE(HidNpadButton_Plus), |
31 | | - JOYCON_MINUS = BITL_REVERSE(HidNpadButton_Minus), |
32 | | - JOYCON_CROSS_LEFT = BITL_REVERSE(HidNpadButton_Left), |
33 | | - JOYCON_CROSS_UP = BITL_REVERSE(HidNpadButton_Up), |
34 | | - JOYCON_CROSS_RIGHT = BITL_REVERSE(HidNpadButton_Right), |
35 | | - JOYCON_CROSS_DOWN = BITL_REVERSE(HidNpadButton_Down), |
36 | | - JOYCON_LDPAD_LEFT = BITL_REVERSE(HidNpadButton_StickLLeft), |
37 | | - JOYCON_LDPAD_UP = BITL_REVERSE(HidNpadButton_StickLUp), |
38 | | - JOYCON_LDPAD_RIGHT = BITL_REVERSE(HidNpadButton_StickLRight), |
39 | | - JOYCON_LDPAD_DOWN = BITL_REVERSE(HidNpadButton_StickLDown), |
40 | | - JOYCON_RDPAD_LEFT = BITL_REVERSE(HidNpadButton_StickRLeft), |
41 | | - JOYCON_RDPAD_UP = BITL_REVERSE(HidNpadButton_StickRUp), |
42 | | - JOYCON_RDPAD_RIGHT = BITL_REVERSE(HidNpadButton_StickRRight), |
43 | | - JOYCON_RDPAD_DOWN = BITL_REVERSE(HidNpadButton_StickRDown) |
| 25 | + // see /opt/devkitpro/libnx/include/switch/services/hid.h |
| 26 | + |
| 27 | + JOYCON_A = BITL_REVERSE(HidNpadButton_A), ///< A button / Right face button |
| 28 | + JOYCON_B = BITL_REVERSE(HidNpadButton_B), ///< B button / Down face button |
| 29 | + JOYCON_X = BITL_REVERSE(HidNpadButton_X), ///< X button / Up face button |
| 30 | + JOYCON_Y = BITL_REVERSE(HidNpadButton_Y), ///< Y button / Left face button |
| 31 | + |
| 32 | + //NOTE: stick buttons are not key events, but can be moved, these need separate handling |
| 33 | + JOYCON_STICK_L = BITL(HidNpadButton_StickL), ///< Left Stick button |
| 34 | + JOYCON_STICK_R = BITL(HidNpadButton_StickR), ///< Right Stick button |
| 35 | + |
| 36 | + JOYCON_L = BITL_REVERSE(HidNpadButton_L), ///< L button |
| 37 | + JOYCON_R = BITL(HidNpadButton_R), ///< R button |
| 38 | + JOYCON_ZL = BITL(HidNpadButton_ZL), ///< ZL button |
| 39 | + JOYCON_ZR = BITL(HidNpadButton_ZR), ///< ZR button |
| 40 | + |
| 41 | + |
| 42 | + JOYCON_PLUS = BITL_REVERSE(HidNpadButton_Plus), ///< Plus button |
| 43 | + JOYCON_MINUS = BITL_REVERSE(HidNpadButton_Minus), ///< Minus button |
| 44 | + |
| 45 | + // DPAD alias CROSS |
| 46 | + JOYCON_DPAD_LEFT = BITL_REVERSE(HidNpadButton_Left), ///< D-Pad Left button |
| 47 | + JOYCON_DPAD_UP = BITL_REVERSE(HidNpadButton_Up), ///< D-Pad Up button |
| 48 | + JOYCON_DPAD_RIGHT = BITL_REVERSE(HidNpadButton_Right), ///< D-Pad Right button |
| 49 | + JOYCON_DPAD_DOWN = BITL_REVERSE(HidNpadButton_Down), ///< D-Pad Down button |
| 50 | + |
| 51 | + JOYCON_LDPAD_LEFT = BITL_REVERSE(HidNpadButton_StickLLeft), ///< Left Stick pseudo-button when moved Left |
| 52 | + JOYCON_LDPAD_UP = BITL_REVERSE(HidNpadButton_StickLUp), ///< Left Stick pseudo-button when moved Up |
| 53 | + JOYCON_LDPAD_RIGHT = BITL_REVERSE(HidNpadButton_StickLRight), ///< Left Stick pseudo-button when moved Right |
| 54 | + JOYCON_LDPAD_DOWN = BITL_REVERSE(HidNpadButton_StickLDown), ///< Left Stick pseudo-button when moved Down |
| 55 | + |
| 56 | + JOYCON_RDPAD_LEFT = BITL_REVERSE(HidNpadButton_StickRLeft), ///< Right Stick pseudo-button when moved Left |
| 57 | + JOYCON_RDPAD_UP = BITL_REVERSE(HidNpadButton_StickRUp), ///< Right Stick pseudo-button when moved Up |
| 58 | + JOYCON_RDPAD_RIGHT = BITL_REVERSE(HidNpadButton_StickRRight), ///< Right Stick pseudo-button when moved Right |
| 59 | + JOYCON_RDPAD_DOWN = BITL_REVERSE(HidNpadButton_StickRDown), ///< Right Stick pseudo-button when moved Left |
| 60 | + |
| 61 | + |
| 62 | + JOYCON_JOYCONL_SL = BITL_REVERSE(HidNpadButton_LeftSL), ///< SL button on Left Joy-Con |
| 63 | + JOYCON_JOYCONL_SR = BITL_REVERSE(HidNpadButton_LeftSR), ///< SR button on Left Joy-Con |
| 64 | + |
| 65 | + JOYCON_JOYCONR_SL = BITL_REVERSE(HidNpadButton_RightSL), ///< SL button on Right Joy-Con |
| 66 | + JOYCON_JOYCONR_SL = BITL_REVERSE(HidNpadButton_RightSR), ///< SR button on Right Joy-Con |
| 67 | + |
| 68 | + JOYCON_VERIFICATION = BITL_REVERSE(HidNpadButton_Verification), ///< Verification |
44 | 69 |
|
45 | 70 | }; |
46 | 71 |
|
47 | 72 | // some static asserts to check if BITL_REVERSE works as expected |
48 | 73 | static_assert(BITL(JOYCON_B) == HidNpadButton_B); |
49 | 74 | static_assert(BITL(JOYCON_PLUS) == HidNpadButton_Plus); |
50 | 75 |
|
| 76 | +#elif defined(__3DS__) |
| 77 | + |
| 78 | + |
| 79 | +#include <3ds.h> |
| 80 | + |
| 81 | +// some 3ds buttons, from libctru, but since SDL doesn't handle inputs as flags, like libctru, the have to be reversed and reversing 1 << x = log_2(x), this is done constexpr |
| 82 | + |
| 83 | + |
| 84 | +namespace { |
| 85 | + // this is rounding down since >> 1 throws away the least significant bit, but if its a power of two it is spot on |
| 86 | + constexpr unsigned int BIT_REVERSE(unsigned int x) { |
| 87 | + return x == 1 ? 0 : 1 + BIT_REVERSE(x >> 1); |
| 88 | + } |
| 89 | +}; // namespace |
| 90 | + |
| 91 | +//using C enum (not enum class) on purpose |
| 92 | +enum JOYCON { |
| 93 | + |
| 94 | + // see /opt/devkitpro/libctru/include/3ds/services/hid.h |
| 95 | + |
| 96 | + JOYCON_A = BIT_REVERSE(KEY_A), ///< A |
| 97 | + JOYCON_B = BIT_REVERSE(KEY_B), ///< B |
| 98 | + |
| 99 | + JOYCON_SELECT = BIT_REVERSE(KEY_SELECT), ///< Select |
| 100 | + JOYCON_START = BIT_REVERSE(KEY_START), ///< Start |
| 101 | + |
| 102 | + JOYCON_DPAD_RIGHT = BIT_REVERSE(KEY_DRIGHT), ///< D-Pad Right |
| 103 | + JOYCON_DPAD_LEFT = BIT_REVERSE(KEY_DLEFT), ///< D-Pad Left |
| 104 | + JOYCON_DPAD_UP = BIT_REVERSE(KEY_DUP), ///< D-Pad Up |
| 105 | + JOYCON_DPAD_DOWN = BIT_REVERSE(KEY_DDOWN), ///< D-Pad Down |
| 106 | + |
| 107 | + JOYCON_R = BIT_REVERSE(KEY_R), ///< R |
| 108 | + JOYCON_L = BIT_REVERSE(KEY_L), ///< L |
| 109 | + JOYCON_X = BIT_REVERSE(KEY_X), ///< X |
| 110 | + JOYCON_Y = BIT_REVERSE(KEY_Y), ///< Y |
| 111 | + |
| 112 | + JOYCON_ZL = BIT_REVERSE(KEY_ZL), ///< ZL (New 3DS only) |
| 113 | + JOYCON_ZR = BIT_REVERSE(KEY_ZR), ///< ZR (New 3DS only) |
| 114 | + |
| 115 | + // has to be handled separately, but MIGHT be used in some form by SDL2 |
| 116 | + JOYCON_TOUCH = BIT_REVERSE(KEY_TOUCH), ///< Touch (Not actually provided by HID) |
| 117 | + |
| 118 | + JOYCON_CSTICK_RIGHT = BIT_REVERSE(KEY_CSTICK_RIGHT), ///< C-Stick Right (New 3DS only) |
| 119 | + JOYCON_CSTICK_LEFT = BIT_REVERSE(KEY_CSTICK_LEFT), ///< C-Stick Left (New 3DS only) |
| 120 | + JOYCON_CSTICK_UP = BIT_REVERSE(KEY_CSTICK_UP), ///< C-Stick Up (New 3DS only) |
| 121 | + JOYCON_CSTICK_DOWN = BIT_REVERSE(KEY_CSTICK_DOWN), ///< C-Stick Down (New 3DS only) |
| 122 | + |
| 123 | + JOYCON_CPAD_RIGHT = BIT_REVERSE(KEY_CPAD_RIGHT), ///< Circle Pad Right |
| 124 | + JOYCON_CPAD_LEFT = BIT_REVERSE(KEY_CPAD_LEFT), ///< Circle Pad Left |
| 125 | + JOYCON_CPAD_UP = BIT_REVERSE(KEY_CPAD_UP), ///< Circle Pad Up |
| 126 | + JOYCON_CPAD_DOWN = BIT_REVERSE(KEY_CPAD_DOWN), ///< Circle Pad Down |
| 127 | + |
| 128 | +}; |
| 129 | + |
| 130 | +// some static asserts to check if BIT_REVERSE works as expected |
| 131 | +static_assert(BIT(JOYCON_B) == KEY_B); |
| 132 | +static_assert(BIT(JOYCON_SELECT) == KEY_SELECT); |
| 133 | + |
51 | 134 |
|
52 | 135 | #endif |
53 | 136 |
|
54 | | -//TODO: implement for 3ds |
55 | 137 |
|
56 | 138 | #endif |
0 commit comments