Skip to content

Commit

Permalink
Merge pull request #298 from sere3925sere/getcontrollerstate3
Browse files Browse the repository at this point in the history
Implement th06::Controller::GetControllerState, take 3
  • Loading branch information
roblabla authored Nov 2, 2024
2 parents 65ba90d + 09e813c commit 2e4139c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/globals.csv
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ _g_NumOfFramesInputsWereHeld, 0x0069d910
_g_LastFileSize, 0x0069d914
_g_Chain, 0x0069d918
_g_GameErrorContext, 0x0069d998
_g_ControllerData, 0x0069e1af
_g_TextBufferSurface, 0x0069e230
_g_ItemManager, 0x0069e268
_g_GameWindow, 0x006c6bd4
Expand Down
1 change: 1 addition & 0 deletions config/implemented.csv
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ th06::Supervisor::PlayAudio
th06::Supervisor::StopAudio
th06::Supervisor::SetupMidiPlayback
th06::Supervisor::FadeOutMusic
th06::Controller::GetControllerState
th06::GameWindow::InitD3dDevice
th06::GameWindow::InitD3dRendering
th06::ScreenEffect::Clear
Expand Down
1 change: 0 additions & 1 deletion config/stubbed.csv
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ th06::ReplayManager::StopRecording
th06::ReplayManager::SaveReplay
th06::ReplayManager::ValidateReplayData
th06::ScreenEffect::DrawSquare
th06::Controller::GetControllerState
th06::Pbg3Archive::Pbg3Archive
67 changes: 67 additions & 0 deletions src/Supervisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,4 +1221,71 @@ ZunResult Supervisor::FadeOutMusic(f32 fadeOutSeconds)
return ZUN_SUCCESS;
}
#pragma optimize("", on)

DIFFABLE_STATIC_ARRAY(u8, (32 * 4), g_ControllerData)

#pragma optimize("", on)
#pragma var_order(joyinfoex, joyButtonBit, joyButtonIndex, dires, dijoystate2, diRetryCount)
// This is for rebinding keys
u8 *th06::Controller::GetControllerState()
{
JOYINFOEX joyinfoex;
u32 joyButtonBit;
u32 joyButtonIndex;

i32 dires;
DIJOYSTATE2 dijoystate2;
i32 diRetryCount;

memset(&g_ControllerData, 0, sizeof(g_ControllerData));
if (g_Supervisor.controller == NULL)
{
memset(&joyinfoex, 0, sizeof(JOYINFOEX));
joyinfoex.dwSize = sizeof(JOYINFOEX);
joyinfoex.dwFlags = JOY_RETURNALL;
if (joyGetPosEx(0, &joyinfoex) != JOYERR_NOERROR)
{
return g_ControllerData;
}
for (joyButtonBit = joyinfoex.dwButtons, joyButtonIndex = 0; joyButtonIndex < 32;
joyButtonIndex += 1, joyButtonBit >>= 1)
{
if ((joyButtonBit & 1) != 0)
{
g_ControllerData[joyButtonIndex] = 0x80;
}
}
return g_ControllerData;
}
else
{
dires = g_Supervisor.controller->Poll();
if (FAILED(dires))
{
diRetryCount = 0;
utils::DebugPrint2("error : DIERR_INPUTLOST\n");
dires = g_Supervisor.controller->Acquire();
while (dires == DIERR_INPUTLOST)
{
dires = g_Supervisor.controller->Acquire();
utils::DebugPrint2("error : DIERR_INPUTLOST %d\n", diRetryCount);
diRetryCount++;
if (diRetryCount >= 400)
{
return g_ControllerData;
}
}
return g_ControllerData;
}
/* dires = */ g_Supervisor.controller->GetDeviceState(sizeof(DIJOYSTATE2), &dijoystate2);
// TODO: seems ZUN forgot "dires =" above
if (FAILED(dires))
{
return g_ControllerData;
}
memcpy(&g_ControllerData, dijoystate2.rgbButtons, sizeof(dijoystate2.rgbButtons));
return g_ControllerData;
}
}
#pragma optimize("", on)
}; // namespace th06

0 comments on commit 2e4139c

Please sign in to comment.