mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
@@ -8,19 +8,6 @@ namespace WiimoteEmu
|
||||
{
|
||||
|
||||
static const u8 nunchuk_id[] = { 0x00, 0x00, 0xa4, 0x20, 0x00, 0x00 };
|
||||
/* Default calibration for the nunchuk. 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 nunchuk_calibration[] =
|
||||
{
|
||||
0x80, 0x80, 0x80, 0x00, // accelerometer x, y, z neutral
|
||||
0xb3, 0xb3, 0xb3, 0x00, // x, y, z g-force values
|
||||
|
||||
// 0x80 = analog stick x and y axis center
|
||||
0xff, 0x00, 0x80,
|
||||
0xff, 0x00, 0x80,
|
||||
0xec, 0x41 // checksum on the last two bytes
|
||||
};
|
||||
|
||||
static const u8 nunchuk_button_bitmasks[] =
|
||||
{
|
||||
@@ -50,9 +37,6 @@ Nunchuk::Nunchuk(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"),
|
||||
m_shake->controls.emplace_back(new ControlGroup::Input("Y"));
|
||||
m_shake->controls.emplace_back(new ControlGroup::Input("Z"));
|
||||
|
||||
// set up register
|
||||
// calibration
|
||||
memcpy(&calibration, nunchuk_calibration, sizeof(nunchuk_calibration));
|
||||
// id
|
||||
memcpy(&id, nunchuk_id, sizeof(nunchuk_id));
|
||||
|
||||
@@ -66,35 +50,26 @@ void Nunchuk::GetState(u8* const data)
|
||||
ncdata->bt.hex = 0;
|
||||
|
||||
// stick
|
||||
double state[2];
|
||||
m_stick->GetState(&state[0], &state[1]);
|
||||
double jx, jy;
|
||||
m_stick->GetState(&jx, &jy);
|
||||
|
||||
nu_cal &cal = *(nu_cal*)®.calibration;
|
||||
nu_js cal_js[2];
|
||||
cal_js[0] = cal.jx;
|
||||
cal_js[1] = cal.jy;
|
||||
ncdata->jx = u8(STICK_CENTER + jx * STICK_RADIUS);
|
||||
ncdata->jy = u8(STICK_CENTER + jy * STICK_RADIUS);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
// Some terribly coded games check whether to move with a check like
|
||||
//
|
||||
// if (x != 0 && y != 0)
|
||||
// do_movement(x, y);
|
||||
//
|
||||
// With keyboard controls, these games break if you simply hit
|
||||
// of the axes. Adjust this if you're hitting one of the axes so that
|
||||
// we slightly tweak the other axis.
|
||||
if (ncdata->jx != STICK_CENTER || ncdata->jy != STICK_CENTER)
|
||||
{
|
||||
double &s = state[i];
|
||||
nu_js c = cal_js[i];
|
||||
if (s < 0)
|
||||
s = s * abs(c.min - c.center) + c.center;
|
||||
else if (s > 0)
|
||||
s = s * abs(c.max - c.center) + c.center;
|
||||
else
|
||||
s = c.center;
|
||||
}
|
||||
|
||||
ncdata->jx = u8(trim(state[0]));
|
||||
ncdata->jy = u8(trim(state[1]));
|
||||
|
||||
if (ncdata->jx != cal.jx.center || ncdata->jy != cal.jy.center)
|
||||
{
|
||||
if (ncdata->jy == cal.jy.center)
|
||||
ncdata->jy = cal.jy.center + 1;
|
||||
if (ncdata->jx == cal.jx.center)
|
||||
ncdata->jx = cal.jx.center + 1;
|
||||
if (ncdata->jx == STICK_CENTER)
|
||||
++ncdata->jx;
|
||||
if (ncdata->jy == STICK_CENTER)
|
||||
++ncdata->jy;
|
||||
}
|
||||
|
||||
AccelData accel;
|
||||
@@ -112,25 +87,23 @@ void Nunchuk::GetState(u8* const data)
|
||||
// flip the button bits :/
|
||||
ncdata->bt.hex ^= 0x03;
|
||||
|
||||
accel_cal& calib = *(accel_cal*)®.calibration;
|
||||
u16 accel_x = (u16)(accel.x * ACCEL_RANGE + ACCEL_ZERO_G);
|
||||
u16 accel_y = (u16)(accel.y * ACCEL_RANGE + ACCEL_ZERO_G);
|
||||
u16 accel_z = (u16)(accel.z * ACCEL_RANGE + ACCEL_ZERO_G);
|
||||
|
||||
u16 x = (u16)(accel.x * (calib.one_g.x - calib.zero_g.x) + calib.zero_g.x);
|
||||
u16 y = (u16)(accel.y * (calib.one_g.y - calib.zero_g.y) + calib.zero_g.y);
|
||||
u16 z = (u16)(accel.z * (calib.one_g.z - calib.zero_g.z) + calib.zero_g.z);
|
||||
if (accel_x > 1024)
|
||||
accel_x = 1024;
|
||||
if (accel_y > 1024)
|
||||
accel_y = 1024;
|
||||
if (accel_z > 1024)
|
||||
accel_z = 1024;
|
||||
|
||||
if (x > 1024)
|
||||
x = 1024;
|
||||
if (y > 1024)
|
||||
y = 1024;
|
||||
if (z > 1024)
|
||||
z = 1024;
|
||||
|
||||
ncdata->ax = x & 0xFF;
|
||||
ncdata->ay = y & 0xFF;
|
||||
ncdata->az = z & 0xFF;
|
||||
ncdata->passthrough_data.acc_x_lsb = x >> 8 & 0x3;
|
||||
ncdata->passthrough_data.acc_y_lsb = y >> 8 & 0x3;
|
||||
ncdata->passthrough_data.acc_z_lsb = z >> 8 & 0x3;
|
||||
ncdata->ax = accel_x & 0xFF;
|
||||
ncdata->ay = accel_y & 0xFF;
|
||||
ncdata->az = accel_z & 0xFF;
|
||||
ncdata->passthrough_data.acc_x_lsb = accel_x >> 8 & 0x3;
|
||||
ncdata->passthrough_data.acc_y_lsb = accel_y >> 8 & 0x3;
|
||||
ncdata->passthrough_data.acc_z_lsb = accel_z >> 8 & 0x3;
|
||||
}
|
||||
|
||||
void Nunchuk::LoadDefaults(const ControllerInterface& ciface)
|
||||
|
||||
@@ -22,6 +22,19 @@ public:
|
||||
BUTTON_Z = 0x01,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ACCEL_ZERO_G = 0x80,
|
||||
ACCEL_ONE_G = 0xB3,
|
||||
ACCEL_RANGE = (ACCEL_ONE_G - ACCEL_ZERO_G),
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
STICK_CENTER = 0x80,
|
||||
STICK_RADIUS = 0x7F,
|
||||
};
|
||||
|
||||
void LoadDefaults(const ControllerInterface& ciface) override;
|
||||
|
||||
private:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -39,10 +39,6 @@ static const u8 eeprom_data_0[] = {
|
||||
// assuming last 2 bytes are checksum
|
||||
0xA1, 0xAA, 0x8B, 0x99, 0xAE, 0x9E, 0x78, 0x30, 0xA7, /*0x74, 0xD3,*/ 0x00, 0x00, // messing up the checksum on purpose
|
||||
0xA1, 0xAA, 0x8B, 0x99, 0xAE, 0x9E, 0x78, 0x30, 0xA7, /*0x74, 0xD3,*/ 0x00, 0x00,
|
||||
// Accelerometer
|
||||
// 0g x,y,z, 1g x,y,z, idk, last byte is a checksum
|
||||
0x80, 0x80, 0x80, 0x00, 0x9A, 0x9A, 0x9A, 0x00, 0x40, 0xE3,
|
||||
0x80, 0x80, 0x80, 0x00, 0x9A, 0x9A, 0x9A, 0x00, 0x40, 0xE3,
|
||||
};
|
||||
|
||||
static const u8 motion_plus_id[] = { 0x00, 0x00, 0xA6, 0x20, 0x00, 0x05 };
|
||||
@@ -395,11 +391,10 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf)
|
||||
|
||||
wm_accel& accel = *(wm_accel*)(data + rptf.accel);
|
||||
wm_buttons& core = *(wm_buttons*)(data + rptf.core);
|
||||
accel_cal& calib = *(accel_cal*)&m_eeprom[0x16];
|
||||
|
||||
u16 x = (u16)(m_accel.x * (calib.one_g.x - calib.zero_g.x) + calib.zero_g.x);
|
||||
u16 y = (u16)(m_accel.y * (calib.one_g.y - calib.zero_g.y) + calib.zero_g.y);
|
||||
u16 z = (u16)(m_accel.z * (calib.one_g.z - calib.zero_g.z) + calib.zero_g.z);
|
||||
u16 x = (u16)(m_accel.x * ACCEL_RANGE + ACCEL_ZERO_G);
|
||||
u16 y = (u16)(m_accel.y * ACCEL_RANGE + ACCEL_ZERO_G);
|
||||
u16 z = (u16)(m_accel.z * ACCEL_RANGE + ACCEL_ZERO_G);
|
||||
|
||||
if (x > 1024)
|
||||
x = 1024;
|
||||
@@ -756,7 +751,6 @@ void Wiimote::Update()
|
||||
// send data report
|
||||
if (rptf_size)
|
||||
{
|
||||
WiimoteEmu::Spy(this, data, rptf_size);
|
||||
Core::Callback_WiimoteInterruptChannel(m_index, m_reporting_channel, data, rptf_size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,6 @@ inline double trim(double a)
|
||||
class Wiimote : public ControllerEmu
|
||||
{
|
||||
friend class WiimoteReal::Wiimote;
|
||||
friend void Spy(Wiimote* wm_, const void* data_, size_t size_);
|
||||
public:
|
||||
|
||||
enum
|
||||
@@ -107,6 +106,13 @@ public:
|
||||
BUTTON_HOME = 0x8000,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ACCEL_ZERO_G = 0x80,
|
||||
ACCEL_ONE_G = 0x9A,
|
||||
ACCEL_RANGE = (ACCEL_ONE_G - ACCEL_ZERO_G),
|
||||
};
|
||||
|
||||
Wiimote(const unsigned int index);
|
||||
std::string GetName() const override;
|
||||
|
||||
@@ -234,6 +240,4 @@ private:
|
||||
#pragma pack(pop)
|
||||
};
|
||||
|
||||
void Spy(Wiimote* wm_, const void* data_, size_t size_);
|
||||
|
||||
}
|
||||
|
||||
@@ -495,64 +495,4 @@ struct wm_speaker_data
|
||||
|
||||
// Custom structs
|
||||
|
||||
/**
|
||||
* @struct accel_t
|
||||
* @brief Accelerometer struct. For any device with an accelerometer.
|
||||
*/
|
||||
struct accel_cal
|
||||
{
|
||||
struct
|
||||
{
|
||||
u8 x, y, z;
|
||||
u8 xlo : 2;
|
||||
u8 ylo : 2;
|
||||
u8 zlo : 2;
|
||||
} zero_g;
|
||||
|
||||
struct
|
||||
{
|
||||
u8 x, y, z;
|
||||
u8 xlo : 2;
|
||||
u8 ylo : 2;
|
||||
u8 zlo : 2;
|
||||
} one_g;
|
||||
};
|
||||
|
||||
struct nu_js
|
||||
{
|
||||
u8 max, min, center;
|
||||
};
|
||||
|
||||
struct cc_trigger
|
||||
{
|
||||
u8 neutral;
|
||||
};
|
||||
|
||||
struct nu_cal
|
||||
{
|
||||
wm_accel cal_zero; // zero calibration
|
||||
u8 pad1;
|
||||
wm_accel cal_g; // g size
|
||||
u8 pad2;
|
||||
nu_js jx;
|
||||
nu_js jy;
|
||||
u8 sum[2];
|
||||
};
|
||||
|
||||
struct cc_cal
|
||||
{
|
||||
nu_js Lx;
|
||||
nu_js Ly;
|
||||
nu_js Rx;
|
||||
nu_js Ry;
|
||||
cc_trigger Tl;
|
||||
cc_trigger Tr;
|
||||
};
|
||||
|
||||
struct gh3_cal
|
||||
{
|
||||
nu_js Lx;
|
||||
nu_js Ly;
|
||||
};
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
@@ -677,8 +677,6 @@ int _IORead(HANDLE &dev_handle, OVERLAPPED &hid_overlap_read, u8* buf, int index
|
||||
}
|
||||
}
|
||||
|
||||
WiimoteEmu::Spy(nullptr, buf, bytes + 1);
|
||||
|
||||
return bytes + 1;
|
||||
}
|
||||
|
||||
@@ -699,8 +697,6 @@ int WiimoteWindows::IORead(u8* buf)
|
||||
|
||||
int _IOWrite(HANDLE &dev_handle, OVERLAPPED &hid_overlap_write, enum win_bt_stack_t &stack, const u8* buf, size_t len, DWORD* written)
|
||||
{
|
||||
WiimoteEmu::Spy(nullptr, buf, len);
|
||||
|
||||
switch (stack)
|
||||
{
|
||||
case MSBT_STACK_UNKNOWN:
|
||||
|
||||
Reference in New Issue
Block a user