diff --git a/Core/Debugger/WebSocket/InputSubscriber.cpp b/Core/Debugger/WebSocket/InputSubscriber.cpp index 49db4758ca..3b2f5c5733 100644 --- a/Core/Debugger/WebSocket/InputSubscriber.cpp +++ b/Core/Debugger/WebSocket/InputSubscriber.cpp @@ -155,12 +155,7 @@ void WebSocketInputState::ButtonsSend(DebuggerRequest &req) { } } - if (downFlags) { - __CtrlButtonDown(downFlags); - } - if (upFlags) { - __CtrlButtonUp(upFlags); - } + __CtrlUpdateButtons(downFlags, upFlags); req.Respond(); } @@ -193,7 +188,7 @@ void WebSocketInputState::ButtonsPress(DebuggerRequest &req) { press.button = info->second; // TODO: Route into the control mapper's PSPKey function instead. - __CtrlButtonDown(press.button); + __CtrlUpdateButtons(press.button, 0); pressTickets_.push_back(press); } @@ -207,7 +202,7 @@ void WebSocketInputState::Broadcast(net::WebSocketServer *ws) { press.duration--; if (press.duration == -1) { // TODO: Route into the control mapper's PSPKey function instead. - __CtrlButtonUp(press.button); + __CtrlUpdateButtons(0, press.button); ws->Send(press.Event()); } } diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 6e8e160da5..e2d60a723c 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -189,22 +189,7 @@ u32 __CtrlReadLatch() return ret; } -// Functions so that the rest of the emulator can control what the sceCtrl interface should return -// to the game: - -void __CtrlButtonDown(u32 buttonBit) -{ - std::lock_guard guard(ctrlMutex); - ctrlCurrent.buttons |= buttonBit; -} - -void __CtrlButtonUp(u32 buttonBit) -{ - std::lock_guard guard(ctrlMutex); - ctrlCurrent.buttons &= ~buttonBit; -} - -void __CtrlSetAllButtons(u32 bitsToSet, u32 bitsToClear) +void __CtrlUpdateButtons(u32 bitsToSet, u32 bitsToClear) { std::lock_guard guard(ctrlMutex); ctrlCurrent.buttons &= ~(bitsToClear & CTRL_MASK_USER); diff --git a/Core/HLE/sceCtrl.h b/Core/HLE/sceCtrl.h index c163f21744..02feaceb43 100644 --- a/Core/HLE/sceCtrl.h +++ b/Core/HLE/sceCtrl.h @@ -64,15 +64,8 @@ void __CtrlInit(); void __CtrlDoState(PointerWrap &p); void __CtrlShutdown(); -// Call this whenever a button is pressed, using the above CTRL_ constants. -// Multiple buttons may be sent in one call OR'd together. -// Resending a currently pressed button is fine but not required. -void __CtrlButtonDown(u32 buttonBit); -// Call this whenever a button is released. Similar to __CtrlButtonDown(). -void __CtrlButtonUp(u32 buttonBit); -// Sets the full state. Used by the new control mapper. The above two functions -// should go away over time. -void __CtrlSetAllButtons(u32 bitsToSet, u32 bitsToClear); +// Clears and sets selected buttons. NOTE: Clearing happens first. +void __CtrlUpdateButtons(u32 bitsToSet, u32 bitsToClear); // Call this to set the position of an analog stick, ideally when it changes. // X and Y values should be from -1 to 1, inclusive, in a square (no need to force to a circle.) diff --git a/Core/TiltEventProcessor.cpp b/Core/TiltEventProcessor.cpp index 716fee429e..f505f23397 100644 --- a/Core/TiltEventProcessor.cpp +++ b/Core/TiltEventProcessor.cpp @@ -139,12 +139,12 @@ void GenerateDPadEvent(int digitalX, int digitalY) { static const int dir[4] = { CTRL_RIGHT, CTRL_DOWN, CTRL_LEFT, CTRL_UP }; if (digitalX == 0) { - __CtrlButtonUp(tiltButtonsDown & (CTRL_RIGHT | CTRL_LEFT)); + __CtrlUpdateButtons(tiltButtonsDown & (CTRL_RIGHT | CTRL_LEFT), 0); tiltButtonsDown &= ~(CTRL_LEFT | CTRL_RIGHT); } if (digitalY == 0) { - __CtrlButtonUp(tiltButtonsDown & (CTRL_UP | CTRL_DOWN)); + __CtrlUpdateButtons(0, tiltButtonsDown & (CTRL_UP | CTRL_DOWN)); tiltButtonsDown &= ~(CTRL_UP | CTRL_DOWN); } @@ -159,7 +159,7 @@ void GenerateDPadEvent(int digitalX, int digitalY) { if (digitalY == 1) ctrlMask |= CTRL_UP; ctrlMask &= ~__CtrlPeekButtons(); - __CtrlButtonDown(ctrlMask); + __CtrlUpdateButtons(ctrlMask, 0); tiltButtonsDown |= ctrlMask; } @@ -167,12 +167,12 @@ void GenerateActionButtonEvent(int digitalX, int digitalY) { static const int buttons[4] = { CTRL_CIRCLE, CTRL_CROSS, CTRL_SQUARE, CTRL_TRIANGLE }; if (digitalX == 0) { - __CtrlButtonUp(tiltButtonsDown & (CTRL_SQUARE | CTRL_CIRCLE)); + __CtrlUpdateButtons(0, tiltButtonsDown & (CTRL_SQUARE | CTRL_CIRCLE)); tiltButtonsDown &= ~(CTRL_SQUARE | CTRL_CIRCLE); } if (digitalY == 0) { - __CtrlButtonUp(tiltButtonsDown & (CTRL_TRIANGLE | CTRL_CROSS)); + __CtrlUpdateButtons(0, tiltButtonsDown & (CTRL_TRIANGLE | CTRL_CROSS)); tiltButtonsDown &= ~(CTRL_TRIANGLE | CTRL_CROSS); } @@ -187,7 +187,7 @@ void GenerateActionButtonEvent(int digitalX, int digitalY) { if (digitalY == 1) ctrlMask |= CTRL_TRIANGLE; ctrlMask &= ~__CtrlPeekButtons(); - __CtrlButtonDown(ctrlMask); + __CtrlUpdateButtons(ctrlMask, 0); tiltButtonsDown |= ctrlMask; } @@ -208,14 +208,13 @@ void GenerateTriggerButtonEvent(int digitalX, int digitalY) { } downButtons &= ~__CtrlPeekButtons(); - __CtrlButtonUp(tiltButtonsDown & upButtons); - __CtrlButtonDown(downButtons); + __CtrlUpdateButtons(downButtons, tiltButtonsDown & upButtons); tiltButtonsDown = (tiltButtonsDown & ~upButtons) | downButtons; } void ResetTiltEvents() { // Reset the buttons we have marked pressed. - __CtrlButtonUp(tiltButtonsDown); + __CtrlUpdateButtons(0, tiltButtonsDown); tiltButtonsDown = 0; __CtrlSetAnalogXY(CTRL_STICK_LEFT, 0.0f, 0.0f); } diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 96590a75e5..b3da268c81 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -179,13 +179,13 @@ EmuScreen::EmuScreen(const Path &filename) std::bind(&EmuScreen::onVKey, this, _1, _2), std::bind(&EmuScreen::onVKeyAnalog, this, _1, _2), [](uint32_t bitsToSet, uint32_t bitsToClear) { - __CtrlSetAllButtons(bitsToSet, bitsToClear); + __CtrlUpdateButtons(bitsToSet, bitsToClear); }, [](int pspButton, bool down) { if (down) { - __CtrlButtonDown(pspButton); + __CtrlUpdateButtons(pspButton, 0); } else { - __CtrlButtonUp(pspButton); + __CtrlUpdateButtons(0, pspButton); } }, &SetPSPAnalog, diff --git a/UI/GamepadEmu.cpp b/UI/GamepadEmu.cpp index 4e6e45e561..b26e00400b 100644 --- a/UI/GamepadEmu.cpp +++ b/UI/GamepadEmu.cpp @@ -182,9 +182,9 @@ bool PSPButton::Touch(const TouchInput &input) { if (g_Config.bHapticFeedback) { System_Vibrate(HAPTIC_VIRTUAL_KEY); } - __CtrlButtonDown(pspButtonBit_); + __CtrlUpdateButtons(pspButtonBit_, 0); } else if (lastDown && !down) { - __CtrlButtonUp(pspButtonBit_); + __CtrlUpdateButtons(0, pspButtonBit_); } return retval; } @@ -361,10 +361,10 @@ void PSPDpad::ProcessTouch(float x, float y, bool down) { if (g_Config.bHapticFeedback) { System_Vibrate(HAPTIC_VIRTUAL_KEY); } - __CtrlButtonDown(dir[i]); + __CtrlUpdateButtons(dir[i], 0); } if (released & dir[i]) { - __CtrlButtonUp(dir[i]); + __CtrlUpdateButtons(0, dir[i]); } } } @@ -652,10 +652,9 @@ void PSPCustomStick::ProcessTouch(float x, float y, bool down) { posY_ = 0.0f; } - if (release != 0) - __CtrlButtonUp(release); - if (press != 0) - __CtrlButtonDown(press); + if (release || press) { + __CtrlUpdateButtons(press, release); + } } void InitPadLayout(float xres, float yres, float globalScale) { diff --git a/pspautotests b/pspautotests index 4606502750..2e02c4a7c0 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit 46065027500cd781ce7c15c051c8b0c4751ad1fa +Subproject commit 2e02c4a7c075f1a7cf28ec1add000ecd7077cd09