Input option to use PC Joystick 1 Thumbstick 2 for emulated Joystick 2 (#428)

* Input option to use PC Joystick 1 Thumbstick 2 for emulated Joystick 2
This commit is contained in:
Nick Westgate
2017-06-07 10:14:25 +12:00
committed by GitHub
parent 2dabab907b
commit 3a30a3ee4b
5 changed files with 73 additions and 13 deletions
+66 -9
View File
@@ -48,14 +48,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define BUTTONTIME 5000 // This is the latch (debounce) time in usecs for the joystick buttons
enum {DEVICE_NONE=0, DEVICE_JOYSTICK, DEVICE_KEYBOARD, DEVICE_MOUSE};
enum {DEVICE_NONE=0, DEVICE_JOYSTICK, DEVICE_KEYBOARD, DEVICE_MOUSE, DEVICE_JOYSTICK_THUMBSTICK2};
// Indexed by joytype[n]
static const DWORD joyinfo[5] = { DEVICE_NONE,
static const DWORD joyinfo[6] = { DEVICE_NONE,
DEVICE_JOYSTICK,
DEVICE_KEYBOARD, // Cursors (prev: Numpad-Standard)
DEVICE_KEYBOARD, // Numpad (prev: Numpad-Centering)
DEVICE_MOUSE };
DEVICE_MOUSE,
DEVICE_JOYSTICK_THUMBSTICK2 };
// Key pad [1..9]; Key pad 0,Key pad '.'; Left ALT,Right ALT
enum JOYKEY { JK_DOWNLEFT=0,
@@ -149,7 +150,24 @@ void CheckJoystick1()
{
lastcheck = currtime;
JOYINFO info;
if (joyGetPos(JOYSTICKID2,&info) == JOYERR_NOERROR)
MMRESULT result = 0;
if (joyinfo[joytype[1]] == DEVICE_JOYSTICK_THUMBSTICK2)
{
// Use results of joystick 1 thumbstick 2 and button 2 for joystick 1 and button 1
JOYINFOEX infoEx;
infoEx.dwSize = sizeof(infoEx);
infoEx.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNZ | JOY_RETURNR;
result = joyGetPosEx(JOYSTICKID1, &infoEx);
if (result == JOYERR_NOERROR)
{
info.wButtons = (infoEx.dwButtons & JOY_BUTTON2) ? JOY_BUTTON1 : 0;
info.wXpos = infoEx.dwZpos;
info.wYpos = infoEx.dwRpos;
}
}
else
result = joyGetPos(JOYSTICKID2, &info);
if (result == JOYERR_NOERROR)
{
if ((info.wButtons & JOY_BUTTON1) && !joybutton[2])
{
@@ -245,6 +263,33 @@ void JoyInitialize()
joytype[1] = J1C_DISABLED;
}
}
else if (joyinfo[joytype[1]] == DEVICE_JOYSTICK_THUMBSTICK2)
{
JOYCAPS caps;
if (joyGetDevCaps(JOYSTICKID1, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR)
{
joyshrx[1] = 0;
joyshry[1] = 0;
joysubx[1] = (int)caps.wZmin;
joysuby[1] = (int)caps.wRmin;
UINT xrange = caps.wZmax - caps.wZmin;
UINT yrange = caps.wRmax - caps.wRmin;
while (xrange > 256)
{
xrange >>= 1;
++joyshrx[1];
}
while (yrange > 256)
{
yrange >>= 1;
++joyshry[1];
}
}
else
{
joytype[1] = J1C_DISABLED;
}
}
}
//===========================================================================
@@ -493,7 +538,7 @@ BYTE __stdcall JoyReadButton(WORD pc, WORD address, BYTE, BYTE, ULONG nCyclesLef
if(joyinfo[joytype[0]] == DEVICE_JOYSTICK)
CheckJoystick0();
if(joyinfo[joytype[1]] == DEVICE_JOYSTICK)
if((joyinfo[joytype[1]] == DEVICE_JOYSTICK) || (joyinfo[joytype[1]] == DEVICE_JOYSTICK_THUMBSTICK2))
CheckJoystick1();
if (g_bJoyportEnabled)
@@ -593,7 +638,7 @@ BYTE __stdcall JoyResetPosition(WORD, WORD, BYTE, BYTE, ULONG nCyclesLeft)
if(joyinfo[joytype[0]] == DEVICE_JOYSTICK)
CheckJoystick0();
if(joyinfo[joytype[1]] == DEVICE_JOYSTICK)
if((joyinfo[joytype[1]] == DEVICE_JOYSTICK) || (joyinfo[joytype[1]] == DEVICE_JOYSTICK_THUMBSTICK2))
CheckJoystick1();
return MemReadFloatingBus(nCyclesLeft);
@@ -629,12 +674,13 @@ BOOL JoySetEmulationType(HWND window, DWORD newtype, int nJoystickNumber, const
if(joytype[nJoystickNumber] == newtype)
return 1; // Already set to this type. Return OK.
if (joyinfo[newtype] == DEVICE_JOYSTICK)
if (joyinfo[newtype] == DEVICE_JOYSTICK || joyinfo[newtype] == DEVICE_JOYSTICK_THUMBSTICK2)
{
JOYCAPS caps;
unsigned int nJoyID = nJoystickNumber == JN_JOYSTICK0 ? JOYSTICKID1 : JOYSTICKID2;
unsigned int nJoy2ID = joyinfo[newtype] == DEVICE_JOYSTICK_THUMBSTICK2 ? JOYSTICKID1 : JOYSTICKID2;
unsigned int nJoyID = nJoystickNumber == JN_JOYSTICK0 ? JOYSTICKID1 : nJoy2ID;
if (joyGetDevCaps(nJoyID, &caps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
{
{
MessageBox(window,
TEXT("The emulator is unable to read your PC joystick. ")
TEXT("Ensure that your game port is configured properly, ")
@@ -644,6 +690,17 @@ BOOL JoySetEmulationType(HWND window, DWORD newtype, int nJoystickNumber, const
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
return 0;
}
if ((joyinfo[newtype] == DEVICE_JOYSTICK_THUMBSTICK2) && (caps.wNumAxes < 4))
{
MessageBox(window,
TEXT("The emulator is unable to read thumbstick 2. ")
TEXT("Ensure that your game port is configured properly, ")
TEXT("that the joystick is firmly plugged in, and that ")
TEXT("you have a joystick driver installed."),
TEXT("Configuration"),
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
return 0;
}
}
else if ((joyinfo[newtype] == DEVICE_MOUSE) &&
(joyinfo[joytype[nJoystickNumber]] != DEVICE_MOUSE))