[Decompile] pad and gs (#389)

* update stuff

* gs reference added

* update config
This commit is contained in:
water111
2021-04-26 21:40:08 -04:00
committed by GitHub
parent 8619e6df19
commit 3d2ca71fe3
40 changed files with 3716 additions and 1542 deletions
+1 -1
View File
@@ -161,7 +161,7 @@ std::unique_ptr<FormRegressionTest::TestData> FormRegressionTest::make_function(
// convert instruction to atomic ops
DecompWarnings warnings;
auto ops = convert_function_to_atomic_ops(test->func, program.labels, warnings);
auto ops = convert_function_to_atomic_ops(test->func, program.labels, warnings, false);
test->func.ir2.atomic_ops = std::make_shared<FunctionAtomicOps>(std::move(ops));
test->func.ir2.atomic_ops_succeeded = true;
test->func.ir2.env.set_end_var(test->func.ir2.atomic_ops->end_op().return_var());
@@ -63,7 +63,17 @@
(define-extern *listener-process* process)
(define-extern *active-pool* process-tree)
(define-extern reset-and-call (function thread function object))
(define-extern ash (function int int int))
(defun ash ((value int) (shift-amount int))
"Arithmetic shift value by shift-amount.
A positive shift-amount will shift to the left and a negative will shift to the right.
"
;; OpenGOAL does not support ash in the compiler, so we implement it here as an inline function.
(declare (inline))
(if (> shift-amount 0)
(shl value shift-amount)
(sar value (- shift-amount))
)
)
(define-extern inspect-process-tree (function process-tree int int symbol process-tree))
(define-extern set-to-run-bootstrap (function none))
(define-extern dead-state state)
@@ -87,6 +97,11 @@
'(none)
)
(defmacro gpr->fpr (in)
in)
(define-extern get-current-time (function uint))
(define-extern get-integral-current-time (function uint))
;; math
(define-extern fabs (function float float))
@@ -199,6 +214,75 @@
(end 7) ;; next, but ends.
)
(defenum gs-psm
:bitfield #f
:type uint8
(ct32 0)
(ct24 1)
(ct16 2)
(ct16s 10)
(mt8 19)
(mt4 20)
(mt8h 27)
(mt4hl 36)
(mt4hh 44)
(mz32 48)
(mz24 49)
(mz16 50)
(mz16s 58)
)
(defenum gs-prim-type
:type uint8
(point 0)
(line 1)
(line-strip 2)
(tri 3)
(tri-strip 4)
(tri-fan 5)
(sprite 6)
)
(defenum gs-reg-id
:bitfield #f
:type uint8
(prim 0)
(rgbaq 1)
(st 2)
(uv 3)
(xyzf2 4)
(xyz2 5)
(tex0-1 6)
(tex0-2 7)
(clamp-1 8)
(clamp-2 9)
(fog 10)
(xyzf3 12)
(xyz3 13)
(a+d 14)
(nop 15)
)
(deftype gif-tag-regs (uint64)
((regs0 gs-reg-id :offset 0 :size 4)
(regs1 gs-reg-id :offset 4 :size 4)
(regs2 gs-reg-id :offset 8 :size 4)
(regs3 gs-reg-id :offset 12 :size 4)
(regs4 gs-reg-id :offset 16 :size 4)
(regs5 gs-reg-id :offset 20 :size 4)
(regs6 gs-reg-id :offset 24 :size 4)
(regs7 gs-reg-id :offset 28 :size 4)
(regs8 gs-reg-id :offset 32 :size 4)
(regs9 gs-reg-id :offset 36 :size 4)
(regs10 gs-reg-id :offset 40 :size 4)
(regs11 gs-reg-id :offset 44 :size 4)
(regs12 gs-reg-id :offset 48 :size 4)
(regs13 gs-reg-id :offset 52 :size 4)
(regs14 gs-reg-id :offset 56 :size 4)
(regs15 gs-reg-id :offset 60 :size 4)
)
)
;; display-h
(deftype display-env (structure)
((pmode uint64 :offset-assert 0)
+1 -1
View File
@@ -9,7 +9,7 @@
(set!
(-> current-bucket tag)
(new 'static 'dma-tag
:id #x2
:id (dma-tag-id next)
:addr (the-as int (&+ (the-as pointer current-bucket) 16))
)
)
+10 -2
View File
@@ -149,7 +149,11 @@
)
(set!
(-> buf-ptr dma)
(new 'static 'dma-tag :id #x3 :addr (the-as int func-ptr) :qwc qwc-now)
(new 'static 'dma-tag
:id (dma-tag-id ref)
:addr (the-as int func-ptr)
:qwc qwc-now
)
)
(set!
(-> buf-ptr vif0)
@@ -157,7 +161,11 @@
)
(set!
(-> buf-ptr vif1)
(new 'static 'vif-tag :cmd #x4a :num (shl qwc-now 1) :imm origin)
(new 'static 'vif-tag
:cmd (vif-cmd mpg)
:num (shl qwc-now 1)
:imm origin
)
)
(set! (-> dma-buf-2 base) (&+ (the-as pointer buf-ptr) 16))
)
+2 -2
View File
@@ -725,8 +725,8 @@
(empty-form)
(cond
((or
(zero? (+ (the-as uint (-> current-tag id)) (the-as uint -3)))
(zero? (+ (the-as uint (-> current-tag id)) (the-as uint -4)))
(= (-> current-tag id) (dma-tag-id ref))
(= (-> current-tag id) (dma-tag-id refs))
(zero? (-> current-tag id))
)
(set! addr (-> current-tag addr))
File diff suppressed because it is too large Load Diff
+371
View File
@@ -0,0 +1,371 @@
;;-*-Lisp-*-
(in-package goal)
;; definition for symbol *cheat-mode*, type symbol
(define *cheat-mode* #t)
;; definition of type hw-cpad
(deftype hw-cpad (basic)
((valid uint8 :offset-assert 4)
(status uint8 :offset-assert 5)
(button0 uint16 :offset-assert 6)
(rightx uint8 :offset-assert 8)
(righty uint8 :offset-assert 9)
(leftx uint8 :offset-assert 10)
(lefty uint8 :offset-assert 11)
(abutton uint8 12 :offset-assert 12)
(dummy uint8 12 :offset-assert 24)
)
:method-count-assert 9
:size-assert #x24
:flag-assert #x900000024
)
;; definition for method 3 of type hw-cpad
(defmethod inspect hw-cpad ((obj hw-cpad))
(format #t "[~8x] ~A~%" obj (-> obj type))
(format #t "~Tvalid: #x~X~%" (-> obj valid))
(format #t "~Tstatus: #x~X~%" (-> obj status))
(format #t "~Tbutton0: #x~X~%" (-> obj button0))
(format #t "~Trightx: ~D~%" (-> obj rightx))
(format #t "~Trighty: ~D~%" (-> obj righty))
(format #t "~Tleftx: ~D~%" (-> obj leftx))
(format #t "~Tlefty: ~D~%" (-> obj lefty))
(format #t "~Tabutton[12] @ #x~X~%" (-> obj abutton))
(format #t "~Tdummy[12] @ #x~X~%" (-> obj dummy))
obj
)
;; definition of type cpad-info
(deftype cpad-info (hw-cpad)
((number int32 :offset-assert 36)
(cpad-file int32 :offset-assert 40)
(button0-abs uint32 3 :offset-assert 44)
(button0-shadow-abs uint32 1 :offset-assert 56)
(button0-rel uint32 3 :offset-assert 60)
(stick0-dir float :offset-assert 72)
(stick0-speed float :offset-assert 76)
(new-pad int32 :offset-assert 80)
(state int32 :offset-assert 84)
(align uint8 6 :offset-assert 88)
(direct uint8 6 :offset-assert 94)
(buzz-val uint8 2 :offset-assert 100)
(buzz-time uint64 2 :offset-assert 104)
(buzz basic :offset-assert 120)
(buzz-act int32 :offset-assert 124)
(change-time uint64 :offset-assert 128)
)
:method-count-assert 9
:size-assert #x88
:flag-assert #x900000088
(:methods
(new (symbol type int) _type_ 0)
)
)
;; definition for method 3 of type cpad-info
(defmethod inspect cpad-info ((obj cpad-info))
(format #t "[~8x] ~A~%" obj (-> obj type))
(format #t "~Tvalid: #x~X~%" (-> obj valid))
(format #t "~Tstatus: #x~X~%" (-> obj status))
(format #t "~Tbutton0: #x~X~%" (-> obj button0))
(format #t "~Trightx: ~D~%" (-> obj rightx))
(format #t "~Trighty: ~D~%" (-> obj righty))
(format #t "~Tleftx: ~D~%" (-> obj leftx))
(format #t "~Tlefty: ~D~%" (-> obj lefty))
(format #t "~Tabutton[12] @ #x~X~%" (-> obj abutton))
(format #t "~Tdummy[12] @ #x~X~%" (-> obj dummy))
(format #t "~Tnumber: ~D~%" (-> obj number))
(format #t "~Tcpad-file: ~D~%" (-> obj cpad-file))
(format #t "~Tbutton0-abs[3] @ #x~X~%" (-> obj button0-abs))
(format #t "~Tbutton0-shadow-abs[1] @ #x~X~%" (-> obj button0-shadow-abs))
(format #t "~Tbutton0-rel[3] @ #x~X~%" (-> obj button0-rel))
(format #t "~Tstick0-dir: ~f~%" (-> obj stick0-dir))
(format #t "~Tstick0-speed: ~f~%" (-> obj stick0-speed))
(format #t "~Tnew-pad: ~D~%" (-> obj new-pad))
(format #t "~Tstate: ~D~%" (-> obj state))
(format #t "~Talign[6] @ #x~X~%" (-> obj align))
(format #t "~Tdirect[6] @ #x~X~%" (-> obj direct))
(format #t "~Tbuzz-val[2] @ #x~X~%" (-> obj buzz-val))
(format #t "~Tbuzz-time[2] @ #x~X~%" (-> obj buzz-time))
(format #t "~Tbuzz: ~A~%" (-> obj buzz))
(format #t "~Tbuzz-act: ~D~%" (-> obj buzz-act))
(format #t "~Tchange-time: ~D~%" (-> obj change-time))
obj
)
;; definition for function cpad-invalid!
(defun cpad-invalid! ((pad cpad-info))
(set! (-> pad valid) (logior (-> pad valid) 128))
(set! (-> pad button0) (the-as uint 0))
(set! (-> pad button0-abs 0) (the-as uint 0))
(set! (-> pad button0-shadow-abs 0) (the-as uint 0))
(set! (-> pad button0-rel 0) (the-as uint 0))
(dotimes (v1-2 12)
(nop!)
(set! (-> pad abutton v1-2) 0)
)
(set! (-> pad stick0-dir) 0.0)
(set! (-> pad stick0-speed) 0.0)
(set! (-> pad rightx) (the-as uint 128))
(set! (-> pad righty) (the-as uint 128))
(set! (-> pad leftx) (the-as uint 128))
(set! (-> pad lefty) (the-as uint 128))
(set! (-> pad align 0) (the-as uint 0))
(set! (-> pad align 1) (the-as uint 1))
(set! (-> pad align 2) (the-as uint 255))
(set! (-> pad align 3) (the-as uint 255))
(set! (-> pad align 4) (the-as uint 255))
(set! (-> pad align 5) (the-as uint 255))
(dotimes (v1-14 6)
(set! (-> pad direct v1-14) 0)
)
(dotimes (v1-17 2)
(set! (-> pad buzz-val 0) (the-as uint 0))
(set! (-> pad buzz-time 0) (the-as uint 0))
)
pad
)
;; definition for method 0 of type cpad-info
(defmethod new cpad-info ((alloction symbol) (type-to-make type) (idx int))
(let
((obj
(object-new alloction type-to-make (the-as int (-> type-to-make size)))
)
)
(set! (-> obj number) idx)
(set! (-> obj buzz) #f)
(cpad-open obj idx)
(cpad-invalid! obj)
)
)
;; definition of type cpad-list
(deftype cpad-list (basic)
((num-cpads int32 :offset-assert 4)
(cpads cpad-info 2 :offset-assert 8)
)
:method-count-assert 9
:size-assert #x10
:flag-assert #x900000010
(:methods
(new (symbol type) _type_ 0)
)
)
;; definition for method 3 of type cpad-list
(defmethod inspect cpad-list ((obj cpad-list))
(format #t "[~8x] ~A~%" obj (-> obj type))
(format #t "~Tnum-cpads: ~D~%" (-> obj num-cpads))
(format #t "~Tcpads[2] @ #x~X~%" (-> obj cpads))
obj
)
;; definition for method 0 of type cpad-list
(defmethod new cpad-list ((allocation symbol) (type-to-make type))
(let
((gp-0
(object-new allocation type-to-make (the-as int (-> type-to-make size)))
)
)
(set! (-> gp-0 num-cpads) 2)
(set! (-> gp-0 cpads 0) (new 'global 'cpad-info 0))
(set! (-> gp-0 cpads 1) (new 'global 'cpad-info 1))
gp-0
)
)
;; definition for function analog-input
(defun
analog-input
((in int) (offset float) (center-val float) (max-val float) (out-range float))
(let* ((in (gpr->fpr in))
(offset-in (- (the float in) offset))
(magnitude (- (fabs offset-in) center-val))
(max-magnitude (- max-val center-val))
)
(if (< offset-in 0.0)
(set! out-range (- out-range))
)
(cond
((>= 0.0 magnitude)
0.0
)
((>= magnitude max-magnitude)
out-range
)
(else
(/ (* magnitude out-range) max-magnitude)
)
)
)
)
;; definition for function cpad-set-buzz!
;; INFO: Return type mismatch int vs none.
(defun
cpad-set-buzz!
((pad cpad-info) (buzz-idx int) (buzz-amount int) (duration int))
(cond
((zero? buzz-amount)
(set! (-> pad buzz-val buzz-idx) 0)
(let ((v1-2 0))
)
)
((= buzz-amount (-> pad buzz-val buzz-idx))
(set!
(-> pad buzz-time buzz-idx)
(max
(the-as int (-> pad buzz-time buzz-idx))
(the-as int (+ (get-current-time) (the-as uint duration)))
)
)
)
((< (-> pad buzz-val buzz-idx) (the-as uint buzz-amount))
(set! (-> pad buzz-val buzz-idx) buzz-amount)
(set!
(-> pad buzz-time buzz-idx)
(+ (get-current-time) (the-as uint duration))
)
)
)
(let ((v0-2 0))
)
(none)
)
;; definition for symbol *cpad-list*, type cpad-list
(define *cpad-list* (new 'global 'cpad-list))
;; definition for symbol *cpad-debug*, type symbol
(define *cpad-debug* #f)
;; definition for function service-cpads
(defun service-cpads ()
(let ((pad-list *cpad-list*))
(dotimes (pad-idx (-> pad-list num-cpads))
(let ((pad (-> *cpad-list* cpads pad-idx)))
(cpad-get-data pad)
(cond
((zero? (logand (-> pad valid) 128))
(dotimes (buzz-idx 2)
(cond
((and
(-> pad buzz)
(<
(the-as int (get-current-time))
(the-as int (-> pad buzz-time buzz-idx))
)
(= *master-mode* 'game)
)
(let ((v1-10 buzz-idx))
(cond
((zero? v1-10)
(set!
(-> pad direct buzz-idx)
(logand
(ash
(-> pad buzz-val buzz-idx)
(- (the-as int (logand (get-integral-current-time) 7)))
)
1
)
)
)
((= v1-10 1)
(set! (-> pad direct buzz-idx) (-> pad buzz-val buzz-idx))
)
)
)
)
(else
(set! (-> pad buzz-val buzz-idx) 0)
(set! (-> pad direct buzz-idx) 0)
(let ((v1-22 0))
)
)
)
)
(set! (-> pad button0-abs 2) (-> pad button0-abs 1))
(set! (-> pad button0-abs 1) (-> pad button0-shadow-abs 0))
(set! (-> pad button0-rel 2) (-> pad button0-rel 1))
(set! (-> pad button0-rel 1) (-> pad button0-rel 0))
(let ((current-button0 (-> pad button0)))
(set! (-> pad button0-shadow-abs 0) current-button0)
(set! (-> pad button0-abs 0) current-button0)
)
(set!
(-> pad button0-rel 0)
(logand (-> pad button0-abs 0) (lognot (-> pad button0-abs 1)))
)
(when *cpad-debug*
(set! (-> pad leftx) (the-as uint 255))
(set! (-> pad rightx) (the-as uint 255))
)
(set! (-> pad stick0-speed) 1.0)
(cond
((= (shr (-> pad status) 4) 7)
(let ((f30-0 (* 0.0078125 (the float (+ (-> pad leftx) -128))))
(f28-0
(* 0.0078125 (the float (- 127 (the-as int (-> pad lefty)))))
)
)
(set! (-> pad stick0-dir) (atan (- f30-0) f28-0))
(set!
(-> pad stick0-speed)
(fmin 1.0 (sqrtf (+ (* f30-0 f30-0) (* f28-0 f28-0))))
)
)
(if (< (-> pad stick0-speed) 0.3)
(let ((f0-8 0.0))
(set! (-> pad stick0-speed) f0-8)
)
)
)
(else
(set! (-> pad leftx) (the-as uint 128))
(set! (-> pad lefty) (the-as uint 128))
(set! (-> pad rightx) (the-as uint 128))
(set! (-> pad righty) (the-as uint 128))
(set! (-> pad stick0-dir) 0.0)
(let ((f0-10 0.0))
(set! (-> pad stick0-speed) f0-10)
)
)
)
(if
(or
(!= (-> pad button0-abs 0) (-> pad button0-abs 1))
(or (< 0.3 (-> pad stick0-speed)) (zero? (-> pad change-time)))
)
(set! (-> pad change-time) (get-current-time))
)
)
(else
(cpad-invalid! pad)
)
)
)
)
)
*cpad-list*
)
;; definition for function buzz-stop!
;; INFO: Return type mismatch int vs none.
(defun buzz-stop! ((idx int))
(cpad-set-buzz! (-> *cpad-list* cpads idx) 0 0 0)
(cpad-set-buzz! (-> *cpad-list* cpads idx) 1 0 0)
(let ((v0-0 0))
)
(none)
)
;; failed to figure out what this is:
(let ((v0-4 0))
)
@@ -967,7 +967,7 @@ TEST_F(FormRegressionTest, DmaBufferAddVuFunction) {
" (quote static)\n"
" (quote dma-tag)\n"
" :id\n"
" 3\n"
" (dma-tag-id ref)\n"
" :addr\n"
" (the-as int v1-0)\n"
" :qwc\n"
@@ -984,7 +984,7 @@ TEST_F(FormRegressionTest, DmaBufferAddVuFunction) {
" )\n"
" (set!\n"
" (-> (the-as dma-packet t2-0) vif1)\n"
" (new (quote static) (quote vif-tag) :cmd 74 :num (shl t0-1 1) :imm a1-1)\n"
" (new (quote static) (quote vif-tag) :cmd (vif-cmd mpg) :num (shl t0-1 1) :imm a1-1)\n"
" )\n"
" (set! (-> t1-1 base) (&+ (the-as pointer t2-0) 16))\n"
" )\n"
+6 -3
View File
@@ -17,7 +17,7 @@ const std::unordered_set<std::string> g_object_files_to_decompile = {
"trigonometry-h", /* transformq-h */ "matrix", "transform", "quaternion",
"euler", /* geometry, trigonometry, */
"gsound-h", "timer-h", "timer", "vif-h", "dma-h", "video-h", "vu1-user-h", "dma", "dma-buffer",
"dma-bucket", "dma-disasm",
"dma-bucket", "dma-disasm", "pad", "gs",
/* gap */
"bounding-box",
/* gap */
@@ -32,7 +32,7 @@ const std::vector<std::string> g_object_files_to_check_against_reference = {
/* transformq-h, */
"matrix", "transform", "quaternion", "euler", /* geometry, trigonometry */
"gsound-h", "timer-h", /* timer, */ "vif-h", "dma-h", "video-h", "vu1-user-h", "dma",
"dma-buffer", "dma-bucket", "dma-disasm",
"dma-buffer", "dma-bucket", "dma-disasm", "pad", "gs",
/* gap */ "bounding-box",
/* gap */
"sync-info-h", "sync-info"};
@@ -118,7 +118,10 @@ const std::unordered_set<std::string> skip_in_compiling = {
"(method 3 profile-frame)", // double definition.
// dma-disasm
"disasm-dma-list",
"disasm-dma-list", // missing a single cast :(
// gs
"(method 3 gif-tag)", // inspect for a 128-bit type.
// sync-info
"(method 15 sync-info)", // needs display stuff first