From 56ee6e54974215d98c4c34a6cd8471d6e3e2f13b Mon Sep 17 00:00:00 2001 From: hrydgard Date: Wed, 21 Jan 2009 12:41:01 +0000 Subject: [PATCH] more f-zero work - no success :( Still fp errors. maybe we should pull in a full accuracy ppc fp emulator. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1971 8ced0084-cf51-0410-be5f-012b33b47a6e --- Data/User/Maps/GFZE01.map | 11 ++- .../Core/Src/Debugger/PPCDebugInterface.cpp | 2 +- Source/Core/Core/Src/HLE/HLE.cpp | 27 ++++++- Source/Core/Core/Src/HLE/HLE.h | 2 + Source/Core/Core/Src/HLE/HLE_Misc.cpp | 81 ++++++++++++++----- Source/Core/Core/Src/HLE/HLE_Misc.h | 4 + Source/Core/Core/Src/PowerPC/PPCTables.cpp | 4 +- Source/Core/DebuggerWX/Src/MemoryView.cpp | 38 +-------- 8 files changed, 106 insertions(+), 63 deletions(-) diff --git a/Data/User/Maps/GFZE01.map b/Data/User/Maps/GFZE01.map index 888605c580..1588db0935 100644 --- a/Data/User/Maps/GFZE01.map +++ b/Data/User/Maps/GFZE01.map @@ -5,13 +5,16 @@ 8006d044 0000002c 8006d044 0 .kill_infinites_helper 8006d070 00000018 8006d070 0 .kill_infinites 8006d088 0000002c 8006d088 0 .rsqrt -8006d0b4 00000034 8006d0b4 0 .sqrt_internal_needs_cr1 -8006d0e8 00000030 8006d0e8 0 .rsqrt_internal_needs_cr1 +8006d0b4 00000034 8006d0b4 0 .sqrt_internal_fz +8006d0e8 00000030 8006d0e8 0 .rsqrt_internal_fz +8006d118 00000070 8006d118 0 .sqrt_fz 8006d188 00000030 8006d188 0 .wrapping_once_fp_lookup 8006d1b8 00000064 8006d1b8 0 .weird2 8006d1c4 00000058 8006d1c4 0 .into_weird2 8006d21c 00000030 8006d21c 0 .lookup_some_float_in_table_with_neg_wrap 8006d24c 00000184 8006d24c 0 .atan2 +8006d3d0 0000009c 8006d3d0 0 .asin_fz +8006d46c 000000c8 8006d46c 0 .acos_fz 8006d534 00000070 8006d534 0 .evil_vec_cosine 8006d5f0 00000078 8006d5f0 0 .evil_vec_setlength 8006d668 00000094 8006d668 0 .evil_vec_something @@ -24,6 +27,8 @@ 8006dbe4 0000003c 8006dbe4 0 .read_current_3x3_matrix 8006dc20 00000014 8006dc20 0 .pop_matrix_stack 8006e424 00000074 8006e424 0 .weird_param_in_p1_p2 +8006e978 000001d4 8006e978 0 zz_006e978_ +8006eb4c 000001c0 8006eb4c 0 zz_006eb4c_ 8006f6a8 000000cc 8006f6a8 0 .z_last_skum_function 800798f0 000000ec 800798f0 0 __div2u 800799dc 00000138 800799dc 0 __div2i @@ -32,3 +37,5 @@ 80079d04 00000024 80079d04 0 __shl2i 80079d28 00000024 80079d28 0 __shr2u 80079d4c 00000028 80079d4c 0 __shr2i +8008596c 00000310 8008596c 0 big_matrix_trickery +80088538 00000020 80088538 0 zz_0088538_ diff --git a/Source/Core/Core/Src/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Src/Debugger/PPCDebugInterface.cpp index b959bfeaf2..dc9f097777 100644 --- a/Source/Core/Core/Src/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Src/Debugger/PPCDebugInterface.cpp @@ -41,7 +41,7 @@ void PPCDebugInterface::disasm(unsigned int address, char *dest, int max_size) } else { - strcpy(dest, "No RAM here - invalid"); + strcpy(dest, "(No RAM here)"); } } else diff --git a/Source/Core/Core/Src/HLE/HLE.cpp b/Source/Core/Core/Src/HLE/HLE.cpp index 88a97102c9..3c146d8e9e 100644 --- a/Source/Core/Core/Src/HLE/HLE.cpp +++ b/Source/Core/Core/Src/HLE/HLE.cpp @@ -15,6 +15,9 @@ // Official SVN repository and contact information can be found at // http://code.google.com/p/dolphin-emu/ +#include +#include "Common.h" + #include "HLE.h" #include "../PowerPC/PowerPC.h" @@ -69,10 +72,15 @@ static const SPatch OSPatches[] = { ".evil_vec_cosine", HLE_Misc::SMB_EvilVecCosine }, { ".evil_normalize", HLE_Misc::SMB_EvilNormalize }, { ".evil_vec_setlength", HLE_Misc::SMB_evil_vec_setlength }, + { ".evil_vec_something", HLE_Misc::FZero_evil_vec_normalize }, { "PanicAlert", HLE_Misc::HLEPanicAlert }, { ".sqrt_internal_needs_cr1", HLE_Misc::SMB_sqrt_internal }, { ".rsqrt_internal_needs_cr1", HLE_Misc::SMB_rsqrt_internal }, { ".atan2", HLE_Misc::SMB_atan2}, + { ".sqrt_fz", HLE_Misc::FZ_sqrt}, + + { ".sqrt_internal_fz", HLE_Misc::FZ_sqrt_internal }, + { ".rsqrt_internal_fz", HLE_Misc::FZ_rsqrt_internal }, //{ ".kill_infinites", HLE_Misc::FZero_kill_infinites }, // special @@ -85,6 +93,9 @@ static const SPatch OSBreakPoints[] = { "FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction }, }; + +static std::map orig_instruction; + void Patch(u32 address, const char *hle_func_name) { for (u32 i = 0; i < sizeof(OSPatches) / sizeof(SPatch); i++) @@ -98,15 +109,18 @@ void Patch(u32 address, const char *hle_func_name) } void PatchFunctions() -{ +{ + orig_instruction.clear(); for (u32 i = 0; i < sizeof(OSPatches) / sizeof(SPatch); i++) { Symbol *symbol = g_symbolDB.GetSymbolFromName(OSPatches[i].m_szPatchName); if (symbol > 0) { u32 HLEPatchValue = (1 & 0x3f) << 26; - for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4) + for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4) { + orig_instruction[addr] = Memory::ReadUnchecked_U32(addr); Memory::Write_U32(HLEPatchValue | i, addr); + } LOG(HLE,"Patching %s %08x", OSPatches[i].m_szPatchName, symbol->address); } } @@ -139,4 +153,13 @@ void Execute(u32 _CurrentPC, u32 _Instruction) // _dbg_assert_msg_(HLE,NPC == LR, "Broken HLE function (doesn't set NPC)", OSPatches[pos].m_szPatchName); } +u32 GetOrigInstruction(u32 addr) +{ + std::map::const_iterator iter = orig_instruction.find(addr); + if (iter != orig_instruction.end()) + return iter->second; + else + return 0; +} + } diff --git a/Source/Core/Core/Src/HLE/HLE.h b/Source/Core/Core/Src/HLE/HLE.h index 06e981d6e0..f11d38f314 100644 --- a/Source/Core/Core/Src/HLE/HLE.h +++ b/Source/Core/Core/Src/HLE/HLE.h @@ -25,6 +25,8 @@ namespace HLE void PatchFunctions(); void Patch(u32 pc, const char *func_name); void Execute(u32 _CurrentPC, u32 _Instruction); + + u32 GetOrigInstruction(u32 em_address); } #endif diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.cpp b/Source/Core/Core/Src/HLE/HLE_Misc.cpp index 70280b8bf5..f0b69eb741 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.cpp +++ b/Source/Core/Core/Src/HLE/HLE_Misc.cpp @@ -129,7 +129,7 @@ void SMB_evil_vec_setlength() float x = F(r3); float y = F(r3 + 4); float z = F(r3 + 8); - float inv_len = (float)(rPS0(1) / sqrt(x*x + y*y + z*z)); + float inv_len = (float)(rPS0(0) / sqrt(x*x + y*y + z*z)); x *= inv_len; y *= inv_len; z *= inv_len; @@ -181,23 +181,71 @@ void FZero_kill_infinites() NPC = LR; } -void FZero_evil_vec_something() +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 -8006d66c: lfs f6, 0 (r3) -8006d670: lfs f7, 0x0004 (r3) -8006d674: fmuls f1,f6,f6 -8006d678: lfs f8, 0x0008 (r3) -8006d67c: fmadds f1,f7,f7,f1 -8006d680: fmadds f1,f8,f8,f1 8006d684: lfs f2, 0x01A0 (r5) -8006d688: mcrfs cr1, cr4 -8006d68c: mcrfs cr0, cr3 -8006d690: bso- cr1,->0x8006D6E8 -8006d694: ble- cr1,->0x8006D6E8 -8006d698: bso- ->0x8006D6E8 8006d69c: fmr f0,f2 8006d6a0: fmuls f4,f2,f1 8006d6a4: fadds f3,f2,f2 @@ -217,11 +265,6 @@ void FZero_evil_vec_something() 8006d6dc: stfs f8, 0x0008 (r3) 8006d6e0: fmuls f1,f1,f0 8006d6e4: blr -8006d6e8: lfs f1, 0x0198 (r5) -8006d6ec: stfs f1, 0 (r3) -8006d6f0: stfs f1, 0x0004 (r3) -8006d6f4: stfs f1, 0x0008 (r3) -8006d6f8: blr */ NPC = LR; } diff --git a/Source/Core/Core/Src/HLE/HLE_Misc.h b/Source/Core/Core/Src/HLE/HLE_Misc.h index 773da897df..8d5fcddb3e 100644 --- a/Source/Core/Core/Src/HLE/HLE_Misc.h +++ b/Source/Core/Core/Src/HLE/HLE_Misc.h @@ -34,6 +34,10 @@ namespace HLE_Misc 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(); } #endif diff --git a/Source/Core/Core/Src/PowerPC/PPCTables.cpp b/Source/Core/Core/Src/PowerPC/PPCTables.cpp index 3e2bd2d868..2b667320dc 100644 --- a/Source/Core/Core/Src/PowerPC/PPCTables.cpp +++ b/Source/Core/Core/Src/PowerPC/PPCTables.cpp @@ -700,7 +700,7 @@ void CompileInstruction(UGeckoInstruction _inst) GekkoOPInfo *info = GetOpInfo(_inst); if (info) { #ifdef OPLOG - if (!strcmp(info->opname, "mcrfs")) { + if (!strcmp(info->opname, "mffsx")) { ///"mcrfs" rsplocations.push_back(jit.js.compilerPC); } #endif @@ -766,7 +766,7 @@ void LogCompiledInstructions() #ifdef OPLOG f = fopen(StringFromFormat(FULL_LOGS_DIR "mcrfs_at.txt", time).c_str(), "w"); for (size_t i = 0; i < rsplocations.size(); i++) { - fprintf(f, "mcrfs: %08x\n", rsplocations[i]); + fprintf(f, "mffsx: %08x\n", rsplocations[i]); } fclose(f); #endif diff --git a/Source/Core/DebuggerWX/Src/MemoryView.cpp b/Source/Core/DebuggerWX/Src/MemoryView.cpp index 46bce90034..020caa29c4 100644 --- a/Source/Core/DebuggerWX/Src/MemoryView.cpp +++ b/Source/Core/DebuggerWX/Src/MemoryView.cpp @@ -289,7 +289,7 @@ void CMemoryView::OnPaint(wxPaintEvent& event) sprintf(dis, "f: %f", flt); char desc[256] = ""; - dc.DrawText(wxString::FromAscii(dis), 17+fontSize*(8+8), rowY1); + dc.DrawText(wxString::FromAscii(dis), 17 + fontSize*(8 + 8), rowY1); if (desc[0] == 0) { @@ -298,50 +298,14 @@ void CMemoryView::OnPaint(wxPaintEvent& event) dc.SetTextForeground(_T("#0000FF")); - //char temp[256]; - //UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE); if (strlen(desc)) { dc.DrawText(wxString::FromAscii(desc), 17+fontSize*(8+8+8+30), rowY1); } - - if (debugger->isBreakpoint(address)) - { - dc.SetBrush(bpBrush); - dc.DrawRectangle(2, rowY1 + 1, 11, 11); -// DrawIconEx(hdc, 2, rowY1, breakPoint, 32, 32, 0, 0, DI_NORMAL); - } } } dc.SetPen(currentPen); - /* - for (i = 0; i < numBranches; i++) - { - int x = 250 + (branches[i].srcAddr % 9) * 8; - MoveToEx(hdc, x-2, branches[i].src, 0); - - if (branches[i].dst < rect.bottom + 200 && branches[i].dst > -200) - { - LineTo(hdc, x+2, branches[i].src); - LineTo(hdc, x+2, branches[i].dst); - LineTo(hdc, x-4, branches[i].dst); - - MoveToEx(hdc, x, branches[i].dst - 4,0); - LineTo(hdc, x-4, branches[i].dst); - LineTo(hdc, x+1, branches[i].dst+5); - } - else - { - LineTo(hdc, x+4, branches[i].src); - //MoveToEx(hdc,x+2,branches[i].dst-4,0); - //LineTo(hdc,x+6,branches[i].dst); - //LineTo(hdc,x+1,branches[i].dst+5); - } - //LineTo(hdc,x,branches[i].dst+4); - - //LineTo(hdc,x-2,branches[i].dst); - }*/ }