2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
#include "pluginspecs_wiimote.h"
|
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
#include "WiimoteReal/WiimoteReal.h"
|
|
|
|
|
2010-06-03 18:05:08 +00:00
|
|
|
#include "ControllerInterface/ControllerInterface.h"
|
2010-04-13 05:15:38 +00:00
|
|
|
#include "WiimoteEmu/WiimoteEmu.h"
|
|
|
|
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-07-08 00:52:46 +00:00
|
|
|
#include "WiimoteConfigDiag.h"
|
2010-06-12 17:39:33 +00:00
|
|
|
#include "../../InputUICommon/Src/ConfigDiag.h"
|
2010-04-13 05:15:38 +00:00
|
|
|
#endif
|
2010-06-12 17:39:33 +00:00
|
|
|
#include "../../InputCommon/Src/InputConfig.h"
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
#include <X11/Xlib.h>
|
2010-04-23 04:46:42 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#endif
|
2010-04-13 05:15:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PLUGIN_VERSION 0x0100
|
|
|
|
|
|
|
|
#define PLUGIN_NAME "Dolphin Wiimote New Incomplete"
|
|
|
|
#ifdef DEBUGFAST
|
|
|
|
#define PLUGIN_FULL_NAME PLUGIN_NAME" (DebugFast)"
|
|
|
|
#else
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#define PLUGIN_FULL_NAME PLUGIN_NAME" (Debug)"
|
|
|
|
#else
|
|
|
|
#define PLUGIN_FULL_NAME PLUGIN_NAME
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2010-04-13 20:02:48 +00:00
|
|
|
// plugin globals
|
2010-07-03 08:04:10 +00:00
|
|
|
InputPlugin g_plugin( "WiimoteNew", "Wiimote", "Wiimote" );
|
2010-04-13 20:02:48 +00:00
|
|
|
SWiimoteInitialize g_WiimoteInitialize;
|
|
|
|
|
2010-04-13 05:15:38 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
class wxDLLApp : public wxApp
|
|
|
|
{
|
|
|
|
bool OnInit()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// copied from GCPad
|
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
|
|
|
|
// copied from GCPad
|
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
wxWindow* GetParentedWxWindow(HWND Parent)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
wxSetInstance((HINSTANCE)g_hInstance);
|
|
|
|
#endif
|
|
|
|
wxWindow *win = new wxWindow();
|
|
|
|
#ifdef _WIN32
|
|
|
|
win->SetHWND((WXHWND)Parent);
|
|
|
|
win->AdoptAttributesFromHWND();
|
|
|
|
#endif
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// /
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
|
|
|
|
{
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
wxSetInstance(hinstDLL);
|
|
|
|
wxInitialize();
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
wxUninitialize();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void DeInitPlugin()
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
if (g_plugin.controller_interface.IsInit())
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
|
|
|
std::vector<ControllerEmu*>::const_iterator
|
|
|
|
i = g_plugin.controllers.begin(),
|
|
|
|
e = g_plugin.controllers.end();
|
|
|
|
for ( ; i!=e; ++i )
|
|
|
|
delete *i;
|
|
|
|
g_plugin.controllers.clear();
|
|
|
|
|
2010-06-06 03:52:11 +00:00
|
|
|
// true parameter to make SDL not quit in the wiimote plugin,
|
|
|
|
// the old wiimote plugin uses this hack as well, to prevent crash on stop
|
|
|
|
g_plugin.controller_interface.DeInit(true);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
// real wiimotes
|
|
|
|
WiimoteReal::Shutdown();
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if plugin isn't initialized, init and load config
|
|
|
|
void InitPlugin( void* const hwnd )
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
if (false == g_plugin.controller_interface.IsInit())
|
2010-04-13 05:15:38 +00:00
|
|
|
{
|
|
|
|
// add 4 wiimotes
|
|
|
|
for ( unsigned int i = 0; i<4; ++i )
|
2010-04-22 07:11:49 +00:00
|
|
|
g_plugin.controllers.push_back( new WiimoteEmu::Wiimote(i) );
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
// needed for Xlib and exclusive dinput
|
2010-07-03 08:04:10 +00:00
|
|
|
g_plugin.controller_interface.SetHwnd(hwnd);
|
2010-04-13 05:15:38 +00:00
|
|
|
g_plugin.controller_interface.Init();
|
|
|
|
|
2010-07-10 06:48:24 +00:00
|
|
|
// load the saved controller config
|
|
|
|
g_plugin.LoadConfig();
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
// real wiimotes
|
2010-07-03 11:20:38 +00:00
|
|
|
WiimoteReal::LoadSettings();
|
2010-07-03 08:04:10 +00:00
|
|
|
WiimoteReal::Initialize();
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// I N T E R F A C E
|
|
|
|
|
|
|
|
// __________________________________________________________________________________________________
|
|
|
|
// Function: Wiimote_Output
|
|
|
|
// Purpose: An L2CAP packet is passed from the Core to the Wiimote,
|
|
|
|
// on the HID CONTROL channel.
|
|
|
|
// input: Da pakket.
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void Wiimote_ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
switch (g_wiimote_sources[_number])
|
|
|
|
{
|
|
|
|
case WIIMOTE_SRC_REAL :
|
|
|
|
WiimoteReal::ControlChannel(_number, _channelID, _pData, _Size);
|
|
|
|
break;
|
|
|
|
case WIIMOTE_SRC_EMU :
|
|
|
|
((WiimoteEmu::Wiimote*)g_plugin.controllers[ _number ])->ControlChannel( _channelID, _pData, _Size );
|
|
|
|
break;
|
|
|
|
}
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// __________________________________________________________________________________________________
|
2010-06-05 19:03:37 +00:00
|
|
|
// Function: Send keyboard input to the plugin
|
|
|
|
// Purpose:
|
|
|
|
// input: The key and if it's pressed or released
|
|
|
|
// output: None
|
|
|
|
//
|
|
|
|
void Wiimote_Input(u16 _Key, u8 _UpDown)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-20 02:17:53 +00:00
|
|
|
// __________________________________________________________________________________________________
|
|
|
|
// Function: Unpair real Wiimotes (just a dummy to be compliant)
|
|
|
|
// Purpose:
|
|
|
|
// input: None
|
|
|
|
// output: 0 Wiimotes disconnected
|
|
|
|
//
|
|
|
|
unsigned int Wiimote_UnPairWiimotes(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-05 19:03:37 +00:00
|
|
|
// __________________________________________________________________________________________________
|
|
|
|
// Function: Wiimote_InterruptChannel
|
2010-04-13 05:15:38 +00:00
|
|
|
// Purpose: An L2CAP packet is passed from the Core to the Wiimote,
|
|
|
|
// on the HID INTERRUPT channel.
|
|
|
|
// input: Da pakket.
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void Wiimote_InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
switch (g_wiimote_sources[_number])
|
|
|
|
{
|
|
|
|
case WIIMOTE_SRC_REAL :
|
|
|
|
WiimoteReal::InterruptChannel(_number, _channelID, _pData, _Size);
|
|
|
|
break;
|
|
|
|
case WIIMOTE_SRC_EMU :
|
|
|
|
((WiimoteEmu::Wiimote*)g_plugin.controllers[ _number ])->InterruptChannel( _channelID, _pData, _Size );
|
|
|
|
break;
|
|
|
|
}
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// __________________________________________________________________________________________________
|
|
|
|
// Function: Wiimote_Update
|
|
|
|
// Purpose: This function is called periodically by the Core.
|
|
|
|
// input: none
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void Wiimote_Update(int _number)
|
|
|
|
{
|
|
|
|
//PanicAlert( "Wiimote_Update" );
|
|
|
|
|
|
|
|
// TODO: change this to a TryEnter, and make it give empty input on failure
|
|
|
|
g_plugin.controls_crit.Enter();
|
|
|
|
|
|
|
|
static int _last_number = 4;
|
|
|
|
if ( _number <= _last_number && g_plugin.interface_crit.TryEnter() )
|
|
|
|
{
|
|
|
|
g_plugin.controller_interface.UpdateOutput();
|
|
|
|
g_plugin.controller_interface.UpdateInput();
|
|
|
|
g_plugin.interface_crit.Leave();
|
|
|
|
}
|
|
|
|
_last_number = _number;
|
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
switch (g_wiimote_sources[_number])
|
|
|
|
{
|
|
|
|
case WIIMOTE_SRC_REAL :
|
|
|
|
WiimoteReal::Update(_number);
|
|
|
|
break;
|
|
|
|
case WIIMOTE_SRC_EMU :
|
|
|
|
((WiimoteEmu::Wiimote*)g_plugin.controllers[ _number ])->Update();
|
|
|
|
break;
|
|
|
|
}
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
g_plugin.controls_crit.Leave();
|
|
|
|
}
|
|
|
|
|
|
|
|
// __________________________________________________________________________________________________
|
|
|
|
// Function: PAD_GetAttachedPads
|
|
|
|
// Purpose: Get mask of attached pads (eg: controller 1 & 4 -> 0x9)
|
|
|
|
// input: none
|
|
|
|
// output: number of pads
|
|
|
|
//
|
|
|
|
unsigned int Wiimote_GetAttachedControllers()
|
|
|
|
{
|
2010-05-29 10:09:24 +00:00
|
|
|
unsigned int attached = 0;
|
|
|
|
for (unsigned int i=0; i<4; ++i)
|
2010-07-03 11:20:38 +00:00
|
|
|
if (g_wiimote_sources[i])
|
2010-05-29 10:09:24 +00:00
|
|
|
attached |= (1 << i);
|
|
|
|
return attached;
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GLOBAL I N T E R F A C E
|
|
|
|
// Function: GetDllInfo
|
|
|
|
// Purpose: This function allows the emulator to gather information
|
|
|
|
// about the DLL by filling in the PluginInfo structure.
|
|
|
|
// input: A pointer to a PLUGIN_INFO structure that needs to be
|
|
|
|
// filled by the function. (see def above)
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void GetDllInfo(PLUGIN_INFO* _pPluginInfo)
|
|
|
|
{
|
|
|
|
// don't feel like messing around with all those strcpy functions and warnings
|
|
|
|
//char *s1 = CIFACE_PLUGIN_FULL_NAME, *s2 = _pPluginInfo->Name;
|
|
|
|
//while ( *s2++ = *s1++ );
|
|
|
|
memcpy( _pPluginInfo->Name, PLUGIN_FULL_NAME, sizeof(PLUGIN_FULL_NAME) );
|
|
|
|
_pPluginInfo->Type = PLUGIN_TYPE_WIIMOTE;
|
|
|
|
_pPluginInfo->Version = PLUGIN_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ___________________________________________________________________________
|
|
|
|
// Function: DllConfig
|
|
|
|
// Purpose: This function is optional function that is provided
|
|
|
|
// to allow the user to configure the DLL
|
|
|
|
// input: A handle to the window that calls this function
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void DllConfig(HWND _hParent)
|
|
|
|
{
|
2010-04-23 04:46:42 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2010-07-03 08:04:10 +00:00
|
|
|
const bool was_init = g_plugin.controller_interface.IsInit();
|
2010-04-23 04:46:42 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
if (false == was_init)
|
2010-04-23 04:46:42 +00:00
|
|
|
{
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
Window win = GDK_WINDOW_XID(GTK_WIDGET(_hParent)->window);
|
2010-07-16 14:14:57 +00:00
|
|
|
InitPlugin((void *)win);
|
2010-04-23 04:46:42 +00:00
|
|
|
#else
|
|
|
|
InitPlugin(_hParent);
|
|
|
|
#endif
|
|
|
|
}
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
wxWindow *frame = GetParentedWxWindow(_hParent);
|
2010-07-03 08:04:10 +00:00
|
|
|
WiimoteConfigDiag* const m_ConfigFrame = new WiimoteConfigDiag(frame, g_plugin);
|
|
|
|
//InputConfigDialog* const m_ConfigFrame = new InputConfigDialog(frame, g_plugin, PLUGIN_FULL_NAME);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
frame->Disable();
|
|
|
|
m_ConfigFrame->ShowModal();
|
|
|
|
frame->Enable();
|
|
|
|
#else
|
|
|
|
m_ConfigFrame->ShowModal();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2010-07-03 08:04:10 +00:00
|
|
|
wxMilliSleep(50); // hooray for hacks
|
2010-04-13 05:15:38 +00:00
|
|
|
frame->SetFocus();
|
|
|
|
frame->SetHWND(NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_ConfigFrame->Destroy();
|
|
|
|
frame->Destroy();
|
|
|
|
// /
|
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
if (false == was_init)
|
2010-04-13 05:15:38 +00:00
|
|
|
DeInitPlugin();
|
2010-04-23 04:46:42 +00:00
|
|
|
#endif
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ___________________________________________________________________________
|
|
|
|
// Function: DllDebugger
|
|
|
|
// Purpose: Open the debugger
|
|
|
|
// input: a handle to the window that calls this function
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void DllDebugger(HWND _hParent, bool Show)
|
|
|
|
{
|
|
|
|
// wut?
|
|
|
|
}
|
|
|
|
|
|
|
|
// ___________________________________________________________________________
|
|
|
|
// Function: DllSetGlobals
|
|
|
|
// Purpose: Set the pointer for globals variables
|
|
|
|
// input: a pointer to the global struct
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
|
|
|
|
{
|
|
|
|
// wut?
|
|
|
|
}
|
|
|
|
|
|
|
|
// ___________________________________________________________________________
|
|
|
|
// Function: Initialize
|
|
|
|
// Purpose: Initialize the plugin
|
|
|
|
// input: Init
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void Initialize(void *init)
|
|
|
|
{
|
|
|
|
g_WiimoteInitialize = *(SWiimoteInitialize*)init;
|
|
|
|
if ( false == g_plugin.controller_interface.IsInit() )
|
2010-04-23 04:46:42 +00:00
|
|
|
InitPlugin( g_WiimoteInitialize.hWnd );
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ___________________________________________________________________________
|
|
|
|
// Function: Shutdown
|
|
|
|
// Purpose: This function is called when the emulator is shutting down
|
|
|
|
// a game allowing the dll to de-initialise.
|
|
|
|
// input: none
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void Shutdown(void)
|
|
|
|
{
|
|
|
|
if ( g_plugin.controller_interface.IsInit() )
|
|
|
|
DeInitPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ___________________________________________________________________________
|
|
|
|
// Function: DoState
|
|
|
|
// Purpose: Saves/load state
|
|
|
|
// input/output: ptr
|
|
|
|
// input: mode
|
|
|
|
//
|
|
|
|
void DoState(unsigned char **ptr, int mode)
|
|
|
|
{
|
2010-07-03 08:04:10 +00:00
|
|
|
// TODO: this
|
|
|
|
|
|
|
|
//PointerWrap p(ptr, mode);
|
|
|
|
//for (unsigned int i=0; i<4; ++i)
|
|
|
|
// ((WiimoteEmu::Wiimote*)g_plugin.controllers[i])->DoState(p);
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ___________________________________________________________________________
|
|
|
|
// Function: EmuStateChange
|
|
|
|
// Purpose: Notifies the plugin of a change in emulation state
|
|
|
|
// input: newState
|
|
|
|
// output: none
|
|
|
|
//
|
|
|
|
void EmuStateChange(PLUGIN_EMUSTATE newState)
|
|
|
|
{
|
|
|
|
// maybe use this later
|
2010-07-03 08:04:10 +00:00
|
|
|
WiimoteReal::StateChange(newState);
|
2010-04-13 05:15:38 +00:00
|
|
|
}
|