Fix bitwise operation for button state check

Classic buttons are shifted up by kHighestWiimote (20) before being stored, so they occupy bits 21–35 of the uint64 buttons variable. When the loop checks those bits with (1 << i), 1 is a plain 32-bit int. Shifting it by 32 or more is undefined behaviour — in practice on x86 it wraps modulo 32, so on x86

A (bit 32) → mask becomes 1 << 0 → becomes X
B (bit 34) → mask becomes 1 << 2 → X
Y (bit 33) → mask becomes 1 << 1 → X
ZL (bit 35) → mask becomes 1 << 3 → also X
X (bit 31) → mask is 1 << 31 → still within 32 bits → expectedly, X.

change to 1ULL so it all works properly
This commit is contained in:
Squall Leonhart 2026-03-28 16:41:45 +11:00 committed by GitHub
parent 6648a9c225
commit 77d5e09576
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -232,7 +232,7 @@ ControllerState NativeWiimoteController::raw_state()
for (int i = 0; i < std::numeric_limits<uint64>::digits; i++)
{
// OR with base buttons
if((buttons & (1 << i)))
if((buttons & (1ULL << i)))
result.buttons.SetButtonState(i, true);
}
result.axis = classic.left_axis;