Add rayman2 source files

This commit is contained in:
2024-09-18 02:33:44 +08:00
parent bcc093f8ed
commit fb036c54fd
14339 changed files with 2596224 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
/***************************************************************************/
/* Description: INOInit.c, part of CPA INO library */
/* Declaration of the global variables for MMG and ERM */
/* for joystick and keyboard and mouse */
/* */
/* Author: F. Jentey */
/* Creation date: 21/04/97 */
/* Last Update: 30/07/97 Direct input initialisation */
/***************************************************************************/
/*======== CPA Header ========*/
#ifdef INO_USE_CPA
/* CPA Error */
#define __DeclareGlobalVariableErrINO_h__
#include "INO/errINO.h"
#undef __DeclareGlobalVariableErrINO_h__
/* CPA Memory */
#define __DeclareGlobalVariableMemINO_h__
#include "INO/MmgINO.h"
#undef __DeclareGlobalVariableMemINO_h__
#endif
/*==============================*/
/*======== Direct Input header ========*/
#ifndef INITGUID
#define INITGUID
#include "DInput.h"
#undef INITGUID
#else
#include "DInput.h"
#endif
#define DIRECTINPUT_VERSION_3 0x0300
#include "INOInit.h"
/*=======================================*/
/* CPA ERM and MMG init OK ? */
short INO_g_wErrorInitialisationOK = 0;
short INO_g_wMemoryInitialisationOK = 0;
LPDIRECTINPUT INO_g_p_stDInputInterface = NULL;
HINSTANCE INO_g_hAppInstance;
HWND INO_g_hAppMainWindow;
#ifdef INO_USE_CPA
/***********************************/
/* Init CPA errors for module INO */
/***********************************/
short INO_fn_wInitError()
{
if (INO_g_wErrorInitialisationOK) return(0);
Erm_M_InitErrMsg(INO);
INO_g_wErrorInitialisationOK = 1;
return(0);
}
/***********************************/
/* Init CPA memory for module INO */
/***********************************/
short INO_fn_wInitMemory()
{
if (INO_g_wMemoryInitialisationOK) return(0);
M_INOInitMem();
INO_g_wMemoryInitialisationOK = 1;
return(0);
}
#endif
/***********************************/
/* Init Direct Input */
/* Return 1 if OK, else 0 */
/***********************************/
short INO_fn_wInitDirectInput(HINSTANCE hInstance, HWND hWindow)
{
HRESULT DInputErr;
if (INO_g_p_stDInputInterface) return(1);
#ifdef OLD_DIRECTINPUT
DInputErr = DirectInputCreate(hInstance,DIRECTINPUT_VERSION,&INO_g_p_stDInputInterface,NULL);
if (DInputErr==DIERR_OLDDIRECTINPUTVERSION)
/* If compiled with Direct Input 5, and Direct Input 3 is installed */
DInputErr = DirectInputCreate(hInstance,DIRECTINPUT_VERSION_3,&INO_g_p_stDInputInterface,NULL);
#else
DInputErr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput8,&INO_g_p_stDInputInterface, NULL );
#endif
switch (DInputErr)
{
case DI_OK:
INO_g_hAppInstance = hInstance;
INO_g_hAppMainWindow = hWindow;
break;
case DIERR_INVALIDPARAM:
case DIERR_OUTOFMEMORY:
case DIERR_OLDDIRECTINPUTVERSION:
case DIERR_BETADIRECTINPUTVERSION:
INO_g_p_stDInputInterface = NULL;
break;
default:
break;
}
return (INO_g_p_stDInputInterface != NULL);
}
/***********************************/
/* Release Direct Input */
/***********************************/
void INO_fn_vReleaseDirectInput()
{
if (INO_g_p_stDInputInterface) return;
INO_g_p_stDInputInterface->lpVtbl->Release(INO_g_p_stDInputInterface);
INO_g_p_stDInputInterface = NULL;
}

View File

@@ -0,0 +1,34 @@
/***************************************************************************/
/* Description: INOInot.h, part of CPA INO library */
/* Header for error, memory and direct input initialisation */
/* */
/* Author: F. Jentey */
/* Creation date: 21/04/97 */
/* Last Update: 30/07/97 Direct Input */
/***************************************************************************/
#include "CPA_std.h"
#include "DInput.h"
/*
Direct Input interface
*/
extern LPDIRECTINPUT INO_g_p_stDInputInterface;
extern HINSTANCE INO_g_hAppInstance;
extern HWND INO_g_hAppMainWindow;
/*
Function to call for cpa error initialisation
*/
#ifdef USE_CPA
extern short INO_fn_wInitError();
extern short INO_fn_wInitMemory();
#endif
extern short INO_fn_wInitDirectInput(HINSTANCE hInstance,HWND hWindow);
extern void INO_fn_vReleaseDirectInput();

View File

@@ -0,0 +1,446 @@
/***************************************************************************/
/* Description: InitDI.c, part of CPA INO library */
/* Direct Input device low level init implementation */
/* */
/* Author: F. Jentey */
/* Creation date: 21/04/97 */
/* Last Update: 30/07/97 Direct input initialisation */
/***************************************************************************/
/*======== Direct Input header ========*/
#ifndef INITGUID
#define INITGUID
#include "DInput.h"
#undef INITGUID
#else
#include "DInput.h"
#endif
/*=======================================*/
#include "INO\errINO.h"
#include "INOInit.h"
#include "InitDI.h"
#include "INOJoy.h"
#include "INOKeyb.h"
#include "INOMouse.h"
#include "Joystick.h"
#define M_DInput() INO_g_p_stDInputInterface->lpVtbl
LPDIRECTINPUT INO_g_p_stDInputInterface = NULL;
HINSTANCE INO_g_hAppInstance;
HWND INO_g_hAppMainWindow;
unsigned long m_ulDITargetVersion = DIRECTINPUT_VERSION; /* Version of Direct Input the module was build for*/
unsigned long m_ulDIInstalledVersion; /* Version of Direct Input installed on the machine*/
DIDEVCAPS g_stDIDevCaps;
DIDEVCAPS_DX3 g_stDIDevCaps3;
INO_tdstDIDevice INO_g_a_stDIDevice[INO_C_wNbMaxDevice];
short INO_g_wNbDevices = 0;
/*********************************************************************************/
/* Joystick enumeration callback */
/* Device instance are stored in INO_g_a_stJoystickInstance */
/*********************************************************************************/
BOOL CALLBACK fn_bEnumDeviceCallback(LPCDIDEVICEINSTANCE p_stDeviceInstance, LPVOID p_vRef)
{
LPDIRECTINPUTDEVICE p_stDevice;
LPDIRECTINPUTDEVICE2 p_stDevice2;
LPCDIDATAFORMAT p_stDataFormat;
DWORD ulCooperativeLevel;
HRESULT DInputErr;
/* Create the DirectInput joystick device */
DInputErr = M_DInput()->CreateDevice(
INO_g_p_stDInputInterface,
&p_stDeviceInstance->guidInstance,
&p_stDevice,
NULL
);
if (DInputErr != DI_OK) return FALSE;
switch (GET_DIDEVICE_TYPE(p_stDeviceInstance->dwDevType))
{
case DIDEVTYPE_MOUSE:
p_stDataFormat = &c_dfDIMouse;
/* All these settings have been tried in NT 4 with Service Pack 3 installed*/
/* This is the option selected...*/
ulCooperativeLevel = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
/* This one freezes the mouse...*/
/*ulCooperativeLevel = DISCL_EXCLUSIVE | DISCL_FOREGROUND;*/
/* Works similarly to DISCL_NONEXCLUSIVE | DISCL_FOREGROUND*/
/*ulCooperativeLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;*/
/* This one causes unhandled exceptions...*/
/*ulCooperativeLevel = DISCL_EXCLUSIVE | DISCL_BACKGROUND;*/
break;
case DIDEVTYPE_KEYBOARD:
p_stDataFormat = &c_dfDIKeyboard;
ulCooperativeLevel = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
/*ulCooperativeLevel = DISCL_EXCLUSIVE | DISCL_FOREGROUND;*/
break;
case DIDEVTYPE_JOYSTICK:
p_stDataFormat = &c_dfDIJoystick;
ulCooperativeLevel = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
break;
default:
return FALSE;
}
/* Make sure the device is not acquired before calling setDataFormat */
/* and SetCooperativeLevel. */
DInputErr = p_stDevice->lpVtbl->Unacquire(p_stDevice);
/* Set joystick data format */
DInputErr = p_stDevice->lpVtbl->SetDataFormat(p_stDevice, p_stDataFormat);
if (DInputErr != DI_OK)
{
p_stDevice->lpVtbl->Release(p_stDevice);
return FALSE;
}
/* Set the cooperative level */
DInputErr = p_stDevice->lpVtbl->SetCooperativeLevel(
p_stDevice,
INO_g_hAppMainWindow,
ulCooperativeLevel
);
if (DInputErr != DI_OK)
{
p_stDevice->lpVtbl->Release(p_stDevice);
return FALSE;
}
/* Everything is OK, keep this joystick */
memcpy(
&INO_g_a_stDIDevice[INO_g_wNbDevices].m_stDevInstance,
p_stDeviceInstance,
sizeof(DIDEVICEINSTANCE)
);
INO_g_a_stDIDevice[INO_g_wNbDevices].m_p_stDevInterface = p_stDevice;
/* Find the IDirectInput2 interface, for using Poll method */
if (GET_DIDEVICE_TYPE(p_stDeviceInstance->dwDevType) == DIDEVTYPE_JOYSTICK)
{
DInputErr = p_stDevice->lpVtbl->QueryInterface(
p_stDevice,
&IID_IDirectInputDevice2,
(LPVOID*)&p_stDevice2
);
if (DInputErr == S_OK)
{
INO_g_a_stDIDevice[INO_g_wNbDevices].m_p_stDevInterface2 = p_stDevice2;
INO_g_a_stDIDevice[INO_g_wNbDevices].m_wExtendedInterfaceAvailable = 1;
}
else
{
INO_g_a_stDIDevice[INO_g_wNbDevices].m_p_stDevInterface2 = NULL;
INO_g_a_stDIDevice[INO_g_wNbDevices].m_wExtendedInterfaceAvailable = 0;
}
}
else
{
INO_g_a_stDIDevice[INO_g_wNbDevices].m_p_stDevInterface2 = NULL;
INO_g_a_stDIDevice[INO_g_wNbDevices].m_wExtendedInterfaceAvailable = 0;
}
INO_g_wNbDevices++;
return DIENUM_CONTINUE;
}
/***********************************/
/* Init Direct Input */
/* Return 1 if OK, else 0 */
/***********************************/
short INO_fn_wInitAllDevices(HINSTANCE hInstance, HWND hWindow)
{
HRESULT DInputErr;
if (INO_g_p_stDInputInterface)
return(1);
INO_g_wNbDevices = 0;
DInputErr = DirectInputCreate(hInstance,DIRECTINPUT_VERSION,&INO_g_p_stDInputInterface,NULL);
if (DInputErr==DIERR_OLDDIRECTINPUTVERSION)
{
/* If compiled with Direct Input 5, and Direct Input 3 is installed */
DInputErr = DirectInputCreate(hInstance,DIRECTINPUT_VERSION_3,&INO_g_p_stDInputInterface,NULL);
if (DInputErr == DI_OK)
m_ulDIInstalledVersion = DIRECTINPUT_VERSION_3;
}
else
m_ulDIInstalledVersion = DIRECTINPUT_VERSION;
switch (DInputErr)
{
case DI_OK:
INO_g_hAppInstance = hInstance;
INO_g_hAppMainWindow = hWindow;
break;
case DIERR_INVALIDPARAM:
case DIERR_OUTOFMEMORY:
case DIERR_OLDDIRECTINPUTVERSION:
case DIERR_BETADIRECTINPUTVERSION:
default:
INO_g_p_stDInputInterface = NULL;
m_ulDIInstalledVersion = 0;
INO_fn_vUpdateLastError(E_uwINO_FatalDirectInpuNotFound);
return (0);
}
memset(INO_g_a_stDIDevice,0,sizeof(INO_tdstDIDevice)*INO_C_wNbMaxDevice);
DInputErr = M_DInput()->EnumDevices(
INO_g_p_stDInputInterface,
0,
fn_bEnumDeviceCallback,
NULL,
DIEDFL_ALLDEVICES
);
if( DInputErr == DI_OK )
{
return ( 1 );
}
return( 0 );
}
/***********************************/
/* Init one device */
/***********************************/
short INO_fn_wInitDevice(INO_tdhDevice hDev)
{
HRESULT DInputErr;
short i, wResult;
for (i=0; i<INO_C_wNbMaxDevice; i++)
{
if (!INO_g_a_stDIDevice[i].m_hDevice &&
(1 << GET_DIDEVICE_TYPE(INO_g_a_stDIDevice[i].m_stDevInstance.dwDevType) == INO_M_uwType(hDev))
)
{
INO_g_a_stDIDevice[i].m_hDevice = hDev;
switch (INO_M_uwType(hDev))
{
case INO_C_uwJoystick:
hDev->m_pfnRead = INO_fn_wReadJoystick;
wResult = INO_fn_wInitJoystickCaps(hDev);
break;
case INO_C_uwKeyboard:
hDev->m_pfnRead = INO_fn_wReadKeyboard;
wResult = INO_fn_wInitKeyboardCaps(hDev);
break;
case INO_C_uwMouse:
/* Initialize the mouse only if the application uses it*/
hDev->m_pfnRead = INO_fn_wReadMouse;
wResult = INO_fn_wInitMouseCaps(hDev);
break;
}
if (!wResult)
{
INO_fn_vUpdateLastError(E_uwINO_DeviceInitFailed);
return (-1);
}
DInputErr = M_DIAcquire(i);
switch (DInputErr)
{
case DI_OK:
case S_FALSE:
hDev->m_p_stState->m_ucStatus |= INO_C_ucAcquired;
break;
case DIERR_INPUTLOST:
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucAcquired;
break;
case DIERR_INVALIDPARAM:
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucAcquired;
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
return (-1);
default:
break;
}
return (i);
}
}
return (-1);
}
/***********************************/
/* Release one device */
/***********************************/
short INO_fn_wDestroyDevice(INO_tdhDevice hDev)
{
long i;
for (i=0; i<INO_C_wNbMaxDevice; i++)
{
if (INO_g_a_stDIDevice[i].m_hDevice == hDev)
{
M_DIUnacquire(i);
/* M_DIRelease(i);*/
memset(&INO_g_a_stDIDevice[i],0,sizeof(INO_tdstDIDevice));
return (1);
}
}
return (0);
}
/***********************************/
/* Release Direct Input */
/***********************************/
void INO_fn_vReleaseAllDevices()
{
long i;
if (!INO_g_p_stDInputInterface) return;
for (i=0; i<INO_C_wNbMaxDevice; i++)
if (INO_g_a_stDIDevice[i].m_hDevice)
{
M_DIRelease(i);
INO_fn_wDestroyDevice(INO_g_a_stDIDevice[i].m_hDevice);
}
M_DInput()->Release(INO_g_p_stDInputInterface);
INO_g_p_stDInputInterface = NULL;
}
/****************************************/
/* Free All */
/****************************************/
short INO_fn_wGetNbDevices(unsigned short uwType)
{
short i, lNb = 0;
if (!INO_g_p_stDInputInterface) return (0);
for (i=0; i<INO_C_wNbMaxDevice; i++)
if ((1 << GET_DIDEVICE_TYPE(INO_g_a_stDIDevice[i].m_stDevInstance.dwDevType)) == uwType) lNb++;
/*if (INO_g_a_stDIDevice[i].m_hDevice)*/
/* if (GET_DIDEVICE_TYPE(INO_g_a_stDIDevice[i].m_stDevInstance.dwDevType) == uwType) lNb++;*/
return (lNb);
}
/******************************************/
/* init the device capabilities */
/* and return the DInput sub-type */
/******************************************/
short INO_fn_wFillDeviceCaps(INO_tdhDevice hDev)
{
HRESULT DInputErr;
short wDev;
INO_tdstDevCaps *p_stCaps = (INO_tdstDevCaps*)(hDev->m_p_stCaps);
for (wDev=0; wDev<INO_C_wNbMaxDevice; wDev++)
if (INO_g_a_stDIDevice[wDev].m_hDevice == hDev) break;
if (wDev == INO_C_wNbMaxDevice) return (0);
M_DIAcquire(wDev);
if (m_ulDIInstalledVersion == DIRECTINPUT_VERSION_3)
{
memset(&g_stDIDevCaps3,0,sizeof(DIDEVCAPS_DX3));
g_stDIDevCaps3.dwSize = sizeof(DIDEVCAPS_DX3);
DInputErr = M_DIGetCaps(wDev,(DIDEVCAPS*)&g_stDIDevCaps3);
}
else
{
memset(&g_stDIDevCaps,0,sizeof(DIDEVCAPS));
g_stDIDevCaps.dwSize = sizeof(DIDEVCAPS);
DInputErr = M_DIGetCaps(wDev,&g_stDIDevCaps);
}
if (DInputErr == DI_OK)
{
if (m_ulDIInstalledVersion == DIRECTINPUT_VERSION_3)
{
if (g_stDIDevCaps3.dwFlags & DIDC_ATTACHED)
hDev->m_p_stState->m_ucStatus |= INO_C_ucConnected;
p_stCaps->m_ucNbButtons = (unsigned char)g_stDIDevCaps3.dwButtons;
switch (INO_M_uwType(hDev))
{
case INO_C_uwJoystick:
((INO_tdstJoystickCaps*)p_stCaps)->m_ucNbPOVs = (unsigned char)g_stDIDevCaps3.dwPOVs;
case INO_C_uwMouse:
((INO_tdstJoystickCaps*)p_stCaps)->m_ucNbAxes = (unsigned char)g_stDIDevCaps3.dwAxes;
break;
}
return (GET_DIDEVICE_SUBTYPE(g_stDIDevCaps3.dwDevType));
}
else
{
if (g_stDIDevCaps.dwFlags & DIDC_ATTACHED)
hDev->m_p_stState->m_ucStatus |= INO_C_ucConnected;
p_stCaps->m_ucNbButtons = (unsigned char)g_stDIDevCaps.dwButtons;
switch (INO_M_uwType(hDev))
{
case INO_C_uwJoystick:
((INO_tdstJoystickCaps*)p_stCaps)->m_ucNbAxes = (unsigned char)g_stDIDevCaps.dwAxes;
((INO_tdstJoystickCaps*)p_stCaps)->m_ucNbPOVs = (unsigned char)g_stDIDevCaps.dwPOVs;
break;
}
return (GET_DIDEVICE_SUBTYPE(g_stDIDevCaps.dwDevType));
}
}
else
{
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucConnected;
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucAcquired;
INO_fn_vUpdateLastError(E_uwINO_DeviceInitFailed);
return (0);
}
}
short INO_fn_wIsConnected(INO_tdhDevice hDev)
{
HRESULT DInputErr;
short wDev;
/* JFP: what is this used for? Is it necessary?*/
for (wDev=0; wDev<INO_C_wNbMaxDevice; wDev++)
if (INO_g_a_stDIDevice[wDev].m_hDevice == hDev)
break;
if (wDev == INO_C_wNbMaxDevice)
return (0);
/* Use DI 3 structure to go faster */
memset(&g_stDIDevCaps3,0,sizeof(DIDEVCAPS_DX3));
g_stDIDevCaps3.dwSize = sizeof(DIDEVCAPS_DX3);
DInputErr = M_DIGetCaps(wDev,(DIDEVCAPS*)&g_stDIDevCaps3);
if (DInputErr == DI_OK)
{
if (g_stDIDevCaps3.dwFlags & DIDC_ATTACHED)
{
hDev->m_p_stState->m_ucStatus |= INO_C_ucConnected;
return (1);
}
else
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucConnected;
}
return (0);
}

View File

@@ -0,0 +1,81 @@
/***************************************************************************/
/* Description: InitPrv.c, part of CPA INO library */
/* Declaration of the global variables for MMG and ERM */
/* for joystick and keyboard and mouse */
/* */
/* Author: F. Jentey */
/* Creation date: 21/04/97 */
/* Last Update: 30/07/97 Direct input initialisation */
/***************************************************************************/
#include <windows.h>
#include <dinput.h>
#include "INOMain.h"
#define DIRECTINPUT_VERSION_3 0x0300
typedef struct INO_stDIDevice
{
DIDEVICEINSTANCE m_stDevInstance;
LPDIRECTINPUTDEVICE m_p_stDevInterface;
LPDIRECTINPUTDEVICE2 m_p_stDevInterface2;
short m_wExtendedInterfaceAvailable;
INO_tdhDevice m_hDevice;
}
INO_tdstDIDevice;
extern LPDIRECTINPUT INO_g_p_stDInputInterface;
extern INO_tdstDIDevice INO_g_a_stDIDevice[];
extern unsigned long m_ulDITargetVersion;
extern unsigned long m_ulDIInstalledVersion;
extern INO_tdstDevice g_a_tdhDevice[];
extern DIDEVCAPS g_stDIDevCaps;
extern DIDEVCAPS_DX3 g_stDIDevCaps3;
extern short INO_fn_wFillDeviceCaps(INO_tdhDevice hDev);
extern short INO_fn_wIsAttached(short hDev);
#define M_DIDev1(A) INO_g_a_stDIDevice[A].m_p_stDevInterface
#define M_DIDev2(A) INO_g_a_stDIDevice[A].m_p_stDevInterface2
#define M_DIDevEx(A) INO_g_a_stDIDevice[A].m_wExtendedInterfaceAvailable
#define M_DIAcquire(A) ( \
M_DIDevEx(A) ?\
M_DIDev2(A)->lpVtbl->Acquire(M_DIDev2(A)) \
: \
M_DIDev1(A)->lpVtbl->Acquire(M_DIDev1(A)) )
#define M_DIUnacquire(A) ( \
M_DIDevEx(A) ?\
M_DIDev2(A)->lpVtbl->Unacquire(M_DIDev2(A)) \
: \
M_DIDev1(A)->lpVtbl->Unacquire(M_DIDev1(A)) )
#define M_DIRelease(A) ( \
M_DIDevEx(A) ?\
M_DIDev2(A)->lpVtbl->Release(M_DIDev2(A)) \
: \
M_DIDev1(A)->lpVtbl->Release(M_DIDev1(A)) )
#define M_DIGetCaps(A,B) ( \
M_DIDevEx(A) ?\
M_DIDev2(A)->lpVtbl->GetCapabilities(M_DIDev2(A),B) \
: \
M_DIDev1(A)->lpVtbl->GetCapabilities(M_DIDev1(A),B) )
#define M_DIGetState(A,B,C) ( \
M_DIDevEx(A) ?\
M_DIDev2(A)->lpVtbl->GetDeviceState(M_DIDev2(A),B,C) \
: \
M_DIDev1(A)->lpVtbl->GetDeviceState(M_DIDev1(A),B,C) )
#define M_DIGetProp(A,B,C) ( \
M_DIDevEx(A) ?\
M_DIDev2(A)->lpVtbl->GetProperty(M_DIDev2(A),B,C) \
: \
M_DIDev1(A)->lpVtbl->GetProperty(M_DIDev1(A),B,C) )

View File

@@ -0,0 +1,22 @@
/******************************************************************************/
/* InoJoy.h : */
/* */
/* Author : JENTEY F. */
/* Last update : 01/12/97 */
/******************************************************************************/
#ifndef _JOYSTCIK_PRIVATE_H
#define _JOYSTCIK_PRIVATE_H
#include "InoMain.h"
extern short INO_fn_wReadJoystick(INO_tdhDevice hDev);
extern short INO_fn_wInitJoystickCaps(INO_tdhDevice hDev);
#endif /* _JOYSTCIK_PRIVATE_H */

View File

@@ -0,0 +1,22 @@
/******************************************************************************/
/* InoKeyb.h : */
/* */
/* Author : JENTEY F. */
/* Last update : 01/12/97 */
/******************************************************************************/
#ifndef _KEYBOARD_PRIVATE_H
#define _KEYBOARD_PRIVATE_H
#include "InoMain.h"
extern short INO_fn_wReadKeyboard(INO_tdhDevice hDev);
extern short INO_fn_wInitKeyboardCaps(INO_tdhDevice hDev);
#endif /* _KEYBOARD_PRIVATE_H */

View File

@@ -0,0 +1,21 @@
/******************************************************************************/
/* InoMouse.h : */
/* */
/* Author : JENTEY F. */
/* Last update : 01/12/97 */
/******************************************************************************/
#ifndef _MOUSE_PRIVATE_H
#define _MOUSE_PRIVATE_H
#include "InoMain.h"
extern short INO_fn_wReadMouse(INO_tdhDevice hDev);
extern short INO_fn_wInitMouseCaps(INO_tdhDevice hDev);
#endif /* _MOUSE_PRIVATE_H */

View File

