mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Moved wiimote_test to wiimote
Some linux compile fixes git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1266 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
54
Source/Plugins/Plugin_Wiimote/Src/Config.cpp
Normal file
54
Source/Plugins/Plugin_Wiimote/Src/Config.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
// 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"
|
||||
#include "IniFile.h"
|
||||
#include "Config.h"
|
||||
|
||||
Config g_Config;
|
||||
|
||||
Config::Config()
|
||||
{
|
||||
memset(this, 0, sizeof(Config));
|
||||
}
|
||||
|
||||
void Config::Load()
|
||||
{
|
||||
std::string temp;
|
||||
IniFile iniFile;
|
||||
iniFile.Load(FULL_CONFIG_DIR "Wiimote.ini");
|
||||
|
||||
// get resolution
|
||||
|
||||
iniFile.Get("Settings", "SidewaysDPad", &bSidewaysDPad, 0); // Hardware
|
||||
iniFile.Get("Settings", "WideScreen", &bWideScreen, 0);
|
||||
iniFile.Get("Settings", "ExtensionConnected", &bExtensionConnected, 0);
|
||||
|
||||
}
|
||||
|
||||
void Config::Save()
|
||||
{
|
||||
IniFile iniFile;
|
||||
iniFile.Load(FULL_CONFIG_DIR "Wiimote.ini");
|
||||
iniFile.Set("Settings", "SidewaysDPad", bSidewaysDPad);
|
||||
iniFile.Set("Settings", "WideScreen", bWideScreen);
|
||||
iniFile.Set("Settings", "ExtensionConnected", bExtensionConnected);
|
||||
|
||||
|
||||
iniFile.Save(FULL_CONFIG_DIR "Wiimote.ini");
|
||||
}
|
41
Source/Plugins/Plugin_Wiimote/Src/Config.h
Normal file
41
Source/Plugins/Plugin_Wiimote/Src/Config.h
Normal file
@ -0,0 +1,41 @@
|
||||
// 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/
|
||||
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
||||
#define CONF_LOG 1
|
||||
#define CONF_PRIMLOG 2
|
||||
#define CONF_SAVETEXTURES 4
|
||||
#define CONF_SAVETARGETS 8
|
||||
#define CONF_SAVESHADERS 16
|
||||
|
||||
struct Config
|
||||
{
|
||||
Config();
|
||||
void Load();
|
||||
void Save();
|
||||
|
||||
// General
|
||||
bool bSidewaysDPad;
|
||||
bool bWideScreen;
|
||||
bool bExtensionConnected;
|
||||
};
|
||||
|
||||
extern Config g_Config;
|
||||
|
||||
#endif // _CONFIG_H
|
140
Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.cpp
Normal file
140
Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
// 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" // for u16
|
||||
#include "ConfigDlg.h"
|
||||
#include "Config.h"
|
||||
#include "EmuSubroutines.h" // for WmRequestStatus_
|
||||
|
||||
|
||||
BEGIN_EVENT_TABLE(ConfigDialog,wxDialog)
|
||||
EVT_CLOSE(ConfigDialog::OnClose)
|
||||
EVT_BUTTON(ID_CLOSE, ConfigDialog::CloseClick)
|
||||
EVT_BUTTON(ID_ABOUTOGL, ConfigDialog::AboutClick)
|
||||
EVT_CHECKBOX(ID_SIDEWAYSDPAD, ConfigDialog::GeneralSettingsChanged)
|
||||
EVT_CHECKBOX(ID_WIDESCREEN, ConfigDialog::GeneralSettingsChanged)
|
||||
EVT_CHECKBOX(ID_EXTENSIONCONNECTED, ConfigDialog::GeneralSettingsChanged)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
ConfigDialog::ConfigDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
|
||||
: wxDialog(parent, id, title, position, size, style)
|
||||
{
|
||||
g_Config.Load();
|
||||
CreateGUIControls();
|
||||
}
|
||||
|
||||
ConfigDialog::~ConfigDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void ConfigDialog::CreateGUIControls()
|
||||
{
|
||||
// Notebook
|
||||
m_Notebook = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize);
|
||||
m_PageEmu = new wxPanel(m_Notebook, ID_PAGEEMU, wxDefaultPosition, wxDefaultSize);
|
||||
m_PageReal = new wxPanel(m_Notebook, ID_PAGEREAL, wxDefaultPosition, wxDefaultSize);
|
||||
m_Notebook->AddPage(m_PageEmu, wxT("Emulated Wiimote"));
|
||||
m_Notebook->AddPage(m_PageReal, wxT("Real Wiimote"));
|
||||
|
||||
// Buttons
|
||||
//m_About = new wxButton(this, ID_ABOUTOGL, wxT("About"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_Close = new wxButton(this, ID_CLOSE, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
|
||||
// Put notebook and buttons in sizers
|
||||
wxBoxSizer* sButtons;
|
||||
sButtons = new wxBoxSizer(wxHORIZONTAL);
|
||||
//sButtons->Add(m_About, 0, wxALL, 5); // there is no about
|
||||
sButtons->AddStretchSpacer();
|
||||
sButtons->Add(m_Close, 0, wxALL, 5);
|
||||
|
||||
wxBoxSizer* sMain;
|
||||
sMain = new wxBoxSizer(wxVERTICAL);
|
||||
sMain->Add(m_Notebook, 1, wxEXPAND|wxALL, 5);
|
||||
sMain->Add(sButtons, 0, wxEXPAND, 5);
|
||||
|
||||
|
||||
// General
|
||||
sbBasic = new wxStaticBoxSizer(wxVERTICAL, m_PageEmu, wxT("Basic Settings"));
|
||||
m_SidewaysDPad = new wxCheckBox(m_PageEmu, ID_SIDEWAYSDPAD, wxT("Sideways D-Pad"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_SidewaysDPad->SetValue(g_Config.bSidewaysDPad);
|
||||
m_WideScreen = new wxCheckBox(m_PageEmu, ID_WIDESCREEN, wxT("WideScreen Mode (for correct aiming)"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_WideScreen->SetValue(g_Config.bWideScreen);
|
||||
m_ExtensionConnected = new wxCheckBox(m_PageEmu, ID_EXTENSIONCONNECTED, wxT("Extension connected"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_ExtensionConnected->SetValue(g_Config.bExtensionConnected);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Set up sGeneral and sBasic
|
||||
// Usage: The wxGBPosition() must have a column and row
|
||||
// ----------------
|
||||
sGeneral = new wxBoxSizer(wxVERTICAL);
|
||||
sBasic = new wxGridBagSizer(0, 0);
|
||||
sBasic->Add(m_SidewaysDPad, wxGBPosition(0, 0), wxGBSpan(1, 2), wxALL, 5);
|
||||
sBasic->Add(m_WideScreen, wxGBPosition(1, 0), wxGBSpan(1, 2), wxALL, 5);
|
||||
sBasic->Add(m_ExtensionConnected, wxGBPosition(2, 0), wxGBSpan(1, 2), wxALL, 5);
|
||||
sbBasic->Add(sBasic);
|
||||
sGeneral->Add(sbBasic, 0, wxEXPAND|wxALL, 5);
|
||||
|
||||
m_PageEmu->SetSizer(sGeneral);
|
||||
sGeneral->Layout();
|
||||
|
||||
this->SetSizer(sMain);
|
||||
this->Layout();
|
||||
// ----------------
|
||||
|
||||
|
||||
Fit();
|
||||
Center();
|
||||
}
|
||||
|
||||
void ConfigDialog::OnClose(wxCloseEvent& WXUNUSED (event))
|
||||
{
|
||||
g_Config.Save();
|
||||
EndModal(0);
|
||||
}
|
||||
|
||||
void ConfigDialog::CloseClick(wxCommandEvent& WXUNUSED (event))
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void ConfigDialog::AboutClick(wxCommandEvent& WXUNUSED (event))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ConfigDialog::GeneralSettingsChanged(wxCommandEvent& event)
|
||||
{
|
||||
switch (event.GetId())
|
||||
{
|
||||
case ID_SIDEWAYSDPAD:
|
||||
g_Config.bSidewaysDPad = m_SidewaysDPad->IsChecked();
|
||||
break;
|
||||
case ID_WIDESCREEN:
|
||||
g_Config.bWideScreen = m_WideScreen->IsChecked();
|
||||
break;
|
||||
case ID_EXTENSIONCONNECTED:
|
||||
g_Config.bExtensionConnected = m_ExtensionConnected->IsChecked();
|
||||
|
||||
// generate connect/disconnect status event
|
||||
u8 DataFrame[8]; // make a blank report for it
|
||||
wm_request_status *rs = (wm_request_status*)DataFrame;
|
||||
if(WiiMoteEmu::g_ReportingChannel > 0)
|
||||
WiiMoteEmu::WmRequestStatus(WiiMoteEmu::g_ReportingChannel, rs);
|
||||
break;
|
||||
}
|
||||
}
|
85
Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.h
Normal file
85
Source/Plugins/Plugin_Wiimote/Src/ConfigDlg.h
Normal file
@ -0,0 +1,85 @@
|
||||
// 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/
|
||||
|
||||
#ifndef __CONFIGDIALOG_h__
|
||||
#define __CONFIGDIALOG_h__
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <wx/dialog.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/filepicker.h>
|
||||
#include <wx/gbsizer.h>
|
||||
|
||||
|
||||
#undef ConfigDialog_STYLE
|
||||
#define ConfigDialog_STYLE wxCAPTION | wxSYSTEM_MENU | wxDIALOG_NO_PARENT | wxCLOSE_BOX
|
||||
|
||||
|
||||
class ConfigDialog : public wxDialog
|
||||
{
|
||||
public:
|
||||
ConfigDialog(wxWindow *parent, wxWindowID id = 1,
|
||||
const wxString &title = wxT("Wii Remote Plugin Configuration"),
|
||||
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
||||
long style = ConfigDialog_STYLE);
|
||||
virtual ~ConfigDialog();
|
||||
void CloseClick(wxCommandEvent& event);
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
wxBoxSizer* sGeneral;
|
||||
wxStaticBoxSizer* sbBasic;
|
||||
wxGridBagSizer* sBasic;
|
||||
|
||||
wxButton *m_About;
|
||||
wxButton *m_Close;
|
||||
wxNotebook *m_Notebook;
|
||||
wxPanel *m_PageEmu, *m_PageReal;
|
||||
|
||||
wxCheckBox *m_SidewaysDPad; // general settings
|
||||
wxCheckBox *m_WideScreen;
|
||||
wxCheckBox *m_ExtensionConnected;
|
||||
|
||||
enum
|
||||
{
|
||||
ID_CLOSE = 1000,
|
||||
ID_ABOUTOGL,
|
||||
|
||||
ID_NOTEBOOK,
|
||||
ID_PAGEEMU,
|
||||
ID_PAGEREAL,
|
||||
|
||||
ID_SIDEWAYSDPAD,
|
||||
ID_WIDESCREEN,
|
||||
ID_EXTENSIONCONNECTED
|
||||
};
|
||||
|
||||
void OnClose(wxCloseEvent& event);
|
||||
void CreateGUIControls();
|
||||
|
||||
void AboutClick(wxCommandEvent& event);
|
||||
void GeneralSettingsChanged(wxCommandEvent& event);
|
||||
};
|
||||
|
||||
#endif
|
223
Source/Plugins/Plugin_Wiimote/Src/Console.cpp
Normal file
223
Source/Plugins/Plugin_Wiimote/Src/Console.cpp
Normal file
@ -0,0 +1,223 @@
|
||||
// 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/
|
||||
|
||||
|
||||
// --------------------
|
||||
// Includes
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
// --------------------
|
||||
// On and off
|
||||
bool g_consoleEnable = true;
|
||||
int gSaveFile = 0;
|
||||
#define DEBUG_WIIMOTE
|
||||
|
||||
|
||||
// --------------------
|
||||
// Settings
|
||||
int nFiles = 1;
|
||||
|
||||
|
||||
// --------------------
|
||||
// Create handles
|
||||
|
||||
#ifdef DEBUG_WIIMOTE
|
||||
FILE* __fStdOut[1]; // you have to update this manually, we can't place a nFiles in there
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
HANDLE __hStdOut = NULL;
|
||||
#endif
|
||||
|
||||
|
||||
// =======================================================================================
|
||||
/* Start console window - width and height is the size of console window, if you specify
|
||||
fname, the output will also be written to this file. TODO: Close the file pointer when the app
|
||||
is closed */
|
||||
// -------------
|
||||
void startConsoleWin(int width, int height, char* fname)
|
||||
{
|
||||
#if defined(DEBUG_WIIMOTE) && defined(_WIN32)
|
||||
|
||||
AllocConsole();
|
||||
|
||||
SetConsoleTitle(fname);
|
||||
__hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
COORD co = {width,height};
|
||||
SetConsoleScreenBufferSize(__hStdOut, co);
|
||||
|
||||
SMALL_RECT coo = {0,0,(width - 1),70}; // top, left, right, bottom
|
||||
SetConsoleWindowInfo(__hStdOut, TRUE, &coo);
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Write to a file
|
||||
if(fname)
|
||||
{
|
||||
for(int i = 0; i < nFiles; i++)
|
||||
{
|
||||
// Edit the log file name
|
||||
std::string FileEnding = ".log";
|
||||
std::string FileName = fname;
|
||||
char buffer[33]; itoa(i, buffer, 10); // convert number to string
|
||||
std::string FullFilename = (FileName + buffer + FileEnding);
|
||||
__fStdOut[i] = fopen(FullFilename.c_str(), "w");
|
||||
}
|
||||
}
|
||||
// ---------------
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// File printf function
|
||||
int aprintf(int a, char *fmt, ...)
|
||||
{
|
||||
#if defined(DEBUG_WIIMOTE) && defined(_WIN32)
|
||||
if(gSaveFile)
|
||||
{
|
||||
char s[500]; // WARNING: mind this value
|
||||
va_list argptr;
|
||||
int cnt;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
cnt = vsnprintf(s, 500, fmt, argptr); // remember to update this value to
|
||||
va_end(argptr);
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
if(__fStdOut[a]) // TODO: make this work, we have to set all default values to NULL
|
||||
//to make it work
|
||||
fprintf(__fStdOut[a], s);
|
||||
// -------------
|
||||
|
||||
return(cnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Printf to screen function
|
||||
int wprintf(char *fmt, ...)
|
||||
{
|
||||
#if defined(DEBUG_WIIMOTE) && defined(_WIN32)
|
||||
char s[500]; // WARNING: mind this value
|
||||
va_list argptr;
|
||||
int cnt;
|
||||
|
||||
va_start(argptr, fmt);
|
||||
cnt = vsnprintf(s, 500, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
DWORD cCharsWritten;
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
if(__hStdOut)
|
||||
{
|
||||
WriteConsole(__hStdOut, s, strlen(s), &cCharsWritten, NULL);
|
||||
}
|
||||
// -------------
|
||||
|
||||
return(cnt);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Clear console screen
|
||||
void ClearScreen()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
if(g_consoleEnable)
|
||||
{
|
||||
COORD coordScreen = { 0, 0 };
|
||||
DWORD cCharsWritten;
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
DWORD dwConSize;
|
||||
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
|
||||
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize,
|
||||
coordScreen, &cCharsWritten);
|
||||
GetConsoleScreenBufferInfo(hConsole, &csbi);
|
||||
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize,
|
||||
coordScreen, &cCharsWritten);
|
||||
SetConsoleCursorPosition(hConsole, coordScreen);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------
|
||||
// Get window handle of console window to be able to resize it
|
||||
#if defined(_WIN32)
|
||||
HWND GetConsoleHwnd(void)
|
||||
{
|
||||
|
||||
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
|
||||
HWND hwndFound; // This is what is returned to the caller.
|
||||
char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated
|
||||
// WindowTitle.
|
||||
char pszOldWindowTitle[MY_BUFSIZE]; // Contains original
|
||||
// WindowTitle.
|
||||
|
||||
// Fetch current window title.
|
||||
|
||||
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
|
||||
|
||||
// Format a "unique" NewWindowTitle.
|
||||
|
||||
wsprintf(pszNewWindowTitle,"%d/%d",
|
||||
GetTickCount(),
|
||||
GetCurrentProcessId());
|
||||
|
||||
// Change current window title.
|
||||
|
||||
SetConsoleTitle(pszNewWindowTitle);
|
||||
|
||||
// Ensure window title has been updated.
|
||||
|
||||
Sleep(40);
|
||||
|
||||
// Look for NewWindowTitle.
|
||||
|
||||
hwndFound = FindWindow(NULL, pszNewWindowTitle);
|
||||
|
||||
// Restore original window title.
|
||||
|
||||
SetConsoleTitle(pszOldWindowTitle);
|
||||
|
||||
return(hwndFound);
|
||||
|
||||
}
|
||||
#endif // win32
|
26
Source/Plugins/Plugin_Wiimote/Src/Console.h
Normal file
26
Source/Plugins/Plugin_Wiimote/Src/Console.h
Normal file
@ -0,0 +1,26 @@
|
||||
// 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/
|
||||
|
||||
|
||||
void startConsoleWin(int width, int height, char* fname);
|
||||
int wprintf(char *fmt, ...);
|
||||
int aprintf(int a, char *fmt, ...);
|
||||
void ClearScreen();
|
||||
|
||||
#ifdef _WIN32
|
||||
HWND GetConsoleHwnd(void);
|
||||
#endif
|
259
Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp
Normal file
259
Source/Plugins/Plugin_Wiimote/Src/DataReports.cpp
Normal file
@ -0,0 +1,259 @@
|
||||
// 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/
|
||||
|
||||
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Data reports guide. The different structures location in the Input reports. The ? in
|
||||
the IR coordinates is the High coordinates that are four in one byte. */
|
||||
// ----------------
|
||||
|
||||
/* 0x33
|
||||
[c.left etc] [c.a etc] acc.x y z ir0.x y ? ir1.x y ? ir2.x y ? ir3.x y ?
|
||||
|
||||
0x37
|
||||
[c.left etc] [c.a etc] acc.x y z ir0.x1 y1 ? x2 y2 ir1.x1 y1 ? x2 y2 ext.jx jy ax ay az bt*/
|
||||
|
||||
// ================
|
||||
|
||||
|
||||
|
||||
|
||||
#include "pluginspecs_wiimote.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Common.h"
|
||||
#include "wiimote_hid.h"
|
||||
#include "EmuSubroutines.h"
|
||||
#include "EmuDefinitions.h"
|
||||
#include "Encryption.h" // for extension encryption
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
#include "Config.h" // for g_Config
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
//extern void __Log(int log, const char *format, ...);
|
||||
//extern void __Log(int log, int v, const char *format, ...);
|
||||
|
||||
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
//******************************************************************************
|
||||
// Subroutines
|
||||
//******************************************************************************
|
||||
|
||||
|
||||
void WmDataReporting(u16 _channelID, wm_data_reporting* dr)
|
||||
{
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "===========================================================");
|
||||
LOG(WII_IPC_WIIMOTE, " Set Data reporting mode");
|
||||
LOG(WII_IPC_WIIMOTE, " Rumble: %x", dr->rumble);
|
||||
LOG(WII_IPC_WIIMOTE, " Continuous: %x", dr->continuous);
|
||||
LOG(WII_IPC_WIIMOTE, " All The Time: %x (not only on data change)", dr->all_the_time);
|
||||
LOG(WII_IPC_WIIMOTE, " Rumble: %x", dr->rumble);
|
||||
LOG(WII_IPC_WIIMOTE, " Mode: 0x%02x", dr->mode);
|
||||
wprintf("\nData reporting mode: 0x%02x", dr->mode);
|
||||
wprintf("\nData reporting channel: 0x%04x\n", _channelID);
|
||||
|
||||
|
||||
g_ReportingMode = dr->mode;
|
||||
g_ReportingChannel = _channelID;
|
||||
switch(dr->mode) { //see Wiimote_Update()
|
||||
case WM_REPORT_CORE:
|
||||
case WM_REPORT_CORE_ACCEL:
|
||||
case WM_REPORT_CORE_ACCEL_IR12:
|
||||
case WM_REPORT_CORE_ACCEL_EXT16:
|
||||
case WM_REPORT_CORE_ACCEL_IR10_EXT6:
|
||||
break;
|
||||
default:
|
||||
PanicAlert("Wiimote: Unknown reporting mode 0x%x", dr->mode);
|
||||
}
|
||||
|
||||
// WmSendAck(_channelID, WM_DATA_REPORTING);
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "===========================================================");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Case 0x30: Core Buttons */
|
||||
// ----------------
|
||||
void SendReportCore(u16 _channelID)
|
||||
{
|
||||
u8 DataFrame[1024];
|
||||
u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE);
|
||||
|
||||
wm_report_core* pReport = (wm_report_core*)(DataFrame + Offset);
|
||||
Offset += sizeof(wm_report_core);
|
||||
memset(pReport, 0, sizeof(wm_report_core));
|
||||
|
||||
FillReportInfo(pReport->c);
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " SendReportCore()");
|
||||
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* 0x31: Core Buttons and Accelerometer */
|
||||
// ----------------
|
||||
void SendReportCoreAccel(u16 _channelID)
|
||||
{
|
||||
u8 DataFrame[1024];
|
||||
u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL);
|
||||
|
||||
wm_report_core_accel* pReport = (wm_report_core_accel*)(DataFrame + Offset);
|
||||
Offset += sizeof(wm_report_core_accel);
|
||||
memset(pReport, 0, sizeof(wm_report_core_accel));
|
||||
|
||||
FillReportInfo(pReport->c);
|
||||
FillReportAcc(pReport->a);
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " SendReportCoreAccel()");
|
||||
|
||||
// Debugging
|
||||
/*if(GetAsyncKeyState('V'))
|
||||
{
|
||||
wprintf("DataFrame: ");
|
||||
for (int i = 0; i < Offset; i++)
|
||||
{
|
||||
wprintf("%02x ", DataFrame[i]);
|
||||
if((i + 1) % 30 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n");
|
||||
}*/
|
||||
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Case 0x33: Core Buttons and Accelerometer with 12 IR bytes */
|
||||
// ----------------
|
||||
void SendReportCoreAccelIr12(u16 _channelID) {
|
||||
u8 DataFrame[1024];
|
||||
u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL_IR12);
|
||||
|
||||
wm_report_core_accel_ir12* pReport = (wm_report_core_accel_ir12*)(DataFrame + Offset);
|
||||
Offset += sizeof(wm_report_core_accel_ir12);
|
||||
memset(pReport, 0, sizeof(wm_report_core_accel_ir12));
|
||||
|
||||
FillReportInfo(pReport->c);
|
||||
FillReportAcc(pReport->a);
|
||||
|
||||
// We settle with emulating two objects, not all four
|
||||
FillReportIR(pReport->ir[0], pReport->ir[1]);
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " SendReportCoreAccelIr12()");
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " Offset: %08x", Offset);
|
||||
|
||||
// Debugging
|
||||
#ifdef _WIN32
|
||||
/*if(GetAsyncKeyState('V'))
|
||||
{
|
||||
wprintf("DataFrame: ");
|
||||
for (int i = 0; i < Offset; i++)
|
||||
{
|
||||
wprintf("%02x ", DataFrame[i]);
|
||||
if((i + 1) % 30 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n");
|
||||
}*/
|
||||
#endif
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Case 0x35: Core Buttons and Accelerometer with 16 Extension Bytes */
|
||||
// ----------------
|
||||
void SendReportCoreAccelExt16(u16 _channelID)
|
||||
{
|
||||
u8 DataFrame[1024];
|
||||
u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL_EXT16);
|
||||
|
||||
wm_report_core_accel_ext16* pReport = (wm_report_core_accel_ext16*)(DataFrame + Offset);
|
||||
Offset += sizeof(wm_report_core_accel_ext16);
|
||||
memset(pReport, 0, sizeof(wm_report_core_accel_ext16));
|
||||
|
||||
FillReportInfo(pReport->c);
|
||||
FillReportAcc(pReport->a);
|
||||
//FillReportIRBasic(pReport->ir[0], pReport->ir[1]); // no IR here
|
||||
FillReportExtension(pReport->ext);
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " SendReportCoreAccelExt16()");
|
||||
|
||||
// Debugging
|
||||
#ifdef _WIN32
|
||||
/*if(GetAsyncKeyState('V'))
|
||||
{
|
||||
wprintf("DataFrame: ");
|
||||
for (int i = 0; i < Offset; i++)
|
||||
{
|
||||
wprintf("%02x ", DataFrame[i]);
|
||||
if((i + 1) % 30 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n");
|
||||
}*/
|
||||
#endif
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Case 0x37: Core Buttons and Accelerometer with 10 IR bytes and 6 Extension Bytes */
|
||||
// ----------------
|
||||
void SendReportCoreAccelIr10Ext(u16 _channelID)
|
||||
{
|
||||
u8 DataFrame[1024];
|
||||
u32 Offset = WriteWmReport(DataFrame, WM_REPORT_CORE_ACCEL_IR10_EXT6);
|
||||
|
||||
wm_report_core_accel_ir10_ext6* pReport = (wm_report_core_accel_ir10_ext6*)(DataFrame + Offset);
|
||||
Offset += sizeof(wm_report_core_accel_ir10_ext6);
|
||||
memset(pReport, 0, sizeof(wm_report_core_accel_ir10_ext6));
|
||||
|
||||
FillReportInfo(pReport->c);
|
||||
FillReportAcc(pReport->a);
|
||||
FillReportIRBasic(pReport->ir[0], pReport->ir[1]);
|
||||
FillReportExtension(pReport->ext);
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " SendReportCoreAccelIr10Ext()");
|
||||
|
||||
// Debugging
|
||||
#ifdef _WIN32
|
||||
/*if(GetAsyncKeyState('V'))
|
||||
{
|
||||
wprintf("DataFrame: ");
|
||||
for (int i = 0; i < Offset; i++)
|
||||
{
|
||||
wprintf("%02x ", DataFrame[i]);
|
||||
if((i + 1) % 30 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n");
|
||||
}*/
|
||||
#endif
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
||||
}
|
||||
|
||||
|
||||
} // end of namespace
|
56
Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp
Normal file
56
Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
// 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/
|
||||
|
||||
#ifndef _EMU_DECLARATIONS_
|
||||
#define _EMU_DECLARATIONS_
|
||||
|
||||
#include "pluginspecs_wiimote.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Common.h"
|
||||
#include "wiimote_hid.h"
|
||||
#include "EmuDefinitions.h"
|
||||
#include "Encryption.h"
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
//******************************************************************************
|
||||
// Definitions and variable declarations
|
||||
//******************************************************************************
|
||||
|
||||
u8 g_Leds = 0x1;
|
||||
|
||||
u8 g_Eeprom[WIIMOTE_EEPROM_SIZE];
|
||||
|
||||
u8 g_RegSpeaker[WIIMOTE_REG_SPEAKER_SIZE];
|
||||
u8 g_RegExt[WIIMOTE_REG_EXT_SIZE];
|
||||
u8 g_RegExtTmp[WIIMOTE_REG_EXT_SIZE];
|
||||
u8 g_RegIr[WIIMOTE_REG_IR_SIZE];
|
||||
|
||||
u8 g_ReportingMode; // the reporting mode and channel id
|
||||
u16 g_ReportingChannel;
|
||||
|
||||
wiimote_key g_ExtKey; // the extension encryption key
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif //_EMU_DECLARATIONS_
|
64
Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h
Normal file
64
Source/Plugins/Plugin_Wiimote/Src/EmuDefinitions.h
Normal file
@ -0,0 +1,64 @@
|
||||
// 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/
|
||||
|
||||
#ifndef _EMU_DEFINITIONS_
|
||||
#define _EMU_DEFINITIONS_
|
||||
|
||||
#include "pluginspecs_wiimote.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Common.h"
|
||||
#include "wiimote_hid.h"
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
//extern void __Log(int log, const char *format, ...);
|
||||
//extern void __Log(int log, int v, const char *format, ...);
|
||||
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
//******************************************************************************
|
||||
// Definitions and variable declarations
|
||||
//******************************************************************************
|
||||
|
||||
/* Libogc bounding box, in smoothed IR coordinates: 232,284 792,704, however, it was
|
||||
possible for me to get a better calibration with these values, if they are not
|
||||
universal for all PCs we have to make a setting for it. */
|
||||
#define LEFT 266
|
||||
#define TOP 211
|
||||
#define RIGHT 752
|
||||
#define BOTTOM 728
|
||||
#define SENSOR_BAR_RADIUS 200
|
||||
|
||||
#define wLEFT 332
|
||||
#define wTOP 348
|
||||
#define wRIGHT 693
|
||||
#define wBOTTOM 625
|
||||
#define wSENSOR_BAR_RADIUS 200
|
||||
|
||||
// vars
|
||||
#define WIIMOTE_EEPROM_SIZE (16*1024)
|
||||
#define WIIMOTE_REG_SPEAKER_SIZE 10
|
||||
#define WIIMOTE_REG_EXT_SIZE 0x100
|
||||
#define WIIMOTE_REG_IR_SIZE 0x34
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif //_EMU_DEFINITIONS_
|
530
Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp
Normal file
530
Source/Plugins/Plugin_Wiimote/Src/EmuMain.cpp
Normal file
@ -0,0 +1,530 @@
|
||||
// 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 "pluginspecs_wiimote.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Common.h"
|
||||
#include "wiimote_hid.h"
|
||||
#include "EmuSubroutines.h"
|
||||
#include "EmuDefinitions.h"
|
||||
#include "EmuMain.h"
|
||||
#include "Encryption.h" // for extension encryption
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
#include "Config.h" // for g_Config
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
//extern void __Log(int log, const char *format, ...);
|
||||
//extern void __Log(int log, int v, const char *format, ...);
|
||||
|
||||
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
//******************************************************************************
|
||||
// Subroutines
|
||||
//******************************************************************************
|
||||
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* 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 */
|
||||
// ----------------
|
||||
void HidOutputReport(u16 _channelID, wm_report* sr) {
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "===========================================================");
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "HidOutputReport (0x%02x)", sr->channel);
|
||||
|
||||
switch(sr->channel)
|
||||
{
|
||||
case 0x10:
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "HidOutputReport: unknown sr->channel 0x10");
|
||||
break;
|
||||
case WM_LEDS: // 0x11
|
||||
WmLeds(_channelID, (wm_leds*)sr->data);
|
||||
break;
|
||||
case WM_DATA_REPORTING: // 0x12
|
||||
WmDataReporting(_channelID, (wm_data_reporting*)sr->data);
|
||||
break;
|
||||
case WM_REQUEST_STATUS: // 0x15
|
||||
//global_struct = (wm_request_status*)sr->data;
|
||||
WmRequestStatus(_channelID, (wm_request_status*)sr->data);
|
||||
break;
|
||||
case WM_READ_DATA: // 0x17
|
||||
WmReadData(_channelID, (wm_read_data*)sr->data);
|
||||
break;
|
||||
case WM_IR_PIXEL_CLOCK: // 0x13
|
||||
case WM_IR_LOGIC: // 0x1a
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " IR Enable 0x%02x 0x%02x", sr->channel, sr->data[0]);
|
||||
break;
|
||||
case WM_WRITE_DATA: // 0x16
|
||||
WmWriteData(_channelID, (wm_write_data*)sr->data);
|
||||
break;
|
||||
case WM_SPEAKER_ENABLE:
|
||||
LOGV(WII_IPC_WIIMOTE, 1, " WM Speaker Enable 0x%02x 0x%02x", sr->channel, sr->data[0]);
|
||||
break;
|
||||
case WM_SPEAKER_MUTE:
|
||||
LOGV(WII_IPC_WIIMOTE, 1, " WM Mute Enable 0x%02x 0x%02x", sr->channel, sr->data[0]);
|
||||
break;
|
||||
default:
|
||||
PanicAlert("HidOutputReport: Unknown channel 0x%02x", sr->channel);
|
||||
return;
|
||||
}
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "===========================================================");
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Generate the right address for wm reports. */
|
||||
// ----------------
|
||||
int WriteWmReport(u8* dst, u8 channel) {
|
||||
u32 Offset = 0;
|
||||
hid_packet* pHidHeader = (hid_packet*)(dst + Offset);
|
||||
Offset += sizeof(hid_packet);
|
||||
pHidHeader->type = HID_TYPE_DATA;
|
||||
pHidHeader->param = HID_PARAM_INPUT;
|
||||
|
||||
wm_report* pReport = (wm_report*)(dst + Offset);
|
||||
Offset += sizeof(wm_report);
|
||||
pReport->channel = channel;
|
||||
return Offset;
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* LED (blue lights) report. */
|
||||
// ----------------
|
||||
void WmLeds(u16 _channelID, wm_leds* leds) {
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "===========================================================");
|
||||
|
||||
LOG(WII_IPC_WIIMOTE, " Set LEDs");
|
||||
LOG(WII_IPC_WIIMOTE, " Leds: %x", leds->leds);
|
||||
LOG(WII_IPC_WIIMOTE, " Rumble: %x", leds->rumble);
|
||||
|
||||
g_Leds = leds->leds;
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "===========================================================");
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* This will generate the 0x22 acknowledgment after all Input reports. It will
|
||||
have the form a1 22 00 00 _reportID 00. The first two bytes are unknown but
|
||||
00 00 seems to work fine. */
|
||||
// ----------------
|
||||
void WmSendAck(u16 _channelID, u8 _reportID, u32 address)
|
||||
{
|
||||
u8 DataFrame[1024];
|
||||
|
||||
u32 Offset = 0;
|
||||
|
||||
// Header
|
||||
hid_packet* pHidHeader = (hid_packet*)(DataFrame + Offset);
|
||||
pHidHeader->type = HID_TYPE_DATA;
|
||||
pHidHeader->param = HID_PARAM_INPUT;
|
||||
Offset += sizeof(hid_packet);
|
||||
|
||||
wm_acknowledge* pData = (wm_acknowledge*)(DataFrame + Offset);
|
||||
pData->Channel = WM_WRITE_DATA_REPLY;
|
||||
pData->unk0 = 0;
|
||||
pData->unk1 = 0;
|
||||
pData->reportID = _reportID;
|
||||
pData->errorID = 0;
|
||||
Offset += sizeof(wm_acknowledge);
|
||||
|
||||
/* Debug. Write the report for extension registry writes.
|
||||
if((_reportID == 0x16 || _reportID == 0x17) && ((address >> 16) & 0xfe) == 0xa4)
|
||||
{
|
||||
wprintf("\nWMSendAck Report ID: %02x KeyReady: %i, Encryption: %02x\n",
|
||||
_reportID, (int)KeyReady, g_RegExt[0xf0]);
|
||||
wprintf("Data: ");
|
||||
for (int i = 0; i < Offset; i++)
|
||||
{
|
||||
wprintf("%02x ", DataFrame[i]);
|
||||
if((i + 1) % 20 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n");
|
||||
}*/
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " WMSendAck()");
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " Report ID: %02x", _reportID);
|
||||
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Read data from Wiimote and Extensions registers. */
|
||||
// ----------------
|
||||
void WmReadData(u16 _channelID, wm_read_data* rd)
|
||||
{
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "===========================================================");
|
||||
u32 address = convert24bit(rd->address);
|
||||
u16 size = convert16bit(rd->size);
|
||||
LOG(WII_IPC_WIIMOTE, " Read data");
|
||||
LOG(WII_IPC_WIIMOTE, " Address space: %x", rd->space);
|
||||
LOG(WII_IPC_WIIMOTE, " Address: 0x%06x", address);
|
||||
LOG(WII_IPC_WIIMOTE, " Size: 0x%04x", size);
|
||||
LOG(WII_IPC_WIIMOTE, " Rumble: %x", rd->rumble);
|
||||
|
||||
//u32 _address = address;
|
||||
|
||||
if(rd->space == 0)
|
||||
{
|
||||
if (address + size > WIIMOTE_EEPROM_SIZE)
|
||||
{
|
||||
PanicAlert("WmReadData: address + size out of bounds!");
|
||||
return;
|
||||
}
|
||||
SendReadDataReply(_channelID, g_Eeprom+address, address, (u8)size);
|
||||
}
|
||||
else if(rd->space == WM_SPACE_REGS1 || rd->space == WM_SPACE_REGS2)
|
||||
{
|
||||
u8* block;
|
||||
u32 blockSize;
|
||||
switch((address >> 16) & 0xFE)
|
||||
{
|
||||
/**/ case 0xA2:
|
||||
block = g_RegSpeaker;
|
||||
blockSize = WIIMOTE_REG_SPEAKER_SIZE;
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "WmReadData: 0xB0 g_RegSpeaker");
|
||||
break;
|
||||
case 0xA4:
|
||||
block = g_RegExt;
|
||||
blockSize = WIIMOTE_REG_EXT_SIZE;
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " Case 0xA4: Read ExtReg ****************************");
|
||||
//wprintf("WmReadData\n"); ReadExt();
|
||||
break;
|
||||
/**/ case 0xB0:
|
||||
block = g_RegIr;
|
||||
blockSize = WIIMOTE_REG_IR_SIZE;
|
||||
//PanicAlert("WmReadData: 0xB0 g_RegIr");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "WmReadData: 0xB0 g_RegIr");
|
||||
break;
|
||||
default:
|
||||
PanicAlert("WmWriteData: bad register block!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------
|
||||
// Encrypt data that is read from the Wiimote Extension Register
|
||||
// -------------
|
||||
if(((address >> 16) & 0xfe) == 0xa4)
|
||||
{
|
||||
wprintf("\n\nWmReadData Address: %08x Offset: %08x Size: %i byte\n",
|
||||
address, address & 0xffff, (u8)size);
|
||||
|
||||
// Debugging
|
||||
u32 offset = address & 0xffff;
|
||||
wprintf("Unencrypted data:\n");
|
||||
for (int i = 0; i < (u8)size; i++)
|
||||
{
|
||||
wprintf("%02x ", g_RegExt[i + offset]);
|
||||
if((i + 1) % 20 == 0) wprintf("\n");
|
||||
}
|
||||
|
||||
// Check if encrypted reads is on
|
||||
if(g_RegExt[0xf0] == 0xaa)
|
||||
{
|
||||
// Copy g_RegExt to g_RegExtTmp
|
||||
memcpy(g_RegExtTmp, g_RegExt, sizeof(g_RegExt));
|
||||
|
||||
// Copy the registry to a temporary space
|
||||
memcpy(g_RegExtTmp, g_RegExt, sizeof(g_RegExt));
|
||||
|
||||
// Encrypt the read
|
||||
wiimote_encrypt(&g_ExtKey, &g_RegExtTmp[address & 0xffff], (address & 0xffff), (u8)size);
|
||||
|
||||
/* Debugging
|
||||
wprintf("\nEncrypted data:\n");
|
||||
for (int i = 0; i < (u8)size; i++)
|
||||
{
|
||||
wprintf("%02x ", g_RegExtTmp[i + offset]);
|
||||
if((i + 1) % 20 == 0) wprintf("\n");
|
||||
}
|
||||
|
||||
wprintf("\ng_RegExtTmp after: \n");
|
||||
ReadExtTmp();
|
||||
wprintf("\nFrom g_RegExt: \n");
|
||||
ReadExt();*/
|
||||
|
||||
// Update the block that SendReadDataReply will eventually send to the Wii
|
||||
block = g_RegExtTmp;
|
||||
}
|
||||
|
||||
//wprintf("\n\n");
|
||||
}
|
||||
//---------
|
||||
|
||||
|
||||
address &= 0xFFFF;
|
||||
if(address + size > blockSize) {
|
||||
PanicAlert("WmReadData: address + size out of bounds!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Let this function process the message and send it to the Wii
|
||||
SendReadDataReply(_channelID, block+address, address, (u8)size);
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlert("WmReadData: unimplemented parameters (size: %i, addr: 0x%x!", size, rd->space);
|
||||
}
|
||||
|
||||
// Acknowledge the 0x17 read, we will do this from InterruptChannel()
|
||||
//WmSendAck(_channelID, WM_READ_DATA, _address);
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "===========================================================");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Write data to Wiimote and Extensions registers. */
|
||||
// ----------------
|
||||
void WmWriteData(u16 _channelID, wm_write_data* wd)
|
||||
{
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "========================================================");
|
||||
u32 address = convert24bit(wd->address);
|
||||
LOG(WII_IPC_WIIMOTE, " Write data");
|
||||
LOG(WII_IPC_WIIMOTE, " Address space: %x", wd->space);
|
||||
LOG(WII_IPC_WIIMOTE, " Address: 0x%06x", address);
|
||||
LOG(WII_IPC_WIIMOTE, " Size: 0x%02x", wd->size);
|
||||
LOG(WII_IPC_WIIMOTE, " Rumble: %x", wd->rumble);
|
||||
|
||||
u32 _address = address;
|
||||
|
||||
// Write to EEPROM
|
||||
if(wd->size <= 16 && wd->space == WM_SPACE_EEPROM)
|
||||
{
|
||||
if(address + wd->size > WIIMOTE_EEPROM_SIZE) {
|
||||
PanicAlert("WmWriteData: address + size out of bounds!");
|
||||
return;
|
||||
}
|
||||
memcpy(g_Eeprom + address, wd->data, wd->size);
|
||||
|
||||
// WmSendAck(_channelID, WM_WRITE_DATA);
|
||||
}
|
||||
// Write to registers
|
||||
else if(wd->size <= 16 && (wd->space == WM_SPACE_REGS1 || wd->space == WM_SPACE_REGS2))
|
||||
{
|
||||
u8* block;
|
||||
u32 blockSize;
|
||||
switch((address >> 16) & 0xFE)
|
||||
{
|
||||
case 0xA2:
|
||||
block = g_RegSpeaker;
|
||||
blockSize = WIIMOTE_REG_SPEAKER_SIZE;
|
||||
break;
|
||||
case 0xA4:
|
||||
block = g_RegExt; // Extension Controller register
|
||||
blockSize = WIIMOTE_REG_EXT_SIZE;
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " *******************************************************");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " Case 0xA4: Write ExtReg");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " *******************************************************");
|
||||
wprintf("\n\nWmWriteData Size: %i Address: %08x Offset: %08x \n",
|
||||
wd->size, address, (address & 0xffff));
|
||||
break;
|
||||
case 0xB0:
|
||||
block = g_RegIr;
|
||||
blockSize = WIIMOTE_REG_IR_SIZE;
|
||||
break;
|
||||
default:
|
||||
PanicAlert("WmWriteData: bad register block!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Remove for example 0xa40000 from the address
|
||||
_address = address; address &= 0xFFFF;
|
||||
|
||||
// Check if the address is within bounds
|
||||
if(address + wd->size > blockSize) {
|
||||
PanicAlert("WmWriteData: address + size out of bounds!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Finally write the registers to the right structure
|
||||
memcpy(block + address, wd->data, wd->size);
|
||||
|
||||
// -----------------------------------------
|
||||
// Generate key for the Wiimote Extension
|
||||
// -------------
|
||||
if(blockSize == WIIMOTE_REG_EXT_SIZE)
|
||||
{
|
||||
/* Debugging. Write the data.
|
||||
wprintf("Data: ");
|
||||
for (int i = 0; i < wd->size; i++)
|
||||
{
|
||||
wprintf("%02x ", wd->data[i]);
|
||||
if((i + 1) % 25 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n");
|
||||
|
||||
//wprintf("Current address: %08x\n", address);
|
||||
|
||||
//wprintf("g_RegExt:\n");
|
||||
//ReadExt(); */
|
||||
|
||||
|
||||
/* 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 */
|
||||
if(address >= 0x40 && address <= 0x4c)
|
||||
wiimote_gen_key(&g_ExtKey, &g_RegExt[0x40]);
|
||||
}
|
||||
// -------------
|
||||
|
||||
|
||||
} else {
|
||||
PanicAlert("WmWriteData: unimplemented parameters!");
|
||||
}
|
||||
|
||||
/* Just added for home brew... Isn't it enough that we call this from
|
||||
InterruptChannel()? Or is there a separate route here that don't pass though
|
||||
InterruptChannel()? */
|
||||
//WmSendAck(_channelID, WM_WRITE_DATA, _address);
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "==========================================================");
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* 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 pressedn, 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 the the
|
||||
registry that was read. */
|
||||
// ----------------
|
||||
void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size)
|
||||
{
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "=========================================");
|
||||
int dataOffset = 0;
|
||||
while (_Size > 0)
|
||||
{
|
||||
u8 DataFrame[1024];
|
||||
u32 Offset = WriteWmReport(DataFrame, WM_READ_DATA_REPLY);
|
||||
|
||||
int copySize = _Size;
|
||||
if (copySize > 16)
|
||||
{
|
||||
copySize = 16;
|
||||
}
|
||||
|
||||
wm_read_data_reply* pReply = (wm_read_data_reply*)(DataFrame + Offset);
|
||||
Offset += sizeof(wm_read_data_reply);
|
||||
pReply->buttons = 0;
|
||||
pReply->error = 0;
|
||||
pReply->size = (copySize - 1) & 0xF;
|
||||
pReply->address = Common::swap16(_Address + dataOffset);
|
||||
|
||||
|
||||
// Write a pice
|
||||
memcpy(pReply->data + dataOffset, _Base, copySize);
|
||||
|
||||
if(copySize < 16) // check if we have less than 16 bytes left to send
|
||||
{
|
||||
memset(pReply->data + copySize, 0, 16 - copySize);
|
||||
}
|
||||
dataOffset += copySize;
|
||||
|
||||
|
||||
LOG(WII_IPC_WIIMOTE, " SendReadDataReply()");
|
||||
LOG(WII_IPC_WIIMOTE, " Buttons: 0x%04x", pReply->buttons);
|
||||
LOG(WII_IPC_WIIMOTE, " Error: 0x%x", pReply->error);
|
||||
LOG(WII_IPC_WIIMOTE, " Size: 0x%x", pReply->size);
|
||||
LOG(WII_IPC_WIIMOTE, " Address: 0x%04x", pReply->address);
|
||||
|
||||
|
||||
/* Debugging
|
||||
wprintf("SendReadDataReply Address: %08x\n", _Address);
|
||||
for (int i = 0; i < Offset; i++)
|
||||
{
|
||||
wprintf("%02x ", DataFrame[i]);
|
||||
if((i + 1) % 25 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n\n");*/
|
||||
//---------
|
||||
|
||||
// Send a piece
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
||||
|
||||
_Size -= copySize;
|
||||
}
|
||||
|
||||
if (_Size != 0)
|
||||
{
|
||||
PanicAlert("WiiMote-Plugin: SendReadDataReply() failed");
|
||||
}
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "==========================================");
|
||||
}
|
||||
// ================
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Here we produce a 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 WmRequestStatus(u16 _channelID, wm_request_status* rs)
|
||||
{
|
||||
//PanicAlert("WmRequestStatus");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "================================================");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " Request Status");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " Rumble: %x", rs->rumble);
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " Channel: %04x", _channelID);
|
||||
|
||||
//SendStatusReport();
|
||||
u8 DataFrame[1024];
|
||||
u32 Offset = WriteWmReport(DataFrame, WM_STATUS_REPORT);
|
||||
|
||||
wm_status_report* pStatus = (wm_status_report*)(DataFrame + Offset);
|
||||
Offset += sizeof(wm_status_report);
|
||||
memset(pStatus, 0, sizeof(wm_status_report)); // fill the status report with zeroes
|
||||
|
||||
// Status values
|
||||
pStatus->leds = g_Leds;
|
||||
pStatus->ir = 1;
|
||||
pStatus->battery = 0x4F; //arbitrary number
|
||||
|
||||
// Read config value for this one
|
||||
if(g_Config.bExtensionConnected)
|
||||
pStatus->extension = 1;
|
||||
else
|
||||
pStatus->extension = 0;
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " Extension: %x", pStatus->extension);
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " SendStatusReport()");
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " Flags: 0x%02x", pStatus->padding1[2]);
|
||||
LOGV(WII_IPC_WIIMOTE, 0, " Battery: %d", pStatus->battery);
|
||||
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "=================================================");
|
||||
}
|
||||
|
||||
} // end of namespace
|
40
Source/Plugins/Plugin_Wiimote/Src/EmuMain.h
Normal file
40
Source/Plugins/Plugin_Wiimote/Src/EmuMain.h
Normal file
@ -0,0 +1,40 @@
|
||||
// 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/
|
||||
|
||||
#ifndef WIIMOTE_EMU_H
|
||||
#define WIIMOTE_EMU_H
|
||||
|
||||
#include "wiimote_hid.h"
|
||||
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
void Initialize();
|
||||
void DoState(void* ptr, int mode);
|
||||
void Shutdown(void);
|
||||
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size);
|
||||
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) ;
|
||||
void Update();
|
||||
|
||||
//void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1);
|
||||
|
||||
void ReadExt(); // Debugging
|
||||
void ReadExtTmp();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
288
Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp
Normal file
288
Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.cpp
Normal file
@ -0,0 +1,288 @@
|
||||
// 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/
|
||||
|
||||
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* 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 "pluginspecs_wiimote.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Common.h"
|
||||
#include "wiimote_hid.h"
|
||||
#include "EmuSubroutines.h"
|
||||
#include "EmuDefinitions.h"
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
|
||||
//******************************************************************************
|
||||
// Subroutine declarations
|
||||
//******************************************************************************
|
||||
|
||||
u32 convert24bit(const u8* src) {
|
||||
return (src[0] << 16) | (src[1] << 8) | src[2];
|
||||
}
|
||||
|
||||
u16 convert16bit(const u8* src) {
|
||||
return (src[0] << 8) | src[1];
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Calibrate the mouse position to the emulation window. */
|
||||
// ----------------
|
||||
void GetMousePos(float& x, float& y)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
POINT point;
|
||||
|
||||
GetCursorPos(&point);
|
||||
ScreenToClient(g_WiimoteInitialize.hWnd, &point);
|
||||
|
||||
RECT Rect;
|
||||
GetClientRect(g_WiimoteInitialize.hWnd, &Rect);
|
||||
|
||||
int width = Rect.right - Rect.left;
|
||||
int height = Rect.bottom - Rect.top;
|
||||
|
||||
x = point.x / (float)width;
|
||||
y = point.y / (float)height;
|
||||
#else
|
||||
// TODO fix on linux
|
||||
x = 0.5f;
|
||||
y = 0.5f;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Homebrew encryption for 0x00000000 encryption keys. */
|
||||
// ----------------
|
||||
void CryptBuffer(u8* _buffer, u8 _size)
|
||||
{
|
||||
for (int i=0; i<_size; i++)
|
||||
{
|
||||
_buffer[i] = ((_buffer[i] - 0x17) ^ 0x17) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
void WriteCrypted16(u8* _baseBlock, u16 _address, u16 _value)
|
||||
{
|
||||
u16 cryptedValue = _value;
|
||||
CryptBuffer((u8*)&cryptedValue, sizeof(u16));
|
||||
|
||||
*(u16*)(_baseBlock + _address) = cryptedValue;
|
||||
//PanicAlert("Converted %04x to %04x", _value, cryptedValue);
|
||||
}
|
||||
// ================
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Write initial values to Eeprom and registers. */
|
||||
// ----------------
|
||||
void Initialize()
|
||||
{
|
||||
memset(g_Eeprom, 0, WIIMOTE_EEPROM_SIZE);
|
||||
memcpy(g_Eeprom, EepromData_0, sizeof(EepromData_0));
|
||||
memcpy(g_Eeprom + 0x16D0, EepromData_16D0, sizeof(EepromData_16D0));
|
||||
|
||||
g_ReportingMode = 0;
|
||||
|
||||
|
||||
/* Extension data for homebrew applications that use the 0x00000000 key. This
|
||||
writes 0x0000 in encrypted form (0xfefe) to 0xfe in the extension register. */
|
||||
//WriteCrypted16(g_RegExt, 0xfe, 0x0000); // Fully inserted Nunchuk
|
||||
|
||||
|
||||
// Copy nuncuck id and calibration to its register
|
||||
memcpy(g_RegExt + 0x20, nunchuck_calibration, sizeof(nunchuck_calibration));
|
||||
memcpy(g_RegExt + 0xfa, nunchuck_id, sizeof(nunchuck_id));
|
||||
|
||||
|
||||
// g_RegExt[0xfd] = 0x1e;
|
||||
// g_RegExt[0xfc] = 0x9a;
|
||||
}
|
||||
// ================
|
||||
|
||||
|
||||
void DoState(void* ptr, int mode)
|
||||
{
|
||||
//TODO: implement
|
||||
}
|
||||
|
||||
void Shutdown(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* This function produce Wiimote Input, i.e. reports from the Wiimote in response
|
||||
to Output from the Wii. */
|
||||
// ----------------
|
||||
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
|
||||
{
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "=============================================================");
|
||||
const u8* data = (const u8*)_pData;
|
||||
|
||||
// Debugging. Dump raw data.
|
||||
{
|
||||
LOG(WII_IPC_WIIMOTE, "Wiimote_Input");
|
||||
std::string Temp;
|
||||
for (u32 j=0; j<_Size; j++)
|
||||
{
|
||||
char Buffer[128];
|
||||
sprintf(Buffer, "%02x ", data[j]);
|
||||
Temp.append(Buffer);
|
||||
}
|
||||
LOG(WII_IPC_WIIMOTE, " Data: %s", Temp.c_str());
|
||||
}
|
||||
hid_packet* hidp = (hid_packet*) data;
|
||||
|
||||
switch(hidp->type)
|
||||
{
|
||||
case HID_TYPE_DATA:
|
||||
{
|
||||
switch(hidp->param)
|
||||
{
|
||||
case HID_PARAM_OUTPUT:
|
||||
{
|
||||
wm_report* sr = (wm_report*)hidp->data;
|
||||
|
||||
HidOutputReport(_channelID, sr);
|
||||
|
||||
/* This is the 0x22 answer to all Inputs. In most games it didn't matter
|
||||
if it was written before or after HidOutputReport(), but Wii Sports
|
||||
and Mario Galaxy would stop working if it was placed before
|
||||
HidOutputReport(). */
|
||||
wm_write_data *wd = (wm_write_data*)sr->data;
|
||||
u32 address = convert24bit(wd->address);
|
||||
WmSendAck(_channelID, sr->channel, address);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
PanicAlert("HidInput: HID_TYPE_DATA - param 0x%02x", hidp->type, hidp->param);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
PanicAlert("HidInput: Unknown type 0x%02x and param 0x%02x", hidp->type, hidp->param);
|
||||
break;
|
||||
}
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "=============================================================");
|
||||
}
|
||||
|
||||
|
||||
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
|
||||
{
|
||||
const u8* data = (const u8*)_pData;
|
||||
// dump raw data
|
||||
{
|
||||
LOG(WII_IPC_WIIMOTE, "Wiimote_ControlChannel");
|
||||
std::string Temp;
|
||||
for (u32 j=0; j<_Size; j++)
|
||||
{
|
||||
char Buffer[128];
|
||||
sprintf(Buffer, "%02x ", data[j]);
|
||||
Temp.append(Buffer);
|
||||
}
|
||||
LOG(WII_IPC_WIIMOTE, " Data: %s", Temp.c_str());
|
||||
}
|
||||
|
||||
hid_packet* hidp = (hid_packet*) data;
|
||||
switch(hidp->type)
|
||||
{
|
||||
case HID_TYPE_HANDSHAKE:
|
||||
if (hidp->param == HID_PARAM_INPUT)
|
||||
{
|
||||
PanicAlert("HID_TYPE_HANDSHAKE - HID_PARAM_INPUT");
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlert("HID_TYPE_HANDSHAKE - HID_PARAM_OUTPUT");
|
||||
}
|
||||
break;
|
||||
|
||||
case HID_TYPE_SET_REPORT:
|
||||
if (hidp->param == HID_PARAM_INPUT)
|
||||
{
|
||||
PanicAlert("HID_TYPE_SET_REPORT input");
|
||||
}
|
||||
else
|
||||
{
|
||||
HidOutputReport(_channelID, (wm_report*)hidp->data);
|
||||
|
||||
//return handshake
|
||||
u8 handshake = 0;
|
||||
g_WiimoteInitialize.pWiimoteInput(_channelID, &handshake, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case HID_TYPE_DATA:
|
||||
PanicAlert("HID_TYPE_DATA %s", hidp->type, hidp->param == HID_PARAM_INPUT ? "input" : "output");
|
||||
break;
|
||||
|
||||
default:
|
||||
PanicAlert("HidControlChanel: Unknown type %x and param %x", hidp->type, hidp->param);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//LOG(WII_IPC_WIIMOTE, "Wiimote_Update");
|
||||
|
||||
switch(g_ReportingMode) {
|
||||
case 0:
|
||||
break;
|
||||
case WM_REPORT_CORE: SendReportCore(g_ReportingChannel); break;
|
||||
case WM_REPORT_CORE_ACCEL: SendReportCoreAccel(g_ReportingChannel); break;
|
||||
case WM_REPORT_CORE_ACCEL_IR12: SendReportCoreAccelIr12(g_ReportingChannel);break;
|
||||
case WM_REPORT_CORE_ACCEL_EXT16: SendReportCoreAccelExt16(g_ReportingChannel);break;
|
||||
case WM_REPORT_CORE_ACCEL_IR10_EXT6: SendReportCoreAccelIr10Ext(g_ReportingChannel);break;
|
||||
}
|
||||
// g_ReportingMode = 0;
|
||||
}
|
||||
|
||||
}
|
140
Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h
Normal file
140
Source/Plugins/Plugin_Wiimote/Src/EmuSubroutines.h
Normal file
@ -0,0 +1,140 @@
|
||||
// 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/
|
||||
|
||||
#ifndef _EMU_DECLARATIONS_
|
||||
#define _EMU_DECLARATIONS_
|
||||
|
||||
#include "pluginspecs_wiimote.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Common.h"
|
||||
#include "wiimote_hid.h"
|
||||
#include "EmuDefinitions.h"
|
||||
#include "Encryption.h"
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
//extern void __Log(int log, const char *format, ...);
|
||||
//extern void __Log(int log, int v, const char *format, ...);
|
||||
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
//******************************************************************************
|
||||
// Definitions and variable declarations
|
||||
//******************************************************************************
|
||||
|
||||
|
||||
//extern u8 g_Leds = 0x1;
|
||||
extern u8 g_Leds;
|
||||
|
||||
extern u8 g_Eeprom[WIIMOTE_EEPROM_SIZE];
|
||||
|
||||
extern u8 g_RegSpeaker[WIIMOTE_REG_SPEAKER_SIZE];
|
||||
extern u8 g_RegExt[WIIMOTE_REG_EXT_SIZE];
|
||||
extern u8 g_RegExtTmp[WIIMOTE_REG_EXT_SIZE];
|
||||
extern u8 g_RegIr[WIIMOTE_REG_IR_SIZE];
|
||||
|
||||
extern u8 g_ReportingMode;
|
||||
extern u16 g_ReportingChannel;
|
||||
|
||||
extern wiimote_key g_ExtKey; // extension encryption key
|
||||
|
||||
|
||||
static const u8 EepromData_0[] = {
|
||||
0xA1, 0xAA, 0x8B, 0x99, 0xAE, 0x9E, 0x78, 0x30,
|
||||
0xA7, 0x74, 0xD3, 0xA1, 0xAA, 0x8B, 0x99, 0xAE,
|
||||
0x9E, 0x78, 0x30, 0xA7, 0x74, 0xD3, 0x82, 0x82,
|
||||
0x82, 0x15, 0x9C, 0x9C, 0x9E, 0x38, 0x40, 0x3E,
|
||||
0x82, 0x82, 0x82, 0x15, 0x9C, 0x9C, 0x9E, 0x38,
|
||||
0x40, 0x3E
|
||||
};
|
||||
|
||||
static const u8 EepromData_16D0[] = {
|
||||
0x00, 0x00, 0x00, 0xFF, 0x11, 0xEE, 0x00, 0x00,
|
||||
0x33, 0xCC, 0x44, 0xBB, 0x00, 0x00, 0x66, 0x99,
|
||||
0x77, 0x88, 0x00, 0x00, 0x2B, 0x01, 0xE8, 0x13
|
||||
};
|
||||
|
||||
|
||||
/* 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, 0xb3,0xb3,0xb3,0x00,
|
||||
0xe0,0x20,0x80,0xe0, 0x20,0x80,0xee,0x43,
|
||||
0x80,0x80,0x80,0x00, 0xb3,0xb3,0xb3,0x00,
|
||||
0xe0,0x20,0x80,0xe0, 0x20,0x80,0xee,0x43
|
||||
};
|
||||
|
||||
|
||||
/* The nunchuck id. It should be written to the last bytes of the
|
||||
extension register */
|
||||
static const u8 nunchuck_id[] =
|
||||
{
|
||||
0x00, 0x00, 0xa4, 0x20, 0x00, 0x00
|
||||
};
|
||||
|
||||
/* 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
|
||||
};
|
||||
|
||||
|
||||
void HidOutputReport(u16 _channelID, wm_report* sr);
|
||||
|
||||
void WmLeds(u16 _channelID, wm_leds* leds);
|
||||
void WmReadData(u16 _channelID, wm_read_data* rd);
|
||||
void WmWriteData(u16 _channelID, wm_write_data* wd);
|
||||
void WmRequestStatus(u16 _channelID, wm_request_status* rs);
|
||||
void WmRequestStatus_(u16 _channelID, int a);
|
||||
void WmDataReporting(u16 _channelID, wm_data_reporting* dr);
|
||||
|
||||
void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size);
|
||||
void SendReportCoreAccel(u16 _channelID);
|
||||
void SendReportCoreAccelIr12(u16 _channelID);
|
||||
void SendReportCore(u16 _channelID);
|
||||
void SendReportCoreAccelExt16(u16 _channelID);
|
||||
void SendReportCoreAccelIr10Ext(u16 _channelID);
|
||||
|
||||
int WriteWmReport(u8* dst, u8 channel);
|
||||
void WmSendAck(u16 _channelID, u8 _reportID, u32 address);
|
||||
|
||||
|
||||
void FillReportAcc(wm_accel& _acc);
|
||||
void FillReportInfo(wm_core& _core);
|
||||
void FillReportIR(wm_ir_extended& _ir0, wm_ir_extended& _ir1);
|
||||
void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1);
|
||||
void FillReportExtension(wm_extension& _ext);
|
||||
|
||||
|
||||
u32 convert24bit(const u8* src);
|
||||
u16 convert16bit(const u8* src);
|
||||
void GetMousePos(float& x, float& y);
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif //_EMU_DECLARATIONS_
|
297
Source/Plugins/Plugin_Wiimote/Src/Encryption.cpp
Normal file
297
Source/Plugins/Plugin_Wiimote/Src/Encryption.cpp
Normal file
@ -0,0 +1,297 @@
|
||||
// Copyright (C) 2003-2008 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 "pluginspecs_wiimote.h"
|
||||
#include "Common.h"
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
#include "Encryption.h"
|
||||
|
||||
|
||||
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},
|
||||
};
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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(u8 a, u8 b) {
|
||||
return (a>>b) | ((a<<(8-b))&0xff);
|
||||
}
|
||||
|
||||
|
||||
void genkey(u8 *rand, u8 idx, u8 *key)
|
||||
{
|
||||
u8 *ans = ans_tbl[idx];
|
||||
u8 t0[10];
|
||||
int i;
|
||||
|
||||
for(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(u8 *rand, u8 *key, u8 idx, u8 *ft, u8 *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 *key, u8 *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];
|
||||
|
||||
wprintf("rand: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", rand[0], rand[1], rand[2], rand[3], rand[4], rand[5], rand[6], rand[7], rand[8], rand[9]);
|
||||
wprintf("key: %02x %02x %02x %02x %02x %02x\n", skey[0], skey[1], skey[2], skey[3], skey[4], skey[5]);
|
||||
|
||||
for(idx=0;idx<7;idx++)
|
||||
{
|
||||
genkey(rand, idx, testkey);
|
||||
if(!memcmp(testkey,skey,6))
|
||||
break;
|
||||
}
|
||||
// default case is idx = 7 which is valid (homebrew uses it for the 0x17 case)
|
||||
wprintf("idx: %d\n", idx);
|
||||
|
||||
gentabs(rand, skey, idx, key->ft, key->sb);
|
||||
|
||||
wprintf("ft: %02x %02x %02x %02x %02x %02x %02x %02x\n", key->ft[0], key->ft[1], key->ft[2], key->ft[3], key->ft[4], key->ft[5], key->ft[6], key->ft[7]);
|
||||
wprintf("sb: %02x %02x %02x %02x %02x %02x %02x %02x\n", 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
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Encrypt data */
|
||||
// ----------------
|
||||
void wiimote_encrypt(wiimote_key *key, u8 *data, int addr, u8 len)
|
||||
{
|
||||
for(int i = 0; i < len; i++, addr++)
|
||||
{
|
||||
//wprintf("data[%i] from %02x ", i, data[i]);
|
||||
data[i] = (data[i] - key->ft[addr%8]) ^ key->sb[addr%8];
|
||||
//wprintf("to %02x\n", data[i]);
|
||||
}
|
||||
}
|
38
Source/Plugins/Plugin_Wiimote/Src/Encryption.h
Normal file
38
Source/Plugins/Plugin_Wiimote/Src/Encryption.h
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2003-2008 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/
|
||||
|
||||
|
||||
#ifndef WIIMOTE_EXTENSION_ENCRYPTION_H
|
||||
#define WIIMOTE_EXTENSION_ENCRYPTION_H
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* They key structure to use with wiimote_gen_key() */
|
||||
// ----------------
|
||||
typedef struct {
|
||||
u8 ft[8];
|
||||
u8 sb[8];
|
||||
} wiimote_key;
|
||||
|
||||
|
||||
void wiimote_encrypt(wiimote_key *key, u8 *data, int addr, u8 len);
|
||||
|
||||
void wiimote_gen_key(wiimote_key *key, u8 *keydata);
|
||||
|
||||
|
||||
#endif
|
549
Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp
Normal file
549
Source/Plugins/Plugin_Wiimote/Src/FillReport.cpp
Normal file
@ -0,0 +1,549 @@
|
||||
// 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 <wx/msgdlg.h>
|
||||
|
||||
#include "pluginspecs_wiimote.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Common.h"
|
||||
#include "wiimote_hid.h"
|
||||
#include "EmuSubroutines.h"
|
||||
#include "EmuDefinitions.h"
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
#include "Config.h" // for g_Config
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
|
||||
|
||||
namespace WiiMoteEmu
|
||||
{
|
||||
|
||||
//******************************************************************************
|
||||
// Subroutines
|
||||
//******************************************************************************
|
||||
|
||||
|
||||
|
||||
/* Debugging. Read out the structs. */
|
||||
void ReadExt()
|
||||
{
|
||||
for (int i = 0; i < WIIMOTE_REG_EXT_SIZE; i++)
|
||||
{
|
||||
//wprintf("%i | (i % 16)
|
||||
wprintf("%02x ", g_RegExt[i]);
|
||||
if((i + 1) % 20 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n\n");
|
||||
}
|
||||
|
||||
|
||||
void ReadExtTmp()
|
||||
{
|
||||
for (int i = 0; i < WIIMOTE_REG_EXT_SIZE; i++)
|
||||
{
|
||||
//wprintf("%i | (i % 16)
|
||||
wprintf("%02x ", g_RegExtTmp[i]);
|
||||
if((i + 1) % 20 == 0) wprintf("\n");
|
||||
}
|
||||
wprintf("\n\n");
|
||||
}
|
||||
|
||||
|
||||
void FillReportInfo(wm_core& _core)
|
||||
{
|
||||
memset(&_core, 0x00, sizeof(wm_core));
|
||||
|
||||
#ifdef _WIN32
|
||||
// allow both mouse buttons and keyboard to press a and b
|
||||
if(GetAsyncKeyState(VK_LBUTTON) ? 1 : 0 || GetAsyncKeyState('A') ? 1 : 0)
|
||||
_core.a = 1;
|
||||
|
||||
if(GetAsyncKeyState(VK_RBUTTON) ? 1 : 0 || GetAsyncKeyState('B') ? 1 : 0)
|
||||
_core.b = 1;
|
||||
|
||||
_core.one = GetAsyncKeyState('1') ? 1 : 0;
|
||||
_core.two = GetAsyncKeyState('2') ? 1 : 0;
|
||||
_core.plus = GetAsyncKeyState('P') ? 1 : 0;
|
||||
_core.minus = GetAsyncKeyState('M') ? 1 : 0;
|
||||
_core.home = GetAsyncKeyState('H') ? 1 : 0;
|
||||
|
||||
|
||||
/* Sideways controls (for example for Wario Land) was not enabled automatically
|
||||
so I have to use this function. I'm not sure how it works on the actual Wii.
|
||||
*/
|
||||
if(g_Config.bSidewaysDPad)
|
||||
{
|
||||
_core.left = GetAsyncKeyState(VK_DOWN) ? 1 : 0;
|
||||
_core.up = GetAsyncKeyState(VK_LEFT) ? 1 : 0;
|
||||
_core.right = GetAsyncKeyState(VK_UP) ? 1 : 0;
|
||||
_core.down = GetAsyncKeyState(VK_RIGHT) ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_core.left = GetAsyncKeyState(VK_LEFT) ? 1 : 0;
|
||||
_core.up = GetAsyncKeyState(VK_UP) ? 1 : 0;
|
||||
_core.right = GetAsyncKeyState(VK_RIGHT) ? 1 : 0;
|
||||
_core.down = GetAsyncKeyState(VK_DOWN) ? 1 : 0;
|
||||
}
|
||||
#else
|
||||
// TODO: fill in
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
/* Global declarations for FillReportAcc. The accelerometer x, y and z values range from
|
||||
0x00 to 0xff with the default netural values being [y = 0x84, x = 0x84, z = 0x9f]
|
||||
according to a source. The extremes are 0x00 for (-) and 0xff for (+). It's important
|
||||
that all values are not 0x80, the the mouse pointer can disappear from the screen
|
||||
permanently then, until z is adjusted back. */
|
||||
// ----------
|
||||
// the variables are global so they can be changed during debugging
|
||||
//int A = 0, B = 128, C = 64; // for debugging
|
||||
//int a = 1, b = 1, c = 2, d = -2; // for debugging
|
||||
//int consoleDisplay = 0;
|
||||
|
||||
int X = 0x84, Y = 0x84, Z = 0x9f; // neutral values
|
||||
u8 x = X, y = Y, z = Z;
|
||||
int shake = -1, yhistsize = 15; // for the shake function
|
||||
std::vector<u8> yhist(15); // for the tilt function
|
||||
|
||||
void FillReportAcc(wm_accel& _acc)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
// -----------------------------
|
||||
// Wiimote to Gamepad translations
|
||||
// ----------
|
||||
// Tilting Wiimote (Wario Land aiming, Mario Kart steering) : For some reason 150 and 40
|
||||
// seemed like decent starting values.
|
||||
if(GetAsyncKeyState('3'))
|
||||
{
|
||||
//if(a < 128) // for debugging
|
||||
if(y < 250)
|
||||
{
|
||||
y += 4; // aim left
|
||||
//a += c; // debugging values
|
||||
//y = A + a; // aim left
|
||||
}
|
||||
}
|
||||
else if(GetAsyncKeyState('4'))
|
||||
{
|
||||
// if(b < 128) // for debugging
|
||||
if(y > 5)
|
||||
{
|
||||
y -= 4; // aim right
|
||||
//b -= d; // debugging values
|
||||
//y = B + b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Single shake of Wiimote while holding it sideways (Wario Land pound ground)
|
||||
if(GetAsyncKeyState('S'))
|
||||
z = 0;
|
||||
else
|
||||
z = Z;*/
|
||||
|
||||
if(GetAsyncKeyState('S'))
|
||||
{
|
||||
z = 0;
|
||||
y = 0;
|
||||
shake = 2;
|
||||
}
|
||||
else if(shake == 2)
|
||||
{
|
||||
z = 128;
|
||||
y = 0;
|
||||
shake = 1;
|
||||
}
|
||||
else if(shake == 1)
|
||||
{
|
||||
z = Z;
|
||||
y = Y;
|
||||
shake = -1;
|
||||
}
|
||||
else // the default Y and Z if nothing is pressed
|
||||
{
|
||||
z = Z;
|
||||
}
|
||||
// ----------
|
||||
|
||||
|
||||
// -----------------------------
|
||||
// For tilting: add new value and move all back
|
||||
// ----------
|
||||
bool ypressed = false;
|
||||
|
||||
yhist[yhist.size() - 1] = (
|
||||
GetAsyncKeyState('3') ? true : false
|
||||
|| GetAsyncKeyState('4') ? true : false
|
||||
|| shake > 0
|
||||
);
|
||||
if(yhistsize > yhist.size()) yhistsize = yhist.size();
|
||||
for (int i = 1; i < yhistsize; i++)
|
||||
{
|
||||
yhist[i-1] = yhist[i];
|
||||
if(yhist[i]) ypressed = true;
|
||||
}
|
||||
|
||||
if(!ypressed) // y was not pressed a single time
|
||||
{
|
||||
y = Y; // this is the default value that will occur most of the time
|
||||
//a = 0; // for debugging
|
||||
//b = 0;
|
||||
}
|
||||
else if(!GetAsyncKeyState('3') && !GetAsyncKeyState('4'))
|
||||
{
|
||||
// perhaps start dropping acceleration back?
|
||||
}
|
||||
// ----------
|
||||
|
||||
|
||||
// Write values
|
||||
_acc.x = X;
|
||||
_acc.y = y;
|
||||
_acc.z = z;
|
||||
|
||||
|
||||
// ----------------------------
|
||||
// Debugging for translating Wiimote to Keyboard (or Gamepad)
|
||||
// ----------
|
||||
/*
|
||||
|
||||
// Toogle console display
|
||||
if(GetAsyncKeyState('U'))
|
||||
{
|
||||
if(consoleDisplay < 2)
|
||||
consoleDisplay ++;
|
||||
else
|
||||
consoleDisplay = 0;
|
||||
}
|
||||
|
||||
if(GetAsyncKeyState('5'))
|
||||
A-=1;
|
||||
else if(GetAsyncKeyState('6'))
|
||||
A+=1;
|
||||
if(GetAsyncKeyState('7'))
|
||||
B-=1;
|
||||
else if(GetAsyncKeyState('8'))
|
||||
B+=1;
|
||||
if(GetAsyncKeyState('9'))
|
||||
C-=1;
|
||||
else if(GetAsyncKeyState('0'))
|
||||
C+=1;
|
||||
|
||||
else if(GetAsyncKeyState(VK_NUMPAD3))
|
||||
d-=1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD6))
|
||||
d+=1;
|
||||
else if(GetAsyncKeyState(VK_ADD))
|
||||
yhistsize-=1;
|
||||
else if(GetAsyncKeyState(VK_SUBTRACT))
|
||||
yhistsize+=1;
|
||||
|
||||
|
||||
/*if(GetAsyncKeyState(VK_INSERT))
|
||||
AX-=1;
|
||||
else if(GetAsyncKeyState(VK_DELETE))
|
||||
AX+=1;
|
||||
else if(GetAsyncKeyState(VK_HOME))
|
||||
AY-=1;
|
||||
else if(GetAsyncKeyState(VK_END))
|
||||
AY+=1;
|
||||
else if(GetAsyncKeyState(VK_SHIFT))
|
||||
AZ-=1;
|
||||
else if(GetAsyncKeyState(VK_CONTROL))
|
||||
AZ+=1;*/
|
||||
|
||||
/*
|
||||
if(GetAsyncKeyState(VK_NUMPAD1))
|
||||
X+=1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD2))
|
||||
X-=1;
|
||||
if(GetAsyncKeyState(VK_NUMPAD4))
|
||||
Y+=1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD5))
|
||||
Y-=1;
|
||||
if(GetAsyncKeyState(VK_NUMPAD7))
|
||||
Z+=1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD8))
|
||||
Z-=1;
|
||||
|
||||
|
||||
//if(consoleDisplay == 0)
|
||||
wprintf("x: %03i | y: %03i | z: %03i | A:%i B:%i C:%i a:%i b:%i c:%i d:%i X:%i Y:%i Z:%i\n",
|
||||
_acc.x, _acc.y, _acc.z,
|
||||
A, B, C,
|
||||
a, b, c, d,
|
||||
X, Y, Z
|
||||
);
|
||||
wprintf("x: %03i | y: %03i | z: %03i | X:%i Y:%i Z:%i | AX:%i AY:%i AZ:%i \n",
|
||||
_acc.x, _acc.y, _acc.z,
|
||||
X, Y, Z,
|
||||
AX, AY, AZ
|
||||
);*/
|
||||
#else
|
||||
// TODO port to linux
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void FillReportIR(wm_ir_extended& _ir0, wm_ir_extended& _ir1)
|
||||
{
|
||||
|
||||
/* DESCRIPTION: The calibration is controlled by these values, their absolute value and
|
||||
the relative distance between between them control the calibration. WideScreen mode
|
||||
has its own settings. */
|
||||
int Top, Left, Right, Bottom, SensorBarRadius;
|
||||
if(g_Config.bWideScreen)
|
||||
{
|
||||
Top = wTOP; Left = wLEFT; Right = wRIGHT;
|
||||
Bottom = wBOTTOM; SensorBarRadius = wSENSOR_BAR_RADIUS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Top = TOP; Left = LEFT; Right = RIGHT;
|
||||
Bottom = BOTTOM; SensorBarRadius = SENSOR_BAR_RADIUS;
|
||||
}
|
||||
|
||||
// Fill with 0xff if empty
|
||||
memset(&_ir0, 0xFF, sizeof(wm_ir_extended));
|
||||
memset(&_ir1, 0xFF, sizeof(wm_ir_extended));
|
||||
|
||||
float MouseX, MouseY;
|
||||
GetMousePos(MouseX, MouseY);
|
||||
|
||||
int y0 = Top + (MouseY * (Bottom - Top));
|
||||
int y1 = Top + (MouseY * (Bottom - Top));
|
||||
|
||||
int x0 = Left + (MouseX * (Right - Left)) - SensorBarRadius;
|
||||
int x1 = Left + (MouseX * (Right - Left)) + SensorBarRadius;
|
||||
|
||||
x0 = 1023 - x0;
|
||||
_ir0.x = x0 & 0xFF;
|
||||
_ir0.y = y0 & 0xFF;
|
||||
_ir0.size = 10;
|
||||
_ir0.xHi = x0 >> 8;
|
||||
_ir0.yHi = y0 >> 8;
|
||||
|
||||
x1 = 1023 - x1;
|
||||
_ir1.x = x1 & 0xFF;
|
||||
_ir1.y = y1 & 0xFF;
|
||||
_ir1.size = 10;
|
||||
_ir1.xHi = x1 >> 8;
|
||||
_ir1.yHi = y1 >> 8;
|
||||
|
||||
|
||||
// ----------------------------
|
||||
// Debugging for calibration
|
||||
// ----------
|
||||
/*
|
||||
if(GetAsyncKeyState(VK_NUMPAD1))
|
||||
Right +=1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD2))
|
||||
Right -=1;
|
||||
if(GetAsyncKeyState(VK_NUMPAD4))
|
||||
Left +=1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD5))
|
||||
Left -=1;
|
||||
if(GetAsyncKeyState(VK_NUMPAD7))
|
||||
Top += 1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD8))
|
||||
Top -= 1;
|
||||
if(GetAsyncKeyState(VK_NUMPAD6))
|
||||
Bottom += 1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD3))
|
||||
Bottom -= 1;
|
||||
if(GetAsyncKeyState(VK_INSERT))
|
||||
SensorBarRadius += 1;
|
||||
else if(GetAsyncKeyState(VK_DELETE))
|
||||
SensorBarRadius -= 1;
|
||||
|
||||
//ClearScreen();
|
||||
//if(consoleDisplay == 1)
|
||||
wprintf("x0:%03i x1:%03i y0:%03i y1:%03i irx0:%03i y0:%03i x1:%03i y1:%03i | T:%i L:%i R:%i B:%i S:%i\n",
|
||||
x0, x1, y0, y1, _ir0.x, _ir0.y, _ir1.x, _ir1.y, Top, Left, Right, Bottom, SensorBarRadius
|
||||
);
|
||||
wprintf("\n");
|
||||
wprintf("ir0.x:%02x xHi:%02x ir1.x:%02x xHi:%02x | ir0.y:%02x yHi:%02x ir1.y:%02x yHi:%02x | 1.s:%02x 2:%02x\n",
|
||||
_ir0.x, _ir0.xHi, _ir1.x, _ir1.xHi,
|
||||
_ir0.y, _ir0.yHi, _ir1.y, _ir1.yHi,
|
||||
_ir0.size, _ir1.size
|
||||
);*/
|
||||
}
|
||||
|
||||
|
||||
void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1)
|
||||
{
|
||||
/* See description above */
|
||||
int Top, Left, Right, Bottom, SensorBarRadius;
|
||||
|
||||
if(g_Config.bWideScreen)
|
||||
{
|
||||
Top = wTOP; Left = wLEFT; Right = wRIGHT;
|
||||
Bottom = wBOTTOM; SensorBarRadius = wSENSOR_BAR_RADIUS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Top = TOP; Left = LEFT; Right = RIGHT;
|
||||
Bottom = BOTTOM; SensorBarRadius = SENSOR_BAR_RADIUS;
|
||||
}
|
||||
|
||||
// Fill with 0xff if empty
|
||||
memset(&_ir0, 0xff, sizeof(wm_ir_basic));
|
||||
memset(&_ir1, 0xff, sizeof(wm_ir_basic));
|
||||
|
||||
float MouseX, MouseY;
|
||||
GetMousePos(MouseX, MouseY);
|
||||
|
||||
int y1 = Top + (MouseY * (Bottom - Top));
|
||||
int y2 = Top + (MouseY * (Bottom - Top));
|
||||
|
||||
int x1 = Left + (MouseX * (Right - Left)) - SensorBarRadius;
|
||||
int x2 = Left + (MouseX * (Right - Left)) + SensorBarRadius;
|
||||
|
||||
/* As with the extented report we settle with emulating two out of four
|
||||
possible objects */
|
||||
x1 = 1023 - x1;
|
||||
_ir0.x1 = x1 & 0xff;
|
||||
_ir0.y1 = y1 & 0xff;
|
||||
_ir0.x1Hi = (x1 >> 8); // we are dealing with 2 bit values here
|
||||
_ir0.y1Hi = (y1 >> 8);
|
||||
|
||||
x2 = 1023 - x2;
|
||||
_ir0.x2 = x2 & 0xff;
|
||||
_ir0.y2 = y2 & 0xff;
|
||||
_ir0.x2Hi = (x2 >> 8);
|
||||
_ir0.y2Hi = (y2 >> 8);
|
||||
|
||||
// I don't understand't the & 0x03, should we do that?
|
||||
//_ir1.x1Hi = (x1 >> 8) & 0x3;
|
||||
//_ir1.y1Hi = (y1 >> 8) & 0x3;
|
||||
|
||||
// ----------------------------
|
||||
// Debugging for calibration
|
||||
// ----------
|
||||
/*
|
||||
if(GetAsyncKeyState(VK_NUMPAD1))
|
||||
Right +=1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD2))
|
||||
Right -=1;
|
||||
if(GetAsyncKeyState(VK_NUMPAD4))
|
||||
Left +=1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD5))
|
||||
Left -=1;
|
||||
if(GetAsyncKeyState(VK_NUMPAD7))
|
||||
Top += 1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD8))
|
||||
Top -= 1;
|
||||
if(GetAsyncKeyState(VK_NUMPAD6))
|
||||
Bottom += 1;
|
||||
else if(GetAsyncKeyState(VK_NUMPAD3))
|
||||
Bottom -= 1;
|
||||
if(GetAsyncKeyState(VK_INSERT))
|
||||
SensorBarRadius += 1;
|
||||
else if(GetAsyncKeyState(VK_DELETE))
|
||||
SensorBarRadius -= 1;
|
||||
|
||||
//ClearScreen();
|
||||
//if(consoleDisplay == 1)
|
||||
|
||||
wprintf("x1:%03i x2:%03i y1:%03i y2:%03i irx1:%02x y1:%02x x2:%02x y2:%02x | T:%i L:%i R:%i B:%i S:%i\n",
|
||||
x1, x2, y1, y2, _ir0.x1, _ir0.y1, _ir1.x2, _ir1.y2, Top, Left, Right, Bottom, SensorBarRadius
|
||||
);
|
||||
wprintf("\n");
|
||||
wprintf("ir0.x1:%02x x1h:%02x x2:%02x x2h:%02x | ir0.y1:%02x y1h:%02x y2:%02x y2h:%02x | ir1.x1:%02x x1h:%02x x2:%02x x2h:%02x | ir1.y1:%02x y1h:%02x y2:%02x y2h:%02x\n",
|
||||
_ir0.x1, _ir0.x1Hi, _ir0.x2, _ir0.x2Hi,
|
||||
_ir0.y1, _ir0.y1Hi, _ir0.y2, _ir0.y2Hi,
|
||||
_ir1.x1, _ir1.x1Hi, _ir1.x2, _ir1.x2Hi,
|
||||
_ir1.y1, _ir1.y1Hi, _ir1.y2, _ir1.y2Hi
|
||||
);*/
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Generate the 6 byte extension report, encrypted. The bytes are JX JY AX AY AZ BT. */
|
||||
// ----------------
|
||||
void FillReportExtension(wm_extension& _ext)
|
||||
{
|
||||
|
||||
/* These are the default neutral values for the nunchuck accelerometer according
|
||||
to a source. */
|
||||
_ext.ax = 0x80;
|
||||
_ext.ay = 0x80;
|
||||
_ext.az = 0xb3;
|
||||
|
||||
|
||||
_ext.jx = 0x80; // these are the default values unless we use them
|
||||
_ext.jy = 0x80;
|
||||
_ext.bt = 0x03; // 0x03 means no button pressed, the button is zero active
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
if(GetAsyncKeyState(VK_NUMPAD4))
|
||||
_ext.jx = 0x20;
|
||||
|
||||
if(GetAsyncKeyState(VK_NUMPAD8))
|
||||
_ext.jy = 0xe0;
|
||||
|
||||
if(GetAsyncKeyState(VK_NUMPAD6))
|
||||
_ext.jx = 0xe0;
|
||||
|
||||
if(GetAsyncKeyState(VK_NUMPAD5))
|
||||
_ext.jy = 0x20;
|
||||
|
||||
|
||||
|
||||
if(GetAsyncKeyState('C'))
|
||||
_ext.bt = 0x01;
|
||||
|
||||
if(GetAsyncKeyState('Z'))
|
||||
_ext.bt = 0x02;
|
||||
|
||||
if(GetAsyncKeyState('C') && GetAsyncKeyState('Z'))
|
||||
_ext.bt = 0x00;
|
||||
#else
|
||||
// TODO linux port
|
||||
#endif
|
||||
|
||||
// Clear g_RegExtTmp by copying zeroes to it
|
||||
memset(g_RegExtTmp, 0, sizeof(g_RegExtTmp));
|
||||
|
||||
// Write the nunchuck inputs to it
|
||||
g_RegExtTmp[0x08] = _ext.jx;
|
||||
g_RegExtTmp[0x09] = _ext.jy;
|
||||
g_RegExtTmp[0x0a] = _ext.ax;
|
||||
g_RegExtTmp[0x0b] = _ext.ay;
|
||||
g_RegExtTmp[0x0c] = _ext.az;
|
||||
g_RegExtTmp[0x0d] = _ext.bt;
|
||||
|
||||
// Encrypt it
|
||||
wiimote_encrypt(&g_ExtKey, &g_RegExtTmp[0x08], 0x08, 0x06);
|
||||
|
||||
// Write it back
|
||||
_ext.jx = g_RegExtTmp[0x08];
|
||||
_ext.jy = g_RegExtTmp[0x09];
|
||||
_ext.ax = g_RegExtTmp[0x0a];
|
||||
_ext.ay = g_RegExtTmp[0x0b];
|
||||
_ext.az = g_RegExtTmp[0x0c];
|
||||
_ext.bt = g_RegExtTmp[0x0d];
|
||||
}
|
||||
|
||||
|
||||
} // end of namespace
|
36
Source/Plugins/Plugin_Wiimote/Src/SConscript
Normal file
36
Source/Plugins/Plugin_Wiimote/Src/SConscript
Normal file
@ -0,0 +1,36 @@
|
||||
# -*- python -*-
|
||||
|
||||
Import('env')
|
||||
import sys
|
||||
|
||||
name = "Plugin_Wiimote"
|
||||
|
||||
files = [
|
||||
"Config.cpp",
|
||||
"ConfigDlg.cpp",
|
||||
"Console.cpp",
|
||||
"DataReports.cpp",
|
||||
"EmuDefinitions.cpp",
|
||||
"EmuMain.cpp",
|
||||
"EmuSubroutines.cpp",
|
||||
"Encryption.cpp",
|
||||
"FillReport.cpp",
|
||||
"main.cpp",
|
||||
"wiimote_real.cpp",
|
||||
]
|
||||
|
||||
wiimoteenv = env.Clone()
|
||||
|
||||
if wiimoteenv['osx64']:
|
||||
wiimoteenv.Append(
|
||||
CXXFLAGS = [ '-arch', 'x86_64' ],
|
||||
LINKFLAGS = [ '-arch', 'x86_64' ],
|
||||
LIBS = [ 'common' ],
|
||||
)
|
||||
else:
|
||||
wiimoteenv.Append(
|
||||
CXXFLAGS = [ '-fPIC' ],
|
||||
LIBS = [ 'common', 'wiiuse' ],
|
||||
)
|
||||
|
||||
wiimoteenv.SharedLibrary(env['plugin_dir']+name, files)
|
250
Source/Plugins/Plugin_Wiimote/Src/main.cpp
Normal file
250
Source/Plugins/Plugin_Wiimote/Src/main.cpp
Normal file
@ -0,0 +1,250 @@
|
||||
// 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/
|
||||
|
||||
|
||||
#if !defined(OSX64)
|
||||
#include <wx/aboutdlg.h>
|
||||
#include "ConfigDlg.h"
|
||||
#endif
|
||||
|
||||
#include "Common.h"
|
||||
#include "Config.h"
|
||||
#include "StringUtil.h"
|
||||
|
||||
#include "pluginspecs_wiimote.h"
|
||||
|
||||
#include "EmuMain.h"
|
||||
#include "wiimote_real.h"
|
||||
|
||||
#include "Console.h" // for startConsoleWin, wprintf, GetConsoleHwnd
|
||||
|
||||
SWiimoteInitialize g_WiimoteInitialize;
|
||||
#define VERSION_STRING "0.1"
|
||||
|
||||
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
|
||||
sprintf(_PluginInfo->Name, "Wiimote Plug-in (DebugFast) " VERSION_STRING);
|
||||
#else
|
||||
#ifndef _DEBUG
|
||||
sprintf(_PluginInfo->Name, "Wiimote Plug-in " VERSION_STRING);
|
||||
#else
|
||||
sprintf(_PluginInfo->Name, "Wiimote Plug-in (Debug) " VERSION_STRING);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
extern "C" void DllAbout(HWND _hParent)
|
||||
{
|
||||
#if !defined(OSX64)
|
||||
wxAboutDialogInfo info;
|
||||
info.SetName(_T("Wiimote plug-in"));
|
||||
info.AddDeveloper(_T("masken (masken3@gmail.com)"));
|
||||
info.SetDescription(_T("Wiimote plug-in"));
|
||||
wxAboutBox(info);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void DllConfig(HWND _hParent)
|
||||
{
|
||||
wxWindow win;
|
||||
#ifdef _WIN32
|
||||
win.SetHWND(_hParent);
|
||||
#endif
|
||||
ConfigDialog frame(&win);
|
||||
frame.ShowModal();
|
||||
#ifdef _WIN32
|
||||
win.SetHWND(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void Wiimote_Initialize(SWiimoteInitialize _WiimoteInitialize)
|
||||
{
|
||||
g_WiimoteInitialize = _WiimoteInitialize;
|
||||
|
||||
/* We will run WiiMoteReal::Initialize() even if we are not using a real wiimote,
|
||||
we will initiate wiiuse.dll, but we will return before creating a new thread
|
||||
for it in that case */
|
||||
g_UseRealWiiMote = WiiMoteReal::Initialize() > 0;
|
||||
|
||||
WiiMoteEmu::Initialize();
|
||||
|
||||
g_Config.Load(); // load config settings
|
||||
|
||||
// Debugging window
|
||||
/*startConsoleWin(100, 750, "Wiimote"); // give room for 20 rows
|
||||
wprintf("Wiimote console opened\n");
|
||||
|
||||
// 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*/
|
||||
}
|
||||
|
||||
|
||||
extern "C" void Wiimote_DoState(void* ptr, int mode)
|
||||
{
|
||||
WiiMoteReal::DoState(ptr, mode);
|
||||
WiiMoteEmu::DoState(ptr, mode);
|
||||
}
|
||||
|
||||
extern "C" void Wiimote_Shutdown(void)
|
||||
{
|
||||
WiiMoteReal::Shutdown();
|
||||
WiiMoteEmu::Shutdown();
|
||||
}
|
||||
|
||||
extern "C" void Wiimote_InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
|
||||
{
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "=============================================================");
|
||||
const u8* data = (const u8*)_pData;
|
||||
|
||||
// Debugging. Dump raw data.
|
||||
{
|
||||
LOG(WII_IPC_WIIMOTE, "Wiimote_Input");
|
||||
LOG(WII_IPC_WIIMOTE, " Channel ID: %04x", _channelID);
|
||||
|
||||
std::string Temp;
|
||||
for (u32 j=0; j<_Size; j++)
|
||||
{
|
||||
char Buffer[128];
|
||||
sprintf(Buffer, "%02x ", data[j]);
|
||||
Temp.append(Buffer);
|
||||
}
|
||||
LOG(WII_IPC_WIIMOTE, " Data: %s", Temp.c_str());
|
||||
}
|
||||
|
||||
if (g_UseRealWiiMote)
|
||||
WiiMoteReal::InterruptChannel(_channelID, _pData, _Size);
|
||||
else
|
||||
WiiMoteEmu::InterruptChannel(_channelID, _pData, _Size);
|
||||
LOGV(WII_IPC_WIIMOTE, 0, "=============================================================");
|
||||
}
|
||||
|
||||
extern "C" void Wiimote_ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
|
||||
{
|
||||
const u8* data = (const u8*)_pData;
|
||||
// dump raw data
|
||||
{
|
||||
LOG(WII_IPC_WIIMOTE, "Wiimote_ControlChannel");
|
||||
std::string Temp;
|
||||
for (u32 j=0; j<_Size; j++)
|
||||
{
|
||||
char Buffer[128];
|
||||
sprintf(Buffer, "%02x ", data[j]);
|
||||
Temp.append(Buffer);
|
||||
}
|
||||
LOG(WII_IPC_WIIMOTE, " Data: %s", Temp.c_str());
|
||||
}
|
||||
|
||||
if (g_UseRealWiiMote)
|
||||
WiiMoteReal::ControlChannel(_channelID, _pData, _Size);
|
||||
else
|
||||
WiiMoteEmu::ControlChannel(_channelID, _pData, _Size);
|
||||
}
|
||||
|
||||
extern "C" void Wiimote_Update()
|
||||
{
|
||||
if (g_UseRealWiiMote)
|
||||
WiiMoteReal::Update();
|
||||
else
|
||||
WiiMoteEmu::Update();
|
||||
}
|
||||
|
||||
extern "C" unsigned int Wiimote_GetAttachedControllers()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Logging functions. */
|
||||
// ----------------
|
||||
void __Log(int log, const char *_fmt, ...)
|
||||
{
|
||||
char Msg[512];
|
||||
va_list ap;
|
||||
|
||||
va_start( ap, _fmt );
|
||||
vsprintf( Msg, _fmt, ap );
|
||||
va_end( ap );
|
||||
|
||||
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);
|
||||
}
|
||||
// ================
|
251
Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h
Normal file
251
Source/Plugins/Plugin_Wiimote/Src/wiimote_hid.h
Normal file
@ -0,0 +1,251 @@
|
||||
// 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/
|
||||
|
||||
#ifndef WIIMOTE_HID_H
|
||||
#define WIIMOTE_HID_H
|
||||
|
||||
#include <CommonTypes.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4200)
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
//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
|
||||
|
||||
struct wm_report {
|
||||
u8 channel;
|
||||
u8 data[0];
|
||||
};
|
||||
|
||||
#define WM_LEDS 0x11
|
||||
struct wm_leds {
|
||||
u8 rumble : 1;
|
||||
u8 : 3;
|
||||
u8 leds : 4;
|
||||
};
|
||||
|
||||
#define WM_DATA_REPORTING 0x12
|
||||
struct wm_data_reporting {
|
||||
u8 rumble : 1;
|
||||
u8 continuous : 1;
|
||||
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 {
|
||||
u8 padding1[2];
|
||||
u8 unknown : 1;
|
||||
u8 extension : 1;
|
||||
u8 speaker : 1;
|
||||
u8 ir : 1;
|
||||
u8 leds : 4;
|
||||
u8 padding2[2];
|
||||
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_WRITE_DATA_REPLY 0x22 //empty, afaik
|
||||
struct wm_acknowledge
|
||||
{
|
||||
u8 Channel;
|
||||
u8 unk0;
|
||||
u8 unk1;
|
||||
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];
|
||||
u8 size[2];
|
||||
};
|
||||
|
||||
#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 {
|
||||
u16 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
|
||||
|
||||
struct wm_core {
|
||||
u8 left : 1;
|
||||
u8 right : 1;
|
||||
u8 down : 1;
|
||||
u8 up : 1;
|
||||
u8 plus : 1;
|
||||
u8 : 3;
|
||||
u8 two : 1;
|
||||
u8 one : 1;
|
||||
u8 b : 1;
|
||||
u8 a : 1;
|
||||
u8 minus : 1;
|
||||
u8 : 2;
|
||||
u8 home : 1;
|
||||
};
|
||||
|
||||
struct wm_accel {
|
||||
u8 x, y, z;
|
||||
};
|
||||
|
||||
//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;
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
#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
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
#endif //WIIMOTE_HID_H
|
292
Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp
Normal file
292
Source/Plugins/Plugin_Wiimote/Src/wiimote_real.cpp
Normal file
@ -0,0 +1,292 @@
|
||||
// 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 "pluginspecs_wiimote.h"
|
||||
|
||||
#include "wiiuse.h"
|
||||
#include <queue>
|
||||
|
||||
#include "Common.h"
|
||||
#include "Thread.h"
|
||||
|
||||
#include "wiimote_hid.h"
|
||||
#include "EmuMain.h"
|
||||
|
||||
|
||||
extern SWiimoteInitialize g_WiimoteInitialize;
|
||||
//extern void __Log(int log, const char *format, ...);
|
||||
//extern void __Log(int log, int v, const char *format, ...);
|
||||
|
||||
|
||||
namespace WiiMoteReal
|
||||
{
|
||||
#define MAX_WIIMOTES 1
|
||||
|
||||
//******************************************************************************
|
||||
// Forwarding
|
||||
//******************************************************************************
|
||||
|
||||
class CWiiMote;
|
||||
#ifdef _WIN32
|
||||
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg);
|
||||
#else
|
||||
void* ReadWiimote_ThreadFunc(void* arg);
|
||||
#endif
|
||||
//******************************************************************************
|
||||
// Variable declarations
|
||||
//******************************************************************************
|
||||
|
||||
wiimote_t** g_WiiMotesFromWiiUse = NULL;
|
||||
Common::Thread* g_pReadThread = NULL;
|
||||
int g_NumberOfWiiMotes;
|
||||
CWiiMote* g_WiiMotes[MAX_WIIMOTES];
|
||||
bool g_Shutdown = false;
|
||||
|
||||
//******************************************************************************
|
||||
// Probably this class should be in its own file
|
||||
//******************************************************************************
|
||||
|
||||
class CWiiMote
|
||||
{
|
||||
public:
|
||||
|
||||
CWiiMote(u8 _WiimoteNumber, wiimote_t* _pWiimote)
|
||||
: m_WiimoteNumber(_WiimoteNumber)
|
||||
, m_pWiiMote(_pWiimote)
|
||||
, m_LastReportValid(false)
|
||||
, m_channelID(0)
|
||||
, m_pCriticalSection(NULL)
|
||||
{
|
||||
m_pCriticalSection = new Common::CriticalSection();
|
||||
|
||||
wiiuse_set_leds(m_pWiiMote, WIIMOTE_LED_4);
|
||||
|
||||
#ifdef _WIN32
|
||||
// F|RES: i dunno if we really need this
|
||||
CancelIo(m_pWiiMote->dev_handle);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual ~CWiiMote()
|
||||
{
|
||||
delete m_pCriticalSection;
|
||||
};
|
||||
|
||||
// send raw HID data from the core to wiimote
|
||||
void SendData(u16 _channelID, const u8* _pData, u32 _Size)
|
||||
{
|
||||
m_channelID = _channelID;
|
||||
|
||||
m_pCriticalSection->Enter();
|
||||
{
|
||||
SEvent WriteEvent;
|
||||
memcpy(WriteEvent.m_PayLoad, _pData+1, _Size-1);
|
||||
m_EventWriteQueue.push(WriteEvent);
|
||||
}
|
||||
m_pCriticalSection->Leave();
|
||||
}
|
||||
|
||||
// read data from wiimote (but don't send it to the core, just filter
|
||||
// and queue)
|
||||
void ReadData()
|
||||
{
|
||||
m_pCriticalSection->Enter();
|
||||
|
||||
if (!m_EventWriteQueue.empty())
|
||||
{
|
||||
SEvent& rEvent = m_EventWriteQueue.front();
|
||||
wiiuse_io_write(m_pWiiMote, (byte*)rEvent.m_PayLoad, MAX_PAYLOAD);
|
||||
m_EventWriteQueue.pop();
|
||||
}
|
||||
|
||||
m_pCriticalSection->Leave();
|
||||
|
||||
if (wiiuse_io_read(m_pWiiMote))
|
||||
{
|
||||
const byte* pBuffer = m_pWiiMote->event_buf;
|
||||
|
||||
// check if we have a channel (connection) if so save the
|
||||
// data...
|
||||
if (m_channelID > 0)
|
||||
{
|
||||
m_pCriticalSection->Enter();
|
||||
|
||||
// filter out reports
|
||||
if (pBuffer[0] >= 0x30)
|
||||
{
|
||||
memcpy(m_LastReport.m_PayLoad, pBuffer,
|
||||
MAX_PAYLOAD);
|
||||
m_LastReportValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SEvent ImportantEvent;
|
||||
memcpy(ImportantEvent.m_PayLoad, pBuffer,
|
||||
MAX_PAYLOAD);
|
||||
m_EventReadQueue.push(ImportantEvent);
|
||||
}
|
||||
|
||||
m_pCriticalSection->Leave();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// send queued data to the core
|
||||
void Update()
|
||||
{
|
||||
m_pCriticalSection->Enter();
|
||||
|
||||
if (m_EventReadQueue.empty())
|
||||
{
|
||||
if (m_LastReportValid)
|
||||
SendEvent(m_LastReport);
|
||||
}
|
||||
else
|
||||
{
|
||||
SendEvent(m_EventReadQueue.front());
|
||||
m_EventReadQueue.pop();
|
||||
}
|
||||
|
||||
m_pCriticalSection->Leave();
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
struct SEvent
|
||||
{
|
||||
SEvent()
|
||||
{
|
||||
memset(m_PayLoad, 0, MAX_PAYLOAD);
|
||||
}
|
||||
byte m_PayLoad[MAX_PAYLOAD];
|
||||
};
|
||||
typedef std::queue<SEvent> CEventQueue;
|
||||
|
||||
u8 m_WiimoteNumber; // just for debugging
|
||||
u16 m_channelID;
|
||||
wiimote_t* m_pWiiMote;
|
||||
|
||||
Common::CriticalSection* m_pCriticalSection;
|
||||
CEventQueue m_EventReadQueue;
|
||||
CEventQueue m_EventWriteQueue;
|
||||
bool m_LastReportValid;
|
||||
SEvent m_LastReport;
|
||||
|
||||
void SendEvent(SEvent& _rEvent)
|
||||
{
|
||||
// we don't have an answer channel
|
||||
if (m_channelID == 0)
|
||||
return;
|
||||
|
||||
// check event buffer;
|
||||
u8 Buffer[1024];
|
||||
u32 Offset = 0;
|
||||
hid_packet* pHidHeader = (hid_packet*)(Buffer + Offset);
|
||||
Offset += sizeof(hid_packet);
|
||||
pHidHeader->type = HID_TYPE_DATA;
|
||||
pHidHeader->param = HID_PARAM_INPUT;
|
||||
|
||||
memcpy(&Buffer[Offset], _rEvent.m_PayLoad, MAX_PAYLOAD);
|
||||
Offset += MAX_PAYLOAD;
|
||||
|
||||
g_WiimoteInitialize.pWiimoteInput(m_channelID, Buffer, Offset);
|
||||
}
|
||||
};
|
||||
|
||||
//******************************************************************************
|
||||
// Function Definitions
|
||||
//******************************************************************************
|
||||
|
||||
int Initialize()
|
||||
{
|
||||
memset(g_WiiMotes, 0, sizeof(CWiiMote*) * MAX_WIIMOTES);
|
||||
g_WiiMotesFromWiiUse = wiiuse_init(MAX_WIIMOTES);
|
||||
g_NumberOfWiiMotes = wiiuse_find(g_WiiMotesFromWiiUse, MAX_WIIMOTES, 5);
|
||||
|
||||
for (int i=0; i<g_NumberOfWiiMotes; i++)
|
||||
{
|
||||
g_WiiMotes[i] = new CWiiMote(i+1, g_WiiMotesFromWiiUse[i]);
|
||||
}
|
||||
|
||||
if (g_NumberOfWiiMotes > 0)
|
||||
g_pReadThread = new Common::Thread(ReadWiimote_ThreadFunc, NULL);
|
||||
|
||||
return g_NumberOfWiiMotes;
|
||||
}
|
||||
|
||||
void DoState(void* ptr, int mode)
|
||||
{}
|
||||
|
||||
void Shutdown(void)
|
||||
{
|
||||
g_Shutdown = true;
|
||||
|
||||
// stop the thread
|
||||
if (g_pReadThread != NULL)
|
||||
{
|
||||
g_pReadThread->WaitForDeath();
|
||||
delete g_pReadThread;
|
||||
g_pReadThread = NULL;
|
||||
}
|
||||
|
||||
// delete the wiimotes
|
||||
for (int i=0; i<g_NumberOfWiiMotes; i++)
|
||||
{
|
||||
delete g_WiiMotes[i];
|
||||
g_WiiMotes[i] = NULL;
|
||||
}
|
||||
|
||||
// clean up wiiuse
|
||||
wiiuse_cleanup(g_WiiMotesFromWiiUse, g_NumberOfWiiMotes);
|
||||
}
|
||||
|
||||
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
|
||||
{
|
||||
g_WiiMotes[0]->SendData(_channelID, (const u8*)_pData, _Size);
|
||||
}
|
||||
|
||||
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
|
||||
{
|
||||
g_WiiMotes[0]->SendData(_channelID, (const u8*)_pData, _Size);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
for (int i=0; i<g_NumberOfWiiMotes; i++)
|
||||
{
|
||||
g_WiiMotes[i]->Update();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD WINAPI ReadWiimote_ThreadFunc(void* arg)
|
||||
#else
|
||||
void *ReadWiimote_ThreadFunc(void* arg)
|
||||
#endif
|
||||
{
|
||||
while (!g_Shutdown)
|
||||
{
|
||||
for (int i=0; i<g_NumberOfWiiMotes; i++)
|
||||
{
|
||||
g_WiiMotes[i]->ReadData();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}; // end of namespace
|
||||
|
34
Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h
Normal file
34
Source/Plugins/Plugin_Wiimote/Src/wiimote_real.h
Normal file
@ -0,0 +1,34 @@
|
||||
// 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/
|
||||
|
||||
|
||||
#ifndef WIIMOTE_REAL_H
|
||||
#define WIIMOTE_REAL_H
|
||||
|
||||
namespace WiiMoteReal
|
||||
{
|
||||
|
||||
int Initialize();
|
||||
void DoState(void* ptr, int mode);
|
||||
void Shutdown(void);
|
||||
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size);
|
||||
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size) ;
|
||||
void Update();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user