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/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
|
|
|
|
/* 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() */
|
|
|
|
|
|
|
|
|
|
// ================
|
|
|
|
|
|
|
|
|
|
|
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 <vector>
|
|
|
|
|
#include <string>
|
2008-12-09 05:37:15 +00:00
|
|
|
|
|
|
|
|
|
#include "Common.h" // Common
|
|
|
|
|
#include "StringUtil.h"
|
2009-01-26 07:01:43 +00:00
|
|
|
|
#include "pluginspecs_wiimote.h"
|
2008-12-09 05:37:15 +00:00
|
|
|
|
|
2009-02-01 13:01:50 +00:00
|
|
|
|
#include "EmuMain.h" // Local
|
2008-12-08 05:25:12 +00:00
|
|
|
|
#include "EmuSubroutines.h"
|
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
|
|
|
|
// Subroutines
|
2008-12-08 05:25:12 +00:00
|
|
|
|
//******************************************************************************
|
|
|
|
|
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// ===================================================
|
|
|
|
|
/* Here we process the Output Reports that the Wii sends. Our response will be an Input Report
|
|
|
|
|
back to the Wii. Input and Output is from the Wii's perspective, Output means data to
|
|
|
|
|
the Wiimote (from the Wii), Input means data from the Wiimote.
|
|
|
|
|
|
|
|
|
|
The call browser:
|
|
|
|
|
|
|
|
|
|
1. Wiimote_InterruptChannel > InterruptChannel > HidOutputReport
|
|
|
|
|
2. Wiimote_ControlChannel > ControlChannel > HidOutputReport
|
|
|
|
|
|
|
|
|
|
The IR lights and speaker enable/disable and mute/unmute values are
|
|
|
|
|
0x2 = Disable
|
|
|
|
|
0x6 = Enable */
|
|
|
|
|
// ----------------
|
|
|
|
|
void HidOutputReport(u16 _channelID, wm_report* sr) {
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "===========================================================");
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "HidOutputReport (0x%02x)", sr->channel);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
std::string Temp;
|
|
|
|
|
|
|
|
|
|
switch(sr->channel)
|
|
|
|
|
{
|
|
|
|
|
case 0x10:
|
2009-03-02 01:49:16 +00:00
|
|
|
|
ERROR_LOG(WII_IPC_WIIMOTE, "HidOutputReport: unknown sr->channel 0x10");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
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
|
2009-01-26 07:01:43 +00:00
|
|
|
|
if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) WmRequestStatus(_channelID, (wm_request_status*)sr->data);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//Temp = ArrayToString(sr->data, sizeof(wm_request_status), 0);
|
2009-01-17 14:28:09 +00:00
|
|
|
|
//Console::Print("\n%s: InterruptChannel: %s\n", Tm().c_str(), Temp.c_str());
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case WM_READ_DATA: // 0x17
|
2009-01-26 07:01:43 +00:00
|
|
|
|
if (!g_Config.bUseRealWiimote || !g_RealWiiMotePresent) WmReadData(_channelID, (wm_read_data*)sr->data);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* This enables or disables the IR lights, we update the global variable g_IR
|
|
|
|
|
so that WmRequestStatus() knows about it */
|
|
|
|
|
case WM_IR_PIXEL_CLOCK: // 0x13
|
|
|
|
|
case WM_IR_LOGIC: // 0x1a
|
2009-03-02 01:49:16 +00:00
|
|
|
|
WARN_LOG(WII_IPC_WIIMOTE, " IR Enable 0x%02x: 0x%02x", sr->channel, sr->data[0]);
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("IR Enable/Disable 0x%02x: 0x%02x\n", sr->channel, sr->data[0]);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
if(sr->data[0] == 0x02) g_IR = 0;
|
|
|
|
|
else if(sr->data[0] == 0x06) g_IR = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case WM_WRITE_DATA: // 0x16
|
2009-02-04 06:40:05 +00:00
|
|
|
|
WmWriteData(_channelID, (wm_write_data*)sr->data);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
2009-02-08 12:27:04 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
case WM_SPEAKER_ENABLE: // 0x14
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " WM Speaker Enable 0x%02x: 0x%02x", sr->channel, sr->data[0]);
|
2009-01-26 07:01:43 +00:00
|
|
|
|
//Console::Print("Speaker Enable/Disable 0x%02x: 0x%02x\n", sr->channel, sr->data[0]);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
if(sr->data[0] == 0x02) g_Speaker = 0;
|
|
|
|
|
else if(sr->data[0] == 0x06) g_Speaker = 1;
|
|
|
|
|
break;
|
2009-02-08 12:27:04 +00:00
|
|
|
|
case WM_SPEAKER_MUTE: // 0x19
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " WM Mute Enable 0x%02x: 0x%02x", sr->channel, sr->data[0]);
|
2009-01-26 07:01:43 +00:00
|
|
|
|
//Console::Print("Speaker Mute/Unmute 0x%02x: 0x%02x\n", sr->channel, sr->data[0]);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
if(sr->data[0] == 0x02) g_SpeakerVoice = 0; // g_SpeakerVoice
|
|
|
|
|
else if(sr->data[0] == 0x06) g_SpeakerVoice = 1;
|
|
|
|
|
break;
|
2009-02-08 10:15:55 +00:00
|
|
|
|
case WM_WRITE_SPEAKER_DATA: // 0x18
|
|
|
|
|
break;
|
2009-02-08 12:27:04 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
default:
|
2009-03-02 01:49:16 +00:00
|
|
|
|
ERROR_LOG(WII_IPC_WIIMOTE, "HidOutputReport: Unknown channel 0x%02x", sr->channel);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
PanicAlert("HidOutputReport: Unknown channel 0x%02x", sr->channel);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "===========================================================");
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-02-04 06:40:05 +00:00
|
|
|
|
/* Generate the right header for wm reports. The returned values is the length of the header before
|
|
|
|
|
the data begins. It's always two for all reports 0x20 - 0x22, 0x30 - 0x37 */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-02-01 13:01:50 +00:00
|
|
|
|
int WriteWmReport(u8* dst, u8 channel)
|
|
|
|
|
{
|
2009-02-04 06:40:05 +00:00
|
|
|
|
// Update the first byte to 0xa1
|
2009-01-07 02:59:19 +00:00
|
|
|
|
u32 Offset = 0;
|
|
|
|
|
hid_packet* pHidHeader = (hid_packet*)(dst + Offset);
|
|
|
|
|
Offset += sizeof(hid_packet);
|
|
|
|
|
pHidHeader->type = HID_TYPE_DATA;
|
|
|
|
|
pHidHeader->param = HID_PARAM_INPUT;
|
|
|
|
|
|
2009-02-04 06:40:05 +00:00
|
|
|
|
// Update the second byte to the current report type 0x20 - 0x22, 0x30 - 0x37
|
2009-01-07 02:59:19 +00:00
|
|
|
|
wm_report* pReport = (wm_report*)(dst + Offset);
|
|
|
|
|
Offset += sizeof(wm_report);
|
|
|
|
|
pReport->channel = channel;
|
|
|
|
|
return Offset;
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// ===================================================
|
|
|
|
|
/* LED (blue lights) report. */
|
|
|
|
|
// ----------------
|
|
|
|
|
void WmLeds(u16 _channelID, wm_leds* leds) {
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "===========================================================");
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Set LEDs");
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Leds: %x", leds->leds);
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Rumble: %x", leds->rumble);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
g_Leds = leds->leds;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "===========================================================");
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* 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 the core buttons data,
|
|
|
|
|
they are 00 00 when nothing is pressed. The last byte is the success code 00. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void WmSendAck(u16 _channelID, u8 _reportID, u32 address)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " WMSendAck()");
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Report ID: %02x", _reportID);
|
2009-02-01 13:01:50 +00:00
|
|
|
|
//std::string Temp = ArrayToString(DataFrame, Offset, 0);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//LOGV(WII_IPC_WIIMOTE, 2, " Data: %s", Temp.c_str());
|
2009-02-01 13:01:50 +00:00
|
|
|
|
//Console::Print("%s: WMSendAck: %s\n", Tm(true).c_str(), Temp.c_str());
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
/* Debug. Write the report for extension registry writes.
|
|
|
|
|
if((_reportID == 0x16 || _reportID == 0x17) && ((address >> 16) & 0xfe) == 0xa4)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("\nWMSendAck Report ID: %02x Encryption: %02x\n", _reportID, g_RegExt[0xf0]);
|
|
|
|
|
Console::Print("Data: %s\n", Temp.c_str());
|
2009-01-07 02:59:19 +00:00
|
|
|
|
}*/
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
|
|
// Debugging
|
2009-02-04 06:40:05 +00:00
|
|
|
|
ReadDebugging(true, DataFrame, Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* Read data from Wiimote and Extensions registers. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void WmReadData(u16 _channelID, wm_read_data* rd)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-03-02 20:30:04 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "===========================================================");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
u32 address = convert24bit(rd->address);
|
|
|
|
|
u16 size = convert16bit(rd->size);
|
|
|
|
|
std::string Temp;
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "Read data");
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Address space: %x", rd->space);
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Address: 0x%06x", address);
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Size: 0x%04x", size);
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Rumble: %x", rd->rumble);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
//u32 _address = address;
|
|
|
|
|
std::string Tmp; // Debugging
|
|
|
|
|
|
|
|
|
|
/* Now we determine what address space we are reading from. Space 0 is Eeprom and
|
|
|
|
|
space 1 and 2 is the registers. */
|
2009-02-01 13:01:50 +00:00
|
|
|
|
if(rd->space == WM_SPACE_EEPROM)
|
2009-01-07 02:59:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (address + size > WIIMOTE_EEPROM_SIZE)
|
|
|
|
|
{
|
2009-02-01 13:01:50 +00:00
|
|
|
|
PanicAlert("WmReadData: address + size out of bounds");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-02-01 13:01:50 +00:00
|
|
|
|
SendReadDataReply(_channelID, g_Eeprom + address, address, (u8)size);
|
|
|
|
|
/*Console::Print("Read RegEeprom: Size: %i, Address: %08x, Offset: %08x\n",
|
|
|
|
|
size, address, (address & 0xffff));*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
}
|
|
|
|
|
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;
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Case 0xa2: g_RegSpeaker");
|
2009-02-01 13:01:50 +00:00
|
|
|
|
/*Tmp = ArrayToString(g_RegSpeaker, size, (address & 0xffff));
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//LOGV(WII_IPC_WIIMOTE, 0, " Data: %s", Temp.c_str());
|
2009-02-01 13:01:50 +00:00
|
|
|
|
Console::Print("Read RegSpkr: Size %i Address %08x Offset %08x\nData %s\n",
|
|
|
|
|
size, address, (address & 0xffff), Tmp.c_str());*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case 0xA4:
|
|
|
|
|
block = g_RegExt;
|
|
|
|
|
blockSize = WIIMOTE_REG_EXT_SIZE;
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Case 0xa4: Read ExtReg");
|
2009-02-04 06:40:05 +00:00
|
|
|
|
/*Tmp = ArrayToString(g_RegExt, size, (address & 0xffff), 40);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//LOGV(WII_IPC_WIIMOTE, 0, " Data: %s", Temp.c_str());
|
2009-02-01 13:01:50 +00:00
|
|
|
|
Console::Print("Read RegExt: Size %i Address %08x Offset %08x\nData %s\n",
|
|
|
|
|
size, address, (address & 0xffff), Tmp.c_str());*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
|
|
|
|
case 0xB0:
|
|
|
|
|
block = g_RegIr;
|
|
|
|
|
blockSize = WIIMOTE_REG_IR_SIZE;
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Case: 0xb0 g_RegIr");
|
2009-02-01 13:01:50 +00:00
|
|
|
|
/*Tmp = ArrayToString(g_RegIr, size, (address & 0xffff));
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//LOGV(WII_IPC_WIIMOTE, 0, " Data: %s", Temp.c_str());
|
2009-02-01 13:01:50 +00:00
|
|
|
|
Console::Print("Read RegIR: Size %i Address %08x Offset %08x\nData %s\n",
|
|
|
|
|
size, address, (address & 0xffff), Tmp.c_str());*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2009-03-02 01:49:16 +00:00
|
|
|
|
ERROR_LOG(WII_IPC_WIIMOTE, "WmWriteData: bad register block!");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
PanicAlert("WmWriteData: bad register block!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// -----------------------------------------
|
|
|
|
|
// Encrypt data that is read from the Wiimote Extension Register
|
|
|
|
|
// -------------
|
|
|
|
|
if(((address >> 16) & 0xfe) == 0xa4)
|
|
|
|
|
{
|
|
|
|
|
/* Debugging
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("\n\nWmReadData Address: %08x Offset: %08x Size: %i byte\n",
|
2009-01-07 02:59:19 +00:00
|
|
|
|
address, address & 0xffff, (u8)size);
|
|
|
|
|
// Debugging
|
|
|
|
|
u32 offset = address & 0xffff;
|
|
|
|
|
std::string Temp = ArrayToString(g_RegExt, size, offset);
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("Unencrypted data:\n%s\n", Temp.c_str());*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
// Check if encrypted reads is on
|
|
|
|
|
if(g_RegExt[0xf0] == 0xaa)
|
|
|
|
|
{
|
|
|
|
|
/* Copy the registry to a temporary space. We don't want to change the unencrypted
|
|
|
|
|
data in the registry */
|
|
|
|
|
memcpy(g_RegExtTmp, g_RegExt, sizeof(g_RegExt));
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// Encrypt g_RegExtTmp at that location
|
|
|
|
|
wiimote_encrypt(&g_ExtKey, &g_RegExtTmp[address & 0xffff], (address & 0xffff), (u8)size);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-04 06:40:05 +00:00
|
|
|
|
// Update the block that SendReadDataReply will eventually send to the Wii
|
|
|
|
|
block = g_RegExtTmp;
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* Debugging: Show the encrypted data
|
|
|
|
|
std::string Temp = ArrayToString(g_RegExtTmp, size, offset);
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("Encrypted data:\n%s\n", Temp.c_str());*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-02-04 06:40:05 +00:00
|
|
|
|
//-------------
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
address &= 0xFFFF;
|
|
|
|
|
if(address + size > blockSize) {
|
|
|
|
|
PanicAlert("WmReadData: address + size out of bounds!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// Let this function process the message and send it to the Wii
|
2009-02-01 13:01:50 +00:00
|
|
|
|
SendReadDataReply(_channelID, block + address, address, (u8)size);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PanicAlert("WmReadData: unimplemented parameters (size: %i, addr: 0x%x!", size, rd->space);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "===========================================================");
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-02-04 06:40:05 +00:00
|
|
|
|
// ===================================================
|
|
|
|
|
/* Here we produce the actual 0x21 Input report that we send to the Wii. The message
|
|
|
|
|
is divided into 16 bytes pieces and sent piece by piece. There will be five formatting
|
|
|
|
|
bytes at the begging of all reports. A common format is 00 00 f0 00 20, the 00 00
|
|
|
|
|
means that no buttons are pressed, the f means 16 bytes in the message, the 0
|
|
|
|
|
means no error, the 00 20 means that the message is at the 00 20 offest in the
|
|
|
|
|
registry that was read.
|
|
|
|
|
|
|
|
|
|
_Base: The data beginning at _Base[0]
|
|
|
|
|
_Address: The starting address inside the registry, this is used to check for out of bounds reading
|
|
|
|
|
_Size: The total size to send
|
|
|
|
|
*/
|
|
|
|
|
// ----------------
|
|
|
|
|
void SendReadDataReply(u16 _channelID, void* _Base, u16 _Address, u8 _Size)
|
|
|
|
|
{
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "=========================================");
|
2009-02-04 06:40:05 +00:00
|
|
|
|
int dataOffset = 0;
|
|
|
|
|
const u8* data = (const u8*)_Base;
|
|
|
|
|
|
|
|
|
|
while (_Size > 0)
|
|
|
|
|
{
|
|
|
|
|
u8 DataFrame[1024];
|
|
|
|
|
// Write the first two bytes to DataFrame
|
|
|
|
|
u32 Offset = WriteWmReport(DataFrame, WM_READ_DATA_REPLY);
|
|
|
|
|
|
|
|
|
|
// Limit the size to 16 bytes
|
|
|
|
|
int copySize = _Size;
|
|
|
|
|
if (copySize > 16) copySize = 16;
|
|
|
|
|
|
|
|
|
|
// Connect pReply->data to the almost empty DataFrame
|
|
|
|
|
wm_read_data_reply* pReply = (wm_read_data_reply*)(DataFrame + Offset);
|
|
|
|
|
// Now we increase Offset to the final size of the report
|
|
|
|
|
Offset += sizeof(wm_read_data_reply);
|
|
|
|
|
// Add header values
|
|
|
|
|
pReply->buttons = 0;
|
|
|
|
|
pReply->error = 0;
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// 0x1 means two bytes, 0xf means 16 bytes
|
2009-02-04 06:40:05 +00:00
|
|
|
|
pReply->size = (copySize - 1) & 0xf;
|
|
|
|
|
pReply->address = Common::swap16(_Address + dataOffset);
|
|
|
|
|
|
|
|
|
|
// Write a pice of _Base to DataFrame
|
|
|
|
|
memcpy(pReply->data, data + dataOffset, copySize);
|
|
|
|
|
|
|
|
|
|
// Check if we have less than 16 bytes left to send
|
|
|
|
|
if(copySize < 16) memset(pReply->data + copySize, 0, 16 - copySize);
|
|
|
|
|
|
|
|
|
|
// Update DataOffset for the next loop
|
|
|
|
|
dataOffset += copySize;
|
|
|
|
|
|
|
|
|
|
/* Out of bounds. The real Wiimote generate an error for the first request to 0x1770
|
|
|
|
|
if we dont't replicate that the game will never read the capibration data at the
|
|
|
|
|
beginning of Eeprom. I think this error is supposed to occur when we try to read above
|
|
|
|
|
the freely usable space that ends at 0x16ff. */
|
|
|
|
|
if (Common::swap16(pReply->address + pReply->size) > WIIMOTE_EEPROM_FREE_SIZE)
|
|
|
|
|
{
|
|
|
|
|
pReply->size = 0x0f;
|
|
|
|
|
pReply->error = 0x08;
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-02-04 06:40:05 +00:00
|
|
|
|
// Logging
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " SendReadDataReply()");
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Buttons: 0x%04x", pReply->buttons);
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Error: 0x%x", pReply->error);
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Size: 0x%x", pReply->size);
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Address: 0x%04x", pReply->address);
|
2009-02-04 06:40:05 +00:00
|
|
|
|
/*Console::Print(" SendReadDataReply()\n");
|
|
|
|
|
Console::Print(" Offset: 0x%x\n", Offset);
|
|
|
|
|
Console::Print(" dataOffset: 0x%x\n", dataOffset);
|
|
|
|
|
Console::Print(" copySize: 0x%x\n", copySize);
|
|
|
|
|
Console::Print(" Size: 0x%x\n", pReply->size);
|
|
|
|
|
Console::Print(" Address: 0x%04x\n", Common::swap16(pReply->address));*/
|
|
|
|
|
//std::string Temp = ArrayToString(data, 0x40);
|
|
|
|
|
//Console::Print("Data:\n%s\n", Temp.c_str());
|
|
|
|
|
|
|
|
|
|
// Send a piece
|
|
|
|
|
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
|
|
|
|
// Update the size that is left
|
|
|
|
|
_Size -= copySize;
|
|
|
|
|
|
|
|
|
|
// Debugging
|
|
|
|
|
ReadDebugging(true, DataFrame, Offset);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-02 01:49:16 +00:00
|
|
|
|
if (_Size != 0) {
|
|
|
|
|
ERROR_LOG(WII_IPC_WIIMOTE, "WiiMote-Plugin: SendReadDataReply() failed");
|
2009-02-04 06:40:05 +00:00
|
|
|
|
PanicAlert("WiiMote-Plugin: SendReadDataReply() failed");
|
2009-03-02 01:49:16 +00:00
|
|
|
|
}
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "==========================================");
|
2009-02-04 06:40:05 +00:00
|
|
|
|
}
|
|
|
|
|
// ================
|
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
|
|
|
|
/* Write data to Wiimote and Extensions registers. */
|
2008-12-08 05:25:12 +00:00
|
|
|
|
// ----------------
|
2009-01-07 02:59:19 +00:00
|
|
|
|
void WmWriteData(u16 _channelID, wm_write_data* wd)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "========================================================");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
u32 address = convert24bit(wd->address);
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "Write data");
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Address space: %x", wd->space);
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Address: 0x%06x", address);
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Size: 0x%02x", wd->size);
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Rumble: %x", wd->rumble);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//std::string Temp = ArrayToString(wd->data, wd->size);
|
|
|
|
|
//LOGV(WII_IPC_WIIMOTE, 0, " Data: %s", Temp.c_str());
|
|
|
|
|
|
|
|
|
|
// Write to EEPROM
|
|
|
|
|
if(wd->size <= 16 && wd->space == WM_SPACE_EEPROM)
|
|
|
|
|
{
|
|
|
|
|
if(address + wd->size > WIIMOTE_EEPROM_SIZE) {
|
2009-03-02 01:49:16 +00:00
|
|
|
|
ERROR_LOG(WII_IPC_WIIMOTE, "WmWriteData: address + size out of bounds!");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
PanicAlert("WmWriteData: address + size out of bounds!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
memcpy(g_Eeprom + address, wd->data, wd->size);
|
2009-02-01 13:01:50 +00:00
|
|
|
|
/*Console::Print("Write RegEeprom: Size: %i, Address: %08x, Offset: %08x\n",
|
|
|
|
|
wd->size, address, (address & 0xffff));*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
}
|
|
|
|
|
// Write to registers
|
|
|
|
|
else if(wd->size <= 16 && (wd->space == WM_SPACE_REGS1 || wd->space == WM_SPACE_REGS2))
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
u8* block;
|
|
|
|
|
u32 blockSize;
|
|
|
|
|
switch((address >> 16) & 0xFE)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
case 0xA2:
|
|
|
|
|
block = g_RegSpeaker;
|
|
|
|
|
blockSize = WIIMOTE_REG_SPEAKER_SIZE;
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Case 0xa2: RegSpeaker");
|
2009-02-01 13:01:50 +00:00
|
|
|
|
/*Console::Print("Write RegSpeaker: Size: %i, Address: %08x, Offset: %08x\n",
|
|
|
|
|
wd->size, address, (address & 0xffff));
|
|
|
|
|
Console::Print("Data: %s\n", Temp.c_str());*/
|
2008-12-08 05:25:12 +00:00
|
|
|
|
break;
|
2009-01-07 02:59:19 +00:00
|
|
|
|
case 0xA4:
|
|
|
|
|
block = g_RegExt; // Extension Controller register
|
|
|
|
|
blockSize = WIIMOTE_REG_EXT_SIZE;
|
|
|
|
|
//LOGV(WII_IPC_WIIMOTE, 0, " *******************************************************");
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Case 0xa4: ExtReg");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
//LOGV(WII_IPC_WIIMOTE, 0, " *******************************************************");
|
2009-01-17 14:28:09 +00:00
|
|
|
|
/*Console::Print("Write RegExt Size: %i Address: %08x Offset: %08x \n",
|
2009-01-07 02:59:19 +00:00
|
|
|
|
wd->size, address, (address & 0xffff));
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("Data: %s\n", Temp.c_str());*/
|
2008-12-08 05:25:12 +00:00
|
|
|
|
break;
|
2009-01-07 02:59:19 +00:00
|
|
|
|
case 0xB0:
|
|
|
|
|
block = g_RegIr;
|
|
|
|
|
blockSize = WIIMOTE_REG_IR_SIZE;
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Case 0xb0: RegIr");
|
2009-01-17 14:28:09 +00:00
|
|
|
|
/*Console::Print("Write RegIR Size: %i Address: %08x Offset: %08x \n",
|
2009-01-07 02:59:19 +00:00
|
|
|
|
wd->size, address, (address & 0xffff));
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("Data: %s\n", Temp.c_str());*/
|
2009-01-07 02:59:19 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2009-03-02 01:49:16 +00:00
|
|
|
|
ERROR_LOG(WII_IPC_WIIMOTE, "WmWriteData: bad register block!");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
PanicAlert("WmWriteData: bad register block!");
|
|
|
|
|
return;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
// Remove for example 0xa40000 from the address
|
|
|
|
|
address &= 0xFFFF;
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// Check if the address is within bounds
|
|
|
|
|
if(address + wd->size > blockSize) {
|
2009-03-02 01:49:16 +00:00
|
|
|
|
ERROR_LOG(WII_IPC_WIIMOTE, "WmWriteData: address + size out of bounds!");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
PanicAlert("WmWriteData: address + size out of bounds!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-12-08 05:25:12 +00:00
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// 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)
|
2008-12-08 05:25:12 +00:00
|
|
|
|
{
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* Debugging. Write the data.
|
2009-01-17 14:28:09 +00:00
|
|
|
|
Console::Print("Data: %s\n", Temp.c_str());
|
|
|
|
|
Console::Print("Current address: %08x\n", address); */
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
/* 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]);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
// -------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
2009-03-02 01:49:16 +00:00
|
|
|
|
ERROR_LOG(WII_IPC_WIIMOTE, "WmWriteData: unimplemented parameters!");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
PanicAlert("WmWriteData: unimplemented parameters!");
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
/* 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);
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "==========================================================");
|
2009-01-07 02:59:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ===================================================
|
2009-02-07 05:57:28 +00:00
|
|
|
|
/* Here we produce a 0x20 status report to send to the Wii. We currently ignore the status
|
2009-01-07 02:59:19 +00:00
|
|
|
|
request rs and all its eventual instructions it may include (for example turn off
|
|
|
|
|
rumble or something else) and just send the status report. */
|
|
|
|
|
// ----------------
|
2009-02-07 03:16:41 +00:00
|
|
|
|
void WmRequestStatus(u16 _channelID, wm_request_status* rs, int Extension)
|
2009-01-07 02:59:19 +00:00
|
|
|
|
{
|
|
|
|
|
//PanicAlert("WmRequestStatus");
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "================================================");
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Request Status");
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Rumble: %x", rs->rumble);
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Channel: %04x", _channelID);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
//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->battery_low = 0; // battery is okay
|
|
|
|
|
pStatus->leds = g_Leds; // leds are 4 bit
|
|
|
|
|
pStatus->ir = g_IR; // 1 bit
|
|
|
|
|
pStatus->speaker = g_Speaker; // 1 bit
|
|
|
|
|
/* Battery levels in voltage
|
|
|
|
|
0x00 - 0x32: level 1
|
|
|
|
|
0x33 - 0x43: level 2
|
|
|
|
|
0x33 - 0x54: level 3
|
|
|
|
|
0x55 - 0xff: level 4 */
|
|
|
|
|
pStatus->battery = 0x5f; // fully charged
|
|
|
|
|
|
2009-02-07 03:16:41 +00:00
|
|
|
|
// Check if we have a specific order about the extension status
|
|
|
|
|
if (Extension == -1)
|
|
|
|
|
{
|
|
|
|
|
// Read config value for this one
|
|
|
|
|
if(g_Config.bNunchuckConnected || g_Config.bClassicControllerConnected)
|
|
|
|
|
pStatus->extension = 1;
|
|
|
|
|
else
|
|
|
|
|
pStatus->extension = 0;
|
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
else
|
2009-02-07 03:16:41 +00:00
|
|
|
|
{
|
|
|
|
|
if(Extension)
|
|
|
|
|
pStatus->extension = 1;
|
|
|
|
|
else
|
|
|
|
|
pStatus->extension = 0;
|
|
|
|
|
}
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " Extension: %x", pStatus->extension);
|
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, " SendStatusReport()");
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Flags: 0x%02x", pStatus->padding1[2]);
|
|
|
|
|
DEBUG_LOG(WII_IPC_WIIMOTE, " Battery: %d", pStatus->battery);
|
2009-01-07 02:59:19 +00:00
|
|
|
|
|
|
|
|
|
g_WiimoteInitialize.pWiimoteInput(_channelID, DataFrame, Offset);
|
2009-03-02 01:49:16 +00:00
|
|
|
|
INFO_LOG(WII_IPC_WIIMOTE, "=================================================");
|
2009-02-01 13:01:50 +00:00
|
|
|
|
|
|
|
|
|
// Debugging
|
2009-02-04 06:40:05 +00:00
|
|
|
|
ReadDebugging(true, DataFrame, Offset);
|
2008-12-08 05:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-07 02:59:19 +00:00
|
|
|
|
} // WiiMoteEmu
|