Moved WiimoteNew into Dolphin and eliminated the old wiimote plugin. Removed wiimote plugin support. Moved input dialog related InputUICommon stuff into DolphinWX. Removed now unused InputCommon files. UDPWiimote stuff is temporarily disabled until it is reorganized so Core won't depend on wx. Real wiimotes are now initialized on first need(wiimote diag open or game start) and left initialized until Dolphin exit.(maybe this will work better for Linux/OS X) (scons probably needs some fixes)

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6270 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak 2010-10-12 19:42:29 +00:00
commit 7e08fc19fc
116 changed files with 661 additions and 14529 deletions

View file

@ -480,14 +480,6 @@
RelativePath=".\Src\PluginVideo.h"
>
</File>
<File
RelativePath=".\Src\PluginWiimote.cpp"
>
</File>
<File
RelativePath=".\Src\PluginWiimote.h"
>
</File>
<Filter
Name="Specs"
>
@ -511,10 +503,6 @@
RelativePath="..\..\PluginSpecs\pluginspecs_video.h"
>
</File>
<File
RelativePath="..\..\PluginSpecs\pluginspecs_wiimote.h"
>
</File>
</Filter>
</Filter>
<Filter

View file

@ -1,48 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// 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 "PluginWiimote.h"
namespace Common {
PluginWiimote::PluginWiimote(const char *_Filename)
: CPlugin(_Filename), validWiimote(false)
{
Wiimote_ControlChannel = reinterpret_cast<TWiimote_ControlChannel>
(LoadSymbol("Wiimote_ControlChannel"));
Wiimote_Input = reinterpret_cast<TWiimote_Input>
(LoadSymbol("Wiimote_Input"));
Wiimote_InterruptChannel = reinterpret_cast<TWiimote_InterruptChannel>
(LoadSymbol("Wiimote_InterruptChannel"));
Wiimote_Update = reinterpret_cast<TWiimote_Update>
(LoadSymbol("Wiimote_Update"));
Wiimote_GetAttachedControllers = reinterpret_cast<TWiimote_GetAttachedControllers>
(LoadSymbol("Wiimote_GetAttachedControllers"));
Wiimote_UnPairWiimotes = reinterpret_cast<TWiimote_UnPairWiimotes>
(LoadSymbol("Wiimote_UnPairWiimotes"));
if ((Wiimote_ControlChannel != 0) &&
(Wiimote_Input != 0) &&
(Wiimote_InterruptChannel != 0) &&
(Wiimote_Update != 0) &&
(Wiimote_GetAttachedControllers != 0))
validWiimote = true;
}
PluginWiimote::~PluginWiimote() { }
} // Namespace

View file

@ -1,53 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// 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/
#ifndef _PLUGINWIIMOTE_H_
#define _PLUGINWIIMOTE_H_
#include "pluginspecs_wiimote.h"
#include "Plugin.h"
namespace Common {
typedef unsigned int (__cdecl* TPAD_GetAttachedPads)();
typedef void (__cdecl* TWiimote_Update)(int _number);
typedef void (__cdecl* TWiimote_Input)(u16 _Key, u8 _UpDown);
typedef void (__cdecl* TWiimote_ControlChannel)(int _number, u16 _channelID, const void* _pData, u32 _Size);
typedef void (__cdecl* TWiimote_InterruptChannel)(int _number, u16 _channelID, const void* _pData, u32 _Size);
typedef unsigned int (__cdecl* TWiimote_UnPairWiimotes)();
typedef unsigned int (__cdecl* TWiimote_GetAttachedControllers)();
class PluginWiimote : public CPlugin {
public:
PluginWiimote(const char *_Filename);
virtual ~PluginWiimote();
virtual bool IsValid() {return validWiimote;};
TWiimote_ControlChannel Wiimote_ControlChannel;
TWiimote_Input Wiimote_Input;
TWiimote_InterruptChannel Wiimote_InterruptChannel;
TWiimote_Update Wiimote_Update;
TWiimote_UnPairWiimotes Wiimote_UnPairWiimotes;
TWiimote_GetAttachedControllers Wiimote_GetAttachedControllers;
private:
bool validWiimote;
};
} // namespace
#endif // _PLUGINWIIMOTE_H_

View file

@ -45,7 +45,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include;..\..\..\Externals\WiiUse\Src"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -69,8 +69,9 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="wiiuse.lib"
OutputFile="$(OutDir)/Core.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;;&quot;..\..\..\Externals\WiiUse\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -115,7 +116,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include;..\..\..\Externals\WiiUse\Src"
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -140,7 +141,7 @@
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)/Core.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;;&quot;..\..\..\Externals\WiiUse\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -189,7 +190,7 @@
FavorSizeOrSpeed="1"
OmitFramePointers="true"
EnableFiberSafeOptimizations="false"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include;..\..\..\Externals\WiiUse\Src"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
StringPooling="true"
RuntimeLibrary="0"
@ -213,8 +214,9 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="wiiuse.lib"
OutputFile="$(OutDir)/Core.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;;&quot;..\..\..\Externals\WiiUse\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -266,7 +268,7 @@
OmitFramePointers="true"
EnableFiberSafeOptimizations="false"
WholeProgramOptimization="false"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include;..\..\..\Externals\WiiUse\Src"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
StringPooling="true"
RuntimeLibrary="0"
@ -290,8 +292,9 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="wiiuse.lib"
OutputFile="$(OutDir)/Core.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;;&quot;..\..\..\Externals\Lua\$(OutDir)\Lua.lib&quot;"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;;&quot;..\..\..\Externals\Lua\$(OutDir)\Lua.lib&quot;;&quot;..\..\..\Externals\WiiUse\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -340,7 +343,7 @@
FavorSizeOrSpeed="1"
OmitFramePointers="true"
EnableFiberSafeOptimizations="false"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include;..\..\..\Externals\WiiUse\Src"
PreprocessorDefinitions="NDEBUG;_LIB;DEBUGFAST;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
RuntimeLibrary="0"
BufferSecurityCheck="true"
@ -363,8 +366,9 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="wiiuse.lib"
OutputFile="$(OutDir)/Core.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;;&quot;..\..\..\Externals\WiiUse\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -414,7 +418,7 @@
FavorSizeOrSpeed="1"
OmitFramePointers="true"
EnableFiberSafeOptimizations="false"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include"
AdditionalIncludeDirectories=".\Core\Core\Src\Debugger;..\Common\Src;..\DiscIO\Src;..\..\Core\InputCommon\Src;..\..\PluginSpecs;..\..\..\Externals\LZO;..\..\..\Externals\Bochs_disasm;..\..\..\Externals\zlib;..\..\..\Externals\Lua;..\..\..\Externals\SFML\include;..\..\..\Externals\WiiUse\Src"
PreprocessorDefinitions="NDEBUG;_LIB;DEBUGFAST;_CRT_SECURE_NO_DEPRECATE;_SECURE_SCL=0"
RuntimeLibrary="0"
BufferSecurityCheck="false"
@ -437,7 +441,7 @@
<Tool
Name="VCLibrarianTool"
OutputFile="$(OutDir)/Core.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\LZO\$(OutDir)\lzo.lib&quot;;&quot;..\..\..\Externals\WiiUse\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -794,6 +798,122 @@
>
</File>
</Filter>
<Filter
Name="Wiimote"
>
<File
RelativePath=".\Src\HW\Wiimote.cpp"
>
</File>
<File
RelativePath=".\Src\HW\Wiimote.h"
>
</File>
<Filter
Name="Emu"
>
<File
RelativePath=".\Src\HW\WiimoteEmu\EmuSubroutines.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Encryption.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Encryption.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\MatrixMath.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Speaker.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\UDPTLayer.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\WiimoteEmu.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\WiimoteEmu.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\WiimoteHid.h"
>
</File>
<Filter
Name="Attachment"
>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Attachment.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Attachment.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Classic.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Classic.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Drums.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Drums.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Guitar.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Guitar.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Nunchuk.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Nunchuk.h"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Turntable.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteEmu\Attachment\Turntable.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="Real"
>
<File
RelativePath=".\Src\HW\WiimoteReal\WiimoteReal.cpp"
>
</File>
<File
RelativePath=".\Src\HW\WiimoteReal\WiimoteReal.h"
>
</File>
</Filter>
</Filter>
</Filter>
<Filter
Name="PowerPC"

View file

@ -171,7 +171,6 @@ void SConfig::SaveSettings()
// Plugins
ini.Set("Core", "GFXPlugin", m_LocalCoreStartupParameter.m_strVideoPlugin);
ini.Set("Core", "DSPPlugin", m_LocalCoreStartupParameter.m_strDSPPlugin);
ini.Set("Core", "WiiMotePlugin",m_LocalCoreStartupParameter.m_strWiimotePlugin);
ini.Save(File::GetUserPath(F_DOLPHINCONFIG_IDX));
m_SYSCONF->Save();
@ -187,7 +186,6 @@ void SConfig::LoadSettings()
// Hard coded defaults
m_DefaultGFXPlugin = DEFAULT_GFX_PLUGIN;
m_DefaultDSPPlugin = DEFAULT_DSP_PLUGIN;
m_DefaultWiiMotePlugin = DEFAULT_WIIMOTE_PLUGIN;
// General
{
@ -302,7 +300,6 @@ void SConfig::LoadSettings()
// Plugins
ini.Get("Core", "GFXPlugin", &m_LocalCoreStartupParameter.m_strVideoPlugin, m_DefaultGFXPlugin.c_str());
ini.Get("Core", "DSPPlugin", &m_LocalCoreStartupParameter.m_strDSPPlugin, m_DefaultDSPPlugin.c_str());
ini.Get("Core", "WiiMotePlugin", &m_LocalCoreStartupParameter.m_strWiimotePlugin, m_DefaultWiiMotePlugin.c_str());
}
m_SYSCONF = new SysConf();

View file

@ -50,7 +50,6 @@ struct SConfig
// hard coded default plugins ...
std::string m_DefaultGFXPlugin;
std::string m_DefaultDSPPlugin;
std::string m_DefaultWiiMotePlugin;
// name of the last used filename
std::string m_LastFilename;

View file

@ -45,6 +45,7 @@
#include "HW/GPFifo.h"
#include "HW/CPU.h"
#include "HW/GCPad.h"
#include "HW/Wiimote.h"
#include "HW/HW.h"
#include "HW/DSP.h"
#include "HW/GPFifo.h"
@ -382,20 +383,11 @@ THREAD_RETURN EmuThread(void *pArg)
Plugins.GetDSP()->Initialize((void *)&dspInit);
GCPad_Init(g_pWindowHandle);
Pad::Initialize(g_pWindowHandle);
// Load and Init WiimotePlugin - only if we are booting in wii mode
// Load and Init Wiimotes - only if we are booting in wii mode
if (_CoreParameter.bWii)
{
SWiimoteInitialize WiimoteInitialize;
WiimoteInitialize.hWnd = g_pWindowHandle;
WiimoteInitialize.ISOId = Ascii2Hex(_CoreParameter.m_strUniqueID);
WiimoteInitialize.pLog = Callback_WiimoteLog;
WiimoteInitialize.pWiimoteInterruptChannel = Callback_WiimoteInterruptChannel;
WiimoteInitialize.pRendererHasFocus = Callback_RendererHasFocus;
// Wait for Wiiuse to find the number of connected Wiimotes
Plugins.GetWiimote()->Initialize((void *)&WiimoteInitialize);
}
Wiimote::Initialize(g_pWindowHandle);
// The hardware is initialized.
g_bHwInit = true;
@ -508,7 +500,8 @@ THREAD_RETURN EmuThread(void *pArg)
if (_CoreParameter.bCPUThread)
Plugins.ShutdownVideoPlugin();
GCPad_Deinit();
Pad::Shutdown();
Wiimote::Shutdown();
Plugins.ShutdownPlugins();
NOTICE_LOG(CONSOLE, "%s", StopMessage(false, "Plugins shutdown").c_str());

View file

@ -126,7 +126,6 @@ struct SCoreStartupParameter
// files
std::string m_strVideoPlugin;
std::string m_strDSPPlugin;
std::string m_strWiimotePlugin;
std::string m_strFilename;
std::string m_strBootROM;

View file

@ -23,47 +23,42 @@
#include "../../InputCommon/Src/InputConfig.h"
static InputPlugin g_plugin("GCPadNew", "Pad", "GCPad");
namespace Pad
{
InputPlugin *PAD_GetPlugin() {
static InputPlugin g_plugin("GCPadNew", "Pad", "GCPad");
InputPlugin *GetPlugin()
{
return &g_plugin;
}
void GCPad_Deinit()
void Shutdown()
{
if ( g_plugin.controller_interface.IsInit() )
{
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();
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();
g_plugin.controller_interface.DeInit();
}
g_controller_interface.Shutdown();
}
// if plugin isn't initialized, init and load config
void GCPad_Init( void* const hwnd )
void Initialize(void* const hwnd)
{
// i realize i am checking IsInit() twice, just too lazy to change it
if ( false == g_plugin.controller_interface.IsInit() )
{
// add 4 gcpads
for (unsigned int i=0; i<4; ++i)
g_plugin.controllers.push_back(new GCPad(i));
// needed for Xlib
g_plugin.controller_interface.SetHwnd(hwnd);
g_plugin.controller_interface.Init();
// add 4 gcpads
for (unsigned int i=0; i<4; ++i)
g_plugin.controllers.push_back(new GCPad(i));
// load the saved controller config
g_plugin.LoadConfig();
}
g_controller_interface.SetHwnd(hwnd);
g_controller_interface.Initialize();
// load the saved controller config
g_plugin.LoadConfig();
}
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
void GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
{
memset(_pPADStatus, 0, sizeof(*_pPADStatus));
_pPADStatus->err = PAD_ERR_NONE;
@ -84,8 +79,8 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
static int _last_numPAD = 4;
if (_numPAD <= _last_numPAD)
{
g_plugin.controller_interface.UpdateOutput();
g_plugin.controller_interface.UpdateInput();
g_controller_interface.UpdateOutput();
g_controller_interface.UpdateInput();
}
_last_numPAD = _numPAD;
@ -102,7 +97,7 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// input: PAD number, Command type (Stop=0, Rumble=1, Stop Hard=2) and strength of Rumble
// output: none
//
void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
void Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
{
// enter
if ( g_plugin.controls_crit.TryEnter() )
@ -115,3 +110,5 @@ void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength)
g_plugin.controls_crit.Leave();
}
}
}

View file

@ -19,10 +19,20 @@
#include "GCPadStatus.h"
#include "../../InputCommon/Src/InputConfig.h"
void GCPad_Init( void* const hwnd );
void GCPad_Deinit();
#ifndef _GCPAD_H_
#define _GCPAD_H_
void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus);
void PAD_Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength);
namespace Pad
{
InputPlugin *PAD_GetPlugin();
void Shutdown();
void Initialize(void* const hwnd);
InputPlugin *GetPlugin();
void GetStatus(u8 _numPAD, SPADStatus* _pPADStatus);
void Rumble(u8 _numPAD, unsigned int _uType, unsigned int _uStrength);
}
#endif

View file

@ -148,7 +148,7 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* _pBuffer, int _iLength)
DEBUG_LOG(AMBASEBOARDDEBUG, "GC-AM: CMD 10, %02x (READ STATUS&SWITCHES)", ptr(1));
SPADStatus PadStatus;
memset(&PadStatus, 0 ,sizeof(PadStatus));
PAD_GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
Pad::GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
res[resp++] = 0x10;
res[resp++] = 0x2;
int d10_0 = 0xdf;
@ -313,7 +313,7 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* _pBuffer, int _iLength)
for (i=0; i<nr_players; ++i)
{
SPADStatus PadStatus;
PAD_GetStatus(i, &PadStatus);
Pad::GetStatus(i, &PadStatus);
unsigned char player_data[2] = {0,0};
if (PadStatus.button & PAD_BUTTON_START)
player_data[0] |= 0x80;
@ -350,7 +350,7 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* _pBuffer, int _iLength)
int slots = *jvs_io++;
msg.addData(1);
SPADStatus PadStatus;
PAD_GetStatus(0, &PadStatus);
Pad::GetStatus(0, &PadStatus);
while (slots--)
{
msg.addData(0);

View file

@ -131,7 +131,7 @@ bool CSIDevice_GCController::GetData(u32& _Hi, u32& _Low)
SPADStatus PadStatus;
memset(&PadStatus, 0, sizeof(PadStatus));
PAD_GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
Pad::GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
u32 netValues[2] = {0};
int NetPlay = 2;
@ -281,7 +281,7 @@ void CSIDevice_GCController::SendCommand(u32 _Cmd, u8 _Poll)
#endif
if (numPAD < 4)
PAD_Rumble(numPAD, uType, uStrength);
Pad::Rumble(numPAD, uType, uStrength);
if (!_Poll)
{

View file

@ -0,0 +1,153 @@
#include "Common.h"
#include "Wiimote.h"
#include "WiimoteReal/WiimoteReal.h"
#include "WiimoteEmu/WiimoteEmu.h"
#include "ControllerInterface/ControllerInterface.h"
#include "../../InputCommon/Src/InputConfig.h"
namespace Wiimote
{
static InputPlugin g_plugin(WIIMOTE_INI_NAME, "Wiimote", "Wiimote");
InputPlugin *GetPlugin()
{
return &g_plugin;
}
void Shutdown()
{
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();
// WiimoteReal is shutdown on app exit
//WiimoteReal::Shutdown();
g_controller_interface.Shutdown();
}
// if plugin isn't initialized, init and load config
void Initialize(void* const hwnd)
{
// add 4 wiimotes
for (unsigned int i = 0; i<4; ++i)
g_plugin.controllers.push_back(new WiimoteEmu::Wiimote(i));
g_controller_interface.SetHwnd(hwnd);
g_controller_interface.Initialize();
g_plugin.LoadConfig();
WiimoteReal::Initialize();
}
// __________________________________________________________________________________________________
// 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 ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
{
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)g_plugin.controllers[_number])->ControlChannel(_channelID, _pData, _Size);
if (WIIMOTE_SRC_REAL & g_wiimote_sources[_number])
WiimoteReal::ControlChannel(_number, _channelID, _pData, _Size);
}
// __________________________________________________________________________________________________
// Function: Wiimote_InterruptChannel
// Purpose: An L2CAP packet is passed from the Core to the Wiimote,
// on the HID INTERRUPT channel.
// input: Da pakket.
// output: none
//
void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
{
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)g_plugin.controllers[_number])->InterruptChannel(_channelID, _pData, _Size);
else
WiimoteReal::InterruptChannel(_number, _channelID, _pData, _Size);
}
// __________________________________________________________________________________________________
// Function: Wiimote_Update
// Purpose: This function is called periodically by the Core.
// input: none
// output: none
//
void 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_controller_interface.UpdateOutput();
g_controller_interface.UpdateInput();
}
_last_number = _number;
if (WIIMOTE_SRC_EMU & g_wiimote_sources[_number])
((WiimoteEmu::Wiimote*)g_plugin.controllers[_number])->Update();
else
WiimoteReal::Update(_number);
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 GetAttached()
{
unsigned int attached = 0;
for (unsigned int i=0; i<4; ++i)
if (g_wiimote_sources[i])
attached |= (1 << i);
return attached;
}
// ___________________________________________________________________________
// Function: DoState
// Purpose: Saves/load state
// input/output: ptr
// input: mode
//
void DoState(unsigned char **ptr, int mode)
{
// TODO:
//PointerWrap p(ptr, mode);
//for (unsigned int i=0; i<4; ++i)
// ((WiimoteEmu::Wiimote*)g_plugin.controllers[i])->DoState(p);
}
// ___________________________________________________________________________
// Function: EmuStateChange
// Purpose: Notifies the plugin of a change in emulation state
// input: newState
// output: none
//
void EmuStateChange(PLUGIN_EMUSTATE newState)
{
// TODO
WiimoteReal::StateChange(newState);
}
}

View file

@ -0,0 +1,50 @@
#ifndef _WIIMOTE_H_
#define _WIIMOTE_H_
#include "PluginSpecs.h"
#include "../../InputCommon/Src/InputConfig.h"
#define MAX_WIIMOTES 4
#define WIIMOTE_INI_NAME "WiimoteNew"
//extern InputPlugin g_plugin;
extern unsigned int g_wiimote_sources[MAX_WIIMOTES];
//extern SWiimoteInitialize g_WiimoteInitialize;
namespace Wiimote
{
void Shutdown();
void Initialize(void* const hwnd);
unsigned int GetAttached();
void DoState(unsigned char **ptr, int mode);
void EmuStateChange(PLUGIN_EMUSTATE newState);
InputPlugin *GetPlugin();
void ControlChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);
void InterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size);
void Update(int _number);
}
namespace WiimoteReal
{
unsigned int Initialize();
void Shutdown();
void Refresh();
void LoadSettings();
#ifdef _WIN32
int PairUp(bool unpair = false);
int UnPair();
#endif
}
#endif

View file

@ -0,0 +1,34 @@
#include "Attachment.h"
namespace WiimoteEmu
{
// Extension device IDs to be written to the last bytes of the extension reg
// The id for nothing inserted
static const u8 nothing_id[] = { 0x00, 0x00, 0x00, 0x00, 0x2e, 0x2e };
// The id for a partially inserted extension
static const u8 partially_id[] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff };
Attachment::Attachment( const char* const _name ) : name( _name )
{
reg.resize( WIIMOTE_REG_EXT_SIZE, 0);
}
None::None() : Attachment( "None" )
{
// set up register
memcpy( &reg[0xfa], nothing_id, sizeof(nothing_id) );
}
std::string Attachment::GetName() const
{
return name;
}
}
void ControllerEmu::Extension::GetState( u8* const data, const bool focus )
{
((WiimoteEmu::Attachment*)attachments[ active_extension ])->GetState( data, focus );
}

View file

@ -0,0 +1,30 @@
#ifndef _ATTACHMENT_EMU_H_
#define _ATTACHMENT_EMU_H_
#include "ControllerEmu.h"
#include "../WiimoteEmu.h"
namespace WiimoteEmu
{
class Attachment : public ControllerEmu
{
public:
Attachment( const char* const _name );
virtual void GetState( u8* const data, const bool focus = true ) {}
std::string GetName() const;
const char* const name;
std::vector<u8> reg;
};
class None : public Attachment
{
public:
None();
};
}
#endif

View file

@ -0,0 +1,130 @@
#include "Classic.h"
namespace WiimoteEmu
{
static const u8 classic_id[] = { 0x00, 0x00, 0xa4, 0x20, 0x01, 0x01 };
/* Classic Controller calibration */
static const u8 classic_calibration[] =
{
0xff, 0x00, 0x80, 0xff, 0x00, 0x80,
0xff, 0x00, 0x80, 0xff, 0x00, 0x80,
0x00, 0x00, 0x51, 0xa6
};
static const u16 classic_button_bitmasks[] =
{
Classic::BUTTON_A,
Classic::BUTTON_B,
Classic::BUTTON_X,
Classic::BUTTON_Y,
Classic::BUTTON_ZL,
Classic::BUTTON_ZR,
Classic::BUTTON_MINUS,
Classic::BUTTON_PLUS,
Classic::BUTTON_HOME,
};
static const char* const classic_button_names[] =
{
"A","B","X","Y","ZL","ZR","-","+","Home",
};
static const u16 classic_trigger_bitmasks[] =
{
Classic::TRIGGER_L, Classic::TRIGGER_R,
};
static const char* const classic_trigger_names[] =
{
"L", "R", "L-Analog", "R-Analog"
};
static const u16 classic_dpad_bitmasks[] =
{
Classic::PAD_UP, Classic::PAD_DOWN, Classic::PAD_LEFT, Classic::PAD_RIGHT
};
Classic::Classic() : Attachment( "Classic" )
{
// buttons
groups.push_back( m_buttons = new Buttons( "Buttons" ) );
for ( unsigned int i = 0; i < sizeof(classic_button_names)/sizeof(*classic_button_names); ++i )
m_buttons->controls.push_back( new ControlGroup::Input( classic_button_names[i] ) );
// sticks
groups.push_back( m_left_stick = new AnalogStick( "Left Stick" ) );
groups.push_back( m_right_stick = new AnalogStick( "Right Stick" ) );
// triggers
groups.push_back( m_triggers = new MixedTriggers( "Triggers" ) );
for ( unsigned int i=0; i < sizeof(classic_trigger_names)/sizeof(*classic_trigger_names); ++i )
m_triggers->controls.push_back( new ControlGroup::Input( classic_trigger_names[i] ) );
// dpad
groups.push_back( m_dpad = new Buttons( "D-Pad" ) );
for ( unsigned int i=0; i < 4; ++i )
m_dpad->controls.push_back( new ControlGroup::Input( named_directions[i] ) );
// set up register
// calibration
memcpy( &reg[0x20], classic_calibration, sizeof(classic_calibration) );
// id
memcpy( &reg[0xfa], classic_id, sizeof(classic_id) );
}
void Classic::GetState( u8* const data, const bool focus )
{
wm_classic_extension* const ccdata = (wm_classic_extension*)data;
ccdata->bt = 0;
// not using calibration data, o well
// left stick
{
u8 x, y;
m_left_stick->GetState( &x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0 );
ccdata->lx = x;
ccdata->ly = y;
}
// right stick
{
u8 x, y;
m_right_stick->GetState( &x, &y, 0x10, focus ? 0x0F /*0x0C*/ : 0 );
ccdata->rx1 = x;
ccdata->rx2 = x >> 1;
ccdata->rx3 = x >> 3;
ccdata->ry = y;
}
//triggers
{
u8 trigs[2];
m_triggers->GetState( &ccdata->bt, classic_trigger_bitmasks, trigs, focus ? 0x1F : 0 );
ccdata->lt1 = trigs[0];
ccdata->lt2 = trigs[0] >> 3;
ccdata->rt = trigs[1];
}
if (focus)
{
// buttons
m_buttons->GetState( &ccdata->bt, classic_button_bitmasks );
// dpad
m_dpad->GetState( &ccdata->bt, classic_dpad_bitmasks );
}
// flip button bits
ccdata->bt ^= 0xFFFF;
}
}

View file

@ -0,0 +1,41 @@
#include "Attachment.h"
namespace WiimoteEmu
{
class Classic : public Attachment
{
public:
Classic();
void GetState( u8* const data, const bool focus );
enum
{
PAD_RIGHT = 0x80,
PAD_DOWN = 0x40,
TRIGGER_L = 0x20,
BUTTON_MINUS = 0x10,
BUTTON_HOME = 0x08,
BUTTON_PLUS = 0x04,
TRIGGER_R = 0x02,
NOTHING = 0x01,
BUTTON_ZL = 0x8000,
BUTTON_B = 0x4000,
BUTTON_Y = 0x2000,
BUTTON_A = 0x1000,
BUTTON_X = 0x0800,
BUTTON_ZR = 0x0400,
PAD_LEFT = 0x0200,
PAD_UP = 0x0100,
};
private:
Buttons* m_buttons;
MixedTriggers* m_triggers;
Buttons* m_dpad;
AnalogStick* m_left_stick;
AnalogStick* m_right_stick;
};
}

View file

@ -0,0 +1,82 @@
#include "Drums.h"
namespace WiimoteEmu
{
static const u8 drums_id[] = { 0x01, 0x00, 0xa4, 0x20, 0x01, 0x03 };
static const u16 drum_pad_bitmasks[] =
{
Drums::PAD_RED,
Drums::PAD_YELLOW,
Drums::PAD_BLUE,
Drums::PAD_GREEN,
Drums::PAD_ORANGE,
Drums::PAD_BASS,
};
static const char* const drum_pad_names[] =
{
"Red","Yellow","Blue","Green","Orange","Bass"
};
static const u16 drum_button_bitmasks[] =
{
Drums::BUTTON_MINUS,
Drums::BUTTON_PLUS,
};
Drums::Drums() : Attachment( "Drums" )
{
// pads
groups.push_back( m_pads = new Buttons( "Pads" ) );
for ( unsigned int i = 0; i < sizeof(drum_pad_names)/sizeof(*drum_pad_names); ++i )
m_pads->controls.push_back( new ControlGroup::Input( drum_pad_names[i] ) );
// stick
groups.push_back( m_stick = new AnalogStick( "Stick" ) );
// buttons
groups.push_back( m_buttons = new Buttons( "Buttons" ) );
m_buttons->controls.push_back( new ControlGroup::Input("-") );
m_buttons->controls.push_back( new ControlGroup::Input("+") );
// set up register
// id
memcpy( &reg[0xfa], drums_id, sizeof(drums_id) );
}
void Drums::GetState(u8* const data, const bool focus)
{
wm_drums_extension* const ddata = (wm_drums_extension*)data;
ddata->bt = 0;
// calibration data not figured out yet?
// stick
{
u8 x, y;
m_stick->GetState( &x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0 );
ddata->sx = x;
ddata->sy = y;
}
// TODO: softness maybe
data[2] = 0xFF;
data[3] = 0xFF;
if (focus)
{
// buttons
m_buttons->GetState( &ddata->bt, drum_button_bitmasks );
// pads
m_pads->GetState( &ddata->bt, drum_pad_bitmasks );
}
// flip button bits
ddata->bt ^= 0xFFFF;
}
}

View file

@ -0,0 +1,32 @@
#include "Attachment.h"
namespace WiimoteEmu
{
class Drums : public Attachment
{
public:
Drums();
void GetState( u8* const data, const bool focus );
enum
{
BUTTON_PLUS = 0x04,
BUTTON_MINUS = 0x10,
PAD_BASS = 0x0400,
PAD_BLUE = 0x0800,
PAD_GREEN = 0x1000,
PAD_YELLOW = 0x2000,
PAD_RED = 0x4000,
PAD_ORANGE = 0x8000,
};
private:
Buttons* m_buttons;
Buttons* m_pads;
AnalogStick* m_stick;
};
}

View file

@ -0,0 +1,102 @@
#include "Guitar.h"
namespace WiimoteEmu
{
static const u8 guitar_id[] = { 0x00, 0x00, 0xa4, 0x20, 0x01, 0x03 };
static const u16 guitar_fret_bitmasks[] =
{
Guitar::FRET_GREEN,
Guitar::FRET_RED,
Guitar::FRET_YELLOW,
Guitar::FRET_BLUE,
Guitar::FRET_ORANGE,
};
static const char* const guitar_fret_names[] =
{
"Green","Red","Yellow","Blue","Orange",
};
static const u16 guitar_button_bitmasks[] =
{
Guitar::BUTTON_MINUS,
Guitar::BUTTON_PLUS,
};
static const u16 guitar_strum_bitmasks[] =
{
Guitar::BAR_UP,
Guitar::BAR_DOWN,
};
Guitar::Guitar() : Attachment( "Guitar" )
{
// frets
groups.push_back( m_frets = new Buttons( "Frets" ) );
for ( unsigned int i = 0; i < sizeof(guitar_fret_names)/sizeof(*guitar_fret_names); ++i )
m_frets->controls.push_back( new ControlGroup::Input( guitar_fret_names[i] ) );
// strum
groups.push_back( m_strum = new Buttons( "Strum" ) );
m_strum->controls.push_back( new ControlGroup::Input("Up") );
m_strum->controls.push_back( new ControlGroup::Input("Down") );
// buttons
groups.push_back( m_buttons = new Buttons( "Buttons" ) );
m_buttons->controls.push_back( new ControlGroup::Input("-") );
m_buttons->controls.push_back( new ControlGroup::Input("+") );
// stick
groups.push_back( m_stick = new AnalogStick( "Stick" ) );
// whammy
groups.push_back( m_whammy = new Triggers( "Whammy" ) );
m_whammy->controls.push_back( new ControlGroup::Input("Bar") );
// set up register
// id
memcpy( &reg[0xfa], guitar_id, sizeof(guitar_id) );
}
void Guitar::GetState(u8* const data, const bool focus)
{
wm_guitar_extension* const gdata = (wm_guitar_extension*)data;
gdata->bt = 0;
// calibration data not figured out yet?
// stick
{
u8 x, y;
m_stick->GetState( &x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0 );
gdata->sx = x;
gdata->sy = y;
}
// TODO: touch bar, probably not
gdata->tb = 0x0F; // not touched
// whammy bar
u8 whammy;
m_whammy->GetState( &whammy, 0x1F );
gdata->whammy = whammy;
if (focus)
{
// buttons
m_buttons->GetState( &gdata->bt, guitar_button_bitmasks );
// frets
m_frets->GetState( &gdata->bt, guitar_fret_bitmasks );
// strum
m_strum->GetState( &gdata->bt, guitar_strum_bitmasks );
}
// flip button bits
gdata->bt ^= 0xFFFF;
}
}

View file

@ -0,0 +1,35 @@
#include "Attachment.h"
namespace WiimoteEmu
{
class Guitar : public Attachment
{
public:
Guitar();
void GetState( u8* const data, const bool focus );
enum
{
BUTTON_PLUS = 0x04,
BUTTON_MINUS = 0x10,
BAR_DOWN = 0x40,
BAR_UP = 0x0100,
FRET_YELLOW = 0x0800,
FRET_GREEN = 0x1000,
FRET_BLUE = 0x2000,
FRET_RED = 0x4000,
FRET_ORANGE = 0x8000,
};
private:
Buttons* m_buttons;
Buttons* m_frets;
Buttons* m_strum;
Triggers* m_whammy;
AnalogStick* m_stick;
};
}

View file

@ -0,0 +1,131 @@
#include "Nunchuk.h"
#include "UDPWrapper.h"
#include "UDPWiimote.h"
namespace WiimoteEmu
{
static const u8 nunchuck_id[] = { 0x00, 0x00, 0xa4, 0x20, 0x00, 0x00 };
/* Default calibration for the nunchuck. It should be written to 0x20 - 0x3f of the
extension register. 0x80 is the neutral x and y accelerators and 0xb3 is the
neutral z accelerometer that is adjusted for gravity. */
static const u8 nunchuck_calibration[] =
{
0x80, 0x80, 0x80, 0x00, // accelerometer x, y, z neutral
0xb3, 0xb3, 0xb3, 0x00, // x, y, z g-force values
// 0x80 = analog stick x and y axis center
0xff, 0x00, 0x80,
0xff, 0x00, 0x80,
0xec, 0x41 // checksum on the last two bytes
};
static const u8 nunchuk_button_bitmasks[] =
{
Nunchuk::BUTTON_C,
Nunchuk::BUTTON_Z,
};
#ifdef USE_UDP_WIIMOTE
Nunchuk::Nunchuk(UDPWrapper *wrp) : Attachment("Nunchuk") , m_udpWrap(wrp)
#else
Nunchuk::Nunchuk() : Attachment("Nunchuk")
#endif
{
// buttons
groups.push_back(m_buttons = new Buttons("Buttons"));
m_buttons->controls.push_back(new ControlGroup::Input("C"));
m_buttons->controls.push_back(new ControlGroup::Input("Z"));
// stick
groups.push_back(m_stick = new AnalogStick("Stick"));
// swing
groups.push_back(m_swing = new Force("Swing"));
// tilt
groups.push_back(m_tilt = new Tilt("Tilt"));
// shake
groups.push_back(m_shake = new Buttons("Shake"));
m_shake->controls.push_back(new ControlGroup::Input("X"));
m_shake->controls.push_back(new ControlGroup::Input("Y"));
m_shake->controls.push_back(new ControlGroup::Input("Z"));
// set up register
// calibration
memcpy(&reg[0x20], nunchuck_calibration, sizeof(nunchuck_calibration));
// id
memcpy(&reg[0xfa], nunchuck_id, sizeof(nunchuck_id));
// this should get set to 0 on disconnect, but it isn't, o well
memset(m_shake_step, 0, sizeof(m_shake_step));
}
void Nunchuk::GetState(u8* const data, const bool focus)
{
wm_extension* const ncdata = (wm_extension*)data;
ncdata->bt = 0;
// stick / not using calibration data for stick, o well
m_stick->GetState(&ncdata->jx, &ncdata->jy, 0x80, focus ? 127 : 0);
AccelData accel;
// tilt
EmulateTilt(&accel, m_tilt, focus);
if (focus)
{
// swing
EmulateSwing(&accel, m_swing);
// shake
EmulateShake(&accel, m_shake, m_shake_step);
// buttons
m_buttons->GetState(&ncdata->bt, nunchuk_button_bitmasks);
}
// flip the button bits :/
ncdata->bt ^= 0x03;
#ifdef USE_UDP_WIIMOTE
if (m_udpWrap->inst)
{
if (m_udpWrap->updNun)
{
u8 mask;
float x, y;
m_udpWrap->inst->getNunchuck(x, y, mask);
// buttons
if (mask & UDPWM_NC)
ncdata->bt &= ~WiimoteEmu::Nunchuk::BUTTON_C;
if (mask & UDPWM_NZ)
ncdata->bt &= ~WiimoteEmu::Nunchuk::BUTTON_Z;
// stick
if (ncdata->jx == 0x80 && ncdata->jy == 0x80)
{
ncdata->jx = u8(0x80 + x*127);
ncdata->jy = u8(0x80 + y*127);
}
}
if (m_udpWrap->updNunAccel)
{
float x,y,z;
m_udpWrap->inst->getNunchuckAccel(x,y,z);
accel.x=x;
accel.y=y;
accel.z=z;
}
}
#endif
wm_accel* dt = (wm_accel*)&ncdata->ax;
accel_cal* calib = (accel_cal*)&reg[0x20];
dt->x=u8(trim(accel.x*(calib->one_g.x-calib->zero_g.x)+calib->zero_g.x));
dt->y=u8(trim(accel.y*(calib->one_g.y-calib->zero_g.y)+calib->zero_g.y));
dt->z=u8(trim(accel.z*(calib->one_g.z-calib->zero_g.z)+calib->zero_g.z));
}
}

View file

@ -0,0 +1,47 @@
#ifndef NUNCHUCK_H
#define NUNCHUCK_H
#include "Attachment.h"
class UDPWrapper;
namespace WiimoteEmu
{
class Nunchuk : public Attachment
{
public:
#ifdef USE_UDP_WIIMOTE
Nunchuk(UDPWrapper * wrp);
#else
Nunchuk();
#endif
virtual void GetState( u8* const data, const bool focus );
enum
{
BUTTON_C = 0x02,
BUTTON_Z = 0x01,
};
private:
Tilt* m_tilt;
Force* m_swing;
Buttons* m_shake;
Buttons* m_buttons;
AnalogStick* m_stick;
unsigned int m_shake_step[3];
#ifdef USE_UDP_WIIMOTE
UDPWrapper* const m_udpWrap;
#endif
};
}
#endif

View file

@ -0,0 +1,121 @@
#include "Turntable.h"
namespace WiimoteEmu
{
static const u8 turntable_id[] = {0x03, 0x00, 0xa4, 0x20, 0x01, 0x03};
static const u16 turntable_button_bitmasks[] =
{
Turntable::BUTTON_L_GREEN,
Turntable::BUTTON_L_RED,
Turntable::BUTTON_L_BLUE,
Turntable::BUTTON_R_GREEN,
Turntable::BUTTON_R_RED,
Turntable::BUTTON_R_BLUE,
Turntable::BUTTON_MINUS,
Turntable::BUTTON_PLUS,
Turntable::BUTTON_EUPHORIA,
};
static const char* const turntable_button_names[] =
{
"Green Left", "Red Left", "Blue Left",
"Green Right", "Red Right", "Blue Right",
"-", "+", "Euphoria",
};
Turntable::Turntable() : Attachment("Turntable")
{
// buttons
groups.push_back(m_buttons = new Buttons("Buttons"));
for (unsigned int i = 0; i < sizeof(turntable_button_names)/sizeof(*turntable_button_names); ++i)
m_buttons->controls.push_back(new ControlGroup::Input( turntable_button_names[i]));
// turntables
groups.push_back(m_left_table = new Slider("Table Left"));
groups.push_back(m_right_table = new Slider("Table Right"));
// stick
groups.push_back(m_stick = new AnalogStick("Stick"));
// effect dial
groups.push_back(m_effect_dial = new Triggers("Effect"));
m_effect_dial->controls.push_back(new ControlGroup::Input("Dial"));
// crossfade
groups.push_back(m_crossfade = new Slider("Crossfade"));
// set up register
// id
memcpy(&reg[0xfa], turntable_id, sizeof(turntable_id));
}
void Turntable::GetState(u8* const data, const bool focus)
{
wm_turntable_extension* const ttdata = (wm_turntable_extension*)data;
ttdata->bt = 0;
// stick
{
u8 x, y;
m_stick->GetState(&x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0);
ttdata->sx = x;
ttdata->sy = y;
}
// left table
{
s8 tt = 0;
m_left_table->GetState(&tt, focus ? 0x1F : 0);
ttdata->ltable1 = tt;
ttdata->ltable2 = tt << 5;
}
// right table
{
s8 tt = 0;
m_right_table->GetState(&tt, focus ? 0x1F : 0);
ttdata->rtable1 = tt;
ttdata->rtable2 = tt << 1;
ttdata->rtable3 = tt << 3;
ttdata->rtable4 = tt << 5;
}
// effect dial
{
u8 dial = 0;
m_effect_dial->GetState(&dial, focus ? 0xF : 0);
ttdata->dial1 = dial;
ttdata->dial2 = dial << 3;
}
// crossfade slider
{
u8 cfs = 0;
m_crossfade->GetState(&cfs, 8, 7);
ttdata->slider = cfs;
}
if (focus)
{
// buttons
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks);
}
// flip button bits :/
ttdata->bt ^= (
BUTTON_L_GREEN | BUTTON_L_RED | BUTTON_L_BLUE |
BUTTON_R_GREEN | BUTTON_R_RED | BUTTON_R_BLUE |
BUTTON_MINUS | BUTTON_PLUS | BUTTON_EUPHORIA
);
}
}

View file

@ -0,0 +1,37 @@
#include "Attachment.h"
namespace WiimoteEmu
{
class Turntable : public Attachment
{
public:
Turntable();
void GetState(u8* const data, const bool focus);
enum
{
BUTTON_EUPHORIA = 0x1000,
BUTTON_L_GREEN = 0x0800,
BUTTON_L_RED = 0x20,
BUTTON_L_BLUE = 0x8000,
BUTTON_R_GREEN = 0x2000,
BUTTON_R_RED = 0x02,
BUTTON_R_BLUE = 0x0400,
BUTTON_MINUS = 0x10,
BUTTON_PLUS = 0x04,
};
private:
Buttons* m_buttons;
MixedTriggers* m_triggers;
AnalogStick* m_stick;
Triggers *m_effect_dial;
Slider *m_left_table, *m_right_table, *m_crossfade;
};
}

View file

@ -0,0 +1,542 @@
// Copyright (C) 2003 Dolphin Project.
// 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/
/* HID reports access guide. */
/* 0x10 - 0x1a Output EmuMain.cpp: HidOutputReport()
0x10 - 0x14: General
0x15: Status report request from the Wii
0x16 and 0x17: Write and read memory or registers
0x19 and 0x1a: General
0x20 - 0x22 Input EmuMain.cpp: HidOutputReport() to the destination
0x15 leads to a 0x20 Input report
0x17 leads to a 0x21 Input report
0x10 - 0x1a leads to a 0x22 Input report
0x30 - 0x3f Input This file: Update() */
#include <vector>
#include <string>
#include <fstream>
#include "Common.h"
#include "FileUtil.h"
#include "WiimoteEmu.h"
#include "WiimoteHid.h"
#include "../WiimoteReal/WiimoteReal.h"
#include "Attachment/Attachment.h"
/* Bit shift conversions */
u32 swap24(const u8* src)
{
return (src[0] << 16) | (src[1] << 8) | src[2];
}
namespace WiimoteEmu
{
void Wiimote::ReportMode(const wm_report_mode* const dr)
{
//INFO_LOG(WIIMOTE, "Set data report mode");
//DEBUG_LOG(WIIMOTE, " Rumble: %x", dr->rumble);
//DEBUG_LOG(WIIMOTE, " Continuous: %x", dr->continuous);
//DEBUG_LOG(WIIMOTE, " All The Time: %x", dr->all_the_time);
//DEBUG_LOG(WIIMOTE, " Mode: 0x%02x", dr->mode);
//m_reporting_auto = dr->all_the_time;
m_reporting_auto = dr->continuous; // this right?
m_reporting_mode = dr->mode;
//m_reporting_channel = _channelID; // this is set in every Interrupt/Control Channel now
// reset IR camera
//memset(m_reg_ir, 0, sizeof(*m_reg_ir)); //ugly hack
if (dr->mode > 0x37)
PanicAlert("Wiimote: Unsupported Reporting mode.");
else if (dr->mode < WM_REPORT_CORE)
PanicAlert("Wiimote: Reporting mode < 0x30.");
}
/* Here we process the Output Reports that the Wii sends. Our response will be
an Input Report back to the Wii. Input and Output is from the Wii's
perspective, Output means data to the Wiimote (from the Wii), Input means
data from the Wiimote.
The call browser:
1. Wiimote_InterruptChannel > InterruptChannel > HidOutputReport
2. Wiimote_ControlChannel > ControlChannel > HidOutputReport
The IR enable/disable and speaker enable/disable and mute/unmute values are
bit2: 0 = Disable (0x02), 1 = Enable (0x06)
*/
void Wiimote::HidOutputReport(const wm_report* const sr, const bool send_ack)
{
INFO_LOG(WIIMOTE, "HidOutputReport (page: %i, cid: 0x%02x, wm: 0x%02x)", m_index, m_reporting_channel, sr->wm);
// wiibrew:
// In every single Output Report, bit 0 (0x01) of the first byte controls the Rumble feature.
m_rumble_on = sr->rumble;
switch (sr->wm)
{
case WM_RUMBLE : // 0x10
// this is handled above
return; // no ack
break;
case WM_LEDS : // 0x11
//INFO_LOG(WIIMOTE, "Set LEDs: 0x%02x", sr->data[0]);
m_status.leds = sr->data[0] >> 4;
break;
case WM_REPORT_MODE : // 0x12
ReportMode((wm_report_mode*)sr->data);
break;
case WM_IR_PIXEL_CLOCK : // 0x13
//INFO_LOG(WIIMOTE, "WM IR Clock: 0x%02x", sr->data[0]);
//m_ir_clock = sr->enable;
if (false == sr->ack)
return;
break;
case WM_SPEAKER_ENABLE : // 0x14
//INFO_LOG(WIIMOTE, "WM Speaker Enable: 0x%02x", sr->data[0]);
//PanicAlert( "WM Speaker Enable: %d", sr->data[0] );
m_status.speaker = sr->enable;
if (false == sr->ack)
return;
break;
case WM_REQUEST_STATUS : // 0x15
RequestStatus((wm_request_status*)sr->data);
return; // sends its own ack
break;
case WM_WRITE_DATA : // 0x16
WriteData((wm_write_data*)sr->data);
break;
case WM_READ_DATA : // 0x17
ReadData((wm_read_data*)sr->data);
return; // sends its own ack
break;
case WM_WRITE_SPEAKER_DATA : // 0x18
#ifdef USE_WIIMOTE_EMU_SPEAKER
SpeakerData((wm_speaker_data*)sr->data);
#endif
// TODO: Does this need an ack?
return; // no ack
break;
case WM_SPEAKER_MUTE : // 0x19
//INFO_LOG(WIIMOTE, "WM Speaker Mute: 0x%02x", sr->data[0]);
//PanicAlert( "WM Speaker Mute: %d", sr->data[0] & 0x04 );
#ifdef USE_WIIMOTE_EMU_SPEAKER
// testing
if (sr->data[0] & 0x04)
memset(&m_channel_status, 0, sizeof(m_channel_status));
#endif
m_speaker_mute = sr->enable;
if (false == sr->ack)
return;
break;
case WM_IR_LOGIC: // 0x1a
// comment from old plugin:
// This enables or disables the IR lights, we update the global variable g_IR
// so that WmRequestStatus() knows about it
//INFO_LOG(WIIMOTE, "WM IR Enable: 0x%02x", sr->data[0]);
m_status.ir = sr->enable;
if (false == sr->ack)
return;
break;
default:
PanicAlert("HidOutputReport: Unknown channel 0x%02x", sr->wm);
return; // no ack
break;
}
// send ack
if (send_ack)
SendAck(sr->wm);
}
/* This will generate the 0x22 acknowledgement for most Input reports.
It has the form of "a1 22 00 00 _reportID 00".
The first two bytes are the core buttons data,
00 00 means nothing is pressed.
The last byte is the success code 00. */
void Wiimote::SendAck(u8 _reportID)
{
u8 data[6];
data[0] = 0xA1;
data[1] = WM_ACK_DATA;
wm_acknowledge* const ack = (wm_acknowledge*)(data + 2);
ack->buttons = m_status.buttons;
ack->reportID = _reportID;
ack->errorID = 0;
Core::Callback_WiimoteInterruptChannel( m_index, m_reporting_channel, data, sizeof(data));
}
void Wiimote::HandleExtensionSwap()
{
// handle switch extension
if (m_extension->active_extension != m_extension->switch_extension)
{
// if an extension is currently connected and we want to switch to a different extension
if ((m_extension->active_extension > 0) && m_extension->switch_extension)
// detach extension first, wait til next Update() or RequestStatus() call to change to the new extension
m_extension->active_extension = 0;
else
// set the wanted extension
m_extension->active_extension = m_extension->switch_extension;
// update status struct
m_status.extension = m_extension->active_extension ? 1 : 0;
// set register, I hate this line
m_register[0xa40000] = ((WiimoteEmu::Attachment*)m_extension->attachments[m_extension->active_extension])->reg;
}
}
// old comment
/* Here we produce a 0x20 status report to send to the Wii. We currently ignore
the status request rs and all its eventual instructions it may include (for
example turn off rumble or something else) and just send the status
report. */
void Wiimote::RequestStatus(const wm_request_status* const rs)
{
HandleExtensionSwap();
// set up report
u8 data[8];
data[0] = 0xA1;
data[1] = WM_STATUS_REPORT;
// status values
*(wm_status_report*)(data + 2) = m_status;
// hybrid wiimote stuff
if (WIIMOTE_SRC_HYBRID == g_wiimote_sources[m_index] && (m_extension->switch_extension <= 0))
{
using namespace WiimoteReal;
g_refresh_critsec.Enter();
if (g_wiimotes[m_index])
{
wm_request_status rpt;
rpt.rumble = 0;
g_wiimotes[m_index]->SendPacket(WM_REQUEST_STATUS, &rpt, sizeof(rpt));
}
g_refresh_critsec.Leave();
return;
}
// send report
Core::Callback_WiimoteInterruptChannel(m_index, m_reporting_channel, data, sizeof(data));
}
/* Write data to Wiimote and Extensions registers. */
void Wiimote::WriteData(const wm_write_data* const wd)
{
u32 address = swap24(wd->address);
// ignore the 0x010000 bit
address &= 0xFEFFFF;
if (wd->size > 16)
{
PanicAlert("WriteData: size is > 16 bytes");
return;
}
switch (wd->space)
{
case WM_SPACE_EEPROM :
{
// Write to EEPROM
if (address + wd->size > WIIMOTE_EEPROM_SIZE)
{
ERROR_LOG(WIIMOTE, "WriteData: address + size out of bounds!");
PanicAlert("WriteData: address + size out of bounds!");
return;
}
memcpy(m_eeprom + address, wd->data, wd->size);
// write mii data to file
// i need to improve this greatly
if (address >= 0x0FCA && address < 0x12C0)
{
// writing the whole mii block each write :/
std::ofstream file;
file.open( (std::string(File::GetUserPath(D_WIIUSER_IDX)) + "mii.bin").c_str(), std::ios::binary | std::ios::out);
file.write((char*)m_eeprom + 0x0FCA, 0x02f0);
file.close();
}
}
break;
case WM_SPACE_REGS1 :
case WM_SPACE_REGS2 :
{
// Write to Control Register
// ignore second byte for extension area
if (0xA4 == (address >> 16))
address &= 0xFF00FF;
// write to the register
m_register.Write(address, wd->data, wd->size);
switch (address >> 16)
{
// speaker
case 0xa2 :
//PanicAlert("Write to speaker!!");
break;
// extension register
case 0xa4 :
{
// Run the key generation on all writes in the key area, it doesn't matter
// that we send it parts of a key, only the last full key will have an effect
// I might have f'ed this up
if ( address >= 0xa40040 && address <= 0xa4004c )
wiimote_gen_key(&m_ext_key, m_reg_ext->encryption_key);
//else if ( address >= 0xa40020 && address < 0xa40040 )
// PanicAlert("Writing to extension calibration data! Extension may misbehave");
}
break;
// ir
case 0xB0 :
if (5 == m_reg_ir->mode)
PanicAlert("IR Full Mode is Unsupported!");
break;
}
}
break;
default:
PanicAlert("WriteData: unimplemented parameters!");
break;
}
}
/* Read data from Wiimote and Extensions registers. */
void Wiimote::ReadData(const wm_read_data* const rd)
{
u32 address = swap24(rd->address);
u16 size = Common::swap16(rd->size);
// ignore the 0x010000 bit
address &= 0xFEFFFF;
// hybrid wiimote stuff
// relay the read data request to real-wiimote
if (WIIMOTE_SRC_HYBRID == g_wiimote_sources[m_index] && ((0xA4 != (address >> 16)) || (m_extension->switch_extension <= 0)))
{
WiimoteReal::InterruptChannel(m_index, m_reporting_channel, ((u8*)rd) - 2, sizeof(wm_read_data) + 2); // hacky
// don't want emu-wiimote to send reply
return;
}
ReadRequest rr;
u8* block = new u8[size];
switch (rd->space)
{
case WM_SPACE_EEPROM :
{
//PanicAlert("ReadData: reading from EEPROM: address: 0x%x size: 0x%x", address, size);
// Read from EEPROM
if (address + size >= WIIMOTE_EEPROM_FREE_SIZE)
{
if (address + size > WIIMOTE_EEPROM_SIZE)
{
PanicAlert("ReadData: address + size out of bounds");
return;
}
// generate a read error
size = 0;
}
// read mii data from file
// i need to improve this greatly
if (address >= 0x0FCA && address < 0x12C0)
{
// reading the whole mii block :/
std::ifstream file;
file.open( (std::string(File::GetUserPath(D_WIIUSER_IDX)) + "mii.bin").c_str(), std::ios::binary | std::ios::in);
file.read((char*)m_eeprom + 0x0FCA, 0x02f0);
file.close();
}
// read mem to be sent to wii
memcpy( block, m_eeprom + address, size);
}
break;
case WM_SPACE_REGS1 :
case WM_SPACE_REGS2 :
{
// Read from Control Register
// ignore second byte for extension area
if (0xA4 == (address >> 16))
address &= 0xFF00FF;
// read block to send to wii
m_register.Read( address, block, size );
switch (address >> 16)
{
// speaker
case 0xa2 :
//PanicAlert("read from speaker!!");
break;
// extension
case 0xa4 :
{
// Encrypt data read from extension register
// Check if encrypted reads is on
if (0xaa == m_reg_ext->encryption)
wiimote_encrypt(&m_ext_key, block, address & 0xffff, (u8)size);
//if ( address >= 0xa40008 && address < 0xa40020 )
// PanicAlert("Reading extension data from register");
}
break;
// motion plus
case 0xa6 :
{
// emulated motion plus is not yet supported
// return read error
size = 0;
// motion plus crap copied from old wiimote plugin
//block[0xFC] = 0xA6;
//block[0xFD] = 0x20;
//block[0xFE] = 0x00;
//block[0xFF] = 0x05;
}
break;
}
}
break;
default :
PanicAlert("WmReadData: unimplemented parameters (size: %i, addr: 0x%x)!", size, rd->space);
break;
}
// want the requested address, not the above modified one
rr.address = swap24(rd->address);
rr.size = size;
//rr.channel = _channelID;
rr.position = 0;
rr.data = block;
// send up to 16 bytes
SendReadDataReply(rr);
// if there is more data to be sent, add it to the queue
if (rr.size)
m_read_requests.push( rr );
else
delete[] rr.data;
}
// old comment
/* Here we produce the actual 0x21 Input report that we send to the Wii. The
message is divided into 16 bytes pieces and sent piece by piece. There will
be five formatting bytes at the begging of all reports. A common format is
00 00 f0 00 20, the 00 00 means that no buttons are pressed, the f means 16
bytes in the message, the 0 means no error, the 00 20 means that the message
is at the 00 20 offest in the registry that was read.
*/
void Wiimote::SendReadDataReply(ReadRequest& _request)
{
u8 data[23];
data[0] = 0xA1;
data[1] = WM_READ_DATA_REPLY;
wm_read_data_reply* const reply = (wm_read_data_reply*)(data + 2);
reply->buttons = m_status.buttons;
reply->address = Common::swap16(_request.address);
// generate a read error
// Out of bounds. The real Wiimote generate an error for the first
// request to 0x1770 if we dont't replicate that the game will never
// read the calibration data at the beginning of Eeprom. I think this
// error is supposed to occur when we try to read above the freely
// usable space that ends at 0x16ff.
if (0 == _request.size)
{
reply->size = 0x0f;
reply->error = 0x08;
memset(reply->data, 0, sizeof(reply->data));
}
else
{
// Limit the amt to 16 bytes
// AyuanX: the MTU is 640B though... what a waste!
const int amt = std::min( (unsigned int)16, _request.size );
// no error
reply->error = 0;
// 0x1 means two bytes, 0xf means 16 bytes
reply->size = amt - 1;
// Clear the mem first
memset(reply->data, 0, sizeof(reply->data));
// copy piece of mem
memcpy(reply->data, _request.data + _request.position, amt);
// update request struct
_request.size -= amt;
_request.position += amt;
_request.address += amt;
}
// Send a piece
Core::Callback_WiimoteInterruptChannel(m_index, m_reporting_channel, data, sizeof(data));
}
void Wiimote::DoState(PointerWrap& p)
{
// not working :(
//if (p.MODE_READ == p.GetMode())
//{
// // LOAD
// Reset(); // should cause a status report to be sent, then wii should re-setup wiimote
//}
//p.Do(m_reporting_channel);
}
}

View file

@ -0,0 +1,295 @@
// Copyright (C) 2003 Dolphin Project.
// Copyright (C) Hector Martin "marcan" (hector@marcansoft.com)
// 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 "Common.h"
#include "Encryption.h"
static const u8 ans_tbl[7][6] = {
{0xA8,0x77,0xA6,0xE0,0xF7,0x43},
{0x5A,0x35,0x85,0xE2,0x72,0x97},
{0x8F,0xB7,0x1A,0x62,0x87,0x38},
{ 0xD,0x67,0xC7,0xBE,0x4F,0x3E},
{0x20,0x76,0x37,0x8F,0x68,0xB7},
{0xA9,0x26,0x3F,0x2B,0x10,0xE3},
{0x30,0x7E,0x90, 0xE,0x85, 0xA},
};
static const u8 tsbox[256] = {
0x70,0x51, 3,0x86,0x40, 0xD,0x4F,0xEB,0x3E,0xCC,0xD1,0x87,0x35,0xBD,0xF5, 0xB,
0x5E,0xD0,0xF8,0xF2,0xD5,0xE2,0x6C,0x31, 0xC,0xAD,0xFC,0x21,0xC3,0x78,0xC1, 6,
0xC2,0x4C,0x55,0xE6,0x4A,0x34,0x48,0x11,0x1E,0xDA,0xE7,0x1A,0x84,0xA0,0x96,0xA7,
0xE3,0x7F,0xAF,0x63,0x9C,0xFA,0x23,0x5B,0x79,0xC8,0x9E,0xBA,0xB2,0xC9,0x22,0x12,
0x4B,0xB3,0xA1,0xB6,0x32,0x49,0xA2,0xE1,0x89,0x39,0x10,0x66,0xC5, 7,0x8F,0x54,
0xEA,0x91,0xCA,0x3F,0xF9,0x19,0xF0,0xD7,0x46,0xBC,0x28,0x1B,0x61,0xE8,0x2F,0x6A,
0xAE,0x9D,0xF6,0x4E, 9,0x14,0x77,0x4D,0xDB,0x1F,0x2E,0x7B,0x7C,0xF1,0x43,0xA3,
0,0xB8,0x13,0x8C,0x85,0xB9,0x29,0x75,0x88,0xFD,0xD2,0x56,0x1C,0x50,0x97,0x41,
0xE5,0x3B,0x60,0xB5,0xC0,0x64,0xEE,0x98,0xD6,0x2D,0x25,0xA4,0xAA,0xCD,0x7D,0xA8,
0x83,0xC6,0xAB,0xBE,0x44,0x99,0x26,0x3C,0xCE,0x9F,0xBF,0xD3,0xCB,0x76,0x7A,0x7E,
0x82, 1,0x8A,0x9A,0x80,0x1D, 0xE,0xB0,0x5C,0xD4,0x38,0x62,0xF4,0x30,0xE0,0x8E,
0x53,0xB7, 2,0x57,0xAC,0xA6,0x52, 0xA,0x6D,0x92,0x65,0x17,0x24,0x33,0x45,0x72,
0x74,0xB1,0xB4,0xF7,0x5D,0xED,0x2C,0xFF,0x47,0x37,0x5A,0x90,0xBB,0xDF,0x2A,0x16,
0x59,0x95,0xD9,0xC4,0x27,0x67,0x73,0xC7,0x68,0xFE,0xA5,0xDD,0x6B,0x5F,0x93,0xD8,
0xEC, 5,0x3A,0x8D,0x6E,0xFB,0x3D,0xA9,0x69,0x36,0xF3,0x94,0xDE,0xEF,0x15,0x6F,
0x8B,0x9B, 8, 0xF,0xDC,0x81,0x18,0x20, 4,0xE4,0x71,0xCF,0xE9,0x2B,0x42,0x58,
};
static const u8 sboxes[8][256] = {
{
1,0xA0,0xA9,0x62,0xD6,0x3F,0x85,0xA7,0xB6,0xD4,0xFA,0x15,0x66,0x17, 9,0xBD,
0x5D,0x14,0x34,0x26,0x59,0x72,0x91,0x54, 6,0x4F,0xF8,0xB0,0x5B,0x74,0x93,0x99,
0x8C,0xF2,0x45,0xCD,0xEA,0x4E,0xAD,0x10,0x4A,0xE5,0xCA,0xEE,0xDF,0xC6,0x6F,0x9F,
0x88,0x8E, 2,0xCC, 8,0xA8,0x77,0x94,0x6D,0x21,0xB1,0x28,0xE4,0x39,0x79,0x96,
0x60,0x71,0x81,0x16,0x2E,0xE6,0x78,0xB9,0xC4,0x46,0x9A,0x42,0xAE,0xB7,0x7C,0x43,
0xB3,0x22,0x1A,0x86,0xC2,0x32,0x3D,0x2D,0x9C,0xD2,0x29,0xE9,0x63,0x9B,0xD1,0x31,
0x38,0x5E,0x1E,0x36,0x41,0xBB, 3,0x18,0x2B,0x3E,0xBF,0x68,0x61,0xFC,0x52,0xC0,
0xDE,0xE0, 0xA,0x58,0x13,0x5A, 0,0xBE,0x1C,0x90, 0xE,0x53,0x12,0xFD,0xE2,0x6E,
0xBA,0xCE,0x24,0x27,0x44,0x7F,0x87,0xA3,0xA1,0xD5,0x50,0x40,0xE3,0xF9,0x83,0xF7,
0xC7,0xA2,0x35,0xC8,0xDB,0x19,0xAB,0x2F,0x11,0x25,0xED,0x33,0x9E,0x55,0xE1,0x48,
0xAF,0x73,0x84,0xDA,0x2A,0xAA,0x51,0xEB,0x9D,0x95,0xB2,0xCB,0xE7,0x70,0x80,0xFE,
0x4C,0x65, 4,0xEF,0xC5,0xF1,0xC3,0x3A,0xB4,0xF5,0x5F,0x23,0x89,0xDD,0x30,0xA5,
0x8B,0xD3,0xF6,0xDC,0x4D,0x64,0xD7,0xF0,0x8F,0xEC,0x56,0x37,0x5C,0xA4, 0xD, 7,
0x76,0x8A,0x2C, 0xB,0xB5,0xD8,0xC1,0x1F,0xE8,0x3B,0xF4,0x4B,0x1B,0x47,0x6C,0x49,
0x67,0x7B,0x92,0xCF,0x75,0x7E,0x20,0xD9,0x7D,0x3C,0x97,0x7A,0xD0, 5,0x6B, 0xF,
0x1D,0xFB,0x82,0x98,0x57,0x8D,0xF3,0x6A,0xBC,0xAC,0xC9,0xA6,0xFF,0xB8,0x69, 0xC,
},
{
0x4C,0x4D,0x72, 7,0x5A,0x49,0x33,0x8D,0xA2,0xAB,0x46,0x3D,0x63, 0xD,0xA0,0x97,
0xFF,0xF0,0xF5,0xFA,0xC0,0xE9,0xDB,0x62,0xE4,0xE1,0x74,0x43,0xDC,0x86,0x18,0x29,
0x37,0xF4, 6,0xE2,0xED,0x6F,0x90,0x48,0x1E,0x2D,0x1D,0xEA,0x73,0x94,0x54,0xDF,
0x25,0xF6,0x47,0x27,0xD9,0x11,0x77,0xC9,0x84,0x1C,0x5B,0x5C,0x51,0x81,0xA6,0x22,
0x3E,0x24,0x96,0xC8,0x8A,0xEC,0x82,0x7C, 9,0xB8,0x45,0x4A,0x57,0xBB,0x2F,0x50,
0x75,0x8E,0x61,0x70,0x8C,0x6C,0xAF,0xD0,0xFD,0xB4,0x1B,0xAE,0xDE,0xFE,0x3B,0xB5,
0x36,0xBD,0x55, 1, 0xE,0x9C,0x41,0x56,0x5F,0xB3,0x26, 3,0x83,0xBA,0x13,0x4B,
0xCA,0xC5, 0xA,0xF8,0x60,0xA5,0xB9,0xC7,0xC3,0x98,0x32,0xFB,0x12,0xF9,0xA7,0x92,
0xAA,0x68,0xF3,0x78,0x7E, 5,0x20,0x21, 2,0xE8,0xBF,0xF2,0xB0,0x59,0x8F,0xD2,
0xCB,0x87,0x65,0x15,0xF1,0x1A,0xB2,0x30,0xAD,0xEE,0x58,0xA3,0x8B,0x66,0x1F,0x2C,
0xD7,0x5D,0x19,0x85,0xA8,0xE6,0xD3,0x6B,0xA1, 0xC,0x91,0x93,0x6A,0x5E, 0xB,0x79,
0xE3,0xDD, 0,0x4F,0x3C,0x89,0x6E,0x71,0x69,0xA9,0xAC,0x40,0xE5,0x99,0x28,0xC6,
0x31,0x4E,0x7A,0xCD, 8,0x9E,0x7D,0xEF,0x17,0xFC,0x88,0xD8,0xA4,0x6D,0x44,0x95,
0xD1,0xB7,0xD4,0x9B,0xBE,0x2A,0x34,0x64,0x2B,0xCF,0x2E,0xEB,0x38,0xCE,0x23,0xE0,
0x3A,0x3F,0xF7,0x7B,0x9F,0x10,0x53,0xBC,0x52,0x67,0x16,0xE7,0x80,0x76, 4,0xC4,
0xB6,0xC1,0xC2,0x7F,0x9A,0xDA,0xD5,0x39,0x42,0x14,0x9D,0xB1, 0xF,0x35,0xD6,0xCC,
},
{
0xB9,0xDA,0x38, 0xC,0xA2,0x9C, 9,0x1F, 6,0xB1,0xB6,0xFD,0x1A,0x69,0x23,0x30,
0xC4,0xDE, 1,0xD1,0xF4,0x58,0x29,0x37,0x1C,0x7D,0xD5,0xBF,0xFF,0xBD,0xC8,0xC9,
0xCF,0x65,0xBE,0x7B,0x78,0x97,0x98,0x67, 8,0xB3,0x26,0x57,0xF7,0xFA,0x40,0xAD,
0x8E,0x75,0xA6,0x7C,0xDB,0x91,0x8B,0x51,0x99,0xD4,0x17,0x7A,0x90,0x8D,0xCE,0x63,
0xCB,0x4E,0xA0,0xAB,0x18,0x3A,0x5B,0x50,0x7F,0x21,0x74,0xC1,0xBB,0xB8,0xB7,0xBA,
0xB,0x35,0x95,0x31,0x59,0x9A,0x4D, 4, 7,0x1E,0x5A,0x76,0x13,0xF3,0x71,0x83,
0xD0,0x86, 3,0xA8,0x39,0x42,0xAA,0x28,0xE6,0xE4,0xD8,0x5D,0xD3,0xD0,0x6E,0x6F,
0x96,0xFB,0x5E,0xBC,0x56,0xC2,0x5F,0x85,0x9B,0xE7,0xAF,0xD2,0x3B,0x84,0x6A,0xA7,
0x53,0xC5,0x44,0x49,0xA5,0xF9,0x36,0x72,0x3D,0x2C,0xD9,0x1B,0xA1,0xF5,0x4F,0x93,
0x9D,0x68,0x47,0x41,0x16,0xCA,0x2A,0x4C,0xA3,0x87,0xD6,0xE5,0x19,0x2E,0x77,0x15,
0x6D,0x70,0xC0,0xDF,0xB2, 0,0x46,0xED,0xC6,0x6C,0x43,0x60,0x92,0x2D,0xA9,0x22,
0x45,0x8F,0x34,0x55,0xAE,0xA4, 0xA,0x66,0x32,0xE0,0xDC, 2,0xAC,0xE8,0x20,0x8C,
0x89,0x62,0x4A,0xFE,0xEE,0xC3,0xE3,0x3C,0xF1,0x79, 5,0xE9,0xF6,0x27,0x33,0xCC,
0xF2,0x9E,0x11,0x81,0x7E,0x80,0x10,0x8A,0x82,0x9F,0x48, 0xD,0xD7,0xB4,0xFC,0x2F,
0xB5,0xC7,0xDD,0x88,0x14,0x6B,0x2B,0x54,0xEA,0x1D,0x94,0x5C,0xB0,0xEF,0x12,0x24,
0xCD,0xEB,0xE1,0xE2,0x64,0x73,0x3F, 0xE,0x52,0x61,0x25,0x3E,0xF8, 0xF,0x4B,0xEC,
},
{
0xC0, 0,0x30,0xF6, 2,0x49,0x3D,0x10,0x6E,0x20,0xC9,0xA6,0x2F,0xFE,0x2C,0x2B,
0x75,0x2E,0x45,0x26,0xAB,0x48,0xA9,0x80,0xFC, 4,0xCC,0xD3,0xB5,0xBA,0xA3,0x38,
0x31,0x7D, 1,0xD9,0xA7,0x7B,0x96,0xB6,0x63,0x69,0x4E,0xF7,0xDE,0xE0,0x78,0xCA,
0x50,0xAA,0x41,0x91,0x65,0x88,0xE4,0x21,0x85,0xDA,0x3A,0x27,0xBE,0x1C,0x3E,0x42,
0x5E,0x17,0x52,0x7F,0x1F,0x89,0x24,0x6F,0x8F,0x5C,0x67,0x74, 0xE,0x12,0x87,0x8D,
0xE9,0x34,0xED,0x73,0xC4,0xF8,0x61,0x5B, 5,0xDF,0x59,0x4C,0x97,0x79,0x83,0x18,
0xA4,0x55,0x95,0xEB,0xBD,0x53,0xF5,0xF1,0x57,0x66,0x46,0x9F,0xB2,0x81, 9,0x51,
0x86,0x22,0x16,0xDD,0x23,0x93,0x76,0x29,0xC2,0xD7,0x1D,0xD4,0xBF,0x36,0x3F,0xEA,
0x4B,0x11,0x32,0xB9,0x62,0x54,0x60,0xD6,0x6D,0x43,0x9A, 0xD,0x92,0x9C,0xB0,0xEF,
0x58,0x6C,0x9D,0x77,0x2D,0x70,0xFA,0xF3,0xB3, 0xB,0xE2,0x40,0x7E,0xF4,0x8A,0xE5,
0x8C,0x3C,0x56,0x71,0xD1,0x64,0xE1,0x82, 0xA,0xCB,0x13,0x15,0x90,0xEC, 3,0x99,
0xAF,0x14,0x5D, 0xF,0x33,0x4A,0x94,0xA5,0xA8,0x35,0x1B,0xE3,0x6A,0xC6,0x28,0xFF,
0x4D,0xE7,0x25,0x84,0xAC, 8,0xAE,0xC5,0xA2,0x2A,0xB8,0x37, 0xC,0x7A,0xA0,0xC3,
0xCE,0xAD, 6,0x1A,0x9E,0x8B,0xFB,0xD5,0xD0,0xC1,0x1E,0xD0,0xB4,0x9B,0xB1,0x44,
0xF2,0x47,0xC7,0x68,0xCF,0x72,0xBB,0x4F,0x5A,0xF9,0xDC,0x6B,0xDB,0xD2,0xE8,0x7C,
0xC8,0xEE,0x98,0xA1,0xE6,0xD8,0x39, 7,0x5F,0xFD,0x8E,0x19,0xB7,0x3B,0xBC,0xCD,
},
{
0x7C,0xE3,0x81,0x73,0xB2,0x11,0xBF,0x6F,0x20,0x98,0xFE,0x75,0x96,0xEF,0x6C,0xDA,
0x50,0xE1, 9,0x72,0x54,0x45,0xBA,0x34,0x80,0x5B,0xED,0x3E,0x53,0x2C,0x87,0xA4,
0x57,0xF3,0x33,0x3F,0x3C,0xB7,0x67,0xB4,0xA3,0x25,0x60,0x4F, 7,0x6B,0x1B,0x47,
0x15, 0xF,0xE4, 0xA,0xEA,0xD1,0x32,0x78,0x36,0x49,0x8D,0x4B,0xD2,0xBC,0xA5,0xDC,
0x1D, 0xD,0x4D,0xCD,0x9A,0x82,0x5F,0xFC,0x94,0x65,0xBE,0xE2,0xF4,0xC9,0x1E,0x44,
0xCB,0x9E, 0xC,0x64,0x71,0x26,0x63,0xB3,0x14,0xE8,0x40,0x70,0x8A, 0xE,0x19,0x42,
0x6D,0xAC,0x88,0x10,0x5C,0xDF,0x41,0xA9,0xAD,0xE5,0xFB,0x74,0xCC,0xD5, 6,0x8E,
0x59,0x86,0xCE,0x1F,0x3D,0x76,0xE0,0x8F,0xB9,0x77,0x27,0x7B,0xA6,0xD8,0x29,0xD3,
0xEC,0xB8,0x13,0xF7,0xFA,0xC3,0x51,0x6A,0xDE,0x4A,0x5A,0xEB,0xC2,0x8B,0x23,0x48,
0x92,0xCF,0x62,0xA8,0x99,0xF8,0xD0,0x2E,0x85,0x61,0x43,0xC8,0xBD,0xF0, 5,0x93,
0xCA,0x4E,0xF1,0x7D,0x30,0xFD,0xC4,0x69,0x66,0x2F, 8,0xB1,0x52,0xF9,0x21,0xE6,
0x7A,0x2B,0xDD,0x39,0x84,0xFF,0xC0,0x91,0xD6,0x37,0xD4,0x7F,0x2D,0x9B,0x5D,0xA1,
0x3B,0x6E,0xB5,0xC5,0x46, 4,0xF5,0x90,0xEE,0x7E,0x83,0x1C, 3,0x56,0xB6,0xAA,
0,0x17, 1,0x35,0x55,0x79, 0xB,0x12,0xBB,0x1A,0x31,0xE7, 2,0x28,0x16,0xC1,
0xF6,0xA2,0xDB,0x18,0x9C,0x89,0x68,0x38,0x97,0xAB,0xC7,0x2A,0xD7,0x3A,0xF2,0xC6,
0x24,0x4C,0xB0,0x58,0xA0,0x22,0x5E,0x9D,0xD9,0xA7,0xE9,0xAE,0xAF,0x8C,0x95,0x9F,
},
{
0x28,0xB7,0x20,0xD7,0xB0,0x30,0xC3, 9,0x19,0xC0,0x67,0xD6, 0,0x3C,0x7E,0xE7,
0xE9,0xF4, 8,0x5A,0xF8,0xB8,0x2E, 5,0xA6,0x25,0x9E,0x5C,0xD8,0x15, 0xD,0xE1,
0xF6,0x11,0x54,0x6B,0xCD,0x21,0x46,0x66,0x5E,0x84,0xAD, 6,0x38,0x29,0x44,0xC5,
0xA2,0xCE,0xF1,0xAA,0xC1,0x40,0x71,0x86,0xB5,0xEF,0xFC,0x36,0xA8,0xCB, 0xA,0x48,
0x27,0x45,0x64,0xA3,0xAF,0x8C,0xB2,0xC6,0x9F, 7,0x89,0xDC,0x17,0xD3,0x49,0x79,
0xFB,0xFE,0x1D,0xD0,0xB9,0x88,0x43,0x52,0xBC, 1,0x78,0x2B,0x7D,0x94,0xC7, 0xE,
0xDE,0xA5,0xD5,0x9B,0xCC,0xF7,0x61,0x7A,0xC2,0x74,0x81,0x39, 3,0xAB,0x96,0xA0,
0x37,0xBD,0x2D,0x72,0x75,0x3F,0xC9,0xD4,0x8E,0x6F,0xF9,0x8D,0xED,0x62,0xDB,0x1C,
0xDF, 4,0xAC,0x1B,0x6C,0x14,0x4B,0x63,0xD0,0xBF,0xB4,0x82,0xEC,0x7B,0x1A,0x59,
0x92,0xD2,0x10,0x60,0xB6,0x3D,0x5F,0xE6,0x80,0x6E,0x70,0xC4,0xF2,0x35,0xD9,0x7C,
0xEE,0xE5,0x41,0xA4,0x5B,0x50,0xDD,0xBB,0x4C,0xF3,0x1F,0x9D,0x5D,0x57,0x55,0x51,
0x97,0xE3,0x58,0x42,0x4D,0x9C,0x73,0xBA,0xC8,0x77,0x31,0x69,0x26,0xAE,0xEA,0x8A,
0xDA,0x22,0xB3,0x87,0x56,0xFA,0x93, 0xB,0x34,0x16,0x33,0xE8,0xE4,0x53,0xBE,0xA9,
0xB1,0x3A,0x3E,0xF5,0x90,0x6A,0xCF,0x3B,0x12,0xFD,0x8F,0x9A,0xA7,0x47,0x91,0x99,
0xEB, 0xF,0x24,0xFF,0x23,0x18,0x85,0x4E,0x7F, 0xC,0xE0,0xA1,0xD2,0xD1,0x2C,0x2A,
0x4A, 2,0x4F,0x1E,0x95,0x68,0x8B,0x98,0x83,0x6D,0x76,0xCA,0x65,0x32,0x13,0x2F,
},
{
0xC3,0x82,0x9A,0xA4,0xBA,0x81,0x60,0x37,0x34,0x35,0xFC,0x80,0xA8,0x51,0x65,0x67,
0xED,0x30,0x5F,0x10,0xD3,0x4A,0x27,0x2F,0x13,0xB9,0x2A,0xD2,0xCC,0xE1,0xEF,0xAE,
0xEB,0xBE,0xF4,0xBD,0xCF,0x43,0xB3,0xC5,0x88,0x84,0xB7,0xDD,0x39,0x40,0xCE,0x48,
0x6D,0x9B,0x72,0x61,0x7E,0xE7,0xA1,0x4E,0x53,0x2E,0x77,0x3B,0xE2,0xC9,0x36,0x22,
0x1B,0x6E,0x73,0xB1, 3,0xB2,0x4C,0x87,0xA9,0xD4,0x4D, 0xF,0xD8,0x15,0x6C,0xAA,
0x18,0xF6,0x49,0x57,0x5D,0xFB,0x7A,0x14,0x94,0x63,0xA0,0x11,0xB0,0x9E,0xDE, 5,
0x46,0xC8,0xEE,0x47,0xDB,0xDC,0x24,0x89,0x9C,0x91,0x97,0x29,0xE9,0x7B,0xC1, 7,
0x1E,0xB8,0xFD,0xFE,0xAC,0xC6,0x62,0x98,0x4F,0xF1,0x79,0xE0,0xE8,0x6B,0x78,0x56,
0xB6,0x8D, 4,0x50,0x86,0xCA,0x6F,0x20,0xE6,0xEA,0xE5,0x76,0x17,0x1C,0x74,0x7F,
0xBC, 0xD,0x2C,0x85,0xF7,0x66,0x96,0xE4,0x8B,0x75,0x3F,0x4B,0xD9,0x38,0xAF,0x7C,
0xDA, 0xB,0x83,0x2D,0x31,0x32,0xA2,0xF5,0x1D,0x59,0x41,0x45,0xBF,0x3C,0x1F,0xF8,
0xF9,0x8A,0xD0,0x16,0x25,0x69,0x12,0x99,0x9D,0x21,0x95,0xAB, 1,0xA6,0xD7,0xB5,
0xC0,0x7D,0xFF,0x58, 0xE,0x3A,0x92,0xD1,0x55,0xE3, 8,0x9F,0xD6,0x3E,0x52,0x8E,
0xFA,0xA3,0xC7, 2,0xCD,0xDF,0x8F,0x64,0x19,0x8C,0xF3,0xA7, 0xC,0x5E, 0xA,0x6A,
9,0xF0,0x93,0x5B,0x42,0xC2, 6,0x23,0xEC,0x71,0xAD,0xB4,0xCB,0xBB,0x70,0x28,
0xD5,0x1A,0x5C,0x33,0x68,0x5A, 0,0x44,0x90,0xA5,0xC4,0x26,0x3D,0x2B,0xF2,0x54,
},
{
0x96,0xAD,0xDA,0x1F,0xED,0x33,0xE1,0x81,0x69, 8, 0xD, 0xA,0xDB,0x35,0x77,0x9A,
0x64,0xD1,0xFC,0x78,0xAA,0x1B,0xD0,0x67,0xA0,0xDD,0xFA,0x6C,0x63,0x71, 5,0x84,
0x17,0x6A,0x89,0x4F,0x66,0x7F,0xC6,0x50,0x55,0x92,0x6F,0xBD,0xE7,0xD2,0x40,0x72,
0x8D,0xBB,0xEC, 6,0x42,0x8A,0xE4,0x88,0x9D,0x7E,0x7A,0x82,0x27,0x13,0x41,0x1A,
0xAF,0xC8,0xA4,0x76,0xB4,0xC2,0xFE,0x6D,0x1C,0xD9,0x61,0x30,0xB3,0x7C,0xEA,0xF7,
0x29, 0xF,0xF2,0x3B,0x51,0xC1,0xDE,0x5F,0xE5,0x2A,0x2F,0x99, 0xB,0x5D,0xA3,0x2B,
0x4A,0xAB,0x95,0xA5,0xD3,0x58,0x56,0xEE,0x28,0x31, 0,0xCC,0x15,0x46,0xCA,0xE6,
0x86,0x38,0x3C,0x65,0xF5,0xE3,0x9F,0xD6,0x5B, 9,0x49,0x83,0x70,0x2D,0x53,0xA9,
0x7D,0xE2,0xC4,0xAC,0x8E,0x5E,0xB8,0x25,0xF4,0xB9,0x57,0xF3,0xF1,0x68,0x47,0xB2,
0xA2,0x59,0x20,0xCE,0x34,0x79,0x5C,0x90, 0xE,0x1E,0xBE,0xD5,0x22,0x23,0xB1,0xC9,
0x18,0x62,0x16,0x2E,0x91,0x3E, 7,0x8F,0xD8,0x3F,0x93,0x3D,0xD4,0x9B,0xDF,0x85,
0x21,0xFB,0x11,0x74,0x97,0xC7,0xD7,0xDC,0x4C,0x19,0x45,0x98,0xE9,0x43, 2,0x4B,
0xBC,0xC3, 4,0x9C,0x6B,0xF0,0x75,0x52,0xA7,0x26,0xF6,0xC5,0xBA,0xCF,0xB0,0xB7,
0xAE,0x5A,0xA1,0xBF, 3,0x8B,0x80,0x12,0x6E, 0xC,0xEB,0xF9,0xC0,0x44,0x24,0xEF,
0x10,0xF8,0xA8,0x8C,0xE8,0x7B,0xFF,0x9E,0x2C,0xCD,0x60,0x36,0x87,0xB5,0x94,0xA6,
0x54,0x73,0x3A,0x14,0x4E, 1,0x1D,0xB6,0xFD,0x37,0x48,0x4D,0x39,0xCB,0xE0,0x32,
}
};
static inline u8 ror8(const u8 a, const u8 b)
{
return (a>>b) | ((a<<(8-b))&0xff);
}
void genkey(const u8* const rand, const u8 idx, u8* const key)
{
const u8* const ans = ans_tbl[idx];
u8 t0[10];
for(int i=0; i<10; ++i)
t0[i] = tsbox[rand[i]];
key[0] = ((ror8((ans[0]^t0[5]),(t0[2]%8)) - t0[9]) ^ t0[4]);
key[1] = ((ror8((ans[1]^t0[1]),(t0[0]%8)) - t0[5]) ^ t0[7]);
key[2] = ((ror8((ans[2]^t0[6]),(t0[8]%8)) - t0[2]) ^ t0[0]);
key[3] = ((ror8((ans[3]^t0[4]),(t0[7]%8)) - t0[3]) ^ t0[2]);
key[4] = ((ror8((ans[4]^t0[1]),(t0[6]%8)) - t0[3]) ^ t0[4]);
key[5] = ((ror8((ans[5]^t0[7]),(t0[8]%8)) - t0[5]) ^ t0[9]);
}
void gentabs(const u8* const rand, const u8* const key, const u8 idx, u8* const ft, u8* const sb)
{
ft[0] = sboxes[idx][key[4]] ^ sboxes[(idx+1)%8][rand[3]];
ft[1] = sboxes[idx][key[2]] ^ sboxes[(idx+1)%8][rand[5]];
ft[2] = sboxes[idx][key[5]] ^ sboxes[(idx+1)%8][rand[7]];
ft[3] = sboxes[idx][key[0]] ^ sboxes[(idx+1)%8][rand[2]];
ft[4] = sboxes[idx][key[1]] ^ sboxes[(idx+1)%8][rand[4]];
ft[5] = sboxes[idx][key[3]] ^ sboxes[(idx+1)%8][rand[9]];
ft[6] = sboxes[idx][rand[0]] ^ sboxes[(idx+1)%8][rand[6]];
ft[7] = sboxes[idx][rand[1]] ^ sboxes[(idx+1)%8][rand[8]];
sb[0] = sboxes[idx][key[0]] ^ sboxes[(idx+1)%8][rand[1]];
sb[1] = sboxes[idx][key[5]] ^ sboxes[(idx+1)%8][rand[4]];
sb[2] = sboxes[idx][key[3]] ^ sboxes[(idx+1)%8][rand[0]];
sb[3] = sboxes[idx][key[2]] ^ sboxes[(idx+1)%8][rand[9]];
sb[4] = sboxes[idx][key[4]] ^ sboxes[(idx+1)%8][rand[7]];
sb[5] = sboxes[idx][key[1]] ^ sboxes[(idx+1)%8][rand[8]];
sb[6] = sboxes[idx][rand[3]] ^ sboxes[(idx+1)%8][rand[5]];
sb[7] = sboxes[idx][rand[2]] ^ sboxes[(idx+1)%8][rand[6]];
}
/* Generate key from the 0x40-0x4c data in g_RegExt */
void wiimote_gen_key(wiimote_key* const key, const u8* const keydata)
{
u8 rand[10];
u8 skey[6];
u8 testkey[6];
int idx;
for (int i=0; i<10; ++i)
rand[9-i] = keydata[i];
for (int i=0; i<6; ++i)
skey[5-i] = keydata[i+10];
//DEBUG_LOG(WIIMOTE, "rand: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", rand[0], rand[1], rand[2], rand[3], rand[4], rand[5], rand[6], rand[7], rand[8], rand[9]);
//DEBUG_LOG(WIIMOTE, "key: %02x %02x %02x %02x %02x %02x", skey[0], skey[1], skey[2], skey[3], skey[4], skey[5]);
for(idx = 0; idx < 7; ++idx)
{
genkey(rand, idx, testkey);
if (0 == memcmp(testkey, skey, 6))
break;
}
// default case is idx = 7 which is valid (homebrew uses it for the 0x17 case)
//DEBUG_LOG(WIIMOTE, "idx: %d", idx);
gentabs(rand, skey, idx, key->ft, key->sb);
//DEBUG_LOG(WIIMOTE, "ft: %02x %02x %02x %02x %02x %02x %02x %02x", key->ft[0], key->ft[1], key->ft[2], key->ft[3], key->ft[4], key->ft[5], key->ft[6], key->ft[7]);
//DEBUG_LOG(WIIMOTE, "sb: %02x %02x %02x %02x %02x %02x %02x %02x", key->sb[0], key->sb[1], key->sb[2], key->sb[3], key->sb[4], key->sb[5], key->sb[6], key->sb[7]);
// for homebrew, ft and sb are all 0x97 which is equivalent to 0x17
}
// TODO: is there a reason these can only handle a length of 255?
/* Encrypt data */
void wiimote_encrypt(const wiimote_key* const key, u8* const data, int addr, const u8 len)
{
for (int i = 0; i < len; ++i, ++addr)
data[i] = (data[i] - key->ft[addr % 8]) ^ key->sb[addr % 8];
}
/* Decrypt data */
void wiimote_decrypt(const wiimote_key* const key, u8* const data, int addr, const u8 len)
{
for (int i = 0; i < len; ++i, ++addr)
data[i] = (data[i] ^ key->sb[addr % 8]) + key->ft[addr % 8];
}

View file

@ -1,4 +1,5 @@
// Copyright (C) 2003 Dolphin Project.
// Copyright (C) Hector Martin "marcan" (hector@marcansoft.com)
// 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
@ -15,39 +16,26 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#ifndef _DIRECTINPUTBASE_H
#define _DIRECTINPUTBASE_H
#ifndef WIIMOTE_EXTENSION_ENCRYPTION_H
#define WIIMOTE_EXTENSION_ENCRYPTION_H
#include <windows.h> // System
#include <stdio.h>
#define DIRECTINPUT_VERSION 0x0800 // DirectInput
#include <dinput.h>
class DInput
// ===================================================
/* They key structure to use with wiimote_gen_key() */
// ----------------
struct wiimote_key
{
public:
DInput();
~DInput();
static void DInput::DIKToString(unsigned int keycode, char *keyStr);
HRESULT Init(HWND hWnd);
void Free();
HRESULT Read();
BYTE diks[256]; // DirectInput keyboard state buffer
private:
LPDIRECTINPUT8 g_pDI; // The DirectInput object
LPDIRECTINPUTDEVICE8 g_pKeyboard; // The keyboard device
u8 ft[8];
u8 sb[8];
};
void wiimote_encrypt(const wiimote_key* const key, u8* const data, int addr, const u8 len);
void wiimote_decrypt(const wiimote_key* const key, u8* const data, int addr, const u8 len);
void wiimote_gen_key(wiimote_key* const key, const u8* const keydata);
#endif

View file

@ -0,0 +1,89 @@
#ifndef MATRIXMATH_H
#define MATRIXMATH_H
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
typedef double Matrix[4][4];
typedef struct
{
double x,y,z;
} Vertex;
inline void MatrixIdentity(Matrix & m)
{
m[0][0]=1; m[0][1]=0; m[0][2]=0; m[0][3]=0;
m[1][0]=0; m[1][1]=1; m[1][2]=0; m[1][3]=0;
m[2][0]=0; m[2][1]=0; m[2][2]=1; m[2][3]=0;
m[3][0]=0; m[3][1]=0; m[3][2]=0; m[3][3]=1;
}
inline void MatrixFrustum(Matrix &m, double l, double r, double b, double t, double n, double f)
{
m[0][0]=2*n/(r-l); m[0][1]=0; m[0][2]=0; m[0][3]=0;
m[1][0]=0; m[1][1]=2*n/(t-b); m[1][2]=0; m[1][3]=0;
m[2][0]=(r+l)/(r-l); m[2][1]=(t+b)/(t-b); m[2][2]=(f+n)/(f-n); m[2][3]=-1;
m[3][0]=0; m[3][1]=0; m[3][2]=2*f*n/(f-n); m[3][3]=0;
}
inline void MatrixPerspective(Matrix & m, double fovy, double aspect, double nplane, double fplane)
{
double xmin, xmax, ymin, ymax;
ymax = nplane * tan(fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
MatrixFrustum(m,xmin,xmax,ymin,ymax,nplane,fplane);
}
inline void MatrixRotationByZ(Matrix &m, double sin, double cos)
{
m[0][0]=cos; m[0][1]=-sin; m[0][2]=0; m[0][3]=0;
m[1][0]=sin; m[1][1]=cos; m[1][2]=0; m[1][3]=0;
m[2][0]=0; m[2][1]=0; m[2][2]=1; m[2][3]=0;
m[3][0]=0; m[3][1]=0; m[3][2]=0; m[3][3]=1;
}
inline void MatrixScale(Matrix &m, double xfact, double yfact, double zfact)
{
m[0][0]=xfact; m[0][1]=0; m[0][2]=0; m[0][3]=0;
m[1][0]=0; m[1][1]=yfact; m[1][2]=0; m[1][3]=0;
m[2][0]=0; m[2][1]=0; m[2][2]=zfact; m[2][3]=0;
m[3][0]=0; m[3][1]=0; m[3][2]=0; m[3][3]=1;
}
inline void MatrixMultiply(Matrix &r, const Matrix &a, const Matrix &b)
{
for (int i=0; i<16; i++)
r[i>>2][i&3]=0.0f;
for (int i=0; i<4; i++)
for (int j=0; j<4; j++)
for (int k=0; k<4; k++)
r[i][j]+=a[i][k]*b[k][j];
}
inline void MatrixTransformVertex(Matrix const & m, Vertex & v)
{
Vertex ov;
double w;
ov.x=v.x;
ov.y=v.y;
ov.z=v.z;
v.x = m[0][0] * ov.x + m[0][1] * ov.y + m[0][2] * ov.z + m[0][3];
v.y = m[1][0] * ov.x + m[1][1] * ov.y + m[1][2] * ov.z + m[1][3];
v.z = m[2][0] * ov.x + m[2][1] * ov.y + m[2][2] * ov.z + m[2][3];
w = m[3][0] * ov.x + m[3][1] * ov.y + m[3][2] * ov.z + m[3][3];
if (w!=0)
{
v.x/=w;
v.y/=w;
v.z/=w;
}
}
#endif

View file

@ -0,0 +1,38 @@
#include "WiimoteEmu.h"
#ifdef USE_WIIMOTE_EMU_SPEAKER
namespace WiimoteEmu
{
void Wiimote::SpeakerData(wm_speaker_data* sd)
{
SoundBuffer sb;
sb.samples = new s16[sd->length * 2];
s16* s = sb.samples;
const u8* const e = sd->data + sd->length;
for ( const u8* i = sd->data; i<e; ++i )
{
*s++ = NGCADPCM::ADPDecodeSample(*i & 0x0F, sd->data[0] & 0x0F, &m_channel_status.hist1p, &m_channel_status.hist2p);
*s++ = NGCADPCM::ADPDecodeSample(*i >> 4, sd->data[0] >> 4, &m_channel_status.hist1p, &m_channel_status.hist2p);
}
alGenBuffers(1, &sb.buffer);
// TODO make this not always 3000
alBufferData(sb.buffer, AL_FORMAT_MONO16, sb.samples, (sd->length * sizeof(short) * 2), 3360);
// testing
//alBufferData(sb.buffer, AL_FORMAT_MONO16, sb.samples, (sd->length * sizeof(short) * 2), 48000/m_reg_speaker->sample_rate);
alSourceQueueBuffers(m_audio_source, 1, &sb.buffer);
ALint state;
alGetSourcei(m_audio_source, AL_SOURCE_STATE, &state);
if (AL_PLAYING != state)
alSourcePlay(m_audio_source);
m_audio_buffers.push(sb);
}
}
#endif

View file

@ -0,0 +1,56 @@
//UDP Wiimote Translation Layer
#if (defined(USE_UDP_WIIMOTE) && !defined(UDPTLAYER_H))
#define UDPTLAYER_H
#include "UDPWiimote.h"
#include "WiimoteEmu.h"
using WiimoteEmu::Wiimote;
namespace UDPTLayer
{
void GetButtons(UDPWrapper * m , wm_core * butt)
{
if (!(m->inst)) return;
if (!(m->updButt)) return;
u32 mask=m->inst->getButtons();
*butt|=(mask&UDPWM_BA)?Wiimote::BUTTON_A:0;
*butt|=(mask&UDPWM_BB)?Wiimote::BUTTON_B:0;
*butt|=(mask&UDPWM_B1)?Wiimote::BUTTON_ONE:0;
*butt|=(mask&UDPWM_B2)?Wiimote::BUTTON_TWO:0;
*butt|=(mask&UDPWM_BP)?Wiimote::BUTTON_PLUS:0;
*butt|=(mask&UDPWM_BM)?Wiimote::BUTTON_MINUS:0;
*butt|=(mask&UDPWM_BH)?Wiimote::BUTTON_HOME:0;
*butt|=(mask&UDPWM_BU)?Wiimote::PAD_UP:0;
*butt|=(mask&UDPWM_BD)?Wiimote::PAD_DOWN:0;
*butt|=(mask&UDPWM_BL)?Wiimote::PAD_LEFT:0;
*butt|=(mask&UDPWM_BR)?Wiimote::PAD_RIGHT:0;
}
void GetAcceleration(UDPWrapper * m , WiimoteEmu::AccelData * const data)
{
if (!(m->inst)) return;
if (!(m->updAccel)) return;
float x,y,z;
m->inst->getAccel(x,y,z);
data->x=x;
data->y=y;
data->z=z;
}
void GetIR( UDPWrapper * m, float * x, float * y, float * z)
{
if (!(m->inst)) return;
if (!(m->updIR)) return;
if ((*x>=-0.999)&&(*x<=0.999)&&(*y>=-0.999)&&(*y<=0.999)) return; //the recieved values are used ONLY when the normal pointer is offscreen
float _x,_y;
m->inst->getIR(_x,_y);
*x=_x*2-1;
*y=-(_y*2-1);
*z=0;
}
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,243 @@
#ifndef _CONEMU_WIIMOTE_H_
#define _CONEMU_WIIMOTE_H_
//#define USE_WIIMOTE_EMU_SPEAKER
//#include <Core.h>
//#include <HW/StreamADPCM.h>
// just used to get the OpenAL includes :p
//#include <OpenALStream.h>
#include "../../Core.h"
#include "ControllerEmu.h"
#include "ChunkFile.h"
#include "WiimoteHid.h"
#include "Encryption.h"
#include "UDPWrapper.h"
#include <vector>
#include <queue>
#define PI 3.14159265358979323846
// Registry sizes
#define WIIMOTE_EEPROM_SIZE (16*1024)
#define WIIMOTE_EEPROM_FREE_SIZE 0x1700
#define WIIMOTE_REG_SPEAKER_SIZE 10
#define WIIMOTE_REG_EXT_SIZE 0x100
#define WIIMOTE_REG_IR_SIZE 0x34
namespace WiimoteEmu
{
struct ReportFeatures
{
u8 core, accel, ir, ext, size;
};
struct AccelData
{
double x,y,z;
};
extern const ReportFeatures reporting_mode_features[];
void EmulateShake(AccelData* const accel_data
, ControllerEmu::Buttons* const buttons_group
, unsigned int* const shake_step);
void EmulateTilt(AccelData* const accel
, ControllerEmu::Tilt* const tilt_group
, const bool focus, const bool sideways = false, const bool upright = false);
void EmulateSwing(AccelData* const accel
, ControllerEmu::Force* const tilt_group
, const bool sideways = false, const bool upright = false);
inline double trim(double a)
{
if (a<=0) return 0;
if (a>=255) return 255;
return a;
}
class Wiimote : public ControllerEmu
{
public:
enum
{
PAD_LEFT = 0x01,
PAD_RIGHT = 0x02,
PAD_DOWN = 0x04,
PAD_UP = 0x08,
BUTTON_PLUS = 0x10,
BUTTON_TWO = 0x0100,
BUTTON_ONE = 0x0200,
BUTTON_B = 0x0400,
BUTTON_A = 0x0800,
BUTTON_MINUS = 0x1000,
BUTTON_HOME = 0x8000,
};
Wiimote( const unsigned int index );
std::string GetName() const;
void Update();
void InterruptChannel(const u16 _channelID, const void* _pData, u32 _Size);
void ControlChannel(const u16 _channelID, const void* _pData, u32 _Size);
void DoState(PointerWrap& p);
void LoadDefaults(const ControllerInterface& ciface);
protected:
bool Step();
void HidOutputReport(const wm_report* const sr, const bool send_ack = true);
void HandleExtensionSwap();
void GetCoreData(u8* const data);
void GetAccelData(u8* const data, u8* const buttons);
void GetIRData(u8* const data, bool use_accel);
void GetExtData(u8* const data);
bool HaveExtension() const { return m_extension->active_extension > 0; }
bool WantExtension() const { return m_extension->switch_extension != 0; }
private:
struct ReadRequest
{
//u16 channel;
unsigned int address, size, position;
u8* data;
};
void Reset();
void ReportMode(const wm_report_mode* const dr);
void SendAck(const u8 _reportID);
void RequestStatus(const wm_request_status* const rs = NULL);
void ReadData(const wm_read_data* const rd);
void WriteData(const wm_write_data* const wd);
void SendReadDataReply(ReadRequest& _request);
#ifdef USE_WIIMOTE_EMU_SPEAKER
void SpeakerData(wm_speaker_data* sd);
#endif
// control groups
Buttons* m_buttons;
Buttons* m_dpad;
Buttons* m_shake;
Cursor* m_ir;
Tilt* m_tilt;
Force* m_swing;
ControlGroup* m_rumble;
Extension* m_extension;
ControlGroup* m_options;
// WiiMote accel data
AccelData m_accel;
// wiimote index, 0-3
const unsigned int m_index;
double ir_sin,ir_cos; //for the low pass filter
#ifdef USE_UDP_WIIMOTE
UDPWrapper* m_udp;
#endif
bool m_rumble_on;
bool m_speaker_mute;
bool m_reporting_auto;
u8 m_reporting_mode;
u16 m_reporting_channel;
unsigned int m_shake_step[3];
wm_status_report m_status;
class Register : public std::map< size_t, std::vector<u8> >
{
public:
void Write( size_t address, const void* src, size_t length );
void Read( size_t address, void* dst, size_t length );
} m_register;
// read data request queue
// maybe it isn't actualy a queue
// maybe read requests cancel any current requests
std::queue< ReadRequest > m_read_requests;
#ifdef USE_WIIMOTE_EMU_SPEAKER
// speaker stuff
struct SoundBuffer
{
s16* samples;
ALuint buffer;
};
std::queue<SoundBuffer> m_audio_buffers;
ALuint m_audio_source;
struct
{
int hist1p, hist2p;
} m_channel_status;
#endif
u8 m_eeprom[WIIMOTE_EEPROM_SIZE];
u8* m_reg_motion_plus;
struct IrReg
{
u8 data[0x33];
u8 mode;
} *m_reg_ir;
struct ExtensionReg
{
u8 unknown1[0x08];
// address 0x08
u8 controller_data[0x06];
u8 unknown2[0x12];
// address 0x20
u8 calibration[0x10];
u8 unknown3[0x10];
// address 0x40
u8 encryption_key[0x10];
u8 unknown4[0xA0];
// address 0xF0
u8 encryption;
u8 unknown5[0x9];
// address 0xFA
u8 constant_id[6];
} *m_reg_ext;
struct SpeakerReg
{
u16 unknown;
u8 format;
u16 sample_rate;
u8 volume;
u8 unk[4];
} *m_reg_speaker;
wiimote_key m_ext_key;
};
}
#endif

View file

@ -0,0 +1,382 @@
// Copyright (C) 2003 Dolphin Project.
// 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/
#ifndef WIIMOTE_HID_H
#define WIIMOTE_HID_H
#include "CommonTypes.h"
// what is this ?
#ifdef _MSC_VER
#pragma warning(disable:4200)
#endif
#pragma pack(push, 1)
// Source: HID_010_SPC_PFL/1.0 (official HID specification)
struct hid_packet {
u8 param : 4;
u8 type : 4;
u8 data[0];
};
#define HID_TYPE_HANDSHAKE 0
#define HID_TYPE_SET_REPORT 5
#define HID_TYPE_DATA 0xA
#define HID_HANDSHAKE_SUCCESS 0
#define HID_PARAM_INPUT 1
#define HID_PARAM_OUTPUT 2
//source: http://wiibrew.org/wiki/Wiimote
typedef u16 wm_core;
struct wm_accel
{
u8 x, y, z;
};
// Four bytes for two objects. Filled with 0xFF if empty
struct wm_ir_basic
{
u8 x1;
u8 y1;
u8 x2hi : 2;
u8 y2hi : 2;
u8 x1hi : 2;
u8 y1hi : 2;
u8 x2;
u8 y2;
};
// Three bytes for one object
struct wm_ir_extended
{
u8 x;
u8 y;
u8 size : 4;
u8 xhi : 2;
u8 yhi : 2;
};
struct wm_extension
{
u8 jx; // joystick x, y
u8 jy;
u8 ax; // accelerometer
u8 ay;
u8 az;
u8 bt; // buttons
};
struct wm_classic_extension
{
u8 lx : 6; // byte 0
u8 rx3 : 2;
u8 ly : 6; // byte 1
u8 rx2 : 2;
u8 ry : 5; // byte 2
u8 lt2 : 2;
u8 rx1 : 1;
u8 rt : 5; // byte 3
u8 lt1 : 3;
u16 bt; // byte 4, 5
};
struct wm_guitar_extension
{
u8 sx : 6;
u8 pad1 : 2; // 1 on gh3, 0 on ghwt
u8 sy : 6;
u8 pad2 : 2; // 1 on gh3, 0 on ghwt
u8 tb : 5; // not used in gh3
u8 pad3 : 3; // always 0
u8 whammy : 5;
u8 pad4 : 3; // always 0
u16 bt; // buttons
};
struct wm_drums_extension
{
u8 sx : 6;
u8 pad1 : 2; // always 0
u8 sy : 6;
u8 pad2 : 2; // always 0
u8 pad3 : 1; // unknown
u8 which : 5;
u8 none : 1;
u8 hhp : 1;
u8 pad4 : 1; // unknown
u8 velocity : 4; // unknown
u8 softness : 3;
u16 bt; // buttons
};
struct wm_turntable_extension
{
u8 sx : 6;
u8 rtable3 : 2;
u8 sy : 6;
u8 rtable2 : 2;
u8 rtable4 : 1;
u8 slider : 4;
u8 dial2 : 2;
u8 rtable1 : 1;
u8 ltable1 : 5;
u8 dial1 : 3;
union
{
u16 ltable2 : 1;
u16 bt; // buttons
};
};
struct wm_report
{
u8 wm;
union
{
u8 data[0];
struct
{
u8 rumble : 1; // enable/disable rumble
// only valid for certain reports
u8 ack : 1; // respond with an ack
u8 enable : 1; // enable/disable certain features
};
};
};
#define WM_RUMBLE 0x10
#define WM_LEDS 0x11
struct wm_leds {
u8 rumble : 1;
u8 : 3;
u8 leds : 4;
};
#define WM_REPORT_MODE 0x12
struct wm_report_mode {
u8 rumble : 1;
u8 continuous : 1; // these 2 seem to be named wrong
u8 all_the_time : 1;
u8 : 5;
u8 mode;
};
#define WM_IR_PIXEL_CLOCK 0x13
#define WM_IR_LOGIC 0x1A
#define WM_REQUEST_STATUS 0x15
struct wm_request_status {
u8 rumble : 1;
u8 : 7;
};
#define WM_STATUS_REPORT 0x20
struct wm_status_report {
wm_core buttons;
u8 battery_low : 1;
u8 extension : 1;
u8 speaker : 1;
u8 ir : 1;
u8 leds : 4;
u8 padding2[2]; // two 00, TODO: this needs more investigation
u8 battery;
};
#define WM_WRITE_DATA 0x16
struct wm_write_data
{
u8 rumble : 1;
u8 space : 2; //see WM_SPACE_*
u8 : 5;
u8 address[3];
u8 size;
u8 data[16];
};
#define WM_ACK_DATA 0x22
struct wm_acknowledge
{
wm_core buttons;
u8 reportID;
u8 errorID;
};
#define WM_READ_DATA 0x17
struct wm_read_data {
u8 rumble : 1;
u8 space : 2; //see WM_SPACE_*
u8 : 5;
u8 address[3];
u16 size;
};
#define WM_SPACE_EEPROM 0
#define WM_SPACE_REGS1 1
#define WM_SPACE_REGS2 2
#define WM_SPACE_INVALID 3
#define WM_READ_DATA_REPLY 0x21
struct wm_read_data_reply {
wm_core buttons;
u8 error : 4; //see WM_RDERR_*
u8 size : 4;
u16 address;
u8 data[16];
};
#define WM_RDERR_WOREG 7
#define WM_RDERR_NOMEM 8
// Data reports
#define WM_REPORT_CORE 0x30
struct wm_report_core {
wm_core c;
};
#define WM_REPORT_CORE_ACCEL 0x31
struct wm_report_core_accel {
wm_core c;
wm_accel a;
};
#define WM_REPORT_CORE_EXT8 0x32
#define WM_REPORT_CORE_ACCEL_IR12 0x33
struct wm_report_core_accel_ir12 {
wm_core c;
wm_accel a;
wm_ir_extended ir[4];
};
#define WM_REPORT_CORE_EXT19 0x34
#define WM_REPORT_CORE_ACCEL_EXT16 0x35
struct wm_report_core_accel_ext16
{
wm_core c;
wm_accel a;
wm_extension ext;
//wm_ir_basic ir[2];
u8 pad[10];
};
#define WM_REPORT_CORE_IR10_EXT9 0x36
#define WM_REPORT_CORE_ACCEL_IR10_EXT6 0x37
struct wm_report_core_accel_ir10_ext6
{
wm_core c;
wm_accel a;
wm_ir_basic ir[2];
//u8 ext[6];
wm_extension ext;
};
#define WM_REPORT_EXT21 0x3d // never used?
struct wm_report_ext21
{
u8 ext[21];
};
#define WM_REPORT_INTERLEAVE1 0x3e
#define WM_REPORT_INTERLEAVE2 0x3f
#define WM_SPEAKER_ENABLE 0x14
#define WM_SPEAKER_MUTE 0x19
#define WM_WRITE_SPEAKER_DATA 0x18
struct wm_speaker_data {
u8 unknown : 3;
u8 length : 5;
u8 data[20];
};
// Custom structs
/**
* @struct accel_t
* @brief Accelerometer struct. For any device with an accelerometer.
*/
struct accel_cal
{
struct
{
u8 x, y, z;
u8 xlo : 2;
u8 ylo : 2;
u8 zlo : 2;
} zero_g;
struct
{
u8 x, y, z;
u8 xlo : 2;
u8 ylo : 2;
u8 zlo : 2;
} one_g;
};
struct nu_js {
u8 max, min, center;
};
struct cc_trigger {
u8 neutral;
};
struct nu_cal
{
wm_accel cal_zero; // zero calibratio
wm_accel cal_g; // g size
nu_js jx; //
nu_js jy; //
};
struct cc_cal
{
nu_js Lx; //
nu_js Ly; //
nu_js Rx; //
nu_js Ry; //
cc_trigger Tl; //
cc_trigger Tr; //
};
struct gh3_cal
{
nu_js Lx;
nu_js Ly;
};
#pragma pack(pop)
#endif //WIIMOTE_HID_H

View file

@ -0,0 +1,604 @@
// Copyright (C) 2003 Dolphin Project.
// 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 <queue>
#include "Common.h"
#include "IniFile.h"
#include "StringUtil.h"
#include "Timer.h"
#include "wiiuse.h"
#include "WiimoteReal.h"
#include "../WiimoteEmu/WiimoteHid.h"
// used for pair up
#ifdef _WIN32
#undef NTDDI_VERSION
#define NTDDI_VERSION NTDDI_WINXPSP2
#include <bthdef.h>
#include <BluetoothAPIs.h>
#pragma comment(lib, "Bthprops.lib")
#endif
unsigned int g_wiimote_sources[MAX_WIIMOTES];
namespace WiimoteReal
{
bool g_real_wiimotes_initialized = false;
wiimote_t** g_wiimotes_from_wiiuse = NULL;
unsigned int g_wiimotes_found = 0;
// removed g_wiimotes_lastfound because Refresh() isn't taking advantage of it
volatile bool g_run_wiimote_thread = false;
Common::Thread *g_wiimote_threads[MAX_WIIMOTES] = {};
Common::CriticalSection g_refresh_critsec;
THREAD_RETURN WiimoteThreadFunc(void* arg);
void StartWiimoteThreads();
void StopWiimoteThreads();
Wiimote *g_wiimotes[MAX_WIIMOTES];
Wiimote::Wiimote(wiimote_t* const _wiimote, const unsigned int _index)
: index(_index)
, wiimote(_wiimote)
, m_last_data_report(NULL)
, m_channel(0)
{
// disable reporting
DisableDataReporting();
// set LEDs
wiiuse_set_leds(wiimote, WIIMOTE_LED_1 << index);
// TODO: make Dolphin connect wiimote, maybe
}
Wiimote::~Wiimote()
{
ClearReadQueue();
// clear write queue
Report rpt;
while (m_write_reports.Pop(rpt))
delete[] rpt.first;
// disable reporting / wiiuse might do this on shutdown anyway, o well, don't know for sure
DisableDataReporting();
}
// silly, copying data n stuff, o well, don't use this too often
void Wiimote::SendPacket(const u8 rpt_id, const void* const data, const unsigned int size)
{
Report rpt;
rpt.second = size + 2;
rpt.first = new u8[rpt.second];
rpt.first[0] = 0xA1;
rpt.first[1] = rpt_id;
memcpy(rpt.first + 2, data, size);
m_write_reports.Push(rpt);
}
void Wiimote::DisableDataReporting()
{
wm_report_mode rpt;
rpt.mode = WM_REPORT_CORE;
rpt.all_the_time = 0;
rpt.continuous = 0;
rpt.rumble = 0;
SendPacket(WM_REPORT_MODE, &rpt, sizeof(rpt));
}
void Wiimote::ClearReadQueue()
{
if (m_last_data_report)
{
delete[] m_last_data_report;
m_last_data_report = NULL;
}
u8 *rpt;
while (m_read_reports.Pop(rpt))
delete[] rpt;
}
void Wiimote::ControlChannel(const u16 channel, const void* const data, const u32 size)
{
// Check for custom communication
if (99 == channel)
Disconnect();
else
{
InterruptChannel(channel, data, size);
const hid_packet* const hidp = (hid_packet*)data;
if (hidp->type == HID_TYPE_SET_REPORT)
{
u8 handshake_ok = HID_HANDSHAKE_SUCCESS;
Core::Callback_WiimoteInterruptChannel(index, channel, &handshake_ok, sizeof(handshake_ok));
}
}
}
void Wiimote::InterruptChannel(const u16 channel, const void* const data, const u32 size)
{
if (0 == m_channel) // first interrupt/control channel sent
{
ClearReadQueue();
// request status
wm_request_status rpt;
rpt.rumble = 0;
SendPacket(WM_REQUEST_STATUS, &rpt, sizeof(rpt));
}
m_channel = channel; // this right?
Wiimote::Report rpt;
rpt.first = new u8[size];
rpt.second = (u8)size;
memcpy(rpt.first, (u8*)data, size);
// some hax, since we just send the last data report to Dolphin on each Update() call
// , make the wiimote only send updated data reports when data changes
// == less bt traffic, eliminates some unneeded packets
if (WM_REPORT_MODE == ((u8*)data)[1])
{
// also delete the last data report
if (m_last_data_report)
{
delete[] m_last_data_report;
m_last_data_report = NULL;
}
// nice var names :p, this seems to be this one
((wm_report_mode*)(rpt.first + 2))->all_the_time = false;
//((wm_report_mode*)(data + 2))->continuous = false;
}
m_write_reports.Push(rpt);
}
bool Wiimote::Read()
{
if (wiiuse_io_read(wiimote))
{
if (m_channel)
{
// add it to queue
u8* const rpt = new u8[MAX_PAYLOAD];
memcpy(rpt, wiimote->event_buf, MAX_PAYLOAD);
m_read_reports.Push(rpt);
}
return true;
}
return false;
}
bool Wiimote::Write()
{
Report rpt;
if (m_write_reports.Pop(rpt))
{
wiiuse_io_write(wiimote, rpt.first, rpt.second);
delete[] rpt.first;
return true;
}
return false;
}
// returns the next report that should be sent
u8* Wiimote::ProcessReadQueue()
{
// pop through the queued reports
u8* rpt = m_last_data_report;
while (m_read_reports.Pop(rpt))
{
// a data report
if (rpt[1] >= WM_REPORT_CORE)
m_last_data_report = rpt;
// some other kind of report
else
return rpt;
}
// the queue was empty, or there were only data reports
return rpt;
}
void Wiimote::Update()
{
// pop through the queued reports
u8* const rpt = ProcessReadQueue();
// send the report
if (rpt && m_channel)
Core::Callback_WiimoteInterruptChannel(index, m_channel, rpt, MAX_PAYLOAD);
// delete the data if it isn't also the last data rpt
if (rpt != m_last_data_report)
delete[] rpt;
}
void Wiimote::Disconnect()
{
m_channel = 0;
// disable reporting
DisableDataReporting();
}
void LoadSettings()
{
std::string ini_filename = (std::string(File::GetUserPath(D_CONFIG_IDX)) + WIIMOTE_INI_NAME ".ini" );
IniFile inifile;
inifile.Load(ini_filename);
for (unsigned int i=0; i<MAX_WIIMOTES; ++i)
{
std::string secname("Wiimote");
secname += (char)('1' + i);
IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
sec.Get("Source", &g_wiimote_sources[i], WIIMOTE_SRC_EMU);
}
}
unsigned int Initialize()
{
// return if already initialized
if (g_real_wiimotes_initialized)
return g_wiimotes_found;
memset(g_wiimotes, 0, sizeof(g_wiimotes));
// only call wiiuse_find with the number of slots configured for real wiimotes
unsigned int wanted_wiimotes = 0;
for (unsigned int i = 0; i < MAX_WIIMOTES; ++i)
if (WIIMOTE_SRC_REAL & g_wiimote_sources[i])
++wanted_wiimotes;
// don't bother initializing wiiuse if we don't want any real wiimotes
if (0 == wanted_wiimotes)
{
g_wiimotes_found = 0;
return 0;
}
// initialized
g_real_wiimotes_initialized = true;
#ifdef _WIN32
// Alloc memory for wiimote structure only if we're starting fresh
if(!g_wiimotes_from_wiiuse)
g_wiimotes_from_wiiuse = wiiuse_init(MAX_WIIMOTES);
// on windows wiiuse_find() expects as a 3rd parameter the amount of last connected wiimotes instead of the timeout,
// a timeout parameter is useless on win32 here, since at this points we already have the wiimotes discovered and paired up, just not connected.
g_wiimotes_found = wiiuse_find(g_wiimotes_from_wiiuse, wanted_wiimotes, 0);
#else
g_wiimotes_from_wiiuse = wiiuse_init(MAX_WIIMOTES);
g_wiimotes_found = wiiuse_find(g_wiimotes_from_wiiuse, wanted_wiimotes, 5);
#endif
DEBUG_LOG(WIIMOTE, "Found %i Real Wiimotes, %i wanted",
g_wiimotes_found, wanted_wiimotes);
g_wiimotes_found =
wiiuse_connect(g_wiimotes_from_wiiuse, g_wiimotes_found);
DEBUG_LOG(WIIMOTE, "Connected to %i Real Wiimotes", g_wiimotes_found);
// create real wiimote class instances, assign wiimotes
for (unsigned int i = 0, w = 0; i<MAX_WIIMOTES && w<g_wiimotes_found; ++i)
{
// create/assign wiimote
if (WIIMOTE_SRC_REAL & g_wiimote_sources[i])
g_wiimotes[i] = new Wiimote(g_wiimotes_from_wiiuse[w++], i);
}
StartWiimoteThreads();
return g_wiimotes_found;
}
void Shutdown(void)
{
if (false == g_real_wiimotes_initialized)
return;
// Uninitialized
g_real_wiimotes_initialized = false;
StopWiimoteThreads();
// delete wiimotes
for (unsigned int i=0; i<MAX_WIIMOTES; ++i)
if (g_wiimotes[i])
{
delete g_wiimotes[i];
g_wiimotes[i] = NULL;
}
// Clean up wiiuse, win32: we cant just delete the struct on win32, since wiiuse_find() maintains it and
// adds/removes wimotes directly to/from it to prevent problems, which would occur when using more than 1 wiimote if we create it from scratch everytime
#ifndef _WIN32
wiiuse_cleanup(g_wiimotes_from_wiiuse, MAX_WIIMOTES);
#endif
}
void Refresh() // this gets called from the GUI thread
{
#ifdef __linux__
// make sure real wiimotes have been initialized
if (!g_real_wiimotes_initialized)
{
Initialize();
return;
}
// find the number of slots configured for real wiimotes
unsigned int wanted_wiimotes = 0;
for (unsigned int i = 0; i < MAX_WIIMOTES; ++i)
if (WIIMOTE_SRC_REAL & g_wiimote_sources[i])
++wanted_wiimotes;
// don't scan for wiimotes if we don't want any more
if (wanted_wiimotes <= g_wiimotes_found)
return;
// scan for wiimotes
unsigned int num_wiimotes = wiiuse_find(g_wiimotes_from_wiiuse, wanted_wiimotes, 5);
DEBUG_LOG(WIIMOTE, "Found %i Real Wiimotes, %i wanted", num_wiimotes, wanted_wiimotes);
int num_new_wiimotes = wiiuse_connect(g_wiimotes_from_wiiuse, num_wiimotes);
DEBUG_LOG(WIIMOTE, "Connected to %i additional Real Wiimotes", num_new_wiimotes);
StopWiimoteThreads();
g_refresh_critsec.Enter();
// create real wiimote class instances, and assign wiimotes for the new wiimotes
for (unsigned int i = g_wiimotes_found, w = g_wiimotes_found;
i < MAX_WIIMOTES && w < num_wiimotes; ++i)
{
// create/assign wiimote
if (WIIMOTE_SRC_REAL & g_wiimote_sources[i] && NULL == g_wiimotes[i])
g_wiimotes[i] = new Wiimote(g_wiimotes_from_wiiuse[w++], i);
}
g_wiimotes_found = num_wiimotes;
g_refresh_critsec.Leave();
StartWiimoteThreads();
#else // windows/ OSX
g_refresh_critsec.Enter();
// should be fine i think
Shutdown();
Initialize();
g_refresh_critsec.Leave();
#endif
}
void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size)
{
g_refresh_critsec.Enter();
if (g_wiimotes[_WiimoteNumber])
g_wiimotes[_WiimoteNumber]->InterruptChannel(_channelID, _pData, _Size);
g_refresh_critsec.Leave();
}
void ControlChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size)
{
g_refresh_critsec.Enter();
if (g_wiimotes[_WiimoteNumber])
g_wiimotes[_WiimoteNumber]->ControlChannel(_channelID, _pData, _Size);
g_refresh_critsec.Leave();
}
// Read the Wiimote once
void Update(int _WiimoteNumber)
{
g_refresh_critsec.Enter();
if (g_wiimotes[_WiimoteNumber])
g_wiimotes[_WiimoteNumber]->Update();
g_refresh_critsec.Leave();
}
void StateChange(PLUGIN_EMUSTATE newState)
{
//g_refresh_critsec.Enter(); // enter
// TODO: disable/enable auto reporting, maybe
//g_refresh_critsec.Leave(); // leave
}
void StartWiimoteThreads()
{
g_run_wiimote_thread = true;
for (unsigned int i=0; i<MAX_WIIMOTES; ++i)
if (g_wiimotes[i])
g_wiimote_threads[i] = new Common::Thread(WiimoteThreadFunc, g_wiimotes[i]);
}
void StopWiimoteThreads()
{
g_run_wiimote_thread = false;
for (unsigned int i=0; i<MAX_WIIMOTES; ++i)
if (g_wiimote_threads[i])
{
g_wiimote_threads[i]->WaitForDeath();
delete g_wiimote_threads[i];
g_wiimote_threads[i] = NULL;
}
}
THREAD_RETURN WiimoteThreadFunc(void* arg)
{
Wiimote* const wiimote = (Wiimote*)arg;
{
char thname[] = "Wiimote # Thread";
thname[8] = (char)('1' + wiimote->index);
Common::SetCurrentThreadName(thname);
}
// rumble briefly
wiiuse_rumble(wiimote->wiimote, 1);
SLEEP(200);
wiiuse_rumble(wiimote->wiimote, 0);
// main loop
while (g_run_wiimote_thread)
{
// hopefully this is alright
while (wiimote->Write()) {}
// sleep if there was nothing to read
if (false == wiimote->Read())
Common::SleepCurrentThread(1);
}
return 0;
}
#ifdef _WIN32
int UnPair()
{
// TODO:
return 0;
}
// WiiMote Pair-Up, function will return amount of either new paired or unpaired devices
// negative number on failure
int PairUp(bool unpair)
{
int nPaired = 0;
BLUETOOTH_DEVICE_SEARCH_PARAMS srch;
srch.dwSize = sizeof(srch);
srch.fReturnAuthenticated = true;
srch.fReturnRemembered = true;
srch.fReturnConnected = true; // does not filter properly somehow, so we've to do an additional check on fConnected BT Devices
srch.fReturnUnknown = true;
srch.fIssueInquiry = true;
srch.cTimeoutMultiplier = 2; // == (2 * 1.28) seconds
BLUETOOTH_FIND_RADIO_PARAMS radioParam;
radioParam.dwSize = sizeof(radioParam);
HANDLE hRadio;
// Enumerate BT radios
HBLUETOOTH_RADIO_FIND hFindRadio = BluetoothFindFirstRadio(&radioParam, &hRadio);
if (NULL == hFindRadio)
return -1;
while (hFindRadio)
{
BLUETOOTH_RADIO_INFO radioInfo;
radioInfo.dwSize = sizeof(radioInfo);
// TODO: check for SUCCEEDED()
BluetoothGetRadioInfo(hRadio, &radioInfo);
srch.hRadio = hRadio;
BLUETOOTH_DEVICE_INFO btdi;
btdi.dwSize = sizeof(btdi);
// Enumerate BT devices
HBLUETOOTH_DEVICE_FIND hFindDevice = BluetoothFindFirstDevice(&srch, &btdi);
while (hFindDevice)
{
//btdi.szName is sometimes missings it's content - it's a bt feature..
DEBUG_LOG(WIIMOTE, "authed %i connected %i remembered %i ", btdi.fAuthenticated, btdi.fConnected, btdi.fRemembered);
// TODO: Probably could just check for "Nintendo RVL"
if (0 == wcscmp(btdi.szName, L"Nintendo RVL-WBC-01") || 0 == wcscmp(btdi.szName, L"Nintendo RVL-CNT-01"))
{
if (unpair)
{
if (SUCCEEDED(BluetoothRemoveDevice(&btdi.Address)))
{
NOTICE_LOG(WIIMOTE, "Pair-Up: Automatically removed BT Device on shutdown: %08x", GetLastError());
++nPaired;
}
}
else
{
if (false == btdi.fConnected)
{
//TODO: improve the read of the BT driver, esp. when batteries of the wiimote are removed while being fConnected
if (btdi.fRemembered)
{
// Make Windows forget old expired pairing
// we can pretty much ignore the return value here.
// it either worked (ERROR_SUCCESS), or the device did not exist (ERROR_NOT_FOUND)
// in both cases, there is nothing left.
BluetoothRemoveDevice(&btdi.Address);
}
// Activate service
const DWORD hr = BluetoothSetServiceState(hRadio, &btdi, &HumanInterfaceDeviceServiceClass_UUID, BLUETOOTH_SERVICE_ENABLE);
if (SUCCEEDED(hr))
++nPaired;
else
ERROR_LOG(WIIMOTE, "Pair-Up: BluetoothSetServiceState() returned %08x", hr);
}
}
}
if (false == BluetoothFindNextDevice(hFindDevice, &btdi))
{
BluetoothFindDeviceClose(hFindDevice);
hFindDevice = NULL;
}
}
if (false == BluetoothFindNextRadio(hFindRadio, &hRadio))
{
BluetoothFindRadioClose(hFindRadio);
hFindRadio = NULL;
}
}
return nPaired;
}
#endif
}; // end of namespace

View file

@ -0,0 +1,92 @@
// Copyright (C) 2003 Dolphin Project.
// 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/
#ifndef WIIMOTE_REAL_H
#define WIIMOTE_REAL_H
#include "wiiuse.h"
#include "ChunkFile.h"
#include "Thread.h"
#include "FifoQueue.h"
#include "../Wiimote.h"
#include "../WiimoteEmu/WiimoteEmu.h"
#include "../../InputCommon/Src/InputConfig.h"
enum
{
WIIMOTE_SRC_NONE = 0,
WIIMOTE_SRC_EMU = 1,
WIIMOTE_SRC_REAL = 2,
WIIMOTE_SRC_HYBRID = 3, // emu + real
};
namespace WiimoteReal
{
class Wiimote
{
friend class WiimoteEmu::Wiimote;
public:
Wiimote(wiimote_t* const wm, const unsigned int index);
~Wiimote();
void ControlChannel(const u16 channel, const void* const data, const u32 size);
void InterruptChannel(const u16 channel, const void* const data, const u32 size);
void Update();
u8* ProcessReadQueue();
bool Read();
bool Write();
void Disconnect();
void DisableDataReporting();
void SendPacket(const u8 rpt_id, const void* const data, const unsigned int size);
// pointer to data, and size of data
typedef std::pair<u8*,u8> Report;
const unsigned int index;
wiimote_t* const wiimote;
protected:
u8 *m_last_data_report;
u16 m_channel;
private:
void ClearReadQueue();
Common::FifoQueue<u8*> m_read_reports;
Common::FifoQueue<Report> m_write_reports;
};
extern Common::CriticalSection g_refresh_critsec;
extern Wiimote *g_wiimotes[4];
void InterruptChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size);
void ControlChannel(int _WiimoteNumber, u16 _channelID, const void* _pData, u32 _Size);
void Update(int _WiimoteNumber);
void DoState(PointerWrap &p);
void StateChange(PLUGIN_EMUSTATE newState);
}; // WiiMoteReal
#endif

View file

@ -18,7 +18,7 @@
#include "../Core.h"
#include "../Debugger/Debugger_SymbolMap.h"
#include "../Host.h"
#include "../PluginManager.h"
#include "../HW/Wiimote.h"
#include "../HW/WII_IPC.h"
#include "WII_IPC_HLE.h"
#include "WII_IPC_HLE_Device_usb.h"
@ -439,7 +439,7 @@ u32 CWII_IPC_HLE_Device_usb_oh1_57e_305::Update()
#if defined(HAVE_WX) && HAVE_WX
NetPlay_WiimoteUpdate(i);
#endif
CPluginManager::GetInstance().GetWiimote()->Wiimote_Update(i);
Wiimote::Update(i);
//return true;
}
}

View file

@ -24,6 +24,7 @@
#include "../ConfigManager.h"
#include "../Host.h"
#include "../Core.h"
#include "../HW/Wiimote.h"
#include "l2cap.h" // Local
#include "WiiMote_HID_Attr.h"
@ -183,7 +184,7 @@ void CWII_IPC_HLE_WiiMote::EventDisconnect()
{
// Send disconnect message to plugin
u8 Message = WIIMOTE_DISCONNECT;
CPluginManager::GetInstance().GetWiimote()->Wiimote_ControlChannel(m_ConnectionHandle & 0xFF, 99, &Message, 0);
Wiimote::ControlChannel(m_ConnectionHandle & 0xFF, 99, &Message, 0);
m_ConnectionState = CONN_INACTIVE;
// Clear channel flags
@ -256,7 +257,6 @@ void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size)
const int number = 0;
#endif
Common::PluginWiimote* mote = CPluginManager::GetInstance().GetWiimote();
if (itr != m_Channel.end())
{
SChannel& rChannel = itr->second;
@ -268,7 +268,7 @@ void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size)
case L2CAP_PSM_HID_CNTL:
if (number < 4)
mote->Wiimote_ControlChannel(number, pHeader->dcid, pData, DataSize);
Wiimote::ControlChannel(number, pHeader->dcid, pData, DataSize);
break;
case L2CAP_PSM_HID_INTR:
@ -280,7 +280,7 @@ void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size)
std::string Temp = ArrayToString((const u8*)pData, DataSize);
DEBUG_LOG(WIIMOTE, " Data: %s", Temp.c_str());
mote->Wiimote_InterruptChannel(number, pHeader->dcid, pData, DataSize);
Wiimote::InterruptChannel(number, pHeader->dcid, pData, DataSize);
}
}
break;

View file

@ -71,7 +71,6 @@ CPluginManager::CPluginManager()
// Set initial values to NULL.
m_video = NULL;
m_dsp = NULL;
m_wiimote = NULL;
}
// This will call FreeLibrary() for all plugins
@ -81,14 +80,6 @@ CPluginManager::~CPluginManager()
delete m_PluginGlobals;
delete m_dsp;
if (m_wiimote)
{
m_wiimote->Shutdown();
delete m_wiimote;
m_wiimote = NULL;
}
delete m_video;
}
@ -118,18 +109,6 @@ bool CPluginManager::InitPlugins()
return false;
}
// Init wiimote
if (m_params->bWii)
{
if (!m_params->m_strWiimotePlugin.empty())
GetWiimote();
if (!m_wiimote)
{
PanicAlert("Can't init Wiimote Plugin");
return false;
}
}
return true;
}
@ -138,12 +117,6 @@ bool CPluginManager::InitPlugins()
// for an explanation about the current LoadLibrary() and FreeLibrary() behavior.
void CPluginManager::ShutdownPlugins()
{
if (m_wiimote)
{
m_wiimote->Shutdown();
FreeWiimote();
}
if (m_dsp)
{
m_dsp->Shutdown();
@ -247,10 +220,6 @@ void *CPluginManager::LoadPlugin(const char *_rFilename)
plugin = new Common::PluginDSP(_rFilename);
break;
case PLUGIN_TYPE_WIIMOTE:
plugin = new Common::PluginWiimote(_rFilename);
break;
default:
PanicAlert("Trying to load unsupported type %d", type);
return NULL;
@ -319,27 +288,12 @@ void CPluginManager::ScanForPlugins()
/* Create or return the already created plugin pointers. This will be called
often for Wiimote. And often for the DSP from the DSP files.
often for the DSP from the DSP files.
We don't need to check if [Plugin]->IsValid() here because it will not be set by LoadPlugin()
if it's not valid.
*/
Common::PluginWiimote *CPluginManager::GetWiimote()
{
if (m_wiimote != NULL)
{
if (m_wiimote->GetFilename() == m_params->m_strWiimotePlugin)
return m_wiimote;
else
FreeWiimote();
}
// Else load a new plugin
m_wiimote = (Common::PluginWiimote*)LoadPlugin(m_params->m_strWiimotePlugin.c_str());
return m_wiimote;
}
Common::PluginDSP *CPluginManager::GetDSP()
{
if (m_dsp != NULL)
@ -384,17 +338,10 @@ void CPluginManager::FreeDSP()
m_dsp = NULL;
}
void CPluginManager::FreeWiimote()
{
delete m_wiimote;
m_wiimote = NULL;
}
void CPluginManager::EmuStateChange(PLUGIN_EMUSTATE newState)
{
GetVideo()->EmuStateChange(newState);
GetDSP()->EmuStateChange(newState);
GetWiimote()->EmuStateChange(newState);
}
@ -417,16 +364,15 @@ void CPluginManager::OpenConfig(void* _Parent, const char *_rFilename, PLUGIN_TY
if (GetVideo() != NULL)
GetVideo()->Config(_Parent);
break;
case PLUGIN_TYPE_DSP:
if (GetDSP() != NULL)
GetDSP()->Config(_Parent);
break;
case PLUGIN_TYPE_WIIMOTE:
if (GetWiimote() != NULL)
GetWiimote()->Config(_Parent);
break;
default:
PanicAlert("Type %d config not supported in plugin %s", Type, _rFilename);
break;
}
}
@ -444,11 +390,14 @@ void *CPluginManager::OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TY
case PLUGIN_TYPE_VIDEO:
return GetVideo()->Debug(_Parent, Show);
break;
case PLUGIN_TYPE_DSP:
return GetDSP()->Debug(_Parent, Show);
break;
default:
PanicAlert("Type %d debug not supported in plugin %s", Type, _rFilename);
return NULL;
break;
}
}

View file

@ -21,7 +21,6 @@
#include "Plugin.h"
#include "PluginDSP.h"
#include "PluginVideo.h"
#include "PluginWiimote.h"
#include "CoreParameter.h"
class CPluginInfo
@ -51,11 +50,9 @@ public:
Common::PluginVideo *GetVideo();
Common::PluginDSP *GetDSP();
Common::PluginWiimote *GetWiimote();
void FreeVideo();
void FreeDSP();
void FreeWiimote();
void EmuStateChange(PLUGIN_EMUSTATE newState);
@ -75,7 +72,6 @@ private:
PLUGIN_GLOBALS *m_PluginGlobals;
Common::PluginVideo *m_video;
Common::PluginDSP *m_dsp;
Common::PluginWiimote *m_wiimote;
SCoreStartupParameter * m_params;
CPluginManager();

View file

@ -49,6 +49,17 @@ files = [
"HW/EXI_DeviceEthernet.cpp",
"HW/GPFifo.cpp",
"HW/GCPad.cpp",
"HW/Wiimote.cpp",
"HW/WiimoteEmu/WiimoteEmu.cpp",
"HW/WiimoteEmu/Attachment/Classic.cpp",
"HW/WiimoteEmu/Attachment/Attachment.cpp",
"HW/WiimoteEmu/Attachment/Nunchuk.cpp",
"HW/WiimoteEmu/Attachment/Drums.cpp",
"HW/WiimoteEmu/Attachment/Guitar.cpp",
"HW/WiimoteEmu/Attachment/Turntable.cpp",
"HW/WiimoteEmu/EmuSubroutines.cpp",
"HW/WiimoteEmu/Encryption.cpp",
"HW/WiimoteEmu/Speaker.cpp",
"HW/GCPadEmu.cpp",
"HW/HW.cpp",
"HW/Memmap.cpp",
@ -132,6 +143,10 @@ elif sys.platform == 'darwin':
else:
files += [ "HW/BBA-TAP/TAP_Unix.cpp" ]
if env['HAVE_WIIUSE']:
files += [ 'HW/WiimoteReal/WiimoteReal.cpp' ]
libs += [ 'wiiuse' ]
libs = [
'bdisasm',
'inputcommon',

View file

@ -24,6 +24,7 @@
#include "Thread.h"
#include "CoreTiming.h"
#include "OnFrame.h"
#include "HW/Wiimote.h"
#include "HW/HW.h"
#include "PowerPC/PowerPC.h"
#include "PowerPC/JitCommon/JitBase.h"
@ -90,7 +91,7 @@ void DoState(PointerWrap &p)
pm.GetVideo()->DoState(p.GetPPtr(), p.GetMode());
pm.GetDSP()->DoState(p.GetPPtr(), p.GetMode());
if (Core::g_CoreStartupParameter.bWii)
pm.GetWiimote()->DoState(p.GetPPtr(), p.GetMode());
Wiimote::DoState(p.GetPPtr(), p.GetMode());
PowerPC::DoState(p);
HW::DoState(p);
CoreTiming::DoState(p);

View file

@ -90,11 +90,11 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="SDL.lib xinput.lib Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28u.lib wxmsw28u_core.lib wxmsw28u_adv.lib wxmsw28u_aui.lib"
OutputFile="../../../Binary/Win32/Dolphin.exe"
AdditionalDependencies="Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28u.lib wxmsw28u_core.lib wxmsw28u_adv.lib wxmsw28u_aui.lib"
OutputFile="../../../Binary/$(PlatformName)/Dolphin.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32;../../../Externals/OpenAL/Win32/"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)&quot;;&quot;../../../Externals/OpenAL/$(PlatformName)/&quot;;&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
IgnoreAllDefaultLibraries="false"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
@ -208,11 +208,11 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="SDL.lib xinput.lib Iphlpapi.lib comctl32.lib rpcrt4.lib wxbase28u.lib wxmsw28u_core.lib wxmsw28u_adv.lib wxmsw28u_aui.lib"
OutputFile="../../../Binary/x64/Dolphin.exe"
AdditionalDependencies="Iphlpapi.lib comctl32.lib rpcrt4.lib wxbase28u.lib wxmsw28u_core.lib wxmsw28u_adv.lib wxmsw28u_aui.lib"
OutputFile="../../../Binary/$(PlatformName)/Dolphin.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64;../../../Externals/OpenAL/Win64/"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)&quot;;&quot;../../../Externals/OpenAL/$(PlatformName)/&quot;;&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
IgnoreAllDefaultLibraries="false"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
@ -321,11 +321,11 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/TLBID:1"
AdditionalDependencies="SDL.lib xinput.lib Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28ud.lib wxmsw28ud_core.lib wxmsw28ud_adv.lib wxmsw28ud_aui.lib"
AdditionalDependencies="Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28ud.lib wxmsw28ud_core.lib wxmsw28ud_adv.lib wxmsw28ud_aui.lib"
OutputFile="../../../Binary/Win32/DolphinD.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32;../../../Externals/OpenAL/Win32/"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)&quot;;&quot;../../../Externals/OpenAL/$(PlatformName)/&quot;;&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -432,11 +432,11 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/TLBID:1"
AdditionalDependencies="SDL.lib xinput.lib Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28ud.lib wxmsw28ud_core.lib wxmsw28ud_adv.lib wxmsw28ud_aui.lib"
AdditionalDependencies="Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28ud.lib wxmsw28ud_core.lib wxmsw28ud_adv.lib wxmsw28ud_aui.lib"
OutputFile="../../../Binary/x64/DolphinD.exe"
LinkIncremental="2"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64;../../../Externals/OpenAL/Win64/"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)&quot;;&quot;../../../Externals/OpenAL/$(PlatformName)/&quot;;&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -546,11 +546,11 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/NODEFAULTLIB:msvcrt.lib&#x0D;&#x0A;/NODEFAULTLIB:libcmtd.lib"
AdditionalDependencies="SDL.lib xinput.lib Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28u.lib wxmsw28u_core.lib wxmsw28u_adv.lib wxmsw28u_aui.lib"
AdditionalDependencies="Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28u.lib wxmsw28u_core.lib wxmsw28u_adv.lib wxmsw28u_aui.lib"
OutputFile="../../../Binary/Win32/DolphinDF.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\win32;..\..\..\Externals\wxWidgets\lib\vc_lib\Win32;../../../Externals/OpenAL/Win32/"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)&quot;;&quot;../../../Externals/OpenAL/$(PlatformName)/&quot;;&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -659,11 +659,11 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="SDL.lib xinput.lib Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28u.lib wxmsw28u_core.lib wxmsw28u_adv.lib wxmsw28u_aui.lib"
AdditionalDependencies="Iphlpapi.lib comctl32.lib rpcrt4.lib winmm.lib wxbase28u.lib wxmsw28u_core.lib wxmsw28u_adv.lib wxmsw28u_aui.lib"
OutputFile="../../../Binary/x64/DolphinDF.exe"
LinkIncremental="1"
SuppressStartupBanner="true"
AdditionalLibraryDirectories="..\..\..\Externals\SDL\x64;..\..\..\Externals\wxWidgets\lib\vc_lib\x64;../../../Externals/OpenAL/Win64/"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\wxWidgets\lib\vc_lib\$(PlatformName)&quot;;&quot;../../../Externals/OpenAL/$(PlatformName)/&quot;;&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
ProgramDatabaseFile="$(PlatformName)\$(ConfigurationName)\$(TargetName).pdb"
@ -924,6 +924,14 @@
RelativePath=".\Src\PatchAddEdit.h"
>
</File>
<File
RelativePath=".\Src\WiimoteConfigDiag.cpp"
>
</File>
<File
RelativePath=".\Src\WiimoteConfigDiag.h"
>
</File>
<Filter
Name="NetPlay"
>
@ -1054,6 +1062,22 @@
>
</File>
</Filter>
<Filter
Name="InputConfig"
>
<File
RelativePath=".\Src\InputConfigDiag.cpp"
>
</File>
<File
RelativePath=".\Src\InputConfigDiag.h"
>
</File>
<File
RelativePath=".\Src\InputConfigDiagBitmaps.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="Misc"

View file

@ -130,9 +130,6 @@ EVT_BUTTON(ID_GRAPHIC_CONFIG, CConfigMain::OnConfig)
EVT_CHOICE(ID_DSP_CB, CConfigMain::OnSelectionChanged)
EVT_BUTTON(ID_DSP_CONFIG, CConfigMain::OnConfig)
EVT_CHOICE(ID_WIIMOTE_CB, CConfigMain::OnSelectionChanged)
EVT_BUTTON(ID_WIIMOTE_CONFIG, CConfigMain::OnConfig)
END_EVENT_TABLE()
CConfigMain::CConfigMain(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& position, const wxSize& size, long style)
@ -199,7 +196,6 @@ void CConfigMain::UpdateGUI()
// Disable stuff on PluginsPage
GraphicSelection->Disable();
DSPSelection->Disable();
WiimoteSelection->Disable();
}
}
@ -329,7 +325,6 @@ void CConfigMain::InitializeGUIValues()
// Plugins
FillChoiceBox(GraphicSelection, PLUGIN_TYPE_VIDEO, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin);
FillChoiceBox(DSPSelection, PLUGIN_TYPE_DSP, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin);
FillChoiceBox(WiimoteSelection, PLUGIN_TYPE_WIIMOTE, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin);
}
void CConfigMain::InitializeGUITooltips()
@ -743,10 +738,6 @@ void CConfigMain::CreateGUIControls()
DSPSelection = new wxChoice(PluginsPage, ID_DSP_CB, wxDefaultPosition, wxDefaultSize, 0, NULL, 0, wxDefaultValidator);
DSPConfig = new wxButton(PluginsPage, ID_DSP_CONFIG, wxT("Config..."), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
sbWiimotePlugin = new wxStaticBoxSizer(wxHORIZONTAL, PluginsPage, wxT("Wiimote"));
WiimoteSelection = new wxChoice(PluginsPage, ID_WIIMOTE_CB, wxDefaultPosition, wxDefaultSize, 0, NULL, 0, wxDefaultValidator);
WiimoteConfig = new wxButton(PluginsPage, ID_WIIMOTE_CONFIG, wxT("Config..."), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
// Populate the settings
sbGraphicsPlugin->Add(GraphicSelection, 1, wxEXPAND|wxALL, 5);
sbGraphicsPlugin->Add(GraphicConfig, 0, wxALL, 5);
@ -754,14 +745,10 @@ void CConfigMain::CreateGUIControls()
sbDSPPlugin->Add(DSPSelection, 1, wxEXPAND|wxALL, 5);
sbDSPPlugin->Add(DSPConfig, 0, wxALL, 5);
sbWiimotePlugin->Add(WiimoteSelection, 1, wxEXPAND|wxALL, 5);
sbWiimotePlugin->Add(WiimoteConfig, 0, wxALL, 5);
// Populate the Plugins page
sPluginsPage = new wxBoxSizer(wxVERTICAL);
sPluginsPage->Add(sbGraphicsPlugin, 0, wxEXPAND|wxALL, 5);
sPluginsPage->Add(sbDSPPlugin, 0, wxEXPAND|wxALL, 5);
sPluginsPage->Add(sbWiimotePlugin, 0, wxEXPAND|wxALL, 5);
PluginsPage->SetSizer(sPluginsPage);
sPluginsPage->Layout();
@ -1155,8 +1142,6 @@ void CConfigMain::OnSelectionChanged(wxCommandEvent& WXUNUSED (event))
CPluginManager::GetInstance().FreeVideo();
if (GetFilename(DSPSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin))
CPluginManager::GetInstance().FreeDSP();
if (GetFilename(WiimoteSelection, SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin))
CPluginManager::GetInstance().FreeWiimote();
}
void CConfigMain::OnConfig(wxCommandEvent& event)
@ -1169,9 +1154,6 @@ void CConfigMain::OnConfig(wxCommandEvent& event)
case ID_DSP_CONFIG:
CallConfig(DSPSelection);
break;
case ID_WIIMOTE_CONFIG:
CallConfig(WiimoteSelection);
break;
}
}

View file

@ -140,7 +140,7 @@ private:
wxBoxSizer* sPluginsPage; // Plugins settings
wxStaticBoxSizer* sbGraphicsPlugin, *sbDSPPlugin, *sbWiimotePlugin; // Graphics, DSP, Wiimote sections
wxStaticBoxSizer* sbGraphicsPlugin, *sbDSPPlugin; // Graphics, DSP sections
// Graphics
wxChoice* GraphicSelection;
@ -150,10 +150,6 @@ private:
wxChoice* DSPSelection;
wxButton* DSPConfig;
// Wiimote
wxChoice* WiimoteSelection;
wxButton* WiimoteConfig;
wxButton* m_Ok;
FILE* pStream;
@ -262,11 +258,6 @@ private:
ID_DSP_CB,
ID_DSP_CONFIG,
ID_DSP_ABOUT,
ID_WIIMOTE_TEXT,
ID_WIIMOTE_CB,
ID_WIIMOTE_CONFIG,
ID_WIIMOTE_ABOUT
};
void InitializeGUILists();

View file

@ -817,9 +817,6 @@ void CFrame::OnKeyDown(wxKeyEvent& event)
&& event.GetModifiers() == wxMOD_SHIFT)
PostMessage((HWND)Core::GetWindowHandle(), WM_USER, WM_USER_KEYDOWN, event.GetKeyCode());
#endif
// Send the keyboard status to the Input plugins
CPluginManager::GetInstance().GetWiimote()->Wiimote_Input(event.GetKeyCode(), 1); // 1 = Down
}
else
event.Skip();
@ -828,10 +825,6 @@ void CFrame::OnKeyDown(wxKeyEvent& event)
void CFrame::OnKeyUp(wxKeyEvent& event)
{
event.Skip();
if(Core::GetState() != Core::CORE_UNINITIALIZED) {
CPluginManager::GetInstance().GetWiimote()->Wiimote_Input(event.GetKeyCode(), 0); // 0 = Up
}
}
void CFrame::DoFullscreen(bool bF)

View file

@ -57,12 +57,14 @@ Core::GetWindowHandle().
#include "HW/DVDInterface.h"
#include "HW/ProcessorInterface.h"
#include "HW/GCPad.h"
#include "HW/Wiimote.h"
#include "IPC_HLE/WII_IPC_HLE_Device_usb.h"
#include "State.h"
#include "VolumeHandler.h"
#include "NANDContentLoader.h"
#include "WXInputBase.h"
#include "../../InputUICommon/Src/ConfigDiag.h"
#include "WiimoteConfigDiag.h"
#include "InputConfigDiag.h"
#include <wx/datetime.h> // wxWidgets
@ -1024,42 +1026,50 @@ void CFrame::OnPluginDSP(wxCommandEvent& WXUNUSED (event))
void CFrame::OnPluginPAD(wxCommandEvent& WXUNUSED (event))
{
InputPlugin *pad_plugin = PAD_GetPlugin();
InputPlugin *const pad_plugin = Pad::GetPlugin();
bool was_init = false;
if ( pad_plugin->controller_interface.IsInit() ) // check if game is running
if (g_controller_interface.IsInit()) // check if game is running
was_init = true;
else
{
#if defined(HAVE_X11) && HAVE_X11
Window win = X11Utils::XWindowFromHandle(GetHandle());
GCPad_Init((void *)win);
Pad::Initialize((void *)win);
#else
GCPad_Init(GetHandle());
Pad::Initialize(GetHandle());
#endif
}
InputConfigDialog* m_ConfigFrame = new InputConfigDialog(this, *pad_plugin, "Dolphin GCPad Configuration");
InputConfigDialog *const m_ConfigFrame = new InputConfigDialog(this, *pad_plugin, "Dolphin GCPad Configuration");
m_ConfigFrame->ShowModal();
m_ConfigFrame->Destroy();
if (!was_init) // if game isn't running
{
GCPad_Deinit();
Pad::Shutdown();
}
}
void CFrame::OnPluginWiimote(wxCommandEvent& WXUNUSED (event))
{
#ifdef _WIN32
Disable(); // Fake a modal dialog
#endif
CPluginManager::GetInstance().OpenConfig(
this,
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin.c_str(),
PLUGIN_TYPE_WIIMOTE
);
#ifdef _WIN32
Enable();
Raise();
#endif
InputPlugin *const wiimote_plugin = Wiimote::GetPlugin();
bool was_init = false;
if (g_controller_interface.IsInit()) // check if game is running
was_init = true;
else
{
#if defined(HAVE_X11) && HAVE_X11
Window win = X11Utils::XWindowFromHandle(GetHandle());
Wiimote::Initialize((void *)win);
#else
Wiimote::Initialize(GetHandle());
#endif
}
WiimoteConfigDiag *const m_ConfigFrame = new WiimoteConfigDiag(this, *wiimote_plugin);
m_ConfigFrame->ShowModal();
m_ConfigFrame->Destroy();
if (!was_init) // if game isn't running
{
Wiimote::Shutdown();
}
}
void CFrame::OnHelp(wxCommandEvent& event)

View file

