From 432dcbb2535477893c9ff948291aa561b261bc33 Mon Sep 17 00:00:00 2001 From: DHrpcs3 Date: Sun, 13 Dec 2015 19:48:13 +0200 Subject: [PATCH] Fragment program decompiler: implemented LOOP instruction --- .gitignore | 9 +++++++++ rsx_decompiler/rsx_decompiler.cpp | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b8bd026..c497898 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,12 @@ *.exe *.out *.app + + +*.suo +*.ipch +*.VC.db +*.VC.opendb +bin/* +lib/* +tmp/* diff --git a/rsx_decompiler/rsx_decompiler.cpp b/rsx_decompiler/rsx_decompiler.cpp index c37a7c2..099c014 100644 --- a/rsx_decompiler/rsx_decompiler.cpp +++ b/rsx_decompiler/rsx_decompiler.cpp @@ -636,13 +636,27 @@ namespace rsx case opcode::BRK: return conditional(expression_from("break")); case opcode::CAL: return unimplemented("CAL"); case opcode::IFE: + writer += writer_t{ "if (" + all(execution_condition()).to_string() + ")\n{\n" }; + if (instruction.data.src2.end_offset != instruction.data.src1.else_offset) writer.before(instruction.data.src1.else_offset >> 2, "}\nelse\n{\n"); + writer.after(instruction.data.src2.end_offset >> 2, "}\n"); - return writer_t{ "if (" + all(execution_condition()).to_string() + ")\n{\n" }; + return ""; - case opcode::LOOP: return unimplemented("LOOP"); + case opcode::LOOP: + writer += writer_t + { + "for (" + "int i = " + std::to_string(instruction.data.src1.init_counter) + "; " + + "i < " + std::to_string(instruction.data.src1.end_counter) + "; " + + (instruction.data.src1.increment == 1 ? "i++" : "i += " + std::to_string(instruction.data.src1.increment)) + + ")\n{\n" + }; + + writer.after(instruction.data.src2.end_offset >> 2, "}\n"); + return ""; case opcode::REP: return unimplemented("REP"); case opcode::RET: return conditional(expression_from("return")); }