Skip to content

Commit

Permalink
Fix 4-way mode when enabled for both core gamepad and DDI (#733)
Browse files Browse the repository at this point in the history
Prepare another 4way function for DDI

Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
Co-authored-by: sirrow <sirrow@gmail.com>
  • Loading branch information
bsstephan and sirrow committed Dec 29, 2023
1 parent aa2595a commit 94a9803
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions headers/addons/dualdirectional.h
Expand Up @@ -56,6 +56,8 @@ class DualDirectionalInput : public GPAddon {
private:
void debounce();
uint8_t gpadToBinary(DpadMode, GamepadState);
uint8_t updateDpadDDI(uint8_t dpad, DpadDirection direction);
uint8_t filterToFourWayModeDDI(uint8_t dpad);
void SOCDDualClean(SOCDMode);
uint8_t SOCDCombine(SOCDMode, uint8_t);
uint8_t SOCDGamepadClean(uint8_t, bool isLastWin);
Expand Down
50 changes: 49 additions & 1 deletion src/addons/dualdirectional.cpp
Expand Up @@ -71,6 +71,54 @@ void DualDirectionalInput::debounce()
}
}


uint8_t DualDirectionalInput::updateDpadDDI(uint8_t dpad, DpadDirection direction)
{
static bool inList[] = {false, false, false, false, false}; // correspond to DpadDirection: none, up, down, left, right
static list<DpadDirection> dpadList;

if(dpad & getMaskFromDirection(direction))
{
if(!inList[direction])
{
dpadList.push_back(direction);
inList[direction] = true;
}
}
else
{
if(inList[direction])
{
dpadList.remove(direction);
inList[direction] = false;
}
}

if(dpadList.empty()) {
return 0;
}
else {
return getMaskFromDirection(dpadList.back());
}
}

/**
* @brief Filter diagonals out of the dpad, making the device work as a 4-way lever.
*
* The most recent cardinal direction wins.
*
* @param dpad The GameState.dpad value.
* @return uint8_t The new dpad value.
*/
uint8_t DualDirectionalInput::filterToFourWayModeDDI(uint8_t dpad)
{
updateDpadDDI(dpad, DIRECTION_UP);
updateDpadDDI(dpad, DIRECTION_DOWN);
updateDpadDDI(dpad, DIRECTION_LEFT);
return updateDpadDDI(dpad, DIRECTION_RIGHT);
}


void DualDirectionalInput::preprocess()
{
const DualDirectionalOptions& options = Storage::getInstance().getAddonOptions().dualDirectionalOptions;
Expand All @@ -92,7 +140,7 @@ void DualDirectionalInput::preprocess()

// 4-way before SOCD, might have better history without losing any coherent functionality
if (options.fourWayMode) {
dualState = filterToFourWayMode(dualState);
dualState = filterToFourWayModeDDI(dualState);
}

// Combined Mode
Expand Down

0 comments on commit 94a9803

Please sign in to comment.