From 3cfd50b6180eae358230cab29879120a9466c93f Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Mon, 9 Aug 2021 21:55:05 -0400 Subject: [PATCH] decomp: finish `ticky` (#744) Co-authored-by: water --- decompiler/config/all-types.gc | 30 +++--- .../jak1_ntsc_black_label/label_types.jsonc | 7 ++ goal_src/levels/common/ticky.gc | 83 +++++++++++++++ .../reference/levels/common/ticky_REF.gc | 100 ++++++++++++++++++ 4 files changed, 205 insertions(+), 15 deletions(-) create mode 100644 test/decompiler/reference/levels/common/ticky_REF.gc diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 0fca112619..5a44976bf7 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -22947,21 +22947,21 @@ ;; - Types -; (deftype ticky (structure) -; ((delay-til-ramp uint64 :offset-assert 0) -; (delay-til-timeout uint64 :offset-assert 8) -; (starting-time uint64 :offset-assert 16) -; (last-tick-time uint64 :offset-assert 24) -; ) -; :method-count-assert 12 -; :size-assert #x20 -; :flag-assert #xc00000020 -; (:methods -; (dummy-9 () none 9) -; (dummy-10 () none 10) -; (dummy-11 () none 11) -; ) -; ) +(deftype ticky (structure) + ((delay-til-ramp uint64 :offset-assert 0) + (delay-til-timeout uint64 :offset-assert 8) + (starting-time uint64 :offset-assert 16) + (last-tick-time uint64 :offset-assert 24) + ) + :method-count-assert 12 + :size-assert #x20 + :flag-assert #xc00000020 + (:methods + (sleep (_type_ uint) none 9) + (reached-delay? (_type_ uint) symbol 10) + (completed? (_type_) symbol 11) + ) + ) ;; ---------------------- diff --git a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc index c736be612e..2544db748f 100644 --- a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc @@ -1423,6 +1423,13 @@ "tippy": [ ["L7", "float", true] ], + + "ticky": [ + ["L7", "float", true], + ["L8", "float", true], + ["L10", "uint64", 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": [] } diff --git a/goal_src/levels/common/ticky.gc b/goal_src/levels/common/ticky.gc index 4c69770147..3c6a87b5f0 100644 --- a/goal_src/levels/common/ticky.gc +++ b/goal_src/levels/common/ticky.gc @@ -5,3 +5,86 @@ ;; name in dgo: ticky ;; dgos: GAME, COMMON, L1 +;; definition of type ticky +(deftype ticky (structure) + ((delay-til-ramp uint64 :offset-assert 0) + (delay-til-timeout uint64 :offset-assert 8) + (starting-time uint64 :offset-assert 16) + (last-tick-time uint64 :offset-assert 24) + ) + :method-count-assert 12 + :size-assert #x20 + :flag-assert #xc00000020 + (:methods + (sleep (_type_ uint) none 9) + (reached-delay? (_type_ uint) symbol 10) + (completed? (_type_) symbol 11) + ) + ) + +;; definition for method 9 of type ticky +;; INFO: Return type mismatch int vs none. +(defmethod sleep ticky ((obj ticky) (arg0 uint)) + (set! (-> obj starting-time) (-> *display* base-frame-counter)) + (set! (-> obj delay-til-timeout) arg0) + (set! (-> obj delay-til-ramp) (max 0 (the-as int (+ arg0 -1200)))) + (set! (-> obj last-tick-time) (the-as uint 0)) + 0 + (none) + ) + +;; definition for method 11 of type ticky +(defmethod completed? ticky ((obj ticky)) + (let ((gp-0 #f)) + (let ((v1-2 (- (-> *display* base-frame-counter) (-> obj starting-time)))) + (cond + ((>= (the-as int v1-2) (the-as int (-> obj delay-til-timeout))) + (set! gp-0 #t) + ) + (else + (let* + ((f0-1 + (fmin + 1.0 + (/ + (the float (max 0 (the-as int (- v1-2 (-> obj delay-til-ramp))))) + (the float (- (-> obj delay-til-timeout) (-> obj delay-til-ramp))) + ) + ) + ) + (v1-7 (the int (lerp 105.0 41.0 f0-1))) + ) + (when + (>= + (the-as + int + (- (-> *display* base-frame-counter) (-> obj last-tick-time)) + ) + v1-7 + ) + (set! (-> obj last-tick-time) (-> *display* base-frame-counter)) + (sound-play-by-name + (static-sound-name "stopwatch") + (new-sound-id) + 1024 + 0 + 0 + (the-as uint 1) + (the-as vector #t) + ) + ) + ) + ) + ) + ) + gp-0 + ) + ) + +;; definition for method 10 of type ticky +(defmethod reached-delay? ticky ((obj ticky) (arg0 uint)) + (>= + (the-as int (- (-> *display* base-frame-counter) (-> obj starting-time))) + (the-as int arg0) + ) + ) diff --git a/test/decompiler/reference/levels/common/ticky_REF.gc b/test/decompiler/reference/levels/common/ticky_REF.gc new file mode 100644 index 0000000000..e8c1aae4a8 --- /dev/null +++ b/test/decompiler/reference/levels/common/ticky_REF.gc @@ -0,0 +1,100 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type ticky +(deftype ticky (structure) + ((delay-til-ramp uint64 :offset-assert 0) + (delay-til-timeout uint64 :offset-assert 8) + (starting-time uint64 :offset-assert 16) + (last-tick-time uint64 :offset-assert 24) + ) + :method-count-assert 12 + :size-assert #x20 + :flag-assert #xc00000020 + (:methods + (sleep (_type_ uint) none 9) + (reached-delay? (_type_ uint) symbol 10) + (completed? (_type_) symbol 11) + ) + ) + +;; definition for method 3 of type ticky +(defmethod inspect ticky ((obj ticky)) + (format #t "[~8x] ~A~%" obj 'ticky) + (format #t "~Tdelay-til-ramp: ~D~%" (-> obj delay-til-ramp)) + (format #t "~Tdelay-til-timeout: ~D~%" (-> obj delay-til-timeout)) + (format #t "~Tstarting-time: ~D~%" (-> obj starting-time)) + (format #t "~Tlast-tick-time: ~D~%" (-> obj last-tick-time)) + obj + ) + +;; definition for method 9 of type ticky +;; INFO: Return type mismatch int vs none. +(defmethod sleep ticky ((obj ticky) (arg0 uint)) + (set! (-> obj starting-time) (-> *display* base-frame-counter)) + (set! (-> obj delay-til-timeout) arg0) + (set! (-> obj delay-til-ramp) (max 0 (the-as int (+ arg0 -1200)))) + (set! (-> obj last-tick-time) (the-as uint 0)) + 0 + (none) + ) + +;; definition for method 11 of type ticky +(defmethod completed? ticky ((obj ticky)) + (let ((gp-0 #f)) + (let ((v1-2 (- (-> *display* base-frame-counter) (-> obj starting-time)))) + (cond + ((>= (the-as int v1-2) (the-as int (-> obj delay-til-timeout))) + (set! gp-0 #t) + ) + (else + (let* + ((f0-1 + (fmin + 1.0 + (/ + (the float (max 0 (the-as int (- v1-2 (-> obj delay-til-ramp))))) + (the float (- (-> obj delay-til-timeout) (-> obj delay-til-ramp))) + ) + ) + ) + (v1-7 (the int (lerp 105.0 41.0 f0-1))) + ) + (when + (>= + (the-as + int + (- (-> *display* base-frame-counter) (-> obj last-tick-time)) + ) + v1-7 + ) + (set! (-> obj last-tick-time) (-> *display* base-frame-counter)) + (sound-play-by-name + (static-sound-name "stopwatch") + (new-sound-id) + 1024 + 0 + 0 + (the-as uint 1) + (the-as vector #t) + ) + ) + ) + ) + ) + ) + gp-0 + ) + ) + +;; definition for method 10 of type ticky +(defmethod reached-delay? ticky ((obj ticky) (arg0 uint)) + (>= + (the-as int (- (-> *display* base-frame-counter) (-> obj starting-time))) + (the-as int arg0) + ) + ) + + + +