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

View File

@ -117,9 +117,9 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN BEGIN
GROUPBOX "Joystick Control",IDC_STATIC,5,7,200,101 GROUPBOX "Joystick Control",IDC_STATIC,5,7,200,101
LTEXT "Joystick &1:",IDC_STATIC,12,20,40,8 LTEXT "Joystick &1:",IDC_STATIC,12,20,40,8
COMBOBOX IDC_JOYSTICK0,52,18,100,100,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_JOYSTICK0,52,18,110,100,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Joystick &2:",IDC_STATIC,12,35,40,8 LTEXT "Joystick &2:",IDC_STATIC,12,35,40,8
COMBOBOX IDC_JOYSTICK1,52,33,100,100,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_JOYSTICK1,52,33,110,100,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "&X-trim:",IDC_STATIC,13,56,28,8 LTEXT "&X-trim:",IDC_STATIC,13,56,28,8
CTEXT "0",IDC_STATIC,36,50,24,20,SS_CENTERIMAGE CTEXT "0",IDC_STATIC,36,50,24,20,SS_CENTERIMAGE
CONTROL "Spin1",IDC_SPIN_XTRIM,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY,59,53,10,14 CONTROL "Spin1",IDC_SPIN_XTRIM,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY,59,53,10,14

View File

