2008-12-08 05:25:12 +00:00
|
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Includes
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "pluginspecs_wiimote.h"
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
2008-12-09 05:37:15 +00:00
|
|
|
|
|
2009-02-08 15:39:28 +00:00
|
|
|
|
#include "../../../Core/InputCommon/Src/SDL.h" // Core
|
|
|
|
|
#include "../../../Core/InputCommon/Src/XInput.h"
|
|
|
|
|
|
2008-12-09 05:37:15 +00:00
|
|
|
|
#include "Common.h" // Common
|
2009-01-26 07:01:43 +00:00
|
|
|
|
#include "StringUtil.h" // for ArrayToString()
|
2009-01-28 16:09:08 +00:00
|
|
|
|
#include "IniFile.h"
|
2008-12-09 05:37:15 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
#include "EmuDefinitions.h" // Local
|
|
|
|
|
#include "main.h"
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "wiimote_hid.h"
|
|
|
|
|
#include "EmuSubroutines.h"
|
|
|
|
|
#include "EmuMain.h"
|
|
|
|
|
#include "Encryption.h" // for extension encryption
|
2009-01-17 14:28:09 +00:00
|
|
|
|
#include "Logging.h" // for startConsoleWin, Console::Print, GetConsoleHwnd
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "Config.h" // for g_Config
|
2009-01-07 02:59:19 +00:00
|
|
|
|
////////////////////////////////////
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
extern SWiimoteInitialize g_WiimoteInitialize;
|
|
|
|
|
|
|
|
|
|
namespace WiiMoteEmu
|
|
|
|
|
{
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// ===================================================
|
|
|
|
|
/* Bit shift conversions */
|
|
|
|
|
// -------------
|
|
|
|
|
u32 convert24bit(const u8* src) {
|
|
|
|
|
return (src[0] << 16) | (src[1] << 8) | src[2];
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
u16 convert16bit(const u8* src) {
|
|
|
|
|
return (src[0] << 8) | src[1];
|
|
|
|
|
}
|
|
|
|
|
// ==============
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-01-31 01:18:57 +00:00
|
|
|
|
/* Calibrate the mouse position to the emulation window. g_WiimoteInitialize.hWnd is the rendering window handle. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void GetMousePos(float& x, float& y)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
POINT point;
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// Get the cursor position for the entire screen
|
2009-01-07 02:59:19 +00:00
|
|
|
|
GetCursorPos(&point);
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// Get the cursor position relative to the upper left corner of the rendering window
|
2009-01-07 02:59:19 +00:00
|
|
|
|
ScreenToClient(g_WiimoteInitialize.hWnd, &point);
|
2008-12-09 05:37:15 +00:00
|
|
|
|
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// Get the size of the rendering window. In my case top and left was zero.
|
2009-01-07 02:59:19 +00:00
|
|
|
|
RECT Rect;
|
|
|
|
|
GetClientRect(g_WiimoteInitialize.hWnd, &Rect);
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// Width and height is the size of the rendering window
|
2009-01-07 02:59:19 +00:00
|
|
|
|
int width = Rect.right - Rect.left;
|
|
|
|
|
int height = Rect.bottom - Rect.top;
|
|
|
|
|
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// Return the mouse position as a fraction of one
|
2009-01-07 02:59:19 +00:00
|
|
|
|
x = point.x / (float)width;
|
|
|
|
|
y = point.y / (float)height;
|
2009-01-31 01:18:57 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Console::ClearScreen();
|
|
|
|
|
Console::Print("GetCursorPos: %i %i\n", point.x, point.y);
|
|
|
|
|
Console::Print("GetClientRect: %i %i %i %i\n", Rect.left, Rect.right, Rect.top, Rect.bottom);
|
|
|
|
|
Console::Print("x and y: %f %f\n", x, y);
|
|
|
|
|
*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
#else
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// TODO fix on linux
|
2009-01-07 02:59:19 +00:00
|
|
|
|
x = 0.5f;
|
|
|
|
|
y = 0.5f;
|
|
|
|
|
#endif
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-31 01:18:57 +00:00
|
|
|
|
// ==============
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* Homebrew encryption for 0x00000000 encryption keys. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-07 02:59:19 +00:00
|
|
|
|
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);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// ================
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-01-29 08:35:29 +00:00
|
|
|
|
/* Load pre-recorded movements */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-29 08:35:29 +00:00
|
|
|
|
void LoadRecordedMovements()
|
2009-01-07 02:59:19 +00:00
|
|
|
|
{
|
2009-01-28 16:09:08 +00:00
|
|
|
|
IniFile file;
|
|
|
|
|
file.Load("WiimoteMovement.ini");
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < RECORDING_ROWS; i++)
|
|
|
|
|
{
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// Logging
|
|
|
|
|
Console::Print("Recording%i ", i + 1);
|
|
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
|
// Get row name
|
|
|
|
|
std::string SaveName = StringFromFormat("Recording%i", i + 1);
|
|
|
|
|
|
|
|
|
|
// Get movement
|
|
|
|
|
std::string TmpMovement; file.Get(SaveName.c_str(), "Movement", &TmpMovement, "");
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// Get IR
|
|
|
|
|
std::string TmpIR; file.Get(SaveName.c_str(), "IR", &TmpIR, "");
|
|
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
|
// Get time
|
|
|
|
|
std::string TmpTime; file.Get(SaveName.c_str(), "Time", &TmpTime, "");
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// Get IR bytes
|
|
|
|
|
int TmpIRBytes; file.Get(SaveName.c_str(), "IRBytes", &TmpIRBytes, 0);
|
|
|
|
|
VRecording.at(i).IRBytes = TmpIRBytes;
|
|
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
|
SRecording Tmp;
|
2009-02-03 00:59:26 +00:00
|
|
|
|
for (int j = 0, k = 0, l = 0; j < TmpMovement.length(); j+=7)
|
2009-01-28 16:09:08 +00:00
|
|
|
|
{
|
|
|
|
|
// Skip blank savings
|
|
|
|
|
if (TmpMovement.length() < 3) continue;
|
|
|
|
|
|
|
|
|
|
std::string StrX = TmpMovement.substr(j, 2);
|
|
|
|
|
std::string StrY = TmpMovement.substr(j + 2, 2);
|
|
|
|
|
std::string StrZ = TmpMovement.substr(j + 4, 2);
|
|
|
|
|
u32 TmpX, TmpY, TmpZ;
|
|
|
|
|
AsciiToHex(StrX.c_str(), TmpX);
|
|
|
|
|
AsciiToHex(StrY.c_str(), TmpY);
|
|
|
|
|
AsciiToHex(StrZ.c_str(), TmpZ);
|
|
|
|
|
Tmp.x = (u8)TmpX;
|
2009-02-01 13:01:50 +00:00
|
|
|
|
Tmp.y = (u8)TmpY;
|
|
|
|
|
Tmp.z = (u8)TmpZ;
|
2009-01-28 16:09:08 +00:00
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ---------------------------------
|
|
|
|
|
// Go to next set of IR values
|
|
|
|
|
// ---------
|
|
|
|
|
// If there is no IR data saving we fill the array with zeroes. This should only be able to occur from manual ini editing
|
|
|
|
|
// but we check for it anyway
|
|
|
|
|
if (TmpIRBytes == 0) for(int i = 0; i < 12; i++) Tmp.IR[i] = 0;
|
|
|
|
|
for(int ii = 0; ii < TmpIRBytes; ii++)
|
|
|
|
|
{
|
|
|
|
|
if(TmpIR.length() < (k + i + TmpIRBytes)) continue; // Safety check
|
|
|
|
|
std::string TmpStr = TmpIR.substr(k + ii*2, 2);
|
|
|
|
|
u32 TmpU32;
|
|
|
|
|
AsciiToHex(TmpStr.c_str(), TmpU32);
|
|
|
|
|
Tmp.IR[ii] = (u8)TmpU32;
|
|
|
|
|
}
|
|
|
|
|
if (TmpIRBytes == 10) k += (10*2 + 1); else k += (12*2 + 1);
|
|
|
|
|
// ---------------------
|
|
|
|
|
|
2009-01-28 16:09:08 +00:00
|
|
|
|
// Go to next set of time values
|
2009-02-03 00:59:26 +00:00
|
|
|
|
double Time = (double)atoi(TmpTime.substr(l, 5).c_str());
|
2009-01-28 16:09:08 +00:00
|
|
|
|
Tmp.Time = (double)(Time/1000);
|
2009-02-03 00:59:26 +00:00
|
|
|
|
l += 6;
|
|
|
|
|
|
|
|
|
|
// Save the values
|
2009-01-28 16:09:08 +00:00
|
|
|
|
VRecording.at(i).Recording.push_back(Tmp);
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ---------------------------------
|
|
|
|
|
// Log results
|
|
|
|
|
// ---------
|
2009-01-29 08:35:29 +00:00
|
|
|
|
//Console::Print("Time:%f\n", Tmp.Time);
|
2009-02-03 00:59:26 +00:00
|
|
|
|
//std::string TmpIRLog = ArrayToString(Tmp.IR, TmpIRBytes, 0, 30);
|
|
|
|
|
//Console::Print("IR: %s\n", TmpIRLog.c_str());
|
|
|
|
|
//Console::Print("\n");
|
2009-01-28 16:09:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// Get HotKey
|
2009-01-28 16:09:08 +00:00
|
|
|
|
int TmpRecordHotKey; file.Get(SaveName.c_str(), "HotKey", &TmpRecordHotKey, -1);
|
|
|
|
|
VRecording.at(i).HotKey = TmpRecordHotKey;
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// Get Recording speed
|
2009-01-28 16:09:08 +00:00
|
|
|
|
int TmpPlaybackSpeed; file.Get(SaveName.c_str(), "PlaybackSpeed", &TmpPlaybackSpeed, -1);
|
|
|
|
|
VRecording.at(i).PlaybackSpeed = TmpPlaybackSpeed;
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ---------------------------------
|
|
|
|
|
// Logging
|
|
|
|
|
// ---------
|
|
|
|
|
std::string TmpIRLog;
|
|
|
|
|
if(TmpIRBytes > 0)
|
|
|
|
|
TmpIRLog = ArrayToString(VRecording.at(i).Recording.at(0).IR, TmpIRBytes, 0, 30);
|
|
|
|
|
else
|
|
|
|
|
TmpIRLog = "";
|
|
|
|
|
|
|
|
|
|
Console::Print("Size:%i HotKey:%i Speed:%i IR: %s\n",
|
|
|
|
|
VRecording.at(i).Recording.size(), VRecording.at(i).HotKey, VRecording.at(i).PlaybackSpeed,
|
|
|
|
|
TmpIRLog.c_str()
|
2009-01-28 16:09:08 +00:00
|
|
|
|
);
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// ---------------------
|
2009-01-28 16:09:08 +00:00
|
|
|
|
}
|
2009-01-29 08:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
// ================
|
|
|
|
|
|
2009-02-01 14:58:44 +00:00
|
|
|
|
// Update the accelerometer neutral values
|
|
|
|
|
void UpdateEeprom()
|
|
|
|
|
{
|
|
|
|
|
g_accel.cal_zero.x = g_Eeprom[22];
|
|
|
|
|
g_accel.cal_zero.y = g_Eeprom[23];
|
|
|
|
|
g_accel.cal_zero.z = g_Eeprom[24];
|
|
|
|
|
g_accel.cal_g.x = g_Eeprom[26] - g_Eeprom[22];
|
|
|
|
|
g_accel.cal_g.y = g_Eeprom[27] - g_Eeprom[24];
|
|
|
|
|
g_accel.cal_g.z = g_Eeprom[28] - g_Eeprom[24];
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
g_nu.cal_zero.x = g_RegExt[0x20];
|
|
|
|
|
g_nu.cal_zero.y = g_RegExt[0x21];
|
2009-02-07 04:19:52 +00:00
|
|
|
|
g_nu.cal_zero.z = g_RegExt[0x26]; // Including the g-force
|
2009-02-07 03:16:41 +00:00
|
|
|
|
g_nu.jx.max = g_RegExt[0x28];
|
|
|
|
|
g_nu.jx.min = g_RegExt[0x29];
|
|
|
|
|
g_nu.jx.center = g_RegExt[0x2a];
|
|
|
|
|
g_nu.jy.max = g_RegExt[0x2b];
|
|
|
|
|
g_nu.jy.min = g_RegExt[0x2c];
|
|
|
|
|
g_nu.jy.center = g_RegExt[0x2d];
|
|
|
|
|
|
2009-02-07 04:19:52 +00:00
|
|
|
|
Console::Print("\nUpdateEeprom: %i %i %i\n",
|
2009-02-01 14:58:44 +00:00
|
|
|
|
WiiMoteEmu::g_Eeprom[22], WiiMoteEmu::g_Eeprom[23], WiiMoteEmu::g_Eeprom[27]);
|
2009-02-07 04:19:52 +00:00
|
|
|
|
|
|
|
|
|
Console::Print("UpdateExtension: %i %i %i %i %i\n\n",
|
|
|
|
|
WiiMoteEmu::g_RegExt[0x2a], WiiMoteEmu::g_RegExt[0x2d],
|
|
|
|
|
WiiMoteEmu::g_RegExt[20], WiiMoteEmu::g_RegExt[21], WiiMoteEmu::g_RegExt[26]);
|
2009-02-01 14:58:44 +00:00
|
|
|
|
}
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// Calculate checksum for the nunchuck calibration. The last two bytes.
|
|
|
|
|
void ExtensionChecksum(u8 * Calibration)
|
|
|
|
|
{
|
|
|
|
|
u8 sum = 0; u8 Byte15, Byte16;
|
|
|
|
|
for (int i = 0; i < sizeof(Calibration) - 2; i++)
|
|
|
|
|
{
|
|
|
|
|
sum += Calibration[i];
|
|
|
|
|
printf("Plus 0x%02x\n", Calibration[i]);
|
|
|
|
|
}
|
|
|
|
|
Byte15 = sum + 0x55; // Byte 15
|
|
|
|
|
Byte16 = sum + 0xaa; // Byte 16
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-05 00:13:38 +00:00
|
|
|
|
// Set initial values
|
|
|
|
|
void ResetVariables()
|
|
|
|
|
{
|
|
|
|
|
u8 g_Leds = 0x0; // 4 bits
|
|
|
|
|
u8 g_Speaker = 0x0; // 1 = on
|
|
|
|
|
u8 g_SpeakerVoice = 0x0; // 1 = on
|
|
|
|
|
u8 g_IR = 0x0; // 1 = on
|
|
|
|
|
|
|
|
|
|
g_ReportingMode = 0;
|
|
|
|
|
g_ReportingChannel = 0;
|
2009-02-07 03:16:41 +00:00
|
|
|
|
g_Encryption = false;
|
2009-02-05 00:13:38 +00:00
|
|
|
|
|
|
|
|
|
g_EmulatedWiiMoteInitialized = false;
|
|
|
|
|
}
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-07 04:19:52 +00:00
|
|
|
|
// Update the extension calibration values with our default values
|
|
|
|
|
void SetDefaultExtensionRegistry()
|
|
|
|
|
{
|
|
|
|
|
// Copy extension id and calibration to its register
|
|
|
|
|
if(g_Config.bNunchuckConnected)
|
|
|
|
|
{
|
|
|
|
|
memcpy(g_RegExt + 0x20, nunchuck_calibration, sizeof(nunchuck_calibration));
|
|
|
|
|
memcpy(g_RegExt + 0x30, nunchuck_calibration, sizeof(nunchuck_calibration));
|
|
|
|
|
memcpy(g_RegExt + 0xfa, nunchuck_id, sizeof(nunchuck_id));
|
|
|
|
|
}
|
|
|
|
|
else if(g_Config.bClassicControllerConnected)
|
|
|
|
|
{
|
|
|
|
|
memcpy(g_RegExt + 0x20, classic_calibration, sizeof(classic_calibration));
|
|
|
|
|
memcpy(g_RegExt + 0x30, classic_calibration, sizeof(classic_calibration));
|
|
|
|
|
memcpy(g_RegExt + 0xfa, classic_id, sizeof(classic_id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateEeprom();
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-08 15:39:28 +00:00
|
|
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
|
// Fill joyinfo with the current connected devices
|
|
|
|
|
// ----------------
|
|
|
|
|
bool Search_Devices(std::vector<InputCommon::CONTROLLER_INFO> &_joyinfo, int &_NumPads, int &_NumGoodPads)
|
|
|
|
|
{
|
|
|
|
|
bool Success = InputCommon::SearchDevices(_joyinfo, _NumPads, _NumGoodPads);
|
|
|
|
|
|
|
|
|
|
// Warn the user if no gamepads are detected
|
|
|
|
|
if (_NumGoodPads == 0 && g_EmulatorRunning)
|
|
|
|
|
{
|
|
|
|
|
//PanicAlert("nJoy: No Gamepad Detected");
|
|
|
|
|
//return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load PadMapping[] etc
|
|
|
|
|
g_Config.Load();
|
|
|
|
|
|
|
|
|
|
// Update the PadState[].joy handle
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
if (PadMapping[i].enabled && joyinfo.size() > PadMapping[i].ID)
|
|
|
|
|
if(joyinfo.at(PadMapping[i].ID).Good)
|
|
|
|
|
PadState[i].joy = SDL_JoystickOpen(PadMapping[i].ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
|
}
|
|
|
|
|
// ===========================
|
|
|
|
|
|
|
|
|
|
|
2009-01-29 08:35:29 +00:00
|
|
|
|
// ===================================================
|
|
|
|
|
/* Write initial values to Eeprom and registers. */
|
|
|
|
|
// ----------------
|
|
|
|
|
void Initialize()
|
|
|
|
|
{
|
|
|
|
|
if (g_EmulatedWiiMoteInitialized) return;
|
|
|
|
|
|
2009-02-05 00:13:38 +00:00
|
|
|
|
// Reset variables
|
|
|
|
|
ResetVariables();
|
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Write default Eeprom data
|
2009-01-29 08:35:29 +00:00
|
|
|
|
memset(g_Eeprom, 0, WIIMOTE_EEPROM_SIZE);
|
|
|
|
|
memcpy(g_Eeprom, EepromData_0, sizeof(EepromData_0));
|
|
|
|
|
memcpy(g_Eeprom + 0x16D0, EepromData_16D0, sizeof(EepromData_16D0));
|
|
|
|
|
|
|
|
|
|
// Copy extension id and calibration to its register
|
2009-02-07 04:19:52 +00:00
|
|
|
|
SetDefaultExtensionRegistry();
|
2009-01-29 08:35:29 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
g_ReportingMode = 0;
|
2009-01-29 08:35:29 +00:00
|
|
|
|
g_EmulatedWiiMoteInitialized = true;
|
|
|
|
|
|
|
|
|
|
// Load pre-recorded movements
|
|
|
|
|
LoadRecordedMovements();
|
2009-01-28 16:09:08 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Set default recording values
|
2009-02-04 06:40:05 +00:00
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
g_RecordingPlaying[i] = -1;
|
|
|
|
|
g_RecordingCounter[i] = 0;
|
|
|
|
|
g_RecordingPoint[i] = 0;
|
|
|
|
|
g_RecordingStart[i] = 0;
|
|
|
|
|
g_RecordingCurrentTime[i] = 0;
|
|
|
|
|
}
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
2009-02-08 15:39:28 +00:00
|
|
|
|
// Load avaliable pads
|
|
|
|
|
Search_Devices(joyinfo, NumPads, NumGoodPads);
|
|
|
|
|
|
2009-02-07 04:19:52 +00:00
|
|
|
|
/* The Nuncheck extension ID for homebrew applications that use the zero key. This writes 0x0000
|
|
|
|
|
in encrypted form (0xfefe) to 0xfe in the extension register. */
|
|
|
|
|
//WriteCrypted16(g_RegExt, 0xfe, 0x0000); // Fully inserted Nunchuk
|
|
|
|
|
|
|
|
|
|
// I forgot what these were for? Is this the zero key encrypted 0xa420?
|
2009-01-26 07:01:43 +00:00
|
|
|
|
// g_RegExt[0xfd] = 0x1e;
|
|
|
|
|
// g_RegExt[0xfc] = 0x9a;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// ================
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void DoState(void* ptr, int mode)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//TODO: implement
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-05 00:13:38 +00:00
|
|
|
|
/* This is not needed if we call FreeLibrary() when we stop a game, but if it's not called we need to reset
|
|
|
|
|
these variables. */
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void Shutdown(void)
|
2009-02-05 00:13:38 +00:00
|
|
|
|
{
|
|
|
|
|
ResetVariables();
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* An ack delay of 1 was not small enough, but 2 seemed to work, that was about between 20 ms and
|
2009-02-08 10:15:55 +00:00
|
|
|
|
100 ms in my case in Zelda - TP. You may have to increase this value for other things to work, for
|
|
|
|
|
example in the wpad demo I had to set it to at least 3 for the Sound to be able to turned on (I have
|
|
|
|
|
an update rate of around 150 fps in the wpad demo) */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void CreateAckDelay(u8 _ChannelID, u16 _ReportID)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// Settings
|
|
|
|
|
int GlobalDelay = 2;
|
|
|
|
|
|
|
|
|
|
// Queue an acknowledgment
|
|
|
|
|
wm_ackdelay Tmp;
|
|
|
|
|
Tmp.Delay = GlobalDelay;
|
|
|
|
|
Tmp.ChannelID = _ChannelID;
|
2009-01-24 00:45:46 +00:00
|
|
|
|
Tmp.ReportID = (u8)_ReportID;
|
2009-01-07 02:59:19 +00:00
|
|
|
|
AckDelay.push_back(Tmp);
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void CheckAckDelay()
|
|
|
|
|
{
|
2009-01-24 01:50:23 +00:00
|
|
|
|
for (int i = 0; i < (int)AckDelay.size(); i++)
|
2009-01-07 02:59:19 +00:00
|
|
|
|
{
|
|
|
|
|
// See if there are any acks to send
|
|
|
|
|
if (AckDelay.at(i).Delay >= 0)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
if(AckDelay.at(i).Delay == 0)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
WmSendAck(AckDelay.at(i).ChannelID, AckDelay.at(i).ReportID, 0);
|
|
|
|
|
AckDelay.erase(AckDelay.begin() + i);
|
|
|
|
|
continue;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
AckDelay.at(i).Delay--;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-17 14:28:09 +00:00
|
|
|
|
//Console::Print("%i 0x%04x 0x%02x", i, AckDelay.at(i).ChannelID, AckDelay.at(i).ReportID);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// ================
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* This function produce Wiimote Input, i.e. reports from the Wiimote in response
|
|
|
|
|
to Output from the Wii. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void InterruptChannel(u16 _channelID, const void* _pData, u32 _Size)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-26 07:01:43 +00:00
|
|
|
|
//Console::Print("Emu InterruptChannel\n");
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "=============================================================");
|
|
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "Wiimote_Input");
|
|
|
|
|
const u8* data = (const u8*)_pData;
|
|
|
|
|
|
|
|
|
|
/* Debugging. We have not yet decided how much of 'data' we will use, it's not determined
|
|
|
|
|
by sizeof(data). We have to determine it by looking at the data cases. */
|
2009-02-01 13:01:50 +00:00
|
|
|
|
InterruptDebugging(true, data);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
hid_packet* hidp = (hid_packet*) data;
|
|
|
|
|
switch(hidp->type)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
case HID_TYPE_DATA:
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
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(). Zelda - TP is even more sensitive and require
|
|
|
|
|
a delay after the Input for the Nunchuck to work. It seemed to be
|
|
|
|
|
enough to delay only the Nunchuck registry reads and writes but
|
|
|
|
|
for now I'm delaying all inputs. Both for status changes and Eeprom
|
|
|
|
|
and registry reads and writes. */
|
|
|
|
|
|
2009-02-03 00:59:26 +00:00
|
|
|
|
// There are no 0x22 replys to these report from the real wiimote from what I could see
|
|
|
|
|
// Report 0x10 that seems to be only used for rumble
|
2009-02-08 10:15:55 +00:00
|
|
|
|
if(!(data[1] == WM_READ_DATA && data[2] == 0x00)
|
|
|
|
|
&& !(data[1] == WM_REQUEST_STATUS)
|
|
|
|
|
&& !(data[1] == WM_WRITE_SPEAKER_DATA))
|
2009-02-03 00:59:26 +00:00
|
|
|
|
if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) CreateAckDelay((u8)_channelID, (u16)sr->channel);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
default:
|
|
|
|
|
PanicAlert("HidInput: HID_TYPE_DATA - param 0x%02x", hidp->type, hidp->param);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
default:
|
|
|
|
|
PanicAlert("HidInput: Unknown type 0x%02x and param 0x%02x", hidp->type, hidp->param);
|
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
LOGV(WII_IPC_WIIMOTE, 3, "=============================================================");
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void ControlChannel(u16 _channelID, const void* _pData, u32 _Size)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-26 07:01:43 +00:00
|
|
|
|
//Console::Print("Emu ControlChannel\n");
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
const u8* data = (const u8*)_pData;
|
2009-01-26 07:01:43 +00:00
|
|
|
|
// Dump raw data
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
LOG(WII_IPC_WIIMOTE, "Wiimote_ControlChannel");
|
|
|
|
|
std::string Temp = ArrayToString(data, 0, _Size);
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("\n%s: ControlChannel: %s\n", Tm().c_str(), Temp.c_str());
|
2009-01-07 02:59:19 +00:00
|
|
|
|
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)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
PanicAlert("HID_TYPE_HANDSHAKE - HID_PARAM_INPUT");
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
else
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
PanicAlert("HID_TYPE_HANDSHAKE - HID_PARAM_OUTPUT");
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
case HID_TYPE_SET_REPORT:
|
|
|
|
|
if (hidp->param == HID_PARAM_INPUT)
|
|
|
|
|
{
|
|
|
|
|
PanicAlert("HID_TYPE_SET_REPORT input");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HidOutputReport(_channelID, (wm_report*)hidp->data);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
// Return handshake
|
2009-01-07 02:59:19 +00:00
|
|
|
|
u8 handshake = 0;
|
|
|
|
|
g_WiimoteInitialize.pWiimoteInput(_channelID, &handshake, 1);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
case HID_TYPE_DATA:
|
|
|
|
|
PanicAlert("HID_TYPE_DATA %s", hidp->type, hidp->param == HID_PARAM_INPUT ? "input" : "output");
|
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
default:
|
|
|
|
|
PanicAlert("HidControlChanel: Unknown type %x and param %x", hidp->type, hidp->param);
|
|
|
|
|
break;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* This is called from Wiimote_Update(). See SystemTimers.cpp for a documentation. I'm
|
|
|
|
|
not sure exactly how often this function is called but I think it's tied to the frame
|
|
|
|
|
rate of the game rather than a certain amount of times per second. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void Update()
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//LOG(WII_IPC_WIIMOTE, "Wiimote_Update");
|
2009-01-26 07:01:43 +00:00
|
|
|
|
//Console::Print("Emu Update: %i\n", g_ReportingMode);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
switch(g_ReportingMode)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
2009-01-25 23:07:15 +00:00
|
|
|
|
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;
|
2009-01-07 02:59:19 +00:00
|
|
|
|
case WM_REPORT_CORE_ACCEL_IR10_EXT6: SendReportCoreAccelIr10Ext(g_ReportingChannel);break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Potentially send a delayed acknowledgement to an InterruptChannel() Output
|
|
|
|
|
CheckAckDelay();
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
2008-12-08 05:25:12 +00:00
|
|
|
|
} // end of namespace
|
2008-12-09 05:37:15 +00:00
|
|
|
|
|