@@ -0,0 +1,346 @@
/******************************************************************************
Joy.c : Definition of structures and Macros
PC Version
Author : M. TRABUCATO
Last update : 28.04.98
******************************************************************************/
/**************************************************************
Initialization of the Game port.
**************************************************************/
short INO_fn_wInitGamePort(short wHistorySize)
{
short wNbJoystick;
if ( JoyLib_tdstGp.m_wGameportOk == 1 )
return (0);
wNbJoystick = fn_wJoyGetMaxJoystickCount();
if ( wNbJoystick == 0 )
{
/* There is no gameport */
ulJoystickErrorCode = C_ErrNoJoystickDriver;
return (C_wJoyError);
}
memset(&JoyLib_tdstGp,0,sizeof(tdstGamePort));
memset(JoyLib_tdstJC,0,sizeof(tdstJoystickCaps*)*16);
memset(JoyLib_tdstJS,0,sizeof(tdstJoystickStatus*)*16);
JoyLib_tdstGp.m_wHistorySize = wHistorySize;
JoyLib_tdstGp.m_wNbMaxiJoystick = wNbJoystick;
JoyLib_tdstGp.m_wNbJoystick = 0;
JoyLib_tdstGp.m_wGameportOk = 1;
JoyLib_tdstGp.m_uwActiveFlag = 0;
/* Demo mode initialization: mode normal and 0 record frame */
JoyLib_pstDemoRecordBuffer = NULL;
JoyLib_wMode = C_wJoyNormalMode;
DemoRecordJoystick = C_wJoystick1;
return(0);
}
/*****************************************************************
Joystick query function
*****************************************************************/
/******************************************************************
short fn_wJoyReadJoystick(): read all connected joystick.
******************************************************************/
short INO_fn_wReadJoystick(short wReadMode)
{
u_short i,j;
short wResult;
JoyLib_tdstGp.m_ulTimeCount++;
/* Check if the gameport is Ok */
INO_fn_wUpdateGamePort();
if ( JoyLib_tdstGp.m_wGameportOk == 0 )
{
ulJoystickErrorCode = C_ErrDriverNotInitialized;
return (C_wJoyError);
}
for ( i = 0 ; i < JoyLib_tdstGp.m_wNbMaxiJoystick ; i++)
{
if ( (JoyLib_tdstGp.m_uwActiveFlag & (1 << i)) != 0 )
{
/* If the joystick isn't connected and the function mode is C_wJoyReadConnected */
/* skip this joystick */
if ( (wReadMode == C_wJoyReadConnected) && (JoyLib_tdstJC[i]->m_uwType == C_wJoyNone) )
break;
wResult = fn_wJoyGetJoystickState(i, JoyLib_tdstJS[i], JoyLib_tdstJC[i] );
if ( wResult == C_wJoyError )
JoyLib_tdstJC[i]->m_uwType = C_wJoyNone;
/* If we are currently in play demo mode */
/* Any button press stop the demo playing mode */
if ( JoyLib_wMode == C_wJoyDemoPlayingMode )
{
if ( (JoyLib_tdstJS[i]->m_ulButton != 0) || (JoyLib_ulDemoRecordCurrent >= JoyLib_ulDemoRecordCount) )
INO_fn_wStopJoystickDemo();
else
{
if ( i == DemoRecordJoystick )
{
tdstJoystickAxisValues* p_stTmp ,* p_stTmp2;
JoyLib_tdstJS[i]->m_ulButton = JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_ulButton;
JoyLib_tdstJS[i]->m_ulDirection = JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_ulDirection;
p_stTmp = &(JoyLib_tdstJS[i]->m_stAxisValues);
p_stTmp2 = &(JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_stAxisValues);
M_JoyCopyAxisValues(p_stTmp, p_stTmp2);
/*
JoyLib_tdstJS[i]->m_stAxisValues.m_uwXValue = JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_ulXValue;
JoyLib_tdstJS[i]->m_stAxisValues.m_uwYValue = JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_ulYValue;
JoyLib_tdstJS[i]->m_stAxisValues.m_uwZValue = JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_ulZValue;
JoyLib_tdstJS[i]->m_stAxisValues.m_uwRValue = JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_ulRValue;
JoyLib_tdstJS[i]->m_stAxisValues.m_uwUValue = JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_ulUValue;
JoyLib_tdstJS[i]->m_stAxisValues.m_uwVValue = JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCurrent].m_ulVValue;
*/
JoyLib_ulDemoRecordCurrent++;
}
}
}
/* In normal mode or record mode, analyse joystick*/
/* Check the activate directions */
else if ( wResult != C_wJoyError )
fn_vJoyUpdateDirection(i, JoyLib_tdstJS[i], JoyLib_tdstJC[i] );
/* If we are currently in Record demo mode */
if ( JoyLib_wMode == C_wJoyDemoRecordingMode )
{
if ( ((JoyLib_tdstJS[i]->m_ulExitRecordingModeButton & JoyLib_tdstJS[i]->m_ulButton) != 0)
|| (JoyLib_ulDemoRecordCount >= JoyLib_ulDemoMaxStep) )
INO_fn_wStopRecordingJoystick();
else
{
if ( i == DemoRecordJoystick )
{
JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_ulButton = JoyLib_tdstJS[i]->m_ulButton;
JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_ulDirection = JoyLib_tdstJS[i]->m_ulDirection;
M_JoyCopyAxisValues(
&(JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_stAxisValues),
&(JoyLib_tdstJS[i]->m_stAxisValues)
);
/*
JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_ulXValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwXValue;
JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_ulYValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwYValue;
JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_ulZValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwZValue;
JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_ulRValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwRValue;
JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_ulUValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwUValue;
JoyLib_pstDemoRecordBuffer[JoyLib_ulDemoRecordCount].m_ulVValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwVValue;
*/
JoyLib_ulDemoRecordCount++;
}
}
}
/* Update the historic */
if ( wResult != C_wJoyError )
{
if ( JoyLib_tdstJS[i]->m_uwValidRecordNumber == 0 )
{
JoyLib_tdstH[i][0].m_ulDirection = JoyLib_tdstJS[i]->m_ulDirection;
JoyLib_tdstH[i][0].m_ulButton = JoyLib_tdstJS[i]->m_ulButton;
M_JoyCopyAxisValues(
&(JoyLib_tdstH[i][0].m_stAxisValues),
&(JoyLib_tdstJS[i]->m_stAxisValues)
);
/*
JoyLib_tdstH[i][0].m_ulXValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwXValue;
JoyLib_tdstH[i][0].m_ulYValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwYValue;
JoyLib_tdstH[i][0].m_ulZValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwZValue;
JoyLib_tdstH[i][0].m_ulRValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwRValue;
JoyLib_tdstH[i][0].m_ulUValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwUValue;
JoyLib_tdstH[i][0].m_ulVValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwVValue;
*/
/*JoyLib_tdstH[i][0].m_ulTimeCount = JoyLib_tdstGp.m_ulTimeCount;*/
JoyLib_tdstJS[i]->m_ulLastTimeCount = JoyLib_tdstGp.m_ulTimeCount;
JoyLib_tdstJS[i]->m_uwValidRecordNumber = 1;
}
else
{
j = JoyLib_tdstJS[i]->m_uwHistoryHead;
/* if ( (JoyLib_tdstH[i][j].m_ulDirection != JoyLib_tdstJS[i]->m_ulDirection) ||
(JoyLib_tdstH[i][j].m_ulButton != JoyLib_tdstJS[i]->m_ulButton) )
{
*/
j++;
if ( j > JoyLib_tdstGp.m_wHistorySize-1 ) j = 0;
JoyLib_tdstH[i][j].m_ulDirection = JoyLib_tdstJS[i]->m_ulDirection;
JoyLib_tdstH[i][j].m_ulButton = JoyLib_tdstJS[i]->m_ulButton;
M_JoyCopyAxisValues(
&(JoyLib_tdstH[i][j].m_stAxisValues),
&(JoyLib_tdstJS[i]->m_stAxisValues)
);
/*
JoyLib_tdstH[i][j].m_ulXValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwXValue;
JoyLib_tdstH[i][j].m_ulYValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwYValue;
JoyLib_tdstH[i][j].m_ulZValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwZValue;
JoyLib_tdstH[i][j].m_ulRValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwRValue;
JoyLib_tdstH[i][j].m_ulUValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwUValue;
JoyLib_tdstH[i][j].m_ulVValue = JoyLib_tdstJS[i]->m_stAxisValues.m_uwVValue;
*/
/*JoyLib_tdstH[i][j].m_ulTimeCount = JoyLib_tdstGp.m_ulTimeCount;*/
JoyLib_tdstJS[i]->m_ulLastTimeCount = JoyLib_tdstGp.m_ulTimeCount;
JoyLib_tdstJS[i]->m_uwHistoryHead = j;
if ( JoyLib_tdstJS[i]->m_uwValidRecordNumber != JoyLib_tdstGp.m_wHistorySize )
JoyLib_tdstJS[i]->m_uwValidRecordNumber++;
}
}
}
}
return (0);
}
/**************************************************************
**************************************************************/
/**************************************************************
Return the current position of the joystick along the specified axis
The return value is a double contained between -1.0 to 1.0.
**************************************************************/
short INO_fn_wGetJoystickCurrentPosition(short wJoystickNum, short wAxis, double *pdfPosition)
{
double dfPosition, dfMiddle, dfRange;
if ( JoyLib_tdstGp.m_wGameportOk == 0 )
{
ulJoystickErrorCode = C_ErrDriverNotInitialized;
return (C_wJoyError);
}
if ( (wJoystickNum < C_wJoystick1) || (wJoystickNum > C_wJoystick16) )
{
ulJoystickErrorCode = C_ErrBadJoystick;
return (C_wJoyError);
}
if ( (JoyLib_tdstGp.m_uwActiveFlag & (1 << wJoystickNum)) == 0 )
{
ulJoystickErrorCode = C_ErrJoystickNotActive;
return (C_wJoyError);
}
switch (wAxis)
{
case C_ulJoyX:
dfPosition = (double)M_JoyX(JoyLib_tdstJS[wJoystickNum]);
dfRange = (double)(M_JoyXMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyXMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyXMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyXMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyY:
dfPosition = (double)M_JoyY(JoyLib_tdstJS[wJoystickNum]);
dfRange = (double)(M_JoyYMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyYMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyYMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyYMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyZ:
dfPosition = (double)M_JoyZ(JoyLib_tdstJS[wJoystickNum]);
dfRange = (double)(M_JoyZMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyZMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyZMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyZMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyR:
dfPosition = (double)M_JoyR(JoyLib_tdstJS[wJoystickNum]);
dfRange = (double)(M_JoyRMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyRMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyRMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyRMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyU:
dfPosition = (double)M_JoyU(JoyLib_tdstJS[wJoystickNum]);
dfRange = (double)(M_JoyUMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyUMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyUMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyUMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyV:
dfPosition = (double)M_JoyV(JoyLib_tdstJS[wJoystickNum]);
dfRange = (double)(M_JoyVMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyVMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyVMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyVMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
default:
return (C_wJoyError);
}
dfPosition -= dfMiddle;
*pdfPosition = dfPosition / dfRange;
return (0);
}
/**************************************************************
Return the current position of the joystick along the specified axis
The return value is a double contained between -1.0 to 1.0.
**************************************************************/
#ifndef _FIRE_DEADCODE_U64_
short INO_fn_wGetJoystickPreviousPosition(short wJoystickNum, short wAxis, short wHistoryNum, double *pdfPosition)
{
long iIndex;
double dfPosition,dfRange,dfMiddle;
if ( JoyLib_tdstGp.m_wGameportOk == 0 )
{
ulJoystickErrorCode = C_ErrDriverNotInitialized;
return (C_wJoyError);
}
if ( (wJoystickNum < C_wJoystick1) || (wJoystickNum > C_wJoystick16) )
{
ulJoystickErrorCode = C_ErrBadJoystick;
return (C_wJoyError);
}
if ( (JoyLib_tdstGp.m_uwActiveFlag & (1 << wJoystickNum)) == 0 )
{
ulJoystickErrorCode = C_ErrJoystickNotActive;
return (C_wJoyError);
}
if ( wHistoryNum > JoyLib_tdstJS[wJoystickNum]->m_uwValidRecordNumber )
{
ulJoystickErrorCode = C_ErrJoyHistoricOverflow;
return (C_wJoyError);
}
iIndex = JoyLib_tdstJS[wJoystickNum]->m_uwHistoryHead - wHistoryNum;
switch (wAxis)
{
case C_ulJoyX:
dfPosition = (double)M_JoyX(&(JoyLib_tdstH[wJoystickNum][iIndex]));
dfRange = (double)(M_JoyXMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyXMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyXMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyXMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyY:
dfPosition = (double)M_JoyY(&(JoyLib_tdstH[wJoystickNum][iIndex]));
dfRange = (double)(M_JoyYMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyYMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyYMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyYMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyZ:
dfPosition = (long)M_JoyZ(&(JoyLib_tdstH[wJoystickNum][iIndex]));
dfRange = (double)(M_JoyZMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyZMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyZMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyZMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyR:
dfPosition = (double)M_JoyR(&(JoyLib_tdstH[wJoystickNum][iIndex]));
dfRange = (double)(M_JoyRMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyRMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyRMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyRMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyU:
dfPosition = (double)M_JoyU(&(JoyLib_tdstH[wJoystickNum][iIndex]));
dfRange = (double)(M_JoyUMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyUMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyUMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyUMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
case C_ulJoyV:
dfPosition = (double)M_JoyV(&(JoyLib_tdstH[wJoystickNum][iIndex]));
dfRange = (double)(M_JoyVMax(JoyLib_tdstJC[wJoystickNum]) - M_JoyVMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
dfMiddle = (double)(M_JoyVMax(JoyLib_tdstJC[wJoystickNum]) + M_JoyVMin(JoyLib_tdstJC[wJoystickNum])) / 2.0;
break;
default:
return (C_wJoyError);
}
dfPosition -= dfMiddle;
*pdfPosition = dfPosition / dfRange;
return (0);
}
#endif /* _FIRE_DEADCODE_U64_ */

View File

@@ -0,0 +1,248 @@
/***************************************************************************/
/* Description: JoyDI.c, part of CPA INO library */
/* Joystick specific implementation */
/* */
/* Author: F. Jentey */
/* Last Update: 05/03/97 */
/***************************************************************************/
#include "INO\errINO.h"
#include "InitDI.h"
#include "INOInit.h"
#include "Joystick.h"
/**********************************************************************************/
/* Fill the p_stJoyCaps with the capabilities of the specified joystick */
/* Return an error if unable to get these information. */
/* It usually happens when the joystick isn't configurated in the control panel, */
/* but could also appear with some joystick if the joystick isn't connected. */
/**********************************************************************************/
short INO_fn_wInitJoystickCaps(INO_tdhDevice hDev)
{
HRESULT DInputErr;
DIPROPRANGE stAxisRange;
DWORD a_ulAxis[INO_C_wNbMaxAxis] = { DIJOFS_X, DIJOFS_Y, DIJOFS_Z, DIJOFS_RX, DIJOFS_RY, DIJOFS_RZ };
short i, wDev;
INO_tdstJoystickCaps *p_stJoyCaps = (INO_tdstJoystickCaps*)(hDev->m_p_stCaps);
unsigned long ulSubType;
for (i=0; i<INO_C_wNbMaxDevice; i++)
if (INO_g_a_stDIDevice[i].m_hDevice == hDev) break;
if (i == INO_C_wNbMaxDevice) return (0);
wDev = i;
ulSubType = INO_fn_wFillDeviceCaps(hDev);
if (!ulSubType) return(0);
/* Joystick sub-type */
switch (ulSubType)
{
case DIDEVTYPEJOYSTICK_TRADITIONAL:
case DIDEVTYPEJOYSTICK_GAMEPAD:
hDev->m_uwType |= INO_C_uwSubTypeJoypad;
break;
case DIDEVTYPEJOYSTICK_FLIGHTSTICK:
case DIDEVTYPEJOYSTICK_RUDDER:
hDev->m_uwType |= INO_C_uwSubTypeJoystick;
break;
case DIDEVTYPEJOYSTICK_WHEEL:
hDev->m_uwType |= INO_C_uwSubTypeSteeringWheel;
break;
case DIDEVTYPEJOYSTICK_HEADTRACKER:
default:
hDev->m_uwType |= INO_C_uwUnknown;
}
/* Get Axis capabilities */
for (i=0; i<INO_C_wNbMaxAxis; i++)
{
stAxisRange.diph.dwSize = sizeof(DIPROPRANGE);
stAxisRange.diph.dwHeaderSize = sizeof(DIPROPHEADER);
stAxisRange.diph.dwHow = DIPH_BYOFFSET;
stAxisRange.diph.dwObj = a_ulAxis[i];
DInputErr = M_DIGetProp(wDev,DIPROP_RANGE,&stAxisRange.diph);
switch (DInputErr)
{
case DI_OK:
p_stJoyCaps->m_a_stAxisCaps[i].m_lCenter = ((stAxisRange.lMax + stAxisRange.lMin) >> 1);
p_stJoyCaps->m_a_stAxisCaps[i].m_lRange = ((stAxisRange.lMax - stAxisRange.lMin) >> 1);
p_stJoyCaps->m_a_stAxisCaps[i].m_lThreshold = p_stJoyCaps->m_a_stAxisCaps[i].m_lRange >> 1;
p_stJoyCaps->m_ulCapsFlags |= 1 << i;
break;
case DIERR_OBJECTNOTFOUND:
break;
case DIERR_UNSUPPORTED:
case DIERR_INVALIDPARAM:
case DIERR_NOTINITIALIZED:
default:
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
return (0);
}
}
return (1);
}
/**********************************************************************************/
/* GET JOYSTICK STATE USING DURECT INPUT 5 */
/* Fill the p_stJoyState with the state of the specified joystick */
/* Return an error if unable to get these information. */
/* It usually happens when the joystick isn't configurated in the control panel, */
/* but could also appear with some joystick if the joystick isn't connected. */
/**********************************************************************************/
short INO_fn_wReadJoystick(INO_tdhDevice hDev)
{
HRESULT DInputErr;
DIJOYSTATE stJoyState;
short wDev, i;
INO_tdstJoystickState *p_stJoyState = (INO_tdstJoystickState*)(hDev->m_p_stState);
INO_tdstAxisCaps *p_stAxes = (INO_tdstAxisCaps*)&(((INO_tdstJoystickCaps*)(hDev->m_p_stCaps))->m_a_stAxisCaps);
INO_tdstJoystickRecord *p_stH = (INO_tdstJoystickRecord*)hDev->m_pvHistoric;
if (!INO_M_bIsConnected(hDev))
return (0);
for (i=0; i<INO_C_wNbMaxDevice; i++)
if (INO_g_a_stDIDevice[i].m_hDevice == hDev) break;
if (i == INO_C_wNbMaxDevice)
{
INO_fn_vUpdateLastError(E_uwINO_WarningInvalidDevice);
return (0);
}
wDev = i;
/* First, reacquired the joystick if necessary */
if (!(p_stJoyState->m_ucStatus & INO_C_ucAcquired) ||
(p_stJoyState->m_ucStatus & INO_C_ucAccessError) )
{
DInputErr = M_DIAcquire(wDev);
switch (DInputErr)
{
case DI_OK:
case S_FALSE:
p_stJoyState->m_ucStatus |= INO_C_ucAcquired;
p_stJoyState->m_ucStatus &= ~INO_C_ucAccessError;
break;
case DIERR_INPUTLOST:
case DIERR_NOTACQUIRED:
case DIERR_OTHERAPPHASPRIO:
return (0);
default:
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
p_stJoyState->m_ucStatus &= ~INO_C_ucAcquired;
p_stJoyState->m_ucStatus |= INO_C_ucAccessError;
return (0);
}
}
/* If the direct input extended interface is available, call Poll method */
/* before getting joystick state */
if (M_DIDevEx(wDev))
{
DInputErr = M_DIDev2(wDev)->lpVtbl->Poll(M_DIDev2(wDev));
switch (DInputErr)
{
case DI_OK:
case S_FALSE:
break;
case DIERR_INPUTLOST:
case DIERR_NOTACQUIRED:
p_stJoyState->m_ucStatus &= ~INO_C_ucAcquired;
return (0);
default:
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
p_stJoyState->m_ucStatus &= ~INO_C_ucAcquired;
p_stJoyState->m_ucStatus |= INO_C_ucAccessError;
return (0);
}
}
/* Get joystick state */
DInputErr = M_DIGetState(wDev,sizeof(DIJOYSTATE),&stJoyState);
switch (DInputErr)
{
case DI_OK:
case E_PENDING:
break;
case DIERR_INPUTLOST:
case DIERR_NOTACQUIRED:
p_stJoyState->m_ucStatus &= ~INO_C_ucAcquired;
return (0);
default:
p_stJoyState->m_ucStatus |= INO_C_ucAccessError;
p_stJoyState->m_ucStatus &= ~INO_C_ucAcquired;
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
return (0);
}
/* Read axes informations */
p_stJoyState->m_a_lAxisValue[0] = stJoyState.lX - p_stAxes[0].m_lCenter;
p_stJoyState->m_a_lAxisValue[1] = stJoyState.lY - p_stAxes[1].m_lCenter;
p_stJoyState->m_a_lAxisValue[2] = stJoyState.lZ - p_stAxes[2].m_lCenter;
p_stJoyState->m_a_lAxisValue[3] = stJoyState.lRx - p_stAxes[3].m_lCenter;
p_stJoyState->m_a_lAxisValue[4] = stJoyState.lRy - p_stAxes[4].m_lCenter;
p_stJoyState->m_a_lAxisValue[5] = stJoyState.lRz - p_stAxes[5].m_lCenter;
p_stJoyState->m_uwDirections = 0;
/* Update X direction */
if (p_stJoyState->m_a_lAxisValue[0] < -p_stAxes[0].m_lThreshold)
p_stJoyState->m_uwDirections |= INO_C_uwLeft;
else
if (p_stJoyState->m_a_lAxisValue[0] > p_stAxes[0].m_lThreshold)
p_stJoyState->m_uwDirections |= INO_C_uwRight;
/* Update Y direction */
if (p_stJoyState->m_a_lAxisValue[1] > p_stAxes[1].m_lThreshold)
p_stJoyState->m_uwDirections |= INO_C_uwDown;
else
if (p_stJoyState->m_a_lAxisValue[1] < -p_stAxes[1].m_lThreshold)
p_stJoyState->m_uwDirections |= INO_C_uwUp;
/* Update Z direction */
if (p_stJoyState->m_a_lAxisValue[2] < -p_stAxes[2].m_lThreshold)
p_stJoyState->m_uwDirections |= INO_C_uwZDown;
else
if (p_stJoyState->m_a_lAxisValue[2] > p_stAxes[2].m_lThreshold)
p_stJoyState->m_uwDirections |= INO_C_uwZUp;
/* Copy buttons info */
p_stJoyState->m_ulButtons = 0;
for (i=0; i<hDev->m_p_stCaps->m_ucNbButtons; i++)
if (stJoyState.rgbButtons[i] & INO_C_ucButtonDown)
p_stJoyState->m_ulButtons |= 1 << i;
/* Update historic. */
if (hDev->m_wRecordNumber == 0)
{
p_stH[0].m_ulDate = hDev->m_ulLastTimeCount;
p_stH[0].m_ulButtons = p_stJoyState->m_ulButtons;
p_stH[0].m_uwDirections = p_stJoyState->m_uwDirections;
hDev->m_wRecordNumber = 1;
}
else
{
hDev->m_wHistoricHead++;
if (hDev->m_wHistoricHead == hDev->m_wHistoricSize) hDev->m_wHistoricHead = 0;
if (hDev->m_wRecordNumber != hDev->m_wHistoricSize) hDev->m_wRecordNumber++;
p_stH[hDev->m_wHistoricHead].m_ulDate = hDev->m_ulLastTimeCount;
p_stH[hDev->m_wHistoricHead].m_ulButtons = p_stJoyState->m_ulButtons;
p_stH[hDev->m_wHistoricHead].m_uwDirections = p_stJoyState->m_uwDirections;
}
return (1);
}

View File

@@ -0,0 +1,364 @@
/***************************************************************************/
/* Description: CPA Joystick.lib. Implementation of the privates */
/* for the Windows version */
/* Author: F. Jentey */
/* Last Update: 05/03/97 */
/***************************************************************************/
#include <stdio.h>
#include "../Specif/JoyWin.h"
#include "INO/Joystick.h"
#define SEUIL 50
/*
fn_wJoyGetMaxJoystickCount: return the number of joystick gameport can support
return 0 if there is no gameport.
*/
short fn_wJoyGetMaxJoystickCount()
{
return (joyGetNumDevs());
}
/*
Fill the p_stJoyCaps with the capabilities of the specified joystick
Return an error if unable to get these information.
It usually happens when the joystick isn't configurated in the control panel,
but could also appear with some joystcik if the joystick isn't connected.
*/
short fn_wJoyGetJoystickCaps( short wJoystickNum, tdstJoystickCaps* p_stJoyCaps )
{
MMRESULT err;
JOYCAPS JoyCaps;
err = joyGetDevCaps(wJoystickNum, &JoyCaps, sizeof(JOYCAPS));
switch ( err )
{
case JOYERR_NOERROR:
break;
case MMSYSERR_INVALPARAM:
case MMSYSERR_NODRIVER:
default:
return (C_wJoyError);
break;
}
p_stJoyCaps->m_uwMid = JoyCaps.wMid;
p_stJoyCaps->m_uwPid = JoyCaps.wPid;
/* CHRISTOPHE PAD NT 4 RAYMAN II MODIFICATIONS {*/
#ifdef _PAD_NT
p_stJoyCaps->m_uwNbButton = 6;
#else
p_stJoyCaps->m_uwNbButton = JoyCaps.wNumButtons;
#endif _PAD_NT
/* } END CHRISTOPHE PAD NT 4 RAYMAN II MODIFICATIONS*/
p_stJoyCaps->m_stAxisCaps.m_uwXmin = JoyCaps.wXmin;
p_stJoyCaps->m_stAxisCaps.m_uwXmax = JoyCaps.wXmax;
p_stJoyCaps->m_stAxisCaps.m_uwXdown = (JoyCaps.wXmin + JoyCaps.wXmax)/2
- ((JoyCaps.wXmax - JoyCaps.wXmin)*SEUIL)/200;
p_stJoyCaps->m_stAxisCaps.m_uwXup = (JoyCaps.wXmin + JoyCaps.wXmax)/2
+ ((JoyCaps.wXmax - JoyCaps.wXmin)*SEUIL)/200;
p_stJoyCaps->m_stAxisCaps.m_uwYmin = JoyCaps.wYmin;
p_stJoyCaps->m_stAxisCaps.m_uwYmax = JoyCaps.wYmax;
p_stJoyCaps->m_stAxisCaps.m_uwYdown = (JoyCaps.wYmin + JoyCaps.wYmax)/2
+ ((JoyCaps.wYmax - JoyCaps.wYmin)*SEUIL)/200;
p_stJoyCaps->m_stAxisCaps.m_uwYup = (JoyCaps.wYmin + JoyCaps.wYmax)/2
- ((JoyCaps.wYmax - JoyCaps.wYmin)*SEUIL)/200;
p_stJoyCaps->m_uwNbAxe = JoyCaps.wNumAxes;
if ( JoyCaps.wNumAxes > 2 )
{
if ( JoyCaps.wCaps & JOYCAPS_HASZ != 0)
{
p_stJoyCaps->m_uwNbAxe++;
p_stJoyCaps->m_ulCapsFlag |= C_ulJoyZ;
p_stJoyCaps->m_stAxisCaps.m_uwZmin = JoyCaps.wZmin;
p_stJoyCaps->m_stAxisCaps.m_uwZmax = JoyCaps.wZmax;
p_stJoyCaps->m_stAxisCaps.m_uwZdown = (JoyCaps.wZmin + JoyCaps.wZmax)/2
- ((JoyCaps.wZmax - JoyCaps.wZmin)*SEUIL)/200;
p_stJoyCaps->m_stAxisCaps.m_uwZup = (JoyCaps.wZmin + JoyCaps.wZmax)/2
+ ((JoyCaps.wZmax - JoyCaps.wZmin)*SEUIL)/200;
}
/* CHRISTOPHE MODIFICATIONS 02/05/98 { */
#ifdef _PAD_NT
/* TEST THE RUDDER AXIS*/
if ( JoyCaps.wCaps & JOYCAPS_HASR != 0)
{
p_stJoyCaps->m_uwNbAxe++;
p_stJoyCaps->m_ulCapsFlag |= C_ulJoyR;
p_stJoyCaps->m_stAxisCaps.m_uwRmin = JoyCaps.wRmin;
p_stJoyCaps->m_stAxisCaps.m_uwRmax = JoyCaps.wRmax;
p_stJoyCaps->m_stAxisCaps.m_uwRdown = (JoyCaps.wRmin + JoyCaps.wRmax)/2
- ((JoyCaps.wRmax - JoyCaps.wRmin)*SEUIL)/200;
p_stJoyCaps->m_stAxisCaps.m_uwRup = (JoyCaps.wRmin + JoyCaps.wRmax)/2
+ ((JoyCaps.wRmax - JoyCaps.wRmin)*SEUIL)/200;
}
#endif _PAD_NT
/* } END CHRISTOPHE MODIFICATIONS 02/05/98 */
/* TO DO : test the other axis */
}
/* Useless
joySetThreshold(wJoystickNum, 4000);
*/
return (0);
}
/*
Fill the p_stJoyState with the state of the specified joystick
Return an error if unable to get these information.
It usually happens when the joystick isn't configurated in the control panel,
but could also appear with some joystick if the joystick isn't connected.
*/
short fn_wJoyGetJoystickState(
short wJoystickNum,
tdstJoystickStatus* p_stJoyState,
tdstJoystickCaps* p_stJoyCaps
)
{
MMRESULT err;
JOYINFOEX jie;
memset(&jie,0,sizeof(jie));
jie.dwSize = sizeof(jie);
/* CHRISTOPHE MODIFICATIONS PAD NT 4 RAYMAN II }*/
#ifdef _PAD_NT
jie.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNZ | JOY_RETURNR |JOY_RETURNBUTTONS;
#else
jie.dwFlags = JOY_RETURNX | JOY_RETURNY | JOY_RETURNBUTTONS;
#endif _PAD_NT
/* { END CHRISTOPHE MODIFICATION PAD NT 4 RAYMAN II*/
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyZ) != 0 )
jie.dwFlags |= JOY_RETURNZ;
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyR) != 0 )
jie.dwFlags |= JOY_RETURNR;
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyU) != 0 )
jie.dwFlags |= JOY_RETURNU;
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyV) != 0 )
jie.dwFlags |= JOY_RETURNV;
/* TO DO: add support of the other capabilities (pov) */
/* Read joystich state */
err = joyGetPosEx(wJoystickNum, &jie);
/* Check if plugged */
switch ( err )
{
case JOYERR_NOERROR:
break;
case JOYERR_UNPLUGGED:
/* The specified joystick is not connected to the computer. */
case MMSYSERR_BADDEVICEID:
/* The specified joystick identifier is invalid. */
case MMSYSERR_INVALPARAM:
/* An invalid parameter was passed. */
case MMSYSERR_NODRIVER:
/* The joystick driver is not present. */
default:
return (C_wJoyError);
break;
}
/* Copy button info */
p_stJoyState->m_ulButton = jie.dwButtons;
/* Read X and Y informations */
p_stJoyState->m_stAxisValues.m_uwXValue = (u_short)jie.dwXpos;
p_stJoyState->m_stAxisValues.m_uwYValue = (u_short)jie.dwYpos;
/* CHRISTOPHE PAD NT MODIFICATIONS 4 RAYMAN II {*/
/* Read Z information */
/* if ( p_stJoyCaps->m_ulCapsFlag & C_ulJoyZ != 0 )*/
/* p_stJoyState->m_stAxisValues.m_uwZValue = (u_short)jie.dwZpos;*/
#ifdef _PAD_NT
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyZ) != 0 )
{
p_stJoyState->m_stAxisValues.m_uwZValue = (u_short)jie.dwZpos;
if( p_stJoyState->m_stAxisValues.m_uwZValue < (0xffff/2) )
{
p_stJoyState->m_ulButton |= 16;
}
}
#endif _PAD_NT
/* Read R information */
/* if ( p_stJoyCaps->m_ulCapsFlag & C_ulJoyR != 0 )*/
/* p_stJoyState->m_stAxisValues.m_uwRValue = (u_short)jie.dwRpos;*/
#ifdef _PAD_NT
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyR) != 0 )
{
p_stJoyState->m_stAxisValues.m_uwRValue = (u_short)jie.dwRpos;
if( p_stJoyState->m_stAxisValues.m_uwRValue < (0xffff/2) )
{
p_stJoyState->m_ulButton |= 32;
}
}
#endif _PAD_NT
/* Read U information */
/* if ( p_stJoyCaps->m_ulCapsFlag & C_ulJoyU != 0 )*/
/* p_stJoyState->m_stAxisValues.m_uwUValue = (u_short)jie.dwUpos;*/
/* Read U information */
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyU) != 0 )
p_stJoyState->m_stAxisValues.m_uwUValue = (u_short)jie.dwUpos;
/* Read V information */
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyV) != 0 )
p_stJoyState->m_stAxisValues.m_uwVValue = (u_short)jie.dwVpos;
/* Read V information */
/* if ( p_stJoyCaps->m_ulCapsFlag & C_ulJoyV != 0 )*/
/* p_stJoyState->m_stAxisValues.m_uwVValue = (u_short)jie.dwVpos;*/
/* Copy button info */
/* p_stJoyState->m_ulButton = jie.dwButtons;*/
/* } END CHRISTOPHE MODIFICATIONS PAD NT 4 RAYMAN II*/
return (0);
}
void fn_vJoyUpdateDirection(
short wJoystickNum,
tdstJoystickStatus* p_stJoyState,
tdstJoystickCaps* p_stJoyCaps
)
{
p_stJoyState->m_ulDirection = 0;
/* Update X direction */
if ( p_stJoyState->m_stAxisValues.m_uwXValue < p_stJoyCaps->m_stAxisCaps.m_uwXdown )
p_stJoyState->m_ulDirection |= C_ulJoyLeft;
else
if ( p_stJoyState->m_stAxisValues.m_uwXValue > p_stJoyCaps->m_stAxisCaps.m_uwXup )
p_stJoyState->m_ulDirection |= C_ulJoyRight;
/* Update Y direction */
if ( p_stJoyState->m_stAxisValues.m_uwYValue > p_stJoyCaps->m_stAxisCaps.m_uwYdown )
p_stJoyState->m_ulDirection |= C_ulJoyDown;
else
if ( p_stJoyState->m_stAxisValues.m_uwYValue < p_stJoyCaps->m_stAxisCaps.m_uwYup )
p_stJoyState->m_ulDirection |= C_ulJoyUp;
#ifndef _PAD_NT
/* Update Z direction */
if ( (p_stJoyCaps->m_ulCapsFlag & C_ulJoyZ) != 0 )
{
if ( p_stJoyState->m_stAxisValues.m_uwZValue < p_stJoyCaps->m_stAxisCaps.m_uwZdown )
p_stJoyState->m_ulDirection |= C_ulJoyZDown;
else
if ( p_stJoyState->m_stAxisValues.m_uwZValue > p_stJoyCaps->m_stAxisCaps.m_uwZup )
p_stJoyState->m_ulDirection |= C_ulJoyZUp;
}
#endif _PAD_NT
/*
if ( p_stJoyCaps->m_ulCapsFlag & C_ulJoyZ != 0 )
{
if ( p_stJoyState->m_stAxisValues.m_uwZValue < p_stJoyCaps->m_stAxisCaps.m_uwZdown )
p_stJoyState->m_ulDirection |= C_ulJoyZDown;
else
if ( p_stJoyState->m_stAxisValues.m_uwZValue > p_stJoyCaps->m_stAxisCaps.m_uwZup )
p_stJoyState->m_ulDirection |= C_ulJoyZUp;
}
*/
}
/*
Return C_wJoyTrue if the specified joystick is conected else C_wJoyFalse
Return C_wJoyError if an error occured
*/
short fn_wJoyCheckConnection( short wJoystickNum )
{
MMRESULT err;
JOYINFOEX jie;
memset(&jie,0,sizeof(jie));
jie.dwSize = sizeof(jie);
err = joyGetPosEx(wJoystickNum,&jie);
if ( (err != JOYERR_NOERROR) && (err != JOYERR_UNPLUGGED) )
return (C_wJoyError);
else
{
if ( err != JOYERR_NOERROR )
return (C_wJoyFalse);
else
return (C_wJoyTrue);
}
}
/*
Return the productName in pszName
*/
short fn_wJoyGetOEMProductName( short wJoystickNum, char *pszName )
{
JOYCAPS JoyCaps;
TCHAR szKey[256];
TCHAR szValue[256];
TCHAR szOEMKey[256];
HKEY hKey;
DWORD dwcb;
LONG lr;
joyGetDevCaps(wJoystickNum,&JoyCaps,sizeof(JOYCAPS));
wJoystickNum++;
sprintf(szKey,"%s\\%s\\%s",REGSTR_PATH_JOYCONFIG,JoyCaps.szRegKey,REGSTR_KEY_JOYCURR);
lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPTSTR)&szKey,0,KEY_ALL_ACCESS,&hKey);
if (lr != ERROR_SUCCESS )
return (C_wJoyError);
dwcb = sizeof(szOEMKey);
sprintf(szValue, "Joystick%d%s", wJoystickNum, REGSTR_VAL_JOYOEMNAME);
lr = RegQueryValueEx(hKey, szValue,0 ,0 ,(LPBYTE) &szOEMKey, (LPDWORD) &dwcb);
RegCloseKey(hKey);
if (lr != ERROR_SUCCESS )
{
*pszName = 0;
return (C_wJoyError);
}
sprintf(szKey,"%s\\%s",REGSTR_PATH_JOYOEM,szOEMKey);
lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey,0,KEY_ALL_ACCESS,&hKey);
if (lr != ERROR_SUCCESS )
return (C_wJoyError);
dwcb = sizeof(szValue);
lr = RegQueryValueEx(hKey, REGSTR_VAL_JOYOEMNAME,0 ,0 ,(LPBYTE) pszName, (LPDWORD) &dwcb);
RegCloseKey(hKey);
if (lr != ERROR_SUCCESS )
return (C_wJoyError);
else
return (0);
}

