Fixed joystick ID/deviceID/driver handle/instance ID mixup.
This commit is contained in:
parent
e4c4651833
commit
9aa678ca8a
|
@ -34,20 +34,22 @@ typedef struct tagWINE_JOYSTICK {
|
|||
UINT wTimer;
|
||||
DWORD threshold;
|
||||
BOOL bChanged;
|
||||
HDRVR hDriver;
|
||||
} WINE_JOYSTICK;
|
||||
|
||||
static WINE_JOYSTICK JOY_Sticks[MAXJOYSTICK];
|
||||
static HDRVR JOY_Driver;
|
||||
|
||||
/**************************************************************************
|
||||
* JOY_LoadDriver [internal]
|
||||
*/
|
||||
static BOOL JOY_LoadDriver(void)
|
||||
static BOOL JOY_LoadDriver(DWORD dwJoyID)
|
||||
{
|
||||
if (JOY_Driver)
|
||||
if (dwJoyID >= MAXJOYSTICK)
|
||||
return FALSE;
|
||||
if (JOY_Sticks[dwJoyID].hDriver)
|
||||
return TRUE;
|
||||
|
||||
return JOY_Driver = OpenDriverA("joystick.drv", 0, 0);
|
||||
return JOY_Sticks[dwJoyID].hDriver = OpenDriverA("joystick.drv", 0, dwJoyID);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -98,9 +100,15 @@ static void CALLBACK JOY_Timer(HWND hWnd, UINT wMsg, UINT wTimer, DWORD dwTime)
|
|||
*/
|
||||
UINT WINAPI joyGetNumDevs(void)
|
||||
{
|
||||
if (!JOY_LoadDriver()) return MMSYSERR_NODRIVER;
|
||||
UINT ret = 0;
|
||||
int i;
|
||||
|
||||
return SendDriverMessage(JOY_Driver, JDD_GETNUMDEVS, 0L, 0L);
|
||||
for (i = 0; i < MAXJOYSTICK; i++) {
|
||||
if (JOY_LoadDriver(i)) {
|
||||
ret += SendDriverMessage(JOY_Sticks[i].hDriver, JDD_GETNUMDEVS, 0L, 0L);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -117,12 +125,12 @@ UINT16 WINAPI joyGetNumDevs16(void)
|
|||
MMRESULT WINAPI joyGetDevCapsA(UINT wID, LPJOYCAPSA lpCaps, UINT wSize)
|
||||
{
|
||||
if (wID >= MAXJOYSTICK) return JOYERR_PARMS;
|
||||
if (!JOY_LoadDriver()) return MMSYSERR_NODRIVER;
|
||||
if (!JOY_LoadDriver(wID)) return MMSYSERR_NODRIVER;
|
||||
|
||||
lpCaps->wPeriodMin = JOY_PERIOD_MIN; /* FIXME */
|
||||
lpCaps->wPeriodMax = JOY_PERIOD_MAX; /* FIXME (same as MS Joystick Driver) */
|
||||
|
||||
return SendDriverMessage(JOY_Driver, JDD_GETDEVCAPS, (DWORD)lpCaps, wSize);
|
||||
return SendDriverMessage(JOY_Sticks[wID].hDriver, JDD_GETDEVCAPS, (DWORD)lpCaps, wSize);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -213,7 +221,7 @@ MMRESULT WINAPI joyGetPosEx(UINT wID, LPJOYINFOEX lpInfo)
|
|||
TRACE("(%d, %p);\n", wID, lpInfo);
|
||||
|
||||
if (wID >= MAXJOYSTICK) return JOYERR_PARMS;
|
||||
if (!JOY_LoadDriver()) return MMSYSERR_NODRIVER;
|
||||
if (!JOY_LoadDriver(wID)) return MMSYSERR_NODRIVER;
|
||||
|
||||
lpInfo->dwXpos = 0;
|
||||
lpInfo->dwYpos = 0;
|
||||
|
@ -227,7 +235,7 @@ MMRESULT WINAPI joyGetPosEx(UINT wID, LPJOYINFOEX lpInfo)
|
|||
lpInfo->dwReserved1 = 0;
|
||||
lpInfo->dwReserved2 = 0;
|
||||
|
||||
return SendDriverMessage(JOY_Driver, JDD_GETPOSEX, (DWORD)lpInfo, 0L);
|
||||
return SendDriverMessage(JOY_Sticks[wID].hDriver, JDD_GETPOSEX, (DWORD)lpInfo, 0L);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -246,14 +254,14 @@ MMRESULT WINAPI joyGetPos(UINT wID, LPJOYINFO lpInfo)
|
|||
TRACE("(%d, %p);\n", wID, lpInfo);
|
||||
|
||||
if (wID >= MAXJOYSTICK) return JOYERR_PARMS;
|
||||
if (!JOY_LoadDriver()) return MMSYSERR_NODRIVER;
|
||||
if (!JOY_LoadDriver(wID)) return MMSYSERR_NODRIVER;
|
||||
|
||||
lpInfo->wXpos = 0;
|
||||
lpInfo->wYpos = 0;
|
||||
lpInfo->wZpos = 0;
|
||||
lpInfo->wButtons = 0;
|
||||
|
||||
return SendDriverMessage(JOY_Driver, JDD_GETPOS, (DWORD)lpInfo, 0L);
|
||||
return SendDriverMessage(JOY_Sticks[wID].hDriver, JDD_GETPOS, (DWORD)lpInfo, 0L);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -309,7 +317,7 @@ MMRESULT WINAPI joyReleaseCapture(UINT wID)
|
|||
TRACE("(%04X);\n", wID);
|
||||
|
||||
if (wID >= MAXJOYSTICK) return JOYERR_PARMS;
|
||||
if (!JOY_LoadDriver()) return MMSYSERR_NODRIVER;
|
||||
if (!JOY_LoadDriver(wID)) return MMSYSERR_NODRIVER;
|
||||
if (!JOY_Sticks[wID].hCapture) return JOYERR_NOCANDO;
|
||||
|
||||
KillTimer(JOY_Sticks[wID].hCapture, JOY_Sticks[wID].wTimer);
|
||||
|
@ -336,7 +344,7 @@ MMRESULT WINAPI joySetCapture(HWND hWnd, UINT wID, UINT wPeriod, BOOL bChanged)
|
|||
|
||||
if (wID >= MAXJOYSTICK || hWnd == 0) return JOYERR_PARMS;
|
||||
if (wPeriod<JOY_PERIOD_MIN || wPeriod>JOY_PERIOD_MAX) return JOYERR_PARMS;
|
||||
if (!JOY_LoadDriver()) return MMSYSERR_NODRIVER;
|
||||
if (!JOY_LoadDriver(wID)) return MMSYSERR_NODRIVER;
|
||||
|
||||
if (JOY_Sticks[wID].hCapture || !IsWindow(hWnd))
|
||||
return JOYERR_NOCANDO; /* FIXME: what should be returned ? */
|
||||
|
|
|
@ -49,19 +49,40 @@ DEFAULT_DEBUG_CHANNEL(joystick);
|
|||
|
||||
#define MAXJOYSTICK (JOYSTICKID2 + 1)
|
||||
|
||||
static struct dummy_struct* JSTCK_Dummy = NULL;
|
||||
typedef struct tagWINE_JSTCK {
|
||||
int joyIntf;
|
||||
int in_use;
|
||||
} WINE_JSTCK;
|
||||
|
||||
static WINE_JSTCK JSTCK_Data[MAXJOYSTICK];
|
||||
|
||||
/**************************************************************************
|
||||
* JSTCK_drvGet [internal]
|
||||
*/
|
||||
static WINE_JSTCK* JSTCK_drvGet(DWORD dwDevID)
|
||||
{
|
||||
int p;
|
||||
|
||||
if ((dwDevID - (DWORD)JSTCK_Data) % sizeof(JSTCK_Data[0]) != 0)
|
||||
return NULL;
|
||||
p = (dwDevID - (DWORD)JSTCK_Data) / sizeof(JSTCK_Data[0]);
|
||||
if (p < 0 || p >= MAXJOYSTICK || !((WINE_JSTCK*)dwDevID)->in_use)
|
||||
return NULL;
|
||||
|
||||
return (WINE_JSTCK*)dwDevID;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
* JSTCK_drvOpen [internal]
|
||||
*/
|
||||
static DWORD JSTCK_drvOpen(LPSTR str)
|
||||
static DWORD JSTCK_drvOpen(LPSTR str, DWORD dwIntf)
|
||||
{
|
||||
if (JSTCK_Dummy)
|
||||
if (dwIntf >= MAXJOYSTICK || JSTCK_Data[dwIntf].in_use)
|
||||
return 0;
|
||||
|
||||
/* I know, this is ugly, but who cares... */
|
||||
JSTCK_Dummy = (struct dummy_struct*)1;
|
||||
return 1;
|
||||
|
||||
JSTCK_Data[dwIntf].joyIntf = dwIntf;
|
||||
JSTCK_Data[dwIntf].in_use = 1;
|
||||
return (DWORD)&JSTCK_Data[dwIntf];
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
|
@ -69,11 +90,12 @@ static DWORD JSTCK_drvOpen(LPSTR str)
|
|||
*/
|
||||
static DWORD JSTCK_drvClose(DWORD dwDevID)
|
||||
{
|
||||
if (JSTCK_Dummy) {
|
||||
JSTCK_Dummy = NULL;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
WINE_JSTCK* jstck = JSTCK_drvGet(dwDevID);
|
||||
|
||||
if (jstck == NULL)
|
||||
return 0;
|
||||
jstck->in_use = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct js_status
|
||||
|
@ -86,14 +108,12 @@ struct js_status
|
|||
/**************************************************************************
|
||||
* JSTCK_OpenDevice [internal]
|
||||
*/
|
||||
static int JSTCK_OpenDevice(WORD wID)
|
||||
static int JSTCK_OpenDevice(WINE_JSTCK* jstick)
|
||||
{
|
||||
char buf[20];
|
||||
int flags;
|
||||
|
||||
if (wID >= MAXJOYSTICK) return -1;
|
||||
|
||||
sprintf(buf, JOYDEV, wID);
|
||||
sprintf(buf, JOYDEV, jstick->joyIntf);
|
||||
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
||||
flags = O_RDONLY | O_NONBLOCK;
|
||||
#else
|
||||
|
@ -107,6 +127,7 @@ static int JSTCK_OpenDevice(WORD wID)
|
|||
*/
|
||||
static LONG JSTCK_GetDevCaps(DWORD dwDevID, LPJOYCAPSA lpCaps, DWORD dwSize)
|
||||
{
|
||||
WINE_JSTCK* jstck;
|
||||
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
||||
int dev;
|
||||
char nrOfAxes;
|
||||
|
@ -115,11 +136,12 @@ static LONG JSTCK_GetDevCaps(DWORD dwDevID, LPJOYCAPSA lpCaps, DWORD dwSize)
|
|||
int driverVersion;
|
||||
#endif
|
||||
|
||||
if (dwDevID >= MAXJOYSTICK) return MMSYSERR_NODRIVER;
|
||||
if ((jstck = JSTCK_drvGet(dwDevID)) == NULL)
|
||||
return MMSYSERR_NODRIVER;
|
||||
|
||||
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
||||
|
||||
if ((dev = JSTCK_OpenDevice(dwDevID)) < 0) return JOYERR_PARMS;
|
||||
if ((dev = JSTCK_OpenDevice(jstck)) < 0) return JOYERR_PARMS;
|
||||
ioctl(dev, JSIOCGAXES, &nrOfAxes);
|
||||
ioctl(dev, JSIOCGBUTTONS, &nrOfButtons);
|
||||
ioctl(dev, JSIOCGVERSION, &driverVersion);
|
||||
|
@ -200,6 +222,7 @@ static LONG JSTCK_GetDevCaps(DWORD dwDevID, LPJOYCAPSA lpCaps, DWORD dwSize)
|
|||
*/
|
||||
static LONG JSTCK_GetPosEx(DWORD dwDevID, LPJOYINFOEX lpInfo)
|
||||
{
|
||||
WINE_JSTCK* jstck;
|
||||
int dev;
|
||||
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
||||
struct js_event ev;
|
||||
|
@ -208,7 +231,10 @@ static LONG JSTCK_GetPosEx(DWORD dwDevID, LPJOYINFOEX lpInfo)
|
|||
int dev_stat;
|
||||
#endif
|
||||
|
||||
if ((dev = JSTCK_OpenDevice(dwDevID)) < 0) return JOYERR_PARMS;
|
||||
if ((jstck = JSTCK_drvGet(dwDevID)) == NULL)
|
||||
return MMSYSERR_NODRIVER;
|
||||
|
||||
if ((dev = JSTCK_OpenDevice(jstck)) < 0) return JOYERR_PARMS;
|
||||
|
||||
#ifdef HAVE_LINUX_22_JOYSTICK_API
|
||||
/* After opening the device it's state can be
|
||||
|
@ -312,7 +338,7 @@ static LONG JSTCK_GetPos(DWORD dwDevID, LPJOYINFO lpInfo)
|
|||
* JSTCK_DriverProc [internal]
|
||||
*/
|
||||
LONG CALLBACK JSTCK_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
|
||||
DWORD dwParam1, DWORD dwParam2)
|
||||
DWORD dwParam1, DWORD dwParam2)
|
||||
{
|
||||
/* EPP TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n", */
|
||||
/* EPP dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
|
||||
|
@ -320,7 +346,7 @@ LONG CALLBACK JSTCK_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
|
|||
switch(wMsg) {
|
||||
case DRV_LOAD: return 1;
|
||||
case DRV_FREE: return 1;
|
||||
case DRV_OPEN: return JSTCK_drvOpen((LPSTR)dwParam1);
|
||||
case DRV_OPEN: return JSTCK_drvOpen((LPSTR)dwParam1, dwParam2);
|
||||
case DRV_CLOSE: return JSTCK_drvClose(dwDevID);
|
||||
case DRV_ENABLE: return 1;
|
||||
case DRV_DISABLE: return 1;
|
||||
|
@ -329,7 +355,7 @@ LONG CALLBACK JSTCK_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
|
|||
case DRV_INSTALL: return DRVCNF_RESTART;
|
||||
case DRV_REMOVE: return DRVCNF_RESTART;
|
||||
|
||||
case JDD_GETNUMDEVS: return MAXJOYSTICK;
|
||||
case JDD_GETNUMDEVS: return 1;
|
||||
case JDD_GETDEVCAPS: return JSTCK_GetDevCaps(dwDevID, (LPJOYCAPSA)dwParam1, dwParam2);
|
||||
case JDD_GETPOS: return JSTCK_GetPos(dwDevID, (LPJOYINFO)dwParam1);
|
||||
case JDD_SETCALIBRATION:
|
||||
|
@ -346,7 +372,7 @@ LONG CALLBACK JSTCK_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
|
|||
* JSTCK_DriverProc [internal]
|
||||
*/
|
||||
LONG CALLBACK JSTCK_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
|
||||
DWORD dwParam1, DWORD dwParam2)
|
||||
DWORD dwParam1, DWORD dwParam2)
|
||||
{
|
||||
/* EPP TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n", */
|
||||
/* EPP dwDevID, hDriv, wMsg, dwParam1, dwParam2); */
|
||||
|
|
Loading…
Reference in New Issue