@ -51,10 +51,10 @@
PadMapping[1, 2, 3 and 4]: The button mapping
Joystate[1, 2, 3 and 4]: The current button states
The arrays PadMapping[] and joys tate[] are numbered 0 to 3 for the four different virtual
The arrays PadMapping[] and PadS tate[] are numbered 0 to 3 for the four different virtual
controllers. Joysticks[].ID will have the number of the physical input device mapped to that
controller (this value range between 0 and the total number of connected physical devices). The
mapping of a certain physical device to joys tate[].joy is initially done by Initialize(), but
mapping of a certain physical device to PadS tate[].joy is initially done by Initialize(), but
for the configuration we can remap that, like in ConfigBox::ChangeJoystick().
The joyinfo[] array holds the physical gamepad info for a certain physical device. It's therefore
@ -84,10 +84,11 @@
# define _CONTROLLER_STATE_H // Avoid certain declarations in nJoy.h
FILE * pFile ;
HINSTANCE nJoy_hInst = NULL ;
CONTROLLER_INFO * joyinfo = 0 ;
CONTROLLER_STATE joys tate[ 4 ] ;
std : : vector < CONTROLLER_INFO > joyinfo ;
CONTROLLER_STATE PadS tate[ 4 ] ;
CONTROLLER_MAPPING PadMapping [ 4 ] ;
bool emulator_running = FALSE ;
bool emulator_running = false ;
int NumPads = 0 , NumGoodPads = 0 ;
HWND m_hWnd ; // Handle to window
// TODO: fix this dirty hack to stop missing symbols
@ -178,36 +179,35 @@ void GetDllInfo(PLUGIN_INFO* _PluginInfo)
# endif
}
void SetDllGlobals ( PLUGIN_GLOBALS * _pPluginGlobals ) {
}
void SetDllGlobals ( PLUGIN_GLOBALS * _pPluginGlobals ) { }
// Call config dialog
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
void DllConfig ( HWND _hParent )
{
# ifdef _WIN32
// Debugging
//Console::Open();
# ifdef _WIN32
// Start the pads so we can use them in the configuration and advanced controls
if ( ! emulator_running )
{
SPADInitialize _PADInitialize ;
_PADInitialize . hWnd = NULL ;
_PADInitialize . pLog = NULL ;
Initialize ( ( void * ) & _PADInitialize ) ;
emulator_running = false ; // Set it back to false
NumPads = Search_Devices ( ) ; // Populate joyinfo for all attached devices
}
g_Config . Load ( ) ; // Load settings
// We don't need a parent for this wxDialog
//wxWindow win;
//win.SetHWND(_hParent);
//ConfigBox frame(&win);
//win.SetHWND(0);
m_frame = new ConfigBox ( NULL ) ;
m_frame - > ShowModal ( ) ;
/* Check if any of the pads failed to open. In Windows there is a strange "IDirectInputDevice2::
SetDataFormat() DirectX error -2147024809" after a few Open and Close */
if ( ( PadMapping [ 0 ] . enabled & & PadState [ 0 ] . joy = = NULL )
| | ( PadMapping [ 1 ] . enabled & & PadState [ 1 ] . joy = = NULL )
| | ( PadMapping [ 2 ] . enabled & & PadState [ 2 ] . joy = = NULL )
| | ( PadMapping [ 3 ] . enabled & & PadState [ 3 ] . joy = = NULL ) )
{
//PostMessage(_hParent, 25, 0, 0);
Console : : Print ( " %s \n " , SDL_GetError ( ) ) ;
}
# else
if ( SDL_Init ( SDL_INIT_JOYSTICK ) < 0 )
{
@ -221,12 +221,10 @@ void DllConfig(HWND _hParent)
ConfigBox frame ( NULL ) ;
frame . ShowModal ( ) ;
# endif
# endif
}
void DllDebugger ( HWND _hParent , bool Show ) {
}
void DllDebugger ( HWND _hParent , bool Show ) { }
// Init PAD (start emulation)
@ -240,49 +238,26 @@ void Initialize(void *init)
{
// Debugging
//Console::Open();
//Console::Print("Initialize: %i\n", SDL_WasInit(0));
Console : : Print ( " Initialize: %i \n " , SDL_WasInit ( 0 ) ) ;
SPADInitialize * _PADInitialize = ( SPADInitialize * ) init ;
emulator_running = true ;
# ifdef _DEBUG
DEBUG_INIT ( ) ;
# endif
/* SDL 1.3 use DirectInput instead of the old Microsoft Multimeda API, and with this we need
the SDL_INIT_VIDEO flag to */
if ( ! SDL_WasInit ( 0 ) )
if ( SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 )
{
# ifdef _WIN32
MessageBox ( NULL , SDL_GetError ( ) , " Could not initialize SDL! " , MB_ICONERROR ) ;
# else
printf ( " Could not initialize SDL! (%s) \n " , SDL_GetError ( ) ) ;
# endif
return ;
}
# ifdef _WIN32
m_hWnd = ( HWND ) _PADInitialize - > hWnd ;
# endif
Search_Devices ( ) ; // Populate joyinfo for all attached devices
g_Config . Load ( ) ; // Load joystick mapping, PadMapping[].ID etc
if ( PadMapping [ 0 ] . enabled )
joystate [ 0 ] . joy = SDL_JoystickOpen ( PadMapping [ 0 ] . ID ) ;
if ( PadMapping [ 1 ] . enabled )
joystate [ 1 ] . joy = SDL_JoystickOpen ( PadMapping [ 1 ] . ID ) ;
if ( PadMapping [ 2 ] . enabled )
joystate [ 2 ] . joy = SDL_JoystickOpen ( PadMapping [ 2 ] . ID ) ;
if ( PadMapping [ 3 ] . enabled )
joystate [ 3 ] . joy = SDL_JoystickOpen ( PadMapping [ 3 ] . ID ) ;
NumPads = Search_Devices( ) ; // Populate joyinfo for all attached devices
/* Check if any of the pads failed to open. In Windows there is a strange "IDirectInputDevice2::
SetDataFormat() DirectX error -2147024809" after a few Open and Close */
if ( ( PadMapping [ 0 ] . enabled & & joys tate[ 0 ] . joy = = NULL )
| | ( PadMapping [ 1 ] . enabled & & joys tate[ 1 ] . joy = = NULL )
| | ( PadMapping [ 2 ] . enabled & & joys tate[ 2 ] . joy = = NULL )
| | ( PadMapping [ 3 ] . enabled & & joys tate[ 3 ] . joy = = NULL ) )
if ( ( PadMapping [ 0 ] . enabled & & PadS tate[ 0 ] . joy = = NULL )
| | ( PadMapping [ 1 ] . enabled & & PadS tate[ 1 ] . joy = = NULL )
| | ( PadMapping [ 2 ] . enabled & & PadS tate[ 2 ] . joy = = NULL )
| | ( PadMapping [ 3 ] . enabled & & PadS tate[ 3 ] . joy = = NULL ) )
{
_PADInitialize - > padNumber = - 1 ;
Console : : Print ( " %s \n " , SDL_GetError ( ) ) ;
@ -299,26 +274,12 @@ int Search_Devices()
DEBUG_INIT ( ) ;
# endif
int numjoy = SDL_NumJoysticks ( ) ;
if ( joyinfo )
/* SDL 1.3 use DirectInput instead of the old Microsoft Multimeda API, and with this we need
the SDL_INIT_VIDEO flag to */
if ( ! SDL_WasInit ( 0 ) )
if ( SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 )
{
delete [ ] joyinfo ;
joyinfo = new CONTROLLER_INFO [ numjoy ] ;
}
else
{
joyinfo = new CONTROLLER_INFO [ numjoy ] ;
}
// Warn the user if no PadMapping are detected
if ( numjoy = = 0 )
{
# ifdef _WIN32
//MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING);
# else
printf ( " No Joystick detected! \n " ) ;
# endif
PanicAlert ( " Could not initialize SDL: %s " , SDL_GetError ( ) ) ;
return 0 ;
}
@ -327,16 +288,36 @@ int Search_Devices()
fprintf ( pFile , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> \n " ) ;
# endif
// Get device status
int numjoy = SDL_NumJoysticks ( ) ;
for ( int i = 0 ; i < numjoy ; i + + )
{
// Open the device to be able to read the values
joyinfo [ i ] . joy = SDL_JoystickOpen ( i ) ;
joyinfo [ i ] . ID = i ;
joyinfo [ i ] . NumAxes = SDL_JoystickNumAxes ( joyinfo [ i ] . joy ) ;
joyinfo [ i ] . NumButton s = SDL_JoystickNumButtons ( joyinfo [ i ] . joy ) ;
joyinfo [ i ] . NumBall s = SDL_JoystickNumBall s ( joyinfo [ i ] . joy ) ;
joyinfo [ i ] . NumHat s = SDL_JoystickNumHat s ( joyinfo [ i ] . joy ) ;
joyinfo [ i ] . Name = SDL_JoystickName ( i ) ;
CONTROLLER_INFO Tmp ;
Tmp . joy = SDL_JoystickOpen ( i ) ;
Tmp . ID = i ;
Tmp . NumAxe s = SDL_JoystickNumAxes ( Tmp . joy ) ;
Tmp . NumButton s = SDL_JoystickNumButton s ( Tmp . joy ) ;
Tmp . NumBall s = SDL_JoystickNumBall s ( Tmp . joy ) ;
Tmp . NumHats = SDL_JoystickNumHats ( Tmp . joy ) ;
Tmp . Name = SDL_JoystickName ( i ) ;
// Check if the device is okay
if ( Tmp . NumAxes = = 0
& & Tmp . NumBalls = = 0
& & Tmp . NumButtons = = 0
& & Tmp . NumHats = = 0
)
{
Tmp . Good = false ;
}
else
{
NumGoodPads + + ;
Tmp . Good = true ;
}
joyinfo . push_back ( Tmp ) ;
# ifdef _DEBUG
fprintf ( pFile , " ID: %d \n " , i ) ;
@ -351,9 +332,26 @@ int Search_Devices()
if ( SDL_JoystickOpened ( i ) ) SDL_JoystickClose ( joyinfo [ i ] . joy ) ;
}
return numjoy ;
// Warn the user if no gamepads are detected
if ( NumGoodPads = = 0 & & emulator_running )
{
PanicAlert ( " No Joystick detected " ) ;
return joyinfo . size ( ) ;
}
// Load PadMapping[] etc
g_Config . Load ( ) ;
// Update the PadState[].joy handle
for ( int i = 0 ; i < 4 ; i + + )
{
if ( PadMapping [ i ] . enabled & & joyinfo . size ( ) > PadMapping [ i ] . ID )
if ( joyinfo . at ( PadMapping [ i ] . ID ) . Good )
PadState [ i ] . joy = SDL_JoystickOpen ( PadMapping [ i ] . ID ) ;
}
return joyinfo . size ( ) ;
}
// Shutdown PAD (stop emulation)
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
@ -362,16 +360,16 @@ int Search_Devices()
Called from: The Dolphin Core, ConfigBox::OnClose() */
void Shutdown ( )
{
// Console::Print("Shutdown: %i\n", SDL_WasInit(0));
Console: : Print ( " Shutdown: %i \n " , SDL_WasInit ( 0 ) ) ;
if ( PadMapping [ 0 ] . enabled & & SDL_JoystickOpened ( PadMapping [ 0 ] . ID ) )
SDL_JoystickClose ( joystate [ 0 ] . joy ) ;
i f ( PadMapping [ 1 ] . enabled & & SDL_JoystickOpened ( PadMapping [ 1 ] . ID ) )
SDL_JoystickClose ( joystate [ 1 ] . joy ) ;
if ( PadMapping [ 2 ] . enabled & & SDL_JoystickOpened ( PadMapping [ 2 ] . ID ) )
SDL_JoystickClose ( joystate [ 2 ] . joy ) ;
if ( PadMapping [ 3 ] . enabled & & SDL_JoystickOpened ( PadMapping [ 3 ] . ID ) )
SDL_JoystickClose ( joystate [ 3 ] . joy ) ;
/* Close all devices carefully. We must check that we are not accessing any undefined
vector elements or any bad devices */
for ( int i = 0 ; i < 4 ; i + + )
{
if ( PadMapping [ i ] . enabled & & joyinfo . size ( ) > PadMapping [ i ] . ID )
if ( joyinfo . at ( PadMapping [ i ] . ID ) . Good )
if ( SDL_JoystickOpened ( PadMapping [ i ] . ID ) ) SDL_JoystickClose ( PadState [ i ] . joy ) ;
}
SDL_Quit ( ) ;
@ -379,8 +377,10 @@ void Shutdown()
DEBUG_QUIT ( ) ;
# endif
delete [ ] joyinfo ;
joyinfo = NULL ;
// Clear the physical device info
//delete [] joyinfo;
//joyinfo = NULL;
joyinfo . clear ( ) ;
emulator_running = false ;
@ -404,13 +404,13 @@ void PAD_Input(u16 _Key, u8 _UpDown)
for ( int j = CTL_L_SHOULDER ; j < = CTL_START ; j + + )
{
if ( PadMapping [ i ] . buttons [ j ] = = _Key )
{ joys tate[ i ] . buttons [ j ] = _UpDown ; break ; }
{ PadS tate[ i ] . buttons [ j ] = _UpDown ; break ; }
}
for ( int j = CTL_D_PAD_UP ; j < = CTL_D_PAD_RIGHT ; j + + )
{
if ( PadMapping [ i ] . dpad2 [ j ] = = _Key )
{ joys tate[ i ] . dpad2 [ j ] = _UpDown ; break ; }
{ PadS tate[ i ] . dpad2 [ j ] = _UpDown ; break ; }
}
}
@ -430,8 +430,10 @@ void DoState(unsigned char **ptr, int mode) {}
// Function: Gives the current pad status to the Core
void PAD_GetStatus ( u8 _numPAD , SPADStatus * _pPADStatus )
{
if ( ! PadMapping [ _numPAD ] . enabled )
return ;
Console : : Print ( " %i %i %i \n " , _numPAD , PadMapping [ _numPAD ] . enabled , PadState [ _numPAD ] . joy ) ;
// Check if the pad is enabled
if ( ! PadMapping [ _numPAD ] . enabled | | ! PadState [ _numPAD ] . joy ) return ;
// Clear pad status
memset ( _pPADStatus , 0 , sizeof ( SPADStatus ) ) ;
@ -447,12 +449,12 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// -----------
// Read axis values
int i_main_stick_x = joys tate[ _numPAD ] . axis [ CTL_MAIN_X ] ;
int i_main_stick_y = - joys tate[ _numPAD ] . axis [ CTL_MAIN_Y ] ;
int i_sub_stick_x = joys tate[ _numPAD ] . axis [ CTL_SUB_X ] ;
int i_sub_stick_y = - joys tate[ _numPAD ] . axis [ CTL_SUB_Y ] ;
int TriggerLeft = joys tate[ _numPAD ] . axis [ CTL_L_SHOULDER ] ;
int TriggerRight = joys tate[ _numPAD ] . axis [ CTL_R_SHOULDER ] ;
int i_main_stick_x = PadS tate[ _numPAD ] . axis [ CTL_MAIN_X ] ;
int i_main_stick_y = - PadS tate[ _numPAD ] . axis [ CTL_MAIN_Y ] ;
int i_sub_stick_x = PadS tate[ _numPAD ] . axis [ CTL_SUB_X ] ;
int i_sub_stick_y = - PadS tate[ _numPAD ] . axis [ CTL_SUB_Y ] ;
int TriggerLeft = PadS tate[ _numPAD ] . axis [ CTL_L_SHOULDER ] ;
int TriggerRight = PadS tate[ _numPAD ] . axis [ CTL_R_SHOULDER ] ;
// Check if we should make adjustments
if ( PadMapping [ _numPAD ] . bSquareToCircle )
@ -490,10 +492,10 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// The L and R triggers
// -----------
int TriggerValue = 255 ;
if ( joys tate[ _numPAD ] . halfpress ) TriggerValue = 100 ;
if ( PadS tate[ _numPAD ] . halfpress ) TriggerValue = 100 ;
_pPADStatus - > button | = PAD_USE_ORIGIN ; // Neutral value, no button pressed
if ( joys tate[ _numPAD ] . buttons [ CTL_L_SHOULDER ] )
if ( PadS tate[ _numPAD ] . buttons [ CTL_L_SHOULDER ] )
{
_pPADStatus - > button | = PAD_TRIGGER_L ;
_pPADStatus - > triggerLeft = TriggerValue ;
@ -501,7 +503,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
else if ( TriggerLeft > 0 )
_pPADStatus - > triggerLeft = TriggerLeft ;
if ( joys tate[ _numPAD ] . buttons [ CTL_R_SHOULDER ] )
if ( PadS tate[ _numPAD ] . buttons [ CTL_R_SHOULDER ] )
{
_pPADStatus - > button | = PAD_TRIGGER_R ;
_pPADStatus - > triggerRight = TriggerValue ;
@ -517,20 +519,20 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
///////////////////////////////////////////////////
// The digital buttons
// -----------
if ( joys tate[ _numPAD ] . buttons [ CTL_A_BUTTON ] )
if ( PadS tate[ _numPAD ] . buttons [ CTL_A_BUTTON ] )
{
_pPADStatus - > button | = PAD_BUTTON_A ;
_pPADStatus - > analogA = 255 ; // Perhaps support pressure?
}
if ( joys tate[ _numPAD ] . buttons [ CTL_B_BUTTON ] )
if ( PadS tate[ _numPAD ] . buttons [ CTL_B_BUTTON ] )
{
_pPADStatus - > button | = PAD_BUTTON_B ;
_pPADStatus - > analogB = 255 ; // Perhaps support pressure?
}
if ( joys tate[ _numPAD ] . buttons [ CTL_X_BUTTON ] ) _pPADStatus - > button | = PAD_BUTTON_X ;
if ( joys tate[ _numPAD ] . buttons [ CTL_Y_BUTTON ] ) _pPADStatus - > button | = PAD_BUTTON_Y ;
if ( joys tate[ _numPAD ] . buttons [ CTL_Z_TRIGGER ] ) _pPADStatus - > button | = PAD_TRIGGER_Z ;
if ( joys tate[ _numPAD ] . buttons [ CTL_START ] ) _pPADStatus - > button | = PAD_BUTTON_START ;
if ( PadS tate[ _numPAD ] . buttons [ CTL_X_BUTTON ] ) _pPADStatus - > button | = PAD_BUTTON_X ;
if ( PadS tate[ _numPAD ] . buttons [ CTL_Y_BUTTON ] ) _pPADStatus - > button | = PAD_BUTTON_Y ;
if ( PadS tate[ _numPAD ] . buttons [ CTL_Z_TRIGGER ] ) _pPADStatus - > button | = PAD_TRIGGER_Z ;
if ( PadS tate[ _numPAD ] . buttons [ CTL_START ] ) _pPADStatus - > button | = PAD_BUTTON_START ;
///////////////////////////////////////////////////
@ -538,20 +540,20 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// -----------
if ( PadMapping [ _numPAD ] . controllertype = = CTL_DPAD_HAT )
{
if ( joys tate[ _numPAD ] . dpad = = SDL_HAT_LEFTUP | | joys tate[ _numPAD ] . dpad = = SDL_HAT_UP | | joys tate[ _numPAD ] . dpad = = SDL_HAT_RIGHTUP ) _pPADStatus - > button | = PAD_BUTTON_UP ;
if ( joys tate[ _numPAD ] . dpad = = SDL_HAT_LEFTUP | | joys tate[ _numPAD ] . dpad = = SDL_HAT_LEFT | | joys tate[ _numPAD ] . dpad = = SDL_HAT_LEFTDOWN ) _pPADStatus - > button | = PAD_BUTTON_LEFT ;
if ( joys tate[ _numPAD ] . dpad = = SDL_HAT_LEFTDOWN | | joys tate[ _numPAD ] . dpad = = SDL_HAT_DOWN | | joys tate[ _numPAD ] . dpad = = SDL_HAT_RIGHTDOWN ) _pPADStatus - > button | = PAD_BUTTON_DOWN ;
if ( joys tate[ _numPAD ] . dpad = = SDL_HAT_RIGHTUP | | joys tate[ _numPAD ] . dpad = = SDL_HAT_RIGHT | | joys tate[ _numPAD ] . dpad = = SDL_HAT_RIGHTDOWN ) _pPADStatus - > button | = PAD_BUTTON_RIGHT ;
if ( PadS tate[ _numPAD ] . dpad = = SDL_HAT_LEFTUP | | PadS tate[ _numPAD ] . dpad = = SDL_HAT_UP | | PadS tate[ _numPAD ] . dpad = = SDL_HAT_RIGHTUP ) _pPADStatus - > button | = PAD_BUTTON_UP ;
if ( PadS tate[ _numPAD ] . dpad = = SDL_HAT_LEFTUP | | PadS tate[ _numPAD ] . dpad = = SDL_HAT_LEFT | | PadS tate[ _numPAD ] . dpad = = SDL_HAT_LEFTDOWN ) _pPADStatus - > button | = PAD_BUTTON_LEFT ;
if ( PadS tate[ _numPAD ] . dpad = = SDL_HAT_LEFTDOWN | | PadS tate[ _numPAD ] . dpad = = SDL_HAT_DOWN | | PadS tate[ _numPAD ] . dpad = = SDL_HAT_RIGHTDOWN ) _pPADStatus - > button | = PAD_BUTTON_DOWN ;
if ( PadS tate[ _numPAD ] . dpad = = SDL_HAT_RIGHTUP | | PadS tate[ _numPAD ] . dpad = = SDL_HAT_RIGHT | | PadS tate[ _numPAD ] . dpad = = SDL_HAT_RIGHTDOWN ) _pPADStatus - > button | = PAD_BUTTON_RIGHT ;
}
else
{
if ( joys tate[ _numPAD ] . dpad2 [ CTL_D_PAD_UP ] )
if ( PadS tate[ _numPAD ] . dpad2 [ CTL_D_PAD_UP ] )
_pPADStatus - > button | = PAD_BUTTON_UP ;
if ( joys tate[ _numPAD ] . dpad2 [ CTL_D_PAD_DOWN ] )
if ( PadS tate[ _numPAD ] . dpad2 [ CTL_D_PAD_DOWN ] )
_pPADStatus - > button | = PAD_BUTTON_DOWN ;
if ( joys tate[ _numPAD ] . dpad2 [ CTL_D_PAD_LEFT ] )
if ( PadS tate[ _numPAD ] . dpad2 [ CTL_D_PAD_LEFT ] )
_pPADStatus - > button | = PAD_BUTTON_LEFT ;
if ( joys tate[ _numPAD ] . dpad2 [ CTL_D_PAD_RIGHT ] )
if ( PadS tate[ _numPAD ] . dpad2 [ CTL_D_PAD_RIGHT ] )
_pPADStatus - > button | = PAD_BUTTON_RIGHT ;
}
@ -564,10 +566,18 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
/* Debugging
Console::ClearScreen();
Console::Print(
"Pad %i: %i %i\n"
"Trigger type: %s Left:%04x Right:%04x Value:%i\n"
"Buttons: %i X:%i\n"
"D-Pad type: %s L:%i R:%i U:%i D:%i",
_numPAD, PadMapping[_numPAD].enabled, PadState[_numPAD].joy,
(PadMapping[_numPAD].triggertype ? "CTL_TRIGGER_XINPUT" : "CTL_TRIGGER_SDL"),
TriggerLeft, T riggerRight, TriggerValue,
_pPADStatus->triggerLeft, _pPADStatus->t riggerRight, TriggerValue,
_pPADStatus->button, PadState[_numPAD].buttons[CTL_X_BUTTON],
(PadMapping[_numPAD].controllertype ? "CTL_DPAD_CUSTOM" : "CTL_DPAD_HAT"),
0, 0, 0, 0
);*/
@ -587,6 +597,8 @@ unsigned int PAD_GetAttachedPads()
if ( PadMapping [ 2 ] . enabled ) connected | = 4 ;
if ( PadMapping [ 3 ] . enabled ) connected | = 8 ;
//Console::Print("PAD_GetAttachedPads: %i %i %i\n", PadMapping[0].enabled, PadMapping[1].enabled, PadMapping[2].enabled, PadMapping[3].enabled);
return connected ;
}
@ -608,7 +620,7 @@ unsigned int PAD_GetAttachedPads()
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
int Pad_Convert ( int _val )
{
/* If the limits on joys tate[].axis[] actually is a u16 then we don't need this
/* If the limits on PadS tate[].axis[] actually is a u16 then we don't need this
but if it's not actually limited to that we need to apply these limits */
if ( _val > 32767 ) _val = 32767 ; // upper limit
if ( _val < - 32768 ) _val = - 32768 ; // lower limit
@ -713,7 +725,7 @@ std::vector<int> Pad_Square_to_Circle(int _x, int _y, int _pad)
// Read current joystick status
/* <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
The value PadMapping[].buttons[] is the number of the assigned joypad button,
joys tate[].buttons[] is the status of the button, it becomes 0 (no pressed) or 1 (pressed) */
PadS tate[].buttons[] is the status of the button, it becomes 0 (no pressed) or 1 (pressed) */
// Read buttons status. Called from GetJoyState().
@ -723,7 +735,7 @@ void ReadButton(int controller, int button)
int ctl_button = PadMapping [ controller ] . buttons [ button ] ;
if ( ctl_button < joyinfo [ PadMapping [ controller ] . ID ] . NumButtons )
{
joys tate[ controller ] . buttons [ button ] = SDL_JoystickGetButton ( joys tate[ controller ] . joy , ctl_button ) ;
PadS tate[ controller ] . buttons [ button ] = SDL_JoystickGetButton ( PadS tate[ controller ] . joy , ctl_button ) ;
}
}
@ -731,7 +743,7 @@ void ReadButton(int controller, int button)
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
/* Called from: PAD_GetStatus()
Input: The virtual device 0, 1, 2 or 3
Function: Updates the joys tate struct with the current pad status. The input value "controller" is
Function: Updates the PadS tate struct with the current pad status. The input value "controller" is
for a virtual controller 0 to 3. */
void GetJoyState ( int controller )
{
@ -742,36 +754,37 @@ void GetJoyState(int controller)
int Buttons = joyinfo [ PadMapping [ controller ] . ID ] . NumButtons ;
// Update axis states. It doesn't hurt much if we happen to ask for nonexisting axises here.
joys tate[ controller ] . axis [ CTL_MAIN_X ] = SDL_JoystickGetAxis ( joys tate[ controller ] . joy , PadMapping [ controller ] . axis [ CTL_MAIN_X ] ) ;
joys tate[ controller ] . axis [ CTL_MAIN_Y ] = SDL_JoystickGetAxis ( joys tate[ controller ] . joy , PadMapping [ controller ] . axis [ CTL_MAIN_Y ] ) ;
joys tate[ controller ] . axis [ CTL_SUB_X ] = SDL_JoystickGetAxis ( joys tate[ controller ] . joy , PadMapping [ controller ] . axis [ CTL_SUB_X ] ) ;
joys tate[ controller ] . axis [ CTL_SUB_Y ] = SDL_JoystickGetAxis ( joys tate[ controller ] . joy , PadMapping [ controller ] . axis [ CTL_SUB_Y ] ) ;
PadS tate[ controller ] . axis [ CTL_MAIN_X ] = SDL_JoystickGetAxis ( PadS tate[ controller ] . joy , PadMapping [ controller ] . axis [ CTL_MAIN_X ] ) ;
PadS tate[ controller ] . axis [ CTL_MAIN_Y ] = SDL_JoystickGetAxis ( PadS tate[ controller ] . joy , PadMapping [ controller ] . axis [ CTL_MAIN_Y ] ) ;
PadS tate[ controller ] . axis [ CTL_SUB_X ] = SDL_JoystickGetAxis ( PadS tate[ controller ] . joy , PadMapping [ controller ] . axis [ CTL_SUB_X ] ) ;
PadS tate[ controller ] . axis [ CTL_SUB_Y ] = SDL_JoystickGetAxis ( PadS tate[ controller ] . joy , PadMapping [ controller ] . axis [ CTL_SUB_Y ] ) ;
// Update trigger axises
# ifdef _WIN32
if ( PadMapping [ controller ] . triggertype = = CTL_TRIGGER_SDL )
{
# endif
joys tate[ controller ] . axis [ CTL_L_SHOULDER ] = SDL_JoystickGetAxis ( joys tate[ controller ] . joy , PadMapping [ controller ] . buttons [ CTL_L_SHOULDER ] - 1000 ) ;
joys tate[ controller ] . axis [ CTL_R_SHOULDER ] = SDL_JoystickGetAxis ( joys tate[ controller ] . joy , PadMapping [ controller ] . buttons [ CTL_R_SHOULDER ] - 1000 ) ;
if ( PadMapping [ controller ] . buttons [ CTL_L_SHOULDER ] > = 1000 ) PadS tate[ controller ] . axis [ CTL_L_SHOULDER ] = SDL_JoystickGetAxis ( PadS tate[ controller ] . joy , PadMapping [ controller ] . buttons [ CTL_L_SHOULDER ] - 1000 ) ;
if ( PadMapping [ controller ] . buttons [ CTL_R_SHOULDER ] > = 1000 ) PadS tate[ controller ] . axis [ CTL_R_SHOULDER ] = SDL_JoystickGetAxis ( PadS tate[ controller ] . joy , PadMapping [ controller ] . buttons [ CTL_R_SHOULDER ] - 1000 ) ;
# ifdef _WIN32
}
else
{
joys tate[ controller ] . axis [ CTL_L_SHOULDER ] = XInput : : GetXI ( 0 , PadMapping [ controller ] . buttons [ CTL_L_SHOULDER ] - 1000 ) ;
joys tate[ controller ] . axis [ CTL_R_SHOULDER ] = XInput : : GetXI ( 0 , PadMapping [ controller ] . buttons [ CTL_R_SHOULDER ] - 1000 ) ;
PadS tate[ controller ] . axis [ CTL_L_SHOULDER ] = XInput : : GetXI ( 0 , PadMapping [ controller ] . buttons [ CTL_L_SHOULDER ] - 1000 ) ;
PadS tate[ controller ] . axis [ CTL_R_SHOULDER ] = XInput : : GetXI ( 0 , PadMapping [ controller ] . buttons [ CTL_R_SHOULDER ] - 1000 ) ;
}
# endif
/* Debugging
Console::ClearScreen();
Console::Print("sfjsdfgsdf");
Console::Print(
"Controller and handle: %i %i\n"
"Triggers:%i %i %i %i %i\n",
controller, (int)joys tate[controller].joy,
controller, (int)PadS tate[controller].joy,
PadMapping[controller].triggertype,
PadMapping[controller].buttons[CTL_L_SHOULDER], PadMapping[controller].buttons[CTL_R_SHOULDER],
joys tate[controller].axis[CTL_L_SHOULDER], joys tate[controller].axis[CTL_R_SHOULDER]
PadS tate[controller].axis[CTL_L_SHOULDER], PadS tate[controller].axis[CTL_R_SHOULDER]
); */
ReadButton ( controller , CTL_L_SHOULDER ) ;
@ -785,25 +798,25 @@ void GetJoyState(int controller)
//
if ( PadMapping [ controller ] . halfpress < joyinfo [ controller ] . NumButtons )
joys tate[ controller ] . halfpress = SDL_JoystickGetButton ( joys tate[ controller ] . joy , PadMapping [ controller ] . halfpress ) ;
PadS tate[ controller ] . halfpress = SDL_JoystickGetButton ( PadS tate[ controller ] . joy , PadMapping [ controller ] . halfpress ) ;
// Check if we have an analog or digital joypad
if ( PadMapping [ controller ] . controllertype = = CTL_DPAD_HAT )
{
joys tate[ controller ] . dpad = SDL_JoystickGetHat ( joys tate[ controller ] . joy , PadMapping [ controller ] . dpad ) ;
PadS tate[ controller ] . dpad = SDL_JoystickGetHat ( PadS tate[ controller ] . joy , PadMapping [ controller ] . dpad ) ;
}
else
{
/* Only do this if the assigned button is in range (to allow for the current way of saving keyboard
keys in the same array) */
if ( PadMapping [ controller ] . dpad2 [ CTL_D_PAD_UP ] < = Buttons )
joys tate[ controller ] . dpad2 [ CTL_D_PAD_UP ] = SDL_JoystickGetButton ( joys tate[ controller ] . joy , PadMapping [ controller ] . dpad2 [ CTL_D_PAD_UP ] ) ;
PadS tate[ controller ] . dpad2 [ CTL_D_PAD_UP ] = SDL_JoystickGetButton ( PadS tate[ controller ] . joy , PadMapping [ controller ] . dpad2 [ CTL_D_PAD_UP ] ) ;
if ( PadMapping [ controller ] . dpad2 [ CTL_D_PAD_DOWN ] < = Buttons )
joys tate[ controller ] . dpad2 [ CTL_D_PAD_DOWN ] = SDL_JoystickGetButton ( joys tate[ controller ] . joy , PadMapping [ controller ] . dpad2 [ CTL_D_PAD_DOWN ] ) ;
PadS tate[ controller ] . dpad2 [ CTL_D_PAD_DOWN ] = SDL_JoystickGetButton ( PadS tate[ controller ] . joy , PadMapping [ controller ] . dpad2 [ CTL_D_PAD_DOWN ] ) ;
if ( PadMapping [ controller ] . dpad2 [ CTL_D_PAD_LEFT ] < = Buttons )
joys tate[ controller ] . dpad2 [ CTL_D_PAD_LEFT ] = SDL_JoystickGetButton ( joys tate[ controller ] . joy , PadMapping [ controller ] . dpad2 [ CTL_D_PAD_LEFT ] ) ;
PadS tate[ controller ] . dpad2 [ CTL_D_PAD_LEFT ] = SDL_JoystickGetButton ( PadS tate[ controller ] . joy , PadMapping [ controller ] . dpad2 [ CTL_D_PAD_LEFT ] ) ;
if ( PadMapping [ controller ] . dpad2 [ CTL_D_PAD_RIGHT ] < = Buttons )
joys tate[ controller ] . dpad2 [ CTL_D_PAD_RIGHT ] = SDL_JoystickGetButton ( joys tate[ controller ] . joy , PadMapping [ controller ] . dpad2 [ CTL_D_PAD_RIGHT ] ) ;
PadS tate[ controller ] . dpad2 [ CTL_D_PAD_RIGHT ] = SDL_JoystickGetButton ( PadS tate[ controller ] . joy , PadMapping [ controller ] . dpad2 [ CTL_D_PAD_RIGHT ] ) ;
}
}
//////////////////////////////////////////////////////////////////////////////////////////