View File

@@ -0,0 +1,254 @@
/******************************************************************************/
/* JoyWin.h : Private definitions and functions for the Window version */
/* */
/* Author : JENTEY F. */
/* Last update : 06/03/97 */
/******************************************************************************/
#ifndef _JOYSTICK_WIN_H
#define _JOYSTICK_WIN_H
#include <windows.h>
#include <mmsystem.h>
#include <regstr.h>
#include <stdio.h>
/******************************************************************************/
/* Platform dependant structures */
/******************************************************************************/
/*
tdstJoystickAxisCaps
Defines the min, max, up and down threshold values
*/
typedef struct _tdstJoystickAxisCaps
{
u_short m_uwXmin;
u_short m_uwXmax;
u_short m_uwXup;
u_short m_uwXdown;
u_short m_uwYmin;
u_short m_uwYmax;
u_short m_uwYup;
u_short m_uwYdown;
u_short m_uwZmin;
u_short m_uwZmax;
u_short m_uwZup;
u_short m_uwZdown;
u_short m_uwRmin;
u_short m_uwRmax;
/* CHRISTOPHE PAD NT MODIFICATIONS 4 RAYMAN II */
#ifdef _PAD_NT
u_short m_uwRup;
u_short m_uwRdown;
#endif _PAD_NT
/* END CHRISTOPHE PAD NT MODIFICATIONS 4 RAYMAN II */
u_short m_uwUmin;
u_short m_uwUmax;
u_short m_uwVmin;
u_short m_uwVmax;
} tdstJoystickAxisCaps;
/*
tdstJoystickAxisValues
Structure use to store axis position
*/
typedef struct _tdstJoystickAxisValues
{
u_short m_uwXValue;
u_short m_uwYValue;
u_short m_uwZValue;
u_short m_uwRValue;
u_short m_uwUValue;
u_short m_uwVValue;
} tdstJoystickAxisValues;
#define M_JoyCopyAxisValues( p_stA, p_stB ) \
{ (p_stA)->m_uwXValue = (p_stB)->m_uwXValue; \
(p_stA)->m_uwYValue = (p_stB)->m_uwYValue; \
(p_stA)->m_uwZValue = (p_stB)->m_uwZValue; \
(p_stA)->m_uwRValue = (p_stB)->m_uwRValue; \
(p_stA)->m_uwUValue = (p_stB)->m_uwUValue; \
(p_stA)->m_uwVValue = (p_stB)->m_uwVValue; }
/******************************************************************************/
/* Common structures */
/******************************************************************************/
/*
tdsGamePortCaps : Game Port features
*/
typedef struct _tdstGamePort
{
/* This flag indicates if the game port if initialized */
short m_wGameportOk;
/* Number of joystick supported by the driver */
short m_wNbMaxiJoystick;
/* Number of Allocated joystick */
short m_wNbJoystick;
/* Define whose joystick features the game will try to use */
u_long m_ulGameFeatures;
/* Define whose joystick are active */
u_short m_uwActiveFlag;
/* A counter that is incremented each time the fnReadGamePort function is called */
u_long m_ulTimeCount;
/* Define the number of joystick previous states stored in the history */
short m_wHistorySize;
} tdstGamePort;
/*
tdstJoystickCaps : joystick features
*/
typedef struct _tdstJoystickCaps
{
u_short m_uwPid;
u_short m_uwMid;
u_short m_uwNbAxe;
u_short m_uwNbButton;
u_long m_ulCapsFlag;
u_short m_uwType;
tdstJoystickAxisCaps m_stAxisCaps;
} tdstJoystickCaps;
/* Macros to get private members with a tdstJoystickCaps pointer */
#define M_JoyXMax(A) (A)->m_stAxisCaps.m_uwXmax
#define M_JoyXMin(A) (A)->m_stAxisCaps.m_uwXmin
#define M_JoyXUp(A) (A)->m_stAxisCaps.m_uwXup
#define M_JoyXDown(A) (A)->m_stAxisCaps.m_uwXDown
#define M_JoyYMax(A) (A)->m_stAxisCaps.m_uwYmax
#define M_JoyYMin(A) (A)->m_stAxisCaps.m_uwYmin
#define M_JoyYUp(A) (A)->m_stAxisCaps.m_uwYup
#define M_JoyYDown(A) (A)->m_stAxisCaps.m_uwYDown
#define M_JoyZMax(A) (A)->m_stAxisCaps.m_uwZmax
#define M_JoyZMin(A) (A)->m_stAxisCaps.m_uwZmin
#define M_JoyZUp(A) (A)->m_stAxisCaps.m_uwZup
#define M_JoyZDown(A) (A)->m_stAxisCaps.m_uwZDown
#define M_JoyRMax(A) (A)->m_stAxisCaps.m_uwRmax
#define M_JoyRMin(A) (A)->m_stAxisCaps.m_uwRmin
#define M_JoyUMax(A) (A)->m_stAxisCaps.m_uwUmax
#define M_JoyUMin(A) (A)->m_stAxisCaps.m_uwUmin
#define M_JoyVMax(A) (A)->m_stAxisCaps.m_uwVmax
#define M_JoyVMin(A) (A)->m_stAxisCaps.m_uwVmin
/*
tdstJoystickStatus : joystick status informations
*/
typedef struct _stJoystickStatus
{
u_long m_ulDirection;
u_long m_ulButton;
u_long m_ulLastTimeCount;
u_short m_uwHistoryHead;
u_short m_uwValidRecordNumber;
u_long m_ulExitRecordingModeButton;
tdstJoystickAxisValues m_stAxisValues;
} tdstJoystickStatus;
/* Macros to get private members with a tdstJoystickStatus pointer */
#define M_JoyX(A) (A)->m_stAxisValues.m_uwXValue
#define M_JoyY(A) (A)->m_stAxisValues.m_uwYValue
#define M_JoyZ(A) (A)->m_stAxisValues.m_uwZValue
#define M_JoyR(A) (A)->m_stAxisValues.m_uwRValue
#define M_JoyU(A) (A)->m_stAxisValues.m_uwUValue
#define M_JoyV(A) (A)->m_stAxisValues.m_uwVValue
/*
tdsJoystickRecord : data structure for joystick historic and demo record
*/
typedef struct _tdstJoystickRecord
{
u_long m_ulDirection;
u_long m_ulButton;
tdstJoystickAxisValues m_stAxisValues;
/* u_long m_ulTimeCount;*/
} tdstJoystickRecord;
/*******************************************************************************/
/* Private function for the Window version */
/*******************************************************************************/
/*
fn_wJoyGetMaxJoystickCount: return the number of joystick gameport can support
return 0 if there is no gameport.
*/
extern short fn_wJoyGetMaxJoystickCount();
/*
Fill the p_stJoyCaps with the capabilities of the specified joystick
Return an error if unable to get these information.
It usually happens when the joystick isn't configurated in the control panel,
but could also appear with some joystcik if the joystick isn't connected.
*/
extern short fn_wJoyGetJoystickCaps( short wJoystickNum, tdstJoystickCaps* p_stJoyCaps );
/*
Fill the p_stJoyState with the state of the specified joystick
Return an error if unable to get these information.
It usually happens when the joystick isn't configurated in the control panel,
but could also appear with some joystick if the joystick isn't connected.
*/
extern short fn_wJoyGetJoystickState(
short wJoystickNum,
tdstJoystickStatus* p_stJoyState,
tdstJoystickCaps* p_stJoyCaps
);
/*
This function must be called after fn_wJoyGetJoystickState()
It updates the directions values in the p_stJoyState structure
*/
extern void fn_vJoyUpdateDirection(
short wJoystickNum,
tdstJoystickStatus* p_stJoyState,
tdstJoystickCaps* p_stJoyCaps
);
/*
Return C_wJoyTrue if the specified joystick is conected else C_wJoyFalse
Return C_wJoyError if an error occured
*/
extern short fn_wJoyCheckConnection( short wJoystickNum );
/*
Return the productName in pszName
*/
extern short fn_wJoyGetOEMProductName( short wJoystickNum, char *pszName );
#endif