@ -40,6 +40,7 @@ const TCHAR CPageInput::m_szJoyChoice2[] = TEXT("PC Joystick #2\0");
const TCHAR CPageInput::m_szJoyChoice3[] = TEXT("Keyboard (cursors)\0"); const TCHAR CPageInput::m_szJoyChoice3[] = TEXT("Keyboard (cursors)\0");
const TCHAR CPageInput::m_szJoyChoice4[] = TEXT("Keyboard (numpad)\0"); const TCHAR CPageInput::m_szJoyChoice4[] = TEXT("Keyboard (numpad)\0");
const TCHAR CPageInput::m_szJoyChoice5[] = TEXT("Mouse\0"); const TCHAR CPageInput::m_szJoyChoice5[] = TEXT("Mouse\0");
const TCHAR CPageInput::m_szJoyChoice6[] = TEXT("PC Joystick #1 Thumbstick 2\0");
const TCHAR* const CPageInput::m_pszJoy0Choices[J0C_MAX] = { const TCHAR* const CPageInput::m_pszJoy0Choices[J0C_MAX] = {
CPageInput::m_szJoyChoice0, CPageInput::m_szJoyChoice0,
@ -53,7 +54,8 @@ const TCHAR* const CPageInput::m_pszJoy1Choices[J1C_MAX] = {
CPageInput::m_szJoyChoice2, // PC Joystick #2 CPageInput::m_szJoyChoice2, // PC Joystick #2
CPageInput::m_szJoyChoice3, CPageInput::m_szJoyChoice3,
CPageInput::m_szJoyChoice4, CPageInput::m_szJoyChoice4,
CPageInput::m_szJoyChoice5 }; CPageInput::m_szJoyChoice5,
CPageInput::m_szJoyChoice6 };
const TCHAR CPageInput::m_szCPMSlotChoice_Slot4[] = TEXT("Slot 4\0"); const TCHAR CPageInput::m_szCPMSlotChoice_Slot4[] = TEXT("Slot 4\0");
const TCHAR CPageInput::m_szCPMSlotChoice_Slot5[] = TEXT("Slot 5\0"); const TCHAR CPageInput::m_szCPMSlotChoice_Slot5[] = TEXT("Slot 5\0");

View File

@ -60,6 +60,7 @@ private:
static const TCHAR m_szJoyChoice3[]; static const TCHAR m_szJoyChoice3[];
static const TCHAR m_szJoyChoice4[]; static const TCHAR m_szJoyChoice4[];
static const TCHAR m_szJoyChoice5[]; static const TCHAR m_szJoyChoice5[];
static const TCHAR m_szJoyChoice6[];
static const TCHAR* const m_pszJoy0Choices[J0C_MAX]; static const TCHAR* const m_pszJoy0Choices[J0C_MAX];
static const TCHAR* const m_pszJoy1Choices[J1C_MAX]; static const TCHAR* const m_pszJoy1Choices[J1C_MAX];

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 #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] // Indexed by joytype[n]
static const DWORD joyinfo[5] = { DEVICE_NONE, static const DWORD joyinfo[6] = { DEVICE_NONE,
DEVICE_JOYSTICK, DEVICE_JOYSTICK,
DEVICE_KEYBOARD, // Cursors (prev: Numpad-Standard) DEVICE_KEYBOARD, // Cursors (prev: Numpad-Standard)
DEVICE_KEYBOARD, // Numpad (prev: Numpad-Centering) 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 // Key pad [1..9]; Key pad 0,Key pad '.'; Left ALT,Right ALT
enum JOYKEY { JK_DOWNLEFT=0, enum JOYKEY { JK_DOWNLEFT=0,
@ -149,7 +150,24 @@ void CheckJoystick1()
{ {
lastcheck = currtime; lastcheck = currtime;
JOYINFO info; 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]) if ((info.wButtons & JOY_BUTTON1) && !joybutton[2])
{ {
@ -245,6 +263,33 @@ void JoyInitialize()
joytype[1] = J1C_DISABLED; 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) if(joyinfo[joytype[0]] == DEVICE_JOYSTICK)
CheckJoystick0(); CheckJoystick0();
if(joyinfo[joytype[1]] == DEVICE_JOYSTICK) if((joyinfo[joytype[1]] == DEVICE_JOYSTICK) || (joyinfo[joytype[1]] == DEVICE_JOYSTICK_THUMBSTICK2))
CheckJoystick1(); CheckJoystick1();
if (g_bJoyportEnabled) if (g_bJoyportEnabled)
@ -593,7 +638,7 @@ BYTE __stdcall JoyResetPosition(WORD, WORD, BYTE, BYTE, ULONG nCyclesLeft)
if(joyinfo[joytype[0]] == DEVICE_JOYSTICK) if(joyinfo[joytype[0]] == DEVICE_JOYSTICK)
CheckJoystick0(); CheckJoystick0();
if(joyinfo[joytype[1]] == DEVICE_JOYSTICK) if((joyinfo[joytype[1]] == DEVICE_JOYSTICK) || (joyinfo[joytype[1]] == DEVICE_JOYSTICK_THUMBSTICK2))
CheckJoystick1(); CheckJoystick1();
return MemReadFloatingBus(nCyclesLeft); return MemReadFloatingBus(nCyclesLeft);
@ -629,12 +674,13 @@ BOOL JoySetEmulationType(HWND window, DWORD newtype, int nJoystickNumber, const
if(joytype[nJoystickNumber] == newtype) if(joytype[nJoystickNumber] == newtype)
return 1; // Already set to this type. Return OK. 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; 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) if (joyGetDevCaps(nJoyID, &caps, sizeof(JOYCAPS)) != JOYERR_NOERROR)
{ {
MessageBox(window, MessageBox(window,
TEXT("The emulator is unable to read your PC joystick. ") TEXT("The emulator is unable to read your PC joystick. ")
TEXT("Ensure that your game port is configured properly, ") 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); MB_ICONEXCLAMATION | MB_SETFOREGROUND);
return 0; 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) && else if ((joyinfo[newtype] == DEVICE_MOUSE) &&
(joyinfo[joytype[nJoystickNumber]] != DEVICE_MOUSE)) (joyinfo[joytype[nJoystickNumber]] != DEVICE_MOUSE))

View File

@ -3,7 +3,7 @@
enum JOYNUM {JN_JOYSTICK0=0, JN_JOYSTICK1}; enum JOYNUM {JN_JOYSTICK0=0, JN_JOYSTICK1};
enum JOY0CHOICE {J0C_DISABLED=0, J0C_JOYSTICK1, J0C_KEYBD_CURSORS, J0C_KEYBD_NUMPAD, J0C_MOUSE, J0C_MAX}; enum JOY0CHOICE {J0C_DISABLED=0, J0C_JOYSTICK1, J0C_KEYBD_CURSORS, J0C_KEYBD_NUMPAD, J0C_MOUSE, J0C_MAX};
enum JOY1CHOICE {J1C_DISABLED=0, J1C_JOYSTICK2, J1C_KEYBD_CURSORS, J1C_KEYBD_NUMPAD, J1C_MOUSE, J1C_MAX}; enum JOY1CHOICE {J1C_DISABLED=0, J1C_JOYSTICK2, J1C_KEYBD_CURSORS, J1C_KEYBD_NUMPAD, J1C_MOUSE, J0C_JOYSTICK1_THUMBSTICK2, J1C_MAX};
enum {JOYSTICK_MODE_FLOATING=0, JOYSTICK_MODE_CENTERING}; // Joystick centering control enum {JOYSTICK_MODE_FLOATING=0, JOYSTICK_MODE_CENTERING}; // Joystick centering control