Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[decomp] decompile sprite-distort without vu1 stuff #759

Merged
merged 8 commits into from
Aug 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions decompiler/IR2/AtomicOpTypeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,20 @@ TypeState AsmOp::propagate_types_internal(const TypeState& input,
}
}

// srl out, bitfield, int
if (m_instr.kind == InstructionKind::SRL) {
auto type = dts.ts.lookup_type(result.get(m_src[0]->reg()).typespec());
auto as_bitfield = dynamic_cast<BitFieldType*>(type);
if (as_bitfield) {
int sa = m_instr.src[1].get_imm();
int offset = sa;
int size = 32 - offset;
auto field = find_field(dts.ts, as_bitfield, offset, size, {});
result.get(m_dst->reg()) = TP_Type::make_from_ts(coerce_to_reg_type(field.type()));
return result;
}
}

if (m_dst.has_value()) {
auto kind = m_dst->reg().get_kind();
if (kind == Reg::FPR) {
Expand Down
72 changes: 49 additions & 23 deletions decompiler/analysis/final_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,11 @@ std::string add_indent(const std::string& in, int indent, bool indent_first_line
return result;
}

std::string write_from_top_level(const Function& top_level,
const DecompilerTypeSystem& dts,
const LinkedObjectFile& file,
const std::unordered_set<std::string>& skip_functions) {
auto top_form = top_level.ir2.top_form;
if (!top_form) {
return ";; ERROR: top level function was not converted to expressions. Cannot decompile.\n\n";
}

auto& env = top_level.ir2.env;
if (!env.has_type_analysis()) {
return ";; ERROR: top level has no type analysis. Cannot decompile.\n\n";
}

if (!env.has_local_vars()) {
return ";; ERROR: top level has no local vars. Cannot decompile.\n\n";
}

if (!env.has_reg_use()) {
return ";; ERROR: top level has no register use analysis. Cannot decompile.\n\n";
}

std::string write_from_top_level_form(Form* top_form,
const DecompilerTypeSystem& dts,
const LinkedObjectFile& file,
const std::unordered_set<std::string>& skip_functions,
const Env& env) {
std::vector<FormElement*> forms = top_form->elts();
assert(!forms.empty());

Expand All @@ -232,7 +215,7 @@ std::string write_from_top_level(const Function& top_level,

std::string result;
// local vars:
auto var_dec = env.local_var_type_list(top_level.ir2.top_form, 0);
auto var_dec = env.local_var_type_list(top_form, 0);
if (var_dec.local_vars) {
result += pretty_print::to_string(*var_dec.local_vars);
result += '\n';
Expand Down Expand Up @@ -424,6 +407,24 @@ std::string write_from_top_level(const Function& top_level,
}
}

if (!something_matched) {
auto as_cne = f.try_as_element<CondNoElseElement>();
if (as_cne && as_cne->entries.size() == 1) {
auto& entry = as_cne->entries.at(0);
// a bit gross...
if (entry.condition->to_string(env) == "*debug-segment*") {
something_matched = true;
// forms = entry.body->elts();
result += ";; this part is debug only\n";
result += "(when *debug-segment*\n";

result += write_from_top_level_form(entry.body, dts, file, skip_functions, env);

result += ")\n";
}
}
}

if (!something_matched) {
auto empty = dynamic_cast<EmptyElement*>(x);
if (empty) {
Expand All @@ -450,4 +451,29 @@ std::string write_from_top_level(const Function& top_level,

return result;
}

std::string write_from_top_level(const Function& top_level,
const DecompilerTypeSystem& dts,
const LinkedObjectFile& file,
const std::unordered_set<std::string>& skip_functions) {
auto top_form = top_level.ir2.top_form;
if (!top_form) {
return ";; ERROR: top level function was not converted to expressions. Cannot decompile.\n\n";
}

auto& env = top_level.ir2.env;
if (!env.has_type_analysis()) {
return ";; ERROR: top level has no type analysis. Cannot decompile.\n\n";
}

if (!env.has_local_vars()) {
return ";; ERROR: top level has no local vars. Cannot decompile.\n\n";
}

if (!env.has_reg_use()) {
return ";; ERROR: top level has no register use analysis. Cannot decompile.\n\n";
}

return write_from_top_level_form(top_form, dts, file, skip_functions, env);
}
} // namespace decompiler
63 changes: 51 additions & 12 deletions decompiler/config/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -5201,14 +5201,53 @@
:flag-assert #x900000010
)

(defenum font-color
:type uint64
(default 0)
(white 1)
(gray 2)
(orange-red 3)
(bright-orange-red 4)
(dark-yellow 5)
(bright-green 6)
(dark-blue 7)
(light-blue 8)
(dark-pink 9)
(lighter-blue 10)
(dark-light-blue 11)
(dim-white 12)
(dim-gray 13)
(orange-red-2 14)
(yellow-green 15)
(dark-green 16)
(another-gray 17)
(dark-dark-green 18)
(flat-dark-purple 19)
(yellow 20)
(blue-white 21)
(flat-dark-gray 22)
(flat-gray 23)
(flat-pink 24)
(flat-red 25)
(flat-green 26)
(flat-purple 27)
(lighter-lighter-blue 28)
(yellow-orange 29)
(yellow-green-2 30)
(another-light-blue 31)
(another-default 32)
(red-orange 33)
(another-orange-red 34)
)

(deftype font-context (basic)
((origin vector :inline :offset-assert 16)
(strip-gif vector :inline :offset-assert 32)
(width float :offset-assert 48)
(height float :offset-assert 52)
(projection float :offset-assert 56)
(context-vec vector :inline :offset 48) ;; added
(color int64 :offset-assert 64)
(color font-color :offset-assert 64)
(color-s32 int32 :offset 64) ;; added for asm
(flags uint32 :offset-assert 72)
(flags-signed int32 :offset 72) ;; added for asm
Expand All @@ -5220,15 +5259,15 @@
:size-assert #x58
:flag-assert #x1400000058
(:methods
(new (symbol type matrix int int float int uint) _type_ 0)
(new (symbol type matrix int int float font-color uint) _type_ 0)
(set-mat! (font-context matrix) font-context 9)
(set-origin! (font-context int int) font-context 10)
(set-depth! (font-context int) font-context 11)
(set-w! (font-context float) font-context 12)
(set-width! (font-context int) font-context 13)
(set-height! (font-context int) font-context 14)
(set-projection! (font-context float) font-context 15)
(set-color! (font-context int) font-context 16)
(set-color! (font-context font-color) font-context 16)
(set-flags! (font-context uint) font-context 17)
(set-start-line! (font-context uint) font-context 18)
(set-scale! (font-context float) font-context 19)
Expand Down Expand Up @@ -5264,9 +5303,9 @@
(justify vector 64 :inline :offset-assert 944)
(color-shadow vector4w :inline :offset-assert 1968)
(color-table char-color 64 :inline :offset-assert 1984)
(last-color uint64 :offset-assert 3008)
(last-color font-color :offset-assert 3008)
(last-color-32 int32 :offset 3008)
(save-last-color uint64 :offset-assert 3016)
(save-last-color font-color :offset-assert 3016)
(save-last-color-32 int32 :offset 3016) ;; added
(buf basic :offset-assert 3024)
(str-ptr uint32 :offset-assert 3028)
Expand Down Expand Up @@ -5324,7 +5363,7 @@
(define-extern set-display-env (function display-env int int int int int int display-env))
(define-extern set-draw-env (function draw-env int int int int int int draw-env))
(define-extern get-video-mode (function symbol))
(define-extern draw-string-xy (function string dma-buffer int int int int none))
(define-extern draw-string-xy (function string dma-buffer int int font-color int none))
(define-extern set-draw-env-offset (function draw-env int int int draw-env))
(define-extern put-display-alpha-env (function display-env none))
(define-extern set-display2 (function display int int int int int display))
Expand Down Expand Up @@ -15100,7 +15139,7 @@
((flags int32 :offset-assert 0)
(bucket bucket-id :offset-assert 4)
(pos vector :inline :offset-assert 16)
(color uint64 :offset-assert 32)
(color font-color :offset-assert 32)
(offset vector2h :inline :offset-assert 40)
(str string :offset-assert 44)
)
Expand All @@ -15123,16 +15162,16 @@
(define-extern debug-set-camera-pos-rot! (function vector matrix int))
(define-extern drawable-frag-count (function drawable int))
(define-extern add-debug-light (function symbol bucket-id light vector string symbol))
(define-extern add-debug-text-3d (function symbol bucket-id string vector rgba vector2h symbol))
(define-extern add-debug-text-3d (function symbol bucket-id string vector font-color vector2h symbol))
(define-extern add-debug-x (function symbol bucket-id vector rgba symbol))
(define-extern add-debug-curve (function symbol bucket-id pointer int (inline-array vector) int rgba symbol))
(define-extern add-debug-sphere (function symbol bucket-id vector float rgba symbol))
(define-extern get-debug-text-3d (function debug-text-3d))
(define-extern internal-draw-debug-text-3d (function bucket-id string vector rgba vector2h pointer))
(define-extern internal-draw-debug-text-3d (function bucket-id string vector font-color vector2h pointer))
(define-extern get-debug-line (function debug-line))
(define-extern internal-draw-debug-line (function bucket-id vector vector rgba symbol rgba pointer))
(define-extern draw-string (function string dma-buffer font-context float))
(define-extern transform-float-point (function vector vector vector))
(define-extern transform-float-point (function vector vector4w vector4w))
(define-extern add-debug-point (function symbol bucket-id vector symbol)) ;; unused
(define-extern add-debug-outline-triangle (function symbol bucket-id vector vector vector rgba symbol))
(define-extern add-debug-triangle-normal (function symbol bucket-id vector vector vector rgba symbol))
Expand All @@ -15141,7 +15180,7 @@
(define-extern debug-draw-buffers (function symbol))
(define-extern add-debug-line2d (function symbol bucket-id vector vector vector symbol))
(define-extern add-debug-box (function symbol bucket-id vector vector rgba symbol))
(define-extern add-debug-sphere-with-transform (function symbol bucket-id vector float matrix rgba symbol))
(define-extern add-debug-sphere-with-transform (function symbol bucket-id vector meters matrix rgba symbol))
(define-extern add-debug-spheres (function symbol bucket-id (inline-array vector) int rgba symbol))
(define-extern add-debug-circle (function symbol bucket-id vector float rgba matrix symbol))
(define-extern add-debug-rot-matrix (function symbol bucket-id matrix vector matrix))
Expand Down Expand Up @@ -17367,7 +17406,7 @@

;; - Functions

(define-extern set-font-color-alpha (function int int none))
(define-extern set-font-color-alpha (function font-color int none))
(define-extern load-game-text-info (function string symbol kheap int))
(define-extern load-level-text-files (function int none))
(define-extern draw-debug-text-box (function font-context none))
Expand Down
9 changes: 8 additions & 1 deletion decompiler/config/jak1_ntsc_black_label/type_casts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -1652,7 +1652,14 @@
[119, "a0", "(pointer int32)"],
[124, "v1", "vector"],
[154, "v1", "vector"],
[[172, 189], "a1", "dma-packet"]
[[172, 189], "a1", "dma-packet"],
[[199, 203], "a0", "dma-packet"],
[[207, 211], "a0", "vector4w"],
[[216, 221], "a0", "dma-packet"],
[[248, 265], "a1", "dma-packet"],
[[273, 277], "a1", "dma-packet"],
[[281, 285], "a1", "vector4w"],
[[289, 294], "v1", "dma-packet"]
],

"debug-menu-make-from-template": [
Expand Down
Loading