2008-12-08 05:25:12 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Project description
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2009-01-15 06:48:15 +00:00
|
|
|
|
// Name: nJoy
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// 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/
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
2008-12-28 18:50:24 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Issues
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
The StrangeHack in ConfigAdvanced.cpp doesn't work in Linux, it still wont resize the
|
|
|
|
|
window correctly. So currently in Linux you have to have advanced controls enabled when
|
|
|
|
|
you open the window to see them.
|
|
|
|
|
|
|
|
|
|
////////////////////////*/
|
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-28 18:50:24 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Variables guide
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
2009-01-21 18:09:31 +00:00
|
|
|
|
Joyinfo[1, 2, 3, 4, ..., number of attached devices]: Gamepad info that is populate by Search_Devices()
|
|
|
|
|
PadMapping[1, 2, 3 and 4]: The button mapping
|
|
|
|
|
Joystate[1, 2, 3 and 4]: The current button states
|
2009-01-19 05:49:25 +00:00
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
The arrays PadMapping[] and PadState[] are numbered 0 to 3 for the four different virtual
|
2009-01-19 05:49:25 +00:00
|
|
|
|
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
|
2009-01-24 22:13:53 +00:00
|
|
|
|
mapping of a certain physical device to PadState[].joy is initially done by Initialize(), but
|
2009-01-19 05:49:25 +00:00
|
|
|
|
for the configuration we can remap that, like in ConfigBox::ChangeJoystick().
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
2009-01-19 05:49:25 +00:00
|
|
|
|
The joyinfo[] array holds the physical gamepad info for a certain physical device. It's therefore
|
2009-01-21 18:09:31 +00:00
|
|
|
|
used as joyinfo[PadMapping[controller].ID] if we want to get the joyinfo for a certain joystick.
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////*/
|
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
2008-12-26 02:42:15 +00:00
|
|
|
|
// Include
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "nJoy.h"
|
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// Declare config window so that we can write debugging info to it from functions in this file
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
|
ConfigBox* m_frame;
|
|
|
|
|
#endif
|
|
|
|
|
/////////////////////////
|
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Variables
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
// Rumble in windows
|
2008-12-27 11:32:03 +00:00
|
|
|
|
#define _CONTROLLER_STATE_H // Avoid certain declarations in nJoy.h
|
2008-12-08 05:25:12 +00:00
|
|
|
|
FILE *pFile;
|
|
|
|
|
HINSTANCE nJoy_hInst = NULL;
|
2009-01-24 22:13:53 +00:00
|
|
|
|
std::vector<CONTROLLER_INFO> joyinfo;
|
|
|
|
|
CONTROLLER_STATE PadState[4];
|
2009-01-21 18:09:31 +00:00
|
|
|
|
CONTROLLER_MAPPING PadMapping[4];
|
2009-01-24 22:13:53 +00:00
|
|
|
|
bool emulator_running = false;
|
|
|
|
|
int NumPads = 0, NumGoodPads = 0;
|
2008-12-26 02:42:15 +00:00
|
|
|
|
HWND m_hWnd; // Handle to window
|
2009-02-01 20:45:27 +00:00
|
|
|
|
SPADInitialize *g_PADInitialize = NULL;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2008-12-26 09:20:01 +00:00
|
|
|
|
// TODO: fix this dirty hack to stop missing symbols
|
|
|
|
|
void __Log(int log, const char *format, ...) {}
|
|
|
|
|
void __Logv(int log, int v, const char *format, ...) {}
|
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
// Rumble
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
|
|
#elif defined(__linux__)
|
2008-12-26 02:42:15 +00:00
|
|
|
|
extern int fd;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// wxWidgets
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-26 02:42:15 +00:00
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
|
class wxDLLApp : public wxApp
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2008-12-26 02:42:15 +00:00
|
|
|
|
bool OnInit()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
2008-12-26 02:42:15 +00:00
|
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
2008-12-14 23:52:01 +00:00
|
|
|
|
#endif
|
2008-12-26 02:42:15 +00:00
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
2009-01-15 06:48:15 +00:00
|
|
|
|
// DllMain
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
BOOL APIENTRY DllMain( HINSTANCE hinstDLL, // DLL module handle
|
|
|
|
|
DWORD dwReason, // reason called
|
|
|
|
|
LPVOID lpvReserved) // reserved
|
2009-01-15 06:48:15 +00:00
|
|
|
|
{
|
2008-12-08 05:25:12 +00:00
|
|
|
|
switch (dwReason)
|
|
|
|
|
{
|
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
|
{
|
|
|
|
|
//use wxInitialize() if you don't want GUI instead of the following 12 lines
|
|
|
|
|
wxSetInstance((HINSTANCE)hinstDLL);
|
|
|
|
|
int argc = 0;
|
|
|
|
|
char **argv = NULL;
|
|
|
|
|
wxEntryStart(argc, argv);
|
|
|
|
|
|
2008-12-10 21:23:15 +00:00
|
|
|
|
if (!wxTheApp || !wxTheApp->CallOnInit() )
|
2008-12-08 05:25:12 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2009-01-15 06:48:15 +00:00
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2009-01-15 06:48:15 +00:00
|
|
|
|
wxEntryCleanup(); //use wxUninitialize() if you don't want GUI
|
2008-12-08 05:25:12 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
|
|
|
|
nJoy_hInst = hinstDLL;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Input Plugin Functions (from spec's)
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <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>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
// Get properties of plugin
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
void GetDllInfo(PLUGIN_INFO* _PluginInfo)
|
|
|
|
|
{
|
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_PAD;
|
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
#ifdef DEBUGFAST
|
2008-12-08 05:25:12 +00:00
|
|
|
|
sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION" (DebugFast) by Falcon4ever");
|
|
|
|
|
#else
|
|
|
|
|
#ifndef _DEBUG
|
|
|
|
|
sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION " by Falcon4ever");
|
|
|
|
|
#else
|
|
|
|
|
sprintf(_PluginInfo->Name, "nJoy v"INPUT_VERSION" (Debug) by Falcon4ever");
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) {}
|
2009-01-08 12:12:15 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// Call config dialog
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
void DllConfig(HWND _hParent)
|
2009-01-15 06:48:15 +00:00
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
// Debugging
|
|
|
|
|
//Console::Open();
|
2009-01-23 21:28:55 +00:00
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
// Start the pads so we can use them in the configuration and advanced controls
|
|
|
|
|
if(!emulator_running)
|
|
|
|
|
{
|
|
|
|
|
NumPads = Search_Devices(); // Populate joyinfo for all attached devices
|
|
|
|
|
}
|
2009-01-23 21:28:55 +00:00
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
m_frame = new ConfigBox(NULL);
|
|
|
|
|
m_frame->ShowModal();
|
2009-01-23 21:28:55 +00:00
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
/* 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());
|
|
|
|
|
}
|
2009-01-23 21:28:55 +00:00
|
|
|
|
#else
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (SDL_Init(SDL_INIT_JOYSTICK ) < 0)
|
|
|
|
|
{
|
|
|
|
|
printf("Could not initialize SDL! (%s)\n", SDL_GetError());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-01-23 21:28:55 +00:00
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
g_Config.Load(); // load settings
|
2009-01-23 21:28:55 +00:00
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
|
ConfigBox frame(NULL);
|
|
|
|
|
frame.ShowModal();
|
|
|
|
|
#endif
|
2009-01-23 10:00:59 +00:00
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
void DllDebugger(HWND _hParent, bool Show) {}
|
2008-12-17 17:49:38 +00:00
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// Init PAD (start emulation)
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <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>
|
2009-01-19 17:47:00 +00:00
|
|
|
|
/* Information: This function can not be run twice without a Shutdown in between. If
|
|
|
|
|
it's run twice the SDL_Init() will cause a crash. One solution to this is to keep a
|
|
|
|
|
global function that remembers the SDL_Init() and SDL_Quit() (emulator_running does
|
|
|
|
|
not do that since we can open and close this without any game running). But I would
|
|
|
|
|
suggest that avoiding to run this twice from the Core is better. */
|
2009-01-15 06:48:15 +00:00
|
|
|
|
void Initialize(void *init)
|
|
|
|
|
{
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// Debugging
|
|
|
|
|
//Console::Open();
|
2009-01-24 22:13:53 +00:00
|
|
|
|
Console::Print("Initialize: %i\n", SDL_WasInit(0));
|
2009-02-01 16:29:35 +00:00
|
|
|
|
g_PADInitialize = (SPADInitialize*)init;
|
2009-01-19 05:49:25 +00:00
|
|
|
|
emulator_running = true;
|
2009-01-24 22:13:53 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#ifdef _DEBUG
|
2009-01-19 05:49:25 +00:00
|
|
|
|
DEBUG_INIT();
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#endif
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#ifdef _WIN32
|
2009-02-01 16:29:35 +00:00
|
|
|
|
m_hWnd = (HWND)g_PADInitialize->hWnd;
|
2009-01-23 13:31:00 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
NumPads = Search_Devices(); // Populate joyinfo for all attached devices
|
2009-01-24 12:09:30 +00:00
|
|
|
|
|
|
|
|
|
/* 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 */
|
2009-01-24 22:13:53 +00:00
|
|
|
|
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))
|
2009-01-24 12:09:30 +00:00
|
|
|
|
{
|
2009-02-01 16:29:35 +00:00
|
|
|
|
g_PADInitialize->padNumber = -1;
|
2009-01-24 12:09:30 +00:00
|
|
|
|
Console::Print("%s\n", SDL_GetError());
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// Search attached devices. Populate joyinfo for all attached physical 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()
|
|
|
|
|
{
|
2009-01-19 23:17:29 +00:00
|
|
|
|
// Load config
|
2008-12-27 11:32:03 +00:00
|
|
|
|
#ifdef _DEBUG
|
2009-01-19 23:17:29 +00:00
|
|
|
|
DEBUG_INIT();
|
2008-12-27 11:32:03 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
/* 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)
|
|
|
|
|
{
|
|
|
|
|
PanicAlert("Could not initialize SDL: %s", SDL_GetError());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2009-01-22 00:31:12 +00:00
|
|
|
|
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");
|
2008-12-27 11:32:03 +00:00
|
|
|
|
#endif
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
// Get device status
|
|
|
|
|
int numjoy = SDL_NumJoysticks();
|
|
|
|
|
for (int i = 0; i < numjoy; i++ )
|
2008-12-27 11:32:03 +00:00
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
CONTROLLER_INFO Tmp;
|
|
|
|
|
|
|
|
|
|
Tmp.joy = SDL_JoystickOpen(i);
|
|
|
|
|
Tmp.ID = i;
|
|
|
|
|
Tmp.NumAxes = SDL_JoystickNumAxes(Tmp.joy);
|
|
|
|
|
Tmp.NumButtons = SDL_JoystickNumButtons(Tmp.joy);
|
|
|
|
|
Tmp.NumBalls = SDL_JoystickNumBalls(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);
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
#ifdef _DEBUG
|
2009-01-24 22:13:53 +00:00
|
|
|
|
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);
|
2009-01-15 06:48:15 +00:00
|
|
|
|
#endif
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
|
|
|
|
// We have now read the values we need so we close the device
|
|
|
|
|
if (SDL_JoystickOpened(i)) SDL_JoystickClose(joyinfo[i].joy);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
// 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();
|
2008-12-27 11:32:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// Shutdown PAD (stop emulation)
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <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>
|
2009-01-19 17:47:00 +00:00
|
|
|
|
/* Information: This function can not be run twice without an Initialize in between. If
|
|
|
|
|
it's run twice the SDL_...() functions below will cause a crash.
|
|
|
|
|
Called from: The Dolphin Core, ConfigBox::OnClose() */
|
2009-01-15 06:48:15 +00:00
|
|
|
|
void Shutdown()
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
Console::Print("Shutdown: %i\n", SDL_WasInit(0));
|
2009-01-23 10:00:59 +00:00
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
/* 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);
|
|
|
|
|
}
|
2009-01-23 10:00:59 +00:00
|
|
|
|
|
2009-01-23 21:28:55 +00:00
|
|
|
|
SDL_Quit();
|
2009-01-23 10:00:59 +00:00
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
DEBUG_QUIT();
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-01-24 22:13:53 +00:00
|
|
|
|
// Clear the physical device info
|
|
|
|
|
//delete [] joyinfo;
|
|
|
|
|
//joyinfo = NULL;
|
|
|
|
|
joyinfo.clear();
|
2009-01-23 10:00:59 +00:00
|
|
|
|
|
|
|
|
|
emulator_running = false;
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
#ifdef USE_RUMBLE_DINPUT_HACK
|
2009-01-24 22:13:53 +00:00
|
|
|
|
FreeDirectInput();
|
2009-01-23 10:00:59 +00:00
|
|
|
|
#endif
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
|
close(fd);
|
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
|
2009-02-03 10:17:01 +00:00
|
|
|
|
// Set buttons status from keyboard input. Currently this is done from wxWidgets in the main application.
|
2008-12-28 18:50:24 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2009-01-19 17:47:00 +00:00
|
|
|
|
void PAD_Input(u16 _Key, u8 _UpDown)
|
2008-12-28 18:50:24 +00:00
|
|
|
|
{
|
2009-02-01 20:45:27 +00:00
|
|
|
|
// Check that Dolphin is in focus, otherwise don't update the pad status
|
2009-02-03 10:17:01 +00:00
|
|
|
|
if (!IsFocus()) return;
|
2009-02-01 16:29:35 +00:00
|
|
|
|
|
2008-12-28 18:50:24 +00:00
|
|
|
|
// Check if the keys are interesting, and then update it
|
|
|
|
|
for(int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
for(int j = CTL_L_SHOULDER; j <= CTL_START; j++)
|
|
|
|
|
{
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if (PadMapping[i].buttons[j] == _Key)
|
2009-01-24 22:13:53 +00:00
|
|
|
|
{ PadState[i].buttons[j] = _UpDown; break; }
|
2008-12-28 18:50:24 +00:00
|
|
|
|
}
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
|
|
|
|
for(int j = CTL_D_PAD_UP; j <= CTL_D_PAD_RIGHT; j++)
|
|
|
|
|
{
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if (PadMapping[i].dpad2[j] == _Key)
|
2009-01-24 22:13:53 +00:00
|
|
|
|
{ PadState[i].dpad2[j] = _UpDown; break; }
|
2009-01-19 17:47:00 +00:00
|
|
|
|
}
|
2008-12-28 18:50:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// Debugging
|
|
|
|
|
//Console::Print("%i", _Key);
|
2009-01-15 06:48:15 +00:00
|
|
|
|
}
|
2008-12-28 18:50:24 +00:00
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
|
|
|
|
// Save state
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void DoState(unsigned char **ptr, int mode) {}
|
|
|
|
|
|
2009-02-01 20:19:21 +00:00
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
g_Config.Load();
|
|
|
|
|
|
|
|
|
|
if (PadMapping[0].enabled) connected |= 1;
|
|
|
|
|
if (PadMapping[1].enabled) connected |= 2;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
|
|
|
|
// Set PAD status
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2009-01-22 00:31:12 +00:00
|
|
|
|
// Called from: SI_DeviceGCController.cpp
|
2009-01-19 05:49:25 +00:00
|
|
|
|
// Function: Gives the current pad status to the Core
|
2008-12-08 05:25:12 +00:00
|
|
|
|
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
|
|
|
|
|
{
|
2009-02-01 20:19:21 +00:00
|
|
|
|
//Console::Print("%i %i %i\n", _numPAD, PadMapping[_numPAD].enabled, PadState[_numPAD].joy);
|
2009-01-24 22:13:53 +00:00
|
|
|
|
|
|
|
|
|
// Check if the pad is enabled
|
|
|
|
|
if (!PadMapping[_numPAD].enabled || !PadState[_numPAD].joy) return;
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
// Clear pad status
|
2008-12-08 05:25:12 +00:00
|
|
|
|
memset(_pPADStatus, 0, sizeof(SPADStatus));
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// Update the pad status
|
2008-12-08 05:25:12 +00:00
|
|
|
|
GetJoyState(_numPAD);
|
|
|
|
|
|
2009-01-20 05:28:30 +00:00
|
|
|
|
// Get type
|
2009-01-21 18:09:31 +00:00
|
|
|
|
int TriggerType = PadMapping[_numPAD].triggertype;
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
///////////////////////////////////////////////////
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// The analog controls
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// -----------
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// Read axis values
|
2009-01-24 22:13:53 +00:00
|
|
|
|
int i_main_stick_x = PadState[_numPAD].axis[CTL_MAIN_X];
|
|
|
|
|
int i_main_stick_y = -PadState[_numPAD].axis[CTL_MAIN_Y];
|
|
|
|
|
int i_sub_stick_x = PadState[_numPAD].axis[CTL_SUB_X];
|
|
|
|
|
int i_sub_stick_y = -PadState[_numPAD].axis[CTL_SUB_Y];
|
|
|
|
|
int TriggerLeft = PadState[_numPAD].axis[CTL_L_SHOULDER];
|
|
|
|
|
int TriggerRight = PadState[_numPAD].axis[CTL_R_SHOULDER];
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// Check if we should make adjustments
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if(PadMapping[_numPAD].bSquareToCircle)
|
2008-12-27 11:32:03 +00:00
|
|
|
|
{
|
2009-01-20 06:38:29 +00:00
|
|
|
|
std::vector<int> main_xy = Pad_Square_to_Circle(i_main_stick_x, i_main_stick_y, _numPAD);
|
2008-12-27 11:32:03 +00:00
|
|
|
|
i_main_stick_x = main_xy.at(0);
|
|
|
|
|
i_main_stick_y = main_xy.at(1);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-20 05:28:30 +00:00
|
|
|
|
// Convert axis values
|
2008-12-27 11:32:03 +00:00
|
|
|
|
u8 main_stick_x = Pad_Convert(i_main_stick_x);
|
|
|
|
|
u8 main_stick_y = Pad_Convert(i_main_stick_y);
|
|
|
|
|
u8 sub_stick_x = Pad_Convert(i_sub_stick_x);
|
|
|
|
|
u8 sub_stick_y = Pad_Convert(i_sub_stick_y);
|
2009-01-20 05:28:30 +00:00
|
|
|
|
|
2009-02-01 20:19:21 +00:00
|
|
|
|
// Convert the triggers values, if we are using analog triggers at all
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if(PadMapping[_numPAD].triggertype == CTL_TRIGGER_SDL)
|
2009-01-20 14:25:33 +00:00
|
|
|
|
{
|
2009-02-01 20:19:21 +00:00
|
|
|
|
if(PadMapping[_numPAD].buttons[CTL_L_SHOULDER] >= 1000) TriggerLeft = Pad_Convert(TriggerLeft);
|
|
|
|
|
if(PadMapping[_numPAD].buttons[CTL_R_SHOULDER] >= 1000) TriggerRight = Pad_Convert(TriggerRight);
|
2009-01-20 14:25:33 +00:00
|
|
|
|
}
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// Set Deadzones (perhaps out of function?)
|
2009-01-21 18:09:31 +00:00
|
|
|
|
int deadzone = (int)(((float)(128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone + 1));
|
|
|
|
|
int deadzone2 = (int)(((float)(-128.00/100.00)) * (float)(PadMapping[_numPAD].deadzone + 1));
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
|
|
|
|
// Send values to Dolpin if they are outside the deadzone
|
|
|
|
|
if ((main_stick_x < deadzone2) || (main_stick_x > deadzone)) _pPADStatus->stickX = main_stick_x;
|
|
|
|
|
if ((main_stick_y < deadzone2) || (main_stick_y > deadzone)) _pPADStatus->stickY = main_stick_y;
|
|
|
|
|
if ((sub_stick_x < deadzone2) || (sub_stick_x > deadzone)) _pPADStatus->substickX = sub_stick_x;
|
|
|
|
|
if ((sub_stick_y < deadzone2) || (sub_stick_y > deadzone)) _pPADStatus->substickY = sub_stick_y;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
///////////////////////////////////////////////////
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// The L and R triggers
|
|
|
|
|
// -----------
|
2009-01-20 06:38:29 +00:00
|
|
|
|
int TriggerValue = 255;
|
2009-02-01 20:19:21 +00:00
|
|
|
|
if (PadState[_numPAD].halfpress) TriggerValue = 100;
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
_pPADStatus->button |= PAD_USE_ORIGIN; // Neutral value, no button pressed
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
2009-02-01 20:19:21 +00:00
|
|
|
|
// Check if the digital L button is pressed
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].buttons[CTL_L_SHOULDER])
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-19 17:47:00 +00:00
|
|
|
|
_pPADStatus->button |= PAD_TRIGGER_L;
|
2009-01-20 06:38:29 +00:00
|
|
|
|
_pPADStatus->triggerLeft = TriggerValue;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-20 14:25:33 +00:00
|
|
|
|
else if(TriggerLeft > 0)
|
2009-01-19 18:09:03 +00:00
|
|
|
|
_pPADStatus->triggerLeft = TriggerLeft;
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
2009-02-01 20:19:21 +00:00
|
|
|
|
// Check if the digital R button is pressed
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].buttons[CTL_R_SHOULDER])
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-19 17:47:00 +00:00
|
|
|
|
_pPADStatus->button |= PAD_TRIGGER_R;
|
2009-01-20 06:38:29 +00:00
|
|
|
|
_pPADStatus->triggerRight = TriggerValue;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-20 14:25:33 +00:00
|
|
|
|
else if(TriggerRight > 0)
|
2009-01-19 17:47:00 +00:00
|
|
|
|
_pPADStatus->triggerRight = TriggerRight;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-19 18:09:03 +00:00
|
|
|
|
// Update the buttons in analog mode to
|
|
|
|
|
if(TriggerLeft == 0xff) _pPADStatus->button |= PAD_TRIGGER_L;
|
|
|
|
|
if(TriggerRight == 0xff) _pPADStatus->button |= PAD_TRIGGER_R;
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
|
// The digital buttons
|
|
|
|
|
// -----------
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].buttons[CTL_A_BUTTON])
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-19 05:49:25 +00:00
|
|
|
|
_pPADStatus->button |= PAD_BUTTON_A;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_pPADStatus->analogA = 255; // Perhaps support pressure?
|
|
|
|
|
}
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].buttons[CTL_B_BUTTON])
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-19 05:49:25 +00:00
|
|
|
|
_pPADStatus->button |= PAD_BUTTON_B;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_pPADStatus->analogB = 255; // Perhaps support pressure?
|
|
|
|
|
}
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].buttons[CTL_X_BUTTON]) _pPADStatus->button|=PAD_BUTTON_X;
|
|
|
|
|
if (PadState[_numPAD].buttons[CTL_Y_BUTTON]) _pPADStatus->button|=PAD_BUTTON_Y;
|
|
|
|
|
if (PadState[_numPAD].buttons[CTL_Z_TRIGGER]) _pPADStatus->button|=PAD_TRIGGER_Z;
|
|
|
|
|
if (PadState[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
|
// The D-pad
|
|
|
|
|
// -----------
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if (PadMapping[_numPAD].controllertype == CTL_DPAD_HAT)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].dpad == SDL_HAT_LEFTUP || PadState[_numPAD].dpad == SDL_HAT_UP || PadState[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP;
|
|
|
|
|
if (PadState[_numPAD].dpad == SDL_HAT_LEFTUP || PadState[_numPAD].dpad == SDL_HAT_LEFT || PadState[_numPAD].dpad == SDL_HAT_LEFTDOWN ) _pPADStatus->button|=PAD_BUTTON_LEFT;
|
|
|
|
|
if (PadState[_numPAD].dpad == SDL_HAT_LEFTDOWN || PadState[_numPAD].dpad == SDL_HAT_DOWN || PadState[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_DOWN;
|
|
|
|
|
if (PadState[_numPAD].dpad == SDL_HAT_RIGHTUP || PadState[_numPAD].dpad == SDL_HAT_RIGHT || PadState[_numPAD].dpad == SDL_HAT_RIGHTDOWN ) _pPADStatus->button|=PAD_BUTTON_RIGHT;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].dpad2[CTL_D_PAD_UP])
|
2008-12-27 11:32:03 +00:00
|
|
|
|
_pPADStatus->button |= PAD_BUTTON_UP;
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].dpad2[CTL_D_PAD_DOWN])
|
2008-12-27 11:32:03 +00:00
|
|
|
|
_pPADStatus->button |= PAD_BUTTON_DOWN;
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].dpad2[CTL_D_PAD_LEFT])
|
2008-12-27 11:32:03 +00:00
|
|
|
|
_pPADStatus->button |= PAD_BUTTON_LEFT;
|
2009-01-24 22:13:53 +00:00
|
|
|
|
if (PadState[_numPAD].dpad2[CTL_D_PAD_RIGHT])
|
2008-12-27 11:32:03 +00:00
|
|
|
|
_pPADStatus->button |= PAD_BUTTON_RIGHT;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2009-01-19 18:09:03 +00:00
|
|
|
|
// Update error code
|
2008-12-08 05:25:12 +00:00
|
|
|
|
_pPADStatus->err = PAD_ERR_NONE;
|
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
// Use rumble
|
2008-12-27 11:32:03 +00:00
|
|
|
|
Pad_Use_Rumble(_numPAD, _pPADStatus);
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
2009-01-20 05:28:30 +00:00
|
|
|
|
/* Debugging
|
2009-01-19 17:47:00 +00:00
|
|
|
|
Console::ClearScreen();
|
2009-01-19 18:09:03 +00:00
|
|
|
|
Console::Print(
|
2009-01-24 22:13:53 +00:00
|
|
|
|
"Pad %i: %i %i\n"
|
2009-02-01 20:19:21 +00:00
|
|
|
|
"State: L:%i R:%i HalfPress:%i\n"
|
|
|
|
|
"Trigger type: %s StatusLeft:%04x StatusRight:%04x TriggerLeft:%04x TriggerRight:%04x TriggerValue:%i\n"
|
2009-01-24 22:13:53 +00:00
|
|
|
|
"Buttons: %i X:%i\n"
|
2009-01-23 21:28:55 +00:00
|
|
|
|
"D-Pad type: %s L:%i R:%i U:%i D:%i",
|
2009-01-24 22:13:53 +00:00
|
|
|
|
|
|
|
|
|
_numPAD, PadMapping[_numPAD].enabled, PadState[_numPAD].joy,
|
|
|
|
|
|
2009-02-01 20:19:21 +00:00
|
|
|
|
PadState[_numPAD].buttons[CTL_L_SHOULDER], PadState[_numPAD].buttons[CTL_R_SHOULDER], PadState[_numPAD].halfpress,
|
|
|
|
|
|
2009-01-21 18:09:31 +00:00
|
|
|
|
(PadMapping[_numPAD].triggertype ? "CTL_TRIGGER_XINPUT" : "CTL_TRIGGER_SDL"),
|
2009-02-01 20:19:21 +00:00
|
|
|
|
_pPADStatus->triggerLeft, _pPADStatus->triggerRight, TriggerLeft, TriggerRight, TriggerValue,
|
2009-01-24 22:13:53 +00:00
|
|
|
|
|
2009-02-01 20:19:21 +00:00
|
|
|
|
_pPADStatus->button, PadState[_numPAD].buttons[CTL_X_BUTTON],
|
2009-01-24 22:13:53 +00:00
|
|
|
|
|
2009-01-21 18:09:31 +00:00
|
|
|
|
(PadMapping[_numPAD].controllertype ? "CTL_DPAD_CUSTOM" : "CTL_DPAD_HAT"),
|
2009-01-24 22:13:53 +00:00
|
|
|
|
0, 0, 0, 0
|
2009-01-19 18:09:03 +00:00
|
|
|
|
);*/
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////// Spec functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-01 16:29:35 +00:00
|
|
|
|
//******************************************************************************
|
|
|
|
|
// Supporting functions
|
|
|
|
|
//******************************************************************************
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Check if Dolphin is in focus
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
bool IsFocus()
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
2009-02-01 20:45:27 +00:00
|
|
|
|
HWND RenderingWindow = NULL; if (g_PADInitialize) RenderingWindow = g_PADInitialize->hWnd;
|
|
|
|
|
HWND Parent = GetParent(RenderingWindow);
|
2009-02-01 16:29:35 +00:00
|
|
|
|
HWND TopLevel = GetParent(Parent);
|
2009-02-01 20:45:27 +00:00
|
|
|
|
HWND Config = NULL; if (m_frame) Config = (HWND)m_frame->GetHWND();
|
2009-02-01 16:29:35 +00:00
|
|
|
|
// Support both rendering to main window and not
|
2009-02-01 20:45:27 +00:00
|
|
|
|
if (GetForegroundWindow() == TopLevel || GetForegroundWindow() == RenderingWindow || GetForegroundWindow() == Config)
|
2009-02-01 16:29:35 +00:00
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
#else
|
|
|
|
|
return true;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
2009-01-20 05:28:30 +00:00
|
|
|
|
// Convert stick values
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
/* Convert stick values.
|
|
|
|
|
|
|
|
|
|
The value returned by SDL_JoystickGetAxis is a signed integer s16
|
2009-01-15 06:48:15 +00:00
|
|
|
|
(-32768 to 32767). The value used for the gamecube controller is an unsigned
|
2008-12-27 11:32:03 +00:00
|
|
|
|
char u8 (0 to 255) with neutral at 0x80 (128), so that it's equivalent to a signed
|
2009-01-20 05:28:30 +00:00
|
|
|
|
-128 to 127.
|
2009-01-20 14:25:33 +00:00
|
|
|
|
*/
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2009-01-20 14:25:33 +00:00
|
|
|
|
int Pad_Convert(int _val)
|
2008-12-27 11:32:03 +00:00
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
/* If the limits on PadState[].axis[] actually is a u16 then we don't need this
|
2008-12-27 11:32:03 +00:00
|
|
|
|
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
|
2009-01-20 05:28:30 +00:00
|
|
|
|
|
|
|
|
|
// Convert the range (-0x8000 to 0x7fff) to (0 to 0xffff)
|
2009-01-20 14:25:33 +00:00
|
|
|
|
_val = 0x8000 +_val;
|
2009-01-20 05:28:30 +00:00
|
|
|
|
|
|
|
|
|
// Convert the range (-32768 to 32767) to (-128 to 127)
|
2008-12-27 11:32:03 +00:00
|
|
|
|
_val = _val >> 8;
|
|
|
|
|
|
2009-01-20 05:28:30 +00:00
|
|
|
|
//Console::Print("0x%04x %06i\n\n", _val, _val);
|
2008-12-27 11:32:03 +00:00
|
|
|
|
|
2009-01-20 14:25:33 +00:00
|
|
|
|
return _val;
|
2008-12-27 11:32:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-27 11:32:03 +00:00
|
|
|
|
/* Convert the stick raidus from a circular to a square. I don't know what input values
|
|
|
|
|
the actual GC controller produce for the GC, it may be a square, a circle or something
|
|
|
|
|
in between. But one thing that is certain is that PC pads differ in their output (as
|
|
|
|
|
shown in the list below), so it may be beneficiary to convert whatever radius they
|
|
|
|
|
produce to the radius the GC games expect. This is the first implementation of this
|
|
|
|
|
that convert a square radius to a circual radius. Use the advanced settings to enable
|
|
|
|
|
and calibrate it.
|
|
|
|
|
|
|
|
|
|
Observed diagonals:
|
|
|
|
|
Perfect circle: 71% = sin(45)
|
|
|
|
|
Logitech Dual Action: 100%
|
|
|
|
|
Dual Shock 2 (Original) with Super Dual Box Pro: 90%
|
|
|
|
|
XBox 360 Wireless: 85%
|
|
|
|
|
GameCube Controller (Third Party) with EMS TrioLinker Plus II: 60%
|
|
|
|
|
*/
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
float SquareDistance(float deg)
|
|
|
|
|
{
|
|
|
|
|
// See if we have to adjust the angle
|
|
|
|
|
deg = abs(deg);
|
|
|
|
|
if( (deg > 45 && deg < 135) ) deg = deg - 90;
|
|
|
|
|
|
|
|
|
|
float rad = deg * M_PI / 180;
|
|
|
|
|
|
|
|
|
|
float val = abs(cos(rad));
|
|
|
|
|
float dist = 1 / val; // Calculate distance from center
|
|
|
|
|
|
|
|
|
|
//m_frame->m_pStatusBar2->SetLabel(wxString::Format("Deg:%f Val:%f Dist:%f", deg, val, dist));
|
|
|
|
|
|
|
|
|
|
return dist;
|
|
|
|
|
}
|
2009-01-20 06:38:29 +00:00
|
|
|
|
std::vector<int> Pad_Square_to_Circle(int _x, int _y, int _pad)
|
2008-12-27 11:32:03 +00:00
|
|
|
|
{
|
|
|
|
|
/* Do we need this? */
|
|
|
|
|
if(_x > 32767) _x = 32767; if(_y > 32767) _y = 32767; // upper limit
|
|
|
|
|
if(_x < -32768) _x = -32768; if(_y > 32767) _y = 32767; // lower limit
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// ====================================
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// Convert to circle
|
|
|
|
|
// -----------
|
2009-01-21 18:09:31 +00:00
|
|
|
|
int Tmp = atoi (PadMapping[_pad].SDiagonal.substr(0, PadMapping[_pad].SDiagonal.length() - 1).c_str());
|
2008-12-27 11:32:03 +00:00
|
|
|
|
float Diagonal = Tmp / 100.0;
|
|
|
|
|
|
|
|
|
|
// First make a perfect square in case we don't have one already
|
|
|
|
|
float OrigDist = sqrt( pow((float)_y, 2) + pow((float)_x, 2) ); // Get current distance
|
|
|
|
|
float rad = atan2((float)_y, (float)_x); // Get current angle
|
|
|
|
|
float deg = rad * 180 / M_PI;
|
|
|
|
|
|
|
|
|
|
// A diagonal of 85% means a distance of 1.20
|
|
|
|
|
float corner_circle_dist = ( Diagonal / sin(45 * M_PI / 180) );
|
|
|
|
|
float SquareDist = SquareDistance(deg);
|
|
|
|
|
float adj_ratio1; // The original-to-square distance adjustment
|
|
|
|
|
float adj_ratio2 = SquareDist; // The circle-to-square distance adjustment
|
2009-01-24 00:45:46 +00:00
|
|
|
|
// float final_ratio; // The final adjustment to the current distance //TODO: This is not used
|
2008-12-27 11:32:03 +00:00
|
|
|
|
float result_dist; // The resulting distance
|
|
|
|
|
|
|
|
|
|
// Calculate the corner-to-square adjustment ratio
|
|
|
|
|
if(corner_circle_dist < SquareDist) adj_ratio1 = SquareDist / corner_circle_dist;
|
|
|
|
|
else adj_ratio1 = 1;
|
|
|
|
|
|
|
|
|
|
// Calculate the resulting distance
|
|
|
|
|
result_dist = OrigDist * adj_ratio1 / adj_ratio2;
|
|
|
|
|
|
|
|
|
|
float x = result_dist * cos(rad); // calculate x
|
|
|
|
|
float y = result_dist * sin(rad); // calculate y
|
|
|
|
|
|
|
|
|
|
int int_x = (int)floor(x);
|
|
|
|
|
int int_y = (int)floor(y);
|
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
|
//m_frame->m_pStatusBar2->SetLabel(wxString::Format("%f %f %i", corner_circle_dist, Diagonal, Tmp));
|
|
|
|
|
|
|
|
|
|
std::vector<int> vec;
|
|
|
|
|
vec.push_back(int_x);
|
|
|
|
|
vec.push_back(int_y);
|
|
|
|
|
return vec;
|
|
|
|
|
}
|
2009-01-19 23:17:29 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////////// Convert stick values
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
2009-01-19 23:17:29 +00:00
|
|
|
|
// Supporting functions
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
// Read current joystick status
|
2008-12-28 18:50:24 +00:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2009-01-21 18:09:31 +00:00
|
|
|
|
The value PadMapping[].buttons[] is the number of the assigned joypad button,
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[].buttons[] is the status of the button, it becomes 0 (no pressed) or 1 (pressed) */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
// Read buttons status. Called from GetJoyState().
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-26 02:42:15 +00:00
|
|
|
|
void ReadButton(int controller, int button)
|
|
|
|
|
{
|
2009-01-21 18:09:31 +00:00
|
|
|
|
int ctl_button = PadMapping[controller].buttons[button];
|
|
|
|
|
if (ctl_button < joyinfo[PadMapping[controller].ID].NumButtons)
|
2008-12-26 02:42:15 +00:00
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].buttons[button] = SDL_JoystickGetButton(PadState[controller].joy, ctl_button);
|
2008-12-10 21:23:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-19 05:49:25 +00:00
|
|
|
|
// Request joystick state.
|
2008-12-27 11:32:03 +00:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2009-01-20 05:28:30 +00:00
|
|
|
|
/* Called from: PAD_GetStatus()
|
|
|
|
|
Input: The virtual device 0, 1, 2 or 3
|
2009-01-24 22:13:53 +00:00
|
|
|
|
Function: Updates the PadState struct with the current pad status. The input value "controller" is
|
2009-01-19 05:49:25 +00:00
|
|
|
|
for a virtual controller 0 to 3. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
void GetJoyState(int controller)
|
|
|
|
|
{
|
2009-02-01 16:29:35 +00:00
|
|
|
|
// Check that Dolphin is in focus, otherwise don't update the pad status
|
2009-02-03 10:17:01 +00:00
|
|
|
|
if (!g_Config.bCheckFocus && !IsFocus()) return;
|
2009-02-01 16:29:35 +00:00
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// Update the gamepad status
|
2008-12-08 05:25:12 +00:00
|
|
|
|
SDL_JoystickUpdate();
|
|
|
|
|
|
2009-01-19 17:47:00 +00:00
|
|
|
|
// Save the number of buttons
|
2009-01-21 18:09:31 +00:00
|
|
|
|
int Buttons = joyinfo[PadMapping[controller].ID].NumButtons;
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
|
|
|
|
// Update axis states. It doesn't hurt much if we happen to ask for nonexisting axises here.
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].axis[CTL_MAIN_X] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].axis[CTL_MAIN_X]);
|
|
|
|
|
PadState[controller].axis[CTL_MAIN_Y] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].axis[CTL_MAIN_Y]);
|
|
|
|
|
PadState[controller].axis[CTL_SUB_X] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].axis[CTL_SUB_X]);
|
|
|
|
|
PadState[controller].axis[CTL_SUB_Y] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].axis[CTL_SUB_Y]);
|
2009-01-19 17:47:00 +00:00
|
|
|
|
|
2009-02-01 20:19:21 +00:00
|
|
|
|
// Update the analog trigger axis values
|
2009-01-20 20:21:05 +00:00
|
|
|
|
#ifdef _WIN32
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if (PadMapping[controller].triggertype == CTL_TRIGGER_SDL)
|
2009-01-20 05:28:30 +00:00
|
|
|
|
{
|
2009-01-20 20:21:05 +00:00
|
|
|
|
#endif
|
2009-02-01 20:19:21 +00:00
|
|
|
|
// If we are using SDL analog triggers the buttons have to be mapped as 1000 or up, otherwise they are not used
|
|
|
|
|
if(PadMapping[controller].buttons[CTL_L_SHOULDER] >= 1000) PadState[controller].axis[CTL_L_SHOULDER] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].buttons[CTL_L_SHOULDER] - 1000); else PadState[controller].axis[CTL_L_SHOULDER] = 0;
|
|
|
|
|
if(PadMapping[controller].buttons[CTL_R_SHOULDER] >= 1000) PadState[controller].axis[CTL_R_SHOULDER] = SDL_JoystickGetAxis(PadState[controller].joy, PadMapping[controller].buttons[CTL_R_SHOULDER] - 1000); else PadState[controller].axis[CTL_R_SHOULDER] = 0;
|
2009-01-20 20:21:05 +00:00
|
|
|
|
#ifdef _WIN32
|
2009-01-20 14:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].axis[CTL_L_SHOULDER] = XInput::GetXI(0, PadMapping[controller].buttons[CTL_L_SHOULDER] - 1000);
|
|
|
|
|
PadState[controller].axis[CTL_R_SHOULDER] = XInput::GetXI(0, PadMapping[controller].buttons[CTL_R_SHOULDER] - 1000);
|
2009-01-20 05:28:30 +00:00
|
|
|
|
}
|
2009-01-20 20:21:05 +00:00
|
|
|
|
#endif
|
2009-01-20 05:28:30 +00:00
|
|
|
|
|
2009-02-01 20:19:21 +00:00
|
|
|
|
// Update button states to on or off
|
2008-12-10 21:23:15 +00:00
|
|
|
|
ReadButton(controller, CTL_L_SHOULDER);
|
|
|
|
|
ReadButton(controller, CTL_R_SHOULDER);
|
|
|
|
|
ReadButton(controller, CTL_A_BUTTON);
|
|
|
|
|
ReadButton(controller, CTL_B_BUTTON);
|
|
|
|
|
ReadButton(controller, CTL_X_BUTTON);
|
|
|
|
|
ReadButton(controller, CTL_Y_BUTTON);
|
|
|
|
|
ReadButton(controller, CTL_Z_TRIGGER);
|
|
|
|
|
ReadButton(controller, CTL_START);
|
2009-01-15 06:48:15 +00:00
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
//
|
2009-01-23 21:28:55 +00:00
|
|
|
|
if (PadMapping[controller].halfpress < joyinfo[controller].NumButtons)
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].halfpress = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].halfpress);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2008-12-26 02:42:15 +00:00
|
|
|
|
// Check if we have an analog or digital joypad
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if (PadMapping[controller].controllertype == CTL_DPAD_HAT)
|
2008-12-10 21:23:15 +00:00
|
|
|
|
{
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].dpad = SDL_JoystickGetHat(PadState[controller].joy, PadMapping[controller].dpad);
|
2008-12-10 21:23:15 +00:00
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2009-01-19 17:47:00 +00:00
|
|
|
|
/* Only do this if the assigned button is in range (to allow for the current way of saving keyboard
|
|
|
|
|
keys in the same array) */
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if(PadMapping[controller].dpad2[CTL_D_PAD_UP] <= Buttons)
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_UP]);
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if(PadMapping[controller].dpad2[CTL_D_PAD_DOWN] <= Buttons)
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].dpad2[CTL_D_PAD_DOWN] = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_DOWN]);
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if(PadMapping[controller].dpad2[CTL_D_PAD_LEFT] <= Buttons)
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].dpad2[CTL_D_PAD_LEFT] = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_LEFT]);
|
2009-01-21 18:09:31 +00:00
|
|
|
|
if(PadMapping[controller].dpad2[CTL_D_PAD_RIGHT] <= Buttons)
|
2009-01-24 22:13:53 +00:00
|
|
|
|
PadState[controller].dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(PadState[controller].joy, PadMapping[controller].dpad2[CTL_D_PAD_RIGHT]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-02-01 20:19:21 +00:00
|
|
|
|
|
|
|
|
|
/* Debugging
|
|
|
|
|
Console::ClearScreen();
|
|
|
|
|
Console::Print(
|
|
|
|
|
"Controller and handle: %i %i\n"
|
|
|
|
|
|
|
|
|
|
"Triggers:%i %i %i %i %i | HalfPress: %i Mapping: %i\n",
|
|
|
|
|
|
|
|
|
|
controller, (int)PadState[controller].joy,
|
|
|
|
|
|
|
|
|
|
PadMapping[controller].triggertype,
|
|
|
|
|
PadMapping[controller].buttons[CTL_L_SHOULDER], PadMapping[controller].buttons[CTL_R_SHOULDER],
|
|
|
|
|
PadState[controller].axis[CTL_L_SHOULDER], PadState[controller].axis[CTL_R_SHOULDER],
|
|
|
|
|
|
|
|
|
|
PadState[controller].halfpress, PadMapping[controller].halfpress
|
|
|
|
|
); */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2008-12-28 18:50:24 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|