diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 5989d47399..ef5c3e9d1e 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -143,6 +143,7 @@ set(SRCS ActionReplay.cpp IPC_HLE/WII_Socket.cpp IPC_HLE/WII_IPC_HLE_Device_net.cpp IPC_HLE/WII_IPC_HLE_Device_net_ssl.cpp + IPC_HLE/WII_IPC_HLE_Device_stm.cpp IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp IPC_HLE/WII_IPC_HLE_Device_usb.cpp IPC_HLE/WII_IPC_HLE_Device_usb_kbd.cpp diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index e89a1d6a41..f0a54a74f3 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -183,6 +183,7 @@ + @@ -386,8 +387,8 @@ - + @@ -480,4 +481,4 @@ - \ No newline at end of file + diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index bc12b068ac..082b302901 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -585,6 +585,9 @@ IPC HLE %28IOS/Starlet%29\SDIO - SD Card + + IPC HLE %28IOS/Starlet%29 + IPC HLE %28IOS/Starlet%29\USB @@ -1247,4 +1250,4 @@ - \ No newline at end of file + diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_stm.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_stm.cpp new file mode 100644 index 0000000000..7b801b5c1c --- /dev/null +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_stm.cpp @@ -0,0 +1,134 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/IPC_HLE/WII_IPC_HLE_Device_stm.h" + +IPCCommandResult CWII_IPC_HLE_Device_stm_immediate::Open(u32 _CommandAddress, u32 _Mode) +{ + INFO_LOG(WII_IPC_STM, "STM immediate: Open"); + Memory::Write_U32(GetDeviceID(), _CommandAddress + 4); + m_Active = true; + return GetDefaultReply(); +} + +IPCCommandResult CWII_IPC_HLE_Device_stm_immediate::Close(u32 _CommandAddress, bool _bForce) +{ + INFO_LOG(WII_IPC_STM, "STM immediate: Close"); + if (!_bForce) + Memory::Write_U32(0, _CommandAddress + 4); + m_Active = false; + return GetDefaultReply(); +} + +IPCCommandResult CWII_IPC_HLE_Device_stm_immediate::IOCtl(u32 _CommandAddress) +{ + u32 Parameter = Memory::Read_U32(_CommandAddress + 0x0C); + u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10); + u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14); + u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18); + u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C); + + // Prepare the out buffer(s) with zeroes as a safety precaution + // to avoid returning bad values + Memory::Memset(BufferOut, 0, BufferOutSize); + u32 ReturnValue = 0; + + switch (Parameter) + { + case IOCTL_STM_RELEASE_EH: + INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); + INFO_LOG(WII_IPC_STM, " IOCTL_STM_RELEASE_EH"); + break; + + case IOCTL_STM_HOTRESET: + INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); + INFO_LOG(WII_IPC_STM, " IOCTL_STM_HOTRESET"); + break; + + case IOCTL_STM_VIDIMMING: // (Input: 20 bytes, Output: 20 bytes) + INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); + INFO_LOG(WII_IPC_STM, " IOCTL_STM_VIDIMMING"); + // DumpCommands(BufferIn, BufferInSize / 4, LogTypes::WII_IPC_STM); + // Memory::Write_U32(1, BufferOut); + // ReturnValue = 1; + break; + + case IOCTL_STM_LEDMODE: // (Input: 20 bytes, Output: 20 bytes) + INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); + INFO_LOG(WII_IPC_STM, " IOCTL_STM_LEDMODE"); + break; + + default: + { + _dbg_assert_msg_(WII_IPC_STM, 0, "CWII_IPC_HLE_Device_stm_immediate: 0x%x", Parameter); + + INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); + DEBUG_LOG(WII_IPC_STM, " Parameter: 0x%x", Parameter); + DEBUG_LOG(WII_IPC_STM, " InBuffer: 0x%08x", BufferIn); + DEBUG_LOG(WII_IPC_STM, " InBufferSize: 0x%08x", BufferInSize); + DEBUG_LOG(WII_IPC_STM, " OutBuffer: 0x%08x", BufferOut); + DEBUG_LOG(WII_IPC_STM, " OutBufferSize: 0x%08x", BufferOutSize); + } + break; + } + + // Write return value to the IPC call + Memory::Write_U32(ReturnValue, _CommandAddress + 0x4); + return GetDefaultReply(); +} + +IPCCommandResult CWII_IPC_HLE_Device_stm_eventhook::Open(u32 _CommandAddress, u32 _Mode) +{ + Memory::Write_U32(GetDeviceID(), _CommandAddress + 4); + m_Active = true; + return GetDefaultReply(); +} + +IPCCommandResult CWII_IPC_HLE_Device_stm_eventhook::Close(u32 _CommandAddress, bool _bForce) +{ + m_EventHookAddress = 0; + + INFO_LOG(WII_IPC_STM, "STM eventhook: Close"); + if (!_bForce) + Memory::Write_U32(0, _CommandAddress + 4); + m_Active = false; + return GetDefaultReply(); +} + +IPCCommandResult CWII_IPC_HLE_Device_stm_eventhook::IOCtl(u32 _CommandAddress) +{ + u32 Parameter = Memory::Read_U32(_CommandAddress + 0x0C); + if (Parameter != IOCTL_STM_EVENTHOOK) + { + ERROR_LOG(WII_IPC_STM, "Bad IOCtl in CWII_IPC_HLE_Device_stm_eventhook"); + Memory::Write_U32(FS_EINVAL, _CommandAddress + 4); + return GetDefaultReply(); + } + + // IOCTL_STM_EVENTHOOK waits until the reset button or power button + // is pressed. + m_EventHookAddress = _CommandAddress; + return GetNoReply(); +} + +void CWII_IPC_HLE_Device_stm_eventhook::ResetButton() +{ + if (!m_Active || m_EventHookAddress == 0) + { + // If the device isn't open, ignore the button press. + return; + } + + // The reset button returns STM_EVENT_RESET. + u32 BufferOut = Memory::Read_U32(m_EventHookAddress + 0x18); + Memory::Write_U32(STM_EVENT_RESET, BufferOut); + + // Fill in command buffer. + Memory::Write_U32(FS_SUCCESS, m_EventHookAddress + 4); + Memory::Write_U32(IPC_REP_ASYNC, m_EventHookAddress); + Memory::Write_U32(IPC_CMD_IOCTL, m_EventHookAddress + 8); + + // Generate a reply to the IPC command. + WII_IPC_HLE_Interface::EnqueueReply(m_EventHookAddress); +} diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_stm.h b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_stm.h index b8c78b2776..10f5ed6000 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_stm.h +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_stm.h @@ -4,7 +4,6 @@ #pragma once -#include #include "Core/IPC_HLE/WII_IPC_HLE_Device.h" enum @@ -40,80 +39,10 @@ public: { } - virtual ~CWII_IPC_HLE_Device_stm_immediate() {} - IPCCommandResult Open(u32 _CommandAddress, u32 _Mode) override - { - INFO_LOG(WII_IPC_STM, "STM immediate: Open"); - Memory::Write_U32(GetDeviceID(), _CommandAddress + 4); - m_Active = true; - return GetDefaultReply(); - } - - IPCCommandResult Close(u32 _CommandAddress, bool _bForce) override - { - INFO_LOG(WII_IPC_STM, "STM immediate: Close"); - if (!_bForce) - Memory::Write_U32(0, _CommandAddress + 4); - m_Active = false; - return GetDefaultReply(); - } - - IPCCommandResult IOCtl(u32 _CommandAddress) override - { - u32 Parameter = Memory::Read_U32(_CommandAddress + 0x0C); - u32 BufferIn = Memory::Read_U32(_CommandAddress + 0x10); - u32 BufferInSize = Memory::Read_U32(_CommandAddress + 0x14); - u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18); - u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C); - - // Prepare the out buffer(s) with zeroes as a safety precaution - // to avoid returning bad values - Memory::Memset(BufferOut, 0, BufferOutSize); - u32 ReturnValue = 0; - - switch (Parameter) - { - case IOCTL_STM_RELEASE_EH: - INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); - INFO_LOG(WII_IPC_STM, " IOCTL_STM_RELEASE_EH"); - break; - - case IOCTL_STM_HOTRESET: - INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); - INFO_LOG(WII_IPC_STM, " IOCTL_STM_HOTRESET"); - break; - - case IOCTL_STM_VIDIMMING: // (Input: 20 bytes, Output: 20 bytes) - INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); - INFO_LOG(WII_IPC_STM, " IOCTL_STM_VIDIMMING"); - // DumpCommands(BufferIn, BufferInSize / 4, LogTypes::WII_IPC_STM); - // Memory::Write_U32(1, BufferOut); - // ReturnValue = 1; - break; - - case IOCTL_STM_LEDMODE: // (Input: 20 bytes, Output: 20 bytes) - INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); - INFO_LOG(WII_IPC_STM, " IOCTL_STM_LEDMODE"); - break; - - default: - { - _dbg_assert_msg_(WII_IPC_STM, 0, "CWII_IPC_HLE_Device_stm_immediate: 0x%x", Parameter); - - INFO_LOG(WII_IPC_STM, "%s - IOCtl:", GetDeviceName().c_str()); - DEBUG_LOG(WII_IPC_STM, " Parameter: 0x%x", Parameter); - DEBUG_LOG(WII_IPC_STM, " InBuffer: 0x%08x", BufferIn); - DEBUG_LOG(WII_IPC_STM, " InBufferSize: 0x%08x", BufferInSize); - DEBUG_LOG(WII_IPC_STM, " OutBuffer: 0x%08x", BufferOut); - DEBUG_LOG(WII_IPC_STM, " OutBufferSize: 0x%08x", BufferOutSize); - } - break; - } - - // Write return value to the IPC call - Memory::Write_U32(ReturnValue, _CommandAddress + 0x4); - return GetDefaultReply(); - } + ~CWII_IPC_HLE_Device_stm_immediate() override = default; + IPCCommandResult Open(u32 _CommandAddress, u32 _Mode) override; + IPCCommandResult Close(u32 _CommandAddress, bool _bForce) override; + IPCCommandResult IOCtl(u32 _CommandAddress) override; }; // The /dev/stm/eventhook @@ -125,61 +54,12 @@ public: { } - virtual ~CWII_IPC_HLE_Device_stm_eventhook() {} - IPCCommandResult Open(u32 _CommandAddress, u32 _Mode) override - { - Memory::Write_U32(GetDeviceID(), _CommandAddress + 4); - m_Active = true; - return GetDefaultReply(); - } + ~CWII_IPC_HLE_Device_stm_eventhook() override = default; + IPCCommandResult Open(u32 _CommandAddress, u32 _Mode) override; + IPCCommandResult Close(u32 _CommandAddress, bool _bForce) override; + IPCCommandResult IOCtl(u32 _CommandAddress) override; - IPCCommandResult Close(u32 _CommandAddress, bool _bForce) override - { - m_EventHookAddress = 0; - - INFO_LOG(WII_IPC_STM, "STM eventhook: Close"); - if (!_bForce) - Memory::Write_U32(0, _CommandAddress + 4); - m_Active = false; - return GetDefaultReply(); - } - - IPCCommandResult IOCtl(u32 _CommandAddress) override - { - u32 Parameter = Memory::Read_U32(_CommandAddress + 0x0C); - if (Parameter != IOCTL_STM_EVENTHOOK) - { - ERROR_LOG(WII_IPC_STM, "Bad IOCtl in CWII_IPC_HLE_Device_stm_eventhook"); - Memory::Write_U32(FS_EINVAL, _CommandAddress + 4); - return GetDefaultReply(); - } - - // IOCTL_STM_EVENTHOOK waits until the reset button or power button - // is pressed. - m_EventHookAddress = _CommandAddress; - return GetNoReply(); - } - - void ResetButton() - { - if (!m_Active || m_EventHookAddress == 0) - { - // If the device isn't open, ignore the button press. - return; - } - - // The reset button returns STM_EVENT_RESET. - u32 BufferOut = Memory::Read_U32(m_EventHookAddress + 0x18); - Memory::Write_U32(STM_EVENT_RESET, BufferOut); - - // Fill in command buffer. - Memory::Write_U32(FS_SUCCESS, m_EventHookAddress + 4); - Memory::Write_U32(IPC_REP_ASYNC, m_EventHookAddress); - Memory::Write_U32(IPC_CMD_IOCTL, m_EventHookAddress + 8); - - // Generate a reply to the IPC command. - WII_IPC_HLE_Interface::EnqueueReply(m_EventHookAddress); - } + void ResetButton(); // STATE_TO_SAVE u32 m_EventHookAddress;