diff --git a/common/type_system/TypeSystem.cpp b/common/type_system/TypeSystem.cpp index 4e126424d..9f94ae658 100644 --- a/common/type_system/TypeSystem.cpp +++ b/common/type_system/TypeSystem.cpp @@ -2147,6 +2147,12 @@ std::optional find_best_field_in_structure(const TypeSystem& ts, } else { int rel_offset = offset - field.offset(); // array case (and array encompasses what we want) + ASSERT_MSG( + type->get_size_in_memory() > 0, + fmt::format( + "In type {}, type size was 0 for array field {} of type {}, check that the type " + "is fully defined.", + st->get_name(), field.name(), field.type().print())); int array_idx = rel_offset / type->get_size_in_memory(); if (!field.is_inline() && field.offset() + field.array_size() * type->get_load_size() > offset) { diff --git a/decompiler/config/jak3/all-types.gc b/decompiler/config/jak3/all-types.gc index 72e2470ee..0c44c977b 100644 --- a/decompiler/config/jak3/all-types.gc +++ b/decompiler/config/jak3/all-types.gc @@ -54,14 +54,16 @@ (defenum language-enum :type int64 - (english) - (french) - (german) - (spanish) - (italian) - (japanese) - (korean) - (uk-english) + (english 0) + (french 1) + (german 2) + (spanish 3) + (italian 4) + (japanese 6) + (korean 7) + (russian 8) + (portuguese 9) + (uk-english 11) ) (define-extern *debug-segment* symbol) @@ -589,10 +591,10 @@ (clock-ratio float :offset-assert 12) (accum float :offset-assert 16) (integral-accum float :offset-assert 20) - (frame-counter uint64 :offset-assert 24) ;; time-frame - (old-frame-counter uint64 :offset-assert 32) ;; time-frame - (integral-frame-counter uint64 :offset-assert 40) - (old-integral-frame-counter uint64 :offset-assert 48) + (frame-counter time-frame :offset-assert 24) ;; time-frame + (old-frame-counter time-frame :offset-assert 32) ;; time-frame + (integral-frame-counter time-frame :offset-assert 40) + (old-integral-frame-counter time-frame :offset-assert 48) (sparticle-data vector :inline :offset-assert 64) (seconds-per-frame float :offset-assert 80) (frames-per-second float :offset-assert 84) @@ -603,13 +605,16 @@ :flag-assert #x180000005c (:methods (new (symbol type int) _type_) ;; 0 - (update-rates! (_type_ float) float) ;; 9 - (clock-method-10 () none) ;; 10 ;; (advance-by! (_type_ float) clock 10) - (clock-method-11 () none) ;; 11 ;; (tick! (_type_) clock 11) - (clock-method-12 () none) ;; 12 ;; (save! (_type_ (pointer uint64)) int 12) - (clock-method-13 () none) ;; 13 ;; (load! (_type_ (pointer uint64)) int 13) - (clock-method-14 () none) ;; 14 ;; (reset! (_type_) none 14) - (clock-method-15 () none) ;; 15 + (update-rates! "Recompute all clock values for the given clock ratio (arg0)." (_type_ float) float) ;; 9 + (advance-by! + "Advance the clock by arg0 timeframes (as a float). + Both counters keep a separate fractional and integer counter." + (_type_ float) clock) ;; 10 + (tick! "Per-game-frame clock tick forward." (_type_) clock) ;; 11 + (save! "Save a clock's state to a buffer, return bytes used." (_type_ (pointer uint64)) int) ;; 12 + (load! "Load a clock's state from a buffer, return bytes used." (_type_ (pointer uint64)) int) ;; 13 + (copy! "Copy the frame counters and ratio from arg0." (_type_ clock) clock) ;; 14 + (reset! "Reset a clock to 1000s, rate of 1." (_type_) none) ;; 15 (frame-mask-2 "Check if the frame count, xored with `xor-val` has its lowest bit set" (_type_ int) symbol) ;; 16 (frame-mask-4 "Check if the frame count, xored with `xor-val` has any of its lowest 2 bits set" (_type_ int) symbol) ;; 17 (frame-mask-8 "Check if the frame count, xored with `xor-val` has any of its lowest 3 bits set" (_type_ int) symbol) ;; 18 @@ -3365,13 +3370,64 @@ ;; vu1-user-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +++vu1-user-h:tpage-category (defenum tpage-category :type int8 ) +;; ---vu1-user-h:tpage-category +;; +++vu1-user-h:bucket-id (defenum bucket-id :type int32 + (debug-no-zbuf2 584) ) +;; ---vu1-user-h:bucket-id + +;; +++vu1-user-h:vu1-renderer-mask +;; TODO stolen from Jak 2 +(defenum vu1-renderer-mask + :type uint64 + :bitfield #t + (rn0) + (rn1) + (rn2) + (sky) + (ocean) + (ocean-wave) + (tfrag) + (tie) + (tie-envmap) + (tie-scissor) + (tie-envmap-scissor) + (tie-vanish) + (generic) + (merc) + (emerc) + (shrubbery) + (shrub-near) + (billboard) + (shrubbery-vanish) + (tfrag-trans) + (tie-scissor-trans) + (tie-trans) + (tie-envmap-trans) + (tie-envmap-scissor-trans) + (tfrag-water) + (tie-scissor-water) + (tie-water) + (tie-envmap-water) + (tie-envmap-scissor-water) + (sprite) + (shadow) + (rn31) + (rn32) + (rn33) + (depth-cue) + (rn35) + (rn36) + (rn37) + ) +;; ---vu1-user-h:vu1-renderer-mask (deftype dma-foreground-sink (basic) "A specification for where a foreground renderer should output its DMA data." @@ -3591,19 +3647,17 @@ ) |# -#| (deftype dma-buffer (basic) ((allocated-length int32 :offset-assert 4) (base pointer :offset-assert 8) ;; guessed by decompiler (end pointer :offset-assert 12) ;; guessed by decompiler (real-buffer-end int32 :offset-assert 16) - (data uint64 1 :offset-assert 32) ;; guessed by decompiler + (data uint64 1 :offset 32) ;; guessed by decompiler ) :method-count-assert 9 :size-assert #x28 :flag-assert #x900000028 ) -|# ;; (define-extern dma-buffer-inplace-new function) ;; (function dma-buffer int dma-buffer) ;; (define-extern dma-buffer-length function) ;; (function dma-buffer int) @@ -3650,7 +3704,49 @@ ;; pad ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| +;; +++pad:pad-buttons +(defenum pad-buttons + :bitfield #t + :type uint32 + (select 0) + (l3 1) + (r3 2) + (start 3) + (up 4) + (right 5) + (down 6) + (left 7) + (l2 8) + (r2 9) + (l1 10) + (r1 11) + (triangle 12) + (circle 13) + (x 14) + (square 15) + ;; only 16 buttons are mapped to hardware, the rest are 'actions' or something else + (l-analog-up 16) + (l-analog-right 17) + (l-analog-down 18) + (l-analog-left 19) + (r-analog-up 20) + (r-analog-right 21) + (r-analog-down 22) + (r-analog-left 23) + (confirm 24) + ) +;; ---pad:pad-buttons + +;; +++pad:mouse-buttons +(defenum mouse-buttons + :bitfield #t + :type uint32 + (left) + (right) + (middle) + ) +;; ---pad:mouse-buttons + (deftype scf-time (structure) ((stat uint8 :offset-assert 0) (second uint8 :offset-assert 1) @@ -3665,10 +3761,12 @@ :size-assert #x8 :flag-assert #x900000008 ) -|# -#| +(define-extern scf-get-time (function scf-time none)) + (deftype hw-cpad (basic) + "Data that comes directly from hardware. + It's 32 bytes + type tag (ignored by C kernel)." ((valid uint8 :offset-assert 4) (status uint8 :offset-assert 5) (button0 uint16 :offset-assert 6) @@ -3683,10 +3781,9 @@ :size-assert #x24 :flag-assert #x900000024 ) -|# -#| (deftype cpad-info (hw-cpad) + "Data from hardware + additional info calculated here." ((number int32 :offset-assert 36) (cpad-file int32 :offset-assert 40) (button0-abs pad-buttons 3 :offset-assert 44) ;; guessed by decompiler @@ -3715,78 +3812,99 @@ :size-assert #x98 :flag-assert #xa00000098 (:methods - (new (symbol type) _type_) ;; 0 ;; (new (symbol type int) _type_) - (cpad-info-method-9 () none) ;; 9 ;; (adjust-to-screen-flip (_type_) int) + (new + "Allocate a new cpad-info and open the pad itself through the kernel." + (symbol type int) _type_) ;; 0 + (adjust-to-screen-flip (_type_) int) ;; 9 ) ) -|# -#| +(define-extern cpad-open (function cpad-info int cpad-info)) +(define-extern cpad-get-data (function cpad-info cpad-info)) + (deftype cpad-list (basic) + "List of controllers. It always has two controllers." ((num-cpads int32 :offset-assert 4) (cpads cpad-info 2 :offset-assert 8) ;; guessed by decompiler ) :method-count-assert 9 :size-assert #x10 :flag-assert #x900000010 + (:methods + (new + "Create a cpad-list for 2 controllers. It's fine to do this even if one or both controllers + aren't connected yet." + (symbol type) _type_) ;; 0 + ) ) -|# -#| (deftype mouse-info (basic) - ((active symbol :offset-assert 4) ;; guessed by decompiler - (cursor basic :offset-assert 8) - (valid symbol :offset-assert 12) ;; guessed by decompiler - (id uint8 :offset-assert 16) - (status uint16 :offset-assert 18) - (button0 uint16 :offset-assert 20) - (deltax int8 :offset-assert 22) - (deltay int8 :offset-assert 23) - (wheel uint8 :offset-assert 24) - (change-time uint64 :offset-assert 32) ;; time-frame - (button0-abs mouse-buttons 3 :offset-assert 40) ;; guessed by decompiler - (button0-shadow-abs mouse-buttons 1 :offset-assert 52) ;; guessed by decompiler - (button0-rel mouse-buttons 3 :offset-assert 56) ;; guessed by decompiler - (pos vector 2 :offset-assert 80) ;; guessed by decompiler - (UNKNOWN UNKNOWN :offset-assert -1) ;; field could not be read. - (posx float :offset-assert 80) - (posy float :offset-assert 84) - (oldposx float :offset-assert 96) - (oldposy float :offset-assert 100) - (speedx float :offset-assert 92) - (speedy float :offset-assert 108) + ((active symbol :offset-assert 4) ;; guessed by decompiler + (cursor symbol :offset-assert 8) + (valid symbol :offset-assert 12) ;; guessed by decompiler + (id uint8 :offset-assert 16) + (status uint16 :offset-assert 18) + (button0 uint16 :offset-assert 20) + (deltax int8 :offset-assert 22) + (deltay int8 :offset-assert 23) + (wheel uint8 :offset-assert 24) + (change-time time-frame :offset-assert 32) + (button0-abs mouse-buttons 3 :offset-assert 40) ;; guessed by decompiler + (button0-shadow-abs mouse-buttons 1 :offset-assert 52) ;; guessed by decompiler + (button0-rel mouse-buttons 3 :offset-assert 56) ;; guessed by decompiler + (pos vector 2 :inline :offset-assert 80) ;; guessed by decompiler + (posx float :offset 80) + (posy float :offset 84) + (oldposx float :offset 96 :do-not-decompile) + (oldposy float :offset 100) + (speedx float :offset 92) + (speedy float :offset 108) ) :method-count-assert 9 :size-assert #x70 :flag-assert #x900000070 + (:methods + (new (symbol type) _type_) ;; 0 + ) ) -|# -#| +(define-extern mouse-get-data (function mouse-info none)) + (deftype keybd-info (basic) - ((active basic :offset-assert 4) - (valid basic :offset-assert 8) - (kdata UNKNOWN 16 :offset-assert 12) - (keys UNKNOWN 256 :offset-assert 28) + ((active symbol :offset-assert 4) + (valid symbol :offset-assert 8) + (kdata uint8 16 :offset-assert 12) + (keys uint8 256 :offset-assert 28) ) :method-count-assert 9 :size-assert #x11c :flag-assert #x90000011c + (:methods + (new (symbol type) _type_) ;; 0 + ) ) -|# -;; (define-extern *cheat-mode* object) ;; symbol -;; (define-extern cpad-invalid! function) ;; (function cpad-info cpad-info) -;; (define-extern analog-input function) ;; (function int float float float float float) -;; (define-extern cpad-set-buzz! function) ;; (function cpad-info int int time-frame none) -;; (define-extern *cpad-list* object) ;; cpad-list -;; (define-extern *cpad-debug* object) ;; symbol -;; (define-extern service-cpads function) ;; (function cpad-list) -;; (define-extern buzz-stop! function) ;; (function int none) -;; (define-extern *mouse* object) ;; mouse-info -;; (define-extern service-mouse function) ;; (function none) -;; (define-extern *keybd* object) -;; (define-extern service-keybd function) +(define-extern keybd-get-data (function keybd-info none)) + +(define-extern *cheat-mode* symbol) +(define-extern cpad-invalid! "Reset all data in a [[cpad-info]]." (function cpad-info cpad-info)) +(define-extern analog-input + "Convert integer input from pad into a float between -out-range and +out-range. + The offset is applied directly to the input. + The center val is the expected value for 0, after applying offset. + The max val is the expected value with the stick pushed all the way." + (function int float float float float float)) +(define-extern cpad-set-buzz! + "Turn on vibration motor `buzz-idx` for duration, at magnitude `buzz-amount`." + (function cpad-info int int time-frame none)) +(define-extern *cpad-list* cpad-list) +(define-extern *cpad-debug* symbol) +(define-extern service-cpads "Read from cpads and update vibration." (function cpad-list)) +(define-extern buzz-stop! "Set the buzz to 0 on both vibration motors of the given cpad." (function int none)) +(define-extern *mouse* mouse-info) +(define-extern service-mouse "Update the mouse, and draw the cursor." (function none)) +(define-extern *keybd* keybd-info) +(define-extern service-keybd (function none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; gs ;; @@ -4239,25 +4357,25 @@ ;; display-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype display-frame (basic) - ((buffer dma-buffer 11 :offset-assert 4) ;; guessed by decompiler - (calc-buf dma-buffer :offset-assert 8) ;; guessed by decompiler - (vu1-buf dma-buffer :offset-assert 8) ;; guessed by decompiler - (debug-buf dma-buffer :offset-assert 36) ;; guessed by decompiler - (global-buf dma-buffer :offset-assert 40) ;; guessed by decompiler - (bucket-group dma-bucket :offset-assert 44) ;; (inline-array dma-bucket) - (profile-array profile-array :inline :offset-assert 48) - (start-time uint64 :offset-assert 56) ;; int64 - (run-time uint64 :offset-assert 64) ;; int64 + ((buffer dma-buffer 11 :offset-assert 4) ;; guessed by decompiler + (calc-buf dma-buffer :offset 8) ;; guessed by decompiler + (vu1-buf dma-buffer :offset 8) ;; guessed by decompiler + (debug-buf dma-buffer :offset 36) ;; guessed by decompiler + (global-buf dma-buffer :offset 40) ;; guessed by decompiler + (bucket-group (inline-array dma-bucket) :offset 44) ;; (inline-array dma-bucket) + (profile-array profile-array :inline :offset 48) + (start-time uint64 :offset 56) ;; int64 + (run-time uint64 :offset 64) ;; int64 ) :method-count-assert 9 :size-assert #x48 :flag-assert #x900000048 + (:methods + (new (symbol type) _type_) ;; 0 + ) ) -|# -#| (deftype display (basic) ((on-screen int32 :offset-assert 4) (last-screen int32 :offset-assert 8) @@ -4265,35 +4383,35 @@ (bgcolor uint64 :offset-assert 24) ;; gs-bgcolor (pmode uint64 :offset-assert 32) ;; gs-pmode (clock clock 22 :offset-assert 40) ;; guessed by decompiler - (session-clock clock :offset-assert 40) ;; guessed by decompiler - (game-clock clock :offset-assert 44) ;; guessed by decompiler - (base-clock clock :offset-assert 48) ;; guessed by decompiler - (real-clock clock :offset-assert 52) ;; guessed by decompiler - (frame-clock clock :offset-assert 56) ;; guessed by decompiler - (real-frame-clock clock :offset-assert 60) ;; guessed by decompiler - (target-clock clock :offset-assert 64) ;; guessed by decompiler - (entity-clock clock :offset-assert 68) ;; guessed by decompiler - (part-clock clock :offset-assert 72) ;; guessed by decompiler - (bg-clock clock :offset-assert 76) ;; guessed by decompiler - (camera-clock clock :offset-assert 80) ;; guessed by decompiler - (total-game-clock clock :offset-assert 84) ;; guessed by decompiler - (user0-clock clock :offset-assert 88) ;; guessed by decompiler - (user1-clock basic :offset-assert 92) - (user2-clock basic :offset-assert 96) - (user3-clock basic :offset-assert 100) - (user4-clock basic :offset-assert 104) - (user5-clock basic :offset-assert 108) - (user6-clock basic :offset-assert 112) - (user7-clock basic :offset-assert 116) - (user8-clock basic :offset-assert 120) - (user9-clock basic :offset-assert 124) + (session-clock clock :offset 40) ;; guessed by decompiler + (game-clock clock :offset 44) ;; guessed by decompiler + (base-clock clock :offset 48) ;; guessed by decompiler + (real-clock clock :offset 52) ;; guessed by decompiler + (frame-clock clock :offset 56) ;; guessed by decompiler + (real-frame-clock clock :offset 60) ;; guessed by decompiler + (target-clock clock :offset 64) ;; guessed by decompiler + (entity-clock clock :offset 68) ;; guessed by decompiler + (part-clock clock :offset 72) ;; guessed by decompiler + (bg-clock clock :offset 76) ;; guessed by decompiler + (camera-clock clock :offset 80) ;; guessed by decompiler + (total-game-clock clock :offset 84) ;; guessed by decompiler + (user0-clock clock :offset 88) ;; guessed by decompiler + (user1-clock clock :offset 92) + (user2-clock clock :offset 96) + (user3-clock clock :offset 100) + (user4-clock clock :offset 104) + (user5-clock clock :offset 108) + (user6-clock clock :offset 112) + (user7-clock clock :offset 116) + (user8-clock clock :offset 120) + (user9-clock clock :offset 124) (time-factor float :offset-assert 128) (dog-ratio float :offset-assert 132) (vblank-start-time int64 2 :offset-assert 136) ;; guessed by decompiler (total-run-time uint64 :offset-assert 152) ;; int64 - (run-half-speed basic :offset-assert 160) - (vu1-enable-user uint64 :offset-assert 168) ;; vu1-renderer-mask - (vu1-enable-user-menu uint64 :offset-assert 176) ;; vu1-renderer-mask + (run-half-speed symbol :offset-assert 160) + (vu1-enable-user vu1-renderer-mask :offset-assert 168) ;; vu1-renderer-mask + (vu1-enable-user-menu vu1-renderer-mask :offset-assert 176) ;; vu1-renderer-mask (force-sync uint32 :offset-assert 184) (mem-reserve-size uint32 :offset-assert 188) (dma-buffer-overflow basic :offset-assert 192) @@ -4302,14 +4420,13 @@ :size-assert #xc4 :flag-assert #xa000000c4 (:methods - (new (symbol type) _type_) ;; 0 ;; (new (symbol type int int int int int) _type_) - (display-method-9 () none) ;; 9 ;; (set-time-ratios (_type_ float) float) + (new (symbol type int int int int int) _type_) ;; 0 + (set-time-ratios (_type_ float) float) ;; 9 ) ) -|# -;; (define-extern *pre-draw-hook* object) ;; (function object none) -;; (define-extern *post-draw-hook* object) ;; (function dma-buffer none) +(define-extern *pre-draw-hook* (function object none)) +(define-extern *post-draw-hook* (function dma-buffer none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; geometry ;; @@ -4500,17 +4617,25 @@ ;; timer ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(define-extern timer-count (function timer-bank uint)) -(define-extern disable-irq (function none)) -(define-extern enable-irq (function none)) -(define-extern stopwatch-init (function stopwatch int)) -(define-extern stopwatch-reset (function stopwatch int)) -(define-extern stopwatch-start (function stopwatch int)) -(define-extern stopwatch-stop (function stopwatch none)) -(define-extern stopwatch-begin (function stopwatch int)) -(define-extern stopwatch-end (function stopwatch none)) -(define-extern stopwatch-elapsed-ticks (function stopwatch time-frame)) -(define-extern stopwatch-elapsed-seconds (function stopwatch float)) +(define-extern timer-count "Return a timer's counter value." (function timer-bank uint)) +(define-extern disable-irq "Disable all interrupts. Has no effect on PC Port." (function none)) +(define-extern enable-irq "Enable all interrupts. Has no effect on PC Port." (function none)) +(define-extern stopwatch-init "Init a stopwatch." (function stopwatch int)) +(define-extern stopwatch-reset "Restart a stopwatch's times." (function stopwatch int)) +(define-extern stopwatch-start "Start a stopwatch from scratch." (function stopwatch int)) +(define-extern stopwatch-stop "Fully stop a stopwatch and save its elapsed time." (function stopwatch none)) +(define-extern stopwatch-begin "Begin a stopwatch level, and starts it if it hasn't yet." (function stopwatch int)) +(define-extern stopwatch-end + "End a stopwatch level. Stops the stopwatch if it's back to level zero. + There is no guard against ending a stopwatch too many times, and a negative level + will cause errors!" + (function stopwatch none)) +(define-extern stopwatch-elapsed-ticks + "Returns the elapsed time so far (in clock cycles) of a stopwatch." + (function stopwatch time-frame)) +(define-extern stopwatch-elapsed-seconds + "Returns the elapsed time so far (in seconds) of a stopwatch." + (function stopwatch float)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; vector ;; @@ -4768,37 +4893,71 @@ ;; file-io ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| +;; +++file-io:file-kind +(defenum file-kind + :bitfield #f + (level-bt 0) ;; aka bsp-header. + (art-group 1) + (tpage 2) + (dir-tpage 3) + (level-vs 4) + (tx 5) + (vis 6) + (map 7) + ) +;; ---file-io:file-kind + (deftype file-stream (basic) - () + ((flags uint32 :offset-assert 4) + (mode symbol :offset-assert 8) + (name string :offset-assert 12) + (file uint32 :offset-assert 16) + ) + (:methods + (new (symbol type string symbol) _type_) + ) :method-count-assert 9 :size-assert #x14 :flag-assert #x900000014 - ;; Failed to read fields. ) -|# -#| (deftype file-info (basic) - ((file-type (pointer string) :offset-assert 4) ;; guessed by decompiler - (file-name basic :offset-assert 8) - (major-version uint32 :offset-assert 12) - (minor-version uint32 :offset-assert 16) - (maya-file-name basic :offset-assert 20) - (tool-debug basic :offset-assert 24) - (mdb-file-name basic :offset-assert 28) + ((file-type (pointer string) :offset-assert 4) ;; guessed by decompiler + (file-name string :offset-assert 8) + (major-version uint32 :offset-assert 12) + (minor-version uint32 :offset-assert 16) + (maya-file-name string :offset-assert 20) + (tool-debug string :offset-assert 24) + (mdb-file-name string :offset-assert 28) ) :method-count-assert 9 :size-assert #x20 :flag-assert #x900000020 ) -|# -;; (define-extern file-stream-read-string function) ;; (function file-stream string string) -;; (define-extern *file-temp-string* object) ;; string -;; (define-extern make-file-name function) ;; (function file-kind string int symbol string) -;; (define-extern make-vfile-name function) ;; (function file-kind string string) -;; (define-extern file-info-correct-version? function) ;; (function file-info file-kind int symbol) +(define-extern file-stream-read-string + "Fill a string with data from a file stream. + Note: this function does not work." + (function file-stream string string)) +(define-extern *file-temp-string* string) +(define-extern make-file-name + "Get a file name to open a file with the given kind and name. + The art-group-version argument can be used to override the version + of the art-group. Set it to 0 or less to use the default version. + Similar to MakeFileName in C. + Note: file type enum is different between C and GOAL. + File versions should match those in versions.h. + Uses a single *file-temp-string* buffer, shared with make-vfile-name. + arg3 is unused." + (function file-kind string int symbol string)) +(define-extern make-vfile-name + "Make virtual? file name. This makes a name that the kernel knows how to + handle in a specific way. This function is not used." + (function file-kind string string)) +(define-extern file-info-correct-version? + "Check if the version and kind in the info is valid. The `version-override` can specify a + non-default version, or set to 0 for the default version." + (function file-info file-kind int symbol)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; loader-h ;; @@ -6511,8 +6670,9 @@ ;; decomp-h ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype decomp-work (structure) + "Temporary storage for visibility data decompression. + This is stored on the scratchpad." ((buffer0 uint8 2048 :offset-assert 0) ;; guessed by decompiler (buffer1 uint8 2048 :offset-assert 2048) ;; guessed by decompiler (indices uint16 2048 :offset-assert 4096) ;; guessed by decompiler @@ -6522,8 +6682,6 @@ :size-assert #x3000 :flag-assert #x900003000 ) -|# - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; time-of-day-h ;; @@ -6684,10 +6842,10 @@ ;; display ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern get-current-time function) ;; (function time-frame) -;; (define-extern get-integral-current-time function) ;; (function uint) -;; (define-extern get-real-current-time function) -;; (define-extern set-display function) ;; (function display display) +(define-extern get-current-time (function time-frame)) +(define-extern get-integral-current-time (function time-frame)) +(define-extern get-real-current-time (function time-frame)) +(define-extern set-display (function display display)) ;; (define-extern allocate-dma-buffers function) ;; (function display display) ;; (define-extern *font-context* object) ;; font-context ;; (define-extern draw-sprite2d-xy function) ;; (function dma-buffer int int int int rgba none) @@ -6701,7 +6859,7 @@ ;; (define-extern set-display-gs-state-offset function) ;; (function dma-buffer int int int int int int int dma-buffer) ;; (define-extern reset-display-gs-state function) ;; (function display dma-buffer display) ;; (define-extern *vu0-dma-list* object) ;; dma-buffer -;; (define-extern *display* object) ;; display +(define-extern *display* display) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; connect ;; @@ -24838,7 +24996,7 @@ ;; (define-extern history-draw-and-update function) ;; (function pos-history symbol vector symbol) ;; (define-extern dma-timeout-cam function) ;; (function vector) ;; (define-extern display-file-info function) ;; (function int) -;; (define-extern add-debug-cursor function) ;; (function symbol bucket-id int int mouse-buttons int) +(define-extern add-debug-cursor (function symbol bucket-id int int mouse-buttons int)) ;; (define-extern *boundary-polygon* object) ;; (inline-array sky-vertex) ;; (define-extern init-boundary-regs function) ;; (function none) ;; (define-extern add-boundary-shader function) ;; (function texture-id dma-buffer none) @@ -26349,7 +26507,7 @@ ;; settings ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern get-current-language function) ;; (function language-enum) +(define-extern get-current-language (function language-enum)) ;; (define-extern *setting-control* object) ;; setting-control ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc index 292765751..1fa31b2ae 100644 --- a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc +++ b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc @@ -63,7 +63,6 @@ [103, "t9", "(function object object object object object object none)"] ], "send-event-function": [[[7, 15], "a0", "process"]], - "logf": [ [12, "f0", "float"], [12, "f1", "float"], @@ -121,5 +120,7 @@ [13, "s5", "(inline-array vector4)"], [14, "s4", "(inline-array vector4)"], [15, "gp", "(inline-array vector4)"] - ] + ], + "(method 9 clock)": [[47, "v1", "float"]], + "service-cpads": [[[207, 311], "s3", "pad-buttons"]] } diff --git a/decompiler/config/jak3/ntsc_v1/var_names.jsonc b/decompiler/config/jak3/ntsc_v1/var_names.jsonc index af5d33517..73470414e 100644 --- a/decompiler/config/jak3/ntsc_v1/var_names.jsonc +++ b/decompiler/config/jak3/ntsc_v1/var_names.jsonc @@ -416,5 +416,47 @@ "vars": { "v1-0": "val" } + }, + "file-info-correct-version?": { + "args": ["file", "kind", "version-override"], + "vars": { + "s5-0": "major", + "v1-1": "file-kind", + "s4-0": "type" + } + }, + "make-vfile-name": { + "args": ["kind", "name"] + }, + "make-file-name": { + "args": ["kind", "name", "ag-version-override", "arg3"] + }, + "file-stream-read-string": { + "args": ["fs", "str"] + }, + "(method 0 file-stream)": { + "args": ["obj", "arg1", "file-name", "mode"] + }, + "service-cpads": { + "vars": { + "gp-0": "pads", + "s5-0": "pad-idx", + "s4-0": "pad", + "s3-0": "motor-idx", + "s3-1": "buttons-pressed", + "v1-123": "lang", + "v1-135": "territory" + } + }, + "service-keybd": { + "vars": { + "gp-0": "keyboard", + "v1-0": "key-idx" + } + }, + "service-mouse": { + "vars": { + "gp-0": "mouse" + } } } diff --git a/goal_src/jak3/engine/game/task/task-control-h.gc b/goal_src/jak3/engine/game/task/task-control-h.gc index 195cd6abf..c4cddd495 100644 --- a/goal_src/jak3/engine/game/task/task-control-h.gc +++ b/goal_src/jak3/engine/game/task/task-control-h.gc @@ -498,9 +498,9 @@ ) ) -;; WARN: Return type mismatch int vs game-task. +;; og:preserve-this this function appears to have been stubbed out in jak 3 (defun c-string->game-task ((arg0 string)) - (the-as game-task -1) + (game-task unknown) ) (defun-debug game-task-actor->string ((arg0 game-task-actor)) diff --git a/goal_src/jak3/engine/gfx/hw/display-h.gc b/goal_src/jak3/engine/gfx/hw/display-h.gc index 47eb49c4e..1951f2116 100644 --- a/goal_src/jak3/engine/gfx/hw/display-h.gc +++ b/goal_src/jak3/engine/gfx/hw/display-h.gc @@ -5,5 +5,141 @@ ;; name in dgo: display-h ;; dgos: GAME +#|@file +At any point in time, there are 3 frames in progress: +- one frame is fully rendered and being drawn on the screen. + this frame just sits in the frame buffer, and isn't tracked by the display system. +- one frame is being rendered + (frame buffer is being written to by GS, VU1 sending tris to GS, VIF1 feeding VU1) + this frame needs a DMA buffer that is full, and being read by VIF1 +- one frame is being set up. The engine is running gameplay code and generating DMA data + this frame also needs a DMA buffer, which is being filled up. +|# + +(defconstant DEFAULT_ALL_RENDERERS + (vu1-renderer-mask + sky ocean ocean-wave tfrag tie tie-envmap tie-scissor tie-envmap-scissor + tie-vanish generic merc emerc shrubbery shrub-near billboard shrubbery-vanish + tfrag-trans tie-scissor-trans tie-trans tie-envmap-trans tie-envmap-scissor-trans + tfrag-water tie-scissor-water tie-water tie-envmap-water tie-envmap-scissor-water + sprite shadow rn31 rn32 rn33 depth-cue rn36 + ) + ) + ;; DECOMP BEGINS +(deftype display-frame (basic) + ((buffer dma-buffer 11) + (calc-buf dma-buffer :overlay-at (-> buffer 1)) + (vu1-buf dma-buffer :overlay-at (-> buffer 1)) + (debug-buf dma-buffer :overlay-at (-> buffer 8)) + (global-buf dma-buffer :overlay-at (-> buffer 9)) + (bucket-group (inline-array dma-bucket) :overlay-at (-> buffer 10)) + (profile-array profile-array :inline :offset 48) + (start-time uint64 :offset 56) + (run-time uint64 :offset 64) + ) + (:methods + (new (symbol type) _type_) + ) + ) + + +(defmethod new display-frame ((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 calc-buf) (the-as dma-buffer 0)) + (set! (-> gp-0 global-buf) (the-as dma-buffer 0)) + (set! (-> gp-0 debug-buf) (the-as dma-buffer 0)) + (when *debug-segment* + (set! (-> gp-0 profile-array data 0) (new 'debug 'profile-segment-array)) + (set! (-> gp-0 profile-array data 1) (new 'debug 'profile-segment-array)) + ) + gp-0 + ) + ) + +(deftype display (basic) + ((on-screen int32) + (last-screen int32) + (frames display-frame 2) + (bgcolor uint64) + (pmode uint64) + (clock clock 22) + (session-clock clock :overlay-at (-> clock 0)) + (game-clock clock :overlay-at (-> clock 1)) + (base-clock clock :overlay-at (-> clock 2)) + (real-clock clock :overlay-at (-> clock 3)) + (frame-clock clock :overlay-at (-> clock 4)) + (real-frame-clock clock :overlay-at (-> clock 5)) + (target-clock clock :overlay-at (-> clock 6)) + (entity-clock clock :overlay-at (-> clock 7)) + (part-clock clock :overlay-at (-> clock 8)) + (bg-clock clock :overlay-at (-> clock 9)) + (camera-clock clock :overlay-at (-> clock 10)) + (total-game-clock clock :overlay-at (-> clock 11)) + (user0-clock clock :overlay-at (-> clock 12)) + (user1-clock clock :overlay-at (-> clock 13)) + (user2-clock clock :overlay-at (-> clock 14)) + (user3-clock clock :overlay-at (-> clock 15)) + (user4-clock clock :overlay-at (-> clock 16)) + (user5-clock clock :overlay-at (-> clock 17)) + (user6-clock clock :overlay-at (-> clock 18)) + (user7-clock clock :overlay-at (-> clock 19)) + (user8-clock clock :overlay-at (-> clock 20)) + (user9-clock clock :overlay-at (-> clock 21)) + (time-factor float) + (dog-ratio float) + (vblank-start-time int64 2) + (total-run-time uint64) + (run-half-speed symbol) + (vu1-enable-user vu1-renderer-mask) + (vu1-enable-user-menu vu1-renderer-mask) + (force-sync uint32) + (mem-reserve-size uint32) + (dma-buffer-overflow basic) + ) + (:methods + (new (symbol type int int int int int) _type_) + (set-time-ratios (_type_ float) float) + ) + ) + +(define-extern set-display (function display display)) + +(defmethod new display ((allocation symbol) (type-to-make type) (arg0 int) (arg1 int) (arg2 int) (arg3 int) (arg4 int)) + (let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set-display gp-0) + (set! (-> gp-0 frames 0) (new 'global 'display-frame)) + (set! (-> gp-0 frames 1) (new 'global 'display-frame)) + (set! (-> gp-0 pmode) (the-as uint 165)) + (set! (-> gp-0 run-half-speed) #f) + (set! (-> gp-0 vu1-enable-user-menu) DEFAULT_ALL_RENDERERS) + (set! (-> gp-0 vu1-enable-user) DEFAULT_ALL_RENDERERS) + gp-0 + ) + ) + +(define *pre-draw-hook* (the-as (function object none) nothing)) + +(define *post-draw-hook* (the-as (function dma-buffer none) nothing)) + +(define-extern *display* display) + +(defmacro current-frame () + `(-> *display* frames (-> *display* on-screen)) + ) + +(defmacro integral-current-time () + `(-> *display* integral-frame-counter) + ) + +(defmacro real-current-time () + `(-> *display* real-frame-counter) + ) + +;; debug stuff really +(defmacro get-screen-x (frac) + `(the int (* ,frac 512))) + +(defmacro get-screen-y (frac) + `(the int (* ,frac 416))) \ No newline at end of file diff --git a/goal_src/jak3/engine/gfx/vu1-user-h.gc b/goal_src/jak3/engine/gfx/vu1-user-h.gc index 2b0405b30..1d296a11e 100644 --- a/goal_src/jak3/engine/gfx/vu1-user-h.gc +++ b/goal_src/jak3/engine/gfx/vu1-user-h.gc @@ -5,13 +5,64 @@ ;; name in dgo: vu1-user-h ;; dgos: GAME +;; +++tpage-category (defenum tpage-category :type int8 ) +;; ---tpage-category +;; +++bucket-id (defenum bucket-id :type int32 + (debug-no-zbuf2 584) ) +;; ---bucket-id + +;; +++vu1-renderer-mask +;; TODO stolen from Jak 2 +(defenum vu1-renderer-mask + :type uint64 + :bitfield #t + (rn0) + (rn1) + (rn2) + (sky) + (ocean) + (ocean-wave) + (tfrag) + (tie) + (tie-envmap) + (tie-scissor) + (tie-envmap-scissor) + (tie-vanish) + (generic) + (merc) + (emerc) + (shrubbery) + (shrub-near) + (billboard) + (shrubbery-vanish) + (tfrag-trans) + (tie-scissor-trans) + (tie-trans) + (tie-envmap-trans) + (tie-envmap-scissor-trans) + (tfrag-water) + (tie-scissor-water) + (tie-water) + (tie-envmap-water) + (tie-envmap-scissor-water) + (sprite) + (shadow) + (rn31) + (rn32) + (rn33) + (depth-cue) + (rn35) + (rn36) + (rn37) + ) +;; ---vu1-renderer-mask ;; DECOMP BEGINS diff --git a/goal_src/jak3/engine/load/decomp-h.gc b/goal_src/jak3/engine/load/decomp-h.gc index 98449f5e0..82ebd46df 100644 --- a/goal_src/jak3/engine/load/decomp-h.gc +++ b/goal_src/jak3/engine/load/decomp-h.gc @@ -7,3 +7,12 @@ ;; DECOMP BEGINS +(deftype decomp-work (structure) + "Temporary storage for visibility data decompression. +This is stored on the scratchpad." + ((buffer0 uint8 2048) + (buffer1 uint8 2048) + (indices uint16 2048) + (temp-indices uint16 2048) + ) + ) diff --git a/goal_src/jak3/engine/load/file-io.gc b/goal_src/jak3/engine/load/file-io.gc index 84e6e76c0..350e8c9f9 100644 --- a/goal_src/jak3/engine/load/file-io.gc +++ b/goal_src/jak3/engine/load/file-io.gc @@ -5,5 +5,235 @@ ;; name in dgo: file-io ;; dgos: GAME +#|@file +GOAL File I/O +This is mostly not used in the retail game and was more for loading stuff during development. +The file-stream is an inefficient way to load data, but is flexible and can load +from the CD, or over the network in development. +The file-info type is used in actual game data for checking versions. + +Represents a file that can be read/written, similar to FILE* in C. + +NOTE: this is a special type in three ways: + 1). It is used in the C runtime. This must be kept in sync with kmachine.h's FileStream. + 2). This type is built-in to the compiler (see TypeSystem.cpp, add_builtin_types). + It must be kept up to date with that definition as well. + 3). The C runtime constructs this type before anything is loaded. The sizes + must be kept up to date there as well. +|# + +;; +++file-kind +(defenum file-kind + :bitfield #f + (level-bt 0) ;; aka bsp-header. + (art-group 1) + (tpage 2) + (dir-tpage 3) + (level-vs 4) + (tx 5) + (vis 6) + (map 7) + ) +;; ---file-kind + +(defconstant SCE_SEEK_SET 0) +(defconstant SCE_SEEK_CUR 1) +(defconstant SCE_SEEK_END 2) + +(defconstant LEVEL_BT_FILE_VERSION 36) +(defconstant ART_GROUP_FILE_VERSION 8) +(defconstant TPAGE_FILE_VERSION 8) ;; also used for dir +(defconstant LEVEL_VS_FILE_VERSION 30) +(defconstant TX_FILE_VERSION 1) +(defconstant MAP_FILE_VERSION 1) + +(defmacro file-stream-valid? (fs) + `(>= (the-as int (-> ,fs file)) 0) + ) + +(defmacro file-stream-tell (fs) + `(file-stream-seek ,fs 0 SCE_SEEK_CUR) + ) + ;; DECOMP BEGINS +(deftype file-stream (basic) + ((flags uint32) + (mode symbol) + (name string) + (file uint32) + ) + (:methods + (new (symbol type string symbol) _type_) + ) + ) + + +(defmethod new file-stream ((obj symbol) (arg1 type) (file-name string) (mode symbol)) + (let ((a0-1 (object-new obj arg1 (the-as int (-> arg1 size))))) + (file-stream-open a0-1 file-name mode) + ) + ) + +(set! (-> file-stream method-table 4) file-stream-length) + +(defun file-stream-read-string ((fs file-stream) (str string)) + "Fill a string with data from a file stream. + Note: this function does not work." + (clear str) + (file-stream-read fs (-> str data) (length fs)) + str + ) + +(deftype file-info (basic) + ((file-type (pointer string)) + (file-name string) + (major-version uint32) + (minor-version uint32) + (maya-file-name string) + (tool-debug string) + (mdb-file-name string) + ) + ) + + +(defmethod print ((this file-info)) + (format + #t + "#<~A ~A :version ~D.~D @ #x~X>" + (-> this type) + (-> this file-name) + (-> this major-version) + (-> this minor-version) + this + ) + this + ) + +(define *file-temp-string* (new 'global 'string 128 (the-as string #f))) + +(defun make-file-name ((kind file-kind) (name string) (ag-version-override int) (arg3 symbol)) + "Get a file name to open a file with the given kind and name. + The art-group-version argument can be used to override the version + of the art-group. Set it to 0 or less to use the default version. + Similar to MakeFileName in C. + Note: file type enum is different between C and GOAL. + File versions should match those in versions.h. + Uses a single *file-temp-string* buffer, shared with make-vfile-name. + arg3 is unused." + (clear *file-temp-string*) + (cond + ((= kind (file-kind dir-tpage)) + (format *file-temp-string* "texture-page~D/dir-tpages" TPAGE_FILE_VERSION) + ) + ((= kind (file-kind tpage)) + (format *file-temp-string* "texture-page~D/tpage-~S" TPAGE_FILE_VERSION name) + ) + ((= kind (file-kind level-bt)) + (format *file-temp-string* "level~D/~S-bt" LEVEL_BT_FILE_VERSION name) + ) + ((= kind (file-kind tx)) + (format *file-temp-string* "res~D/~S-tx" TX_FILE_VERSION name) + ) + ((= kind (file-kind level-vs)) + (format *file-temp-string* "level~D/~S-vs" LEVEL_BT_FILE_VERSION name) + ) + ((= kind (file-kind vis)) + (format *file-temp-string* "~S.VIS" name) + ) + ((= kind (file-kind map)) + (format *file-temp-string* "map~D/~S-mp" MAP_FILE_VERSION name) + ) + ((= kind (file-kind art-group)) + (format + *file-temp-string* + "art-group~D/~S-ag" + (cond + ((> ag-version-override 0) + (empty) + ag-version-override + ) + (else + ART_GROUP_FILE_VERSION + ) + ) + name + ) + ) + ) + *file-temp-string* + ) + +(defun make-vfile-name ((kind file-kind) (name string)) + "Make virtual? file name. This makes a name that the kernel knows how to + handle in a specific way. This function is not used." + (clear *file-temp-string*) + (cond + ((= kind (file-kind level-bt)) + (format *file-temp-string* "$LEVEL/~S" name) + ) + ((= kind (file-kind art-group)) + (format *file-temp-string* "$ART_GROUP/~S" name) + ) + ) + *file-temp-string* + ) + +(defun file-info-correct-version? ((file file-info) (kind file-kind) (version-override int)) + "Check if the version and kind in the info is valid. The `version-override` can specify a + non-default version, or set to 0 for the default version." + (let* ((major (cond + ((zero? version-override) + (case kind + (((file-kind tpage) (file-kind dir-tpage)) + 8 + ) + (((file-kind level-bt)) + 36 + ) + (((file-kind art-group)) + 8 + ) + ) + ) + (else + version-override + ) + ) + ) + (file-kind kind) + (type (cond + ((= file-kind (file-kind tpage)) + "texture-page" + ) + ((= file-kind (file-kind level-bt)) + "bsp-header" + ) + ((= file-kind (file-kind art-group)) + "art-group" + ) + ) + ) + ) + (cond + ((not (name= (-> file file-type 0) type)) + (format 0 "ERROR: file ~A is of type ~S but needs to be ~S.~%" (-> file file-name) (-> file file-type) type) + #f + ) + ((!= major (-> file major-version)) + (format + 0 + "ERROR: file ~A is version ~D.~D, but needs to be ~D.x~%" + (-> file file-name) + (-> file major-version) + (-> file minor-version) + major + ) + #f + ) + (else + #t + ) + ) + ) + ) diff --git a/goal_src/jak3/engine/ps2/pad.gc b/goal_src/jak3/engine/ps2/pad.gc index 512b237b2..38cb79d13 100644 --- a/goal_src/jak3/engine/ps2/pad.gc +++ b/goal_src/jak3/engine/ps2/pad.gc @@ -5,5 +5,776 @@ ;; name in dgo: pad ;; dgos: GAME +;; +++mouse-buttons +(defenum mouse-buttons + :bitfield #t + :type uint32 + (left) + (right) + (middle) + ) +;; ---mouse-buttons + + +;; +++pad-buttons +(defenum pad-buttons + :bitfield #t + :type uint32 + (select 0) + (l3 1) + (r3 2) + (start 3) + (up 4) + (right 5) + (down 6) + (left 7) + (l2 8) + (r2 9) + (l1 10) + (r1 11) + (triangle 12) + (circle 13) + (x 14) + (square 15) + ;; only 16 buttons are mapped to hardware, the rest are 'actions' or something else + (l-analog-up 16) + (l-analog-right 17) + (l-analog-down 18) + (l-analog-left 19) + (r-analog-up 20) + (r-analog-right 21) + (r-analog-down 22) + (r-analog-left 23) + (confirm 24) + ) +;; ---pad-buttons + +;; TODO +;; (#when PC_PORT +;; ;; redefined from C kernel +;; (defun scf-get-territory () +;; "redefined from C kernel for convenience" +;; (if (= (-> *pc-settings* territory) -1) +;; *default-territory* +;; (-> *pc-settings* territory)) +;; ) +;; ) + +(define-extern add-debug-cursor (function symbol bucket-id int int mouse-buttons int)) +(define-extern get-current-time (function time-frame)) +(define-extern get-integral-current-time (function time-frame)) +(define-extern get-real-current-time (function time-frame)) +(define-extern get-current-language (function language-enum)) + ;; DECOMP BEGINS +(deftype scf-time (structure) + ((stat uint8) + (second uint8) + (minute uint8) + (hour uint8) + (week uint8) + (day uint8) + (month uint8) + (year uint8) + ) + ) + +(define-extern scf-get-time (function scf-time none)) + +;; this gets set to #f later on. +(define *cheat-mode* #t) + +(deftype hw-cpad (basic) + "Data that comes directly from hardware. + It's 32 bytes + type tag (ignored by C kernel)." + (;; BASIC CONTROLLER data + ;; status = 0x40 | (data length / 2) + (valid uint8) ;; 0 if success, 255 if fail + (status uint8) ;; depends on controller + (button0 uint16) ;; binary button states! + ;; DUALSHOCK or JOYSTICK data + ;; status (dualshock) = 0x70 | (data length / 2) + ;; status (joystick) = 0x50 | (data length / 2) + (rightx uint8) ;; right stick xdir + (righty uint8) ;; right stick ydir + (leftx uint8) ;; left stick xdir + (lefty uint8) ;; left stick ydir + ;; DUALSHOCK 2 data + ;; status = 0x70 | (data length / 2) + (abutton uint8 12) ;; pressure sensitivity information + + ;; pad buffer needs to be 32 bytes large. + (dummy uint8 12) + ) + ) + + +(deftype cpad-info (hw-cpad) + "Data from hardware + additional info calculated here." + ((number int32) + (cpad-file int32) + (button0-abs pad-buttons 3) + (button0-shadow-abs pad-buttons 1) + (button0-rel pad-buttons 3) + (stick0-dir float) + (stick0-speed float) + (new-pad int32) + (state int32) + (align uint8 6) + (direct uint8 6) + (buzz-val uint8 2) + (buzz-pause-val uint8 1) + (buzz-pause-time uint8) + (buzz-time time-frame 2) + (buzz basic) + (buzz-act int32) + (change-time uint64) + (real-change-time uint64) + (old-rightx uint8 2) + (old-righty uint8 2) + (old-leftx uint8 2) + (old-lefty uint8 2) + ) + (:methods + (new (symbol type int) _type_) + (adjust-to-screen-flip (_type_) int) + ) + ) + + +(defun cpad-invalid! ((arg0 cpad-info)) + "Reset all data in a [[cpad-info]]." + (logior! (-> arg0 valid) 128) + (set! (-> arg0 button0) (the-as uint 0)) + (set! (-> arg0 button0-abs 0) (pad-buttons)) + (set! (-> arg0 button0-shadow-abs 0) (pad-buttons)) + (set! (-> arg0 button0-rel 0) (pad-buttons)) + (dotimes (v1-2 12) + (nop!) + (set! (-> arg0 abutton v1-2) (the-as uint 0)) + ) + (set! (-> arg0 stick0-dir) 0.0) + (set! (-> arg0 stick0-speed) 0.0) + (set! (-> arg0 rightx) (the-as uint 128)) + (set! (-> arg0 righty) (the-as uint 128)) + (set! (-> arg0 leftx) (the-as uint 128)) + (set! (-> arg0 lefty) (the-as uint 128)) + (set! (-> arg0 align 0) (the-as uint 0)) + (set! (-> arg0 align 1) (the-as uint 1)) + (set! (-> arg0 align 2) (the-as uint 255)) + (set! (-> arg0 align 3) (the-as uint 255)) + (set! (-> arg0 align 4) (the-as uint 255)) + (set! (-> arg0 align 5) (the-as uint 255)) + (dotimes (v1-14 6) + (nop!) + (set! (-> arg0 direct v1-14) (the-as uint 0)) + ) + (dotimes (v1-17 2) + (nop!) + (set! (-> arg0 buzz-val v1-17) (the-as uint 0)) + (set! (-> arg0 buzz-time v1-17) 0) + ) + (set! (-> arg0 buzz-pause-val 0) (the-as uint 0)) + (set! (-> arg0 buzz-time 0) 0) + arg0 + ) + +(defmethod new cpad-info ((allocation symbol) (type-to-make type) (arg0 int)) + "Allocate a new cpad-info and open the pad itself through the kernel." + (let ((s5-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> s5-0 number) arg0) + (set! (-> s5-0 buzz) #f) + (cpad-open s5-0 arg0) + (cpad-invalid! s5-0) + ) + ) + +(deftype cpad-list (basic) + "List of controllers. It always has two controllers." + ((num-cpads int32) + (cpads cpad-info 2) + ) + (:methods + (new (symbol type) _type_) + ) + ) + + +(defmethod new cpad-list ((allocation symbol) (type-to-make type)) + "Create a cpad-list for 2 controllers. It's fine to do this even if one or both controllers + aren't connected yet." + (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 + ) + ) + +(defun analog-input ((arg0 int) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Convert integer input from pad into a float between -out-range and +out-range. + The offset is applied directly to the input. + The center val is the expected value for 0, after applying offset. + The max val is the expected value with the stick pushed all the way." + (let* ((f1-1 (- (the float arg0) arg1)) + (f0-3 (- (fabs f1-1) arg2)) + (v1-0 (- arg3 arg2)) + ) + (if (< f1-1 0.0) + (set! arg4 (- arg4)) + ) + (cond + ((>= 0.0 f0-3) + 0.0 + ) + ((>= f0-3 v1-0) + arg4 + ) + (else + (/ (* f0-3 arg4) v1-0) + ) + ) + ) + ) + +;; og:preserve-this macros +(defmacro analog-input-horizontal-first (in offset center-val max-val out-range) + "Same as analog-input, but respects first person horizontal camera control setting." + `(#if PC_PORT ;; first-person horizontal is NOT inverted in original game + (* (if (-> *pc-settings* first-camera-h-inverted?) -1.0 1.0) + (analog-input ,in ,offset ,center-val ,max-val ,out-range)) + (analog-input ,in ,offset ,center-val ,max-val ,out-range) + ) + ) + +(defmacro analog-input-vertical-first (in offset center-val max-val out-range) + "Same as analog-input, but respects first person vertical camera control setting." + `(#if PC_PORT ;; first-person vertical is already inverted in original game + (* (if (-> *pc-settings* first-camera-v-inverted?) 1.0 -1.0) + (analog-input ,in ,offset ,center-val ,max-val ,out-range)) + (analog-input ,in ,offset ,center-val ,max-val ,out-range) + ) + ) + +(defmacro analog-input-horizontal-third (in offset center-val max-val out-range) + "Same as analog-input, but respects third person horizontal camera control setting." + `(#if PC_PORT ;; third-person horizontal is already inverted in original game + (* (if (-> *pc-settings* third-camera-h-inverted?) 1.0 -1.0) + (analog-input ,in ,offset ,center-val ,max-val ,out-range)) + (analog-input ,in ,offset ,center-val ,max-val ,out-range) + ) + ) + +(defmacro analog-input-vertical-third (in offset center-val max-val out-range) + "Same as analog-input, but respects third person vertical camera control setting." + `(#if PC_PORT ;; third-person vertical is already inverted in original game + (* (if (-> *pc-settings* third-camera-v-inverted?) 1.0 -1.0) + (analog-input ,in ,offset ,center-val ,max-val ,out-range)) + (analog-input ,in ,offset ,center-val ,max-val ,out-range) + ) + ) + +(defun cpad-set-buzz! ((arg0 cpad-info) (arg1 int) (arg2 int) (arg3 time-frame)) + "Turn on vibration motor `buzz-idx` for duration, at magnitude `buzz-amount`." + (cond + ((zero? arg2) + (set! (-> arg0 buzz-val arg1) (the-as uint 0)) + 0 + ) + ((= arg2 (-> arg0 buzz-val arg1)) + (set! (-> arg0 buzz-time arg1) (the-as time-frame (max (-> arg0 buzz-time arg1) (+ (get-current-time) arg3)))) + ) + ((< (-> arg0 buzz-val arg1) (the-as uint arg2)) + (set! (-> arg0 buzz-val arg1) (the-as uint arg2)) + (set! (-> arg0 buzz-time arg1) (+ (get-current-time) arg3)) + ) + ) + 0 + (none) + ) + +(define *cpad-list* (new 'global 'cpad-list)) + +(define *cpad-debug* #f) + +;; TODO +;; (#if PC_PORT +;; (defconstant STICK_DEADZONE (-> *pc-settings* stick-deadzone)) +;; (defconstant STICK_DEADZONE 0.3) +;; ) +(defconstant STICK_DEADZONE 0.3) + +(defun service-cpads () + "Read from cpads and update vibration." + (let ((pads *cpad-list*)) + (dotimes (pad-idx (-> pads num-cpads)) + (let ((pad (-> *cpad-list* cpads pad-idx))) + (set! (-> pad old-leftx 1) (-> pad old-leftx 0)) + (set! (-> pad old-leftx 0) (-> pad leftx)) + (set! (-> pad old-lefty 1) (-> pad old-lefty 0)) + (set! (-> pad old-lefty 0) (-> pad lefty)) + (set! (-> pad old-rightx 1) (-> pad old-rightx 0)) + (set! (-> pad old-rightx 0) (-> pad rightx)) + (set! (-> pad old-righty 1) (-> pad old-righty 0)) + (set! (-> pad old-righty 0) (-> pad righty)) + (cpad-get-data pad) + (adjust-to-screen-flip pad) + (cond + ((not (logtest? (-> pad valid) 128)) + (dotimes (motor-idx 2) + (cond + ((and (-> pad buzz) (< (get-current-time) (-> pad buzz-time motor-idx)) (= *master-mode* 'game)) + (let ((v1-20 motor-idx)) + (cond + ((zero? v1-20) + (set! (-> pad direct motor-idx) + (logand (ash (-> pad buzz-val motor-idx) (- (the-as int (logand (get-integral-current-time) 7)))) 1) + ) + ) + ((= v1-20 1) + (set! (-> pad direct motor-idx) (-> pad buzz-val motor-idx)) + ) + ) + ) + ) + ((and (zero? motor-idx) (> (-> pad buzz-pause-time) 0)) + (set! (-> pad direct motor-idx) + (logand (ash (-> pad buzz-pause-val motor-idx) (- (the-as int (logand (get-integral-current-time) 7)))) 1) + ) + (+! (-> pad buzz-pause-time) -1) + ) + (else + (set! (-> pad buzz-val motor-idx) (the-as uint 0)) + (set! (-> pad direct motor-idx) (the-as uint 0)) + (when (zero? motor-idx) + (set! (-> pad buzz-pause-time) (the-as uint 0)) + 0 + ) + ) + ) + ) + (when (< (the-as uint 192) (-> pad direct 1)) + (set! (-> pad direct 0) (the-as uint 0)) + 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)) + (when (= (-> pad status) 115) + (set! (-> pad abutton 0) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons right)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 1) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons left)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 2) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons up)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 3) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons down)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 6) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons x)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 5) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons circle)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 4) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons triangle)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 7) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons square)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 8) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons l1)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 10) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons l2)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 9) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons r1)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 11) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons r2)) + 255 + 0 + ) + ) + ) + ) + (let ((buttons-pressed (the-as pad-buttons (-> pad button0)))) + (cond + ((< (-> pad lefty) (the-as uint 30)) + (set! buttons-pressed (logior (pad-buttons l-analog-up) buttons-pressed)) + ) + ((< (the-as uint 225) (-> pad lefty)) + (set! buttons-pressed (logior (pad-buttons l-analog-down) buttons-pressed)) + ) + ) + (cond + ((< (-> pad leftx) (the-as uint 30)) + (set! buttons-pressed (logior (pad-buttons l-analog-left) buttons-pressed)) + ) + ((< (the-as uint 225) (-> pad leftx)) + (set! buttons-pressed (logior (pad-buttons l-analog-right) buttons-pressed)) + ) + ) + (cond + ((< (-> pad righty) (the-as uint 30)) + (set! buttons-pressed (logior (pad-buttons r-analog-up) buttons-pressed)) + ) + ((< (the-as uint 225) (-> pad righty)) + (set! buttons-pressed (logior (pad-buttons r-analog-down) buttons-pressed)) + ) + ) + (cond + ((< (-> pad rightx) (the-as uint 30)) + (set! buttons-pressed (logior (pad-buttons r-analog-left) buttons-pressed)) + ) + ((< (the-as uint 225) (-> pad rightx)) + (set! buttons-pressed (logior (pad-buttons r-analog-right) buttons-pressed)) + ) + ) + (let ((lang (get-current-language))) + (cond + ((or (= lang (language-enum japanese)) (= lang (language-enum korean))) + (case (scf-get-territory) + ((2 3) + (if (logtest? buttons-pressed (pad-buttons circle)) + (set! buttons-pressed (logior (pad-buttons confirm) buttons-pressed)) + ) + ) + (else + (if (logtest? buttons-pressed (pad-buttons circle x)) + (set! buttons-pressed (logior (pad-buttons confirm) buttons-pressed)) + ) + ) + ) + ) + ((let ((territory (scf-get-territory))) + (or (= territory 2) (= territory 3)) + ) + (if (logtest? buttons-pressed (pad-buttons circle x)) + (set! buttons-pressed (logior (pad-buttons confirm) buttons-pressed)) + ) + ) + (else + (if (logtest? buttons-pressed (pad-buttons x)) + (set! buttons-pressed (logior (pad-buttons confirm) buttons-pressed)) + ) + ) + ) + ) + (set! (-> pad button0-shadow-abs 0) buttons-pressed) + (set! (-> pad button0-abs 0) buttons-pressed) + ) + (set! (-> pad button0-rel 0) (logclear (-> pad button0-abs 0) (-> 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) STICK_DEADZONE) + (set! (-> pad stick0-speed) 0.0) + ) + ) + (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) + (set! (-> pad stick0-speed) 0.0) + ) + ) + (when (or (!= (-> pad button0-abs 0) (-> pad button0-abs 1)) + (or (< STICK_DEADZONE (-> pad stick0-speed)) (zero? (-> pad change-time))) + ) + (set! (-> pad change-time) (the-as uint (get-current-time))) + (set! (-> pad real-change-time) (the-as uint (get-real-current-time))) + ) + ) + (else + (cpad-invalid! pad) + ) + ) + ) + ) + ) + *cpad-list* + ) + +(defun buzz-stop! ((arg0 int)) + "Set the buzz to 0 on both vibration motors of the given cpad." + (cpad-set-buzz! (-> *cpad-list* cpads arg0) 0 0 0) + (cpad-set-buzz! (-> *cpad-list* cpads arg0) 1 0 0) + 0 + (none) + ) + +(defmacro cpad-pressed (pad-idx) + `(-> *cpad-list* cpads ,pad-idx button0-rel 0) + ) + +(defmacro cpad-hold (pad-idx) + `(-> *cpad-list* cpads ,pad-idx button0-abs 0) + ) + +(defmacro cpad-pressed? (pad-idx &rest buttons) + `(logtest? (cpad-pressed ,pad-idx) (pad-buttons ,@buttons)) + ) + +(defmacro cpad-hold? (pad-idx &rest buttons) + `(logtest? (cpad-hold ,pad-idx) (pad-buttons ,@buttons)) + ) + +(defmacro cpad-clear! (pad-idx &rest buttons) + `(begin + (logclear! (cpad-pressed ,pad-idx) (pad-buttons ,@buttons)) + (logclear! (cpad-hold ,pad-idx) (pad-buttons ,@buttons)) + ) + ) + +(defmacro cpad-change-time (pad-idx) + `(-> *cpad-list* cpads ,pad-idx change-time) + ) + +(deftype mouse-info (basic) + ((active symbol) + (cursor symbol) + (valid symbol) + (id uint8) + (status uint16) + (button0 uint16) + (deltax int8) + (deltay int8) + (wheel uint8) + (change-time time-frame) + (button0-abs mouse-buttons 3) + (button0-shadow-abs mouse-buttons 1) + (button0-rel mouse-buttons 3) + (pos vector 2 :inline) + (posx float :overlay-at (-> pos 0 data 0)) + (posy float :overlay-at (-> pos 0 data 1)) + (oldposx float :offset 96) + (oldposy float :offset 100) + (speedx float :overlay-at (-> pos 0 data 3)) + (speedy float :offset 108) + ) + (:methods + (new (symbol type) _type_) + ) + ) + + +(defmethod new mouse-info ((allocation symbol) (type-to-make type)) + (let ((v0-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> v0-0 active) #f) + (set! (-> v0-0 valid) #f) + (set! (-> v0-0 cursor) #f) + v0-0 + ) + ) + +(define *mouse* (new 'global 'mouse-info)) +(#when PC_PORT +;; added so we can hide the mouse +(define *disable-mouse* #f) +) + +;; WARN: Return type mismatch mouse-info vs none. +(defun service-mouse () + "Update the mouse, and draw the cursor." + (let ((mouse *mouse*)) + (mouse-get-data mouse) + (set! (-> mouse pos 1 quad) (-> mouse pos 0 quad)) + (set! (-> mouse button0-abs 2) (-> mouse button0-abs 1)) + (set! (-> mouse button0-abs 1) (-> mouse button0-shadow-abs 0)) + (set! (-> mouse button0-rel 2) (-> mouse button0-rel 1)) + (set! (-> mouse button0-rel 1) (-> mouse button0-rel 0)) + (set! (-> mouse button0-rel 0) (mouse-buttons)) + (set! (-> mouse speedx) 0.0) + (set! (-> mouse speedy) 0.0) + (cond + ((or (not (-> mouse valid)) (not (-> mouse active))) + (set! (-> mouse valid) #f) + (set! (-> mouse status) (the-as uint 0)) + (set! (-> mouse pos 0 quad) (the-as uint128 0)) + (set! (-> mouse pos 1 quad) (the-as uint128 0)) + ) + ((logtest? (-> mouse status) 1) + (set! (-> mouse change-time) (get-current-time)) + (set! (-> mouse speedx) + (* (sign (the float (-> mouse deltax))) (pow (fabs (the float (-> mouse deltax))) 1.3)) + ) + (set! (-> mouse speedy) + (* (sign (the float (-> mouse deltay))) (pow (fabs (the float (-> mouse deltay))) 1.3)) + ) + (set! (-> mouse posx) (fmax -256.0 (fmin 256.0 (+ (-> mouse posx) (-> mouse speedx))))) + (set! (-> mouse posy) (fmax -208.0 (fmin 208.0 (+ (-> mouse posy) (-> mouse speedy))))) + (let ((v1-22 (-> mouse button0))) + (set! (-> mouse button0-shadow-abs 0) (the-as mouse-buttons v1-22)) + (set! (-> mouse button0-abs 0) (the-as mouse-buttons v1-22)) + ) + (set! (-> mouse button0-rel 0) (logclear (-> mouse button0-abs 0) (-> mouse button0-abs 1))) + ) + ) + (if (and (-> mouse active) (-> mouse valid) (-> mouse cursor)) + (add-debug-cursor + #t + (bucket-id debug-no-zbuf2) + (+ (the int (-> mouse posx)) 256) + (+ (the int (-> mouse posy)) 208) + (-> mouse button0-abs 0) + ) + ) + ) + (none) + ) + +(defmacro mouse-pressed () + `(-> *mouse* button0-rel 0) + ) + +(defmacro mouse-hold () + `(-> *mouse* button0-abs 0) + ) + +(defmacro mouse-pressed? (&rest buttons) + `(logtest? (mouse-pressed) (mouse-buttons ,@buttons)) + ) + +(defmacro mouse-hold? (&rest buttons) + `(logtest? (mouse-hold) (mouse-buttons ,@buttons)) + ) + +(defmacro mouse-clear! (&rest buttons) + `(begin + (logclear! (mouse-pressed) (mouse-buttons ,@buttons)) + (logclear! (mouse-hold) (mouse-buttons ,@buttons)) + ) + ) + +(deftype keybd-info (basic) + ((active symbol) + (valid symbol) + (kdata uint8 16) + (keys uint8 256) + ) + (:methods + (new (symbol type) _type_) + ) + ) + + +(defmethod new keybd-info ((allocation symbol) (type-to-make type)) + (let ((v0-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> v0-0 active) #f) + (set! (-> v0-0 valid) #f) + v0-0 + ) + ) + +(define *keybd* (new 'global 'keybd-info)) + +;; WARN: Return type mismatch keybd-info vs none. +(defun service-keybd () + (let ((keyboard *keybd*)) + (keybd-get-data keyboard) + (dotimes (key-idx 256) + (cond + ((= (-> keyboard keys key-idx) 1) + (set! (-> keyboard keys key-idx) (the-as uint 2)) + ) + ((= (-> keyboard keys key-idx) 2) + (set! (-> keyboard keys key-idx) (the-as uint 0)) + 0 + ) + ) + ) + (dotimes (v1-3 (the-as int (+ (-> keyboard kdata 1) -2))) + (if (and (nonzero? (-> keyboard kdata (+ v1-3 4))) (!= (-> keyboard kdata (+ v1-3 4)) 1)) + (set! (-> keyboard keys (-> keyboard kdata (+ v1-3 4))) (the-as uint 1)) + ) + ) + (if (nonzero? (-> keyboard kdata 1)) + (set! (-> keyboard keys 0) (-> keyboard kdata 2)) + ) + ) + (none) + ) + +(defmacro check-cheat-code (cheat-var pad-idx buttons &rest body) + "execute body when a cheat code made up of sequential inputs has been inputted" + + `(when (nonzero? (cpad-pressed ,pad-idx)) ;; only check when some button has been pressed + (case ,cheat-var + ,@(apply-i + (lambda (x i) + `((,i) + (if (cpad-pressed? ,pad-idx ,x) + ,(if (< i (- (length buttons) 1)) + `(1+! ,cheat-var) + + `(begin ,@body (set! ,cheat-var 0)) + ) + + (set! ,cheat-var 0) + ) + ) + ) + buttons) + ) + ) + ) + +(defmacro cheats-sound-play (cheat?) + "play the appropriate sound for inputting a cheat code" + + `(if ,cheat? + (sound-play-by-spec (static-sound-spec "menu-pick" :fo-curve 1) (new-sound-id) (the-as vector #t)) + (sound-play-by-spec (static-sound-spec "menu-back" :fo-curve 1) (new-sound-id) (the-as vector #t)) + ) + ) diff --git a/goal_src/jak3/engine/ps2/timer.gc b/goal_src/jak3/engine/ps2/timer.gc index 8b00912ac..0ee32f9c9 100644 --- a/goal_src/jak3/engine/ps2/timer.gc +++ b/goal_src/jak3/engine/ps2/timer.gc @@ -7,3 +7,265 @@ ;; DECOMP BEGINS +(defun timer-count ((arg0 timer-bank)) + "Return a timer's counter value." + (#when PC_PORT + (when (= arg0 TIMER1_BANK) + (return (- (get-bus-clock/256) *timer-reset-value*)) + ) + (format 0 "Unknown timer #x~X requested.~%" arg0) + ) + (.sync.l) + (let ((v0-0 (-> arg0 count))) + (.sync.l) + v0-0 + ) + ) + +(defmacro timer1-time () + `(timer-count TIMER1_BANK) + ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Interrupt Control +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; cop0 status register "interrupt enable" flag +;; if cop0 status is needed anywhere else, move this elsewhere +(defconstant COP0_STATUS_IE (the-as uint #x1)) + +(defun disable-irq () + "Disable all interrupts. Has no effect on PC Port." + (rlet ((status :class gpr :type uint)) + (let ((status-mask (lognot COP0_STATUS_IE))) + (.mfc0 status Status) + (logand! status status-mask) ;; should status-mask be replaced directly? + (.mtc0 Status status) + (.sync.p) + ) + ) + ) + +(defun enable-irq () + "Enable all interrupts. Has no effect on PC Port." + (rlet ((status :class gpr :type uint)) + (.mfc0 status Status) + (logior! status COP0_STATUS_IE) + (.mtc0 Status status) + (.sync.p) + ) + ) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Stopwatch (CPU clock cycle counting) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun stopwatch-init ((this stopwatch)) + "Init a stopwatch." + (set! (-> this begin-level) 0) + (set! (-> this prev-time-elapsed) 0) + ) + + +(defun stopwatch-reset ((this stopwatch)) + "Restart a stopwatch's times." + (set! (-> this prev-time-elapsed) 0) + (when (> (-> this begin-level) 0) + (let ((count 0)) + (.mfc0 count Count) + (#when PC_PORT + (set! count (the int (get-cpu-clock))) + ) + (set! (-> this start-time) count) + ) + ) + ) + +(defun stopwatch-start ((this stopwatch)) + "Start a stopwatch from scratch." + (when (zero? (-> this begin-level)) + (set! (-> this begin-level) 1) + (let ((count 0)) + (.mfc0 count Count) + (#when PC_PORT + (set! count (the int (get-cpu-clock))) + ) + (set! (-> this start-time) count) + ) + ) + ) + +(defun stopwatch-stop ((this stopwatch)) + "Fully stop a stopwatch and save its elapsed time." + (when (> (-> this begin-level) 0) + (set! (-> this begin-level) 0) + (let ((count 0)) + (let ((count 0)) + (.mfc0 count Count) ;; wrong register? a typo in a rlet? who knows. + (#when PC_PORT + (set! count (the int (get-cpu-clock))) + ) + (+! (-> this prev-time-elapsed) (- count (-> this start-time))) + ) + ) + ) + (none) + ) + +(defun stopwatch-begin ((this stopwatch)) + "Begin a stopwatch level, and starts it if it hasn't yet." + (when (zero? (-> this begin-level)) + (let ((count 0)) + (.mfc0 count Count) + (#when PC_PORT + (set! count (the int (get-cpu-clock))) + ) + (set! (-> this start-time) count) + ) + ) + (+! (-> this begin-level) 1) + ) + + +(defun stopwatch-end ((this stopwatch)) + "End a stopwatch level. Stops the stopwatch if it's back to level zero. + There is no guard against ending a stopwatch too many times, and a negative level + will cause errors!" + (+! (-> this begin-level) -1) + (when (zero? (-> this begin-level)) + (set! (-> this begin-level) 0) + (let ((count 0)) + (.mfc0 count Count) + (#when PC_PORT + (set! count (the int (get-cpu-clock))) + ) + + (+! (-> this prev-time-elapsed) (- count (-> this start-time))) + ) + ) + (none) + ) + +(defun stopwatch-elapsed-ticks ((this stopwatch)) + "Returns the elapsed time so far (in clock cycles) of a stopwatch." + (let ((elapsed (-> this prev-time-elapsed))) + (when (> (-> this begin-level) 0) + (let ((count 0)) + (.mfc0 count Count) + (#when PC_PORT + (set! count (the int (get-cpu-clock))) + ) + + (+! elapsed (- count (-> this start-time))) + (set! count elapsed) ;; ?? + ) + ) + elapsed + ) + ) + +(defglobalconstant EE_SECONDS_PER_TICK (/ 1.0 3000000)) ;; 300MHz is a "decent enough" estimate +(defmacro cpu-ticks-to-seconds (ticks) + `(* ,EE_SECONDS_PER_TICK ,ticks) + ) +(defun stopwatch-elapsed-seconds ((this stopwatch)) + "Returns the elapsed time so far (in seconds) of a stopwatch" + (cpu-ticks-to-seconds (stopwatch-elapsed-ticks this)) + ) + +(defmethod update-rates! ((this clock) (rate float)) + "Recompute all clock values for the given clock ratio (arg0)." + (set! (-> this clock-ratio) rate) + (let ((f0-6 (if (nonzero? *display*) + (* (-> *display* time-factor) (-> *display* dog-ratio) rate) + (* 5.0 rate) + ) + ) + ) + (set! (-> this time-adjust-ratio) (* 0.2 f0-6)) + ) + (set! (-> this seconds-per-frame) (* 0.016666668 (-> this time-adjust-ratio))) + (set! (-> this frames-per-second) (if (= (-> this time-adjust-ratio) 0.0) + 0.0 + (* 60.0 (/ 1.0 (-> this time-adjust-ratio))) + ) + ) + ;; og:preserve-this removed number cast + (let* ((v1-12 (- (-> this frame-counter) (-> this old-frame-counter))) + (f0-14 (the-as float v1-12)) + (f1-9 (* 0.2 (the float v1-12))) + ) + (set-vector! (-> this sparticle-data) f0-14 (* 5.0 f1-9) f1-9 f1-9) + ) + rate + ) + +(defmethod advance-by! ((this clock) (arg0 float)) + "Advance the clock by arg0 timeframes (as a float). + Both counters keep a separate fractional and integer counter." + (the int (+ arg0 (-> this accum))) + (+! (-> this integral-accum) arg0) + (set! (-> this old-integral-frame-counter) (-> this integral-frame-counter)) + (while (>= (-> this integral-accum) (-> *display* time-factor)) + (+! (-> this integral-frame-counter) 1) + (set! (-> this integral-accum) (- (-> this integral-accum) (-> *display* time-factor))) + ) + (let ((v1-7 (the int (+ arg0 (-> this accum))))) + (set! (-> this accum) (- (+ arg0 (-> this accum)) (the float v1-7))) + (set! (-> this old-frame-counter) (-> this frame-counter)) + (+! (-> this frame-counter) v1-7) + ) + (update-rates! this (-> this clock-ratio)) + this + ) + +(defmethod tick! ((this clock)) + "Per-game-frame clock tick forward." + (if (not (logtest? (-> this mask) (-> *kernel-context* prevent-from-run))) + (advance-by! this (* (-> *display* time-factor) (-> *display* dog-ratio) (-> this clock-ratio))) + (set! (-> this sparticle-data x) 0.0) + ) + this + ) + +(defmethod reset! ((this clock)) + "Reset a clock to 1000s, rate of 1." + (set! (-> this frame-counter) (seconds 1000)) + (set! (-> this integral-frame-counter) (seconds 1000)) + (set! (-> this accum) 0.0) + (set! (-> this old-frame-counter) (+ (-> this frame-counter) -1)) + (set! (-> this old-integral-frame-counter) (+ (-> this integral-frame-counter) -1)) + (update-rates! this 1.0) + 0 + (none) + ) + +(defmethod save! ((this clock) (arg0 (pointer uint64))) + "Save a clock's state to a buffer, return bytes used." + (set! (-> arg0 0) (the-as uint (-> this frame-counter))) + (set! (-> arg0 1) (the-as uint (-> this integral-frame-counter))) + 16 + ) + +(defmethod load! ((this clock) (arg0 (pointer uint64))) + "Load a clock's state from a buffer, return bytes used." + (set! (-> this frame-counter) (the-as time-frame (-> arg0 0))) + (set! (-> this integral-frame-counter) (the-as time-frame (-> arg0 1))) + (set! (-> this accum) 0.0) + (set! (-> this integral-accum) 0.0) + (set! (-> this old-frame-counter) (-> this frame-counter)) + (set! (-> this old-integral-frame-counter) (-> this integral-frame-counter)) + 16 + ) + +(defmethod copy! ((this clock) (arg0 clock)) + "Copy the frame counters and ratio from arg0." + (set! (-> this frame-counter) (-> arg0 frame-counter)) + (set! (-> this integral-frame-counter) (-> arg0 integral-frame-counter)) + (set! (-> this accum) (-> arg0 accum)) + (set! (-> this integral-accum) (-> arg0 integral-accum)) + (set! (-> this old-frame-counter) (-> arg0 old-frame-counter)) + (set! (-> this old-integral-frame-counter) (-> arg0 old-integral-frame-counter)) + (set! (-> this clock-ratio) (-> arg0 clock-ratio)) + this + ) diff --git a/goal_src/jak3/kernel-defs.gc b/goal_src/jak3/kernel-defs.gc index 9b7c63ddd..cba19ccf5 100644 --- a/goal_src/jak3/kernel-defs.gc +++ b/goal_src/jak3/kernel-defs.gc @@ -28,14 +28,16 @@ (defenum language-enum :type int64 - (english) - (french) - (german) - (spanish) - (italian) - (japanese) - (korean) - (uk-english) + (english 0) + (french 1) + (german 2) + (spanish 3) + (italian 4) + (japanese 6) + (korean 7) + (russian 8) + (portuguese 9) + (uk-english 11) ) ;; fixed symbols @@ -113,6 +115,9 @@ (declare-type mouse-info basic) (define-extern mouse-get-data (function mouse-info none)) +(declare-type keybd-info basic) +(define-extern keybd-get-data (function keybd-info none)) + (defconstant GAME_TERRITORY_SCEA 0) (defconstant GAME_TERRITORY_SCEE 1) (defconstant GAME_TERRITORY_SCEI 2) diff --git a/goal_src/jak3/kernel/gkernel-h.gc b/goal_src/jak3/kernel/gkernel-h.gc index f669cd572..1a3a75dd4 100644 --- a/goal_src/jak3/kernel/gkernel-h.gc +++ b/goal_src/jak3/kernel/gkernel-h.gc @@ -151,30 +151,30 @@ ;; Changing clock-ratio will make integral-frame-counter not count actual vsyncs (deftype clock (basic) - ((index int16) - (ref-count uint16) - (mask process-mask) - (clock-ratio float) - (accum float) - (integral-accum float) - (frame-counter uint64) - (old-frame-counter uint64) - (integral-frame-counter uint64) - (old-integral-frame-counter uint64) - (sparticle-data vector :inline) - (seconds-per-frame float) - (frames-per-second float) - (time-adjust-ratio float) + ((index int16 :offset-assert 4) ;; int32 + (ref-count uint16 :offset-assert 6) + (mask process-mask :offset-assert 8) ;; guessed by decompiler + (clock-ratio float :offset-assert 12) + (accum float :offset-assert 16) + (integral-accum float :offset-assert 20) + (frame-counter time-frame :offset-assert 24) ;; time-frame + (old-frame-counter time-frame :offset-assert 32) ;; time-frame + (integral-frame-counter time-frame :offset-assert 40) + (old-integral-frame-counter time-frame :offset-assert 48) + (sparticle-data vector :inline :offset-assert 64) + (seconds-per-frame float :offset-assert 80) + (frames-per-second float :offset-assert 84) + (time-adjust-ratio float :offset-assert 88) ) (:methods (new (symbol type int) _type_) (update-rates! (_type_ float) float) - (clock-method-10 () none) - (clock-method-11 () none) - (clock-method-12 () none) - (clock-method-13 () none) - (clock-method-14 () none) - (clock-method-15 () none) + (advance-by! (_type_ float) clock) + (tick! (_type_) clock) + (save! (_type_ (pointer uint64)) int) + (load! (_type_ (pointer uint64)) int) + (copy! (_type_ clock) clock) + (reset! (_type_) none) (frame-mask-2 (_type_ int) symbol) (frame-mask-4 (_type_ int) symbol) (frame-mask-8 (_type_ int) symbol) @@ -229,8 +229,8 @@ (defmethod new clock ((allocation symbol) (type-to-make type) (index int)) (let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) (set! (-> gp-0 index) index) - (set! (-> gp-0 frame-counter) (the-as uint #x493e0)) - (set! (-> gp-0 integral-frame-counter) (the-as uint #x493e0)) + (set! (-> gp-0 frame-counter) (seconds 1000)) + (set! (-> gp-0 integral-frame-counter) (seconds 1000)) (set! (-> gp-0 old-frame-counter) (+ (-> gp-0 frame-counter) -1)) (set! (-> gp-0 old-integral-frame-counter) (+ (-> gp-0 integral-frame-counter) -1)) (update-rates! gp-0 1.0) diff --git a/test/decompiler/reference/jak3/decompiler-macros.gc b/test/decompiler/reference/jak3/decompiler-macros.gc index 56476e327..0a4773a6f 100644 --- a/test/decompiler/reference/jak3/decompiler-macros.gc +++ b/test/decompiler/reference/jak3/decompiler-macros.gc @@ -277,6 +277,97 @@ ) ) +;; meters are stored as (usually) a float, scaled by 4096. +;; this gives you reasonable accuracy as an integer. +(defglobalconstant METER_LENGTH 4096.0) + +(defmacro meters (x) + "Convert number to meters. + If the input is a constant float or integer, the result will be a + compile time constant float. Otherwise, it will not be constant. + Returns float." + + ;; we don't have enough constant propagation for the compiler to figure this out. + (cond + ((float? x) + (* METER_LENGTH x) + ) + ((integer? x) + (* METER_LENGTH x) + ) + (#t + `(* METER_LENGTH ,x) + ) + ) + ) + +;; rotations are stored in 65,536ths of a full rotation. +;; like with meters, you get a reasonable accuracy as an integer. +;; additionally, it is a power-of-two, so wrapping rotations can be done +;; quickly by converting to an int, masking, and back to float +(defglobalconstant DEGREES_PER_ROT 65536.0) + +;; this was deg in GOAL +(defmacro degrees (x) + "Convert number to degrees unit. + Will keep a constant float/int constant." + (cond + ((or (float? x) (integer? x)) + (* DEGREES_PER_ROT (/ (+ 0.0 x) 360.0)) + ) + (#t + `(* (/ (the float ,x) 360.0) + DEGREES_PER_ROT + ) + ) + ) + ) + +;; times are stored in 300ths of a second. +;; this divides evenly into frames at both 50 and 60 fps. +;; typically these are stored as integers as more precision is not useful. +;; an unsigned 32-bit integer can store about 150 days +(defglobalconstant TICKS_PER_SECOND 300) ;; 5 t/frame @ 60fps, 6 t/frame @ 50fps + +;; this was usec in GOAL +(defmacro seconds (x) + "Convert number to seconds unit. + Returns uint." + (cond + ((integer? x) + (* TICKS_PER_SECOND x) + ) + ((float? x) + (* 1 (* 1.0 x TICKS_PER_SECOND)) + ) + (#t + `(the uint (* TICKS_PER_SECOND ,x)) + ) + ) + ) + +(defmacro fsec (x) + "Convert number to seconds unit. + Returns float." + (cond + ((or (integer? x) (float? x)) + (* 1.0 TICKS_PER_SECOND x) + ) + (#t + `(* 1.0 TICKS_PER_SECOND ,x) + ) + ) + ) + +(fake-asm .sync.l) +(fake-asm .sync.p) +(fake-asm .mfc0 dest src) +(fake-asm .mtc0 dest src) +(fake-asm .mtpc dest src) +(fake-asm .mfpc dest src) +(fake-asm .mtdab src) +(fake-asm .mtdabm src) + (defmacro suspend () '(none) ) @@ -296,4 +387,37 @@ (defmacro seekl! (place target rate) "Macro to use seekl in-place. place is the base, and where the result is stored." `(set! ,place (seekl ,place ,target ,rate)) + ) + +;; pad +(defmacro cpad-pressed (pad-idx) + `(-> *cpad-list* cpads ,pad-idx button0-rel 0) + ) + +(defmacro cpad-hold (pad-idx) + `(-> *cpad-list* cpads ,pad-idx button0-abs 0) + ) + +(defmacro cpad-pressed? (pad-idx &rest buttons) + `(logtest? (cpad-pressed ,pad-idx) (pad-buttons ,@buttons)) + ) + +(defmacro cpad-hold? (pad-idx &rest buttons) + `(logtest? (cpad-hold ,pad-idx) (pad-buttons ,@buttons)) + ) + +(defmacro mouse-pressed () + `(-> *mouse* button0-rel 0) + ) + +(defmacro mouse-hold () + `(-> *mouse* button0-abs 0) + ) + +(defmacro mouse-pressed? (&rest buttons) + `(logtest? (mouse-pressed) (mouse-buttons ,@buttons)) + ) + +(defmacro mouse-hold? (&rest buttons) + `(logtest? (mouse-hold) (mouse-buttons ,@buttons)) ) \ No newline at end of file diff --git a/test/decompiler/reference/jak3/engine/gfx/hw/display-h_REF.gc b/test/decompiler/reference/jak3/engine/gfx/hw/display-h_REF.gc new file mode 100644 index 000000000..fcb69220d --- /dev/null +++ b/test/decompiler/reference/jak3/engine/gfx/hw/display-h_REF.gc @@ -0,0 +1,246 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type display-frame +(deftype display-frame (basic) + ((buffer dma-buffer 11) + (calc-buf dma-buffer :overlay-at (-> buffer 1)) + (vu1-buf dma-buffer :overlay-at (-> buffer 1)) + (debug-buf dma-buffer :overlay-at (-> buffer 8)) + (global-buf dma-buffer :overlay-at (-> buffer 9)) + (bucket-group (inline-array dma-bucket) :overlay-at (-> buffer 10)) + (profile-array profile-array :inline :offset 48) + (start-time uint64 :offset 56) + (run-time uint64 :offset 64) + ) + (:methods + (new (symbol type) _type_) + ) + ) + +;; definition for method 3 of type display-frame +(defmethod inspect ((this display-frame)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tbuffer[11] @ #x~X~%" (-> this buffer)) + (format #t "~1Tcalc-buf: ~A~%" (-> this calc-buf)) + (format #t "~1Tvu1-buf: ~A~%" (-> this calc-buf)) + (format #t "~1Tdebug-buf: ~A~%" (-> this debug-buf)) + (format #t "~1Tglobal-buf: ~A~%" (-> this global-buf)) + (format #t "~1Tbucket-group: #~%" (-> this bucket-group)) + (format #t "~1Tprofile-array: #~%" (-> this profile-array)) + (format #t "~1Tstart-time: ~D~%" (-> this start-time)) + (format #t "~1Trun-time: ~D~%" (-> this run-time)) + (label cfg-4) + this + ) + +;; definition for method 0 of type display-frame +(defmethod new display-frame ((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 calc-buf) (the-as dma-buffer 0)) + (set! (-> gp-0 global-buf) (the-as dma-buffer 0)) + (set! (-> gp-0 debug-buf) (the-as dma-buffer 0)) + (when *debug-segment* + (set! (-> gp-0 profile-array data 0) (new 'debug 'profile-segment-array)) + (set! (-> gp-0 profile-array data 1) (new 'debug 'profile-segment-array)) + ) + gp-0 + ) + ) + +;; definition of type display +(deftype display (basic) + ((on-screen int32) + (last-screen int32) + (frames display-frame 2) + (bgcolor uint64) + (pmode uint64) + (clock clock 22) + (session-clock clock :overlay-at (-> clock 0)) + (game-clock clock :overlay-at (-> clock 1)) + (base-clock clock :overlay-at (-> clock 2)) + (real-clock clock :overlay-at (-> clock 3)) + (frame-clock clock :overlay-at (-> clock 4)) + (real-frame-clock clock :overlay-at (-> clock 5)) + (target-clock clock :overlay-at (-> clock 6)) + (entity-clock clock :overlay-at (-> clock 7)) + (part-clock clock :overlay-at (-> clock 8)) + (bg-clock clock :overlay-at (-> clock 9)) + (camera-clock clock :overlay-at (-> clock 10)) + (total-game-clock clock :overlay-at (-> clock 11)) + (user0-clock clock :overlay-at (-> clock 12)) + (user1-clock clock :overlay-at (-> clock 13)) + (user2-clock clock :overlay-at (-> clock 14)) + (user3-clock clock :overlay-at (-> clock 15)) + (user4-clock clock :overlay-at (-> clock 16)) + (user5-clock clock :overlay-at (-> clock 17)) + (user6-clock clock :overlay-at (-> clock 18)) + (user7-clock clock :overlay-at (-> clock 19)) + (user8-clock clock :overlay-at (-> clock 20)) + (user9-clock clock :overlay-at (-> clock 21)) + (time-factor float) + (dog-ratio float) + (vblank-start-time int64 2) + (total-run-time uint64) + (run-half-speed symbol) + (vu1-enable-user vu1-renderer-mask) + (vu1-enable-user-menu vu1-renderer-mask) + (force-sync uint32) + (mem-reserve-size uint32) + (dma-buffer-overflow basic) + ) + (:methods + (new (symbol type int int int int int) _type_) + (set-time-ratios (_type_ float) float) + ) + ) + +;; definition for method 3 of type display +(defmethod inspect ((this display)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Ton-screen: ~D~%" (-> this on-screen)) + (format #t "~1Tlast-screen: ~D~%" (-> this last-screen)) + (format #t "~1Tframes[2] @ #x~X~%" (-> this frames)) + (format #t "~1Tbgcolor: #x~X~%" (-> this bgcolor)) + (format #t "~1Tpmode: ~D~%" (-> this pmode)) + (format #t "~1Tclock[22] @ #x~X~%" (-> this clock)) + (format #t "~1Tsession-clock: ~A~%" (-> this session-clock)) + (format #t "~1Tgame-clock: ~A~%" (-> this game-clock)) + (format #t "~1Tbase-clock: ~A~%" (-> this base-clock)) + (format #t "~1Treal-clock: ~A~%" (-> this real-clock)) + (format #t "~1Tframe-clock: ~A~%" (-> this frame-clock)) + (format #t "~1Treal-frame-clock: ~A~%" (-> this real-frame-clock)) + (format #t "~1Ttarget-clock: ~A~%" (-> this target-clock)) + (format #t "~1Tentity-clock: ~A~%" (-> this entity-clock)) + (format #t "~1Tpart-clock: ~A~%" (-> this part-clock)) + (format #t "~1Tbg-clock: ~A~%" (-> this bg-clock)) + (format #t "~1Tcamera-clock: ~A~%" (-> this camera-clock)) + (format #t "~1Ttotal-game-clock: ~A~%" (-> this total-game-clock)) + (format #t "~1Tuser0-clock: ~A~%" (-> this user0-clock)) + (format #t "~1Tuser1-clock: ~A~%" (-> this user1-clock)) + (format #t "~1Tuser2-clock: ~A~%" (-> this user2-clock)) + (format #t "~1Tuser3-clock: ~A~%" (-> this user3-clock)) + (format #t "~1Tuser4-clock: ~A~%" (-> this user4-clock)) + (format #t "~1Tuser5-clock: ~A~%" (-> this user5-clock)) + (format #t "~1Tuser6-clock: ~A~%" (-> this user6-clock)) + (format #t "~1Tuser7-clock: ~A~%" (-> this user7-clock)) + (format #t "~1Tuser8-clock: ~A~%" (-> this user8-clock)) + (format #t "~1Tuser9-clock: ~A~%" (-> this user9-clock)) + (format #t "~1Ttime-factor: ~f~%" (-> this time-factor)) + (format #t "~1Tdog-ratio: ~f~%" (-> this dog-ratio)) + (format #t "~1Tvblank-start-time[2] @ #x~X~%" (-> this vblank-start-time)) + (format #t "~1Ttotal-run-time: ~D~%" (-> this total-run-time)) + (format #t "~1Trun-half-speed: ~A~%" (-> this run-half-speed)) + (format #t "~1Tvu1-enable-user: ~D~%" (-> this vu1-enable-user)) + (format #t "~1Tvu1-enable-user-menu: ~D~%" (-> this vu1-enable-user-menu)) + (format #t "~1Tforce-sync: ~D~%" (-> this force-sync)) + (format #t "~1Tmem-reserve-size: ~D~%" (-> this mem-reserve-size)) + (format #t "~1Tdma-buffer-overflow: ~A~%" (-> this dma-buffer-overflow)) + (label cfg-4) + this + ) + +;; definition for method 0 of type display +(defmethod new display ((allocation symbol) (type-to-make type) (arg0 int) (arg1 int) (arg2 int) (arg3 int) (arg4 int)) + (let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set-display gp-0) + (set! (-> gp-0 frames 0) (new 'global 'display-frame)) + (set! (-> gp-0 frames 1) (new 'global 'display-frame)) + (set! (-> gp-0 pmode) (the-as uint 165)) + (set! (-> gp-0 run-half-speed) #f) + (set! (-> gp-0 vu1-enable-user-menu) (vu1-renderer-mask + sky + ocean + ocean-wave + tfrag + tie + tie-envmap + tie-scissor + tie-envmap-scissor + tie-vanish + generic + merc + emerc + shrubbery + shrub-near + billboard + shrubbery-vanish + tfrag-trans + tie-scissor-trans + tie-trans + tie-envmap-trans + tie-envmap-scissor-trans + tfrag-water + tie-scissor-water + tie-water + tie-envmap-water + tie-envmap-scissor-water + sprite + shadow + rn31 + rn32 + rn33 + depth-cue + rn36 + ) + ) + (set! (-> gp-0 vu1-enable-user) (vu1-renderer-mask + sky + ocean + ocean-wave + tfrag + tie + tie-envmap + tie-scissor + tie-envmap-scissor + tie-vanish + generic + merc + emerc + shrubbery + shrub-near + billboard + shrubbery-vanish + tfrag-trans + tie-scissor-trans + tie-trans + tie-envmap-trans + tie-envmap-scissor-trans + tfrag-water + tie-scissor-water + tie-water + tie-envmap-water + tie-envmap-scissor-water + sprite + shadow + rn31 + rn32 + rn33 + depth-cue + rn36 + ) + ) + gp-0 + ) + ) + +;; definition for symbol *pre-draw-hook*, type (function object none) +(define *pre-draw-hook* (the-as (function object none) nothing)) + +;; definition for symbol *post-draw-hook*, type (function dma-buffer none) +(define *post-draw-hook* (the-as (function dma-buffer none) nothing)) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/load/decomp-h_REF.gc b/test/decompiler/reference/jak3/engine/load/decomp-h_REF.gc new file mode 100644 index 000000000..0b474b441 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/load/decomp-h_REF.gc @@ -0,0 +1,35 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type decomp-work +(deftype decomp-work (structure) + "Temporary storage for visibility data decompression. +This is stored on the scratchpad." + ((buffer0 uint8 2048) + (buffer1 uint8 2048) + (indices uint16 2048) + (temp-indices uint16 2048) + ) + ) + +;; definition for method 3 of type decomp-work +(defmethod inspect ((this decomp-work)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'decomp-work) + (format #t "~1Tbuffer0[2048] @ #x~X~%" (-> this buffer0)) + (format #t "~1Tbuffer1[2048] @ #x~X~%" (-> this buffer1)) + (format #t "~1Tindices[2048] @ #x~X~%" (-> this indices)) + (format #t "~1Ttemp-indices[2048] @ #x~X~%" (-> this temp-indices)) + (label cfg-4) + this + ) + +;; failed to figure out what this is: +0 + + + + diff --git a/test/decompiler/reference/jak3/engine/load/file-io_REF.gc b/test/decompiler/reference/jak3/engine/load/file-io_REF.gc new file mode 100644 index 000000000..f4b65728f --- /dev/null +++ b/test/decompiler/reference/jak3/engine/load/file-io_REF.gc @@ -0,0 +1,228 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type file-stream +(deftype file-stream (basic) + ((flags uint32) + (mode symbol) + (name string) + (file uint32) + ) + (:methods + (new (symbol type string symbol) _type_) + ) + ) + +;; definition for method 3 of type file-stream +(defmethod inspect ((this file-stream)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tflags: #x~X~%" (-> this flags)) + (format #t "~1Tmode: ~A~%" (-> this mode)) + (format #t "~1Tname: ~A~%" (-> this name)) + (format #t "~1Tfile: ~D~%" (-> this file)) + (label cfg-4) + this + ) + +;; definition for method 0 of type file-stream +(defmethod new file-stream ((obj symbol) (arg1 type) (file-name string) (mode symbol)) + (let ((a0-1 (object-new obj arg1 (the-as int (-> arg1 size))))) + (file-stream-open a0-1 file-name mode) + ) + ) + +;; failed to figure out what this is: +(set! (-> file-stream method-table 4) file-stream-length) + +;; definition for function file-stream-read-string +(defun file-stream-read-string ((fs file-stream) (str string)) + "Fill a string with data from a file stream. + Note: this function does not work." + (clear str) + (file-stream-read fs (-> str data) (length fs)) + str + ) + +;; definition of type file-info +(deftype file-info (basic) + ((file-type (pointer string)) + (file-name string) + (major-version uint32) + (minor-version uint32) + (maya-file-name string) + (tool-debug string) + (mdb-file-name string) + ) + ) + +;; definition for method 3 of type file-info +(defmethod inspect ((this file-info)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tfile-type: ~A~%" (-> this file-type)) + (format #t "~1Tfile-name: ~A~%" (-> this file-name)) + (format #t "~1Tmajor-version: ~D~%" (-> this major-version)) + (format #t "~1Tminor-version: ~D~%" (-> this minor-version)) + (format #t "~1Tmaya-file-name: ~A~%" (-> this maya-file-name)) + (format #t "~1Ttool-debug: ~A~%" (-> this tool-debug)) + (format #t "~1Tmdb-file-name: ~A~%" (-> this mdb-file-name)) + (label cfg-4) + this + ) + +;; definition for method 2 of type file-info +(defmethod print ((this file-info)) + (format + #t + "#<~A ~A :version ~D.~D @ #x~X>" + (-> this type) + (-> this file-name) + (-> this major-version) + (-> this minor-version) + this + ) + this + ) + +;; definition for symbol *file-temp-string*, type string +(define *file-temp-string* (new 'global 'string 128 (the-as string #f))) + +;; definition for function make-file-name +(defun make-file-name ((kind file-kind) (name string) (ag-version-override int) (arg3 symbol)) + "Get a file name to open a file with the given kind and name. + The art-group-version argument can be used to override the version + of the art-group. Set it to 0 or less to use the default version. + Similar to MakeFileName in C. + Note: file type enum is different between C and GOAL. + File versions should match those in versions.h. + Uses a single *file-temp-string* buffer, shared with make-vfile-name. + arg3 is unused." + (clear *file-temp-string*) + (cond + ((= kind (file-kind dir-tpage)) + (format *file-temp-string* "texture-page~D/dir-tpages" 8) + ) + ((= kind (file-kind tpage)) + (format *file-temp-string* "texture-page~D/tpage-~S" 8 name) + ) + ((= kind (file-kind level-bt)) + (format *file-temp-string* "level~D/~S-bt" 36 name) + ) + ((= kind (file-kind tx)) + (format *file-temp-string* "res~D/~S-tx" 1 name) + ) + ((= kind (file-kind level-vs)) + (format *file-temp-string* "level~D/~S-vs" 36 name) + ) + ((= kind (file-kind vis)) + (format *file-temp-string* "~S.VIS" name) + ) + ((= kind (file-kind map)) + (format *file-temp-string* "map~D/~S-mp" 1 name) + ) + ((= kind (file-kind art-group)) + (format + *file-temp-string* + "art-group~D/~S-ag" + (cond + ((> ag-version-override 0) + (empty) + ag-version-override + ) + (else + 8 + ) + ) + name + ) + ) + ) + *file-temp-string* + ) + +;; definition for function make-vfile-name +(defun make-vfile-name ((kind file-kind) (name string)) + "Make virtual? file name. This makes a name that the kernel knows how to + handle in a specific way. This function is not used." + (clear *file-temp-string*) + (cond + ((= kind (file-kind level-bt)) + (format *file-temp-string* "$LEVEL/~S" name) + ) + ((= kind (file-kind art-group)) + (format *file-temp-string* "$ART_GROUP/~S" name) + ) + ) + *file-temp-string* + ) + +;; definition for function file-info-correct-version? +(defun file-info-correct-version? ((file file-info) (kind file-kind) (version-override int)) + "Check if the version and kind in the info is valid. The `version-override` can specify a + non-default version, or set to 0 for the default version." + (let* ((major (cond + ((zero? version-override) + (case kind + (((file-kind tpage) (file-kind dir-tpage)) + 8 + ) + (((file-kind level-bt)) + 36 + ) + (((file-kind art-group)) + 8 + ) + ) + ) + (else + version-override + ) + ) + ) + (file-kind kind) + (type (cond + ((= file-kind (file-kind tpage)) + "texture-page" + ) + ((= file-kind (file-kind level-bt)) + "bsp-header" + ) + ((= file-kind (file-kind art-group)) + "art-group" + ) + ) + ) + ) + (cond + ((not (name= (-> file file-type 0) type)) + (format 0 "ERROR: file ~A is of type ~S but needs to be ~S.~%" (-> file file-name) (-> file file-type) type) + #f + ) + ((!= major (-> file major-version)) + (format + 0 + "ERROR: file ~A is version ~D.~D, but needs to be ~D.x~%" + (-> file file-name) + (-> file major-version) + (-> file minor-version) + major + ) + #f + ) + (else + #t + ) + ) + ) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/ps2/pad_REF.gc b/test/decompiler/reference/jak3/engine/ps2/pad_REF.gc new file mode 100644 index 000000000..88acce671 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/ps2/pad_REF.gc @@ -0,0 +1,738 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type scf-time +(deftype scf-time (structure) + ((stat uint8) + (second uint8) + (minute uint8) + (hour uint8) + (week uint8) + (day uint8) + (month uint8) + (year uint8) + ) + ) + +;; definition for method 3 of type scf-time +(defmethod inspect ((this scf-time)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'scf-time) + (format #t "~1Tstat: ~D~%" (-> this stat)) + (format #t "~1Tsecond: #x~X~%" (-> this second)) + (format #t "~1Tminute: #x~X~%" (-> this minute)) + (format #t "~1Thour: #x~X~%" (-> this hour)) + (format #t "~1Tweek: #x~X~%" (-> this week)) + (format #t "~1Tday: #x~X~%" (-> this day)) + (format #t "~1Tmonth: #x~X~%" (-> this month)) + (format #t "~1Tyear: #x~X~%" (-> this year)) + (label cfg-4) + this + ) + +;; definition for symbol *cheat-mode*, type symbol +(define *cheat-mode* #t) + +;; definition of type hw-cpad +(deftype hw-cpad (basic) + "Data that comes directly from hardware. +It's 32 bytes + type tag (ignored by C kernel)." + ((valid uint8) + (status uint8) + (button0 uint16) + (rightx uint8) + (righty uint8) + (leftx uint8) + (lefty uint8) + (abutton uint8 12) + (dummy uint8 12) + ) + ) + +;; definition for method 3 of type hw-cpad +(defmethod inspect ((this hw-cpad)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tvalid: #x~X~%" (-> this valid)) + (format #t "~1Tstatus: #x~X~%" (-> this status)) + (format #t "~1Tbutton0: #x~X~%" (-> this button0)) + (format #t "~1Trightx: ~D~%" (-> this rightx)) + (format #t "~1Trighty: ~D~%" (-> this righty)) + (format #t "~1Tleftx: ~D~%" (-> this leftx)) + (format #t "~1Tlefty: ~D~%" (-> this lefty)) + (format #t "~1Tabutton[12] @ #x~X~%" (-> this abutton)) + (format #t "~1Tdummy[12] @ #x~X~%" (-> this dummy)) + (label cfg-4) + this + ) + +;; definition of type cpad-info +(deftype cpad-info (hw-cpad) + "Data from hardware + additional info calculated here." + ((number int32) + (cpad-file int32) + (button0-abs pad-buttons 3) + (button0-shadow-abs pad-buttons 1) + (button0-rel pad-buttons 3) + (stick0-dir float) + (stick0-speed float) + (new-pad int32) + (state int32) + (align uint8 6) + (direct uint8 6) + (buzz-val uint8 2) + (buzz-pause-val uint8 1) + (buzz-pause-time uint8) + (buzz-time time-frame 2) + (buzz basic) + (buzz-act int32) + (change-time uint64) + (real-change-time uint64) + (old-rightx uint8 2) + (old-righty uint8 2) + (old-leftx uint8 2) + (old-lefty uint8 2) + ) + (:methods + (new (symbol type int) _type_) + (adjust-to-screen-flip (_type_) int) + ) + ) + +;; definition for method 3 of type cpad-info +(defmethod inspect ((this cpad-info)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tvalid: #x~X~%" (-> this valid)) + (format #t "~1Tstatus: #x~X~%" (-> this status)) + (format #t "~1Tbutton0: #x~X~%" (-> this button0)) + (format #t "~1Trightx: ~D~%" (-> this rightx)) + (format #t "~1Trighty: ~D~%" (-> this righty)) + (format #t "~1Tleftx: ~D~%" (-> this leftx)) + (format #t "~1Tlefty: ~D~%" (-> this lefty)) + (format #t "~1Tabutton[12] @ #x~X~%" (-> this abutton)) + (format #t "~1Tdummy[12] @ #x~X~%" (-> this dummy)) + (format #t "~1Tnumber: ~D~%" (-> this number)) + (format #t "~1Tcpad-file: ~D~%" (-> this cpad-file)) + (format #t "~1Tbutton0-abs[3] @ #x~X~%" (-> this button0-abs)) + (format #t "~1Tbutton0-shadow-abs[1] @ #x~X~%" (-> this button0-shadow-abs)) + (format #t "~1Tbutton0-rel[3] @ #x~X~%" (-> this button0-rel)) + (format #t "~1Tstick0-dir: ~f~%" (-> this stick0-dir)) + (format #t "~1Tstick0-speed: ~f~%" (-> this stick0-speed)) + (format #t "~1Tnew-pad: ~D~%" (-> this new-pad)) + (format #t "~1Tstate: ~D~%" (-> this state)) + (format #t "~1Talign[6] @ #x~X~%" (-> this align)) + (format #t "~1Tdirect[6] @ #x~X~%" (-> this direct)) + (format #t "~1Tbuzz-val[2] @ #x~X~%" (-> this buzz-val)) + (format #t "~1Tbuzz-pause-val[1] @ #x~X~%" (-> this buzz-pause-val)) + (format #t "~1Tbuzz-pause-time: ~D~%" (-> this buzz-pause-time)) + (format #t "~1Tbuzz-time[2] @ #x~X~%" (-> this buzz-time)) + (format #t "~1Tbuzz: ~A~%" (-> this buzz)) + (format #t "~1Tbuzz-act: ~D~%" (-> this buzz-act)) + (format #t "~1Tchange-time: ~D~%" (-> this change-time)) + (format #t "~1Treal-change-time: ~D~%" (-> this real-change-time)) + (format #t "~1Told-rightx[2] @ #x~X~%" (-> this old-rightx)) + (format #t "~1Told-righty[2] @ #x~X~%" (-> this old-righty)) + (format #t "~1Told-leftx[2] @ #x~X~%" (-> this old-leftx)) + (format #t "~1Told-lefty[2] @ #x~X~%" (-> this old-lefty)) + (label cfg-4) + this + ) + +;; definition for function cpad-invalid! +(defun cpad-invalid! ((arg0 cpad-info)) + "Reset all data in a [[cpad-info]]." + (logior! (-> arg0 valid) 128) + (set! (-> arg0 button0) (the-as uint 0)) + (set! (-> arg0 button0-abs 0) (pad-buttons)) + (set! (-> arg0 button0-shadow-abs 0) (pad-buttons)) + (set! (-> arg0 button0-rel 0) (pad-buttons)) + (dotimes (v1-2 12) + (nop!) + (set! (-> arg0 abutton v1-2) (the-as uint 0)) + ) + (set! (-> arg0 stick0-dir) 0.0) + (set! (-> arg0 stick0-speed) 0.0) + (set! (-> arg0 rightx) (the-as uint 128)) + (set! (-> arg0 righty) (the-as uint 128)) + (set! (-> arg0 leftx) (the-as uint 128)) + (set! (-> arg0 lefty) (the-as uint 128)) + (set! (-> arg0 align 0) (the-as uint 0)) + (set! (-> arg0 align 1) (the-as uint 1)) + (set! (-> arg0 align 2) (the-as uint 255)) + (set! (-> arg0 align 3) (the-as uint 255)) + (set! (-> arg0 align 4) (the-as uint 255)) + (set! (-> arg0 align 5) (the-as uint 255)) + (dotimes (v1-14 6) + (nop!) + (set! (-> arg0 direct v1-14) (the-as uint 0)) + ) + (dotimes (v1-17 2) + (nop!) + (set! (-> arg0 buzz-val v1-17) (the-as uint 0)) + (set! (-> arg0 buzz-time v1-17) 0) + ) + (set! (-> arg0 buzz-pause-val 0) (the-as uint 0)) + (set! (-> arg0 buzz-time 0) 0) + arg0 + ) + +;; definition for method 0 of type cpad-info +(defmethod new cpad-info ((allocation symbol) (type-to-make type) (arg0 int)) + "Allocate a new cpad-info and open the pad itself through the kernel." + (let ((s5-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> s5-0 number) arg0) + (set! (-> s5-0 buzz) #f) + (cpad-open s5-0 arg0) + (cpad-invalid! s5-0) + ) + ) + +;; definition of type cpad-list +(deftype cpad-list (basic) + "List of controllers. It always has two controllers." + ((num-cpads int32) + (cpads cpad-info 2) + ) + (:methods + (new (symbol type) _type_) + ) + ) + +;; definition for method 3 of type cpad-list +(defmethod inspect ((this cpad-list)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tnum-cpads: ~D~%" (-> this num-cpads)) + (format #t "~1Tcpads[2] @ #x~X~%" (-> this cpads)) + (label cfg-4) + this + ) + +;; definition for method 0 of type cpad-list +(defmethod new cpad-list ((allocation symbol) (type-to-make type)) + "Create a cpad-list for 2 controllers. It's fine to do this even if one or both controllers + aren't connected yet." + (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 ((arg0 int) (arg1 float) (arg2 float) (arg3 float) (arg4 float)) + "Convert integer input from pad into a float between -out-range and +out-range. + The offset is applied directly to the input. + The center val is the expected value for 0, after applying offset. + The max val is the expected value with the stick pushed all the way." + (let* ((f1-1 (- (the float arg0) arg1)) + (f0-3 (- (fabs f1-1) arg2)) + (v1-0 (- arg3 arg2)) + ) + (if (< f1-1 0.0) + (set! arg4 (- arg4)) + ) + (cond + ((>= 0.0 f0-3) + 0.0 + ) + ((>= f0-3 v1-0) + arg4 + ) + (else + (/ (* f0-3 arg4) v1-0) + ) + ) + ) + ) + +;; definition for function cpad-set-buzz! +;; WARN: Return type mismatch int vs none. +(defun cpad-set-buzz! ((arg0 cpad-info) (arg1 int) (arg2 int) (arg3 time-frame)) + "Turn on vibration motor `buzz-idx` for duration, at magnitude `buzz-amount`." + (cond + ((zero? arg2) + (set! (-> arg0 buzz-val arg1) (the-as uint 0)) + 0 + ) + ((= arg2 (-> arg0 buzz-val arg1)) + (set! (-> arg0 buzz-time arg1) (the-as time-frame (max (-> arg0 buzz-time arg1) (+ (get-current-time) arg3)))) + ) + ((< (-> arg0 buzz-val arg1) (the-as uint arg2)) + (set! (-> arg0 buzz-val arg1) (the-as uint arg2)) + (set! (-> arg0 buzz-time arg1) (+ (get-current-time) arg3)) + ) + ) + 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 () + "Read from cpads and update vibration." + (let ((pads *cpad-list*)) + (dotimes (pad-idx (-> pads num-cpads)) + (let ((pad (-> *cpad-list* cpads pad-idx))) + (set! (-> pad old-leftx 1) (-> pad old-leftx 0)) + (set! (-> pad old-leftx 0) (-> pad leftx)) + (set! (-> pad old-lefty 1) (-> pad old-lefty 0)) + (set! (-> pad old-lefty 0) (-> pad lefty)) + (set! (-> pad old-rightx 1) (-> pad old-rightx 0)) + (set! (-> pad old-rightx 0) (-> pad rightx)) + (set! (-> pad old-righty 1) (-> pad old-righty 0)) + (set! (-> pad old-righty 0) (-> pad righty)) + (cpad-get-data pad) + (adjust-to-screen-flip pad) + (cond + ((not (logtest? (-> pad valid) 128)) + (dotimes (motor-idx 2) + (cond + ((and (-> pad buzz) (< (get-current-time) (-> pad buzz-time motor-idx)) (= *master-mode* 'game)) + (let ((v1-20 motor-idx)) + (cond + ((zero? v1-20) + (set! (-> pad direct motor-idx) + (logand (ash (-> pad buzz-val motor-idx) (- (the-as int (logand (get-integral-current-time) 7)))) 1) + ) + ) + ((= v1-20 1) + (set! (-> pad direct motor-idx) (-> pad buzz-val motor-idx)) + ) + ) + ) + ) + ((and (zero? motor-idx) (> (-> pad buzz-pause-time) 0)) + (set! (-> pad direct motor-idx) + (logand (ash (-> pad buzz-pause-val motor-idx) (- (the-as int (logand (get-integral-current-time) 7)))) 1) + ) + (+! (-> pad buzz-pause-time) -1) + ) + (else + (set! (-> pad buzz-val motor-idx) (the-as uint 0)) + (set! (-> pad direct motor-idx) (the-as uint 0)) + (when (zero? motor-idx) + (set! (-> pad buzz-pause-time) (the-as uint 0)) + 0 + ) + ) + ) + ) + (when (< (the-as uint 192) (-> pad direct 1)) + (set! (-> pad direct 0) (the-as uint 0)) + 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)) + (when (= (-> pad status) 115) + (set! (-> pad abutton 0) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons right)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 1) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons left)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 2) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons up)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 3) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons down)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 6) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons x)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 5) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons circle)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 4) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons triangle)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 7) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons square)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 8) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons l1)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 10) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons l2)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 9) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons r1)) + 255 + 0 + ) + ) + ) + (set! (-> pad abutton 11) (the-as uint (if (logtest? (-> pad button0-abs 0) (pad-buttons r2)) + 255 + 0 + ) + ) + ) + ) + (let ((buttons-pressed (the-as pad-buttons (-> pad button0)))) + (cond + ((< (-> pad lefty) (the-as uint 30)) + (set! buttons-pressed (logior (pad-buttons l-analog-up) buttons-pressed)) + ) + ((< (the-as uint 225) (-> pad lefty)) + (set! buttons-pressed (logior (pad-buttons l-analog-down) buttons-pressed)) + ) + ) + (cond + ((< (-> pad leftx) (the-as uint 30)) + (set! buttons-pressed (logior (pad-buttons l-analog-left) buttons-pressed)) + ) + ((< (the-as uint 225) (-> pad leftx)) + (set! buttons-pressed (logior (pad-buttons l-analog-right) buttons-pressed)) + ) + ) + (cond + ((< (-> pad righty) (the-as uint 30)) + (set! buttons-pressed (logior (pad-buttons r-analog-up) buttons-pressed)) + ) + ((< (the-as uint 225) (-> pad righty)) + (set! buttons-pressed (logior (pad-buttons r-analog-down) buttons-pressed)) + ) + ) + (cond + ((< (-> pad rightx) (the-as uint 30)) + (set! buttons-pressed (logior (pad-buttons r-analog-left) buttons-pressed)) + ) + ((< (the-as uint 225) (-> pad rightx)) + (set! buttons-pressed (logior (pad-buttons r-analog-right) buttons-pressed)) + ) + ) + (let ((lang (get-current-language))) + (cond + ((or (= lang (language-enum japanese)) (= lang (language-enum korean))) + (case (scf-get-territory) + ((2 3) + (if (logtest? buttons-pressed (pad-buttons circle)) + (set! buttons-pressed (logior (pad-buttons confirm) buttons-pressed)) + ) + ) + (else + (if (logtest? buttons-pressed (pad-buttons circle x)) + (set! buttons-pressed (logior (pad-buttons confirm) buttons-pressed)) + ) + ) + ) + ) + ((let ((territory (scf-get-territory))) + (or (= territory 2) (= territory 3)) + ) + (if (logtest? buttons-pressed (pad-buttons circle x)) + (set! buttons-pressed (logior (pad-buttons confirm) buttons-pressed)) + ) + ) + (else + (if (logtest? buttons-pressed (pad-buttons x)) + (set! buttons-pressed (logior (pad-buttons confirm) buttons-pressed)) + ) + ) + ) + ) + (set! (-> pad button0-shadow-abs 0) buttons-pressed) + (set! (-> pad button0-abs 0) buttons-pressed) + ) + (set! (-> pad button0-rel 0) (logclear (-> pad button0-abs 0) (-> 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) + (set! (-> pad stick0-speed) 0.0) + ) + ) + (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) + (set! (-> pad stick0-speed) 0.0) + ) + ) + (when (or (!= (-> pad button0-abs 0) (-> pad button0-abs 1)) + (or (< 0.3 (-> pad stick0-speed)) (zero? (-> pad change-time))) + ) + (set! (-> pad change-time) (the-as uint (get-current-time))) + (set! (-> pad real-change-time) (the-as uint (get-real-current-time))) + ) + ) + (else + (cpad-invalid! pad) + ) + ) + ) + ) + ) + *cpad-list* + ) + +;; definition for function buzz-stop! +;; WARN: Return type mismatch int vs none. +(defun buzz-stop! ((arg0 int)) + "Set the buzz to 0 on both vibration motors of the given cpad." + (cpad-set-buzz! (-> *cpad-list* cpads arg0) 0 0 0) + (cpad-set-buzz! (-> *cpad-list* cpads arg0) 1 0 0) + 0 + (none) + ) + +;; definition of type mouse-info +(deftype mouse-info (basic) + ((active symbol) + (cursor symbol) + (valid symbol) + (id uint8) + (status uint16) + (button0 uint16) + (deltax int8) + (deltay int8) + (wheel uint8) + (change-time time-frame) + (button0-abs mouse-buttons 3) + (button0-shadow-abs mouse-buttons 1) + (button0-rel mouse-buttons 3) + (pos vector 2 :inline) + (posx float :overlay-at (-> pos 0 data 0)) + (posy float :overlay-at (-> pos 0 data 1)) + (oldposx float :offset 96) + (oldposy float :offset 100) + (speedx float :overlay-at (-> pos 0 data 3)) + (speedy float :offset 108) + ) + (:methods + (new (symbol type) _type_) + ) + ) + +;; definition for method 3 of type mouse-info +(defmethod inspect ((this mouse-info)) + (when (not this) + (set! this this) + (goto cfg-7) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tactive: ~A~%" (-> this active)) + (format #t "~1Tcursor: ~A~%" (-> this cursor)) + (format #t "~1Tvalid: ~A~%" (-> this valid)) + (format #t "~1Tid: ~D~%" (-> this id)) + (format #t "~1Tstatus: #x~X~%" (-> this status)) + (format #t "~1Tbutton0: #x~X~%" (-> this button0)) + (format #t "~1Tdeltax: ~D~%" (-> this deltax)) + (format #t "~1Tdeltay: ~D~%" (-> this deltay)) + (format #t "~1Twheel: ~D~%" (-> this wheel)) + (format #t "~1Tchange-time: ~D~%" (-> this change-time)) + (format #t "~1Tbutton0-abs[3] @ #x~X~%" (-> this button0-abs)) + (format #t "~1Tbutton0-shadow-abs[1] @ #x~X~%" (-> this button0-shadow-abs)) + (format #t "~1Tbutton0-rel[3] @ #x~X~%" (-> this button0-rel)) + (format #t "~1Tpos[2] @ #x~X~%" (-> this pos)) + (dotimes (s5-0 2) + (format #t "~T [~D]~1Tpos: ~`vector`P~%" s5-0 (-> this pos s5-0)) + ) + (format #t "~1Tposx: ~f~%" (-> this posx)) + (format #t "~1Tposy: ~f~%" (-> this posy)) + (format #t "~1Toldposx: ~f~%" (-> this pos 1 x)) + (format #t "~1Toldposy: ~f~%" (-> this oldposy)) + (format #t "~1Tspeedx: ~f~%" (-> this speedx)) + (format #t "~1Tspeedy: ~f~%" (-> this speedy)) + (label cfg-7) + this + ) + +;; definition for method 0 of type mouse-info +(defmethod new mouse-info ((allocation symbol) (type-to-make type)) + (let ((v0-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> v0-0 active) #f) + (set! (-> v0-0 valid) #f) + (set! (-> v0-0 cursor) #f) + v0-0 + ) + ) + +;; definition for symbol *mouse*, type mouse-info +(define *mouse* (new 'global 'mouse-info)) + +;; definition for function service-mouse +;; INFO: Used lq/sq +;; WARN: Return type mismatch mouse-info vs none. +(defun service-mouse () + "Update the mouse, and draw the cursor." + (let ((mouse *mouse*)) + (mouse-get-data mouse) + (set! (-> mouse pos 1 quad) (-> mouse pos 0 quad)) + (set! (-> mouse button0-abs 2) (-> mouse button0-abs 1)) + (set! (-> mouse button0-abs 1) (-> mouse button0-shadow-abs 0)) + (set! (-> mouse button0-rel 2) (-> mouse button0-rel 1)) + (set! (-> mouse button0-rel 1) (-> mouse button0-rel 0)) + (set! (-> mouse button0-rel 0) (mouse-buttons)) + (set! (-> mouse speedx) 0.0) + (set! (-> mouse speedy) 0.0) + (cond + ((or (not (-> mouse valid)) (not (-> mouse active))) + (set! (-> mouse valid) #f) + (set! (-> mouse status) (the-as uint 0)) + (set! (-> mouse pos 0 quad) (the-as uint128 0)) + (set! (-> mouse pos 1 quad) (the-as uint128 0)) + ) + ((logtest? (-> mouse status) 1) + (set! (-> mouse change-time) (get-current-time)) + (set! (-> mouse speedx) + (* (sign (the float (-> mouse deltax))) (pow (fabs (the float (-> mouse deltax))) 1.3)) + ) + (set! (-> mouse speedy) + (* (sign (the float (-> mouse deltay))) (pow (fabs (the float (-> mouse deltay))) 1.3)) + ) + (set! (-> mouse posx) (fmax -256.0 (fmin 256.0 (+ (-> mouse posx) (-> mouse speedx))))) + (set! (-> mouse posy) (fmax -208.0 (fmin 208.0 (+ (-> mouse posy) (-> mouse speedy))))) + (let ((v1-22 (-> mouse button0))) + (set! (-> mouse button0-shadow-abs 0) (the-as mouse-buttons v1-22)) + (set! (-> mouse button0-abs 0) (the-as mouse-buttons v1-22)) + ) + (set! (-> mouse button0-rel 0) (logclear (-> mouse button0-abs 0) (-> mouse button0-abs 1))) + ) + ) + (if (and (-> mouse active) (-> mouse valid) (-> mouse cursor)) + (add-debug-cursor + #t + (bucket-id debug-no-zbuf2) + (+ (the int (-> mouse posx)) 256) + (+ (the int (-> mouse posy)) 208) + (-> mouse button0-abs 0) + ) + ) + ) + (none) + ) + +;; definition of type keybd-info +(deftype keybd-info (basic) + ((active symbol) + (valid symbol) + (kdata uint8 16) + (keys uint8 256) + ) + (:methods + (new (symbol type) _type_) + ) + ) + +;; definition for method 3 of type keybd-info +(defmethod inspect ((this keybd-info)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tactive: ~A~%" (-> this active)) + (format #t "~1Tvalid: ~A~%" (-> this valid)) + (format #t "~1Tkdata[16] @ #x~X~%" (-> this kdata)) + (format #t "~1Tkeys[256] @ #x~X~%" (-> this keys)) + (label cfg-4) + this + ) + +;; definition for method 0 of type keybd-info +(defmethod new keybd-info ((allocation symbol) (type-to-make type)) + (let ((v0-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) + (set! (-> v0-0 active) #f) + (set! (-> v0-0 valid) #f) + v0-0 + ) + ) + +;; definition for symbol *keybd*, type keybd-info +(define *keybd* (new 'global 'keybd-info)) + +;; definition for function service-keybd +;; WARN: Return type mismatch keybd-info vs none. +(defun service-keybd () + (let ((keyboard *keybd*)) + (keybd-get-data keyboard) + (dotimes (key-idx 256) + (cond + ((= (-> keyboard keys key-idx) 1) + (set! (-> keyboard keys key-idx) (the-as uint 2)) + ) + ((= (-> keyboard keys key-idx) 2) + (set! (-> keyboard keys key-idx) (the-as uint 0)) + 0 + ) + ) + ) + (dotimes (v1-3 (the-as int (+ (-> keyboard kdata 1) -2))) + (if (and (nonzero? (-> keyboard kdata (+ v1-3 4))) (!= (-> keyboard kdata (+ v1-3 4)) 1)) + (set! (-> keyboard keys (-> keyboard kdata (+ v1-3 4))) (the-as uint 1)) + ) + ) + (if (nonzero? (-> keyboard kdata 1)) + (set! (-> keyboard keys 0) (-> keyboard kdata 2)) + ) + ) + (none) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/ps2/timer_REF.gc b/test/decompiler/reference/jak3/engine/ps2/timer_REF.gc new file mode 100644 index 000000000..681519921 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/ps2/timer_REF.gc @@ -0,0 +1,259 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function timer-count +(defun timer-count ((arg0 timer-bank)) + "Return a timer's counter value." + (.sync.l) + (let ((v0-0 (-> arg0 count))) + (.sync.l) + v0-0 + ) + ) + +;; definition for function disable-irq +;; WARN: Return type mismatch int vs none. +;; ERROR: Unsupported inline assembly instruction kind - [mfc0 v0, Status] +(defun disable-irq () + "Disable all interrupts. Has no effect on PC Port." + (local-vars (v0-0 int)) + (let ((v1-0 (the-as uint #xfffffffe))) + (.mfc0 v0-0 Status) + (let ((v0-1 (logand v0-0 v1-0))) + (.mtc0 Status v0-1) + ) + ) + (.sync.p) + 0 + (none) + ) + +;; definition for function enable-irq +;; WARN: Return type mismatch int vs none. +;; ERROR: Unsupported inline assembly instruction kind - [mfc0 v0, Status] +(defun enable-irq () + "Enable all interrupts. Has no effect on PC Port." + (local-vars (v0-0 int)) + (.mfc0 v0-0 Status) + (let ((v0-1 (logior v0-0 1))) + (.mtc0 Status v0-1) + ) + (.sync.p) + 0 + (none) + ) + +;; definition for function stopwatch-init +(defun stopwatch-init ((arg0 stopwatch)) + "Init a stopwatch." + (set! (-> arg0 begin-level) 0) + (set! (-> arg0 prev-time-elapsed) 0) + 0 + ) + +;; definition for function stopwatch-reset +;; ERROR: Unsupported inline assembly instruction kind - [mfc0 v1, Count] +(defun stopwatch-reset ((arg0 stopwatch)) + "Restart a stopwatch's times." + (local-vars (v1-3 int)) + (set! (-> arg0 prev-time-elapsed) 0) + (when (> (-> arg0 begin-level) 0) + 0 + (.mfc0 v1-3 Count) + (set! (-> arg0 start-time) (the-as time-frame v1-3)) + ) + 0 + ) + +;; definition for function stopwatch-start +;; ERROR: Unsupported inline assembly instruction kind - [mfc0 v1, Count] +(defun stopwatch-start ((arg0 stopwatch)) + "Start a stopwatch from scratch." + (local-vars (v1-4 int)) + (when (zero? (-> arg0 begin-level)) + (set! (-> arg0 begin-level) 1) + 0 + (.mfc0 v1-4 Count) + (set! (-> arg0 start-time) (the-as time-frame v1-4)) + ) + 0 + ) + +;; definition for function stopwatch-stop +;; WARN: Return type mismatch int vs none. +;; ERROR: Unsupported inline assembly instruction kind - [mfc0 a1, Count] +(defun stopwatch-stop ((arg0 stopwatch)) + "Fully stop a stopwatch and save its elapsed time." + (local-vars (a1-0 int)) + (when (> (-> arg0 begin-level) 0) + (set! (-> arg0 begin-level) 0) + 0 + (.mfc0 a1-0 Count) + (+! (-> arg0 prev-time-elapsed) (- (the-as time-frame a1-0) (-> arg0 start-time))) + ) + 0 + (none) + ) + +;; definition for function stopwatch-begin +;; ERROR: Unsupported inline assembly instruction kind - [mfc0 v1, Count] +(defun stopwatch-begin ((arg0 stopwatch)) + "Begin a stopwatch level, and starts it if it hasn't yet." + (local-vars (v1-3 int)) + (when (zero? (-> arg0 begin-level)) + 0 + (.mfc0 v1-3 Count) + (set! (-> arg0 start-time) (the-as time-frame v1-3)) + ) + (+! (-> arg0 begin-level) 1) + 0 + ) + +;; definition for function stopwatch-end +;; WARN: Return type mismatch int vs none. +;; ERROR: Unsupported inline assembly instruction kind - [mfc0 a1, Count] +(defun stopwatch-end ((arg0 stopwatch)) + "End a stopwatch level. Stops the stopwatch if it's back to level zero. + There is no guard against ending a stopwatch too many times, and a negative level + will cause errors!" + (local-vars (a1-0 int)) + (+! (-> arg0 begin-level) -1) + (when (zero? (-> arg0 begin-level)) + 0 + (.mfc0 a1-0 Count) + (+! (-> arg0 prev-time-elapsed) (- (the-as time-frame a1-0) (-> arg0 start-time))) + ) + 0 + (none) + ) + +;; definition for function stopwatch-elapsed-ticks +;; ERROR: Unsupported inline assembly instruction kind - [mfc0 v1, Count] +(defun stopwatch-elapsed-ticks ((arg0 stopwatch)) + "Returns the elapsed time so far (in clock cycles) of a stopwatch." + (local-vars (v1-3 int)) + (let ((v0-0 (-> arg0 prev-time-elapsed))) + (when (> (-> arg0 begin-level) 0) + 0 + (.mfc0 v1-3 Count) + (+! v0-0 (- (the-as time-frame v1-3) (-> arg0 start-time))) + ) + v0-0 + ) + ) + +;; definition for function stopwatch-elapsed-seconds +(defun stopwatch-elapsed-seconds ((arg0 stopwatch)) + "Returns the elapsed time so far (in seconds) of a stopwatch." + (let ((v1-0 (stopwatch-elapsed-ticks arg0))) + (* 0.0000000033333334 (the float v1-0)) + ) + ) + +;; definition for method 9 of type clock +(defmethod update-rates! ((this clock) (rate float)) + "Recompute all clock values for the given clock ratio (arg0)." + (set! (-> this clock-ratio) rate) + (let ((f0-6 (if (nonzero? *display*) + (* (-> *display* time-factor) (-> *display* dog-ratio) rate) + (* 5.0 rate) + ) + ) + ) + (set! (-> this time-adjust-ratio) (* 0.2 f0-6)) + ) + (set! (-> this seconds-per-frame) (* 0.016666668 (-> this time-adjust-ratio))) + (set! (-> this frames-per-second) (if (= (-> this time-adjust-ratio) 0.0) + 0.0 + (* 60.0 (/ 1.0 (-> this time-adjust-ratio))) + ) + ) + (let* ((v1-12 (the-as number (- (-> this frame-counter) (-> this old-frame-counter)))) + (f0-14 (the-as float v1-12)) + (f1-9 (* 0.2 (the float v1-12))) + ) + (set-vector! (-> this sparticle-data) f0-14 (* 5.0 f1-9) f1-9 f1-9) + ) + rate + ) + +;; definition for method 10 of type clock +(defmethod advance-by! ((this clock) (arg0 float)) + "Advance the clock by arg0 timeframes (as a float). + Both counters keep a separate fractional and integer counter." + (the int (+ arg0 (-> this accum))) + (+! (-> this integral-accum) arg0) + (set! (-> this old-integral-frame-counter) (-> this integral-frame-counter)) + (while (>= (-> this integral-accum) (-> *display* time-factor)) + (+! (-> this integral-frame-counter) 1) + (set! (-> this integral-accum) (- (-> this integral-accum) (-> *display* time-factor))) + ) + (let ((v1-7 (the int (+ arg0 (-> this accum))))) + (set! (-> this accum) (- (+ arg0 (-> this accum)) (the float v1-7))) + (set! (-> this old-frame-counter) (-> this frame-counter)) + (+! (-> this frame-counter) v1-7) + ) + (update-rates! this (-> this clock-ratio)) + this + ) + +;; definition for method 11 of type clock +(defmethod tick! ((this clock)) + "Per-game-frame clock tick forward." + (if (not (logtest? (-> this mask) (-> *kernel-context* prevent-from-run))) + (advance-by! this (* (-> *display* time-factor) (-> *display* dog-ratio) (-> this clock-ratio))) + (set! (-> this sparticle-data x) 0.0) + ) + this + ) + +;; definition for method 15 of type clock +;; WARN: Return type mismatch int vs none. +(defmethod reset! ((this clock)) + "Reset a clock to 1000s, rate of 1." + (set! (-> this frame-counter) (seconds 1000)) + (set! (-> this integral-frame-counter) (seconds 1000)) + (set! (-> this accum) 0.0) + (set! (-> this old-frame-counter) (+ (-> this frame-counter) -1)) + (set! (-> this old-integral-frame-counter) (+ (-> this integral-frame-counter) -1)) + (update-rates! this 1.0) + 0 + (none) + ) + +;; definition for method 12 of type clock +(defmethod save! ((this clock) (arg0 (pointer uint64))) + "Save a clock's state to a buffer, return bytes used." + (set! (-> arg0 0) (the-as uint (-> this frame-counter))) + (set! (-> arg0 1) (the-as uint (-> this integral-frame-counter))) + 16 + ) + +;; definition for method 13 of type clock +(defmethod load! ((this clock) (arg0 (pointer uint64))) + "Load a clock's state from a buffer, return bytes used." + (set! (-> this frame-counter) (the-as time-frame (-> arg0 0))) + (set! (-> this integral-frame-counter) (the-as time-frame (-> arg0 1))) + (set! (-> this accum) 0.0) + (set! (-> this integral-accum) 0.0) + (set! (-> this old-frame-counter) (-> this frame-counter)) + (set! (-> this old-integral-frame-counter) (-> this integral-frame-counter)) + 16 + ) + +;; definition for method 14 of type clock +(defmethod copy! ((this clock) (arg0 clock)) + "Copy the frame counters and ratio from arg0." + (set! (-> this frame-counter) (-> arg0 frame-counter)) + (set! (-> this integral-frame-counter) (-> arg0 integral-frame-counter)) + (set! (-> this accum) (-> arg0 accum)) + (set! (-> this integral-accum) (-> arg0 integral-accum)) + (set! (-> this old-frame-counter) (-> arg0 old-frame-counter)) + (set! (-> this old-integral-frame-counter) (-> arg0 old-integral-frame-counter)) + (set! (-> this clock-ratio) (-> arg0 clock-ratio)) + this + ) + + + + diff --git a/test/decompiler/reference/jak3/kernel/gcommon_REF.gc b/test/decompiler/reference/jak3/kernel/gcommon_REF.gc index acb99bbac..07d082db7 100644 --- a/test/decompiler/reference/jak3/kernel/gcommon_REF.gc +++ b/test/decompiler/reference/jak3/kernel/gcommon_REF.gc @@ -248,7 +248,6 @@ This is the main vector type." ) ;; definition for function type? -;; WARN: Using new Jak 2 rtype-of (defun type? ((obj object) (desired-type type)) "Return if the given object is an instance of the given type. Works on basics, bintegers, or symbols." @@ -1207,14 +1206,12 @@ over a normal (array uint32), since both store data the same way." (define *print-column* (the-as binteger 0)) ;; definition for function print -;; WARN: Using new Jak 2 rtype-of (defun print ((obj object)) "Print any boxed object (symbol, pair, basic, binteger) to #t (the REPL). No newline." ((method-of-type (rtype-of obj) print) obj) ) ;; definition for function printl -;; WARN: Using new Jak 2 rtype-of (defun printl ((obj object)) "Print any boxed object (symbol, pair, basic, binteger) to #t (the REPL), followed by a newline." (let ((a0-1 obj)) @@ -1225,7 +1222,6 @@ over a normal (array uint32), since both store data the same way." ) ;; definition for function inspect -;; WARN: Using new Jak 2 rtype-of (defun inspect ((obj object)) "Inspect any boxed object (symbol, pair, basic, binteger) to #t (the REPL)." ((method-of-type (rtype-of obj) inspect) obj) @@ -1276,11 +1272,6 @@ over a normal (array uint32), since both store data the same way." ) ;; definition for function valid? -;; WARN: Using new Jak 2 rtype-of -;; WARN: Using new Jak 2 rtype-of -;; WARN: Using new Jak 2 rtype-of -;; WARN: Using new Jak 2 rtype-of -;; WARN: Using new Jak 2 rtype-of ;; ERROR: Unsupported inline assembly instruction kind - [daddu v1, v1, s7] ;; ERROR: Unsupported inline assembly instruction kind - [daddu v1, v1, s7] ;; ERROR: Unsupported inline assembly instruction kind - [daddu v1, v1, s7] @@ -1549,3 +1540,7 @@ over a normal (array uint32), since both store data the same way." ;; failed to figure out what this is: 0 + + + + diff --git a/test/decompiler/reference/jak3/kernel/gkernel-h_REF.gc b/test/decompiler/reference/jak3/kernel/gkernel-h_REF.gc index 2ad7487ba..c13e1deb9 100644 --- a/test/decompiler/reference/jak3/kernel/gkernel-h_REF.gc +++ b/test/decompiler/reference/jak3/kernel/gkernel-h_REF.gc @@ -60,10 +60,10 @@ (clock-ratio float) (accum float) (integral-accum float) - (frame-counter uint64) - (old-frame-counter uint64) - (integral-frame-counter uint64) - (old-integral-frame-counter uint64) + (frame-counter time-frame) + (old-frame-counter time-frame) + (integral-frame-counter time-frame) + (old-integral-frame-counter time-frame) (sparticle-data vector :inline) (seconds-per-frame float) (frames-per-second float) @@ -72,12 +72,12 @@ (:methods (new (symbol type int) _type_) (update-rates! (_type_ float) float) - (clock-method-10 () none) - (clock-method-11 () none) - (clock-method-12 () none) - (clock-method-13 () none) - (clock-method-14 () none) - (clock-method-15 () none) + (advance-by! (_type_ float) clock) + (tick! (_type_) clock) + (save! (_type_ (pointer uint64)) int) + (load! (_type_ (pointer uint64)) int) + (copy! (_type_ clock) clock) + (reset! (_type_) none) (frame-mask-2 (_type_ int) symbol) (frame-mask-4 (_type_ int) symbol) (frame-mask-8 (_type_ int) symbol) @@ -117,57 +117,57 @@ ;; definition for method 16 of type clock (defmethod frame-mask-2 ((this clock) (xor-val int)) "Check if the frame count, xored with `xor-val` has its lowest bit set" - (not (logtest? (logxor xor-val (the-as int (-> this integral-frame-counter))) 1)) + (not (logtest? (logxor xor-val (-> this integral-frame-counter)) 1)) ) ;; definition for method 17 of type clock (defmethod frame-mask-4 ((this clock) (xor-val int)) "Check if the frame count, xored with `xor-val` has any of its lowest 2 bits set" - (not (logtest? (logxor xor-val (the-as int (-> this integral-frame-counter))) 3)) + (not (logtest? (logxor xor-val (-> this integral-frame-counter)) 3)) ) ;; definition for method 18 of type clock (defmethod frame-mask-8 ((this clock) (xor-val int)) "Check if the frame count, xored with `xor-val` has any of its lowest 3 bits set" - (not (logtest? (logxor xor-val (the-as int (-> this integral-frame-counter))) 7)) + (not (logtest? (logxor xor-val (-> this integral-frame-counter)) 7)) ) ;; definition for method 19 of type clock (defmethod frame-mask-16 ((this clock) (xor-val int)) "Check if the frame count, xored with `xor-val` has any of its lowest 4 bits set" - (not (logtest? (logxor xor-val (the-as int (-> this integral-frame-counter))) 15)) + (not (logtest? (logxor xor-val (-> this integral-frame-counter)) 15)) ) ;; definition for method 20 of type clock (defmethod frame-mask-32 ((this clock) (xor-val int)) "Check if the frame count, xored with `xor-val` has any of its lowest 5 bits set" - (not (logtest? (logxor xor-val (the-as int (-> this integral-frame-counter))) 31)) + (not (logtest? (logxor xor-val (-> this integral-frame-counter)) 31)) ) ;; definition for method 21 of type clock (defmethod frame-mask-64 ((this clock) (xor-val int)) "Check if the frame count, xored with `xor-val` has any of its lowest 6 bits set" - (not (logtest? (logxor xor-val (the-as int (-> this integral-frame-counter))) 63)) + (not (logtest? (logxor xor-val (-> this integral-frame-counter)) 63)) ) ;; definition for method 22 of type clock (defmethod frame-mask-128 ((this clock) (xor-val int)) "Check if the frame count, xored with `xor-val` has any of its lowest 7 bits set" - (not (logtest? (logxor xor-val (the-as int (-> this integral-frame-counter))) 127)) + (not (logtest? (logxor xor-val (-> this integral-frame-counter)) 127)) ) ;; definition for method 23 of type clock (defmethod frame-mask-256 ((this clock) (xor-val int)) "Check if the frame count, xored with `xor-val` has any of its lowest 8 bits set" - (not (logtest? (logxor xor-val (the-as int (-> this integral-frame-counter))) 255)) + (not (logtest? (logxor xor-val (-> this integral-frame-counter)) 255)) ) ;; definition for method 0 of type clock (defmethod new clock ((allocation symbol) (type-to-make type) (index int)) (let ((gp-0 (object-new allocation type-to-make (the-as int (-> type-to-make size))))) (set! (-> gp-0 index) index) - (set! (-> gp-0 frame-counter) (the-as uint #x493e0)) - (set! (-> gp-0 integral-frame-counter) (the-as uint #x493e0)) + (set! (-> gp-0 frame-counter) (seconds 1000)) + (set! (-> gp-0 integral-frame-counter) (seconds 1000)) (set! (-> gp-0 old-frame-counter) (+ (-> gp-0 frame-counter) -1)) (set! (-> gp-0 old-integral-frame-counter) (+ (-> gp-0 integral-frame-counter) -1)) (update-rates! gp-0 1.0) @@ -766,3 +766,7 @@ ;; failed to figure out what this is: 0 + + + + diff --git a/test/offline/config/jak3/config.jsonc b/test/offline/config/jak3/config.jsonc index a68f9381d..e92c013e0 100644 --- a/test/offline/config/jak3/config.jsonc +++ b/test/offline/config/jak3/config.jsonc @@ -37,7 +37,11 @@ "closest-pt-in-triangle", "circle-circle-xz-intersect", "calculate-basis-functions-vector!", - "curve-evaluate!" + "curve-evaluate!", + // timer + "(method 9 clock)", + // pad + "service-cpads" ], "skip_compile_states": {}