View File

@@ -0,0 +1,418 @@
/***************************************************************************/
/* Description: KeybDI.c, part of CPA INO library */
/* Keyboard specific implementation */
/* */
/* Author: F. Jentey */
/* Last Update: 05/03/97 */
/* 30/07/97 Direct Input */
/***************************************************************************/
#include <locale.h>
#include "INO\errINO.h"
#include "InitDI.h"
#include "INOInit.h"
#include "Keyboard.h"
/**************************************************************************
Globale vars
***************************************************************************/
/* Keyboard config variables : get the country keyboard config */
char INO_LayoutName[KL_NAMELENGTH];
HKL INO_LayoutHandle;
/* Table for virtual key code use for ASCII conversion */
/* INO_acDikToVirtual is used for the numeric pad, coz */
/* MapVirtualKeyEx() doesn't Verr Num state. */
BYTE INO_acVirtualKeyCodeTab[256];
BYTE INO_acDikToVirtual[256];
/* Store the key use in the game */
unsigned short INO_ActiveKey[128];
unsigned short INO_ActiveKeyNumber;
/**********************************************************************************/
/* This fonction returns the ASCII code corresponding to a key code if this key */
/* is printable. */
/**********************************************************************************/
short INO_fn_wDikToAscii(short wKeyCode, INO_tdhDevice hDev)
{
unsigned long VirtualKeyCode;
long iResult;
unsigned short a_uwASCIICode[2];
/* Get the VirtualKey code of the key */
/* We suppose all DIK code correspond to scan code. */
/* For numeric pad key, use the dik to virtual key */
/* code translation table. */
if ( (((wKeyCode>0x46) && (wKeyCode<0x54)) || (wKeyCode==0xb5)) &&
(GetKeyState(VK_NUMLOCK) & INO_C_ucKeyToggled) )
VirtualKeyCode = INO_acDikToVirtual[wKeyCode];
else
VirtualKeyCode = MapVirtualKeyEx(wKeyCode, 1, INO_LayoutHandle);
/* La fameuse modif qui tue - Elie */
if ( (VirtualKeyCode == 0) ||
(VirtualKeyCode == VK_CAPITAL) ||
(VirtualKeyCode == VK_SCROLL) ||
(VirtualKeyCode == VK_NUMLOCK) ||
(VirtualKeyCode == VK_SHIFT) ||
(VirtualKeyCode == VK_CONTROL) ||
(VirtualKeyCode == VK_MENU) ||
((VirtualKeyCode >= VK_F1) && (VirtualKeyCode<=VK_F24))
)
return (0);
/* Fill the INO_acVirtualKeyCodeTab array with SHIFT, ALT and CTRL state */
INO_acVirtualKeyCodeTab[VK_SHIFT] = INO_C_ucKeyDown &
( M_KeyState(hDev,C_ucKey_LSHIFT) |
M_KeyState(hDev,C_ucKey_RSHIFT) );
INO_acVirtualKeyCodeTab[VK_CONTROL] = INO_C_ucKeyDown &
( M_KeyState(hDev,C_ucKey_LCTRL) |
M_KeyState(hDev,C_ucKey_RCTRL) );
INO_acVirtualKeyCodeTab[VK_MENU] = INO_C_ucKeyDown &
( M_KeyState(hDev,C_ucKey_LALT) |
M_KeyState(hDev,C_ucKey_RALT) );
INO_acVirtualKeyCodeTab[VK_CAPITAL] = GetKeyState(VK_CAPITAL) & INO_C_ucKeyToggled;
/* Deuxieme modif qui tue - Elie */
/* INO_acVirtualKeyCodeTab[VK_NUMLOCK] = GetKeyState(VK_NUMLOCK) & INO_C_ucKeyToggled;*/
iResult = ToAsciiEx(VirtualKeyCode, wKeyCode, INO_acVirtualKeyCodeTab, a_uwASCIICode,0 , INO_LayoutHandle);
switch (iResult)
{
case 0:
return (0);
case 1:
iResult = (int)(a_uwASCIICode[0] & 0xFF);
/*if (!isprint(iResult) /*&& iswprint(iResult) ) */
/* return (0);*/
break;
case 2:
return (0);
}
return ((short)iResult);
}
/* Remove an active key. An error occurs when the specified key isn't */
/* active.By default, all keys are active, but you can remove some keys */
/* if they aren't used to speed up the fn_wKbRead function. */
short INO_fn_wRemoveActiveKey(short wKeyCode)
{
short i,j;
for (i=0 ;i<INO_ActiveKeyNumber; i++)
{
if (INO_ActiveKey[i] == wKeyCode)
{
for (j=i+1; j<INO_ActiveKeyNumber; j++)
INO_ActiveKey[j-1] = INO_ActiveKey[j];
INO_ActiveKeyNumber--;
return (1);
}
}
return (0);
}
/* Add a key to be managed. There is an error if the specified key is */
/* already active. */
short INO_fn_wAddActiveKey(short wKeyCode)
{
short i;
if (INO_ActiveKeyNumber > 127)
{
/* TO DO: error message */
return (0);
}
/* Test if key is already active */
for (i=0 ;i<INO_ActiveKeyNumber; i++)
{
if (INO_ActiveKey[i] == wKeyCode)
return (0);
}
INO_ActiveKey[INO_ActiveKeyNumber] = wKeyCode;
INO_ActiveKeyNumber++;
return (0);
}
/*********************************************************************
INITIALISATION
*********************************************************************/
/* Init keyboard capabilities. */
short INO_fn_wInitKeyboardCaps(INO_tdhDevice hDev)
{
short wASCIIForKeyA, i;
short wDev;
unsigned long ulSubType;
for (i=0; i<INO_C_wNbMaxDevice; i++)
if (INO_g_a_stDIDevice[i].m_hDevice == hDev) break;
if (i == INO_C_wNbMaxDevice) return (0);
wDev = i;
ulSubType = INO_fn_wFillDeviceCaps(hDev);
if (!ulSubType)
return(0);
memset(INO_ActiveKey,0,sizeof(unsigned short)*128);
INO_ActiveKeyNumber = 0;
/* For ASCII conversion */
GetKeyboardLayoutName(INO_LayoutName);
INO_LayoutHandle = LoadKeyboardLayout(INO_LayoutName,KLF_ACTIVATE);
/* Set the default active Key (All keys) */
for ( i=0x01 ; i<0x58 ; i++ )
INO_fn_wAddActiveKey(i);
INO_fn_wAddActiveKey(0x69); /* Pause */
INO_fn_wAddActiveKey(0x9c);
INO_fn_wAddActiveKey(0x9d);
INO_fn_wAddActiveKey(0xb5);
INO_fn_wAddActiveKey(0xb7);
INO_fn_wAddActiveKey(0xb8);
INO_fn_wAddActiveKey(0xc7);
INO_fn_wAddActiveKey(0xc5); /* Num Lock */
INO_fn_wAddActiveKey(0xc8);
INO_fn_wAddActiveKey(0xc9);
INO_fn_wAddActiveKey(0xcb);
INO_fn_wAddActiveKey(0xcd);
INO_fn_wAddActiveKey(0xcf);
INO_fn_wAddActiveKey(0xd0);
INO_fn_wAddActiveKey(0xd1);
INO_fn_wAddActiveKey(0xd2);
INO_fn_wAddActiveKey(0xd3);
INO_fn_wAddActiveKey(0xdb);
INO_fn_wAddActiveKey(0xdc);
INO_fn_wAddActiveKey(0xdd);
/* Fill the Dik to Virtual key code translation table */
/* for numeric pad (Vk when Verr Num is ON) */
INO_acDikToVirtual[C_ucKey_PAD_0] = VK_NUMPAD0;
INO_acDikToVirtual[C_ucKey_PAD_1] = VK_NUMPAD1;
INO_acDikToVirtual[C_ucKey_PAD_2] = VK_NUMPAD2;
INO_acDikToVirtual[C_ucKey_PAD_3] = VK_NUMPAD3;
INO_acDikToVirtual[C_ucKey_PAD_4] = VK_NUMPAD4;
INO_acDikToVirtual[C_ucKey_PAD_5] = VK_NUMPAD5;
INO_acDikToVirtual[C_ucKey_PAD_6] = VK_NUMPAD6;
INO_acDikToVirtual[C_ucKey_PAD_7] = VK_NUMPAD7;
INO_acDikToVirtual[C_ucKey_PAD_8] = VK_NUMPAD8;
INO_acDikToVirtual[C_ucKey_PAD_9] = VK_NUMPAD9;
INO_acDikToVirtual[C_ucKey_PAD_DIV] = VK_DIVIDE;
INO_acDikToVirtual[C_ucKey_PAD_MUL] = VK_MULTIPLY;
INO_acDikToVirtual[C_ucKey_PAD_SUB] = VK_SUBTRACT;
INO_acDikToVirtual[C_ucKey_PAD_ADD] = VK_ADD;
INO_acDikToVirtual[C_ucKey_PAD_POINT] = VK_DECIMAL;
/* Find keyboard type (Azerty / Qwerty) */
wASCIIForKeyA = INO_fn_wDikToAscii(C_ucKey_A,hDev) & 0xFF;
if ((wASCIIForKeyA == 'a') || (wASCIIForKeyA == 'A'))
((INO_tdstKeyboardCaps*)(hDev->m_p_stCaps))->m_wIsAzerty = 1;
else
((INO_tdstKeyboardCaps*)(hDev->m_p_stCaps))->m_wIsAzerty = 0;
return (1);
}
/* This function must be called at regular interval, for example each VBL. */
/* It Update the informations about the keyboard. */
short INO_fn_wReadKeyboard(INO_tdhDevice hDev)
{
HRESULT DInputErr;
unsigned short i, j;
short DownKey[INO_C_wMaxKeyDown];
short DownKeyNumber;
short LastKeyHasChanged, StateHasChanged;
short wDev;
INO_tdstKeyboardState *p_stState = M_KState(hDev);
INO_tdstKeyboardRecord *p_stH = (INO_tdstKeyboardRecord*)hDev->m_pvHistoric;
unsigned char *p_ucCurrentTab, *p_ucPrevTab;
if (!INO_M_bIsConnected(hDev))
return (0);
for (wDev=0; wDev<INO_C_wNbMaxDevice; wDev++)
if (INO_g_a_stDIDevice[wDev].m_hDevice == hDev) break;
if (wDev == INO_C_wNbMaxDevice)
{
INO_fn_vUpdateLastError(E_uwINO_WarningInvalidDevice);
return (0);
}
/* Increase the internal engine loop counter */
hDev->m_ulLastTimeCount++;
/* Flip the keyboard state buffer */
p_stState->m_wCurrentTab = 1 - p_stState->m_wCurrentTab;
p_ucCurrentTab = p_stState->m_a_ucTabKey[p_stState->m_wCurrentTab];
p_ucPrevTab = p_stState->m_a_ucTabKey[1-p_stState->m_wCurrentTab];
/* Try to acquire the keyboard if not done */
if (!(p_stState->m_ucStatus & INO_C_ucAcquired) ||
(p_stState->m_ucStatus & INO_C_ucAccessError) )
{
DInputErr = M_DIAcquire(wDev);
switch (DInputErr)
{
case DI_OK:
case S_FALSE:
hDev->m_p_stState->m_ucStatus |= INO_C_ucAcquired;
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucAccessError;
break;
case DIERR_INPUTLOST:
case DIERR_NOTACQUIRED:
case DIERR_OTHERAPPHASPRIO:
return (0);
default:
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucAcquired;
hDev->m_p_stState->m_ucStatus |= INO_C_ucAccessError;
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
return (0);
}
}
/* Read all key */
DInputErr = M_DIGetState(wDev, sizeof(BYTE)*256, p_ucCurrentTab);
switch (DInputErr)
{
case DI_OK:
case E_PENDING:
break;
case DIERR_INPUTLOST:
case DIERR_NOTACQUIRED:
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucAcquired;
return (0);
default:
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
hDev->m_p_stState->m_ucStatus |= INO_C_ucAccessError;
hDev->m_p_stState->m_ucStatus &= ~INO_C_ucAcquired;
return (0);
}
/* Check if the keyboard state has changed by comparing the current buffer with */
/* the previous one. Store the key code of the down key in the local tab */
/* ChangedKey. */
StateHasChanged = 0;
LastKeyHasChanged = 0;
DownKeyNumber = 0;
for (i=0 ; i<INO_ActiveKeyNumber ; i++)
{
j = INO_ActiveKey[i];
if (p_ucCurrentTab[j] != p_ucPrevTab[j])
{
StateHasChanged = 1;
if (p_ucCurrentTab[j])
{
LastKeyHasChanged = 1;
p_stState->m_wLastKey = j;
}
}
if ((DownKeyNumber < INO_C_wMaxKeyDown) && p_ucCurrentTab[j])
DownKey[DownKeyNumber++] = j;
}
if (LastKeyHasChanged)
{
/* Update last ASCII code */
p_stState->m_wLastASCII = INO_fn_wDikToAscii(p_stState->m_wLastKey,hDev);
/* Update the current string */
if (p_stState->m_wLastASCII)
{
if (p_stState->m_wCurrentStringLength == INO_C_wStringMaxLength)
{
for (i=0; i<INO_C_wStringMaxLength-1; i++)
p_stState->m_szCurrentString[i] = p_stState->m_szCurrentString[i+1];
p_stState->m_szCurrentString[INO_C_wStringMaxLength-1] = (char)p_stState->m_wLastASCII;
}
else
{
p_stState->m_szCurrentString[p_stState->m_wCurrentStringLength] = (char)p_stState->m_wLastASCII;
p_stState->m_wCurrentStringLength++;
}
}
}
else
p_stState->m_wLastASCII = 0;
/* Update historic. */
/* Test if it's the first call of the fn_wJKbReadKeyboard */
if (hDev->m_wRecordNumber == 0)
{
p_stH[0].m_ulDate = hDev->m_ulLastTimeCount;
p_stH[0].m_wNbKeyDown = 0;
hDev->m_wRecordNumber = 1;
StateHasChanged = 0;
}
/* If not, update the historic if keyboard state has changed */
else
{
if (StateHasChanged)
{
hDev->m_wHistoricHead++;
if (hDev->m_wHistoricHead == hDev->m_wHistoricSize) hDev->m_wHistoricHead = 0;
if (hDev->m_wRecordNumber != hDev->m_wHistoricSize) hDev->m_wRecordNumber++;
p_stH[hDev->m_wHistoricHead].m_ulDate = hDev->m_ulLastTimeCount;
p_stH[hDev->m_wHistoricHead].m_wNbKeyDown = 0;
for (i=0; i<DownKeyNumber; i++)
p_stH[hDev->m_wHistoricHead].m_wKeyDown[i] = DownKey[i];
p_stH[hDev->m_wHistoricHead].m_wNbKeyDown = DownKeyNumber;
}
}
p_stState->m_wStateHasChanged = StateHasChanged;
return (1);
}
/*
This function return C_wKbTrue if the selected key was down in the
specified previous state.
*/
short INO_fn_bKeyWasDown(INO_tdhDevice hDev, short wKeyCode, short wHistoricIndex)
{
long index, i;
INO_tdstKeyboardRecord *p_stState;
if (wHistoricIndex > hDev->m_wHistoricSize-1)
return (0);
else
{
index = (hDev->m_wHistoricHead - wHistoricIndex + hDev->m_wHistoricSize) % hDev->m_wHistoricSize;
p_stState = &((INO_tdstKeyboardRecord*)(hDev->m_pvHistoric))[index];
for (i=0 ; i<p_stState->m_wNbKeyDown; i++ )
if (p_stState->m_wKeyDown[i] == wKeyCode ) return (1);
}
return (0);
}
short INO_fn_wCheckCheatCode(INO_tdhDevice hDev,char *p_szTestString)
{
short l;
char *p_szCurrentS;
INO_tdstKeyboardState *p_stState = (INO_tdstKeyboardState*)(hDev->m_p_stState);
l = strlen(p_szTestString);
if (l > INO_C_wStringMaxLength) return (0);
if (l > p_stState->m_wCurrentStringLength) return (0);
p_szCurrentS = &p_stState->m_szCurrentString[p_stState->m_wCurrentStringLength-l];
return (strcmp(p_szCurrentS,p_szTestString) == 0);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,449 @@
/***************************************************************************/
/* Description: MouseDI.c, part of CPA INO library */
/* Mouse specific implementation */
/* */
/* Author: F. Jentey */
/* Last Update: 09/08/97 */
/* */
/***************************************************************************/
/********************************************************************
* Modified by : Jean-Francois Prevost
* email : jfprevost@ubisoft.qc.ca
* Date : Mar 25 1998
*____________________________________________________________________
* Description
* -----------
* - Added functions for mouse sensitivity setting.
* - Added INO_g_bUsingMouse variable to enable/disable mouse usage.
* To use the mouse in a program you MUST add the Mouse line in the
* file device.ipt EVEN if you don't use any IPT functions. To use
* the mouse with the AI you must change the device.itp file.
*
********************************************************************/
#include "INO\errINO.h"
#include "InitDI.h"
#include "INOInit.h"
#include "Mouse.h"
/*/////////////////////////////*/
/* Global variable used for mouse control.*/
/* If TRUE => We use the mouse.*/
/* If FALSE => We don't use the mouse*/
/* It is FALSE by default and set to TRUE ONLY if Mouse is present in*/
/* the file Device.ipt*/
BOOL INO_g_bUsingMouse = FALSE;
/*********************************************************************
INITIALISATION
*********************************************************************/
/********************************************************************
* Author: Jean-Francois Prevost
* email : jfprevost@ubisoft.qc.ca
* Date : Mar 25 1998
*____________________________________________________________________
* Function name : INO_fn_hCreateMouseDevice
*
* Parameters
* ----------
* _wHistoricSize: The size of the historic to keep.
*
* Description
* -----------
* Safe mouse device creation function. If the global INO_g_bUsingMouse
* is FALSE then we skip the creation process. This variable is
* only set to TRUE when the Mouse line is present in the file
* Device.ipt.
*
********************************************************************/
INO_tdhDevice INO_fn_hCreateMouseDevice( short _wHistoricSize )
{
if( INO_g_bUsingMouse )
{
return (INO_fn_hCreateDevice( INO_C_uwMouse , _wHistoricSize ));
}
else
{
return NULL;
}
}
short INO_fn_wLinkMouseWithGLD(INO_tdhDevice _hDev, GLD_tdhDevice _tdGLDDeviceHandle)
{
INO_tdstMouseState *p_stMouseState = (INO_tdstMouseState*)(_hDev->m_p_stState);
GLD_tdstDeviceAttributes stGLDDevAtt;
if (!GLD_bIsDeviceHandleValid(_tdGLDDeviceHandle))
{
INO_fn_vUpdateLastError(E_uwINO_Mouse_InvalidGLDDeviceHandle);
return (0);
}
if (GLD_bGetDeviceAttributes(_tdGLDDeviceHandle, &stGLDDevAtt))
{
/* Check the window handle of the device */
/* if (stGLDDevAtt.bFullScreen)
WndHandle = stGLDDevAtt.hFullScreenModeWnd;
else
WndHandle = stGLDDevAtt.hNormalModeWnd;
*/
_hDev->m_p_stState->m_ucStatus |= INO_C_ucGLDLink;
p_stMouseState->m_tdGLDDeviceHandle = _tdGLDDeviceHandle;
p_stMouseState->m_fPixelsPerMickeys = 1.0f;
p_stMouseState->m_fGLDX = 0.5f;
p_stMouseState->m_fGLDY = 0.5f;
p_stMouseState->m_fMouseSensitivity = 1.0f;
return (1);
}
else
{
if (Erm_M_uwCheckError(GLD,C_ucErmDefaultChannel))
Erm_M_ClearLastError(C_ucErmDefaultChannel);
INO_fn_vUpdateLastError(E_uwINO_Mouse_FailedGettingDeviceAttributes);
return (0);
}
}
short INO_fn_wInitMouseCaps(INO_tdhDevice _hDev)
{
HRESULT DInputErr;
DIPROPRANGE stAxisRange;
/* JFP changed the values to the mouse values!! It used to be the joystick values.*/
DWORD a_ulAxis[INO_C_wNbMaxAxis] = { DIMOFS_X, DIMOFS_Y, DIMOFS_Z };
short i;
short wDev;
INO_tdstMouseCaps *p_stMouseCaps = (INO_tdstMouseCaps*)(_hDev->m_p_stCaps);
unsigned long ulSubType;
for (i=0; i<INO_C_wNbMaxDevice; i++)
if (INO_g_a_stDIDevice[i].m_hDevice == _hDev)
break;
if (i == INO_C_wNbMaxDevice)
return (0);
wDev = i;
ulSubType = INO_fn_wFillDeviceCaps(_hDev);
if (!ulSubType)
return(0);
/* Mouse sub-type */
switch (ulSubType)
{
case DIDEVTYPEMOUSE_TRADITIONAL:
_hDev->m_uwType |= INO_C_uwSubTypeMouse;
break;
case DIDEVTYPEMOUSE_TOUCHPAD:
_hDev->m_uwType |= INO_C_uwSubTypeTouchPad;
break;
case DIDEVTYPEMOUSE_TRACKBALL:
_hDev->m_uwType |= INO_C_uwSubTypeTrackball;
break;
case DIDEVTYPEMOUSE_FINGERSTICK:
_hDev->m_uwType |= INO_C_uwSubTypeFingerStick;
break;
default:
_hDev->m_uwType |= INO_C_uwUnknown;
}
/* Get Axis capabilities */
for (i=0; i<3; i++) /* Maxi = 3 axes for mouse, testing Rx return INVALIDPARM */
{
stAxisRange.diph.dwSize = sizeof(DIPROPRANGE);
stAxisRange.diph.dwHeaderSize = sizeof(DIPROPHEADER);
stAxisRange.diph.dwHow = DIPH_BYOFFSET;
stAxisRange.diph.dwObj = a_ulAxis[i];
DInputErr = M_DIGetProp(wDev,DIPROP_RANGE,&stAxisRange.diph);
switch (DInputErr)
{
case DI_OK:
p_stMouseCaps->m_a_stAxisCaps[i].m_lCenter = ((stAxisRange.lMin + stAxisRange.lMax) >> 1);
p_stMouseCaps->m_a_stAxisCaps[i].m_lRange = stAxisRange.lMax - p_stMouseCaps->m_a_stAxisCaps[i].m_lCenter;
p_stMouseCaps->m_ulCapsFlags |= 1 << i;
break;
case DIERR_OBJECTNOTFOUND:
break;
case DIERR_INVALIDPARAM:
case DIERR_NOTINITIALIZED:
case DIERR_UNSUPPORTED:
default:
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
return (0);
}
}
_hDev->m_p_stState->m_ucStatus &= ~INO_C_ucGLDLink;
return (1);
}
/*********************************************************************
POLLING FUNCTION, GETTING MOUSE STATE
*********************************************************************/
/********************************************************************
* Author: Jean-Francois Prevost
* email : jfprevost@ubisoft.qc.ca
* Date : Feb 25 1998
*____________________________________________________________________
* Function name : INO_fn_bMouseMoved
*
* Parameters
* ----------
* _hDev : The handle of the mouse device.
*
* Description
* -----------
* Returns TRUE if the mouse has moved since the last frame.
*
********************************************************************/
short INO_fn_bMouseMoved(INO_tdhDevice _hDev)
{
short wCpt;
long* lAxis = ((INO_tdstMouseState*)(_hDev->m_p_stState))->m_a_lAxisValue;
for( wCpt = 0 ; wCpt < INO_C_wNbMaxAxis ; wCpt++ )
{
if( MTH_M_xAbs( lAxis[ wCpt ] ) > 0 )
return TRUE;
}
return FALSE;
}
/********************************************************************
* Author: Jean-Francois Prevost
* email : jfprevost@ubisoft.qc.ca
* Date : Feb 25 1998
*____________________________________________________________________
* Function name : INO_fn_bMouseButtonPressed
*
* Parameters
* ----------
* _hDev : The handle of the mouse device.
*
* Description
* -----------
* Returns TRUE if a mouse button is pressed
*
********************************************************************/
short INO_fn_bMouseButtonPressed(INO_tdhDevice _hDev)
{
if( INO_M_bLeftMBJustDown(_hDev) || INO_M_bRightMBJustDown(_hDev) )
{
return TRUE;
}
else
{
return FALSE;
}
}
/********************************************************************
* Author : F. Jentey
*____________________________________________________________________
* Modified by : Jean-Francois Prevost
* email : jfprevost@ubisoft.qc.ca
* Date : Mar 11 1998
*____________________________________________________________________
* Function name : INO_fn_wReadMouse
*
* Parameters
* ----------
* _hDev : Handle on the mouse device.
*
* Description
* -----------
* This function is responsible for reading the date from the mouse
* device and updating all of the mouse related data.
*
*____________________________________________________________________
* Modified by Date Changes
* ------------ ----------- ----------------------------------------
* JF Prevost Mar 11 1998 GLD data is modified according to the mouse
* sensitivity. (I also added the member
* m_wMouseSensitivity to the INO_tdstMouseState
* structure.
********************************************************************/
short INO_fn_wReadMouse(INO_tdhDevice _hDev)
{
short i;
short wDev;
HRESULT DInputErr;
DIMOUSESTATE stMouseState;
INO_tdstMouseState* p_stMouseState = MState(_hDev);
GLD_tdstDeviceAttributes stGLDDevAtt;
INO_tdstMouseRecord* p_stH = (INO_tdstMouseRecord*)_hDev->m_pvHistoric;
if (!INO_M_bIsConnected(_hDev))
return (0);
for (i=0; i<INO_C_wNbMaxDevice; i++)
if (INO_g_a_stDIDevice[i].m_hDevice == _hDev) break;
if (i == INO_C_wNbMaxDevice)
{
INO_fn_vUpdateLastError(E_uwINO_WarningInvalidDevice);
return (0);
}
wDev = i;
/* First, reacquired the mouse if necessary */
if (!(p_stMouseState->m_ucStatus & INO_C_ucAcquired) ||
(p_stMouseState->m_ucStatus & INO_C_ucAccessError) )
{
DInputErr = M_DIAcquire(wDev);
switch (DInputErr)
{
case DI_OK:
case S_FALSE:
p_stMouseState->m_ucStatus |= INO_C_ucAcquired;
p_stMouseState->m_ucStatus &= ~INO_C_ucAccessError;
break;
case DIERR_INPUTLOST:
case DIERR_NOTACQUIRED:
case DIERR_OTHERAPPHASPRIO:
/*
INO_g_bUsingMouse = FALSE;
if( _hDev != NULL )
{
// Destroy the device
INO_fn_wReleaseDevice( _hDev );
}
*/
return (0);
default:
p_stMouseState->m_ucStatus |= INO_C_ucAccessError;
p_stMouseState->m_ucStatus &= ~INO_C_ucAcquired;
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
return (0);
}
}
/* Get mouse state */
DInputErr = M_DIGetState(wDev,sizeof(DIMOUSESTATE),&stMouseState);
switch (DInputErr)
{
case DI_OK:
case E_PENDING:
break;
case DIERR_INPUTLOST:
case DIERR_NOTACQUIRED:
p_stMouseState->m_ucStatus &= ~INO_C_ucAcquired;
return (0);
default:
p_stMouseState->m_ucStatus |= INO_C_ucAccessError;
p_stMouseState->m_ucStatus &= ~INO_C_ucAcquired;
INO_fn_vUpdateLastError(E_uwINO_DirectInputError);
return (0);
}
/* JFP: This is where we consider the sensitivity. We could change it to a float value*/
/* instead and multiply the mickeys varitation instead. It would have a broader*/
/* range of settings.*/
p_stMouseState->m_a_lAxisValue[0] = max(-INO_C_ulMouseMaxSpeedValue,min(INO_C_ulMouseMaxSpeedValue,(long)(stMouseState.lX * INO_fn_fGetMouseSensitivity(_hDev))));
p_stMouseState->m_a_lAxisValue[1] = max(-INO_C_ulMouseMaxSpeedValue,min(INO_C_ulMouseMaxSpeedValue,(long)(stMouseState.lY * INO_fn_fGetMouseSensitivity(_hDev))));
p_stMouseState->m_a_lAxisValue[2] = max(-INO_C_ulMouseMaxSpeedValue,min(INO_C_ulMouseMaxSpeedValue,(long)(stMouseState.lZ * INO_fn_fGetMouseSensitivity(_hDev))));
/* Copy buttons info */
p_stMouseState->m_ulButtons = 0;
for (i=0; i<_hDev->m_p_stCaps->m_ucNbButtons; i++)
if (stMouseState.rgbButtons[i] & INO_C_ucButtonDown)
p_stMouseState->m_ulButtons |= 1 << i;
/* If linked with a GLD device, get the device attributes */
if (p_stMouseState->m_ucStatus & INO_C_ucGLDLink)
{
if (GLD_bGetDeviceAttributes(p_stMouseState->m_tdGLDDeviceHandle,&stGLDDevAtt))
{
/* Set the X (percent) coordinate*/
p_stMouseState->m_fGLDX += ((float)p_stMouseState->m_a_lAxisValue[0] * p_stMouseState->m_fPixelsPerMickeys)
/ (float)(stGLDDevAtt.dwWidth-1);
if (p_stMouseState->m_fGLDX < 0.0f) p_stMouseState->m_fGLDX = 0.0f;
if (p_stMouseState->m_fGLDX > 1.0f) p_stMouseState->m_fGLDX = 1.0f;
/* Set the Y (percent) coordinate*/
p_stMouseState->m_fGLDY += ((float)p_stMouseState->m_a_lAxisValue[1] * p_stMouseState->m_fPixelsPerMickeys)
/ (float)(stGLDDevAtt.dwHeight-1);
if (p_stMouseState->m_fGLDY < 0.0f) p_stMouseState->m_fGLDY = 0.0f;
if (p_stMouseState->m_fGLDY > 1.0f) p_stMouseState->m_fGLDY = 1.0f;
}
else
{
if (Erm_M_uwCheckError(GLD,C_ucErmDefaultChannel))
Erm_M_ClearLastError(C_ucErmDefaultChannel);
INO_fn_vUpdateLastError(E_uwINO_Mouse_FailedGettingDeviceAttributes);
return (0);
}
}
/* Update historic. */
if (_hDev->m_wRecordNumber == 0)
{
p_stH[0].m_ulDate = _hDev->m_ulLastTimeCount;
p_stH[0].m_ulButtons = p_stMouseState->m_ulButtons;
_hDev->m_wRecordNumber = 1;
}
else
{
_hDev->m_wHistoricHead++;
if (_hDev->m_wHistoricHead == _hDev->m_wHistoricSize) _hDev->m_wHistoricHead = 0;
if (_hDev->m_wRecordNumber != _hDev->m_wHistoricSize) _hDev->m_wRecordNumber++;
p_stH[_hDev->m_wHistoricHead].m_ulDate = _hDev->m_ulLastTimeCount;
p_stH[_hDev->m_wHistoricHead].m_ulButtons = p_stMouseState->m_ulButtons;
}
return (1);
}
/*//////////////////////////////////////*/
/* Mouse sensitivity related FUNCTIONS*/
void INO_fn_vSetMouseSensitivity(INO_tdhDevice _hDev, float _sensitivity)
{
MState(_hDev)->m_fMouseSensitivity=((_sensitivity>=0)?(_sensitivity):1);
}
float INO_fn_fGetMouseSensitivity(INO_tdhDevice _hDev)
{
return MState(_hDev)->m_fMouseSensitivity;
}
void INO_fn_vIncrementSensitivity(INO_tdhDevice _hDev)
{
MState(_hDev)->m_fMouseSensitivity++;
}
void INO_fn_vDecrementSensitivity(INO_tdhDevice _hDev)
{
if((MState(_hDev)->m_fMouseSensitivity-1)<=0)
{
(MState(_hDev)->m_fMouseSensitivity=1);
}
else
{
(MState(_hDev)->m_fMouseSensitivity-=1);
}
}

View File

@@ -0,0 +1,521 @@
/***************************************************************************/
/* Description: Mouse.c Part of CPA INO */
/* */
/* Author: F. Jentey */
/* Last Update: 09/08/97 */
/* */
/***************************************************************************/
#include "INOInit.h"
#include "Mouse.h"
#define M_Mouse() INO_g_p_stMouseInterface->lpVtbl
/*
tdstMouseStatus : mouse status informations
*/
typedef struct _stMouseStatus
{
DIDEVCAPS m_stCaps;
DIMOUSESTATE m_stStates[2];
short m_wAcquired;
short m_wCurrentBuffer;
/* Link with a GLD device */
short m_wLinkedWithGLD;
GLD_tdhDevice m_tdGLDDeviceHandle;
GLD_tdstDeviceAttributes m_stGLDDeviceAttributes;
float m_fPixelsPerMickeys;
float m_fScreenPosX;
float m_fScreenPosY;
int m_iMousePosX;
int m_iMousePosY;
int m_iOldMousePosX;
int m_iOldMousePosY;
} tdstMouseStatus;
/* Mouse init OK */
short INO_g_wMouseInitOk = 0;
/* The mouse state structure */
tdstMouseStatus INO_g_stMouseState;
/* Mouse device interface */
LPDIRECTINPUTDEVICE INO_g_p_stMouseInterface;
/* Mouse last error code */
u_long INO_g_ulMouseErrorCode;
/* Number of INO_fn_wReadMouse() Call */
u_long INO_g_ulMouseCounter = 0;
/*********************************************************************
INITIALISATION
*********************************************************************/
short INO_fn_wInitMouse(HINSTANCE hInstance, HWND hWindow)
{
GUID guid = GUID_SysMouse;
HRESULT DInputErr;
if (INO_g_wMouseInitOk) return (0);
/* Init direct input */
if (!INO_fn_wInitDirectInput(hInstance,hWindow)) return(C_wMouseError);
DInputErr = INO_g_p_stDInputInterface->lpVtbl->CreateDevice(
INO_g_p_stDInputInterface,
&guid,
&INO_g_p_stMouseInterface,
NULL
);
switch (DInputErr)
{
case DI_OK:
break;
case DIERR_INVALIDPARAM:
case DIERR_OUTOFMEMORY:
case DIERR_NOINTERFACE:
case DIERR_DEVICENOTREG:
INO_fn_vReleaseDirectInput();
return(C_wMouseError);
}
/* Get Mouse Capabilities (number of axis and button) */
INO_g_stMouseState.m_stCaps.dwSize = sizeof(DIDEVCAPS);
DInputErr = M_Mouse()->GetCapabilities(INO_g_p_stMouseInterface,&INO_g_stMouseState.m_stCaps);
if (DInputErr != DI_OK)
{
/* TO DO, warning, message */
}
/* TO DO, check if the device is physicaly attached */
/* Make sure the mouse isn't acquire before calling setDataFormat and */
/* SetCooperativeLevel. Return always OK */
DInputErr = M_Mouse()->Unacquire(INO_g_p_stMouseInterface);
INO_g_stMouseState.m_wAcquired = 0;
/* Tell DirectInput that we want to receive data in mouse format */
DInputErr = M_Mouse()->SetDataFormat(
INO_g_p_stMouseInterface,
&c_dfDIMouse
);
switch (DInputErr)
{
case DI_OK:
break;
case DIERR_INVALIDPARAM:
case DIERR_ACQUIRED:
M_Mouse()->Release(INO_g_p_stMouseInterface);
INO_fn_vReleaseDirectInput();
return(C_wMouseError);
break;
}
/* Set mouse cooperative level */
DInputErr = M_Mouse()->SetCooperativeLevel(
INO_g_p_stMouseInterface,
hWindow,
DISCL_EXCLUSIVE | DISCL_FOREGROUND
);
switch (DInputErr)
{
case DI_OK:
break;
case DIERR_INVALIDPARAM:
M_Mouse()->Release(INO_g_p_stMouseInterface);
INO_fn_vReleaseDirectInput();
return(C_wMouseError);
}
/* Try to acquire the mouse */
DInputErr = M_Mouse()->Acquire(INO_g_p_stMouseInterface);
switch (DInputErr)
{
case DI_OK:
case S_FALSE: /* Already acquired, OK */
INO_g_stMouseState.m_wAcquired = 1;
break;
case DIERR_INPUTLOST:
INO_g_stMouseState.m_wAcquired = 0;
break;
case DIERR_INVALIDPARAM:
INO_g_stMouseState.m_wAcquired = 0;
M_Mouse()->Release(INO_g_p_stMouseInterface);
INO_fn_vReleaseDirectInput();
return(C_wMouseError);
}
/* Init mouse state */
INO_g_stMouseState.m_wCurrentBuffer = 0;
INO_g_stMouseState.m_wLinkedWithGLD = 0;
INO_g_ulMouseCounter = 0;
INO_g_wMouseInitOk++;
return (0);
}
short INO_fn_wInitMouseWithGLD(HINSTANCE hInstance, GLD_tdhDevice tdGLDDeviceHandle)
{
HWND WndHandle;
POINT Point;
if (INO_g_wMouseInitOk) return (0);
if (!GLD_bIsDeviceHandleValid(tdGLDDeviceHandle))
{
INO_g_ulMouseErrorCode = C_ErrMouseInvalidGLDDeviceHandle;
return (C_wMouseError);
}
if (GLD_bGetDeviceAttributes(tdGLDDeviceHandle, &INO_g_stMouseState.m_stGLDDeviceAttributes))
{
/* Check the window handle of the device */
if (INO_g_stMouseState.m_stGLDDeviceAttributes.bFullScreen)
WndHandle = INO_g_stMouseState.m_stGLDDeviceAttributes.hFullScreenModeWnd;
else
WndHandle = INO_g_stMouseState.m_stGLDDeviceAttributes.hNormalModeWnd;
if (INO_fn_wInitMouse(hInstance,WndHandle) != C_wMouseError)
{
INO_g_stMouseState.m_wLinkedWithGLD = 1;
INO_g_stMouseState.m_tdGLDDeviceHandle = tdGLDDeviceHandle;
INO_g_stMouseState.m_fPixelsPerMickeys = 1.0;
INO_g_stMouseState.m_fScreenPosX = 0.5;
INO_g_stMouseState.m_fScreenPosY = 0.5;
return (0);
}
else
return (C_wMouseError);
}
else
{
if (Erm_M_uwCheckError(GLD,C_ucErmDefaultChannel))
Erm_M_ClearLastError(C_ucErmDefaultChannel);
INO_g_ulMouseErrorCode = C_ErrMouseFailedGettingDeviceAttributes;
return (C_wMouseError);
}
}
short INO_fn_vFreeMouse(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if (INO_g_stMouseState.m_wAcquired)
{
M_Mouse()->Unacquire(INO_g_p_stMouseInterface);
INO_g_stMouseState.m_wAcquired = 0;
}
M_Mouse()->Release(INO_g_p_stMouseInterface);
INO_fn_vReleaseDirectInput();
INO_g_wMouseInitOk = 0;
return (0);
}
short INO_fn_wGetMouseNumberOfButtons(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
return ((short)INO_g_stMouseState.m_stCaps.dwButtons);
}
short INO_fn_wGetMouseNumberOfAxes(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
return ((short)INO_g_stMouseState.m_stCaps.dwAxes);
}
/*********************************************************************
POLLING FUNCTION, GETTING MOUSE STATE
*********************************************************************/
short INO_fn_wReadMouse(void)
{
HRESULT DInputErr;
POINT Point;
HWND WndHandle;
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
/* Increase the internal frame counter */
INO_g_ulMouseCounter++;
/* Try to acquire the mouse if not done */
if (!INO_g_stMouseState.m_wAcquired)
{
DInputErr = M_Mouse()->Acquire(INO_g_p_stMouseInterface);
switch (DInputErr)
{
case DI_OK:
case S_FALSE:
INO_g_stMouseState.m_wAcquired = 1;
break;
case DIERR_INPUTLOST:
INO_g_ulMouseErrorCode = C_ErrMouseFocusLost;
return (C_wMouseError);
case DIERR_INVALIDPARAM:
INO_g_stMouseState.m_wAcquired = 0;
INO_g_ulMouseErrorCode = C_ErrMouseDirectInputError;
return (C_wMouseError);
default:
break;
}
}
/* Flip the mouse state buffer */
INO_g_stMouseState.m_wCurrentBuffer = 1 - INO_g_stMouseState.m_wCurrentBuffer;
/* Get mouse current state */
DInputErr = M_Mouse()->GetDeviceState(
INO_g_p_stMouseInterface,
sizeof(DIMOUSESTATE),
&INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer]
);
switch (DInputErr)
{
case DI_OK:
INO_g_stMouseState.m_wAcquired = 1;
break;
case E_PENDING:
break;
case DIERR_INPUTLOST:
/*case DIERR_NOTACQUIRED:*/
INO_g_stMouseState.m_wAcquired = 0;
INO_g_ulMouseErrorCode = C_ErrMouseFocusLost;
return (C_wMouseError);
case DIERR_INVALIDPARAM:
INO_g_stMouseState.m_wAcquired = 0;
INO_g_ulMouseErrorCode = C_ErrMouseDirectInputError;
return(C_wMouseError);
default:
break;
}
//read Cursor Position
if (INO_g_stMouseState.m_stGLDDeviceAttributes.bFullScreen)
WndHandle = INO_g_stMouseState.m_stGLDDeviceAttributes.hFullScreenModeWnd;
else
WndHandle = INO_g_stMouseState.m_stGLDDeviceAttributes.hNormalModeWnd;
//swap Postion;
INO_g_stMouseState.m_iOldMousePosX = INO_g_stMouseState.m_iMousePosX;
INO_g_stMouseState.m_iOldMousePosY = INO_g_stMouseState.m_iMousePosY;
GetCursorPos( &Point );
ScreenToClient( WndHandle, &Point );
INO_g_stMouseState.m_iMousePosX = Point.x;
INO_g_stMouseState.m_iMousePosY = Point.y;
/* If linked with a GLD device, get the device attributes */
if (INO_g_stMouseState.m_wLinkedWithGLD)
{
if (GLD_bGetDeviceAttributes(INO_g_stMouseState.m_tdGLDDeviceHandle,
&INO_g_stMouseState.m_stGLDDeviceAttributes))
{
INO_g_stMouseState.m_fScreenPosX +=
((float)INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer].lX * INO_g_stMouseState.m_fPixelsPerMickeys)
/ (float)(INO_g_stMouseState.m_stGLDDeviceAttributes.dwWidth-1);
if (INO_g_stMouseState.m_fScreenPosX<0.0) INO_g_stMouseState.m_fScreenPosX = 0.0;
if (INO_g_stMouseState.m_fScreenPosX>1.0) INO_g_stMouseState.m_fScreenPosX = 1.0;
INO_g_stMouseState.m_fScreenPosY +=
((float)INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer].lY * INO_g_stMouseState.m_fPixelsPerMickeys)
/ (float)(INO_g_stMouseState.m_stGLDDeviceAttributes.dwHeight-1);
if (INO_g_stMouseState.m_fScreenPosY<0.0) INO_g_stMouseState.m_fScreenPosY = 0.0;
if (INO_g_stMouseState.m_fScreenPosY>1.0) INO_g_stMouseState.m_fScreenPosY = 1.0;
}
else
{
if (Erm_M_uwCheckError(GLD,C_ucErmDefaultChannel))
Erm_M_ClearLastError(C_ucErmDefaultChannel);
INO_g_ulMouseErrorCode = C_ErrMouseFailedGettingDeviceAttributes;
return (C_wMouseError);
}
}
return(0);
}
short INO_fn_wGetMousePosition(int *p_iX, int *p_iY)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if (!INO_g_stMouseState.m_wLinkedWithGLD)
{
INO_g_ulMouseErrorCode = C_ErrNoGLDDeviceLinkedWithMouse;
return (C_wMouseError);
}
*p_iX = INO_g_stMouseState.m_iMousePosX;
*p_iY = INO_g_stMouseState.m_iMousePosY;
if( (INO_g_stMouseState.m_iMousePosX >=0) &&
(INO_g_stMouseState.m_iMousePosY >=0) &&
(INO_g_stMouseState.m_iMousePosX <= INO_g_stMouseState.m_stGLDDeviceAttributes.dwWidth) &&
(INO_g_stMouseState.m_iMousePosY <= INO_g_stMouseState.m_stGLDDeviceAttributes.dwHeight)
)
return C_wMouseTrue;
else
return C_wMouseFalse;
}
short INO_fn_wGetMousePositionInGldDevice(float *p_fX, float *p_fY)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if (!INO_g_stMouseState.m_wLinkedWithGLD)
{
INO_g_ulMouseErrorCode = C_ErrNoGLDDeviceLinkedWithMouse;
return (C_wMouseError);
}
*p_fX = INO_g_stMouseState.m_fScreenPosX;
*p_fY = INO_g_stMouseState.m_fScreenPosY;
return (0);
}
short INO_fn_wLeftMouseButtonDown(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if (INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[0])
return (C_wMouseTrue);
else
return (C_wMouseFalse);
}
short INO_fn_wRightMouseButtonDown(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if (INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[1])
return (C_wMouseTrue);
else
return (C_wMouseFalse);
}
short INO_fn_wLeftMouseButtonJustDown(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if ( (INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[0]) &&
(!INO_g_stMouseState.m_stStates[1-INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[0]) )
return (C_wMouseTrue);
else
return (C_wMouseFalse);
}
short INO_fn_wRightMouseButtonJustDown(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if ( (INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[1]) &&
(!INO_g_stMouseState.m_stStates[1-INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[1]) )
return (C_wMouseTrue);
else
return (C_wMouseFalse);
}
short INO_fn_wLeftMouseButtonJustUp(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if ( (!INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[0]) &&
(INO_g_stMouseState.m_stStates[1-INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[0]) )
return (C_wMouseTrue);
else
return (C_wMouseFalse);
}
short INO_fn_wRightMouseButtonJustUp(void)
{
if (!INO_g_wMouseInitOk)
{
INO_g_ulMouseErrorCode = C_ErrMouseNotInitialized;
return (C_wMouseError);
}
if ( (!INO_g_stMouseState.m_stStates[INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[1]) &&
(INO_g_stMouseState.m_stStates[1-INO_g_stMouseState.m_wCurrentBuffer].rgbButtons[1]) )
return (C_wMouseTrue);
else
return (C_wMouseFalse);
}
u_long INO_fn_ulGetMouseErrorCode(void)
{
return(INO_g_ulMouseErrorCode);
}