Skip to content

Commit

Permalink
Merge pull request #4469 from sepalani/fix_xfb_debug
Browse files Browse the repository at this point in the history
[HLE] Fixes XFB issues in Debug Mode
  • Loading branch information
Helios747 committed Apr 29, 2017
2 parents 4245ed8 + f392e47 commit ecf5f7d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
35 changes: 22 additions & 13 deletions Source/Core/Core/HLE/HLE.cpp
Expand Up @@ -55,17 +55,17 @@ static const SPatch OSPatches[] = {
{"OSPanic", HLE_OS::HLE_OSPanic, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG},

// This needs to be put before vprintf (because vprintf is called indirectly by this)
{"JUTWarningConsole_f", HLE_OS::HLE_GeneralDebugPrint, 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},
{"nlPrintf", 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", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, // used for early init things (normally)
{"__write_console", HLE_OS::HLE_write_console, HLE_HOOK_REPLACE, HLE_TYPE_DEBUG}, // used by sysmenu (+more?)
{"JUTWarningConsole_f", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG},

{"OSReport", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG},
{"DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG},
{"WUD_DEBUGPrint", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG},
{"vprintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG},
{"printf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG},
{"nlPrintf", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG},
{"puts", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, // gcc-optimized printf?
{"___blank", HLE_OS::HLE_GeneralDebugPrint, HLE_HOOK_START, HLE_TYPE_DEBUG}, // used for early init things (normally)
{"__write_console", HLE_OS::HLE_write_console, HLE_HOOK_START, HLE_TYPE_DEBUG}, // used by sysmenu (+more?)

{"GeckoCodehandler", HLE_Misc::GeckoCodeHandlerICacheFlush, HLE_HOOK_START, HLE_TYPE_FIXED},
{"GeckoHandlerReturnTrampoline", HLE_Misc::GeckoReturnTrampoline, HLE_HOOK_REPLACE, HLE_TYPE_FIXED},
Expand Down Expand Up @@ -183,12 +183,21 @@ void Execute(u32 _CurrentPC, u32 _Instruction)
// OSPatches[pos].m_szPatchName);
}

u32 GetFunctionIndex(u32 addr)
u32 GetFunctionIndex(u32 address)
{
auto iter = s_original_instructions.find(addr);
auto iter = s_original_instructions.find(address);
return (iter != s_original_instructions.end()) ? iter->second : 0;
}

u32 GetFirstFunctionIndex(u32 address)
{
u32 index = GetFunctionIndex(address);
auto first = std::find_if(
s_original_instructions.begin(), s_original_instructions.end(),
[=](const auto& entry) { return entry.second == index && entry.first < address; });
return first == std::end(s_original_instructions) ? index : 0;
}

int GetFunctionTypeByIndex(u32 index)
{
return OSPatches[index].type;
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/Core/HLE/HLE.h
Expand Up @@ -34,7 +34,10 @@ u32 UnPatch(const std::string& patchName);
bool UnPatch(u32 addr, const std::string& name = {});
void Execute(u32 _CurrentPC, u32 _Instruction);

u32 GetFunctionIndex(u32 em_address);
// Returns the HLE function index if the address is located in the function
u32 GetFunctionIndex(u32 address);
// Returns the HLE function index if the address matches the function start
u32 GetFirstFunctionIndex(u32 address);
int GetFunctionTypeByIndex(u32 index);
int GetFunctionFlagsByIndex(u32 index);

Expand Down
Expand Up @@ -205,7 +205,7 @@ void CachedInterpreter::Jit(u32 address)
{
js.downcountAmount += ops[i].opinfo->numCycles;

u32 function = HLE::GetFunctionIndex(ops[i].address);
u32 function = HLE::GetFirstFunctionIndex(ops[i].address);
if (function != 0)
{
int type = HLE::GetFunctionTypeByIndex(function);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp
Expand Up @@ -100,7 +100,7 @@ static void Trace(UGeckoInstruction& inst)
int Interpreter::SingleStepInner()
{
static UGeckoInstruction instCode;
u32 function = HLE::GetFunctionIndex(PC);
u32 function = HLE::GetFirstFunctionIndex(PC);
if (function != 0)
{
int type = HLE::GetFunctionTypeByIndex(function);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/Jit64/Jit.cpp
Expand Up @@ -797,7 +797,7 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc
SetJumpTarget(noExtIntEnable);
}

u32 function = HLE::GetFunctionIndex(ops[i].address);
u32 function = HLE::GetFirstFunctionIndex(ops[i].address);
if (function != 0)
{
int type = HLE::GetFunctionTypeByIndex(function);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/Jit64IL/JitIL.cpp
Expand Up @@ -604,7 +604,7 @@ const u8* JitIL::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc
if (i == (code_block.m_num_instructions - 1))
js.isLastInstruction = true;

u32 function = HLE::GetFunctionIndex(ops[i].address);
u32 function = HLE::GetFirstFunctionIndex(ops[i].address);
if (function != 0)
{
int type = HLE::GetFunctionTypeByIndex(function);
Expand Down

0 comments on commit ecf5f7d

Please sign in to comment.