From 88e273fac13b6c3b95256fc083867c2b6553c9d6 Mon Sep 17 00:00:00 2001 From: skidau Date: Tue, 1 Nov 2011 23:00:12 +1100 Subject: [PATCH] Added an IOS check as games which use IOS older than IOS30 do not need to be HLE'd. Added some stubs for Reset to Menu and SSBB's load from disc partition. Fixed loading Fate of Atlantis from the Indiana Jones and the Staff of Kings game. --- Source/Core/Core/Src/Boot/Boot.cpp | 1 - Source/Core/Core/Src/HLE/HLE.cpp | 29 +++++++-- Source/Core/Core/Src/HLE/HLE.h | 1 + Source/Core/Core/Src/HLE/HLE_Misc.cpp | 92 +++++++++++++++++++++++---- 4 files changed, 103 insertions(+), 20 deletions(-) diff --git a/Source/Core/Core/Src/Boot/Boot.cpp b/Source/Core/Core/Src/Boot/Boot.cpp index 228d10b8a8..7711990e65 100644 --- a/Source/Core/Core/Src/Boot/Boot.cpp +++ b/Source/Core/Core/Src/Boot/Boot.cpp @@ -267,7 +267,6 @@ bool CBoot::BootUp() db.Apply(&g_symbolDB); } HLE::PatchFunctions(); - g_symbolDB.Clear(); } /* Try to load the symbol map if there is one, and then scan it for diff --git a/Source/Core/Core/Src/HLE/HLE.cpp b/Source/Core/Core/Src/HLE/HLE.cpp index 671a9e0a3a..0c42f7f4df 100644 --- a/Source/Core/Core/Src/HLE/HLE.cpp +++ b/Source/Core/Core/Src/HLE/HLE.cpp @@ -28,6 +28,7 @@ #include "HLE_OS.h" #include "HLE_Misc.h" #include "IPC_HLE/WII_IPC_HLE_Device_es.h" +#include "ConfigManager.h" namespace HLE { @@ -137,13 +138,16 @@ void PatchFunctions() } } - for (size_t i = 1; i < sizeof(OSBreakPoints) / sizeof(SPatch); i++) + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableDebugging) { - Symbol *symbol = g_symbolDB.GetSymbolFromName(OSPatches[i].m_szPatchName); - if (symbol > 0) + for (size_t i = 1; i < sizeof(OSBreakPoints) / sizeof(SPatch); i++) { - PowerPC::breakpoints.Add(symbol->address, false); - INFO_LOG(OSHLE, "Adding BP to %s %08x", OSBreakPoints[i].m_szPatchName, symbol->address); + Symbol *symbol = g_symbolDB.GetSymbolFromName(OSPatches[i].m_szPatchName); + if (symbol > 0) + { + PowerPC::breakpoints.Add(symbol->address, false); + INFO_LOG(OSHLE, "Adding BP to %s %08x", OSBreakPoints[i].m_szPatchName, symbol->address); + } } } @@ -171,4 +175,19 @@ u32 GetOrigInstruction(u32 addr) return (iter != orig_instruction.end()) ? iter->second : 0; } +u32 UnPatch(std::string patchName) +{ + Symbol *symbol = g_symbolDB.GetSymbolFromName(patchName.c_str()); + if (symbol > 0) + { + for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4) + { + Memory::WriteUnchecked_U32(orig_instruction[addr], addr); + PowerPC::ppcState.iCache.Invalidate(addr); + } + return symbol->address; + } + return 0; +} + } // end of namespace HLE diff --git a/Source/Core/Core/Src/HLE/HLE.h b/Source/Core/Core/Src/HLE/HLE.h index 04c3d35198..b81f347b9f 100644 --- a/Source/Core/Core/Src/HLE/HLE.h +++ b/Source/Core/Core/Src/HLE/HLE.h @@ -24,6 +24,7 @@ namespace HLE { void PatchFunctions(); void Patch(u32 pc, const char *func_name); + u32 UnPatch(std::string patchName); void Execute(u32 _CurrentPC, u32 _Instruction); u32 GetOrigInstruction(u32 em_address); diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.cpp b/Source/Core/Core/Src/HLE/HLE_Misc.cpp index f9bab42f3c..67b2e84963 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.cpp +++ b/Source/Core/Core/Src/HLE/HLE_Misc.cpp @@ -28,10 +28,17 @@ #include "Filesystem.h" #include "../Boot/Boot_DOL.h" #include "IPC_HLE/WII_IPC_HLE_Device_usb.h" +#include "HLE.h" namespace HLE_Misc { +std::string dol; +std::string args; +u32 argsPtr; +u32 bootType; +u16 IOSv; + // Helper to quickly read the floating point value at a memory location. inline float F(u32 addr) { @@ -288,26 +295,19 @@ void HBReload() Host_Message(WM_USER_STOP); } - -void OSBootDol() +void BootDOLFromDisc() { - std::string dol; - std::string args; - - u32 r28 = GPR(28); - Memory::GetString(dol, r28); - - u32 argsPtr = Memory::Read_U32(GPR(5)); - Memory::GetString(args, argsPtr); - DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(SConfig::GetInstance().m_LastFilename.c_str()); DiscIO::IFileSystem* pFileSystem = DiscIO::CreateFileSystem(pVolume); - size_t fileSize = (size_t) pFileSystem->GetFileSize(dol.substr(1).c_str()); + if (dol.substr(1, 1).compare("//")) + dol = dol.substr(1); + + u32 fileSize = (u32) pFileSystem->GetFileSize(dol.c_str()); u8* dolFile = new u8[fileSize]; - if (dolFile) + if (fileSize > 0) { - pFileSystem->ReadFile(dol.substr(1).c_str(), dolFile, fileSize); + pFileSystem->ReadFile(dol.c_str(), dolFile, fileSize); CDolLoader dolLoader(dolFile, fileSize); dolLoader.Load(); PowerPC::ppcState.iCache.Reset(); @@ -346,4 +346,68 @@ void OSBootDol() } } +u32 GetDolFileSize() +{ + DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(SConfig::GetInstance().m_LastFilename.c_str()); + DiscIO::IFileSystem* pFileSystem = DiscIO::CreateFileSystem(pVolume); + + std::string dolFile; + + if (dol.substr(1, 1).compare("//")) + dolFile = dol.substr(1); + + return (u32)pFileSystem->GetFileSize(dolFile.c_str()); +} + +void OSBootDol() +{ + IOSv = Memory::Read_U16(0x00003140); + + if (IOSv >= 30) + { + bootType = GPR(4); + + if ((GPR(4) >> 28) == 0x8) + { + // Reset from menu + PanicAlert("Reset from menu"); + } + else if ((GPR(4) >> 28) == 0xA) + { + // Boot from disc partition + PanicAlert("Boot Partition: %08x", GPR(26)); + } + else if ((GPR(4) >> 28) == 0xC) + { + // Boot DOL from disc + u32 ptr = GPR(28); + Memory::GetString(dol, ptr); + + if (GetDolFileSize() == 0) + { + ptr = GPR(30); + Memory::GetString(dol, ptr); + if (GetDolFileSize() == 0) + { + // Cannot locate the dol file, exit. + HLE::UnPatch("__OSBootDol"); + NPC = PC; + return; + } + } + + argsPtr = Memory::Read_U32(GPR(5)); + Memory::GetString(args, argsPtr); + BootDOLFromDisc(); + return; + } + else + { + PanicAlert("Unknown boot type: %08x", GPR(4)); + } + } + HLE::UnPatch("__OSBootDol"); + NPC = PC; +} + }