Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Wiimote emu motion plus #7589

Closed

Conversation

jordan-woyak
Copy link
Member

Cleanup Wiimote emu code to more closely simulate the real thing.
Simulate Motion Plus attachment.
Eliminated some dead code.

Copy link
Member

@BhaaLseN BhaaLseN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay for cleanup!

// hybrid Wiimote stuff
if (WIIMOTE_SRC_REAL & g_wiimote_sources[m_index] && (m_extension->switch_extension <= 0))
{
using namespace WiimoteReal;

This comment was marked as off-topic.

Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp Outdated Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/Speaker.cpp Outdated Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/Speaker.cpp Outdated Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h Outdated Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp Outdated Show resolved Hide resolved
@@ -202,53 +209,54 @@ void Wiimote::HandleExtensionSwap()

void Wiimote::RequestStatus(const wm_request_status* const rs)
{
HandleExtensionSwap();
INFO_LOG(WIIMOTE, "Wiimote::RequestStatus");

This comment was marked as off-topic.

This comment was marked as off-topic.


// ignore the 0x010000 bit
address &= ~0x010000;
INFO_LOG(WIIMOTE, "Wiimote::WriteData: 0x%02x @ 0x%02x @ 0x%02x (%d)", wd->space, wd->slave_address, address, wd->size);

This comment was marked as off-topic.

This comment was marked as off-topic.

Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp Outdated Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp Outdated Show resolved Hide resolved
@@ -620,4 +478,4 @@ void Wiimote::RealState()
g_wiimotes[m_index]->EnableDataReporting(m_reporting_mode);

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -135,21 +135,37 @@ void Pause()
// An L2CAP packet is passed from the Core to the Wiimote on the HID CONTROL channel.
void ControlChannel(int number, u16 channel_id, const void* data, u32 size)

This comment was marked as off-topic.

Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp Show resolved Hide resolved
Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h Show resolved Hide resolved
class I2CBus
{
public:
void AddSlave(I2CSlave* slave) { m_slaves.emplace_back(slave); }

This comment was marked as off-topic.

This comment was marked as off-topic.

Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp Outdated Show resolved Hide resolved
static const u8 c1[16] = {0x78, 0xd9, 0x78, 0x38, 0x77, 0x9d, 0x2f, 0x0c,
0xcf, 0xf0, 0x31, 0xad, 0xc8, 0x0b, 0x5e, 0x39};
static const u8 c2[16] = {0x6f, 0x81, 0x7b, 0x89, 0x78, 0x51, 0x33, 0x60,
0xc9, 0xf5, 0x37, 0xc1, 0x2d, 0xe9, 0x15, 0x8d};

This comment was marked as off-topic.

This comment was marked as off-topic.

// Address 0x58
m_i2c_bus.AddSlave(&m_camera_logic);

// TODO: only add to bus when enabled

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

{
++times_updated_since_activation;

// TODO: wtf is this value actually..

This comment was marked as off-topic.

This comment was marked as off-topic.

// For some reason the first read seems to have garbage data
// is_mp_data and extension_connected are set, but the data is junk
// it does seem to have some sort of pattern though, byte 5 is always 2
// something like: d5, b0, 4e, 6e, fc, 2

This comment was marked as off-topic.

This comment was marked as off-topic.

Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp Show resolved Hide resolved
return result;

// It seems a write of any value triggers deactivation.
if (0xf0 == addr)

This comment was marked as off-topic.

This comment was marked as off-topic.

auto const result = RawWrite(&reg_data, addr, count, data_in);

// It seems a write of any value triggers activation.
if (0xfe == addr)

This comment was marked as off-topic.

This comment was marked as off-topic.

@Warepire
Copy link

Reading through this code I am missing the handing of the read/write bit in i2c addressing. Am I missing the relevant code blocks or is the addressing handling wrong?

If necessary, this document describes the i2c bus: https://www.nxp.com/docs/en/user-guide/UM10204.pdf

@jordan-woyak
Copy link
Member Author

The read/write bit (lsb of slave_address) is ignored by a real wiimote. I chop it off in Read/WriteData calls (>> 1) and the high level i2c bus simulation just makes use of the 7 bit address.

@Warepire
Copy link

Ah, that makes sense.

Would it be meaningful to name the operation using a small constexpr function?

@jordan-woyak jordan-woyak deleted the wiimote-emu-motion-plus branch February 3, 2019 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants