comparison src/video/windx5/SDL_dx5video.c @ 1854:2280e314a978

Closed bug #74 Added DirectInput joystick code, contributed by Glenn Maynard. This fixes a problem with the Windows Multimedia joystick driver not showing all 6 axes on a GameCube controller converter, which was donated by Jacob Kolding.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 21 May 2006 16:47:41 +0000
parents 8d3ca155c396
children 5ff2c01e475e
comparison
equal deleted inserted replaced
1853:2c4923336dd0 1854:2280e314a978
434 /* WinDIB driver functions for manipulating gamma ramps */ 434 /* WinDIB driver functions for manipulating gamma ramps */
435 extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp); 435 extern int DIB_SetGammaRamp(_THIS, Uint16 *ramp);
436 extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp); 436 extern int DIB_GetGammaRamp(_THIS, Uint16 *ramp);
437 extern void DIB_QuitGamma(_THIS); 437 extern void DIB_QuitGamma(_THIS);
438 438
439 /* DX5 driver bootstrap functions */
440
441 static int DX5_Available(void)
442 {
443 HINSTANCE DInputDLL;
444 HINSTANCE DDrawDLL;
445 int dinput_ok;
446 int ddraw_ok;
447
448 /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
449 dinput_ok = 0;
450 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
451 if ( DInputDLL != NULL ) {
452 dinput_ok = 1;
453 FreeLibrary(DInputDLL);
454 }
455 ddraw_ok = 0;
456 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
457 if ( DDrawDLL != NULL ) {
458 HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
459 LPDIRECTDRAW DDraw;
460
461 /* Try to create a valid DirectDraw object */
462 DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
463 if ( (DDrawCreate != NULL)
464 && !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) {
465 if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
466 NULL, DDSCL_NORMAL)) ) {
467 DDSURFACEDESC desc;
468 LPDIRECTDRAWSURFACE DDrawSurf;
469 LPDIRECTDRAWSURFACE3 DDrawSurf3;
470
471 /* Try to create a DirectDrawSurface3 object */
472 SDL_memset(&desc, 0, sizeof(desc));
473 desc.dwSize = sizeof(desc);
474 desc.dwFlags = DDSD_CAPS;
475 desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
476 if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
477 &DDrawSurf, NULL)) ) {
478 if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf,
479 &IID_IDirectDrawSurface3, (LPVOID *)&DDrawSurf3)) ) {
480 /* Yay! */
481 ddraw_ok = 1;
482
483 /* Clean up.. */
484 IDirectDrawSurface3_Release(DDrawSurf3);
485 }
486 IDirectDrawSurface_Release(DDrawSurf);
487 }
488 }
489 IDirectDraw_Release(DDraw);
490 }
491 FreeLibrary(DDrawDLL);
492 }
493 return(dinput_ok && ddraw_ok);
494 }
495
496 /* Functions for loading the DirectX functions dynamically */ 439 /* Functions for loading the DirectX functions dynamically */
440 static int DX5_loaded = 0;
497 static HINSTANCE DDrawDLL = NULL; 441 static HINSTANCE DDrawDLL = NULL;
498 static HINSTANCE DInputDLL = NULL; 442 static HINSTANCE DInputDLL = NULL;
499 443
500 static void DX5_Unload(void) 444 void DX5_Unload(void)
501 { 445 {
502 if ( DDrawDLL != NULL ) { 446 if ( --DX5_loaded == 0 ) {
503 FreeLibrary(DDrawDLL); 447 if ( DDrawDLL != NULL ) {
504 DDrawCreate = NULL; 448 FreeLibrary(DDrawDLL);
505 DDrawDLL = NULL; 449 DDrawCreate = NULL;
506 } 450 DDrawDLL = NULL;
507 if ( DInputDLL != NULL ) { 451 }
508 FreeLibrary(DInputDLL); 452 if ( DInputDLL != NULL ) {
509 DInputCreate = NULL; 453 FreeLibrary(DInputDLL);
510 DInputDLL = NULL; 454 DInputCreate = NULL;
511 } 455 DInputDLL = NULL;
512 } 456 }
513 static int DX5_Load(void) 457 }
514 { 458 }
515 int status; 459 int DX5_Load(void)
460 {
461 int status = 0;
462
463 if ( ++DX5_loaded == 1 ) {
464 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL"));
465 if ( DDrawDLL != NULL ) {
466 DDrawCreate = (void *)GetProcAddress(DDrawDLL,
467 TEXT("DirectDrawCreate"));
468 }
469 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
470 if ( DInputDLL != NULL ) {
471 DInputCreate = (void *)GetProcAddress(DInputDLL,
472 TEXT("DirectInputCreateA"));
473 }
474 if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
475 status = 0;
476 } else {
477 DX5_Unload();
478 status = -1;
479 }
480 }
481 return status;
482 }
483
484 /* DX5 driver bootstrap functions */
485
486 static int DX5_Available(void)
487 {
488 int ddraw_ok = 0;
489 HRESULT (WINAPI *DDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
490 LPDIRECTDRAW DDraw;
491
492 /* Version check DINPUT.DLL and DDRAW.DLL (Is DirectX okay?) */
493 if ( DX5_Load() < 0 ) {
494 return -1;
495 }
496
497 /* Try to create a valid DirectDraw object */
498 DDrawCreate = (void *)GetProcAddress(DDrawDLL, TEXT("DirectDrawCreate"));
499 if ( (DDrawCreate != NULL)
500 && !FAILED(DDrawCreate(NULL, &DDraw, NULL)) ) {
501 if ( !FAILED(IDirectDraw_SetCooperativeLevel(DDraw,
502 NULL, DDSCL_NORMAL)) ) {
503 DDSURFACEDESC desc;
504 LPDIRECTDRAWSURFACE DDrawSurf;
505 LPDIRECTDRAWSURFACE3 DDrawSurf3;
506
507 /* Try to create a DirectDrawSurface3 object */
508 SDL_memset(&desc, 0, sizeof(desc));
509 desc.dwSize = sizeof(desc);
510 desc.dwFlags = DDSD_CAPS;
511 desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_VIDEOMEMORY;
512 if ( !FAILED(IDirectDraw_CreateSurface(DDraw, &desc,
513 &DDrawSurf, NULL)) ) {
514 if ( !FAILED(IDirectDrawSurface_QueryInterface(DDrawSurf,
515 &IID_IDirectDrawSurface3, (LPVOID *)&DDrawSurf3)) ) {
516 /* Yay! */
517 ddraw_ok = 1;
518
519 /* Clean up.. */
520 IDirectDrawSurface3_Release(DDrawSurf3);
521 }
522 IDirectDrawSurface_Release(DDrawSurf);
523 }
524 }
525 IDirectDraw_Release(DDraw);
526 }
516 527
517 DX5_Unload(); 528 DX5_Unload();
518 DDrawDLL = LoadLibrary(TEXT("DDRAW.DLL")); 529
519 if ( DDrawDLL != NULL ) { 530 return ddraw_ok;
520 DDrawCreate = (void *)GetProcAddress(DDrawDLL,
521 TEXT("DirectDrawCreate"));
522 }
523 DInputDLL = LoadLibrary(TEXT("DINPUT.DLL"));
524 if ( DInputDLL != NULL ) {
525 DInputCreate = (void *)GetProcAddress(DInputDLL,
526 TEXT("DirectInputCreateA"));
527 }
528 if ( DDrawDLL && DDrawCreate && DInputDLL && DInputCreate ) {
529 status = 0;
530 } else {
531 DX5_Unload();
532 status = -1;
533 }
534 return status;
535 } 531 }
536 532
537 static void DX5_DeleteDevice(SDL_VideoDevice *this) 533 static void DX5_DeleteDevice(SDL_VideoDevice *this)
538 { 534 {
539 /* Free DirectDraw object */ 535 /* Free DirectDraw object */
540 if ( ddraw2 != NULL ) { 536 if ( ddraw2 != NULL ) {
541 IDirectDraw2_Release(ddraw2); 537 IDirectDraw2_Release(ddraw2);
542 } 538 }
543 DX5_Unload(); 539 DX5_Unload();
540
544 if ( this ) { 541 if ( this ) {
545 if ( this->hidden ) { 542 if ( this->hidden ) {
546 SDL_free(this->hidden); 543 SDL_free(this->hidden);
547 } 544 }
548 if ( this->gl_data ) { 545 if ( this->gl_data ) {