Skip to content

Commit

Permalink
Make Sys147 button setup changeable through arcadedefs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed May 17, 2024
1 parent e937f36 commit 0efd17e
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 65 deletions.
90 changes: 30 additions & 60 deletions Source/iop/namco_sys147/Iop_NamcoSys147.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@ using namespace Iop::Namco;

#define LOG_NAME ("iop_namco_sys147")

enum
{
SWITCH_TEST = 0x6C,
SWITCH_ENTER = 0x6D,
SWITCH_UP = 0x6E,
SWITCH_DOWN = 0x6F,
SWITCH_SERVICE = 0x72,
SWITCH_1P_LEFT = 0x74,
SWITCH_1P_RIGHT = 0x75,
SWITCH_2P_LEFT = 0x77,
SWITCH_2P_RIGHT = 0x76

};
//Switch IDs for games
//--------------------

//Animal Kaiser
//-------------
// 108 - Test
// 109 - Enter
// 110 - Up
// 111 - Down
// 114 - Service
// 116 - 1P Left
// 117 - 1P Right
// 118 - 2P Right
// 119 - 2P Left

//Pac-Man Arcade Party
//--------------------
// Note: Game seems to be reading from SIO2
// 84 - Test
// 86 - Up
// 87 - Down
// 88 - Enter

CSys147::CSys147(CSifMan& sifMan, const std::string& gameId)
: m_gameId(gameId)
Expand Down Expand Up @@ -51,15 +60,6 @@ CSys147::CSys147(CSifMan& sifMan, const std::string& gameId)
sifMan.RegisterModule(MODULE_ID_201, &m_module201);
sifMan.RegisterModule(MODULE_ID_99, &m_module99);

m_switchStates[SWITCH_TEST] = 0;
m_switchStates[SWITCH_ENTER] = 0;
m_switchStates[SWITCH_UP] = 0;
m_switchStates[SWITCH_DOWN] = 0;
m_switchStates[SWITCH_1P_LEFT] = 0;
m_switchStates[SWITCH_1P_RIGHT] = 0;
m_switchStates[SWITCH_2P_LEFT] = 0;
m_switchStates[SWITCH_2P_RIGHT] = 0;

if(CAppConfig::GetInstance().GetPreferenceBoolean(PREF_PS2_ARCADE_IO_SERVER_ENABLED))
{
fs::path logPath = CAppConfig::GetInstance().GetBasePath() / "arcade_io_server.log";
Expand All @@ -78,47 +78,17 @@ std::string CSys147::GetFunctionName(unsigned int functionId) const
return "unknown";
}

void CSys147::SetButton(unsigned int switchIndex, unsigned int padNumber, PS2::CControllerInfo::BUTTON button)
{
m_switchBindings[{padNumber, button}] = switchIndex;
}

void CSys147::SetButtonState(unsigned int padNumber, PS2::CControllerInfo::BUTTON button, bool pressed, uint8* ram)
{
if(padNumber == 0)
const auto& binding = m_switchBindings.find({padNumber, button});
if(binding != std::end(m_switchBindings))
{
switch(button)
{
case PS2::CControllerInfo::DPAD_UP:
m_switchStates[SWITCH_UP] = pressed ? 0xFF : 0x00;
break;
case PS2::CControllerInfo::DPAD_DOWN:
m_switchStates[SWITCH_DOWN] = pressed ? 0xFF : 0x00;
break;
case PS2::CControllerInfo::DPAD_LEFT:
m_switchStates[SWITCH_1P_LEFT] = pressed ? 0xFF : 0x00;
break;
case PS2::CControllerInfo::DPAD_RIGHT:
m_switchStates[SWITCH_1P_RIGHT] = pressed ? 0xFF : 0x00;
break;
case PS2::CControllerInfo::CROSS:
m_switchStates[SWITCH_ENTER] = pressed ? 0xFF : 0x00;
break;
case PS2::CControllerInfo::L1:
m_switchStates[SWITCH_TEST] = pressed ? 0xFF : 0x00;
break;
default:
break;
}
}
else if(padNumber == 1)
{
switch(button)
{
case PS2::CControllerInfo::DPAD_LEFT:
m_switchStates[SWITCH_2P_LEFT] = pressed ? 0xFF : 0x00;
break;
case PS2::CControllerInfo::DPAD_RIGHT:
m_switchStates[SWITCH_2P_RIGHT] = pressed ? 0xFF : 0x00;
break;
default:
break;
}
m_switchStates[binding->second] = pressed ? 0xFF : 0x00;
}
}

Expand Down
5 changes: 5 additions & 0 deletions Source/iop/namco_sys147/Iop_NamcoSys147.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ namespace Iop
std::string GetFunctionName(unsigned int) const override;
void Invoke(CMIPS&, unsigned int) override;

void SetButton(unsigned int, unsigned int, PS2::CControllerInfo::BUTTON);

//CPadInterface
void SetButtonState(unsigned int, PS2::CControllerInfo::BUTTON, bool, uint8*) override;
void SetAxisState(unsigned int, PS2::CControllerInfo::BUTTON, uint8, uint8*) override;
void GetVibration(unsigned int, uint8&, uint8&) override{};

private:
using ButtonSelector = std::pair<int, PS2::CControllerInfo::BUTTON>;

enum MODULE_ID
{
MODULE_ID_000 = 0x01470000,
Expand Down Expand Up @@ -74,6 +78,7 @@ namespace Iop
CSifModuleAdapter m_module99;

std::string m_gameId;
std::map<ButtonSelector, uint8> m_switchBindings;

std::vector<MODULE_99_PACKET> m_pendingReplies;
std::map<uint8, uint8> m_switchStates;
Expand Down
4 changes: 3 additions & 1 deletion Source/ui_shared/ArcadeDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct ARCADE_MACHINE_DEF
uint32 value = 0;
};

