diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_DI.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_DI.cpp index b9469ab638..906b0c5e18 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_DI.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_DI.cpp @@ -15,10 +15,6 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ - -////////////////////////////////////////////////////////////////////////////////////////// -// Include -// ŻŻŻŻŻŻŻŻŻŻ #include "Common.h" #include "WII_IPC_HLE_Device_DI.h" @@ -31,17 +27,13 @@ #include "VolumeCreator.h" #include "Filesystem.h" -/////////////////////////////////// -////////////////////////////////////////////////// // Music mod -// ŻŻŻŻŻŻŻŻŻŻ #include "Setup.h" // Define MUSICMOD here #ifdef MUSICMOD #include "../../../../Externals/MusicMod/Main/Src/Main.h" #endif -/////////////////////// CWII_IPC_HLE_Device_di::CWII_IPC_HLE_Device_di(u32 _DeviceID, const std::string& _rDeviceName ) @@ -56,10 +48,14 @@ CWII_IPC_HLE_Device_di::CWII_IPC_HLE_Device_di(u32 _DeviceID, const std::string& CWII_IPC_HLE_Device_di::~CWII_IPC_HLE_Device_di() { - if(m_pFileSystem) { delete m_pFileSystem; m_pFileSystem = NULL; } - /* This caused the crash in VolumeHandler.cpp, setting m_pVolume = NULL; didn't help - it still makes VolumeHandler.cpp have a non-NULL pointer with no content so that - delete crashes */ + if (m_pFileSystem) + { + delete m_pFileSystem; + m_pFileSystem = NULL; + } + // This caused the crash in VolumeHandler.cpp, setting m_pVolume = NULL; didn't help + // it still makes VolumeHandler.cpp have a non-NULL pointer with no content so that + // delete crashes //if(m_pVolume) { delete m_pVolume; m_pVolume = NULL; } } @@ -88,7 +84,8 @@ bool CWII_IPC_HLE_Device_di::IOCtl(u32 _CommandAddress) u32 BufferOutSize = Memory::Read_U32(_CommandAddress + 0x1C); u32 Command = Memory::Read_U32(BufferIn) >> 24; - DEBUG_LOG(WII_IPC_DVD, "%s - Command(0x%08x) BufferIn(0x%08x, 0x%x) BufferOut(0x%08x, 0x%x)", GetDeviceName().c_str(), Command, BufferIn, BufferInSize, BufferOut, BufferOutSize); + DEBUG_LOG(WII_IPC_DVD, "%s - Command(0x%08x) BufferIn(0x%08x, 0x%x) BufferOut(0x%08x, 0x%x)", + GetDeviceName().c_str(), Command, BufferIn, BufferInSize, BufferOut, BufferOutSize); u32 ReturnValue = ExecuteCommand(BufferIn, BufferInSize, BufferOut, BufferOutSize); Memory::Write_U32(ReturnValue, _CommandAddress + 0x4); @@ -98,28 +95,61 @@ bool CWII_IPC_HLE_Device_di::IOCtl(u32 _CommandAddress) bool CWII_IPC_HLE_Device_di::IOCtlV(u32 _CommandAddress) { -// PanicAlert("CWII_IPC_HLE_Device_di::IOCtlV() unknown"); -// DumpCommands(_CommandAddress); - u32 ReturnValue = 0; + INFO_LOG(WII_IPC_DVD, "*******************************"); + INFO_LOG(WII_IPC_DVD, "CWII_IPC_DVD_Device_di::IOCtlV"); + INFO_LOG(WII_IPC_DVD, "*******************************"); SIOCtlVBuffer CommandBuffer(_CommandAddress); + // Prepare the out buffer(s) with zeros as a safety precaution + // to avoid returning bad values + for(u32 i = 0; i < CommandBuffer.NumberPayloadBuffer; i++) + { + Memory::Memset(CommandBuffer.PayloadBuffer[i].m_Address, 0, + CommandBuffer.PayloadBuffer[i].m_Size); + } + + u32 ReturnValue = 0; switch (CommandBuffer.Parameter) { - // DVDLowOpenPartition??? + // DVDLowOpenPartition case 0x8b: { - INFO_LOG(WII_IPC_DVD, "DVD IOCtlV: DVDLowOpenPartition"); - _dbg_assert_msg_(WII_IPC_DVD, 0, "DVD IOCtlV: DVDLowOpenPartition"); + _dbg_assert_msg_(WII_IPC_DVD, CommandBuffer.InBuffer[1].m_Address == 0, "DVDLowOpenPartition with ticket"); + _dbg_assert_msg_(WII_IPC_DVD, CommandBuffer.InBuffer[2].m_Address == 0, "DVDLowOpenPartition with cert chain"); + + u8 partition = Memory::Read_U32(CommandBuffer.m_Address + 4); + INFO_LOG(WII_IPC_DVD, "DVD IOCtlV: DVDLowOpenPartition %i", partition); + + bool readOK = false; + + // Get the info table + u8 pInfoTableOffset[4]; + readOK |= VolumeHandler::RAWReadToPtr(pInfoTableOffset, 0x40004, 4); + u64 InfoTableOffset = (u32)(pInfoTableOffset[3] | pInfoTableOffset[2] << 8 | pInfoTableOffset[1] << 16 | pInfoTableOffset[0] << 24) << 2; + + // Get the offset of the partition + u8 pInfoTableEntryOffset[4]; + readOK |= VolumeHandler::RAWReadToPtr(pInfoTableEntryOffset, InfoTableOffset + (partition << 2) + 4, 4); + u64 PartitionOffset = (u32)(pInfoTableEntryOffset[3] | pInfoTableEntryOffset[2] << 8 | pInfoTableEntryOffset[1] << 16 | pInfoTableEntryOffset[0] << 24) << 2; + + // Read TMD to the buffer + readOK |= VolumeHandler::RAWReadToPtr(Memory::GetPointer(CommandBuffer.PayloadBuffer[0].m_Address), + PartitionOffset + 0x2c0, CommandBuffer.PayloadBuffer[0].m_Size); + + // Second outbuffer is error, we can ignore it + + ReturnValue = readOK ? 1 : 0; } break; + default: - INFO_LOG(WII_IPC_DVD, "DVD IOCtlV: %i", CommandBuffer.Parameter); - _dbg_assert_msg_(WII_IPC_DVD, 0, "DVD: %i", CommandBuffer.Parameter); + ERROR_LOG(WII_IPC_DVD, "DVD IOCtlV: %i", CommandBuffer.Parameter); + _dbg_assert_msg_(WII_IPC_DVD, 0, "DVD IOCtlV: %i", CommandBuffer.Parameter); break; } - Memory::Write_U32(ReturnValue, _CommandAddress+4); + Memory::Write_U32(ReturnValue, _CommandAddress + 4); return true; } @@ -127,11 +157,11 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32 { u32 Command = Memory::Read_U32(_BufferIn) >> 24; - /* Set out buffer to zeroes as a safety precaution to avoid answering - nonsense values */ - - // TATSUNOKO VS CAPCOM: Gets here with _BufferOut == 0x0!!! - if (_BufferOut != 0) { + // TATSUNOKO VS CAPCOM: Gets here with _BufferOut == 0!!! + if (_BufferOut != 0) + { + // Set out buffer to zeroes as a safety precaution to avoid answering + // nonsense values Memory::Memset(_BufferOut, 0, _BufferOutSize); } @@ -150,94 +180,98 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32 0x0000, 0x0002, 0x20060526, I tried it in Balls of Fury that gives a DVD error message after the DVDLowInquiry, but that did't change anything, it must be something else. */ - buffer[0] = 0x01; // rev - buffer[1] = 0x02; - buffer[2] = 0x03; // dev code - buffer[3] = 0x04; - buffer[4] = 0x20; // firmware date - buffer[5] = 0x08; - buffer[6] = 0x08; - buffer[7] = 0x29; +// buffer[0] = 0x01; // rev +// buffer[1] = 0x02; +// buffer[2] = 0x03; // dev code +// buffer[3] = 0x04; +// buffer[4] = 0x20; // firmware date +// buffer[5] = 0x08; +// buffer[6] = 0x08; +// buffer[7] = 0x29; - DEBUG_LOG(WII_IPC_DVD, "%s executes DVDLowInquiry (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); - - return 0x1; + buffer[4] = 0x20; // firmware date + buffer[5] = 0x02; + buffer[6] = 0x04; + buffer[7] = 0x02; + buffer[8] = 0x61; // version + + DEBUG_LOG(WII_IPC_DVD, "%s executes DVDLowInquiry (Buffer 0x%08x, 0x%x)", + GetDeviceName().c_str(), _BufferOut, _BufferOutSize); + + return 1; } break; // DVDLowReadDiskID case 0x70: { - // TODO - verify that this is correct - VolumeHandler::ReadToPtr(Memory::GetPointer(_BufferOut), 0, _BufferOutSize); + VolumeHandler::RAWReadToPtr(Memory::GetPointer(_BufferOut), 0, _BufferOutSize); - DEBUG_LOG(WII_IPC_DVD, "%s executes DVDLowReadDiskID (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); - - return 0x1; + DEBUG_LOG(WII_IPC_DVD, "%s executes DVDLowReadDiskID 0x%08x", + GetDeviceName().c_str(), Memory::Read_U64(_BufferOut)); + + return 1; } break; - - // DVDLowRead - case 0x71: - { + + // DVDLowRead + case 0x71: + { if (_BufferOut == 0) { PanicAlert("DVDLowRead : _BufferOut == 0"); return 0; } - u32 Size = Memory::Read_U32(_BufferIn + 0x04); - u64 DVDAddress = (u64)Memory::Read_U32(_BufferIn + 0x08) << 2; + u32 Size = Memory::Read_U32(_BufferIn + 0x04); + u64 DVDAddress = (u64)Memory::Read_U32(_BufferIn + 0x08) << 2; - const char *pFilename = m_pFileSystem->GetFileName(DVDAddress); - if (pFilename != NULL) - { - INFO_LOG(WII_IPC_DVD, " DVDLowRead: %s (0x%x) - (DVDAddr: 0x%x, Size: 0x%x)", pFilename, m_pFileSystem->GetFileSize(pFilename), DVDAddress, Size); - } - else - { - INFO_LOG(WII_IPC_DVD, " DVDLowRead: file unkw - (DVDAddr: 0x%x, Size: 0x%x)", GetDeviceName().c_str(), DVDAddress, Size); - } + const char *pFilename = m_pFileSystem->GetFileName(DVDAddress); + if (pFilename != NULL) + { + INFO_LOG(WII_IPC_DVD, " DVDLowRead: %s (0x%x) - (DVDAddr: 0x%x, Size: 0x%x)", + pFilename, m_pFileSystem->GetFileSize(pFilename), DVDAddress, Size); + } + else + { + INFO_LOG(WII_IPC_DVD, " DVDLowRead: file unkw - (DVDAddr: 0x%x, Size: 0x%x)", + GetDeviceName().c_str(), DVDAddress, Size); + } - if (Size > _BufferOutSize) - { - PanicAlert("Detected attempt to read more data from the DVD than fit inside the out buffer. Clamp."); - Size = _BufferOutSize; - } + if (Size > _BufferOutSize) + { + PanicAlert("Detected attempt to read more data from the DVD than fit inside the out buffer. Clamp."); + Size = _BufferOutSize; + } - if (VolumeHandler::ReadToPtr(Memory::GetPointer(_BufferOut), DVDAddress, Size) != true) - { - PanicAlert("Cant read from DVD_Plugin - DVD-Interface: Fatal Error"); - } + if (!VolumeHandler::ReadToPtr(Memory::GetPointer(_BufferOut), DVDAddress, Size)) + { + PanicAlert("Cant read from DVD_Plugin - DVD-Interface: Fatal Error"); + } - ////////////////////////////////////////////////// - // Music mod - // ŻŻŻŻŻŻŻŻŻŻ #ifdef MUSICMOD - std::string Tmp = pFilename; - MusicMod::CheckFile(Tmp); + std::string Tmp = pFilename; + MusicMod::CheckFile(Tmp); #endif - /////////////////////// - return 0x1; - } - break; + return 1; + } + break; // DVDLowWaitForCoverClose case 0x79: - { - Memory::Memset(_BufferOut, 0, _BufferOutSize); - INFO_LOG(WII_IPC_DVD, "%s executes DVDLowWaitForCoverClose (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); + { + INFO_LOG(WII_IPC_DVD, "%s executes DVDLowWaitForCoverClose (Buffer 0x%08x, 0x%x)", + GetDeviceName().c_str(), _BufferOut, _BufferOutSize); return 4; } break; + // DVDLowPrepareCoverRegister // DVDLowGetCoverReg - Called by "Legend of Spyro" and MP3 case 0x7a: { - INFO_LOG(WII_IPC_DVD, "%s executes DVDLowGetCoverReg (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); - - // Write zeroes to the out buffer just in case there is some nonsense data there - Memory::Memset(_BufferOut, 0, _BufferOutSize); + INFO_LOG(WII_IPC_DVD, "%s executes DVDLowGetCoverReg (Buffer 0x%08x, 0x%x)", + GetDeviceName().c_str(), _BufferOut, _BufferOutSize); // -------------------------------------------------------------------- /* Hack for Legend of Spyro. Switching the 4th byte between 0 and 1 gets @@ -262,19 +296,40 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32 } break; + // DVDLowNotifyReset + case 0x7e: + PanicAlert("DVDLowNotifyReset"); + break; + + // DVDLowReadDvdPhysical + case 0x80: + PanicAlert("DVDLowReadDvdPhysical"); + break; + + // DVDLowReadDvdCopyright + case 0x81: + PanicAlert("DVDLowReadDvdCopyright"); + break; + + // DVDLowReadDvdDiscKey + case 0x82: + PanicAlert("DVDLowReadDvdDiscKey"); + break; + // DVDLowClearCoverInterrupt case 0x86: { - Memory::Memset(_BufferOut, 0, _BufferOutSize); - INFO_LOG(WII_IPC_DVD, "%s executes DVDLowClearCoverInterrupt (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); + INFO_LOG(WII_IPC_DVD, "%s executes DVDLowClearCoverInterrupt (Buffer 0x%08x, 0x%x)", + GetDeviceName().c_str(), _BufferOut, _BufferOutSize); + return 1; } break; // DVDLowGetCoverStatus case 0x88: { - Memory::Memset(_BufferOut, 0, _BufferOutSize); - INFO_LOG(WII_IPC_DVD, "%s executes DVDLowGetCoverStatus (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); + INFO_LOG(WII_IPC_DVD, "%s executes DVDLowGetCoverStatus (Buffer 0x%08x, 0x%x)", + GetDeviceName().c_str(), _BufferOut, _BufferOutSize); return 1; } break; @@ -282,24 +337,27 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32 // DVDLowReset case 0x8a: { - Memory::Memset(_BufferOut, 0, _BufferOutSize); - INFO_LOG(WII_IPC_DVD, "%s executes DVDLowReset (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); + INFO_LOG(WII_IPC_DVD, "%s executes DVDLowReset (Buffer 0x%08x, 0x%x)", + GetDeviceName().c_str(), _BufferOut, _BufferOutSize); return 1; } break; // DVDLowOpenPartition case 0x8b: - PanicAlert("DVDLowOpenPartition", Command); + PanicAlert("DVDLowOpenPartition"); + return 1; break; + // DVDLowClosePartition case 0x8c: - //PanicAlert("DVDLowClosePartition"); + DEBUG_LOG(WII_IPC_DVD, "DVDLowClosePartition"); + return 1; break; // DVDLowUnencryptedRead case 0x8d: - //PanicAlert("DVDLowUnencryptedRead"); + DEBUG_LOG(WII_IPC_DVD, "DVDLowUnencryptedRead"); { if (_BufferOut == 0) { @@ -315,40 +373,106 @@ u32 CWII_IPC_HLE_Device_di::ExecuteCommand(u32 _BufferIn, u32 _BufferInSize, u32 Size = _BufferOutSize; } - if (VolumeHandler::RAWReadToPtr(Memory::GetPointer(_BufferOut), DVDAddress, Size) != true) + if (!VolumeHandler::RAWReadToPtr(Memory::GetPointer(_BufferOut), DVDAddress, Size)) { PanicAlert("Cant read from DVD_Plugin - DVD-Interface: Fatal Error"); - } + } + + return 1; } break; - // DVDLowSeek - case 0xab: - //PanicAlert("DVDLowSeek"); - break; - - case 0xe0: - PanicAlert("DVD unknown command 0xe0, so far only seen in Tatsunoko. Don't know what to do, things will probably go wrong."); + // DVDLowEnableDvdVideo + case 0x8e: + PanicAlert("DVDLowEnableDvdVideo"); break; + // DVDLowReportKey + case 0xa4: + PanicAlert("DVDLowReportKey"); + break; + + // DVDLowSeek + case 0xab: + PanicAlert("DVDLowSeek"); + break; + +// Apparently Dx commands have never been seen in dolphin? *shrug* + // DVDLowReadDvd + case 0xd0: + PanicAlert("DVDLowReadDvd"); + break; + + // DVDLowReadDvdConfig + case 0xd1: + PanicAlert("DVDLowReadDvdConfig"); + break; + + // DVDLowStopLaser + case 0xd2: + PanicAlert("DVDLowStopLaser"); + break; + + // DVDLowOffset + case 0xd9: + PanicAlert("DVDLowOffset"); + break; + + // DVDLowReadDiskBca + case 0xda: + PanicAlert("DVDLowReadDiskBca"); + break; + + // DVDLowRequestDiscStatus + case 0xdb: + PanicAlert("DVDLowRequestDiscStatus"); + break; + + // DVDLowRequestRetryNumber + case 0xdc: + PanicAlert("DVDLowRequestRetryNumber"); + break; + + // DVDLowSetMaximumRotation + case 0xdd: + PanicAlert("DVDLowSetMaximumRotation"); + break; + + // DVDLowSerMeasControl + case 0xdf: + PanicAlert("DVDLowSerMeasControl"); + break; + + // DVDLowRequestError + case 0xe0: + // Identical to the error codes found in yagcd section 5.7.3.5.1 (so far) + PanicAlert("DVDLowRequestError"); + break; + +// Ex commands are immediate and respond with 4 bytes // DVDLowStopMotor case 0xe3: { - Memory::Memset(_BufferOut, 0, _BufferOutSize); u32 eject = Memory::Read_U32(_BufferIn + 0x04); - INFO_LOG(WII_IPC_DVD, "%s executes DVDLowStopMotor (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); + INFO_LOG(WII_IPC_DVD, "%s executes DVDLowStopMotor eject = %s", + GetDeviceName().c_str(), eject ? "true" : "false"); - if(eject) + if (eject) { - INFO_LOG(WII_IPC_DVD, "Eject disc", GetDeviceName().c_str(), _BufferOut, _BufferOutSize); // TODO: eject the disc } } break; + // DVDLowAudioBufferConfig + case 0xe4: + PanicAlert("DVDLowAudioBufferConfig"); + break; + default: - ERROR_LOG(WII_IPC_DVD, "%s executes unknown cmd 0x%08x (Buffer 0x%08x, 0x%x)", GetDeviceName().c_str(), Command, _BufferOut, _BufferOutSize); + ERROR_LOG(WII_IPC_DVD, "%s executes unknown cmd 0x%08x (Buffer 0x%08x, 0x%x)", + GetDeviceName().c_str(), Command, _BufferOut, _BufferOutSize); PanicAlert("%s executes unknown cmd 0x%08x", GetDeviceName().c_str(), Command); break; diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp index 53960b9822..938b8881fb 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.cpp @@ -389,10 +389,17 @@ u32 CWII_IPC_HLE_Device_sdio_slot0::ExecuteCommand(u32 _BufferIn, u32 _BufferInS Memory::Write_U32(0x900, _BufferOut); break; - case CRAZY_BIGN: - DEBUG_LOG(WII_IPC_SD, "CMD64, wtf"); + case CRAZY_BIGN64: + WARN_LOG(WII_IPC_SD, "CMD64, wtf"); + // shuffle2_: try returning -4 for cmd x'40. - Memory::Write_U32(-0x4, _BufferOut); + Memory::Write_U32(-0x04, _BufferOut); + + _dbg_assert_msg_(WII_IPC_SD, req.arg == 2, "cmd64 odd arg value 0x%08x", req.arg); + break; + + case CRAZY_BIGN65: + ERROR_LOG(WII_IPC_SD, "CMD65, wtf"); break; default: diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.h index 01bcd6a92b..89ee99505b 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_sdio_slot0.h @@ -94,7 +94,8 @@ private: ACMD_SENDOPCOND = 0x29, ACMD_SENDSCR = 0x33, - CRAZY_BIGN = 0x40, + CRAZY_BIGN64 = 0x40, + CRAZY_BIGN65 = 0x41, }; u32 m_Status;