2010-04-13 05:15:38 +00:00
|
|
|
#ifndef _CONEMU_WIIMOTE_H_
|
|
|
|
#define _CONEMU_WIIMOTE_H_
|
|
|
|
|
2010-04-29 18:51:04 +00:00
|
|
|
//#define USE_WIIMOTE_EMU_SPEAKER
|
|
|
|
|
|
|
|
// just used to get the OpenAL includes :p
|
|
|
|
//#include <OpenALStream.h>
|
|
|
|
|
2010-04-13 05:15:38 +00:00
|
|
|
#include <ControllerEmu.h>
|
|
|
|
|
|
|
|
#include "WiimoteHid.h"
|
|
|
|
#include "Encryption.h"
|
|
|
|
|
|
|
|
#include <vector>
|
2010-04-22 07:11:49 +00:00
|
|
|
#include <queue>
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
#define PI 3.14159265358979323846
|
|
|
|
|
|
|
|
// Registry sizes
|
|
|
|
#define WIIMOTE_EEPROM_SIZE (16*1024)
|
2010-04-24 00:44:10 +00:00
|
|
|
#define WIIMOTE_EEPROM_FREE_SIZE 0x1700
|
2010-04-13 05:15:38 +00:00
|
|
|
#define WIIMOTE_REG_SPEAKER_SIZE 10
|
|
|
|
#define WIIMOTE_REG_EXT_SIZE 0x100
|
|
|
|
#define WIIMOTE_REG_IR_SIZE 0x34
|
|
|
|
|
2010-04-22 07:11:49 +00:00
|
|
|
extern SWiimoteInitialize g_WiimoteInitialize;
|
|
|
|
|
2010-04-13 05:15:38 +00:00
|
|
|
namespace WiimoteEmu
|
|
|
|
{
|
|
|
|
|
2010-04-29 18:51:04 +00:00
|
|
|
void EmulateShake( u8* const accel_data
|
|
|
|
, ControllerEmu::Buttons* const buttons_group
|
|
|
|
, unsigned int* const shake_step );
|
|
|
|
|
|
|
|
void EmulateTilt( wm_accel* const accel
|
|
|
|
, ControllerEmu::Tilt* const tilt_group
|
|
|
|
, const accel_cal* const cal
|
|
|
|
, bool focus, bool sideways = false, bool upright = false);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
class Wiimote : public ControllerEmu
|
|
|
|
{
|
|
|
|
public:
|
2010-04-24 00:44:10 +00:00
|
|
|
Wiimote( const unsigned int index );
|
|
|
|
std::string GetName() const;
|
|
|
|
|
|
|
|
void Update();
|
|
|
|
void InterruptChannel(const u16 _channelID, const void* _pData, u32 _Size);
|
|
|
|
void ControlChannel(const u16 _channelID, const void* _pData, u32 _Size);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2010-04-24 00:44:10 +00:00
|
|
|
private:
|
2010-04-22 07:11:49 +00:00
|
|
|
struct ReadRequest
|
|
|
|
{
|
|
|
|
unsigned int address, size, position;
|
|
|
|
u8* data;
|
|
|
|
};
|
|
|
|
|
2010-04-13 05:15:38 +00:00
|
|
|
void Reset();
|
|
|
|
|
2010-04-22 07:11:49 +00:00
|
|
|
void ReportMode(const u16 _channelID, wm_report_mode* dr);
|
|
|
|
void HidOutputReport(const u16 _channelID, wm_report* sr);
|
|
|
|
void SendAck(const u16 _channelID, u8 _reportID);
|
|
|
|
void RequestStatus(const u16 _channelID, wm_request_status* rs = NULL);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2010-04-22 07:11:49 +00:00
|
|
|
void WriteData(const u16 _channelID, wm_write_data* wd);
|
|
|
|
void ReadData(const u16 _channelID, wm_read_data* rd);
|
|
|
|
void SendReadDataReply(const u16 _channelID, ReadRequest& _request);
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2010-04-29 18:51:04 +00:00
|
|
|
#ifdef USE_WIIMOTE_EMU_SPEAKER
|
|
|
|
void SpeakerData(wm_speaker_data* sd);
|
|
|
|
#endif
|
|
|
|
|
2010-04-24 00:44:10 +00:00
|
|
|
// control groups
|
2010-04-13 05:15:38 +00:00
|
|
|
Buttons* m_buttons;
|
|
|
|
Buttons* m_dpad;
|
|
|
|
Buttons* m_shake;
|
2010-04-22 07:11:49 +00:00
|
|
|
Cursor* m_ir;
|
2010-04-13 05:15:38 +00:00
|
|
|
Tilt* m_tilt;
|
|
|
|
Force* m_swing;
|
|
|
|
ControlGroup* m_rumble;
|
|
|
|
Extension* m_extension;
|
2010-04-24 00:44:10 +00:00
|
|
|
ControlGroup* m_options;
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2010-04-24 00:44:10 +00:00
|
|
|
// wiimote index, 0-3
|
2010-04-13 05:15:38 +00:00
|
|
|
const unsigned int m_index;
|
|
|
|
|
2010-04-22 07:11:49 +00:00
|
|
|
bool m_rumble_on;
|
2010-04-24 00:44:10 +00:00
|
|
|
bool m_speaker_mute;
|
2010-04-22 07:11:49 +00:00
|
|
|
|
2010-04-13 05:15:38 +00:00
|
|
|
bool m_reporting_auto;
|
|
|
|
unsigned int m_reporting_mode;
|
|
|
|
unsigned int m_reporting_channel;
|
|
|
|
|
2010-04-29 18:51:04 +00:00
|
|
|
// hax
|
|
|
|
unsigned int m_skip_update;
|
|
|
|
|
|
|
|
unsigned int m_shake_step[3];
|
|
|
|
unsigned int m_swing_step[3];
|
2010-04-22 07:11:49 +00:00
|
|
|
|
2010-04-13 05:15:38 +00:00
|
|
|
wm_status_report m_status;
|
|
|
|
|
|
|
|
class Register : public std::map< size_t, std::vector<u8> >
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Write( size_t address, void* src, size_t length );
|
|
|
|
void Read( size_t address, void* dst, size_t length );
|
|
|
|
|
|
|
|
} m_register;
|
|
|
|
|
2010-04-22 07:11:49 +00:00
|
|
|
// read data request queue
|
|
|
|
// maybe it isn't actualy a queue
|
|
|
|
// maybe read requests cancel any current requests
|
|
|
|
std::queue< ReadRequest > m_read_requests;
|
|
|
|
|
2010-04-29 18:51:04 +00:00
|
|
|
#ifdef USE_WIIMOTE_EMU_SPEAKER
|
|
|
|
// speaker stuff
|
|
|
|
struct SoundBuffer
|
|
|
|
{
|
|
|
|
s16* samples;
|
|
|
|
ALuint buffer;
|
|
|
|
};
|
|
|
|
std::queue<SoundBuffer> m_audio_buffers;
|
|
|
|
ALuint m_audio_source;
|
|
|
|
ADPCMChannelStatus m_channel_status;
|
|
|
|
#endif
|
2010-04-13 05:15:38 +00:00
|
|
|
|
2010-04-24 00:44:10 +00:00
|
|
|
u8 m_eeprom[WIIMOTE_EEPROM_SIZE];
|
2010-04-29 18:51:04 +00:00
|
|
|
|
2010-04-24 00:44:10 +00:00
|
|
|
u8* m_reg_motion_plus;
|
2010-04-29 18:51:04 +00:00
|
|
|
|
|
|
|
struct IrReg
|
|
|
|
{
|
|
|
|
u8 unknown1[0x33];
|
|
|
|
u8 mode;
|
|
|
|
|
|
|
|
} *m_reg_ir;
|
|
|
|
|
|
|
|
struct ExtensionReg
|
|
|
|
{
|
|
|
|
u8 unknown1[0x08];
|
|
|
|
|
|
|
|
// address 0x08
|
|
|
|
u8 controller_data[0x06];
|
|
|
|
u8 unknown2[0x12];
|
|
|
|
|
|
|
|
// address 0x20
|
|
|
|
u8 calibration[0x10];
|
|
|
|
u8 unknown3[0x10];
|
|
|
|
|
|
|
|
// address 0x40
|
|
|
|
u8 encryption_key[0x10];
|
|
|
|
u8 unknown4[0xA0];
|
|
|
|
|
|
|
|
// address 0xF0
|
|
|
|
u8 encryption;
|
|
|
|
u8 unknown5[0x9];
|
|
|
|
|
|
|
|
// address 0xFA
|
|
|
|
u8 constant_id[6];
|
|
|
|
|
|
|
|
} *m_reg_ext;
|
|
|
|
|
|
|
|
struct SpeakerReg
|
2010-04-24 00:44:10 +00:00
|
|
|
{
|
2010-04-29 18:51:04 +00:00
|
|
|
u16 unknown;
|
2010-04-24 00:44:10 +00:00
|
|
|
u8 format;
|
|
|
|
u16 sample_rate;
|
|
|
|
u8 volume;
|
2010-04-29 18:51:04 +00:00
|
|
|
u8 unk[4];
|
2010-04-24 00:44:10 +00:00
|
|
|
|
|
|
|
} *m_reg_speaker;
|
2010-04-13 05:15:38 +00:00
|
|
|
|
|
|
|
wiimote_key m_ext_key;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|