Add back RemapControllerButtons and SwapButtons - needed by some VS games

This commit is contained in:
LibretroAdmin 2022-08-12 19:47:43 +02:00
parent a03ff76e33
commit 4026a25a99
6 changed files with 63 additions and 0 deletions

View File

@ -256,3 +256,17 @@ MouseMovement BaseControlDevice::GetMovement()
SetCoordinates({ 0, 0 });
return { pos.X, pos.Y };
}
void BaseControlDevice::SwapButtons(shared_ptr<BaseControlDevice> state1, uint8_t button1, shared_ptr<BaseControlDevice> state2, uint8_t button2)
{
bool pressed1 = state1->IsPressed(button1);
bool pressed2 = state2->IsPressed(button2);
state1->ClearBit(button1);
state2->ClearBit(button2);
if(pressed1)
state2->SetBit(button2);
if(pressed2)
state1->SetBit(button1);
}

View File

@ -78,4 +78,6 @@ public:
virtual uint8_t ReadRAM(uint16_t addr) = 0;
virtual void WriteRAM(uint16_t addr, uint8_t value) = 0;
void static SwapButtons(std::shared_ptr<BaseControlDevice> state1, uint8_t button1, std::shared_ptr<BaseControlDevice> state2, uint8_t button2);
};

View File

@ -229,6 +229,11 @@ uint8_t ControlManager::GetOpenBusMask(uint8_t port)
}
}
void ControlManager::RemapControllerButtons()
{
//Used by VS System games
}
void ControlManager::UpdateInputState()
{
if(_isLagging)
@ -256,6 +261,9 @@ void ControlManager::UpdateInputState()
device->OnAfterSetState();
}
//Used by VS System games
RemapControllerButtons();
_pollCounter++;
}

View File

@ -38,6 +38,7 @@ protected:
virtual void StreamState(bool saving) override;
virtual ControllerType GetControllerType(uint8_t port);
virtual void RemapControllerButtons();
virtual uint8_t GetOpenBusMask(uint8_t port);
public:

View File

@ -52,6 +52,43 @@ uint8_t VsControlManager::GetPrgChrSelectBit()
return _prgChrSelectBit;
}
void VsControlManager::RemapControllerButtons()
{
std::shared_ptr<StandardController> controllers[2];
controllers[0] = std::dynamic_pointer_cast<StandardController>(GetControlDevice(0));
controllers[1] = std::dynamic_pointer_cast<StandardController>(GetControlDevice(1));
if(!controllers[0] || !controllers[1]) {
return;
}
GameInputType inputType = _console->GetRomInfo().InputType;
if(inputType == GameInputType::VsSystemSwapped) {
//Swap controllers 1 & 2
ControlDeviceState port1State = controllers[0]->GetRawState();
ControlDeviceState port2State = controllers[1]->GetRawState();
controllers[0]->SetRawState(port2State);
controllers[1]->SetRawState(port1State);
//But don't swap the start/select buttons
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Start, controllers[1], StandardController::Buttons::Start);
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Select, controllers[1], StandardController::Buttons::Select);
} else if(inputType == GameInputType::VsSystemSwapAB) {
//Swap buttons P1 A & P2 B (Pinball (Japan))
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::B, controllers[1], StandardController::Buttons::A);
}
//Swap Start/Select for all configurations (makes it more intuitive)
BaseControlDevice::SwapButtons(controllers[0], StandardController::Buttons::Start, controllers[0], StandardController::Buttons::Select);
BaseControlDevice::SwapButtons(controllers[1], StandardController::Buttons::Start, controllers[1], StandardController::Buttons::Select);
if(_vsSystemType == VsSystemType::RaidOnBungelingBayProtection || _vsSystemType == VsSystemType::IceClimberProtection) {
//Bit 3 of the input status must always be on
controllers[0]->SetBit(StandardController::Buttons::Start);
controllers[1]->SetBit(StandardController::Buttons::Start);
}
}
uint8_t VsControlManager::GetOpenBusMask(uint8_t port)
{
return 0x00;

View File

@ -44,6 +44,7 @@ private:
protected:
ControllerType GetControllerType(uint8_t port) override;
void RemapControllerButtons() override;
uint8_t GetOpenBusMask(uint8_t port) override;
void UpdateSlaveMasterBit(uint8_t slaveMasterBit);