2008-07-22 09:02:26 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Project description
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
// Name: nJoy
|
|
|
|
|
// Description: A Dolphin Compatible Input Plugin
|
|
|
|
|
//
|
|
|
|
|
// Author: Falcon4ever (nJoy@falcon4ever.com)
|
|
|
|
|
// Site: www.multigesture.net
|
|
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Licensetype: GNU General Public License (GPL)
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
//
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
//
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "nJoy.h"
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Variables
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
FILE *pFile;
|
|
|
|
|
HINSTANCE nJoy_hInst = NULL;
|
|
|
|
|
CONTROLLER_INFO *joyinfo = 0;
|
|
|
|
|
CONTROLLER_STATE joystate[4];
|
|
|
|
|
CONTROLLER_MAPPING joysticks[4];
|
|
|
|
|
bool emulator_running = FALSE;
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// DllMain
|
2008-07-23 19:23:36 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-07-22 09:02:26 +00:00
|
|
|
|
BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle
|
|
|
|
|
DWORD dwReason, // reason called
|
|
|
|
|
LPVOID lpvReserved) // reserved
|
|
|
|
|
{
|
|
|
|
|
InitCommonControls();
|
|
|
|
|
|
|
|
|
|
nJoy_hInst = hinstDLL;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2008-07-23 19:23:36 +00:00
|
|
|
|
#endif
|
2008-07-22 09:02:26 +00:00
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Input Plugin Functions (from spec's)
|
|
|
|
|
// <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><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
// Get properties of plugin
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
|
|
|
|
{
|
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_PAD;
|
|
|
|
|
|
|
|
|
|
#ifndef _DEBUG
|
|
|
|
|
sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION " by Falcon4ever");
|
|
|
|
|
#else
|
|
|
|
|
sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION" (Debug) by Falcon4ever");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call about dialog
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void DllAbout(HWND _hParent)
|
2008-07-23 19:23:36 +00:00
|
|
|
|
{
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-07-23 19:23:36 +00:00
|
|
|
|
OpenAbout(nJoy_hInst, _hParent);
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#endif
|
2008-07-22 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Call config dialog
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void DllConfig(HWND _hParent)
|
2008-07-23 19:23:36 +00:00
|
|
|
|
{
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-07-22 09:02:26 +00:00
|
|
|
|
if(SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
|
|
|
|
{
|
|
|
|
|
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 09:05:59 +00:00
|
|
|
|
LoadConfig(); // load settings
|
2008-07-22 09:02:26 +00:00
|
|
|
|
if(OpenConfig(nJoy_hInst, _hParent))
|
2008-07-23 09:05:59 +00:00
|
|
|
|
{
|
2008-07-22 09:02:26 +00:00
|
|
|
|
SaveConfig();
|
2008-07-23 09:05:59 +00:00
|
|
|
|
}
|
2008-07-23 19:23:36 +00:00
|
|
|
|
LoadConfig(); // reload settings
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#endif
|
2008-07-22 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Init PAD (start 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>
|
|
|
|
|
void PAD_Initialize(SPADInitialize _PADInitialize)
|
|
|
|
|
{
|
|
|
|
|
emulator_running = TRUE;
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
DEBUG_INIT();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if(SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
2008-07-23 19:23:36 +00:00
|
|
|
|
{
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-07-23 19:23:36 +00:00
|
|
|
|
MessageBox(NULL, SDL_GetError(), "Could not initialize SDL!", MB_ICONERROR);
|
|
|
|
|
#else
|
|
|
|
|
printf("Could not initialize SDL! (%s)\n", SDL_GetError());
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#endif
|
2008-07-22 09:02:26 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LoadConfig(); // Load joystick mapping
|
|
|
|
|
|
|
|
|
|
if(joysticks[0].enabled)
|
|
|
|
|
joystate[0].joy = SDL_JoystickOpen(joysticks[0].ID);
|
|
|
|
|
if(joysticks[1].enabled)
|
|
|
|
|
joystate[1].joy = SDL_JoystickOpen(joysticks[1].ID);
|
|
|
|
|
if(joysticks[2].enabled)
|
|
|
|
|
joystate[2].joy = SDL_JoystickOpen(joysticks[2].ID);
|
|
|
|
|
if(joysticks[3].enabled)
|
|
|
|
|
joystate[3].joy = SDL_JoystickOpen(joysticks[3].ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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>
|
|
|
|
|
void PAD_Shutdown()
|
|
|
|
|
{
|
|
|
|
|
if(joysticks[0].enabled)
|
|
|
|
|
SDL_JoystickClose(joystate[0].joy);
|
|
|
|
|
if(joysticks[1].enabled)
|
|
|
|
|
SDL_JoystickClose(joystate[1].joy);
|
|
|
|
|
if(joysticks[2].enabled)
|
|
|
|
|
SDL_JoystickClose(joystate[2].joy);
|
|
|
|
|
if(joysticks[3].enabled)
|
|
|
|
|
SDL_JoystickClose(joystate[3].joy);
|
|
|
|
|
|
|
|
|
|
SDL_Quit();
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
DEBUG_QUIT();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
delete [] joyinfo;
|
|
|
|
|
|
|
|
|
|
emulator_running = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set PAD status
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void PAD_GetStatus(BYTE _numPAD, SPADStatus* _pPADStatus)
|
|
|
|
|
{
|
|
|
|
|
if(!joysticks[_numPAD].enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// clear pad status
|
|
|
|
|
memset(_pPADStatus, 0, sizeof(SPADStatus));
|
|
|
|
|
|
|
|
|
|
// get pad status
|
|
|
|
|
GetJoyState(_numPAD);
|
|
|
|
|
|
|
|
|
|
// Reset!
|
|
|
|
|
int base = 0x80;
|
|
|
|
|
_pPADStatus->stickY = base;
|
|
|
|
|
_pPADStatus->stickX = base;
|
|
|
|
|
_pPADStatus->substickX = base;
|
|
|
|
|
_pPADStatus->substickY = base;
|
|
|
|
|
_pPADStatus->button |= PAD_USE_ORIGIN;
|
|
|
|
|
|
|
|
|
|
// Set analog controllers
|
|
|
|
|
// Set Deadzones perhaps out of function
|
|
|
|
|
int deadzone = ((float)(128.00/100.00)) * (float)(joysticks[_numPAD].deadzone+1);
|
|
|
|
|
int deadzone2 = ((float)(-128.00/100.00)) * (float)(joysticks[_numPAD].deadzone+1);
|
|
|
|
|
|
|
|
|
|
// Adjust range
|
|
|
|
|
// The value returned by SDL_JoystickGetAxis is a signed integer (-32768 to 32768)
|
|
|
|
|
// The value used for the gamecube controller is an unsigned char (0 to 255)
|
|
|
|
|
int main_stick_x = (joystate[_numPAD].axis[CTL_MAIN_X]>>8);
|
2008-07-22 14:23:27 +00:00
|
|
|
|
int main_stick_y = -(joystate[_numPAD].axis[CTL_MAIN_Y]>>8);
|
2008-07-22 09:02:26 +00:00
|
|
|
|
int sub_stick_x = (joystate[_numPAD].axis[CTL_SUB_X]>>8);
|
2008-07-22 14:23:27 +00:00
|
|
|
|
int sub_stick_y = -(joystate[_numPAD].axis[CTL_SUB_Y]>>8);
|
2008-07-22 09:02:26 +00:00
|
|
|
|
|
|
|
|
|
// Quick fix
|
|
|
|
|
if(main_stick_x > 127)
|
|
|
|
|
main_stick_x = 127;
|
|
|
|
|
if(main_stick_y > 127)
|
|
|
|
|
main_stick_y = 127;
|
|
|
|
|
if(sub_stick_x > 127)
|
|
|
|
|
sub_stick_x = 127;
|
|
|
|
|
if(sub_stick_y > 127)
|
|
|
|
|
sub_stick_y = 127;
|
|
|
|
|
|
|
|
|
|
if(main_stick_x < -128)
|
|
|
|
|
main_stick_x = -128;
|
|
|
|
|
if(main_stick_y < -128)
|
|
|
|
|
main_stick_y = -128;
|
|
|
|
|
if(sub_stick_x < -128)
|
|
|
|
|
sub_stick_x = -128;
|
|
|
|
|
if(sub_stick_y < -128)
|
|
|
|
|
sub_stick_y = -128;
|
|
|
|
|
|
|
|
|
|
// Send values to Dolpin
|
|
|
|
|
if ((main_stick_x < deadzone2) || (main_stick_x > deadzone)) _pPADStatus->stickX += main_stick_x;
|
2008-07-22 14:23:27 +00:00
|
|
|
|
if ((main_stick_y < deadzone2) || (main_stick_y > deadzone)) _pPADStatus->stickY += main_stick_y;
|
2008-07-22 09:02:26 +00:00
|
|
|
|
if ((sub_stick_x < deadzone2) || (sub_stick_x > deadzone)) _pPADStatus->substickX += sub_stick_x;
|
2008-07-22 14:23:27 +00:00
|
|
|
|
if ((sub_stick_y < deadzone2) || (sub_stick_y > deadzone)) _pPADStatus->substickY += sub_stick_y;
|
2008-07-22 09:02:26 +00:00
|
|
|
|
|
2008-07-23 00:49:20 +00:00
|
|
|
|
int triggervalue = 255;
|
|
|
|
|
if (joystate[_numPAD].halfpress)
|
|
|
|
|
triggervalue = 100;
|
|
|
|
|
|
2008-07-22 09:02:26 +00:00
|
|
|
|
// Set buttons
|
2008-07-22 14:32:13 +00:00
|
|
|
|
if (joystate[_numPAD].buttons[CTL_L_SHOULDER])
|
|
|
|
|
{
|
|
|
|
|
_pPADStatus->button|=PAD_TRIGGER_L;
|
2008-07-23 00:49:20 +00:00
|
|
|
|
_pPADStatus->triggerLeft = triggervalue;
|
2008-07-22 14:32:13 +00:00
|
|
|
|
}
|
|
|
|
|
if (joystate[_numPAD].buttons[CTL_R_SHOULDER])
|
|
|
|
|
{
|
|
|
|
|
_pPADStatus->button|=PAD_TRIGGER_R;
|
2008-07-23 00:49:20 +00:00
|
|
|
|
_pPADStatus->triggerRight = triggervalue;
|
2008-07-22 14:32:13 +00:00
|
|
|
|
}
|
2008-07-23 00:49:20 +00:00
|
|
|
|
|
2008-07-22 14:32:13 +00:00
|
|
|
|
if (joystate[_numPAD].buttons[CTL_A_BUTTON])
|
|
|
|
|
{
|
|
|
|
|
_pPADStatus->button|=PAD_BUTTON_A;
|
2008-07-23 00:49:20 +00:00
|
|
|
|
_pPADStatus->analogA = 255; // Perhaps support pressure?
|
2008-07-22 14:32:13 +00:00
|
|
|
|
}
|
|
|
|
|
if (joystate[_numPAD].buttons[CTL_B_BUTTON])
|
|
|
|
|
{
|
|
|
|
|
_pPADStatus->button|=PAD_BUTTON_B;
|
2008-07-23 00:49:20 +00:00
|
|
|
|
_pPADStatus->analogB = 255; // Perhaps support pressure?
|
2008-07-22 14:32:13 +00:00
|
|
|
|
}
|
2008-07-22 09:02:26 +00:00
|
|
|
|
if (joystate[_numPAD].buttons[CTL_X_BUTTON]) _pPADStatus->button|=PAD_BUTTON_X;
|
|
|
|
|
if (joystate[_numPAD].buttons[CTL_Y_BUTTON]) _pPADStatus->button|=PAD_BUTTON_Y;
|
|
|
|
|
if (joystate[_numPAD].buttons[CTL_Z_TRIGGER]) _pPADStatus->button|=PAD_TRIGGER_Z;
|
|
|
|
|
if (joystate[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START;
|
|
|
|
|
|
|
|
|
|
// Set D-pad
|
2008-07-23 00:49:20 +00:00
|
|
|
|
if(joysticks[_numPAD].controllertype == CTL_TYPE_JOYSTICK)
|
|
|
|
|
{
|
|
|
|
|
if(joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_UP || joystate[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP;
|
|
|
|
|
if(joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_LEFT || joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN ) _pPADStatus->button|=PAD_BUTTON_LEFT;
|
|
|
|
|
if(joystate[_numPAD].dpad == SDL_HAT_LEFTDOWN || joystate[_numPAD].dpad == SDL_HAT_DOWN || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_DOWN;
|
|
|
|
|
if(joystate[_numPAD].dpad == SDL_HAT_RIGHTUP || joystate[_numPAD].dpad == SDL_HAT_RIGHT || joystate[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_RIGHT;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(joystate[_numPAD].dpad2[CTL_D_PAD_UP])
|
|
|
|
|
_pPADStatus->button|=PAD_BUTTON_UP;
|
|
|
|
|
if(joystate[_numPAD].dpad2[CTL_D_PAD_DOWN])
|
|
|
|
|
_pPADStatus->button|=PAD_BUTTON_DOWN;
|
|
|
|
|
if(joystate[_numPAD].dpad2[CTL_D_PAD_LEFT])
|
|
|
|
|
_pPADStatus->button|=PAD_BUTTON_LEFT;
|
|
|
|
|
if(joystate[_numPAD].dpad2[CTL_D_PAD_RIGHT])
|
|
|
|
|
_pPADStatus->button|=PAD_BUTTON_RIGHT;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-22 09:02:26 +00:00
|
|
|
|
_pPADStatus->err = PAD_ERR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set PAD rumble
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void PAD_Rumble(BYTE _numPAD, unsigned int _uType, unsigned int _uStrength)
|
|
|
|
|
{
|
|
|
|
|
// not supported by SDL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set PAD attached pads
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
unsigned int PAD_GetAttachedPads()
|
|
|
|
|
{
|
|
|
|
|
unsigned int connected = 0;
|
|
|
|
|
|
|
|
|
|
LoadConfig();
|
|
|
|
|
|
|
|
|
|
if(joysticks[0].enabled)
|
|
|
|
|
connected |= 1;
|
|
|
|
|
if(joysticks[1].enabled)
|
|
|
|
|
connected |= 2;
|
|
|
|
|
if(joysticks[2].enabled)
|
|
|
|
|
connected |= 4;
|
|
|
|
|
if(joysticks[3].enabled)
|
|
|
|
|
connected |= 8;
|
|
|
|
|
|
|
|
|
|
return connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Savestates
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
unsigned int SaveLoadState(char *ptr, BOOL save)
|
|
|
|
|
{
|
|
|
|
|
// not used
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Custom Functions
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
// Request joystick state
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void GetJoyState(int controller)
|
|
|
|
|
{
|
|
|
|
|
SDL_JoystickUpdate();
|
|
|
|
|
|
|
|
|
|
joystate[controller].axis[CTL_MAIN_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_MAIN_X]);
|
|
|
|
|
joystate[controller].axis[CTL_MAIN_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_MAIN_Y]);
|
|
|
|
|
joystate[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_X]);
|
|
|
|
|
joystate[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(joystate[controller].joy, joysticks[controller].axis[CTL_SUB_Y]);
|
|
|
|
|
|
|
|
|
|
joystate[controller].buttons[CTL_L_SHOULDER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_L_SHOULDER]);
|
|
|
|
|
joystate[controller].buttons[CTL_R_SHOULDER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_R_SHOULDER]);
|
|
|
|
|
joystate[controller].buttons[CTL_A_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_A_BUTTON]);
|
|
|
|
|
joystate[controller].buttons[CTL_B_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_B_BUTTON]);
|
|
|
|
|
joystate[controller].buttons[CTL_X_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_X_BUTTON]);
|
|
|
|
|
joystate[controller].buttons[CTL_Y_BUTTON] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_Y_BUTTON]);
|
|
|
|
|
joystate[controller].buttons[CTL_Z_TRIGGER] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_Z_TRIGGER]);
|
|
|
|
|
joystate[controller].buttons[CTL_START] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].buttons[CTL_START]);
|
|
|
|
|
|
2008-07-23 00:49:20 +00:00
|
|
|
|
joystate[controller].halfpress = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].halfpress);
|
|
|
|
|
|
|
|
|
|
if(joysticks[controller].controllertype == CTL_TYPE_JOYSTICK)
|
|
|
|
|
joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, joysticks[controller].dpad);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
joystate[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_UP]);
|
|
|
|
|
joystate[controller].dpad2[CTL_D_PAD_DOWN] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_DOWN]);
|
|
|
|
|
joystate[controller].dpad2[CTL_D_PAD_LEFT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_LEFT]);
|
|
|
|
|
joystate[controller].dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_RIGHT]);
|
|
|
|
|
}
|
2008-07-22 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Search attached devices
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int Search_Devices()
|
|
|
|
|
{
|
|
|
|
|
// load config
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
DEBUG_INIT();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
int numjoy = SDL_NumJoysticks();
|
|
|
|
|
|
|
|
|
|
if(numjoy == 0)
|
2008-07-23 19:23:36 +00:00
|
|
|
|
{
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-07-23 19:23:36 +00:00
|
|
|
|
MessageBox(NULL, "No Joystick detected!", NULL, MB_ICONWARNING);
|
|
|
|
|
#else
|
|
|
|
|
printf("No Joystick detected!\n");
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#endif
|
2008-07-22 09:02:26 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(joyinfo)
|
|
|
|
|
{
|
|
|
|
|
delete [] joyinfo;
|
|
|
|
|
joyinfo = new CONTROLLER_INFO [numjoy];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
joyinfo = new CONTROLLER_INFO [numjoy];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
fprintf(pFile, "Scanning for devices\n");
|
|
|
|
|
fprintf(pFile, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < numjoy; i++ )
|
|
|
|
|
{
|
|
|
|
|
joyinfo[i].joy = SDL_JoystickOpen(i);
|
|
|
|
|
joyinfo[i].ID = i;
|
|
|
|
|
joyinfo[i].NumAxes = SDL_JoystickNumAxes(joyinfo[i].joy);
|
|
|
|
|
joyinfo[i].NumButtons = SDL_JoystickNumButtons(joyinfo[i].joy);
|
|
|
|
|
joyinfo[i].NumBalls = SDL_JoystickNumBalls(joyinfo[i].joy);
|
|
|
|
|
joyinfo[i].NumHats = SDL_JoystickNumHats(joyinfo[i].joy);
|
|
|
|
|
joyinfo[i].Name = SDL_JoystickName(i);
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
fprintf(pFile, "ID: %d\n", i);
|
|
|
|
|
fprintf(pFile, "Name: %s\n", joyinfo[i].Name);
|
|
|
|
|
fprintf(pFile, "Buttons: %d\n", joyinfo[i].NumButtons);
|
|
|
|
|
fprintf(pFile, "Axes: %d\n", joyinfo[i].NumAxes);
|
|
|
|
|
fprintf(pFile, "Hats: %d\n", joyinfo[i].NumHats);
|
|
|
|
|
fprintf(pFile, "Balls: %d\n\n", joyinfo[i].NumBalls);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Close if opened
|
|
|
|
|
if(SDL_JoystickOpened(i))
|
|
|
|
|
SDL_JoystickClose(joyinfo[i].joy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return numjoy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enable output log
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void DEBUG_INIT()
|
|
|
|
|
{
|
|
|
|
|
if(pFile)
|
|
|
|
|
return;
|
2008-07-23 19:23:36 +00:00
|
|
|
|
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-07-23 19:23:36 +00:00
|
|
|
|
char dateStr [9];
|
2008-07-22 09:02:26 +00:00
|
|
|
|
_strdate( dateStr);
|
2008-07-23 19:23:36 +00:00
|
|
|
|
char timeStr [9];
|
2008-07-22 09:02:26 +00:00
|
|
|
|
_strtime( timeStr );
|
2008-07-23 19:23:36 +00:00
|
|
|
|
#endif
|
2008-07-22 09:02:26 +00:00
|
|
|
|
|
|
|
|
|
pFile = fopen ("nJoy-debug.txt","wt");
|
2008-07-23 19:23:36 +00:00
|
|
|
|
fprintf(pFile, "nJoy v"INPUT_VERSION" Debug\n");
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-07-23 19:23:36 +00:00
|
|
|
|
fprintf(pFile, "Date: %s\nTime: %s\n", dateStr, timeStr);
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#endif
|
2008-07-22 09:02:26 +00:00
|
|
|
|
fprintf(pFile, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disable output log
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void DEBUG_QUIT()
|
|
|
|
|
{
|
|
|
|
|
if(!pFile)
|
|
|
|
|
return;
|
2008-07-23 19:23:36 +00:00
|
|
|
|
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#ifdef _WIN32
|
2008-07-22 09:02:26 +00:00
|
|
|
|
char timeStr [9];
|
|
|
|
|
_strtime(timeStr);
|
|
|
|
|
|
|
|
|
|
fprintf(pFile, "_______________\n");
|
2008-07-23 19:23:36 +00:00
|
|
|
|
fprintf(pFile, "Time: %s", timeStr);
|
2008-07-23 18:53:54 +00:00
|
|
|
|
#endif
|
2008-07-22 09:02:26 +00:00
|
|
|
|
fclose(pFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save settings to file
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void SaveConfig()
|
|
|
|
|
{
|
|
|
|
|
IniFile file;
|
2008-07-23 00:49:20 +00:00
|
|
|
|
file.Load("nJoy.ini");
|
2008-07-22 09:02:26 +00:00
|
|
|
|
|
|
|
|
|
for (int i=0; i<4; i++)
|
|
|
|
|
{
|
|
|
|
|
char SectionName[32];
|
|
|
|
|
sprintf(SectionName, "PAD%i", i+1);
|
|
|
|
|
|
|
|
|
|
file.Set(SectionName, "l_shoulder", joysticks[i].buttons[CTL_L_SHOULDER]);
|
|
|
|
|
file.Set(SectionName, "r_shoulder", joysticks[i].buttons[CTL_R_SHOULDER]);
|
|
|
|
|
file.Set(SectionName, "a_button", joysticks[i].buttons[CTL_A_BUTTON]);
|
|
|
|
|
file.Set(SectionName, "b_button", joysticks[i].buttons[CTL_B_BUTTON]);
|
|
|
|
|
file.Set(SectionName, "x_button", joysticks[i].buttons[CTL_X_BUTTON]);
|
|
|
|
|
file.Set(SectionName, "y_button", joysticks[i].buttons[CTL_Y_BUTTON]);
|
|
|
|
|
file.Set(SectionName, "z_trigger", joysticks[i].buttons[CTL_Z_TRIGGER]);
|
|
|
|
|
file.Set(SectionName, "start_button", joysticks[i].buttons[CTL_START]);
|
|
|
|
|
file.Set(SectionName, "dpad", joysticks[i].dpad);
|
2008-07-23 00:49:20 +00:00
|
|
|
|
file.Set(SectionName, "dpad_up", joysticks[i].dpad2[CTL_D_PAD_UP]);
|
|
|
|
|
file.Set(SectionName, "dpad_down", joysticks[i].dpad2[CTL_D_PAD_DOWN]);
|
|
|
|
|
file.Set(SectionName, "dpad_left", joysticks[i].dpad2[CTL_D_PAD_LEFT]);
|
|
|
|
|
file.Set(SectionName, "dpad_right", joysticks[i].dpad2[CTL_D_PAD_RIGHT]);
|
2008-07-22 09:02:26 +00:00
|
|
|
|
file.Set(SectionName, "main_x", joysticks[i].axis[CTL_MAIN_X]);
|
|
|
|
|
file.Set(SectionName, "main_y", joysticks[i].axis[CTL_MAIN_Y]);
|
|
|
|
|
file.Set(SectionName, "sub_x", joysticks[i].axis[CTL_SUB_X]);
|
|
|
|
|
file.Set(SectionName, "sub_y", joysticks[i].axis[CTL_SUB_Y]);
|
|
|
|
|
file.Set(SectionName, "enabled", joysticks[i].enabled);
|
|
|
|
|
file.Set(SectionName, "deadzone", joysticks[i].deadzone);
|
|
|
|
|
file.Set(SectionName, "halfpress", joysticks[i].halfpress);
|
|
|
|
|
file.Set(SectionName, "joy_id", joysticks[i].ID);
|
2008-07-23 00:49:20 +00:00
|
|
|
|
file.Set(SectionName, "controllertype", joysticks[i].controllertype);
|
2008-07-22 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-23 00:49:20 +00:00
|
|
|
|
file.Save("nJoy.ini");
|
2008-07-22 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load settings from file
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void LoadConfig()
|
|
|
|
|
{
|
|
|
|
|
IniFile file;
|
2008-07-23 00:49:20 +00:00
|
|
|
|
file.Load("nJoy.ini");
|
2008-07-22 09:02:26 +00:00
|
|
|
|
|
|
|
|
|
for (int i=0; i<4; i++)
|
|
|
|
|
{
|
|
|
|
|
char SectionName[32];
|
|
|
|
|
sprintf(SectionName, "PAD%i", i+1);
|
|
|
|
|
|
|
|
|
|
file.Get(SectionName, "l_shoulder", &joysticks[i].buttons[CTL_L_SHOULDER], 4);
|
|
|
|
|
file.Get(SectionName, "r_shoulder", &joysticks[i].buttons[CTL_R_SHOULDER], 5);
|
|
|
|
|
file.Get(SectionName, "a_button", &joysticks[i].buttons[CTL_A_BUTTON], 0);
|
|
|
|
|
file.Get(SectionName, "b_button", &joysticks[i].buttons[CTL_B_BUTTON], 1);
|
|
|
|
|
file.Get(SectionName, "x_button", &joysticks[i].buttons[CTL_X_BUTTON], 3);
|
|
|
|
|
file.Get(SectionName, "y_button", &joysticks[i].buttons[CTL_Y_BUTTON], 2);
|
|
|
|
|
file.Get(SectionName, "z_trigger", &joysticks[i].buttons[CTL_Z_TRIGGER], 7);
|
|
|
|
|
file.Get(SectionName, "start_button", &joysticks[i].buttons[CTL_START], 9);
|
|
|
|
|
file.Get(SectionName, "dpad", &joysticks[i].dpad, 0);
|
2008-07-23 00:49:20 +00:00
|
|
|
|
file.Get(SectionName, "dpad_up", &joysticks[i].dpad2[CTL_D_PAD_UP], 0);
|
|
|
|
|
file.Get(SectionName, "dpad_down", &joysticks[i].dpad2[CTL_D_PAD_DOWN], 0);
|
|
|
|
|
file.Get(SectionName, "dpad_left", &joysticks[i].dpad2[CTL_D_PAD_LEFT], 0);
|
|
|
|
|
file.Get(SectionName, "dpad_right", &joysticks[i].dpad2[CTL_D_PAD_RIGHT], 0);
|
2008-07-22 09:02:26 +00:00
|
|
|
|
file.Get(SectionName, "main_x", &joysticks[i].axis[CTL_MAIN_X], 0);
|
|
|
|
|
file.Get(SectionName, "main_y", &joysticks[i].axis[CTL_MAIN_Y], 1);
|
|
|
|
|
file.Get(SectionName, "sub_x", &joysticks[i].axis[CTL_SUB_X], 2);
|
|
|
|
|
file.Get(SectionName, "sub_y", &joysticks[i].axis[CTL_SUB_Y], 3);
|
|
|
|
|
file.Get(SectionName, "enabled", &joysticks[i].enabled, 1);
|
|
|
|
|
file.Get(SectionName, "deadzone", &joysticks[i].deadzone, 9);
|
2008-07-23 00:49:20 +00:00
|
|
|
|
file.Get(SectionName, "halfpress", &joysticks[i].halfpress, 6);
|
2008-07-22 09:02:26 +00:00
|
|
|
|
file.Get(SectionName, "joy_id", &joysticks[i].ID, 0);
|
2008-07-23 00:49:20 +00:00
|
|
|
|
file.Get(SectionName, "controllertype", &joysticks[i].controllertype, 0);
|
2008-07-22 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|