| 54 | #include "YamlHelper.h" |
| 55 | |
| 56 | BYTE __stdcall FourPlayCard::IORead(WORD pc, WORD addr, BYTE bWrite, BYTE value, ULONG nExecutedCycles) |
| 57 | { |
| 58 | BYTE nOutput = MemReadFloatingBus(nExecutedCycles); |
| 59 | BOOL up = 0; |
| 60 | BOOL down = 0; |
| 61 | BOOL left = 0; |
| 62 | BOOL right = 0; |
| 63 | BOOL trigger1 = 0; |
| 64 | BOOL trigger2 = 0; |
| 65 | BOOL trigger3 = 0; |
| 66 | BOOL alwaysHigh = 1; |
| 67 | UINT xAxis = 0; |
| 68 | UINT yAxis = 0; |
| 69 | |
| 70 | JOYINFOEX infoEx; |
| 71 | infoEx.dwSize = sizeof(infoEx); |
| 72 | infoEx.dwFlags = JOY_RETURNPOV | JOY_RETURNBUTTONS; |
| 73 | |
| 74 | switch (addr & 0xF) |
| 75 | { |
| 76 | case 0: // Joystick 1 |
| 77 | if (GetJoystick1() >= 0 && joyGetPosEx(GetJoystick1(), &infoEx) == JOYERR_NOERROR) |
| 78 | { |
| 79 | xAxis = (infoEx.dwXpos >> 8) & 0xFF; |
| 80 | yAxis = (infoEx.dwYpos >> 8) & 0xFF; |
| 81 | trigger1 = infoEx.dwButtons & 0x01; |
| 82 | trigger2 = (infoEx.dwButtons & 0x02) >> 1; |
| 83 | up = yAxis < 103 || infoEx.dwPOV == 0 || infoEx.dwPOV == 4500 || infoEx.dwPOV == 31500; |
| 84 | down = yAxis > 153 || (infoEx.dwPOV >= 13500 && infoEx.dwPOV <= 22500); |
| 85 | left = xAxis < 103 || (infoEx.dwPOV >= 22500 && infoEx.dwPOV <= 31500); |
| 86 | right = xAxis > 153 || (infoEx.dwPOV >= 4500 && infoEx.dwPOV <= 13500); |
| 87 | } |
| 88 | nOutput = up | (down << 1) | (left << 2) | (right << 3) | (alwaysHigh << 5) | (trigger2 << 6) | (trigger1 << 7); |
| 89 | break; |
| 90 | case 1: // Joystick 2 |
| 91 | if (GetJoystick2() >= 0 && joyGetPosEx(GetJoystick2(), &infoEx) == JOYERR_NOERROR) |
| 92 | { |
| 93 | xAxis = (infoEx.dwXpos >> 8) & 0xFF; |
| 94 | yAxis = (infoEx.dwYpos >> 8) & 0xFF; |
| 95 | trigger1 = infoEx.dwButtons & 0x01; |
| 96 | trigger2 = (infoEx.dwButtons & 0x02) >> 1; |
| 97 | up = yAxis < 103 || infoEx.dwPOV == 0 || infoEx.dwPOV == 4500 || infoEx.dwPOV == 31500; |
| 98 | down = yAxis > 153 || (infoEx.dwPOV >= 13500 && infoEx.dwPOV <= 22500); |
| 99 | left = xAxis < 103 || (infoEx.dwPOV >= 22500 && infoEx.dwPOV <= 31500); |
| 100 | right = xAxis > 153 || (infoEx.dwPOV >= 4500 && infoEx.dwPOV <= 13500); |
| 101 | } |
| 102 | nOutput = up | (down << 1) | (left << 2) | (right << 3) | (alwaysHigh << 5) | (trigger2 << 6) | (trigger1 << 7); |
| 103 | break; |
| 104 | case 2: // Joystick 3 |
| 105 | nOutput = FourPlayCard::JOYSTICKSTATIONARY; // esdf - direction buttons, zx - trigger buttons |
| 106 | nOutput = nOutput | (MyGetAsyncKeyState('E') | (MyGetAsyncKeyState('D') << 1) | (MyGetAsyncKeyState('S') << 2) | (MyGetAsyncKeyState('F') << 3) | (MyGetAsyncKeyState('X') << 6) | (MyGetAsyncKeyState('Z') << 7)); |
| 107 | break; |
| 108 | case 3: // Joystick 4 |
| 109 | nOutput = FourPlayCard::JOYSTICKSTATIONARY; // ijkl - direction buttons, nm - trigger buttons |
| 110 | nOutput = nOutput | (MyGetAsyncKeyState('I') | (MyGetAsyncKeyState('K') << 1) | (MyGetAsyncKeyState('J') << 2) | (MyGetAsyncKeyState('L') << 3) | (MyGetAsyncKeyState('M') << 6) | (MyGetAsyncKeyState('N') << 7)); |
| 111 | break; |
| 112 | default: |
| 113 | break; |
nothing calls this directly
no test coverage detected