Moved DirectInput joystick code to 1.3 branch
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401821
This commit is contained in:
parent
fe915b7a0a
commit
f2d67baf34
7 changed files with 108 additions and 626 deletions
|
@ -436,98 +436,102 @@ extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
|
|||
extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
|
||||
extern void DIB_QuitGamma(_THIS);
|
||||
|
||||
/* Functions for loading the DirectX functions dynamically */
|
||||
static int DX5_loaded = 0;
|
||||
static HINSTANCE DDrawDLL = NULL;
|
||||
static HINSTANCE DInputDLL = NULL;
|
||||
|
||||
void DX5_Unload(void)
|
||||
{
|
||||
if ( --DX5_loaded == 0 ) {
|
||||
if ( DDrawDLL != NULL ) {
|
||||
FreeLibrary(DDrawDLL);
|
||||
DDrawCreate = NULL;
|
||||
DDrawDLL = NULL;
|
||||
}
|
||||
if ( DInputDLL != NULL ) {
|
||||
FreeLibrary(DInputDLL);
|
||||
DInputCreate = NULL;
|
||||
DInputDLL = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
int DX5_Load(void)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
if ( ++DX5_loaded == 1 ) {
|
||||
DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
|
||||
if ( DDrawDLL != NULL ) {
|
||||
DDrawCreate = (void *)GetProcAddress(DDrawDLL,
|
||||
TEXT("DirectDrawCreate"));
|
||||
}
|
||||
DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
|
||||
if ( DInputDLL != NULL ) {
|
||||
DInputCreate = (void *)GetProcAddress(DInputDLL,
|
||||
TEXT("DirectInputCreateA"));
|
||||
}
|
||||
if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
|
||||
status = 0;
|
||||
} else {
|
||||
DX5_Unload();
|
||||
status = -1;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/* DX5 driver bootstrap functions */
|
||||
|
||||
static int DX5_Available(void)
|
||||
{
|
||||
int ddraw_ok = 0;
|
||||
HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
|
||||
LPDIRECTDRAW DDraw;
|
||||
HINSTANCE DInputDLL;
|
||||
HINSTANCE DDrawDLL;
|
||||
int dinput_ok;
|
||||
int ddraw_ok;
|
||||
|
||||
/* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
|
||||
if ( DX5_Load() < 0 ) {
|
||||
return -1;
|
||||
dinput_ok = 0;
|
||||
DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
|
||||
if ( DInputDLL != NULL ) {
|
||||
dinput_ok = 1;
|
||||
FreeLibrary(DInputDLL);
|
||||
}
|
||||
ddraw_ok = 0;
|
||||
DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
|
||||
if ( DDrawDLL != NULL ) {
|
||||
HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
|
||||
LPDIRECTDRAW DDraw;
|
||||
|
||||
/* Try to create a valid DirectDraw object */
|
||||
DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
|
||||
if ( (DDrawCreate != NULL)
|
||||
/* Try to create a valid DirectDraw object */
|
||||
DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
|
||||
if ( (DDrawCreate != NULL)
|
||||
&& !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) {
|
||||
if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
|
||||
if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
|
||||
NULL, DDSCL_NORMAL)) ) {
|
||||
DDSURFACEDESC desc;
|
||||
LPDIRECTDRAWSURFACE DDrawSurf;
|
||||
LPDIRECTDRAWSURFACE3 DDrawSurf3;
|
||||
DDSURFACEDESC desc;
|
||||
LPDIRECTDRAWSURFACE DDrawSurf;
|
||||
LPDIRECTDRAWSURFACE3 DDrawSurf3;
|
||||
|
||||
/* Try to create a DirectDrawSurface3 object */
|
||||
SDL_memset(&desc, 0, sizeof(desc));
|
||||
desc.dwSize = sizeof(desc);
|
||||
desc.dwFlags = DDSD_CAPS;
|
||||
desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
|
||||
if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
|
||||
/* Try to create a DirectDrawSurface3 object */
|
||||
SDL_memset(&desc, 0, sizeof(desc));
|
||||
desc.dwSize = sizeof(desc);
|
||||
desc.dwFlags = DDSD_CAPS;
|
||||
desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
|
||||
if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
|
||||
&DDrawSurf, NULL)) ) {
|
||||
if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf,
|
||||
if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf,
|
||||
&IID_IDirectDrawSurface3, (LPVOID *)&DDrawSurf3)) ) {
|
||||
/* Yay! */
|
||||
ddraw_ok = 1;
|
||||
/* Yay! */
|
||||
ddraw_ok = 1;
|
||||
|
||||
/* Clean up.. */
|
||||
IDirectDrawSurface3_Release(DDrawSurf3);
|
||||
/* Clean up.. */
|
||||
IDirectDrawSurface3_Release(DDrawSurf3);
|
||||
}
|
||||
IDirectDrawSurface_Release(DDrawSurf);
|
||||
}
|
||||
IDirectDrawSurface_Release(DDrawSurf);
|
||||
}
|
||||
IDirectDraw_Release(DDraw);
|
||||
}
|
||||
IDirectDraw_Release(DDraw);
|
||||
FreeLibrary(DDrawDLL);
|
||||
}
|
||||
return(dinput_ok && ddraw_ok);
|
||||
}
|
||||
|
||||
/* Functions for loading the DirectX functions dynamically */
|
||||
static HINSTANCE DDrawDLL = NULL;
|
||||
static HINSTANCE DInputDLL = NULL;
|
||||
|
||||
static void DX5_Unload(void)
|
||||
{
|
||||
if ( DDrawDLL != NULL ) {
|
||||
FreeLibrary(DDrawDLL);
|
||||
DDrawCreate = NULL;
|
||||
DDrawDLL = NULL;
|
||||
}
|
||||
if ( DInputDLL != NULL ) {
|
||||
FreeLibrary(DInputDLL);
|
||||
DInputCreate = NULL;
|
||||
DInputDLL = NULL;
|
||||
}
|
||||
}
|
||||
static int DX5_Load(void)
|
||||
{
|
||||
int status;
|
||||
|
||||
DX5_Unload();
|
||||
|
||||
return ddraw_ok;
|
||||
DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
|
||||
if ( DDrawDLL != NULL ) {
|
||||
DDrawCreate = (void *)GetProcAddress(DDrawDLL,
|
||||
TEXT("DirectDrawCreate"));
|
||||
}
|
||||
DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
|
||||
if ( DInputDLL != NULL ) {
|
||||
DInputCreate = (void *)GetProcAddress(DInputDLL,
|
||||
TEXT("DirectInputCreateA"));
|
||||
}
|
||||
if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
|
||||
status = 0;
|
||||
} else {
|
||||
DX5_Unload();
|
||||
status = -1;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static void DX5_DeleteDevice(SDL_VideoDevice *this)
|
||||
|
@ -537,7 +541,6 @@ static void DX5_DeleteDevice(SDL_VideoDevice *this)
|
|||
IDirectDraw2_Release(ddraw2);
|
||||
}
|
||||
DX5_Unload();
|
||||
|
||||
if ( this ) {
|
||||
if ( this->hidden ) {
|
||||
SDL_free(this->hidden);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue