2008-11-05 17:15:00 +00:00
|
|
|
// Copyright (C) 2003-2008 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 "Common.h"
|
2008-11-16 20:09:13 +00:00
|
|
|
#include "Config.h"
|
2008-11-05 17:15:00 +00:00
|
|
|
#include "StringUtil.h"
|
|
|
|
|
2008-12-07 19:09:14 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
|
|
|
#include <wx/aboutdlg.h>
|
|
|
|
#include "ConfigDlg.h"
|
|
|
|
#endif
|
|
|
|
|
2008-11-05 17:15:00 +00:00
|
|
|
#include "pluginspecs_wiimote.h"
|
|
|
|
|
2008-11-12 15:03:21 +00:00
|
|
|
#include "EmuMain.h"
|
2008-12-05 13:46:19 +00:00
|
|
|
|
|
|
|
#if HAVE_WIIUSE
|
2008-11-05 17:15:00 +00:00
|
|
|
#include "wiimote_real.h"
|
2008-12-05 13:46:19 +00:00
|
|
|
#endif
|
2008-11-05 17:15:00 +00:00
|
|
|
|
2008-11-08 06:31:18 +00:00
|
|
|
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
|
|
|
|
2008-11-05 17:15:00 +00:00
|
|
|
SWiimoteInitialize g_WiimoteInitialize;
|
|
|
|
|
|
|
|
bool g_UseRealWiiMote = false;
|
|
|
|
|
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
|
|
|
|
class wxDLLApp : public wxApp
|
|
|
|
{
|
|
|
|
bool OnInit()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
IMPLEMENT_APP_NO_MAIN(wxDLLApp)
|
|
|
|
|
|
|
|
WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
|
|
|
|
DWORD dwReason, // reason called
|
|
|
|
LPVOID lpvReserved) // reserved
|
|
|
|
{
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
{ //use wxInitialize() if you don't want GUI instead of the following 12 lines
|
|
|
|
wxSetInstance((HINSTANCE)hinstDLL);
|
|
|
|
int argc = 0;
|
|
|
|
char **argv = NULL;
|
|
|
|
wxEntryStart(argc, argv);
|
|
|
|
if ( !wxTheApp || !wxTheApp->CallOnInit() )
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
wxEntryCleanup(); //use wxUninitialize() if you don't want GUI
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
//******************************************************************************
|
|
|
|
// Exports
|
|
|
|
//******************************************************************************
|
|
|
|
extern "C" void GetDllInfo (PLUGIN_INFO* _PluginInfo)
|
|
|
|
{
|
|
|
|
_PluginInfo->Version = 0x0100;
|
|
|
|
_PluginInfo->Type = PLUGIN_TYPE_WIIMOTE;
|
|
|
|
#ifdef DEBUGFAST
|
2008-11-23 22:00:04 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Wiimote Plug-in (DebugFast)");
|
2008-11-05 17:15:00 +00:00
|
|
|
#else
|
|
|
|
#ifndef _DEBUG
|
2008-11-23 22:00:04 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Wiimote Plug-in");
|
2008-11-05 17:15:00 +00:00
|
|
|
#else
|
2008-11-23 22:00:04 +00:00
|
|
|
sprintf(_PluginInfo->Name, "Wiimote Plug-in (Debug)");
|
2008-11-05 17:15:00 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" void DllAbout(HWND _hParent)
|
|
|
|
{
|
2008-12-07 19:09:14 +00:00
|
|
|
#if defined(HAVE_WX) && HAVE_WX
|
2008-11-05 17:15:00 +00:00
|
|
|
wxAboutDialogInfo info;
|
2008-11-22 22:34:54 +00:00
|
|
|
info.SetName(_T("Wiimote plug-in"));
|
2008-11-05 17:15:00 +00:00
|
|
|
info.AddDeveloper(_T("masken (masken3@gmail.com)"));
|
2008-11-22 22:34:54 +00:00
|
|
|
info.SetDescription(_T("Wiimote plug-in"));
|
2008-11-05 17:15:00 +00:00
|
|
|
wxAboutBox(info);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void DllConfig(HWND _hParent)
|
|
|
|
{
|
2008-11-16 20:09:13 +00:00
|
|
|
wxWindow win;
|
2008-11-20 14:17:12 +00:00
|
|
|
#ifdef _WIN32
|
2008-11-16 20:09:13 +00:00
|
|
|
win.SetHWND(_hParent);
|
2008-11-20 14:17:12 +00:00
|
|
|
#endif
|
2008-11-16 20:09:13 +00:00
|
|
|
ConfigDialog frame(&win);
|
|
|
|
frame.ShowModal();
|
2008-11-20 14:17:12 +00:00
|
|
|
#ifdef _WIN32
|
2008-11-16 20:09:13 +00:00
|
|
|
win.SetHWND(0);
|
|
|
|
#endif
|
2008-11-05 17:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void Wiimote_Initialize(SWiimoteInitialize _WiimoteInitialize)
|
|
|
|
{
|
|
|
|
g_WiimoteInitialize = _WiimoteInitialize;
|
|
|
|
|
2008-11-17 16:59:20 +00:00
|
|
|
/* We will run WiiMoteReal::Initialize() even if we are not using a real wiimote,
|
2008-11-19 08:31:31 +00:00
|
|
|
we will initiate wiiuse.dll, but we will return before creating a new thread
|
|
|
|
for it in that case */
|
2008-12-05 13:46:19 +00:00
|
|
|
#if HAVE_WIIUSE
|
2008-11-05 17:15:00 +00:00
|
|
|
g_UseRealWiiMote = WiiMoteReal::Initialize() > 0;
|
2008-12-05 13:46:19 +00:00
|
|
|
#endif
|
2008-11-16 20:09:13 +00:00
|
|
|
g_Config.Load(); // load config settings
|
|
|
|
|
2008-11-28 19:02:42 +00:00
|
|
|
WiiMoteEmu::Initialize();
|
|
|
|
|
2008-11-08 06:31:18 +00:00
|
|
|
// Debugging window
|
2008-11-18 07:40:56 +00:00
|
|
|
/*startConsoleWin(100, 750, "Wiimote"); // give room for 20 rows
|
2008-11-08 06:31:18 +00:00
|
|
|
wprintf("Wiimote console opened\n");
|
2008-11-18 07:40:56 +00:00
|
|
|
|
|
|
|
// move window, TODO: make this
|
|
|
|
//MoveWindow(GetConsoleHwnd(), 0,400, 100*8,10*14, true); // small window
|
|
|
|
MoveWindow(GetConsoleHwnd(), 400,0, 100*8,70*14, true); // big window*/
|
2008-11-05 17:15:00 +00:00
|
|
|
}
|
|
|
|
|
2008-11-18 07:40:56 +00:00
|
|
|
|
2008-11-05 17:15:00 +00:00
|
|
|
extern "C" void Wiimote_DoState(void* ptr, int mode)
|
|
|
|
{
|
2008-12-05 13:46:19 +00:00
|
|
|
#if HAVE_WIIUSE
|
2008-11-05 17:15:00 +00:00
|
|
|
WiiMoteReal::DoState(ptr, mode);
|
2008-12-05 13:46:19 +00:00
|
|
|
#endif
|
2008-11-05 17:15:00 +00:00
|
|
|
WiiMoteEmu::DoState(ptr, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void Wiimote_Shutdown(void)
|
|
|
|
{
|
2008-12-05 13:46:19 +00:00
|
|
|
#if HAVE_WIIUSE
|
2008-11-05 17:15:00 +00:00
|
|
|
WiiMoteReal::Shutdown();
|
2008-12-05 13:46:19 +00:00
|
|
|
#endif
|
2008-11-05 17:15:00 +00:00
|
|
|
WiiMoteEmu::Shutdown();
|
|
|
|
}
|
|
|
|
|
2008-11-24 02:29:38 +00:00
|
|
|
// ===================================================
|
|
|
|
/* This function produce Wiimote Input (reports from the Wiimote) in response
|
|
|
|
to Output from the Wii. It's called from WII_IPC_HLE_WiiMote.cpp. */
|
|
|
|
// ----------------
|
2008-11-05 17:15:00 +00:00
|
|
|
extern "C" void Wiimote_InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
|
|
|
|
{
|
2008-11-24 02:29:38 +00:00
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "=============================================================");
|
2008-11-05 17:15:00 +00:00
|
|
|
const u8* data = (const u8*)_pData;
|
|
|
|
|
2008-11-24 02:29:38 +00:00
|
|
|
// Debugging
|
2008-11-05 17:15:00 +00:00
|
|
|
{
|
2008-11-24 02:29:38 +00:00
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "Wiimote_Input");
|
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, " Channel ID: %04x", _channelID);
|
|
|
|
std::string Temp = WiiMoteEmu::ArrayToString(data, _Size);
|
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, " Data: %s", Temp.c_str());
|
2008-11-05 17:15:00 +00:00
|
|
|
}
|
|
|
|
|
2008-12-05 13:46:19 +00:00
|
|
|
if (! g_UseRealWiiMote)
|
|
|
|
WiiMoteEmu::InterruptChannel(_channelID, _pData, _Size);
|
|
|
|
#if HAVE_WIIUSE
|
2008-11-05 17:15:00 +00:00
|
|
|
else
|
2008-12-05 13:46:19 +00:00
|
|
|
WiiMoteReal::InterruptChannel(_channelID, _pData, _Size);
|
|
|
|
#endif
|
|
|
|
|
2008-11-24 02:29:38 +00:00
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "=============================================================");
|
2008-11-05 17:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
|
|
|
|
{
|
2008-11-24 02:29:38 +00:00
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "=============================================================");
|
2008-11-05 17:15:00 +00:00
|
|
|
const u8* data = (const u8*)_pData;
|
2008-11-24 02:29:38 +00:00
|
|
|
|
|
|
|
// Debugging
|
2008-11-05 17:15:00 +00:00
|
|
|
{
|
2008-11-24 02:29:38 +00:00
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "Wiimote_ControlChannel");
|
|
|
|
std::string Temp = WiiMoteEmu::ArrayToString(data, _Size);
|
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, " Data: %s", Temp.c_str());
|
2008-11-05 17:15:00 +00:00
|
|
|
}
|
|
|
|
|
2008-12-05 13:46:19 +00:00
|
|
|
|
|
|
|
if (! g_UseRealWiiMote)
|
|
|
|
WiiMoteEmu::ControlChannel(_channelID, _pData, _Size);
|
|
|
|
#if HAVE_WIIUSE
|
|
|
|
else
|
|
|
|
WiiMoteReal::ControlChannel(_channelID, _pData, _Size);
|
|
|
|
#endif
|
|
|
|
|
2008-11-24 02:29:38 +00:00
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "=============================================================");
|
2008-11-05 17:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void Wiimote_Update()
|
|
|
|
{
|
2008-12-05 13:46:19 +00:00
|
|
|
if (! g_UseRealWiiMote)
|
|
|
|
WiiMoteEmu::Update();
|
|
|
|
#if HAVE_WIIUSE
|
|
|
|
else
|
|
|
|
WiiMoteReal::Update();
|
|
|
|
#endif
|
2008-11-05 17:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" unsigned int Wiimote_GetAttachedControllers()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-20 08:46:16 +00:00
|
|
|
// ===================================================
|
|
|
|
/* Logging functions. */
|
|
|
|
// ----------------
|
2008-11-05 17:15:00 +00:00
|
|
|
void __Log(int log, const char *_fmt, ...)
|
|
|
|
{
|
|
|
|
char Msg[512];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start( ap, _fmt );
|
|
|
|
vsprintf( Msg, _fmt, ap );
|
|
|
|
va_end( ap );
|
|
|
|
|
2008-11-12 15:03:21 +00:00
|
|
|
g_WiimoteInitialize.pLog(Msg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __Logv(int log, int v, const char *_fmt, ...)
|
|
|
|
{
|
|
|
|
char Msg[512];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start( ap, _fmt );
|
|
|
|
vsprintf( Msg, _fmt, ap );
|
|
|
|
va_end( ap );
|
|
|
|
|
|
|
|
g_WiimoteInitialize.pLog(Msg, v);
|
2008-11-17 16:59:20 +00:00
|
|
|
}
|
2008-11-20 14:17:12 +00:00
|
|
|
// ================
|