@ -15,18 +15,20 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "ConfigDiag.h"
#include "InputConfigDiag.h"
#define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s)
#define WXSTR_FROM_STR(s) (wxString::From8BitData((s).c_str()))
// ToAscii was causing probs with some extended ascii characters, To8BitData seems to work
#define STR_FROM_WXSTR(w) (std::string((w).To8BitData()))
#ifdef USE_UDP_WIIMOTE
void GamepadPage::ConfigUDPWii(wxCommandEvent &event)
{
UDPWrapper* const wrp = ((UDPConfigButton*)event.GetEventObject())->wrapper;
wrp->Configure(this);
}
#endif
void GamepadPage::ConfigExtension( wxCommandEvent& event )
{
@ -184,10 +186,10 @@ void InputConfigDialog::UpdateControlReferences()
std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
e = m_padpages.end();
for ( ; i != e; ++i )
(*i)->controller->UpdateReferences( m_plugin.controller_interface );
(*i)->controller->UpdateReferences(g_controller_interface);
}
void InputConfigDialog::ClickSave( wxCommandEvent& event )
void InputConfigDialog::ClickSave(wxCommandEvent&)
{
m_plugin.SaveConfig();
Close();
@ -197,7 +199,7 @@ void ControlDialog::UpdateListContents()
{
control_lbox->Clear();
ControllerInterface::Device* const dev = m_plugin.controller_interface.FindDevice(m_devq);
ControllerInterface::Device* const dev = g_controller_interface.FindDevice(m_devq);
if (dev)
{
if (control_reference->is_input)
@ -268,7 +270,7 @@ void GamepadPage::UpdateGUI()
}
}
void GamepadPage::ClearAll( wxCommandEvent& event )
void GamepadPage::ClearAll(wxCommandEvent&)
{
// just load an empty ini section to clear everything :P
IniFile::Section section;
@ -284,29 +286,29 @@ void GamepadPage::ClearAll( wxCommandEvent& event )
UpdateGUI();
}
void GamepadPage::LoadDefaults( wxCommandEvent& event )
void GamepadPage::LoadDefaults(wxCommandEvent&)
{
controller->LoadDefaults(m_plugin.controller_interface);
controller->LoadDefaults(g_controller_interface);
m_plugin.controls_crit.Enter(); // enter
controller->UpdateReferences(m_plugin.controller_interface);
controller->UpdateReferences(g_controller_interface);
m_plugin.controls_crit.Leave(); // leave
UpdateGUI();
}
void ControlDialog::SetControl( wxCommandEvent& event )
void ControlDialog::SetControl(wxCommandEvent&)
{
control_reference->expression = STR_FROM_WXSTR(textctrl->GetValue());
m_plugin.controls_crit.Enter(); // enter
m_plugin.controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
m_plugin.controls_crit.Leave(); // leave
UpdateGUI();
}
void GamepadPage::SetDevice( wxCommandEvent& event )
void GamepadPage::SetDevice(wxCommandEvent&)
{
controller->default_device.FromString(STR_FROM_WXSTR(device_cbox->GetValue()));
@ -318,11 +320,11 @@ void GamepadPage::SetDevice( wxCommandEvent& event )
// update references
m_plugin.controls_crit.Enter(); // enter
controller->UpdateReferences( m_plugin.controller_interface );
controller->UpdateReferences( g_controller_interface );
m_plugin.controls_crit.Leave(); // leave
}
void ControlDialog::SetDevice( wxCommandEvent& event )
void ControlDialog::SetDevice(wxCommandEvent&)
{
m_devq.FromString(STR_FROM_WXSTR(device_cbox->GetValue()));
@ -333,18 +335,18 @@ void ControlDialog::SetDevice( wxCommandEvent& event )
UpdateListContents();
}
void ControlDialog::ClearControl(wxCommandEvent& event)
void ControlDialog::ClearControl(wxCommandEvent&)
{
control_reference->expression.clear();
m_plugin.controls_crit.Enter(); // enter
m_plugin.controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
m_plugin.controls_crit.Leave(); // leave
UpdateGUI();
}
void ControlDialog::SetSelectedControl(wxCommandEvent& event)
void ControlDialog::SetSelectedControl(wxCommandEvent&)
{
const int num = control_lbox->GetSelection();
@ -363,7 +365,7 @@ void ControlDialog::SetSelectedControl(wxCommandEvent& event)
control_reference->expression = STR_FROM_WXSTR(expr);
m_plugin.controls_crit.Enter(); // enter
m_plugin.controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
m_plugin.controls_crit.Leave(); // leave
UpdateGUI();
@ -395,7 +397,7 @@ void ControlDialog::AppendControl(wxCommandEvent& event)
control_reference->expression = STR_FROM_WXSTR(expr);
m_plugin.controls_crit.Enter(); // enter
m_plugin.controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
g_controller_interface.UpdateReference(control_reference, m_parent->controller->default_device);
m_plugin.controls_crit.Leave(); // leave
UpdateGUI();
@ -408,7 +410,7 @@ void GamepadPage::AdjustSetting( wxCommandEvent& event )
m_plugin.controls_crit.Leave(); // leave
}
void GamepadPage::AdjustControlOption( wxCommandEvent& event )
void GamepadPage::AdjustControlOption(wxCommandEvent&)
{
m_plugin.controls_crit.Enter(); // enter / prolly fine not being here
m_control_dialog->control_reference->range = (ControlState)(m_control_dialog->range_slider->GetValue()) / SLIDER_TICK_COUNT;
@ -432,7 +434,7 @@ void GamepadPage::ClearControl( wxCommandEvent& event )
btn->control_reference->range = 1.0f;
m_plugin.controls_crit.Enter(); // enter
controller->UpdateReferences( m_plugin.controller_interface );
controller->UpdateReferences( g_controller_interface );
m_plugin.controls_crit.Leave(); // leave
// update changes
@ -444,7 +446,7 @@ void ControlDialog::DetectControl(wxCommandEvent& event)
wxButton* const btn = (wxButton*)event.GetEventObject();
const wxString lbl = btn->GetLabel();
ControllerInterface::Device* const dev = m_plugin.controller_interface.FindDevice(m_devq);
ControllerInterface::Device* const dev = g_controller_interface.FindDevice(m_devq);
if (dev)
{
btn->SetLabel(wxT("[ waiting ]"));
@ -469,7 +471,7 @@ void GamepadPage::DetectControl( wxCommandEvent& event )
ControlButton* btn = (ControlButton*)event.GetEventObject();
// find device :/
ControllerInterface::Device* const dev = m_plugin.controller_interface.FindDevice(controller->default_device);
ControllerInterface::Device* const dev = g_controller_interface.FindDevice(controller->default_device);
if (dev)
{
btn->SetLabel(wxT("[ waiting ]"));
@ -484,7 +486,7 @@ void GamepadPage::DetectControl( wxCommandEvent& event )
if (ctrl)
{
btn->control_reference->expression = ctrl->GetName();
m_plugin.controller_interface.UpdateReference(btn->control_reference, controller->default_device);
g_controller_interface.UpdateReference(btn->control_reference, controller->default_device);
}
m_plugin.controls_crit.Leave(); // leave
@ -585,7 +587,7 @@ void GamepadPage::GetProfilePath(std::string& path)
}
}
void GamepadPage::LoadProfile(wxCommandEvent& event)
void GamepadPage::LoadProfile(wxCommandEvent&)
{
std::string fname;
GamepadPage::GetProfilePath(fname);
@ -598,13 +600,13 @@ void GamepadPage::LoadProfile(wxCommandEvent& event)
m_plugin.controls_crit.Enter();
controller->LoadConfig(inifile.GetOrCreateSection("Profile"));
controller->UpdateReferences(m_plugin.controller_interface);
controller->UpdateReferences(g_controller_interface);
m_plugin.controls_crit.Leave();
UpdateGUI();
}
void GamepadPage::SaveProfile(wxCommandEvent& event)
void GamepadPage::SaveProfile(wxCommandEvent&)
{
std::string fname;
GamepadPage::GetProfilePath(fname);
@ -622,7 +624,7 @@ void GamepadPage::SaveProfile(wxCommandEvent& event)
PanicAlert("You must enter a valid profile name.");
}
void GamepadPage::DeleteProfile(wxCommandEvent& event)
void GamepadPage::DeleteProfile(wxCommandEvent&)
{
std::string fname;
GamepadPage::GetProfilePath(fname);
@ -647,8 +649,8 @@ void InputConfigDialog::UpdateDeviceComboBox()
{
(*i)->device_cbox->Clear();
std::vector<ControllerInterface::Device*>::const_iterator
di = m_plugin.controller_interface.Devices().begin(),
de = m_plugin.controller_interface.Devices().end();
di = g_controller_interface.Devices().begin(),
de = g_controller_interface.Devices().end();
for ( ; di!=de; ++di )
{
dq.FromDevice( *di );
@ -658,14 +660,13 @@ void InputConfigDialog::UpdateDeviceComboBox()
}
}
void GamepadPage::RefreshDevices( wxCommandEvent& event )
void GamepadPage::RefreshDevices(wxCommandEvent&)
{
m_plugin.controls_crit.Enter(); // enter
// refresh devices
// TODO: remove hackery of not deinting SDL
m_plugin.controller_interface.DeInit(true);
m_plugin.controller_interface.Init();
g_controller_interface.Shutdown();
g_controller_interface.Initialize();
// update all control references
m_config_dialog->UpdateControlReferences();
@ -835,6 +836,7 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi
Add(configure_btn, 0, wxALL|wxEXPAND, 3 );
}
break;
#ifdef USE_UDP_WIIMOTE
case GROUP_TYPE_UDPWII:
{
wxButton* const btn = new UDPConfigButton( parent, (UDPWrapper*)group );
@ -842,6 +844,7 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi
Add(btn, 0, wxALL|wxEXPAND, 3);
}
break;
#endif
default:
{
//options

View file

@ -146,6 +146,7 @@ public:
ControllerInterface::ControlReference* const control_reference;
};
#ifdef USE_UDP_WIIMOTE
class UDPConfigButton : public wxButton
{
@ -157,6 +158,8 @@ public:
{}
};
#endif
class ControlGroupBox : public wxStaticBoxSizer
{
public:

View file

@ -15,15 +15,15 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include "ConfigDiag.h"
#include "InputConfigDiag.h"
void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
{
wxFont small_font(6, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
m_plugin.controller_interface.UpdateInput();
g_controller_interface.UpdateInput();
// don't want game thread updating input when we are using it here
if (false == m_plugin.controller_interface.update_lock.TryEnter())
if (false == g_controller_interface.update_lock.TryEnter())
return;
GamepadPage* const current_page = (GamepadPage*)m_pad_notebook->GetPage(m_pad_notebook->GetSelection());
@ -345,5 +345,5 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
}
}
m_plugin.controller_interface.update_lock.Leave();
g_controller_interface.update_lock.Leave();
}

View file

@ -32,6 +32,7 @@
#include "Host.h" // Core
#include "PluginManager.h"
#include "HW/Wiimote.h"
#include "Globals.h" // Local
#include "Main.h"
@ -336,6 +337,7 @@ bool DolphinApp::OnInit()
LogManager::Init();
SConfig::Init();
CPluginManager::Init();
WiimoteReal::LoadSettings();
if (selectVideoPlugin && videoPluginFilename != wxEmptyString)
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin =
@ -345,10 +347,6 @@ bool DolphinApp::OnInit()
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin =
std::string(audioPluginFilename.mb_str());
if (selectWiimotePlugin && wiimotePluginFilename != wxEmptyString)
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin =
std::string(wiimotePluginFilename.mb_str());
// Enable the PNG image handler for screenshots
wxImage::AddHandler(new wxPNGHandler);
@ -432,12 +430,10 @@ void DolphinApp::OnEndSession()
int DolphinApp::OnExit()
{
WiimoteReal::Shutdown();
#ifdef _WIN32
if (SConfig::GetInstance().m_WiiAutoUnpair)
{
if (CPluginManager::GetInstance().GetWiimote())
CPluginManager::GetInstance().GetWiimote()->Wiimote_UnPairWiimotes();
}
WiimoteReal::UnPair();
#endif
CPluginManager::Shutdown();
SConfig::Shutdown();

View file

@ -392,6 +392,7 @@ int main(int argc, char* argv[])
}
updateMainFrameEvent.Shutdown();
WiimoteReal::Shutdown();
CPluginManager::Shutdown();
SConfig::Shutdown();
LogManager::Shutdown();

View file

@ -33,6 +33,8 @@ if env['HAVE_WX']:
'LogWindow.cpp',
'GameListCtrl.cpp',
'HotkeyDlg.cpp',
'InputConfigDiag.cpp',
'InputConfigDiagBitmaps.cpp',
'ISOFile.cpp',
'ISOProperties.cpp',
'PatchAddEdit.cpp',
@ -43,6 +45,7 @@ if env['HAVE_WX']:
'NetPlayClient.cpp',
'NetPlayServer.cpp',
'NetWindow.cpp',
'WiimoteConfigDiag.cpp',
]
wxlibs = [ 'debwx', 'debugger_ui_util', 'inputuicommon', 'memcard' ]
@ -96,8 +99,6 @@ elif sys.platform == 'darwin' and env['HAVE_WX']:
env.Depends(exeGUIdist, env['plugin_dir'])
env.Fixup(exeGUIdist, exeGUI)
else:
files += [ 'X11Utils.cpp' ]
libs += [ 'SDL' ]
exeGUI = env['binary_dir'] + '/dolphin-emu'
exeNoGUI = env['binary_dir'] + '/dolphin-emu-nogui'
env.InstallAs(env['data_dir'] + '/sys', '#Data/Sys')

View file

@ -0,0 +1,153 @@
#include "WiimoteConfigDiag.h"
#include "HW/Wiimote.h"
#define _connect_macro_(b, f, c, s) (b)->Connect(wxID_ANY, (c), wxCommandEventHandler( f ), (wxObject*)0, (wxEvtHandler*)s)
const wxString& ConnectedWiimotesString()
{
static wxString str = wxT("Connected to . Wiimotes");
str[13] = wxChar(wxT('0') + WiimoteReal::Initialize());
return str;
}
WiimoteConfigPage::WiimoteConfigPage(wxWindow* const parent, const int index)
: wxNotebookPage(parent, -1, wxDefaultPosition, wxDefaultSize)
, m_index(index)
{
// input source
const wxString src_choices[] = { wxT("None"),
wxT("Emulated Wiimote"), wxT("Real Wiimote"), wxT("Hybrid Wiimote") };
wxChoice* const input_src_choice = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize,
sizeof(src_choices)/sizeof(*src_choices), src_choices);
input_src_choice->Select(g_wiimote_sources[m_index]);
_connect_macro_(input_src_choice, WiimoteConfigPage::SelectSource, wxEVT_COMMAND_CHOICE_SELECTED, this);
wxStaticBoxSizer* const input_src_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("Input Source"));
input_src_sizer->Add(input_src_choice, 1, wxEXPAND | wxALL, 5);
// emulated wiimote
wxButton* const configure_wiimote_emu_btn = new wxButton(this, -1, wxT("Configure"));
wxStaticBoxSizer* const wiimote_emu_sizer = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("Emulated Wiimote"));
wiimote_emu_sizer->Add(configure_wiimote_emu_btn, 1, wxEXPAND | wxALL, 5);
_connect_macro_(configure_wiimote_emu_btn, WiimoteConfigDiag::ConfigEmulatedWiimote, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
// real wiimote
connected_wiimotes_txt = new wxStaticText(this, -1, ConnectedWiimotesString());
wxButton* const refresh_btn = new wxButton(this, -1, wxT("Refresh"), wxDefaultPosition);
_connect_macro_(refresh_btn, WiimoteConfigDiag::RefreshRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
wxStaticBoxSizer* const wiimote_real_sizer = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Real Wiimote"));
wiimote_real_sizer->AddStretchSpacer(1);
wiimote_real_sizer->Add(connected_wiimotes_txt, 0, wxALIGN_CENTER | wxBOTTOM | wxLEFT | wxRIGHT, 5);
#ifdef _WIN32
wxButton* const pairup_btn = new wxButton(this, -1, wxT("Pair Up"), wxDefaultPosition);
_connect_macro_(pairup_btn, WiimoteConfigDiag::PairUpRealWiimotes, wxEVT_COMMAND_BUTTON_CLICKED, parent->GetParent());
wiimote_real_sizer->Add(pairup_btn, 0, wxALIGN_CENTER | wxBOTTOM, 5);
#endif
wiimote_real_sizer->Add(refresh_btn, 0, wxALIGN_CENTER, 5);
wiimote_real_sizer->AddStretchSpacer(1);
// sizers
wxBoxSizer* const left_sizer = new wxBoxSizer(wxVERTICAL);
left_sizer->Add(input_src_sizer, 0, wxEXPAND | wxBOTTOM, 5);
left_sizer->Add(wiimote_emu_sizer, 0, wxEXPAND, 0);
wxBoxSizer* const main_sizer = new wxBoxSizer(wxHORIZONTAL);
main_sizer->Add(left_sizer, 1, wxLEFT | wxTOP | wxBOTTOM | wxEXPAND, 5);
main_sizer->Add(wiimote_real_sizer, 1, wxALL | wxEXPAND, 5);
SetSizerAndFit(main_sizer);
Layout();
}
WiimoteConfigDiag::WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin)
: wxDialog(parent, -1, wxT("Dolphin Wiimote Configuration"), wxDefaultPosition, wxDefaultSize)
, m_plugin(plugin)
{
m_pad_notebook = new wxNotebook(this, -1, wxDefaultPosition, wxDefaultSize, wxNB_DEFAULT);
for (unsigned int i = 0; i < 4; ++i)
{
WiimoteConfigPage* const wpage = new WiimoteConfigPage(m_pad_notebook, i);
//m_padpages.push_back(wpage);
m_pad_notebook->AddPage(wpage, wxString(wxT("Wiimote ")) + wxChar('1'+i));
}
wxButton* const ok_button = new wxButton(this, -1, wxT("OK"), wxDefaultPosition);
_connect_macro_(ok_button, WiimoteConfigDiag::Save, wxEVT_COMMAND_BUTTON_CLICKED, this);
wxBoxSizer* const main_sizer = new wxBoxSizer(wxVERTICAL);
main_sizer->Add(m_pad_notebook, 1, wxEXPAND | wxALL, 5);
main_sizer->Add(ok_button, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 5);
SetSizerAndFit(main_sizer);
Center();
}
void WiimoteConfigDiag::ConfigEmulatedWiimote(wxCommandEvent&)
{
InputConfigDialog* const m_emu_config_diag = new InputConfigDialog(this, m_plugin, "Dolphin Emulated Wiimote Configuration", m_pad_notebook->GetSelection());
m_emu_config_diag->ShowModal();
m_emu_config_diag->Destroy();
}
void WiimoteConfigDiag::UpdateGUI()
{
for (size_t p = 0; p < m_pad_notebook->GetPageCount(); ++p)
((WiimoteConfigPage*)m_pad_notebook->GetPage(p))->
connected_wiimotes_txt->SetLabel(ConnectedWiimotesString());
}
#ifdef _WIN32
void WiimoteConfigDiag::PairUpRealWiimotes(wxCommandEvent&)
{
const int paired = WiimoteReal::PairUp();
if (paired > 0)
{
// Will this message be anoying?
//PanicAlert("Paired %d wiimotes.", paired);
WiimoteReal::Refresh();
UpdateGUI();
}
else if (paired < 0)
PanicAlert("A supported bluetooth device was not found!\n"
"(Only the Microsoft bluetooth stack is supported.)");
}
#endif
void WiimoteConfigDiag::RefreshRealWiimotes(wxCommandEvent&)
{
WiimoteReal::Refresh();
UpdateGUI();
}
void WiimoteConfigPage::SelectSource(wxCommandEvent& event)
{
// should be kinda fine, maybe should just set when user clicks OK, w/e change it later
g_wiimote_sources[m_index] = event.GetInt();
}
void WiimoteConfigDiag::Save(wxCommandEvent&)
{
std::string ini_filename = (std::string(File::GetUserPath(D_CONFIG_IDX)) + WIIMOTE_INI_NAME ".ini" );
IniFile inifile;
inifile.Load(ini_filename);
for (unsigned int i=0; i<MAX_WIIMOTES; ++i)
{
std::string secname("Wiimote");
secname += (char)('1' + i);
IniFile::Section& sec = *inifile.GetOrCreateSection(secname.c_str());
sec.Set("Source", (int)g_wiimote_sources[i]);
}
inifile.Save(ini_filename);
Close();
}

View file

@ -0,0 +1,53 @@
#ifndef WIIMOTE_CONFIG_DIAG_H
#define WIIMOTE_CONFIG_DIAG_H
#include <wx/wx.h>
#include <wx/listbox.h>
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/stattext.h>
#include <wx/combobox.h>
#include <wx/checkbox.h>
#include <wx/notebook.h>
#include <wx/panel.h>
#include <wx/spinctrl.h>
#include "InputConfigDiag.h"
class WiimoteConfigPage : public wxNotebookPage
{
public:
WiimoteConfigPage(wxWindow* const parent, const int index);
void SelectSource(wxCommandEvent& event);
wxStaticText* connected_wiimotes_txt;
private:
const int m_index;
};
class WiimoteConfigDiag : public wxDialog
{
public:
WiimoteConfigDiag(wxWindow* const parent, InputPlugin& plugin);
#ifdef _WIN32
void PairUpRealWiimotes(wxCommandEvent& event);
#endif
void RefreshRealWiimotes(wxCommandEvent& event);
void ConfigEmulatedWiimote(wxCommandEvent& event);
void Save(wxCommandEvent& event);
void UpdateGUI();
private:
InputPlugin& m_plugin;
wxNotebook* m_pad_notebook;
};
#endif

View file

@ -66,6 +66,8 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="xinput.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -131,6 +133,8 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="xinput.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -197,6 +201,8 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="xinput.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -264,7 +270,9 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="xinput.lib"
OutputFile="$(OutDir)\$(ProjectName).lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -326,6 +334,8 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="xinput.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -388,6 +398,8 @@
/>
<Tool
Name="VCLibrarianTool"
AdditionalDependencies="xinput.lib"
AdditionalLibraryDirectories="&quot;..\..\..\Externals\SDL\$(PlatformName)&quot;"
/>
<Tool
Name="VCALinkTool"
@ -477,10 +489,6 @@
</File>
</Filter>
</Filter>
<File
RelativePath=".\Src\Configuration.cpp"
>
</File>
<File
RelativePath=".\Src\ControllerEmu.cpp"
>
@ -489,22 +497,10 @@
RelativePath=".\Src\ControllerEmu.h"
>
</File>
<File
RelativePath=".\Src\DirectInputBase.cpp"
>
</File>
<File
RelativePath=".\Src\DirectInputBase.h"
>
</File>
<File
RelativePath=".\Src\GCPadStatus.h"
>
</File>
<File
RelativePath=".\Src\InputCommon.h"
>
</File>
<File
RelativePath=".\Src\InputConfig.cpp"
>
@ -517,14 +513,6 @@
RelativePath=".\Src\SConscript"
>
</File>
<File
RelativePath=".\Src\SDL_Util.cpp"
>
</File>
<File
RelativePath=".\Src\SDL_Util.h"
>
</File>
<File
RelativePath=".\Src\UDPWiimote.cpp"
>
@ -541,14 +529,6 @@
RelativePath=".\Src\UDPWrapper.h"
>
</File>
<File
RelativePath=".\Src\XInput_Util.cpp"
>
</File>
<File
RelativePath=".\Src\XInput_Util.h"
>
</File>
</Files>
<Globals>
</Globals>

View file

