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: main-collide and support a bunch of new inline-asm operations #673

Merged
merged 8 commits into from
Jul 27, 2021
Merged
29 changes: 22 additions & 7 deletions decompiler/IR2/OpenGoalMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,28 @@ const std::map<InstructionKind, OpenGOALAsm::Function> MIPS_ASM_TO_OPEN_GOAL_FUN
{InstructionKind::PSRAW, {".pw.sra", {}}},
{InstructionKind::PSUBW, {".psubw", {}}},

// Boolean Arithmetic - or / not or / and
{InstructionKind::POR, {".por", {}}},
{InstructionKind::PNOR, {".pnor", {}}},
{InstructionKind::PAND, {".pand", {}}},

// Parallel Pack
{InstructionKind::PPACH, {".ppach", {}}},

// Parallel Compares
{InstructionKind::PCEQB, {".pceqb", {}}},
// {InstructionKind::PCEQH, {".pceqh", {}}},
{InstructionKind::PCEQW, {".pceqw", {}}},
// {InstructionKind::PCGTB, {".pcgtb", {}}},
// {InstructionKind::PCGTH, {".pcgth", {}}},
{InstructionKind::PCGTW, {".pcgtw", {}}},

// Parallel Extends
{InstructionKind::PEXTUB, {".pextub", {}}},
{InstructionKind::PEXTUH, {".pextuh", {}}},
{InstructionKind::PEXTUW, {".pextuw", {}}},
{InstructionKind::PEXTLB, {".pextlb", {}}},
{InstructionKind::PEXTLH, {".pextlh", {}}},
{InstructionKind::PEXTLW, {".pextlw", {}}},
{InstructionKind::PCPYLD, {".pcpyld", {}}},
{InstructionKind::PCPYUD, {".pcpyud", {}}},
Expand Down Expand Up @@ -113,13 +130,11 @@ const std::map<InstructionKind, OpenGOALAsm::Function> MIPS_ASM_TO_OPEN_GOAL_FUN
//// Fixed point conversions
{InstructionKind::VFTOI0, {".ftoi.vf", {MOD::DEST_MASK}}},
{InstructionKind::VITOF0, {".itof.vf", {MOD::DEST_MASK}}},

{InstructionKind::VFTOI4, {"TODO.VFTOI4", {}}},

{InstructionKind::VITOF12, {"TODO.VITOF12", {}}},
{InstructionKind::VFTOI12, {"TODO.VFTOI12", {}}},

{InstructionKind::VITOF15, {"TODO.VITOF15", {}}},
// NOTE - Only the .xyzw mask is supported via macros!
{InstructionKind::VFTOI4, {"vftoi4.xyzw", {MOD::DEST_MASK}}},
{InstructionKind::VITOF12, {"vitof12.xyzw", {MOD::DEST_MASK}}},
{InstructionKind::VFTOI12, {"vftoi12.xyzw", {MOD::DEST_MASK}}},
{InstructionKind::VITOF15, {"vitof15.xyzw", {MOD::DEST_MASK}}},

//// Status Checks
{InstructionKind::VCLIP, {"TODO.VCLIP", {}}},
Expand Down
2 changes: 1 addition & 1 deletion decompiler/ObjectFile/LinkedObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,4 +961,4 @@ const DecompilerLabel& LinkedObjectFile::get_label_by_name(const std::string& na
}
throw std::runtime_error("Cannot find label " + name);
}
} // namespace decompiler
} // namespace decompiler
8 changes: 4 additions & 4 deletions decompiler/config/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -15793,7 +15793,7 @@

(define-extern collide-cache-using-line-sphere-test function)
(define-extern collide-cache-using-y-probe-test function)
(define-extern collide-cache-using-box-test function)
(define-extern collide-cache-using-box-test (function vector symbol))
(define-extern draw-node-cull function)


Expand Down Expand Up @@ -19481,9 +19481,9 @@

;; - Functions

(define-extern drawable-sphere-box-intersect? function)
(define-extern instance-sphere-box-intersect? function)
(define-extern instance-tfragment-add-debug-sphere function)
(define-extern drawable-sphere-box-intersect? (function drawable bounding-box4w symbol)) ;; TODO - pcgtw | por | ppach
(define-extern instance-sphere-box-intersect? (function drawable instance-tie bounding-box4w symbol)) ;; pextlh | VITOF12 | pcgtw | por | ppach ;; TODO - the first arg is based from the second arg in `drawable:11`
(define-extern instance-tfragment-add-debug-sphere (function drawable instance-tie symbol)) ;; unused


