diff --git a/Source/Core/Core/Src/HLE/HLE.cpp b/Source/Core/Core/Src/HLE/HLE.cpp index e757fdde9a..6469359a31 100644 --- a/Source/Core/Core/Src/HLE/HLE.cpp +++ b/Source/Core/Core/Src/HLE/HLE.cpp @@ -42,57 +42,7 @@ static const SPatch OSPatches[] = { { "FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - // speedup - //{ "OSProtectRange", HLE_Misc::UnimplementedFunctionFalse, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ "THPPlayerGetState", HLE_Misc:THPPlayerGetState, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ "memcpy", HLE_Misc::gc_memcpy, HLE_HOOK_REPLACE, HLE_TYPE_MEMORY }, - //{ "memcmp", HLE_Misc::gc_memcmp, HLE_HOOK_REPLACE, HLE_TYPE_MEMORY }, - //{ "memset", HLE_Misc::gc_memset, HLE_HOOK_REPLACE, HLE_TYPE_MEMORY }, - //{ "memmove", HLE_Misc::gc_memmove, HLE_HOOK_REPLACE, HLE_TYPE_MEMORY }, - - //{ "__div2i", HLE_Misc::div2i, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, // Slower? - //{ "__div2u", HLE_Misc::div2u, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, // Slower? - - //{ "DCFlushRange", HLE_Misc::UnimplementedFunction, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ "DCInvalidateRange", HLE_Misc::UnimplementedFunction, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ "DCZeroRange", HLE_Misc::UnimplementedFunction, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - - // debug out is very nice ;) - - { "OSReport", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, - { "DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, - { "WUD_DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, - { "OSPanic", HLE_OS::HLE_OSPanic, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, - { "vprintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, - { "printf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, - { "puts", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, // gcc-optimized printf? - { "___blank(char *,...)", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, // used for early init things (normally) - { "___blank", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, - { "__write_console", HLE_OS::HLE_write_console, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, // used by sysmenu (+more?) - - // wii only - //{ "__OSInitAudioSystem", HLE_Misc::UnimplementedFunction, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - - // Super Monkey Ball - no longer needed. - //{ ".evil_vec_cosine", HLE_Misc::SMB_EvilVecCosine, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ ".evil_normalize", HLE_Misc::SMB_EvilNormalize, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ ".evil_vec_setlength", HLE_Misc::SMB_evil_vec_setlength, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ ".evil_vec_something", HLE_Misc::FZero_evil_vec_normalize, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, { "PanicAlert", HLE_Misc::HLEPanicAlert, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, - //{ ".sqrt_internal_needs_cr1", HLE_Misc::SMB_sqrt_internal, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ ".rsqrt_internal_needs_cr1", HLE_Misc::SMB_rsqrt_internal, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ ".atan2", HLE_Misc::SMB_atan2HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ ".sqrt_fz", HLE_Misc::FZ_sqrtHLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - - // F-zero still isn't working correctly, but these aren't really helping. - - //{ ".sqrt_internal_fz", HLE_Misc::FZ_sqrt_internal, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - //{ ".rsqrt_internal_fz", HLE_Misc::FZ_rsqrt_internal, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - - //{ ".kill_infinites", HLE_Misc::FZero_kill_infinites, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - // special - // { "GXPeekZ", HLE_Misc::GXPeekZHLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, - // { "GXPeekARGB", HLE_Misc::GXPeekARGBHLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, // Name doesn't matter, installed in CBoot::BootUp() { "HBReload", HLE_Misc::HBReload, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, @@ -101,11 +51,23 @@ static const SPatch OSPatches[] = { "__OSBootDol", HLE_Misc::OSBootDol, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, { "OSGetResetCode", HLE_Misc::OSGetResetCode, HLE_HOOK_REPLACE, HLE_TYPE_GENERIC }, + // Debug/OS Support + { "OSPanic", HLE_OS::HLE_OSPanic, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, + + { "OSReport", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, + { "DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, + { "WUD_DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, + { "vprintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, + { "printf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, + { "puts", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, // gcc-optimized printf? + { "___blank(char *,...)", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, // used for early init things (normally) + { "___blank", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, + { "__write_console", HLE_OS::HLE_write_console, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG }, // used by sysmenu (+more?) }; static const SPatch OSBreakPoints[] = { - { "FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction }, + { "FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction }, }; void Patch(u32 addr, const char *hle_func_name) diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.cpp b/Source/Core/Core/Src/HLE/HLE_Misc.cpp index c8323ca6c4..0b5db4f17f 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.cpp +++ b/Source/Core/Core/Src/HLE/HLE_Misc.cpp @@ -27,21 +27,6 @@ namespace HLE_Misc std::string args; u32 argsPtr; -u32 bootType; - -// Helper to quickly read the floating point value at a memory location. -inline float F(u32 addr) -{ - u32 mem = Memory::ReadFast32(addr); - return *((float*)&mem); -} - -// Helper to quickly write a floating point value to a memory location. -inline void FW(u32 addr, float x) -{ - u32 data = *((u32*)&x); - Memory::WriteUnchecked_U32(data, addr); -} // If you just want to kill a function, one of the three following are usually appropriate. // According to the PPC ABI, the return value is always in r3. @@ -50,32 +35,6 @@ void UnimplementedFunction() NPC = LR; } -void UnimplementedFunctionTrue() -{ - GPR(3) = 1; - NPC = LR; -} - -void UnimplementedFunctionFalse() -{ - GPR(3) = 0; - NPC = LR; -} - -void GXPeekZ() -{ - // Just some fake Z value. - Memory::Write_U32(0xFFFFFF, GPR(5)); - NPC = LR; -} - -void GXPeekARGB() -{ - // Just some fake color value. - Memory::Write_U32(0xFFFFFFFF, GPR(5)); - NPC = LR; -} - // If you want a function to panic, you can rename it PanicAlert :p // Don't know if this is worth keeping. void HLEPanicAlert() @@ -84,200 +43,6 @@ void HLEPanicAlert() NPC = LR; } -// Computes the cosine of the angle between the two fvec3s pointed at by r3 and r4. -void SMB_EvilVecCosine() -{ - u32 r3 = GPR(3); - u32 r4 = GPR(4); - - float x1 = F(r3); - float y1 = F(r3 + 4); - float z1 = F(r3 + 8); - - float x2 = F(r4); - float y2 = F(r4 + 4); - float z2 = F(r4 + 8); - - float s1 = x1*x1 + y1*y1 + z1*z1; - float s2 = x2*x2 + y2*y2 + z2*z2; - - float dot = x1*x2 + y1*y2 + z1*z2; - - rPS0(1) = dot / sqrtf(s1 * s2); - NPC = LR; -} - -// Normalizes the vector pointed at by r3. -void SMB_EvilNormalize() -{ - u32 r3 = GPR(3); - float x = F(r3); - float y = F(r3 + 4); - float z = F(r3 + 8); - float len = x*x + y*y + z*z; - float inv_len; - if (len <= 0) - inv_len = 0; - else - inv_len = 1.0f / sqrtf(len); - x *= inv_len; - y *= inv_len; - z *= inv_len; - FW(r3, x); - FW(r3 + 4, y); - FW(r3 + 8, z); - NPC = LR; -} - -// Scales the vector pointed at by r3 to the length specified by f0. -// Writes results to vector pointed at by r4. -void SMB_evil_vec_setlength() -{ - u32 r3 = GPR(3); - u32 r4 = GPR(4); - float x = F(r3); - float y = F(r3 + 4); - float z = F(r3 + 8); - float inv_len = (float)(rPS0(0) / sqrt(x*x + y*y + z*z)); - x *= inv_len; - y *= inv_len; - z *= inv_len; - FW(r4, x); - FW(r4 + 4, y); - FW(r4 + 8, z); - NPC = LR; -} - -// Internal square root function in the crazy math lib. Acts a bit odd, just read it. It's not a bug :p -void SMB_sqrt_internal() -{ - double f = sqrt(rPS0(1)); - rPS0(0) = rPS0(1); - rPS1(0) = rPS0(1); - rPS0(1) = f; - rPS1(1) = f; - NPC = LR; -} - -// Internal inverse square root function in the crazy math lib. -void SMB_rsqrt_internal() -{ - double f = 1.0 / sqrt(rPS0(1)); - rPS0(1) = f; - rPS1(1) = f; - NPC = LR; -} - -void SMB_atan2() -{ - // in: f1 = x, f2 = y - // out: r3 = angle - double angle = atan2(rPS0(1), rPS0(2)); - int angle_fixpt = (int)(angle / 3.14159 * 32767); - if (angle_fixpt < -32767) angle_fixpt = -32767; - if (angle_fixpt > 32767) angle_fixpt = 32767; - GPR(3) = angle_fixpt; - NPC = LR; -} - - -// F-zero math lib range: 8006d044 - 8006f770 - -void FZero_kill_infinites() -{ - // TODO: Kill infinites in FPR(1) - - NPC = LR; -} - -void FZ_sqrt() { - u32 r3 = GPR(3); - double x = rPS0(0); - x = sqrt(x); - FW(r3, (float)x); - rPS0(0) = x; - NPC = LR; -} - -// Internal square root function in the crazy math lib. Acts a bit odd, just read it. It's not a bug :p -void FZ_sqrt_internal() -{ - double f = sqrt(rPS0(1)); - rPS0(0) = rPS0(1); - rPS1(0) = rPS0(1); - rPS0(1) = f; - rPS1(1) = f; - NPC = LR; -} - -// Internal inverse square root function in the crazy math lib. -void FZ_rsqrt_internal() -{ - double f = 1.0 / sqrt(rPS0(1)); - rPS0(1) = f; - rPS1(1) = f; - NPC = LR; -} - -void FZero_evil_vec_normalize() -{ - u32 r3 = GPR(3); - float x = F(r3); - float y = F(r3 + 4); - float z = F(r3 + 8); - float sq_len = x*x + y*y + z*z; - float inv_len = 1.0f / sqrtf(sq_len); - x *= inv_len; - y *= inv_len; - z *= inv_len; - FW(r3, x); - FW(r3 + 4, y); - FW(r3 + 8, z); - rPS0(1) = inv_len * sq_len; // len - rPS1(1) = inv_len * sq_len; // len - NPC = LR; - - /* -.evil_vec_something - -(f6, f7, f8) <- [r3] -f1 = f6 * f6 -f1 += f7 * f7 -f1 += f8 * f8 -f2 = mystery -f4 = f2 * f1 -f3 = f2 + f2 -f1 = 1/f0 - -f6 *= f1 -f7 *= f1 -f8 *= f1 - -8006d668: lis r5, 0xE000 -8006d684: lfs f2, 0x01A0 (r5) -8006d69c: fmr f0,f2 -8006d6a0: fmuls f4,f2,f1 -8006d6a4: fadds f3,f2,f2 -8006d6a8: frsqrte f1,f0,f1 -8006d6ac: fadds f3,f3,f2 -8006d6b0: fmuls f5,f1,f1 -8006d6b4: fnmsubs f5,f5,f4,f3 -8006d6b8: fmuls f1,f1,f5 -8006d6bc: fmuls f5,f1,f1 -8006d6c0: fnmsubs f5,f5,f4,f3 -8006d6c4: fmuls f1,f1,f5 -8006d6c8: fmuls f6,f6,f1 -8006d6cc: stfs f6, 0 (r3) -8006d6d0: fmuls f7,f7,f1 -8006d6d4: stfs f7, 0x0004 (r3) -8006d6d8: fmuls f8,f8,f1 -8006d6dc: stfs f8, 0x0008 (r3) -8006d6e0: fmuls f1,f1,f0 -8006d6e4: blr -*/ - NPC = LR; -} - void HBReload() { // There isn't much we can do. Just stop cleanly. @@ -403,62 +168,6 @@ u32 GetDolFileSize(std::string dol) return (u32)pFileSystem->GetFileSize(dolFile.c_str()); } -void gc_memmove() -{ - u32 dest = GPR(3); - u32 src = GPR(4); - u32 count = GPR(5); - memmove((u8*)(Memory::base + dest), (u8*)(Memory::base + src), count); - NPC = LR; -} - -void gc_memcpy() -{ - u32 dest = GPR(3); - u32 src = GPR(4); - u32 count = GPR(5); - memcpy((u8*)(Memory::base + dest), (u8*)(Memory::base + src), count); - NPC = LR; -} - -void gc_memset() -{ - u32 dest = GPR(3); - u32 ch = GPR(4); - u32 count = GPR(5); - memset((u8*)(Memory::base + dest), ch, count); - NPC = LR; -} - -void gc_memcmp() -{ - u32 dest = GPR(3); - u32 src = GPR(4); - u32 count = GPR(5); - GPR(3) = memcmp((u8*)(Memory::base + dest), (u8*)(Memory::base + src), count); - NPC = LR; -} - -void div2i() -{ - s64 num = (s64)(GPR(3)) << 32 | GPR(4); - s64 den = (s64)(GPR(5)) << 32 | GPR(6); - s64 quo = num / den; - GPR(3) = quo >> 32; - GPR(4) = quo & 0xffffffff; - NPC = LR; -} - -void div2u() -{ - u64 num = (u64)(GPR(3)) << 32 | GPR(4); - u64 den = (u64)(GPR(5)) << 32 | GPR(6); - u64 quo = num / den; - GPR(3) = quo >> 32; - GPR(4) = quo & 0xffffffff; - NPC = LR; -} - void OSGetResetCode() { u32 resetCode = Memory::Read_U32(0xCC003024); @@ -484,8 +193,6 @@ void OSBootDol() { if (GetIOSVersion() >= 30) { - bootType = GPR(4); - if ((GPR(4) >> 28) == 0x8) { u32 resetCode = GPR(30); diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.h b/Source/Core/Core/Src/HLE/HLE_Misc.h index e83805d23a..43924a4dcf 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.h +++ b/Source/Core/Core/Src/HLE/HLE_Misc.h @@ -7,34 +7,11 @@ namespace HLE_Misc { - void Pass(); void HLEPanicAlert(); void UnimplementedFunction(); - void UnimplementedFunctionTrue(); - void UnimplementedFunctionFalse(); - void GXPeekZ(); - void GXPeekARGB(); - void SMB_EvilVecCosine(); - void SMB_EvilNormalize(); - void SMB_sqrt_internal(); - void SMB_rsqrt_internal(); - void SMB_atan2(); - void SMB_evil_vec_setlength(); - void FZero_kill_infinites(); - void FZero_evil_vec_normalize(); - void FZ_sqrt(); - void FZ_sqrt_internal(); - void FZ_rsqrt_internal(); void HBReload(); void OSBootDol(); void OSGetResetCode(); - void memcpy(); - void memset(); - void memmove(); - void memcmp(); - void div2i(); - void div2u(); - void ExecuteDOL(u8* dolFile, u32 fileSize); } #endif