From e630c828c3281cfba9135eaced88e7825deed5fb Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sun, 8 Jan 2017 10:34:10 +0300 Subject: [PATCH] [rsx/wip] Implement BRB opcode (test 1) --- .../RSX/Common/VertexProgramDecompiler.cpp | 32 +++++++++++++++---- .../Emu/RSX/Common/VertexProgramDecompiler.h | 1 + 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp b/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp index f073f6e1e3..8229f7f326 100644 --- a/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.cpp @@ -216,12 +216,22 @@ std::string VertexProgramDecompiler::Format(const std::string& code) return "if(" + cond + ") "; } }, - { "$cond", std::bind(std::mem_fn(&VertexProgramDecompiler::GetCond), this) } + { "$cond", std::bind(std::mem_fn(&VertexProgramDecompiler::GetCond), this) }, + { "$bconst", std::bind(std::mem_fn(&VertexProgramDecompiler::GetBooleanConstantCond), this) } }; return fmt::replace_all(code, repl_list); } +std::string VertexProgramDecompiler::GetBooleanConstantCond() +{ + if (d0.cond == 0) return "false"; + if (d0.cond == 7) return "true"; + + LOG_ERROR(RSX, "Boolean constant condition not found; returning false"); + return "false"; +} + std::string VertexProgramDecompiler::GetCond() { enum @@ -476,15 +486,15 @@ std::string VertexProgramDecompiler::Decompile() switch (d1.sca_opcode) { - case 0x08: //BRA - LOG_ERROR(RSX, "BRA found. Please report to RPCS3 team."); + case RSX_SCA_OPCODE_BRA: + case RSX_SCA_OPCODE_BRB: is_has_BRA = true; m_jump_lvls.clear(); d3.HEX = m_data[++i]; i += 4; break; - case 0x09: //BRI + case RSX_SCA_OPCODE_BRI: d2.HEX = m_data[i++]; d3.HEX = m_data[i]; i += 2; @@ -635,7 +645,7 @@ std::string VertexProgramDecompiler::Decompile() } } - AddCode("$ifcond "); + AddCode("$ifcond //BRI"); AddCode("{"); m_cur_instr->open_scopes++; AddCode(fmt::format("jump_position = %u;", jump_position)); @@ -662,11 +672,21 @@ std::string VertexProgramDecompiler::Decompile() case RSX_SCA_OPCODE_COS: SetDSTSca("cos($s)"); break; case RSX_SCA_OPCODE_BRB: // works differently (BRB o[1].x !b0, L0;) - LOG_ERROR(RSX, "Unimplemented sca_opcode BRB"); + LOG_ERROR(RSX, "Unimplemented sca_opcode BRB d0=0x%X, d1=0x%X, d2=0x%X, d3=0x%X"); + + AddCode("$if (!$bconst) //BRB"); //If only the cond flags are set, we can just use $ifcond + AddCode("{"); + m_cur_instr->open_scopes++; + AddCode("jump_position = $a$am;"); + AddCode("continue;"); + m_cur_instr->close_scopes++; + AddCode("}"); + break; case RSX_SCA_OPCODE_CLB: break; // works same as BRB LOG_ERROR(RSX, "Unimplemented sca_opcode CLB"); + AddCode("$if (!$bconst) $f(); //CLB"); break; case RSX_SCA_OPCODE_PSH: break; // works differently (PSH o[1].x A0;) diff --git a/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.h b/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.h index d0d99c72fb..0cb1a3f350 100644 --- a/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.h +++ b/rpcs3/Emu/RSX/Common/VertexProgramDecompiler.h @@ -69,6 +69,7 @@ struct VertexProgramDecompiler std::string GetFunc(); std::string GetTex(); std::string GetCond(); + std::string GetBooleanConstantCond(); std::string AddAddrMask(); std::string AddAddrReg(); std::string AddAddrRegWithoutMask();