Skip to content

Commit

Permalink
add ref test for sprite and support nested bitfields in static data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
water111 authored Jul 27, 2021
1 parent 92a5d84 commit bd9f550
Show file tree
Hide file tree
Showing 18 changed files with 1,535 additions and 258 deletions.
7 changes: 7 additions & 0 deletions decompiler/IR2/Form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ goos::Object SetFormFormElement::to_form_internal(const Env& env) const {

goos::Object SetFormFormElement::to_form_for_define(const Env& env) const {
if (m_cast_for_define) {
// for vu-function, we just put a 0. These aren't supported
if (*m_cast_for_define == TypeSpec("vu-function")) {
return pretty_print::build_list(
fmt::format("define"), m_dst->to_form(env),
pretty_print::build_list(fmt::format("the-as {}", m_cast_for_define->print()),
pretty_print::to_symbol("0")));
}
return pretty_print::build_list(
fmt::format("define"), m_dst->to_form(env),
pretty_print::build_list(fmt::format("the-as {}", m_cast_for_define->print()),
Expand Down
9 changes: 8 additions & 1 deletion decompiler/IR2/bitfields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,14 @@ BitFieldDef BitFieldDef::from_constant(const BitFieldConstantDef& constant, Form
BitFieldDef bfd;
bfd.field_name = constant.field_name;
bfd.is_signed = constant.is_signed;
if (constant.enum_constant) {
if (constant.nested_field) {
std::vector<BitFieldDef> defs;
for (auto& x : constant.nested_field->fields) {
defs.push_back(BitFieldDef::from_constant(x, pool));
}
bfd.value = pool.alloc_single_element_form<BitfieldStaticDefElement>(
nullptr, constant.nested_field->field_type, defs);
} else if (constant.enum_constant) {
bfd.value =
pool.alloc_single_element_form<ConstantTokenElement>(nullptr, *constant.enum_constant);
} else {
Expand Down
7 changes: 4 additions & 3 deletions decompiler/config/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@
(water-tex1 60)
;; merc1 61
;; generic1 62
(depth-cue 64)
(bucket-65 65)
(sprite 66)
;; debug spheres? 67
Expand Down Expand Up @@ -5075,7 +5076,7 @@
(define-extern math-cam-start-smoothing (function float float quaternion))
(define-extern move-target-from-pad (function transform int transform))
(define-extern transform-point-vector! (function vector vector symbol))
(define-extern transform-point-qword! (function vector vector symbol))
(define-extern transform-point-qword! (function vector4w vector symbol))
(define-extern transform-point-vector-scale! (function vector vector float))
(define-extern init-for-transform (function matrix none))

Expand Down Expand Up @@ -15698,15 +15699,15 @@

;; - Functions

(define-extern depth-cue-draw-front function)
(define-extern depth-cue-draw-front (function dma-buffer int float float uint int none))
(define-extern depth-cue-set-stencil function)
(define-extern depth-cue-draw-depth function)
(define-extern depth-cue-calc-z function)
(define-extern depth-cue (function display none))

;; - Unknowns

;;(define-extern *depth-cue-work* object) ;; unknown type
(define-extern *depth-cue-work* depth-cue-work)


;; ----------------------
Expand Down
9 changes: 3 additions & 6 deletions decompiler/config/jak1_ntsc_black_label/hacks.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@
// vector
"vector=", // asm branching

// texture
// "adgif-shader<-texture-with-update!", // F: asm branching
// "(method 9 texture-page-dir)",

// collide-mesh-h
"(method 11 collide-mesh-cache)",

Expand All @@ -117,6 +113,9 @@
"clear-frame-accumulator", // F: asm branching
"cspace<-parented-transformq-joint!",

// sprite
"add-to-sprite-aux-list", // fine, but don't know types yet.

// merc-blend-shape
"setup-blerc-chains-for-one-fragment", // F: asm branching
"blerc-execute", // F: asm branching
Expand Down Expand Up @@ -526,8 +525,6 @@

"(method 12 perf-stat)": [0],
"(method 11 perf-stat)": [0],
"(method 20 actor-link-info)": [2],
"(method 21 actor-link-info)": [2],
"raw-ray-sphere-intersect": [0, 1, 2, 3, 4, 5],
"ray-cylinder-intersect": [0, 1, 2, 3, 4, 5],
"ray-triangle-intersect": [0, 1, 2, 3, 4],
Expand Down
3 changes: 2 additions & 1 deletion decompiler/config/jak1_ntsc_black_label/label_types.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,8 @@
["L509", "(inline-array list-field)", true, 12],
["L123", "_lambda_", true],
["L119", "_lambda_", true],
["L86", "_lambda_", true]
["L86", "_lambda_", true],
["L652", "float", true]
],

// please do not add things after this entry! git is dumb.
Expand Down
60 changes: 34 additions & 26 deletions decompiler/config/jak1_ntsc_black_label/type_casts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -1266,28 +1266,28 @@
[23, "v1", "float"],
[36, "v1", "uint"]
],

"(method 0 anim-test-obj)": [
[9, "s4", "anim-test-obj"],
[10, "s4", "anim-test-obj"],
[13, "s4", "anim-test-obj"],
[15, "s4", "anim-test-obj"]
],

"(method 0 anim-test-sequence)": [
[8, "s5", "anim-test-sequence"],
[11, "s5", "anim-test-sequence"],
[13, "s5", "anim-test-sequence"]
],

"(method 0 anim-test-seq-item)": [
[8, "v1", "anim-test-seq-item"],
[10, "v0", "anim-test-seq-item"],
[11, "v0", "anim-test-seq-item"],
[14, "v0", "anim-test-seq-item"],
[17, "v0", "anim-test-seq-item"]
],

"(method 3 anim-tester)": [
[12, "s5", "anim-test-obj"],
[15, "s5", "anim-test-obj"],
Expand All @@ -1311,7 +1311,7 @@
[126, "s3", "anim-test-seq-item"],
[128, "s3", "anim-test-seq-item"]
],

"anim-test-obj-item-valid?": [
[5, "s5", "anim-test-sequence"],
[12, "s5", "anim-test-sequence"],
Expand All @@ -1322,7 +1322,7 @@
[26, "v1", "anim-test-seq-item"],
[28, "v1", "anim-test-seq-item"]
],

"anim-test-obj-remove-invalid": [
[84, "v1", "anim-test-sequence"],
[88, "v1", "anim-test-sequence"],
Expand Down Expand Up @@ -1350,7 +1350,7 @@
[36, "s3", "anim-test-seq-item"],
[61, "a0", "anim-test-seq-item"]
],

"anim-tester-reset": [
[14, "v1", "anim-test-obj"],
[30, "v1", "anim-test-obj"],
Expand All @@ -1359,12 +1359,12 @@
[43, "v1", "anim-test-obj"],
[[50, 53], "v1", "anim-test-obj"]
],

"anim-tester-save-all-objects": [
[[4, 19], "gp", "anim-test-obj"],
[17, "v1", "anim-test-obj"]
],

"anim-tester-save-object-seqs": [
[63, "s5", "anim-test-sequence"],
[69, "s5", "anim-test-sequence"],
Expand All @@ -1386,15 +1386,15 @@
[121, "v1", "anim-test-seq-item"],
[122, "s4", "anim-test-seq-item"]
],

"anim-test-obj-list-handler": [
[25, "s5", "anim-test-obj"],
[31, "s5", "anim-test-obj"],
[110, "s5", "anim-test-obj"],
[166, "s5", "anim-test-obj"],
[112, "v1", "anim-tester"]
],

"anim-test-anim-list-handler": [
[2, "s5", "anim-test-obj"],
[25, "s5", "anim-test-obj"],
Expand All @@ -1413,7 +1413,7 @@
[171, "v1", "anim-test-obj"],
[173, "v1", "anim-test-obj"]
],

"anim-test-sequence-list-handler": [
[2, "s5", "anim-test-sequence"],
[25, "s5", "anim-test-sequence"],
Expand All @@ -1429,7 +1429,7 @@
[146, "v1", "anim-test-sequence"],
[151, "v1", "anim-test-sequence"]
],

"anim-test-edit-sequence-list-handler": [
[[122, 965], "s4", "anim-test-sequence"],
[129, "v1", "glst-named-node"],
Expand All @@ -1442,21 +1442,21 @@
[491, "s3", "anim-test-seq-item"],
[502, "s3", "anim-test-seq-item"]
],

"anim-tester-interface": [
[[34, 48], "gp", "anim-test-obj"],
[[95, 109], "gp", "anim-test-obj"],
[[156, 160], "v1", "anim-test-obj"],
[[162, 165], "v1", "anim-test-sequence"]
],

"anim-tester-get-playing-item": [
[7, "v0", "anim-test-seq-item"],
[[5, 22], "s5", "anim-test-seq-item"],
[21, "v0", "anim-test-seq-item"],
[25, "v0", "anim-test-seq-item"]
],

"anim-tester-add-newobj": [
[[2, 185], "s2", "anim-test-obj"],
[[70, 193], "s5", "anim-test-obj"],
Expand All @@ -1466,20 +1466,16 @@
[164, "a0", "art-joint-anim"],
[170, "a0", "art-joint-anim"]
],

"anim-tester-start": [
[20, "t9", "(function process function none)"]
],


"anim-tester-start": [[20, "t9", "(function process function none)"]],

"anim-tester-set-name": [
[[34, 51], "s3", "anim-test-obj"],
[[40, 63], "s5", "anim-test-sequence"]
],

"anim-tester-add-sequence": [
[[33, 102], "s5", "anim-test-obj"]
],


"anim-tester-add-sequence": [[[33, 102], "s5", "anim-test-obj"]],

"(anon-function 11 anim-tester)": [
[[23, 113], "s4", "anim-test-obj"],
[[83, 338], "gp", "anim-test-sequence"],
Expand Down Expand Up @@ -1579,5 +1575,17 @@
[[62, 67], "a1", "dma-packet"]
],

"sprite-draw-distorters": [
[[70, 90], "a0", "vector"],
[72, "v1", "vector"],
[93, "v1", "vector"],
[96, "v1", "vector"],
[115, "v1", "(pointer int32)"],
[119, "a0", "(pointer int32)"],
[124, "v1", "vector"],
[154, "v1", "vector"],
[[172, 189], "a1", "dma-packet"]
],

"placeholder-do-not-add-below": []
}
1 change: 1 addition & 0 deletions decompiler/config/jak1_ntsc_black_label/var_names.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,7 @@
},

"add-debug-point": {
"args": ["enable-draw", "bucket", "pt"],
"vars": {
"a0-6": ["a0-6", "(pointer uint64)"],
"a0-7": ["a0-7", "dma-packet"],
Expand Down
8 changes: 8 additions & 0 deletions decompiler/util/data_decompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,14 @@ std::optional<std::vector<BitFieldConstantDef>> try_decompile_bitfield_from_int(
auto name = decompile_int_enum_from_int(field.type(), ts, bitfield_value);
def.enum_constant = fmt::format("({} {})", field.type().print(), name);
}

auto nested_bitfield_type = dynamic_cast<BitFieldType*>(ts.lookup_type(field.type()));
if (nested_bitfield_type) {
BitFieldConstantDef::NestedField nested;
nested.field_type = field.type();
nested.fields = *try_decompile_bitfield_from_int(field.type(), ts, bitfield_value, true);
def.nested_field = nested;
}
result.push_back(def);
}

Expand Down
7 changes: 7 additions & 0 deletions decompiler/util/data_decompile.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ struct BitFieldConstantDef {
u64 value = -1;
std::optional<std::string> enum_constant;
std::string field_name;

struct NestedField {
TypeSpec field_type;
std::vector<BitFieldConstantDef> fields;
};

std::optional<NestedField> nested_field;
};

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion goal_src/engine/camera/math-camera.gc
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@
)
)

(defun transform-point-qword! ((arg0 vector) (arg1 vector))
(defun transform-point-qword! ((arg0 vector4w) (arg1 vector))
"Apply camera transformation to point, returning fixed point 28.4 position"
(rlet ((acc :class vf)
(Q :class vf)
Expand Down
Loading

0 comments on commit bd9f550

Please sign in to comment.