;; ----------------------
Expand Down
4 changes: 4 additions & 0 deletions decompiler/config/jak1_ntsc_black_label/label_types.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,10 @@
["L652", "float", true]
],

"main-collide": [
["L5", "rgba", true]
],

// please do not add things after this entry! git is dumb.
"object-file-that-doesnt-actually-exist-and-i-just-put-this-here-to-prevent-merge-conflicts-with-this-file": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,12 @@
"anim-tester-add-newobj": [[16, "event-message-block"]],
"anim-tester-start": [[16, "event-message-block"]],
"anim-tester-add-sequence": [[16, "event-message-block"]],

"(anon-function 28 task-control)": [[16, "event-message-block"]],

"instance-tfragment-add-debug-sphere": [
[16, "vector"]
],

"placeholder-do-not-add-below!": []
}
224 changes: 224 additions & 0 deletions goal_src/engine/collide/main-collide.gc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,227 @@
;; name in dgo: main-collide
;; dgos: GAME, ENGINE

;; definition for function drawable-sphere-box-intersect?
;; WARN: Function may read a register that is not set: f31
;; Used lq/sq
(defun drawable-sphere-box-intersect? ((arg0 drawable) (arg1 bounding-box4w))
(local-vars
(r0-0 int)
(r0-1 int)
(r0-2 uint128)
(r0-3 int)
(v1-1 uint128)
(v1-2 uint128)
(v1-3 uint128)
(a0-1 uint128)
(a1-2 uint128)
(a2-0 uint128)
(f31-0 none)
)
(rlet ((vf1 :class vf)
(vf2 :class vf)
(vf3 :class vf)
(vf4 :class vf)
)
(nop!)
(nop!)
(.lvf vf1 (&-> arg0 bsphere quad))
(.add.w.vf vf2 vf1 vf1 :mask #b111)
(let ((v1-0 (-> arg1 min quad)))
(.sub.w.vf vf1 vf1 vf1 :mask #b111)
(let ((a1-1 (-> arg1 max quad)))
(.ftoi.vf vf4 vf2)
(nop!)
(.ftoi.vf vf3 vf1)
(nop!)
(.mov a0-1 vf4)
(nop!)
(.mov a2-0 vf3)
(nop!)
(.pcgtw a1-2 a2-0 a1-1)
)
(.mov r0-0 f31-0)
(.pcgtw v1-1 v1-0 a0-1)
)
(.mov r0-1 f31-0)
(.por v1-2 a1-2 v1-1)
(.mov r0-2 f31-0)
(.ppach v1-3 r0-2 v1-2)
(.mov r0-3 f31-0)
(let ((v1-4 (shl (the-as int v1-3) 16)))
(nop!)
(zero? v1-4)
)
)
)

;; definition for function instance-sphere-box-intersect?
;; WARN: Function may read a register that is not set: f31
;; Used lq/sq
(defun
instance-sphere-box-intersect?
((arg0 drawable) (arg1 instance-tie) (arg2 bounding-box4w))
(local-vars
(r0-0 uint128)
(r0-1 int)
(r0-2 uint128)
(r0-3 int)
(r0-4 int)
(r0-5 uint128)
(r0-6 int)
(v1-3 uint128)
(v1-4 uint128)
(v1-5 uint128)
(a0-2 uint128)
(a1-2 uint128)
(a2-1 uint128)
(a3-1 uint128)
(a3-3 uint128)
(a3-4 uint128)
(t0-1 uint128)
(t0-2 uint128)
(t1-0 uint128)
(t2-1 uint128)
(t2-2 uint128)
(f31-0 none)
)
(rlet ((acc :class vf)
(vf0 :class vf)
(vf1 :class vf)
(vf10 :class vf)
(vf2 :class vf)
(vf3 :class vf)
(vf4 :class vf)
(vf5 :class vf)
(vf6 :class vf)
(vf7 :class vf)
(vf8 :class vf)
(vf9 :class vf)
)
(init-vf0-vector)
(nop!)
(let ((v1-0 (-> arg1 max-scale)))
(nop!)
(let ((a3-0 (the-as uint128 (-> arg1 origin vector4h 3 long))))
(nop!)
(let ((t2-0 (the-as uint128 (-> arg1 origin vector4h 0 long))))
(.pextlh a3-1 a3-0 r0-0)
(let ((t0-0 (the-as uint128 (-> arg1 origin vector4h 1 long))))
(.pw.sra t1-0 a3-1 10)
(let ((a3-2 (the-as uint128 (-> arg1 origin vector4h 2 long))))
(.pextlh t2-1 t2-0 r0-0)
(.mov r0-1 f31-0)
(.pw.sra t2-2 t2-1 16)
(.mov r0-2 f31-0)
(.pextlh t0-1 t0-0 r0-2)
(.mov vf8 t1-0)
(.pw.sra t0-2 t0-1 16)
(.mov vf5 t2-2)
(.pextlh a3-3 a3-2 r0-2)
)
)
)
)
(.mov vf6 t0-2)
(.pw.sra a3-4 a3-3 16)
(.lvf vf9 (&-> arg1 bsphere quad))
(nop!)
(.mov vf7 a3-4)
(nop!)
(.mov vf10 v1-0)
)
(.itof.vf vf8 vf8)
(nop!)
(vitof12.xyzw vf5 vf5)
(nop!)
(vitof12.xyzw vf6 vf6)
(nop!)
(vitof12.xyzw vf7 vf7)
(nop!)
(.add.vf vf8 vf8 vf9 :mask #b111)
(nop!)
(nop!)
(.lvf vf9 (&-> arg0 bsphere quad))
(vitof12.xyzw vf10 vf10)
(nop!)
(.mul.w.vf vf10 vf10 vf9 :mask #b1)
(nop!)
(.mul.x.vf acc vf5 vf9)
(nop!)
(.add.mul.y.vf acc vf6 vf9 acc)
(let ((v1-2 (-> arg2 min quad)))
(.add.mul.z.vf acc vf7 vf9 acc)
(let ((a1-1 (-> arg2 max quad)))
(.add.mul.w.vf vf1 vf8 vf0 acc)
(nop!)
(.add.x.vf vf2 vf1 vf10 :mask #b111)
(nop!)
(.sub.x.vf vf1 vf1 vf10 :mask #b111)
(nop!)
(.ftoi.vf vf4 vf2)
(nop!)
(.ftoi.vf vf3 vf1)
(nop!)
(.mov a0-2 vf4)
(nop!)
(.mov a2-1 vf3)
(nop!)
(.pcgtw a1-2 a2-1 a1-1)
)
(.mov r0-3 f31-0)
(.pcgtw v1-3 v1-2 a0-2)
)
(.mov r0-4 f31-0)
(.por v1-4 a1-2 v1-3)
(.mov r0-5 f31-0)
(.ppach v1-5 r0-5 v1-4)
(.mov r0-6 f31-0)
(let ((v1-6 (shl (the-as int v1-5) 16)))
(nop!)
(zero? v1-6)
)
)
)

;; definition for function instance-tfragment-add-debug-sphere
;; Used lq/sq
(defun instance-tfragment-add-debug-sphere ((arg0 drawable) (arg1 instance-tie))
(local-vars (r0-0 uint128) (v1-1 uint128) (v1-2 uint128) (a3-0 float))
(rlet ((vf0 :class vf)
(vf10 :class vf)
(vf11 :class vf)
(vf12 :class vf)
(vf9 :class vf)
)
(init-vf0-vector)
(nop!)
(let ((v1-0 (the-as uint128 (-> arg1 origin vector4h 3 long))))
(.pextlh v1-1 v1-0 r0-0)
)
(.lvf vf9 (&-> arg0 bsphere quad))
(.pw.sra v1-2 v1-1 10)
(.lvf vf10 (&-> arg1 bsphere quad))
(nop!)
(.mov vf12 v1-2)
(.itof.vf vf12 vf12)
(nop!)
(.add.vf vf10 vf10 vf12 :mask #b111)
(nop!)
(.add.vf vf9 vf9 vf10 :mask #b111)
(nop!)
(.add.w.vf vf11 vf0 vf9 :mask #b1)
(nop!)
(.mov a3-0 vf11)
(nop!)
(let ((a2-0 (new-stack-vector0)))
(.svf (&-> a2-0 quad) vf9)
(add-debug-sphere
#t
(bucket-id debug-draw0)
a2-0
a3-0
(new 'static 'rgba :r #x80 :g #x80 :b #x80 :a #x80)
)
)
)
)
Loading