@ -1,253 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// 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 <iostream> // System
#include <vector>
#include <cmath>
#include "Common.h" // Common
#if defined HAVE_WX && HAVE_WX
#include <wx/wx.h>
#endif
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#endif
namespace InputCommon
{
// Degree to radian and back
float Deg2Rad(float Deg)
{
return Deg * (float)M_PI / 180.0f;
}
float Rad2Deg(float Rad)
{
return Rad * 180.0f / (float)M_PI;
}
// Check if the pad is within the dead zone, we assume the range is 0x8000
float CoordinatesToRadius(int x, int y)
{
return sqrt(pow((float)x, 2) + pow((float)y, 2));
}
bool IsDeadZone(float DeadZone, int x, int y)
{
// Get the distance from the center
float Distance = CoordinatesToRadius(x, y) / 32767.0f;
//Console::Print("%f\n", Distance);
// Check if it's within the dead zone
if (Distance <= DeadZone)
return true;
else
return false;
}
// Scale down stick values from 0x8000 to 0x80
/*
The value returned by SDL_JoystickGetAxis is a signed integer s16 (-32768 to
32767). The value used for the gamecube controller is an unsigned char u8 (0
to 255) with neutral at 0x80 (128), so that it's equivalent to a signed -128
to 127. */
//
int Pad_Convert(int _val)
{
/* If the limits on PadState[].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
// Convert the range (-0x8000 to 0x7fff) to (0 to 0xffff)
_val = 0x8000 +_val;
// Convert the range (0 to 0xffff) to (0 to 0xff)
_val = _val >> 8;
//Console::Print("0x%04x %06i\n\n", _val, _val);
return _val;
}
// Adjust the radius
void RadiusAdjustment(s8 &_x, s8 &_y, int _Radius)
{
// Get the radius setting
float RadiusSetting = (float)_Radius / 100.0f;
float x = (float)_x * RadiusSetting;
float y = (float)_y * RadiusSetting;
// Update values
_x = (s8)x;
_y = (s8)y;
}
/* Convert the stick raidus from a square or rounded box to a circular
radius. 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%
PS2 Dual Shock 2 (Original) with Super Dual Box Pro: 90%
XBox 360 Wireless: 85%
GameCube Controller (Third Party) with EMS Trio Linker Plus II: 60%
*/
/* Calculate the distance from the outer edges of the box to the outer edges of
the circle inside the box at any angle from 0 to 360. The returned value is
1 + Distance, for example at most sqrt(2) in the corners and at least 1.0 at
the horizontal and vertical angles. */
float Square2CircleDistance(float deg)
{
// See if we have to adjust the angle
deg = fabsf(deg);
if( (deg > 45 && deg < 135) ) deg = deg - 90;
// Calculate distance from center
float val = fabsf(cos(Deg2Rad(deg)));
float Distance = 1 / val;
//m_frame->m_pStatusBar2->SetLabel(wxString::Format("Deg:%f Val:%f Dist:%f", deg, val, dist));
return Distance;
}
// Produce a perfect circle from an original square or rounded box
void Square2Circle(int &_x, int &_y, int _Diagonal, bool Circle2Square)
{
// Do we need to do this check?
if(_x > 32767) _x = 32767; if(_y > 32767) _y = 32767; // upper limit
if(_x < -32768) _x = -32768; if(_y < -32768) _y = -32768; // lower limit
// Convert to circle
// Get the manually configured diagonal distance
float Diagonal = (float)_Diagonal / 100.0f;
// 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 deg = Rad2Deg(atan2((float)_y, (float)_x)); // Get current angle
/* Calculate the actual distance between the maxium diagonal values, and
the outer edges of the square. A diagonal of 85% means a maximum
distance of 0.85 * sqrt(2) ~1.2 in the diagonals. */
float corner_circle_dist = ( Diagonal / sin(Deg2Rad(45.0f)) );
float SquareDist = Square2CircleDistance(deg);
// The original-to-square distance adjustment
float adj_ratio1;
// The circle-to-square distance adjustment
float adj_ratio2 = SquareDist;
// The resulting distance
float result_dist;
// 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
if(Circle2Square)
result_dist = OrigDist * adj_ratio1;
else
result_dist = OrigDist * adj_ratio1 / adj_ratio2;
// Calculate x and y and return it
float x = result_dist * cos(Deg2Rad(deg));
float y = result_dist * sin(Deg2Rad(deg));
// Update coordinates
_x = (int)floor(x);
_y = (int)floor(y);
// Boundaries
if (_x < -32768) _x = -32768; if (_x > 32767) _x = 32767;
if (_y < -32768) _y = -32768; if (_y > 32767) _y = 32767;
// Debugging
//Console::Print("%f %f %i", corner_circle_dist, Diagonal, Tmp));
}
// Windows Virtual Key Codes Names
#ifdef _WIN32
std::string VKToString(int keycode)
{
// Default value
char KeyStr[64] = {0};
std::string KeyString;
switch(keycode)
{
// Give it some help with a few keys
case VK_END: return "END";
case VK_INSERT: return "INS";
case VK_DELETE: return "DEL";
case VK_HOME: return "HOME";
case VK_PRIOR: return "PGUP";
case VK_NEXT: return "PGDN";
case VK_UP: return "UP";
case VK_DOWN: return "DOWN";
case VK_LEFT: return "LEFT";
case VK_RIGHT: return "RIGHT";
case VK_LSHIFT: return "Left Shift";
case VK_RSHIFT: return "Right Shift";
case VK_LCONTROL: return "Left Ctrl";
case VK_RCONTROL: return "Right Ctrl";
case VK_LMENU: return "Left Alt";
case VK_RMENU: return "Right Alt";
case VK_NUMLOCK: return "Num Lock";
case VK_MULTIPLY: return "Num *";
case VK_ADD: return "Num +";
case VK_SEPARATOR: case 0xC2: return "Num Separator";
case VK_SUBTRACT: return "Num -";
case VK_DECIMAL: return "Num Decimal";
case VK_DIVIDE: return "Num /";
case VK_OEM_PLUS: return "=";
case VK_OEM_MINUS: return "-";
case VK_OEM_COMMA: return ",";
case VK_OEM_PERIOD: return ".";
case VK_BROWSER_BACK: return "Nav Bwd";
case VK_BROWSER_FORWARD: return "Nav Fwd";
//default: return KeyString = KeyStr;
}
// TODO: Switch to unicode GetKeyNameText?
if (keycode < 256) // Keyboard
GetKeyNameTextA(MapVirtualKey(keycode, MAPVK_VK_TO_VSC) << 16, KeyStr, 64);
else // Pad
sprintf(KeyStr, "PAD: %d", keycode - 0x1000);
return KeyString = KeyStr;
}
#endif
}

View file

@ -298,9 +298,8 @@ ControllerEmu::Tilt::Tilt( const char* const _name )
settings.push_back( new Setting("Circle Stick", 0 ) );
}
ControllerEmu::Cursor::Cursor( const char* const _name, const SWiimoteInitialize* const _wiimote_initialize )
: ControlGroup( _name, GROUP_TYPE_CURSOR )
, wiimote_initialize(_wiimote_initialize)
ControllerEmu::Cursor::Cursor(const char* const _name)
: ControlGroup(_name, GROUP_TYPE_CURSOR)
, m_z(0)
{
for ( unsigned int i = 0; i < 4; ++i )

View file

@ -27,7 +27,6 @@
#include <algorithm>
#include "GCPadStatus.h"
#include "pluginspecs_wiimote.h"
#include "ControllerInterface/ControllerInterface.h"
#include "IniFile.h"
@ -374,7 +373,7 @@ public:
class Cursor : public ControlGroup
{
public:
Cursor( const char* const _name, const SWiimoteInitialize* const _wiimote_initialize );
Cursor(const char* const _name);
template <typename C>
void GetState( C* const x, C* const y, C* const z, const bool adjusted = false )
@ -412,9 +411,6 @@ public:
}
}
private:
const SWiimoteInitialize* const wiimote_initialize;
float m_z;
};

View file

@ -20,14 +20,16 @@
#define INPUT_DETECT_THRESHOLD 0.85
ControllerInterface g_controller_interface;
//
// Init
//
// detect devices and inputs outputs / will make refresh function later
//
void ControllerInterface::Init()
void ControllerInterface::Initialize()
{
if ( m_is_init )
if (m_is_init)
return;
#ifdef CIFACE_USE_DINPUT
@ -54,9 +56,9 @@ void ControllerInterface::Init()
//
// remove all devices/ call library cleanup functions
//
void ControllerInterface::DeInit(const bool hacks_no_sdl_quit)
void ControllerInterface::Shutdown()
{
if ( false == m_is_init )
if (false == m_is_init)
return;
std::vector<Device*>::const_iterator
@ -73,12 +75,6 @@ void ControllerInterface::DeInit(const bool hacks_no_sdl_quit)
// update output
(*d)->UpdateOutput();
// TODO: remove this
// major hacks/memleaks to prevent gcpad/wiimote new from crashing eachother
if (hacks_no_sdl_quit)
if ((*d)->GetSource() == "SDL")
continue;
//delete device
delete *d;
}
@ -99,8 +95,7 @@ void ControllerInterface::DeInit(const bool hacks_no_sdl_quit)
#endif
#ifdef CIFACE_USE_SDL
// TODO: there seems to be some sort of memory leak with SDL, quit isn't freeing everything up
if (false == hacks_no_sdl_quit)
SDL_Quit();
SDL_Quit();
#endif
m_is_init = false;

View file

@ -210,9 +210,9 @@ public:
ControllerInterface() : m_is_init(false), m_hwnd(NULL) {}
void SetHwnd(void* const hwnd);
void Init();
void Initialize();
// TODO: remove this hack param
void DeInit(const bool hacks_no_sdl_quit = false);
void Shutdown();
bool IsInit() const { return m_is_init; }
void UpdateReference(ControlReference* control, const DeviceQualifier& default_device) const;
@ -230,4 +230,6 @@ private:
void* m_hwnd;
};
extern ControllerInterface g_controller_interface;
#endif

View file

@ -1,229 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// 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
// -------------------
#include "DirectInputBase.h"
DInput::DInput()
: g_pDI(NULL),
g_pKeyboard(NULL)
{}
DInput::~DInput()
{
Free();
}
void DInput::DIKToString(unsigned int keycode, char *keyStr)
{
switch(keycode) {
case DIK_RETURN:
sprintf(keyStr, "Enter");
break;
case DIK_LCONTROL:
sprintf(keyStr, "Left Ctrl");
break;
case DIK_RCONTROL:
strcpy(keyStr, "Right Ctrl");
break;
case DIK_LSHIFT:
sprintf(keyStr, "Left Shift");
break;
case DIK_RSHIFT:
sprintf(keyStr, "Right Shift");
break;
case DIK_LMENU:
sprintf(keyStr, "Left Alt");
break;
case DIK_RMENU:
strcpy(keyStr, "Right Alt");
break;
case DIK_UP:
sprintf(keyStr, "Up");
break;
case DIK_DOWN:
sprintf(keyStr, "Down");
break;
case DIK_LEFT:
sprintf(keyStr, "Left");
break;
case DIK_RIGHT:
sprintf(keyStr, "Right");
break;
case DIK_HOME:
strcpy(keyStr, "Home");
break;
case DIK_END:
strcpy(keyStr, "End");
break;
case DIK_INSERT:
strcpy(keyStr, "Ins");
break;
case DIK_DELETE:
strcpy(keyStr, "Del");
break;
case DIK_PGUP:
strcpy(keyStr, "PgUp");
break;
case DIK_PGDN:
strcpy(keyStr, "PgDn");
break;
case DIK_NUMLOCK:
strcpy(keyStr, "Num Lock");
break;
case DIK_NUMPAD0:
strcpy(keyStr, "Num 0");
break;
case DIK_NUMPAD1:
strcpy(keyStr, "Num 1");
break;
case DIK_NUMPAD2:
strcpy(keyStr, "Num 2");
break;
case DIK_NUMPAD3:
strcpy(keyStr, "Num 3");
break;
case DIK_NUMPAD4:
strcpy(keyStr, "Num 4");
break;
case DIK_NUMPAD5:
strcpy(keyStr, "Num 5");
break;
case DIK_NUMPAD6:
strcpy(keyStr, "Num 6");
break;
case DIK_NUMPAD7:
strcpy(keyStr, "Num 7");
break;
case DIK_NUMPAD8:
strcpy(keyStr, "Num 8");
break;
case DIK_NUMPAD9:
strcpy(keyStr, "Num 9");
break;
case DIK_DIVIDE:
strcpy(keyStr, "Num /");
break;
case DIK_NUMPADENTER:
strcpy(keyStr, "Num Enter");
break;
case DIK_DECIMAL:
strcpy(keyStr, "Num Decimal");
break;
case DIK_NUMPADCOMMA:
case DIK_ABNT_C2:
strcpy(keyStr, "Num Separator");
break;
case DIK_NUMPADEQUALS:
strcpy(keyStr, "Num =");
break;
default:
// TODO: Switch to unicode GetKeyNameText?
GetKeyNameTextA(keycode << 16, keyStr, 64);
break;
}
}
HRESULT DInput::Init(HWND hWnd)
{
HRESULT hr;
DWORD dwCoopFlags;
dwCoopFlags = DISCL_FOREGROUND | DISCL_NOWINKEY;
// Create a DInput object
if (FAILED(hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID* *)&g_pDI, NULL)))
{
MessageBox(0, L"Direct Input Create Failed", 0, MB_ICONERROR);
return(hr);
}
if (FAILED(hr = g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKeyboard, NULL)))
{
MessageBox(0, L"Couldn't access keyboard", 0, MB_ICONERROR);
Free();
return(hr);
}
g_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
g_pKeyboard->SetCooperativeLevel(hWnd, dwCoopFlags);
g_pKeyboard->Acquire();
return(S_OK);
}
void DInput::Free()
{
if (g_pKeyboard)
{
g_pKeyboard->Unacquire();
g_pKeyboard->Release();
g_pKeyboard = 0;
}
if (g_pDI)
{
g_pDI->Release();
g_pDI = 0;
}
}
// Desc: Read the input device's state when in immediate mode and display it.
HRESULT DInput::Read()
{
HRESULT hr;
if (NULL == g_pKeyboard)
{
return(S_OK);
}
// Get the input's device state, and put the state in dims
ZeroMemory(diks, sizeof(diks));
hr = g_pKeyboard->GetDeviceState(sizeof(diks), diks);
//for (int i=0; i<256; i++)
// if (diks[i]) MessageBox(0,"DSFJDKSF|",0,0);
if (FAILED(hr))
{
// DirectInput may be telling us that the input stream has been
// interrupted. We aren't tracking any state between polls, so
// we don't have any special reset that needs to be done.
// We just re-acquire and try again.
// If input is lost then acquire and keep trying
hr = g_pKeyboard->Acquire();
while (hr == DIERR_INPUTLOST)
{
hr = g_pKeyboard->Acquire();
}
// hr may be DIERR_OTHERAPPHASPRIO or other errors. This
// may occur when the app is minimized or in the process of
// switching, so just try again later
return(S_OK);
}
return(S_OK);
}

View file

@ -1,23 +0,0 @@
namespace InputCommon
{
enum EButtonType
{
CTL_AXIS = 0,
CTL_HAT,
CTL_BUTTON,
CTL_KEY,
};
enum ETriggerType
{
CTL_TRIGGER_SDL = 0,
CTL_TRIGGER_XINPUT,
};
enum EXInputTrigger
{
XI_TRIGGER_L = 0,
XI_TRIGGER_R,
};
}

View file

@ -17,19 +17,6 @@
#include "InputConfig.h"
InputPlugin::InputPlugin( const char* const _ini_name, const char* const _gui_name, const char* const _profile_name )
: ini_name(_ini_name)
, gui_name(_gui_name)
, profile_name(_profile_name)
{
// GCPads
//for ( unsigned int i = 0; i<4; ++i )
//controllers.push_back( new GCPad( i ) );
// Wiimotes / disabled, cause it only the GUI half is done
//for ( unsigned int i = 0; i<4; ++i )
// controllers.push_back( new Wiimote( i ) );
};
InputPlugin::~InputPlugin()
{
// delete pads
@ -52,14 +39,14 @@ bool InputPlugin::LoadConfig()
// load settings from ini
(*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
// update refs
(*i)->UpdateReferences(controller_interface);
(*i)->UpdateReferences(g_controller_interface);
}
return true;
}
else
{
controllers[0]->LoadDefaults(controller_interface);
controllers[0]->UpdateReferences(controller_interface);
controllers[0]->LoadDefaults(g_controller_interface);
controllers[0]->UpdateReferences(g_controller_interface);
return false;
}
}

View file

@ -30,13 +30,16 @@
#include <map>
#include <sstream>
// InputPlugin isn't a very good name anymore since it's also used for GCPad which
// will soon not even be a plugin anymore.
// InputPlugin isn't a very good name anymore since it's used by GCPad/Wiimote
// which are not even plugins anymore.
class InputPlugin
{
public:
InputPlugin( const char* const _ini_name, const char* const _gui_name, const char* const _profile_name );
InputPlugin(const char* const _ini_name, const char* const _gui_name,
const char* const _profile_name)
: ini_name(_ini_name), gui_name(_gui_name), profile_name(_profile_name) {}
~InputPlugin();
bool LoadConfig();
@ -44,8 +47,7 @@ public:
std::vector< ControllerEmu* > controllers;
Common::CriticalSection controls_crit; // critical section for changing any control references
ControllerInterface controller_interface;
Common::CriticalSection controls_crit; // critical section for changing any control references
const char * const ini_name;
const char * const gui_name;

View file

@ -3,13 +3,11 @@ import sys
Import('env')
files = [
'Configuration.cpp',
'ControllerEmu.cpp',
'InputConfig.cpp',
'ControllerInterface/ControllerInterface.cpp',
'UDPWiimote.cpp',
'UDPWrapper.cpp',
'SDL_Util.cpp', # XXX needed by old Wiimote plugin
]
if sys.platform == 'win32':
@ -30,7 +28,6 @@ elif env['HAVE_X11']:
files += [
'ControllerInterface/SDL/SDL.cpp',
'ControllerInterface/Xlib/Xlib.cpp',
'X11InputBase.cpp'
]
env.StaticLibrary(env['local_libs'] + "inputcommon", files)

View file

@ -1,222 +0,0 @@
// Project description
// -------------------
// Name: SDL Input
// Description: Common SDL Input Functions
//
// Author: Falcon4ever (nJoy@falcon4ever.com, www.multigesture.net), JPeterson etc
// Copyright (C) 2003 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/
//
#define _SDL_MAIN_ // Avoid certain declarations in SDL.h
#include "InputCommon.h"
#include "SDL_Util.h" // Local
#ifdef _WIN32
#include "XInput_Util.h"
#endif
namespace InputCommon
{
// Search attached devices. Populate joyinfo for all attached physical devices.
// -----------------------
bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
{
if (!SDL_WasInit(0))
#if SDL_VERSION_ATLEAST(1, 3, 0)
if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0)
#else
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
#endif
{
PanicAlert("Could not initialize SDL: %s", SDL_GetError());
return false;
}
// Get device status
int numjoy = SDL_NumJoysticks();
for (int i = 0; i < numjoy; i++)
{
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);
// We have now read the values we need so we close the device
// if (SDL_JoystickOpened(i)) SDL_JoystickClose(_joyinfo[i].joy);
}
_NumPads = (int)_joyinfo.size();
return true;
}
// Avoid extreme axis values
// ---------------------
/* Function: We have to avoid very big values because some triggers are -0x8000 in the
unpressed state (and then go from -0x8000 to 0x8000 as they are fully pressed) */
bool AvoidValues(int value, bool NoTriggerFilter)
{
// Avoid detecting very small or very big (for triggers) values
if((value > -0x1000 && value < 0x1000) // Small values
|| ((value < -0x7000 || value > 0x7000) && !NoTriggerFilter)) // Big values
return true; // Avoid
else
return false; // Keep
}
// Detect a pressed button
// ---------------------
void GetButton(SDL_Joystick *joy, int ControllerID, int buttons, int axes, int hats,
int &KeyboardKey, int &value, int &type, int &pressed, bool &Succeed, bool &Stop,
bool LeftRight, bool Axis, bool XInput, bool Button, bool Hat, bool NoTriggerFilter)
{
// It needs the wxWidgets excape keycode
static const int WXK_ESCAPE = 27;
// Update the internal status
SDL_JoystickUpdate();
// For the triggers we accept both a digital or an analog button
if(Axis)
{
for(int i = 0; i < axes; i++)
{
value = SDL_JoystickGetAxis(joy, i);
if(AvoidValues(value, NoTriggerFilter)) continue; // Avoid values
pressed = i + (LeftRight ? 1000 : 0); // Identify the analog triggers
type = InputCommon::CTL_AXIS;
Succeed = true;
}
}
// Check for a hat
if(Hat)
{
for(int i = 0; i < hats; i++)
{
value = SDL_JoystickGetHat(joy, i);
if(value)
{
pressed = i;
type = InputCommon::CTL_HAT;
Succeed = true;
}
}
}
// Check for a button
if(Button)
{
for(int i = 0; i < buttons; i++)
{
// Some kind of bug in SDL 1.3 would give button 9 and 10 (nonexistent) the value 48 on the 360 pad
if (SDL_JoystickGetButton(joy, i) > 1) continue;
if(SDL_JoystickGetButton(joy, i))
{
pressed = i;
type = InputCommon::CTL_BUTTON;
Succeed = true;
}
}
}
// Check for a XInput trigger
#ifdef _WIN32
if(XInput && LeftRight)
{
for(int i = 0; i <= InputCommon::XI_TRIGGER_R; i++)
{
if(XInput::GetXI(ControllerID, i))
{
pressed = i + 1000;
type = InputCommon::CTL_AXIS;
Succeed = true;
}
}
}
#endif
// Check for keyboard action
if (KeyboardKey)
{
if(Button)
{
// Todo: Add a separate keyboard vector to remove this restriction
if(KeyboardKey >= buttons)
{
pressed = KeyboardKey;
type = InputCommon::CTL_BUTTON;
Succeed = true;
KeyboardKey = 0;
if(pressed == WXK_ESCAPE) pressed = -1; // Check for the escape key
}
// Else show the error message
else
{
pressed = KeyboardKey;
KeyboardKey = -1;
Stop = true;
}
}
// Only accept the escape key
else if (KeyboardKey == WXK_ESCAPE)
{
Succeed = true;
KeyboardKey = 0;
pressed = -1;
}
}
}
} // InputCommon

View file

@ -1,76 +0,0 @@
// Copyright (C) 2003 Dolphin Project.
// 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/
#ifndef _SDL_h
#define _SDL_h
#include <iostream> // System
#include <vector>
#include <cmath>
#ifdef _WIN32
#include <SDL.h> // Externals
#if SDL_VERSION_ATLEAST(1, 3, 0)
#include <SDL_haptic.h>
#endif
#else
#include <SDL/SDL.h>
#if SDL_VERSION_ATLEAST(1, 3, 0)
#include <SDL/SDL_haptic.h>
#endif
#endif
#include "Common.h" // Common
namespace InputCommon
{
struct CONTROLLER_INFO // CONNECTED WINDOWS DEVICES INFO
{
int NumAxes; // Amount of Axes
int NumButtons; // Amount of Buttons
int NumBalls; // Amount of Balls
int NumHats; // Amount of Hats (POV)
std::string Name; // Joypad/stickname
int ID; // SDL joystick device ID
bool Good; // Pad is good (it has at least one button or axis)
SDL_Joystick *joy; // SDL joystick device
};
// General functions
bool SearchDevices(std::vector<CONTROLLER_INFO> &_joyinfo, int &NumPads, int &NumGoodPads);
void GetButton(SDL_Joystick*, int,int,int,int, int&,int&,int&,int&,bool&,bool&, bool,bool,bool,bool,bool,bool);
// Value conversion
float Deg2Rad(float Deg);
float Rad2Deg(float Rad);
int Pad_Convert(int _val);
float SquareDistance(float deg);
bool IsDeadZone(float DeadZone, int x, int y);
void Square2Circle(int &_x, int &_y, int _Diagonal, bool Circle2Square = false);
void RadiusAdjustment(s8 &_x, s8 &_y, int _Radius);
// Input configuration
std::string VKToString(int keycode);
} // InputCommon
#endif // _SDL_h

View file

@ -1,5 +1,8 @@
#include "UDPWiimote.h"
#ifdef USE_UDP_WIIMOTE
#ifdef _WIN32
#include <winsock2.h>
@ -418,3 +421,5 @@ void UDPWiimote::changeName(const char * name)
displayName=name;
d->nameMutex.Leave();
}
#endif

View file

@ -1,4 +1,7 @@
#ifndef UDPWIIMOTE_H
//#define USE_UDP_WIIMOTE
#if (!defined(UDPWIIMOTE_H) && defined(USE_UDP_WIIMOTE))
#define UDPWIIMOTE_H
#include "Common.h"

View file

@ -1,4 +1,8 @@
#include "UDPWrapper.h"
#ifdef USE_UDP_WIIMOTE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -197,3 +201,5 @@ void UDPWrapper::Configure(wxWindow * parent)
diag->Destroy();
}
#endif
#endif

View file

@ -1,4 +1,7 @@
#ifndef UDPWRAPPER_H
#include "UDPWiimote.h"
#if (defined(USE_UDP_WIIMOTE) && !defined(UDPWRAPPER_H))
#define UDPWRAPPER_H
#include "Common.h"
@ -19,8 +22,6 @@
#include <wx/spinctrl.h>
#endif
#include "UDPWiimote.h"
class UDPWrapper : public ControllerEmu::ControlGroup
{
public:

View file

@ -1,123 +0,0 @@
//
// 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/
//
// File description
/* -------------------
Function: This file will get the status of the analog triggers of any connected XInput device.
This code was made with the help of SimpleController.cpp in the June 2008 Microsoft DirectX SDK
Samples.
///////////////////////////////////////////////////// */
#ifdef _WIN32
// Includes
// -------------------
#include <windows.h>
#include <XInput.h> // XInput API
#include "InputCommon.h"
namespace XInput
{
// Declarations
// -------------------
#define MAX_CONTROLLERS 4 // XInput handles up to 4 controllers
struct CONTROLER_STATE
{
XINPUT_STATE state;
bool bConnected;
};
CONTROLER_STATE g_Controllers[MAX_CONTROLLERS];
// Init
// -------------------
/* Function: Calculate the number of connected XInput devices
Todo: Implement this to figure out if there are multiple XInput controllers connected,
we currently only try to connect to XInput device 0 */
void Init()
{
// Init state
//ZeroMemory( g_Controllers, sizeof( CONTROLER_STATE ) * MAX_CONTROLLERS );
// Declaration
DWORD dwResult;
// Calculate the number of connected XInput devices
for( DWORD i = 0; i < MAX_CONTROLLERS; i++ )
{
// Simply get the state of the controller from XInput.
dwResult = XInputGetState( i, &g_Controllers[i].state );
if( dwResult == ERROR_SUCCESS )
g_Controllers[i].bConnected = true;
else
g_Controllers[i].bConnected = false;
}
}
// Get the trigger status
// -------------------
int GetXI(int Controller, int Button)
{
// Update the internal status
DWORD dwResult;
dwResult = XInputGetState(Controller, &g_Controllers[Controller].state);
if (dwResult != ERROR_SUCCESS) return -1;
switch (Button)
{
case InputCommon::XI_TRIGGER_L:
return g_Controllers[Controller].state.Gamepad.bLeftTrigger;
case InputCommon::XI_TRIGGER_R:
return g_Controllers[Controller].state.Gamepad.bRightTrigger;
default:
return 0;
}
}
// Check if a certain controller is connected
// -------------------
bool IsConnected(int Controller)
{
DWORD dwResult = XInputGetState( Controller, &g_Controllers[Controller].state );
// Update the connected status
if( dwResult == ERROR_SUCCESS )
return true;
else
return false;
}
} // XInput
#endif

View file

@ -1,42 +0,0 @@
//
// 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/
//
#ifdef _WIN32
// Includes
// ----------
#include <iostream>
namespace XInput
{
// Declarations
// ----------
void Init();
int GetXI(int Controller, int Button);
bool IsConnected(int Controller);
} // XInput
#endif

View file

@ -404,18 +404,6 @@
<References>
</References>
<Files>
<File
RelativePath=".\Src\ConfigDiag.cpp"
>
</File>
<File
RelativePath=".\Src\ConfigDiag.h"
>
</File>
<File
RelativePath=".\Src\ConfigDiagBitmaps.cpp"
>
</File>
<File
RelativePath=".\Src\SConscript"
>

View file

@ -6,8 +6,6 @@ if not env['HAVE_WX']:
Return()
files = [
'ConfigDiag.cpp',
'ConfigDiagBitmaps.cpp',
'WXInputBase.cpp',
]