using ButtonSelector = std::pair<int, PS2::CControllerInfo::BUTTON>;

std::string id;
std::string parent;
DRIVER driver = DRIVER::UNKNOWN;
Expand All @@ -39,7 +41,7 @@ struct ARCADE_MACHINE_DEF
std::string hddFileName;
std::string nandFileName;
std::map<std::string, uint32> nandMounts;
std::map<unsigned int, PS2::CControllerInfo::BUTTON> buttons;
std::map<unsigned int, ButtonSelector> buttons;
INPUT_MODE inputMode = INPUT_MODE::DEFAULT;
std::array<float, 4> screenPosXform = {65535, 0, 65535, 0};
uint32 eeFreqScaleNumerator = 1;
Expand Down
21 changes: 19 additions & 2 deletions Source/ui_shared/ArcadeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,26 @@ ARCADE_MACHINE_DEF ReadArcadeMachineDefinition(const fs::path& arcadeDefPath)
{
char* endPtr = nullptr;
const char* buttonNumber = buttonPair.first.c_str();
const char* buttonName = buttonPair.second.c_str();
const char* buttonSelector = buttonPair.second.c_str();
int number = strtol(buttonPair.first.c_str(), &endPtr, 10);
if(endPtr == buttonPair.first.c_str())
{
throw std::runtime_error(string_format("Failed to parse button number '%s'.", buttonNumber));
}
buttons[number] = ParseEnumValue(buttonName, std::begin(g_buttonValues), std::end(g_buttonValues));
//Accepted formats for buttonSelector
//- ${buttonName}
//- ${padIdx}:${buttonName}
std::string buttonName = buttonSelector;
int padIdx = -1;
if(auto colonPos = buttonName.find(':'); colonPos != std::string::npos)
{
padIdx = strtol(buttonName.c_str(), &endPtr, 10);
assert(endPtr == (buttonName.c_str() + colonPos));
buttonName = buttonName.substr(colonPos + 1);
}
auto buttonId = ParseEnumValue(buttonName.c_str(), std::begin(g_buttonValues), std::end(g_buttonValues));
auto selector = ARCADE_MACHINE_DEF::ButtonSelector{padIdx, buttonId};
buttons[number] = selector;
}
return buttons;
};
Expand Down Expand Up @@ -208,6 +221,10 @@ void ApplyParentDefValues(ARCADE_MACHINE_DEF& def, const ARCADE_MACHINE_DEF& par
{
def.nandMounts = parentDef.nandMounts;
}
if(def.buttons.empty())
{
def.buttons = parentDef.buttons;
}
}

void ArcadeUtils::RegisterArcadeMachines()
Expand Down
4 changes: 4 additions & 0 deletions Source/ui_shared/arcadedrivers/NamcoSys147Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ void CNamcoSys147Driver::PrepareEnvironment(CPS2VM* virtualMachine, const ARCADE
iopBios->RegisterModule(sys147Module);
iopBios->RegisterHleModuleReplacement("S147LINK", sys147Module);
virtualMachine->m_pad->InsertListener(sys147Module.get());
for(const auto& button : def.buttons)
{
sys147Module->SetButton(button.first, button.second.first, button.second.second);
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions Source/ui_shared/arcadedrivers/NamcoSys246Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ void CNamcoSys246Driver::PrepareEnvironment(CPS2VM* virtualMachine, const ARCADE
iopBios->RegisterModule(namcoArcadeModule);
iopBios->RegisterHleModuleReplacement("rom0:DAEMON", namcoArcadeModule);
virtualMachine->m_pad->InsertListener(namcoArcadeModule.get());
for(const auto& buttonPair : def.buttons)
for(const auto& buttonDefPair : def.buttons)
{
namcoArcadeModule->SetButton(buttonPair.first, buttonPair.second);
const auto& buttonPair = buttonDefPair.second;
assert(buttonDefPair.first == -1);
namcoArcadeModule->SetButton(buttonDefPair.first, buttonPair.second);
}
switch(def.inputMode)
{
Expand Down
11 changes: 11 additions & 0 deletions arcadedefs/akaievo.arcadedef
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
"atfile6": 393216
}
},
"buttons":
{
"108": "0:l1",
"109": "0:cross",
"110": "0:dpad_up",
"111": "0:dpad_down",
"116": "0:dpad_left",
"117": "0:dpad_right",
"118": "1:dpad_right",
"119": "1:dpad_left"
},
"boot": "atfile0:main.elf",
"patches":
[
Expand Down
11 changes: 11 additions & 0 deletions arcadedefs/akaiser.arcadedef
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
"atfile6": 393216
}
},
"buttons":
{
"108": "0:l1",
"109": "0:cross",
"110": "0:dpad_up",
"111": "0:dpad_down",
"116": "0:dpad_left",
"117": "0:dpad_right",
"118": "1:dpad_right",
"119": "1:dpad_left"
},
"boot": "atfile0:main.elf",
"patches":
[
Expand Down
7 changes: 7 additions & 0 deletions arcadedefs/pacmanap.arcadedef
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"atfile1": 131072
}
},
"buttons":
{
"84": "0:l1",
"86": "0:dpad_up",
"87": "0:dpad_down",
"88": "0:cross"
},
"boot": "atfile0:PMAAC.elf",
"patches":
[
Expand Down

0 comments on commit 0efd17e

Please sign in to comment.