From fae20a19fcea97701e82bb644d463837d6368c43 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Sun, 10 Mar 2024 21:11:41 -0400 Subject: [PATCH] [jak3] Decompile sprite and debug files (#3420) --- decompiler/config/jak3/all-types.gc | 240 +- decompiler/config/jak3/ntsc_v1/hacks.jsonc | 12 +- .../config/jak3/ntsc_v1/label_types.jsonc | 10 + .../jak3/ntsc_v1/stack_structures.jsonc | 48 +- .../config/jak3/ntsc_v1/type_casts.jsonc | 74 + .../config/jak3/ntsc_v1/var_names.jsonc | 246 +++ decompiler/util/data_decompile.cpp | 2 + game/CMakeLists.txt | 2 + game/mips2c/jak3_functions/debug.cpp | 597 +++++ game/mips2c/jak3_functions/sky.cpp | 54 + game/mips2c/jak3_functions/sky.h | 14 + game/mips2c/mips2c_table.cpp | 13 +- goal_src/jak3/engine/camera/cam-debug-h.gc | 2 + goal_src/jak3/engine/debug/debug-sphere.gc | 89 + goal_src/jak3/engine/debug/debug.gc | 1770 +++++++++++++++ goal_src/jak3/engine/gfx/font-h.gc | 5 +- goal_src/jak3/engine/gfx/sky/sky-h.gc | 4 + .../jak3/engine/gfx/sprite/simple-sprite-h.gc | 9 +- .../jak3/engine/gfx/sprite/sprite-distort.gc | 344 +++ .../jak3/engine/gfx/sprite/sprite-glow.gc | 758 +++++++ .../reference/jak3/decompiler-macros.gc | 18 +- .../jak3/engine/debug/debug-sphere_REF.gc | 103 + .../reference/jak3/engine/debug/debug_REF.gc | 1951 +++++++++++++++++ .../reference/jak3/engine/gfx/font-h_REF.gc | 6 +- .../gfx/sprite/particles/sparticle-h_REF.gc | 16 +- .../engine/gfx/sprite/simple-sprite-h_REF.gc | 9 +- .../engine/gfx/sprite/sprite-distort_REF.gc | 378 ++++ .../jak3/engine/gfx/sprite/sprite-glow_REF.gc | 915 ++++++++ test/offline/config/jak3/config.jsonc | 4 +- 29 files changed, 7546 insertions(+), 147 deletions(-) create mode 100644 game/mips2c/jak3_functions/debug.cpp create mode 100644 game/mips2c/jak3_functions/sky.cpp create mode 100644 game/mips2c/jak3_functions/sky.h create mode 100644 test/decompiler/reference/jak3/engine/debug/debug-sphere_REF.gc create mode 100644 test/decompiler/reference/jak3/engine/debug/debug_REF.gc create mode 100644 test/decompiler/reference/jak3/engine/gfx/sprite/sprite-distort_REF.gc create mode 100644 test/decompiler/reference/jak3/engine/gfx/sprite/sprite-glow_REF.gc diff --git a/decompiler/config/jak3/all-types.gc b/decompiler/config/jak3/all-types.gc index 7934fa3ff..076465f17 100644 --- a/decompiler/config/jak3/all-types.gc +++ b/decompiler/config/jak3/all-types.gc @@ -8105,7 +8105,7 @@ :size-assert #xbec :flag-assert #xa00000bec (:methods - (font-work-method-9 () none) ;; 9 + (set-context! (_type_ object) none) ;; 9 ) ) @@ -25131,6 +25131,7 @@ (fade-b float :offset-assert 52) (tex-id texture-id :offset-assert 56) ;; guessed by decompiler (dummy uint32 :offset-assert 60) + (quads vector 4 :inline :offset 0) ) :method-count-assert 10 :size-assert #x40 @@ -25149,9 +25150,9 @@ :size-assert #x8 :flag-assert #xc00000008 (:methods - (simple-sprite-system-method-9 () none) ;; 9 ;; (add! (_type_ sprite-glow-data) none) - (draw-all-sprites! (_type_ dma-buffer) none) ;; 10 - (simple-sprite-system-method-11 () none) ;; 11 ;; (clear! (_type_) none) + (add! "Add a sprite to the list, to be drawn later." (_type_ sprite-glow-data) none) ;; 9 + (draw-all-sprites! "Submit all sprites to the sprite-glow renderer" (_type_ dma-buffer) none) ;; 10 + (clear! "Reset the list." (_type_) none) ;; 11 ) ) @@ -25970,7 +25971,7 @@ (flags sp-cpuinfo-flag :offset-assert 104) ;; guessed by decompiler (user-int32 int32 :offset-assert 108) (user-uint32 uint32 :offset 108) - (user-float float :offset 108) + (user-float float :offset 108 :score 1) (user-pntr uint32 :offset 108) (user-object basic :offset 108) (user-sprite sprite-vec-data-2d :offset 108) @@ -29159,42 +29160,41 @@ ;; sprite-distort ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype sprite-distorter-sine-tables (basic) + "Table of precomputed sine data for the sprite distorter renderer." ((aspx float :offset-assert 4) (aspy float :offset-assert 8) - (entry vector 128 :offset-assert 16) ;; guessed by decompiler - (ientry qword 9 :offset-assert 2064) ;; guessed by decompiler - (giftag qword :inline :offset-assert 2208) ;; gs-gif-tag :inline + (entry vector 128 :inline :offset-assert 16) ;; guessed by decompiler + (ientry qword 9 :inline :offset-assert 2064) ;; guessed by decompiler + (giftag gs-gif-tag :inline :offset-assert 2208) ;; :inline (color qword :inline :offset-assert 2224) ) :method-count-assert 9 :size-assert #x8c0 :flag-assert #x9000008c0 ) -|# -;; (define-extern *sprite-distorter-sine-tables* object) ;; sprite-distorter-sine-tables -(define-extern sprite-distorter-generate-tables (function none)) -;; (define-extern sprite-distort-vu1-block object) ;; vu-function -(define-extern sprite-init-distorter (function dma-buffer none)) -(define-extern sprite-draw-distorters (function dma-buffer none)) +(define-extern *sprite-distorter-sine-tables* sprite-distorter-sine-tables) +(define-extern sprite-distorter-generate-tables "Regenerate the sprite-distorter-sine-tables for the current camera settings." (function none)) +(define-extern sprite-distort-vu1-block vu-function) +(define-extern sprite-init-distorter "Generate DMA to initialize the distort renderer." (function dma-buffer none)) +(define-extern sprite-draw-distorters "Generate DMA to draw all distort sprites." (function dma-buffer none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; sprite-glow ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype sprite-glow-template (structure) + "Sprite glow GS data templates sent to VU1." ((clear-init-giftag gs-gif-tag :inline :offset-assert 0) - (clear-init-adcmds gs-adcmd 5 :offset-assert 16) ;; guessed by decompiler + (clear-init-adcmds gs-adcmd 5 :inline :offset-assert 16) ;; guessed by decompiler (clear-draw-giftag gs-gif-tag :inline :offset-assert 96) (clear-draw-clr-0 gs-packed-rgba :inline :offset-assert 112) - (clear-draw-xyz-0 gs-packed-xyzw 2 :offset-assert 128) ;; guessed by decompiler + (clear-draw-xyz-0 gs-packed-xyzw 2 :inline :offset-assert 128) ;; guessed by decompiler (clear-draw-clr-1 gs-packed-rgba :inline :offset-assert 160) - (clear-draw-xyz-1 vector 2 :offset-assert 176) ;; guessed by decompiler + (clear-draw-xyz-1 vector 2 :inline :offset-assert 176) ;; guessed by decompiler (offscr-setup-giftag gs-gif-tag :inline :offset-assert 208) - (offscr-setup-adcmds gs-adcmd 8 :offset-assert 224) ;; guessed by decompiler + (offscr-setup-adcmds gs-adcmd 8 :inline :offset-assert 224) ;; guessed by decompiler (offscr-first-giftag gs-gif-tag :inline :offset-assert 352) (offscr-first-clr gs-packed-rgba :inline :offset-assert 368) (offscr-first-uv-0 gs-packed-uv :inline :offset-assert 384) @@ -29202,7 +29202,7 @@ (offscr-first-uv-1 gs-packed-uv :inline :offset-assert 416) (offscr-first-xyzw-1 gs-packed-xyzw :inline :offset-assert 432) (repeat-draw-giftag gs-gif-tag :inline :offset-assert 448) - (repeat-draw-adcmds gs-adcmd 29 :offset-assert 464) ;; guessed by decompiler + (repeat-draw-adcmds gs-adcmd 29 :inline :offset-assert 464) ;; guessed by decompiler (flare-alpha-giftag gs-gif-tag :inline :offset-assert 928) (flare-alpha-clr gs-packed-rgba :inline :offset-assert 944) (flare-alpha-uv gs-packed-uv :inline :offset-assert 960) @@ -29211,7 +29211,7 @@ (flare-alpha-xyzw-2 gs-packed-xyzw :inline :offset-assert 1008) (flare-alpha-xyzw-3 gs-packed-xyzw :inline :offset-assert 1024) (flare-init-giftag gs-gif-tag :inline :offset-assert 1040) - (flare-init-adcmds gs-adcmd 8 :offset-assert 1056) ;; guessed by decompiler + (flare-init-adcmds gs-adcmd 8 :inline :offset-assert 1056) ;; guessed by decompiler (flare-draw-giftag gs-gif-tag :inline :offset-assert 1184) (flare-draw-clr gs-packed-rgba :inline :offset-assert 1200) (flare-draw-stq-0 gs-packed-stq :inline :offset-assert 1216) @@ -29227,19 +29227,18 @@ :size-assert #x540 :flag-assert #x900000540 ) -|# -#| (deftype sprite-glow-consts (structure) + "Per-frame constants for sprite-glow VU1." ((camera matrix :inline :offset-assert 0) (perspective matrix :inline :offset-assert 64) (hvdf-offset vector :inline :offset-assert 128) (hmge-scale vector :inline :offset-assert 144) (consts vector :inline :offset-assert 160) - (pfog0 float :offset-assert 160) - (deg-to-rad float :offset-assert 164) - (min-scale float :offset-assert 168) - (inv-area float :offset-assert 172) + (pfog0 float :offset 160) + (deg-to-rad float :offset 164) + (min-scale float :offset 168) + (inv-area float :offset 172) (sincos-01 vector :inline :offset-assert 176) (sincos-23 vector :inline :offset-assert 192) (sincos-45 vector :inline :offset-assert 208) @@ -29247,7 +29246,7 @@ (sincos-89 vector :inline :offset-assert 240) (basis-x vector :inline :offset-assert 256) (basis-y vector :inline :offset-assert 272) - (xy-array vector 4 :offset-assert 288) ;; guessed by decompiler + (xy-array vector 4 :inline :offset-assert 288) ;; guessed by decompiler (clamp-min vector :inline :offset-assert 352) (clamp-max vector :inline :offset-assert 368) ) @@ -29255,10 +29254,9 @@ :size-assert #x180 :flag-assert #x900000180 ) -|# -#| (deftype sprite-glow-dma-packet-data (structure) + "DMA templates for generating DMA to VU1." ((control-packet dma-packet :inline :offset-assert 0) (vecdata-packet dma-packet :inline :offset-assert 16) (shader-cnt-packet dma-packet :inline :offset-assert 32) @@ -29269,10 +29267,9 @@ :size-assert #x50 :flag-assert #x900000050 ) -|# -#| (deftype sprite-glow-cnt-template (structure) + "DMA layout for sending a sprite to VU1, with inline shader." ((control-packet dma-packet :inline :offset-assert 0) (num-sprites uint32 :offset-assert 16) (dummys uint32 3 :offset-assert 20) ;; guessed by decompiler @@ -29281,56 +29278,56 @@ (shader-packet dma-packet :inline :offset-assert 112) (shader adgif-shader :inline :offset-assert 128) (mscal-packet dma-packet :inline :offset-assert 208) + (quads vector 10 :inline :offset 0 :score -1) ) :method-count-assert 9 :size-assert #xe0 :flag-assert #x9000000e0 ) -|# -#| (deftype sprite-glow-ref-template (structure) + "DMA layout for sending a sprite to VU1, with reference to shader." ((control-packet dma-packet :inline :offset-assert 0) (num-sprites uint32 :offset-assert 16) (dummys uint32 3 :offset-assert 20) ;; guessed by decompiler + (num-sprites-quad uint128 :offset 16) (vecdata-packet dma-packet :inline :offset-assert 32) (vecdata sprite-glow-data :inline :offset-assert 48) (shader-packet dma-packet :inline :offset-assert 112) + (shader-packet-ptr pointer :offset 116) ;; pointer to adgif shader to upload. (mscal-packet dma-packet :inline :offset-assert 128) ) :method-count-assert 9 :size-assert #x90 :flag-assert #x900000090 ) -|# -;; (define-extern *sprite-glow-template* object) ;; sprite-glow-template -;; (define-extern sprite-glow-vu1-block object) ;; vu-function -;; (define-extern sprite-glow-init-consts function) ;; (function sprite-glow-consts none) -(define-extern sprite-glow-init-engine (function dma-buffer none)) -;; (define-extern *sprite-glow-dma-packet-data* object) ;; sprite-glow-dma-packet-data -;; (define-extern sprite-glow-add-sprite function) ;; (function dma-buffer sprite-vec-data-2d float float float adgif-shader none) -;; (define-extern sprite-glow-add-simple-sprite function) ;; (function dma-buffer sprite-glow-dma-packet-data sprite-glow-data pointer none) -(define-extern sprite-glow-draw (function dma-buffer none)) -;; (define-extern add-shader-to-dma function) ;; (function dma-buffer adgif-shader) +(define-extern *sprite-glow-template* sprite-glow-template) +(define-extern sprite-glow-vu1-block vu-function) +(define-extern sprite-glow-init-consts "Fill out sprite-glow-consts to be sent to VU1." (function sprite-glow-consts none)) +(define-extern sprite-glow-init-engine "Generate DMA to initialize sprite-glow VU1." (function dma-buffer none)) +(define-extern *sprite-glow-dma-packet-data* sprite-glow-dma-packet-data) +(define-extern sprite-glow-add-sprite "Generate DMA to draw a single sprite from the aux-list." (function dma-buffer sprite-vec-data-2d float float float adgif-shader none)) +(define-extern sprite-glow-add-simple-sprite "Generate DMA to draw a single sprite from the simple sprite system." (function dma-buffer sprite-glow-dma-packet-data sprite-glow-data pointer none)) +(define-extern sprite-glow-draw "Generate DMA for all glow sprites in the aux-list (from sparticle system)" (function dma-buffer none)) +(define-extern add-shader-to-dma (function dma-buffer adgif-shader)) (define-extern *simple-sprite-system* simple-sprite-system) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; debug-sphere ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern make-debug-sphere-table function) ;; (function vector-array float float vector-array) -;; (define-extern *debug-sphere-table* object) ;; (array vector-array) -;; (define-extern add-debug-sphere-from-table function) ;; (function bucket-id vector meters rgba int none) +(define-extern make-debug-sphere-table "Create a table of lines on a sphere." (function vector-array float float vector-array)) +(define-extern *debug-sphere-table* (array vector-array)) +(define-extern add-debug-sphere-from-table "Draw a sphere out of debug lines, using the precomputed table of lines." (function bucket-id vector meters rgba int none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; debug ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype debug-line (structure) ((flags int32 :offset-assert 0) - (bucket int32 :offset-assert 4) ;; bucket-id + (bucket bucket-id :offset-assert 4) ;; (v1 vector :inline :offset-assert 16) (v2 vector :inline :offset-assert 32) (color rgba :offset-assert 48) ;; guessed by decompiler @@ -29341,12 +29338,10 @@ :size-assert #x3c :flag-assert #x90000003c ) -|# -#| (deftype debug-text-3d (structure) ((flags int32 :offset-assert 0) - (bucket int32 :offset-assert 4) ;; bucket-id + (bucket bucket-id :offset-assert 4) ;; (pos vector :inline :offset-assert 16) (color font-color :offset-assert 32) ;; guessed by decompiler (offset vector2h :inline :offset-assert 36) @@ -29356,9 +29351,7 @@ :size-assert #x2c :flag-assert #x90000002c ) -|# -#| (deftype debug-tracking-thang (basic) ((length int32 :offset-assert 4) (allocated-length int32 :offset-assert 8) @@ -29367,74 +29360,93 @@ :size-assert #xc :flag-assert #x90000000c ) -|# ;; debug-vertex-stats is already defined! -;; (define-extern transform-float-point function) ;; (function vector vector4w vector4w) -;; (define-extern add-debug-point function) ;; (function symbol bucket-id vector symbol) -;; (define-extern debug-line-clip? function) ;; (function vector vector vector vector symbol) -;; (define-extern internal-draw-debug-line function) ;; (function bucket-id vector vector rgba symbol rgba pointer) -;; (define-extern internal-draw-debug-text-3d function) ;; (function bucket-id string vector font-color vector2h pointer) -;; (define-extern add-debug-outline-triangle function) ;; (function symbol bucket-id vector vector vector rgba symbol) -;; (define-extern add-debug-triangle-normal function) ;; (function symbol bucket-id vector vector vector rgba symbol) -;; (define-extern add-debug-flat-triangle function) ;; (function symbol bucket-id vector vector vector rgba symbol) -;; (define-extern *debug-lines* object) ;; (inline-array debug-line) -;; (define-extern *debug-lines-trk* object) ;; debug-tracking-thang -;; (define-extern *debug-text-3ds* object) ;; (inline-array debug-text-3d) -;; (define-extern *debug-text-3d-trk* object) ;; debug-tracking-thang -;; (define-extern get-debug-line function) ;; (function debug-line) -;; (define-extern get-debug-text-3d function) ;; (function debug-text-3d) -;; (define-extern debug-reset-buffers function) ;; (function symbol) -;; (define-extern debug-draw-buffers function) ;; (function symbol) -(define-extern add-debug-line (function symbol bucket-id vector vector rgba symbol rgba symbol)) -;; (define-extern add-debug-line2d function) ;; (function symbol bucket-id vector4w vector4w vector4w symbol) -;; (define-extern add-debug-box function) ;; (function symbol bucket-id vector vector rgba symbol) -;; (define-extern add-debug-box-with-transform function) ;; (function symbol bucket-id bounding-box matrix rgba symbol) -(define-extern add-debug-x (function symbol bucket-id vector rgba symbol)) -;; (define-extern add-debug-cross function) ;; (function symbol bucket-id vector float symbol) -(define-extern add-debug-text-3d (function symbol bucket-id string vector font-color vector2h symbol)) -;; (define-extern add-debug-sphere-with-transform function) ;; (function symbol bucket-id vector meters matrix rgba symbol) -(define-extern add-debug-sphere (function symbol bucket-id vector meters rgba symbol)) -(define-extern add-debug-text-sphere (function symbol bucket-id vector meters string rgba symbol)) -;; (define-extern add-debug-spheres function) ;; (function symbol bucket-id (inline-array vector) int rgba symbol) -;; (define-extern add-debug-line-sphere function) ;; (function symbol bucket-id vector vector float rgba none) -;; (define-extern add-debug-circle function) ;; (function symbol bucket-id vector float rgba matrix symbol) -(define-extern add-debug-vector (function symbol bucket-id vector vector meters rgba symbol)) -(define-extern add-debug-matrix (function symbol bucket-id matrix meters matrix)) -;; (define-extern add-debug-rot-matrix function) ;; (function symbol bucket-id matrix vector matrix) -(define-extern add-debug-quaternion (function symbol bucket-id vector quaternion none)) -;; (define-extern add-debug-cspace function) ;; (function symbol bucket-id cspace cspace) -;; (define-extern add-debug-yrot-vector function) ;; (function symbol bucket-id vector float float rgba symbol) -;; (define-extern add-debug-arc function) ;; (function symbol bucket-id vector float float float rgba matrix symbol) -;; (define-extern add-debug-curve function) ;; (function symbol bucket-id (inline-array vector) int (pointer float) int rgba symbol) -;; (define-extern add-debug-curve2 function) ;; (function symbol bucket-id curve rgba symbol symbol) -;; (define-extern add-debug-points function) ;; (function symbol bucket-id (inline-array vector) int rgba float int symbol) -;; (define-extern debug-percent-bar function) ;; (function symbol bucket-id int int float rgba int int symbol) -;; (define-extern debug-pad-display function) ;; (function cpad-info symbol) -;; (define-extern add-debug-light function) ;; (function symbol bucket-id light vector string symbol) -;; (define-extern add-debug-lights function) ;; (function symbol bucket-id (inline-array light) vector symbol) +(define-extern transform-float-point + "Transform a point, using the cached matrix in VU0 registers, set from init-for-transform. + The argument order is backward - be careful! + After transformation, point is constrained to be within some region, but this is not proper clipping, + so you should do this yourself." + (function vector vector4w vector4w)) +(define-extern add-debug-point "Draw a point." (function symbol bucket-id vector symbol)) +(define-extern debug-line-clip? (function vector vector vector vector symbol)) +(define-extern internal-draw-debug-line "Implementation of line drawing DMA." (function bucket-id vector vector rgba symbol rgba symbol)) +(define-extern internal-draw-debug-text-3d "Implementation of 3D text drawing." (function bucket-id string vector font-color vector2h pointer)) +(define-extern add-debug-outline-triangle "Draw a wireframe triangle." (function symbol bucket-id vector vector vector rgba symbol)) +(define-extern add-debug-triangle-normal "Draw the normal of a triangle." (function symbol bucket-id vector vector vector rgba symbol)) +(define-extern add-debug-flat-triangle "Draw a shaded triangle." (function symbol bucket-id vector vector vector rgba symbol)) +(define-extern *debug-lines* (inline-array debug-line)) +(define-extern *debug-lines-trk* debug-tracking-thang) +(define-extern *debug-text-3ds* (inline-array debug-text-3d)) +(define-extern *debug-text-3d-trk* debug-tracking-thang) +(define-extern get-debug-line "Allocate a record for a debug line. + This is used to persist debug drawing for paused objects." + (function debug-line)) +(define-extern get-debug-text-3d "Allocate a record for a debug 3d text. + This is used to persist debug drawing for paused objects." (function debug-text-3d)) +(define-extern debug-reset-buffers + "Reset buffered debug drawing." + (function symbol)) +(define-extern debug-draw-buffers + "Draw all buffered debug drawing." + (function symbol)) +(define-extern add-debug-line + "Draw a line." + (function symbol bucket-id vector vector rgba symbol rgba symbol)) +(define-extern add-debug-line2d + "Draw a screen-space line." + (function symbol bucket-id vector4w vector4w vector4w symbol)) +(define-extern add-debug-box + "Draw an axis-aligned box." + (function symbol bucket-id vector vector rgba symbol)) +(define-extern add-debug-box-with-transform + "Draw a box with arbitrary transform." + (function symbol bucket-id bounding-box matrix rgba symbol)) +(define-extern add-debug-x "Draw an X." (function symbol bucket-id vector rgba symbol)) +(define-extern add-debug-cross "Draw a cross." (function symbol bucket-id vector float symbol)) +(define-extern add-debug-text-3d "Draw debug text." (function symbol bucket-id string vector font-color vector2h symbol)) +(define-extern add-debug-sphere-with-transform "Draw a debug sphere, applying a transform to the given point first." (function symbol bucket-id vector meters matrix rgba symbol)) +(define-extern add-debug-sphere "Draw a debug sphere." (function symbol bucket-id vector meters rgba symbol)) +(define-extern add-debug-text-sphere "Draw a debug sphere with a text label." (function symbol bucket-id vector meters string rgba symbol)) +(define-extern add-debug-spheres "Draw from an array of spheres. The radius is stored in w." (function symbol bucket-id (inline-array vector) int rgba symbol)) +(define-extern add-debug-line-sphere "Draw a capsule as a cylinder." (function symbol bucket-id vector vector float rgba none)) +(define-extern add-debug-circle "Draw a circle." (function symbol bucket-id vector float rgba matrix symbol)) +(define-extern add-debug-vector "Draw a vector." (function symbol bucket-id vector vector meters rgba symbol)) +(define-extern add-debug-matrix "Draw a matrix as a coordinate frame." (function symbol bucket-id matrix meters matrix)) +(define-extern add-debug-rot-matrix "Draw a matrix as a coordinate frame, but use the given origin instead of the trans from the matrix." (function symbol bucket-id matrix vector matrix)) +(define-extern add-debug-quaternion "Draw a quaternion as a coordinate frame." (function symbol bucket-id vector quaternion none)) +(define-extern add-debug-cspace "Draw a cspace as a matrix." (function symbol bucket-id cspace cspace)) +(define-extern add-debug-yrot-vector (function symbol bucket-id vector float float rgba symbol)) +(define-extern add-debug-arc (function symbol bucket-id vector float float float rgba matrix symbol)) +(define-extern add-debug-curve (function symbol bucket-id (inline-array vector) int (pointer float) int rgba symbol)) +(define-extern add-debug-curve2 (function symbol bucket-id curve rgba symbol symbol)) +(define-extern add-debug-points (function symbol bucket-id (inline-array vector) int rgba float int symbol)) +(define-extern debug-percent-bar (function symbol bucket-id int int float rgba int int symbol)) +(define-extern debug-pad-display (function cpad-info symbol)) +(define-extern add-debug-light (function symbol bucket-id light vector string symbol)) +(define-extern add-debug-lights (function symbol bucket-id (inline-array light) vector symbol)) (define-extern drawable-frag-count (function drawable int)) (define-extern drawable-tri-count (function drawable int)) ;; NOTE - defined in kernel? (define-extern drawable-vertex-ratio (function drawable debug-vertex-stats int)) ;; NOTE - defined in kernel? -;; (define-extern history-init function) ;; (function pos-history int pos-history) -;; (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 history-init (function pos-history int pos-history)) +(define-extern history-draw-and-update (function pos-history symbol vector symbol)) +(define-extern dma-timeout-cam (function vector)) +(define-extern display-file-info (function 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) +(define-extern *boundary-polygon* (inline-array sky-vertex)) +(define-extern init-boundary-regs (function none)) +(define-extern add-boundary-shader (function texture-id dma-buffer none)) ;; (define-extern draw-boundary-polygon function) ;; (define-extern render-boundary-quad function) -;; (define-extern render-boundary-tri function) ;; (function sky-vertex dma-buffer none) -;; (define-extern add-debug-bound-internal function) ;; (function dma-buffer (inline-array vector) int rgba rgba int none) +(define-extern render-boundary-tri (function sky-vertex dma-buffer none)) +(define-extern add-debug-bound-internal (function dma-buffer (inline-array vector) int rgba rgba int none)) (define-extern add-debug-bound (function bucket-id (inline-array vector) int rgba rgba int none)) ;; (define-extern cpu-delay function) ;; (function int none) -;; (define-extern qword-read-time function) ;; (function (array uint128) int int) -;; (define-extern bugfix? function) ;; (function symbol) +(define-extern qword-read-time (function (array uint128) int int)) +(define-extern bugfix? (function symbol)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; history ;; @@ -30079,7 +30091,7 @@ ) ;; (define-extern draw-string-asm function) ;; (function string dma-buffer font-context draw-string-result) -;; (define-extern draw-string function) ;; (function string dma-buffer font-context draw-string-result) +(define-extern draw-string (function string dma-buffer font-context draw-string-result)) ;; (define-extern get-string-length function) ;; (function string font-context draw-string-result) (define-extern draw-string-xy (function string dma-buffer int int font-color font-flags draw-string-result)) ;; (define-extern draw-string-adv function) ;; (function string dma-buffer font-context none) @@ -31588,7 +31600,7 @@ ;; sky-data ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern *sky-work* object) ;; sky-work +(define-extern *sky-work* sky-work) ;; (define-extern sky-base-polygons object) ;; (inline-array sky-vertex) ;; (define-extern sky-roof-polygons object) ;; (inline-array sky-vertex) ;; (define-extern *cloud-vert-array* object) ;; cloud-vert-array @@ -31610,7 +31622,7 @@ ;; (define-extern clip-polygon-against-negative-hyperplane function) ;; (define-extern render-sky-quad function) ;; (function (inline-array sky-vertex) dma-buffer none) ;; (define-extern render-sky-tri function) ;; (function (inline-array sky-vertex) dma-buffer none) -;; (define-extern close-sky-buffer function) ;; (function dma-buffer none) +(define-extern close-sky-buffer (function dma-buffer none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; load-state ;; @@ -33009,7 +33021,7 @@ ;; (define-extern cam-collision-record-step function) ;; (function int none) ;; (define-extern cam-collision-record-draw function) ;; (function none) ;; (define-extern camera-master-debug function) ;; (function camera-master none) -;; (define-extern debug-set-camera-pos-rot! function) ;; (function vector matrix vector) +(define-extern debug-set-camera-pos-rot! (function vector matrix vector)) ;; (define-extern cam-restore function) ;; (function none) ;; (define-extern cam-restore-generic-bug function) diff --git a/decompiler/config/jak3/ntsc_v1/hacks.jsonc b/decompiler/config/jak3/ntsc_v1/hacks.jsonc index 7eab5fdb1..bdb8a930e 100644 --- a/decompiler/config/jak3/ntsc_v1/hacks.jsonc +++ b/decompiler/config/jak3/ntsc_v1/hacks.jsonc @@ -90,9 +90,8 @@ "(method 16 ocean)", // unknown instructions - "debug-line-clip?", // logand with #f arg - "bugfix?", + // "bugfix?", // CFG failed "draw-inline-array-instance-shrub", @@ -273,7 +272,11 @@ "(method 9 curve-color-fast)": [0, 1], "evaluate-color-curve-fast": [0, 1], "(anon-function 0 target-death)": [71, 131, 132, 137], - "target-board-handler": [15, 16, 20] + "target-board-handler": [15, 16, 20], + "sprite-draw-distorters": [4, 5], + "(method 10 simple-sprite-system)": [0], + "add-debug-box-with-transform": [0, 3], + "add-debug-line-sphere": [0] }, // Sometimes the game might use format strings that are fetched dynamically, @@ -409,7 +412,8 @@ "generic-warp-dest", "generic-warp-envmap-dest", "generic-no-light-proc", - "(method 21 cloth-system)" + "(method 21 cloth-system)", + "debug-line-clip?" ], "mips2c_jump_table_functions": {}, diff --git a/decompiler/config/jak3/ntsc_v1/label_types.jsonc b/decompiler/config/jak3/ntsc_v1/label_types.jsonc index c6470d0b1..d47b6de95 100644 --- a/decompiler/config/jak3/ntsc_v1/label_types.jsonc +++ b/decompiler/config/jak3/ntsc_v1/label_types.jsonc @@ -275,5 +275,15 @@ ["L683", "uint64", true], ["L685", "uint64", true], ["L678", "uint64", true] + ], + "sprite-glow": [ + ["L29", "vu-function"], + ["L27", "dma-packet"] + ], + "debug": [ + ["L286", "(inline-array vector)", 3], + ["L287", "(inline-array vector)", 3], + ["L283", "(inline-array vector)", 32], + ["L265", "(inline-array vector)", 4] ] } diff --git a/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc b/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc index 7b1a1c5d4..d24cb7cd6 100644 --- a/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc +++ b/decompiler/config/jak3/ntsc_v1/stack_structures.jsonc @@ -250,5 +250,51 @@ ], "add-a-bunch": [[16, "vector"]], "birth-pickup-at-point": [[16, "vector"]], - "(code pickup eco)": [[16, "event-message-block"]] + "(code pickup eco)": [[16, "event-message-block"]], + "(method 10 simple-sprite-system)": [[16, ["array", "texture-id", 128]]], + "make-debug-sphere-table": [ + [16, "vector"], + [32, "vector"], + [48, "vector"], + [64, "vector"], + [80, "vector"], + [96, "vector"], + [112, "vector"] + ], + "add-debug-sphere-from-table": [ + [16, "vector"], + [48, "vector"], + [64, "vector"] + ], + "internal-draw-debug-line": [ + [16, "vector4w-2"], + [48, "vector4w-2"], + [80, "vector"], + [96, "vector"] + ], + "add-debug-box-with-transform": [ + [16, ["inline-array", "vector", 8]], + [144, ["inline-array", "vector", 2]], + [176, "vector"] + ], + "add-debug-line-sphere": [ + [48, "matrix"], + [112, "matrix"], + [128, "vector"], + [144, "vector"], + [160, "vector"], + [176, "vector"], + [208, "vector"], + [192, "vector"] + ], + "add-debug-arc": [ + [16, "vector"], + [32, "vector"] + ], + "add-debug-curve": [ + [16, "vector"], + [32, "vector"] + ], + "add-debug-points": [[16, "vector"]], + "add-debug-cursor": [[16, "vector"]] } diff --git a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc index b1ac74fda..adead7458 100644 --- a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc +++ b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc @@ -2082,5 +2082,79 @@ [[109, 116], "a0", "dma-packet"], [[127, 134], "a0", "dma-packet"], [[148, 155], "a0", "dma-packet"] + ], + "sprite-init-distorter": [ + [50, "a3", "uint"], + [[46, 59], "a1", "dma-packet"] + ], + "sprite-draw-distorters": [ + [[73, 98], "a0", "vector"], + ["_stack_", 32, "vector"], + ["_stack_", 48, "vector"], + [[174, 199], "a1", "dma-packet"], + [[206, 213], "a0", "dma-packet"], + [[215, 221], "a0", "vector4w"], + [[223, 231], "a0", "dma-packet"], + [[251, 276], "a1", "dma-packet"], + [[281, 288], "a1", "dma-packet"], + [[290, 296], "a1", "vector4w"], + [[297, 305], "v1", "dma-packet"] + ], + "sprite-glow-init-engine": [ + [[8, 22], "a0", "dma-packet"], + [[32, 50], "a1", "dma-packet"], + [[52, 74], "a1", "dma-packet"], + [[76, 84], "a0", "dma-packet"], + [[85, 92], "v1", "dma-packet"] + ], + "sprite-glow-add-sprite": [[[0, 33], "v1", "sprite-glow-cnt-template"]], + "sprite-glow-add-simple-sprite": [ + [[0, 33], "v1", "sprite-glow-ref-template"] + ], + "add-shader-to-dma": [[[6, 8], "v1", "(pointer uint32)"]], + "add-debug-sphere-from-table": [ + [[38, 41], "v1", "vector"], + [[55, 59], "s0", "(inline-array vector)"] + ], + "add-debug-point": [ + [[36, 43], "a3", "dma-packet"], + [[45, 52], "a3", "gs-gif-tag"], + [[65, 73], "a3", "vector4w-2"], + [[85, 93], "a3", "vector4w-2"], + [[102, 110], "a3", "vector4w-2"], + [[122, 130], "a1", "vector4w-2"], + [[129, 148], "a0", "(pointer uint64)"] + ], + "internal-draw-debug-line": [ + [[5, 224], "s5", "rgba"], + [[27, 29], "v1", "rgba"], + [[109, 115], "a3", "dma-packet"], + [[118, 124], "a3", "gs-gif-tag"], + [[232, 245], "a1", "(inline-array vector4w-2)"], + [[107, 267], "a0", "(pointer uint64)"] + ], + "add-debug-flat-triangle": [ + [[73, 80], "a3", "dma-packet"], + [[82, 89], "a3", "gs-gif-tag"], + [[111, 131], "a3", "(inline-array vector)"], + [[68, 149], "a0", "(pointer uint64)"] + ], + "add-debug-line2d": [ + [[61, 68], "a2", "dma-packet"], + [[70, 77], "a2", "gs-gif-tag"], + [[79, 85], "a2", "vector4w-2"], + [[87, 93], "a2", "vector4w-2"], + [[97, 111], "a0", "(pointer uint64)"] + ], + "drawable-frag-count": [[[14, 20], "s5", "drawable-group"]], + "add-boundary-shader": [ + [[6, 12], "a0", "gs-gif-tag"], + [[14, 31], "s5", "adgif-shader"] + ], + "add-debug-bound": [ + //[105, "v1", "dma-packet"], + //[85, "a0", "dma-packet"], + ["_stack_", 16, "dma-packet"], + [91, "v1", "dma-packet"] ] } diff --git a/decompiler/config/jak3/ntsc_v1/var_names.jsonc b/decompiler/config/jak3/ntsc_v1/var_names.jsonc index 629ae3e0c..b411023d5 100644 --- a/decompiler/config/jak3/ntsc_v1/var_names.jsonc +++ b/decompiler/config/jak3/ntsc_v1/var_names.jsonc @@ -1733,5 +1733,251 @@ "sv-56": "overhang-nrm", "sv-52": "tangent" } + }, + "transform-float-point": { + "args": [ + "src-world-pt", + "dst-gs-screen-pt" + ] + }, + "add-debug-point": { + "args": [ + "enable", + "bucket", + "pt" + ] + }, + "internal-draw-debug-line": { + "args": [ + "bucket", + "p0", + "p1", + "color", + "mode", + "color2" + ] + }, + "internal-draw-debug-text-3d": { + "args": [ + "bucket", + "text", + "pos", + "color", + "offset" + ] + }, + "add-debug-outline-triangle": { + "args": [ + "enable", + "bucket", + "p0", + "p1", + "p2", + "color" + ] + }, + "add-debug-triangle-normal": { + "args": [ + "enable", + "bucket", + "p0", + "p1", + "p2", + "color" + ] + }, + "add-debug-flat-triangle": { + "args": [ + "enable", + "bucket", + "p0", + "p1", + "p2", + "color" + ] + }, + "get-debug-text-3d": { + "args": [ + "enable", + "bucket", + "p0", + "p1", + "color", + "mode", + "color2" + ] + }, + "debug-reset-buffers": { + "args": [ + "enable", + "bucket", + "p0", + "p1", + "color" + ] + }, + "add-debug-line": { + "args": [ + "enable", + "bucket", + "p0", + "p1", + "color", + "mode", + "color2" + ] + }, + "add-debug-line2d": { + "args": [ + "enable", + "bucket", + "p0", + "p1", + "color" + ] + }, + "add-debug-box": { + "args": [ + "enable", + "bucket", + "p0", + "p1", + "color" + ] + }, + "add-debug-box-with-transform": { + "args": [ + "enable", + "bucket", + "box", + "mat", + "color" + ] + }, + "add-debug-x": { + "args": [ + "enable", + "bucket", + "pos", + "color" + ] + }, + "add-debug-cross": { + "args": [ + "enable", + "bucket", + "pos", + "len" + ] + }, + "add-debug-text-3d": { + "args": [ + "enable", + "bucket", + "text", + "pos", + "color", + "offset" + ] + }, + "add-debug-sphere-with-transform": { + "args": [ + "enable", + "bucket", + "pos", + "radius", + "mat", + "color" + ] + }, + "add-debug-sphere": { + "args": [ + "enable", + "bucket", + "pos", + "radius", + "color" + ] + }, + "add-debug-text-sphere": { + "args": [ + "enable", + "bucket", + "pos", + "radius", + "text", + "color" + ] + }, + "add-debug-spheres": { + "args": [ + "enable", + "bucket", + "spheres", + "count", + "color" + ] + }, + "add-debug-line-sphere": { + "args": [ + "enable", + "bucket", + "base", + "dir", + "rad", + "color" + ] + }, + "add-debug-circle": { + "args": [ + "enable", + "bucket", + "origin", + "radius", + "color", + "mat" + ] + }, + "add-debug-vector": { + "args": [ + "enable", + "bucket", + "base", + "dir", + "len-scale", + "color" + ] + }, + "add-debug-matrix": { + "args": [ + "enable", + "bucket", + "mat", + "len" + ] + }, + "add-debug-rot-matrix": { + "args": [ + "enable", + "bucket", + "mat", + "len", + "trans" + ] + }, + "add-debug-quaternion": { + "args": [ + "enable", + "bucket", + "trans", + "quat" + ] + }, + "add-debug-cspace": { + "args": [ + "enable", + "bucket", + "cs" + ] } } diff --git a/decompiler/util/data_decompile.cpp b/decompiler/util/data_decompile.cpp index 6140ebab8..54bab139b 100644 --- a/decompiler/util/data_decompile.cpp +++ b/decompiler/util/data_decompile.cpp @@ -988,6 +988,8 @@ const std::unordered_map< {{"init-specs", ArrayFieldDecompMeta(TypeSpec("sp-field-init-spec"), 16)}}}, {"sparticle-launch-group", {{"launcher", ArrayFieldDecompMeta(TypeSpec("sparticle-group-item"), 32)}}}, + {"simple-sprite-system", + {{"data", ArrayFieldDecompMeta(TypeSpec("sprite-glow-data"), 64)}}}, }}}; goos::Object decompile_structure(const TypeSpec& type, diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 675c53e4b..aed1459ff 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -185,7 +185,9 @@ set(RUNTIME_SOURCE mips2c/jak2_functions/texture.cpp mips2c/jak2_functions/vortex.cpp mips2c/jak3_functions/collide_func.cpp + mips2c/jak3_functions/debug.cpp mips2c/jak3_functions/lights.cpp + mips2c/jak3_functions/sky.cpp mips2c/mips2c_table.cpp overlord/common/dma.cpp overlord/common/fake_iso.cpp diff --git a/game/mips2c/jak3_functions/debug.cpp b/game/mips2c/jak3_functions/debug.cpp new file mode 100644 index 000000000..e1ffc1266 --- /dev/null +++ b/game/mips2c/jak3_functions/debug.cpp @@ -0,0 +1,597 @@ +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +#include "game/mips2c/jak3_functions/sky.h" + +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace debug_line_clip { +struct Cache { + void* math_camera; // *math-camera* +} cache; + +void qfsrv_same_mtsab_4(ExecutionContext* c, int reg) { + u32 temp[4]; + auto& val = c->gprs[reg]; + temp[0] = val.du32[1]; + temp[1] = val.du32[2]; + temp[2] = val.du32[3]; + temp[3] = val.du32[0]; + val.du32[0] = temp[0]; + val.du32[1] = temp[1]; + val.du32[2] = temp[2]; + val.du32[3] = temp[3]; +} + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + bool cop1_bc = false; + c->load_symbol2(v1, cache.math_camera); // lw v1, *math-camera*(s7) + c->lqc2(vf9, 0, a2); // lqc2 vf9, 0(a2) + c->lqc2(vf10, 0, a3); // lqc2 vf10, 0(a3) + c->lqc2(vf16, 940, v1); // lqc2 vf16, 940(v1) + c->lqc2(vf17, 956, v1); // lqc2 vf17, 956(v1) + c->lqc2(vf18, 972, v1); // lqc2 vf18, 972(v1) + c->lqc2(vf19, 988, v1); // lqc2 vf19, 988(v1) + c->vmula_bc(DEST::xyzw, BC::x, vf16, vf9); // vmulax.xyzw acc, vf16, vf9 + c->vmadda_bc(DEST::xyzw, BC::y, vf17, vf9); // vmadday.xyzw acc, vf17, vf9 + c->vmadda_bc(DEST::xyzw, BC::z, vf18, vf9); // vmaddaz.xyzw acc, vf18, vf9 + c->vmsub_bc(DEST::xyzw, BC::w, vf11, vf19, vf0); // vmsubw.xyzw vf11, vf19, vf0 + c->vmula_bc(DEST::xyzw, BC::x, vf16, vf10); // vmulax.xyzw acc, vf16, vf10 + c->vmadda_bc(DEST::xyzw, BC::y, vf17, vf10); // vmadday.xyzw acc, vf17, vf10 + c->vmadda_bc(DEST::xyzw, BC::z, vf18, vf10); // vmaddaz.xyzw acc, vf18, vf10 + c->vmsub_bc(DEST::xyzw, BC::w, vf12, vf19, vf0); // vmsubw.xyzw vf12, vf19, vf0 + c->mov128_gpr_vf(v1, vf11); // qmfc2.i v1, vf11 + c->pcgtw(v1, r0, v1); // pcgtw v1, r0, v1 + c->ppach(a2, r0, v1); // ppach a2, r0, v1 + c->mov128_gpr_vf(v1, vf12); // qmfc2.i v1, vf12 + c->pcgtw(v1, r0, v1); // pcgtw v1, r0, v1 + c->ppach(a3, r0, v1); // ppach a3, r0, v1 + c->and_(v1, a2, a3); // and v1, a2, a3 + bc = c->sgpr64(v1) != 0; // bne v1, r0, L253 + // nop // sll r0, r0, 0 + if (bc) {goto block_10;} // branch non-likely + + c->vmove(DEST::xyzw, vf13, vf9); // vmove.xyzw vf13, vf9 + c->vmove(DEST::xyzw, vf14, vf10); // vmove.xyzw vf14, vf10 + c->or_(a2, a2, a3); // or a2, a2, a3 + bc = c->sgpr64(a2) == 0; // beq a2, r0, L252 + // nop // sll r0, r0, 0 + if (bc) {goto block_9;} // branch non-likely + + c->mov128_gpr_vf(a2, vf11); // qmfc2.i a2, vf11 + c->mov128_gpr_vf(a3, vf12); // qmfc2.i a3, vf12 + c->mtc1(f0, r0); // mtc1 f0, r0 + c->mtc1(f1, r0); // mtc1 f1, r0 + c->lui(t0, 16256); // lui t0, 16256 + c->mtc1(f2, t0); // mtc1 f2, t0 + c->addiu(t0, r0, 3); // addiu t0, r0, 3 + // Unknown instr: mtsab r0, 4 + +block_3: + c->mtc1(f3, a2); // mtc1 f3, a2 + c->mtc1(f4, a3); // mtc1 f4, a3 + c->subs(f5, f3, f4); // sub.s f5, f3, f4 + cop1_bc = c->fprs[f3] < c->fprs[f0]; // c.lt.s f3, f0 + bc = !cop1_bc; // bc1f L250 + // nop // sll r0, r0, 0 + if (bc) {goto block_5;} // branch non-likely + + c->divs(f6, f3, f5); // div.s f6, f3, f5 + c->maxs(f1, f6, f1); // max.s f1, f6, f1 + +block_5: + cop1_bc = c->fprs[f4] < c->fprs[f0]; // c.lt.s f4, f0 + bc = !cop1_bc; // bc1f L251 + // nop // sll r0, r0, 0 + if (bc) {goto block_7;} // branch non-likely + + c->divs(f3, f3, f5); // div.s f3, f3, f5 + c->mins(f2, f3, f2); // min.s f2, f3, f2 + +block_7: + // Unknown instr: qfsrv a2, a2, a2 + qfsrv_same_mtsab_4(c, a2); + // Unknown instr: qfsrv a3, a3, a3 + qfsrv_same_mtsab_4(c, a3); + bc = c->sgpr64(t0) != 0; // bne t0, r0, L249 + c->daddiu(t0, t0, -1); // daddiu t0, t0, -1 + if (bc) {goto block_3;} // branch non-likely + + c->mfc1(a2, f1); // mfc1 a2, f1 + c->mfc1(a3, f2); // mfc1 a3, f2 + c->mov128_vf_gpr(vf20, a2); // qmtc2.i vf20, a2 + c->mov128_vf_gpr(vf21, a3); // qmtc2.i vf21, a3 + c->vsub(DEST::xyzw, vf15, vf10, vf9); // vsub.xyzw vf15, vf10, vf9 + c->vmul_bc(DEST::xyzw, BC::x, vf13, vf15, vf20); // vmulx.xyzw vf13, vf15, vf20 + c->vadd(DEST::xyzw, vf13, vf9, vf13); // vadd.xyzw vf13, vf9, vf13 + c->vmul_bc(DEST::xyzw, BC::x, vf14, vf15, vf21); // vmulx.xyzw vf14, vf15, vf21 + c->vadd(DEST::xyzw, vf14, vf9, vf14); // vadd.xyzw vf14, vf9, vf14 + +block_9: + c->sqc2(vf13, 0, a0); // sqc2 vf13, 0(a0) + c->sqc2(vf14, 0, a1); // sqc2 vf14, 0(a1) + +block_10: + c->daddiu(v0, s7, 4); // daddiu v0, s7, 4 + c->movn(v0, s7, v1); // movn v0, s7, v1 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.math_camera = intern_from_c(-1, 0, "*math-camera*").c(); + gLinkedFunctionTable.reg("debug-line-clip?", execute, 32); +} + +} // namespace debug_line_clip +} // namespace Mips2C + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace init_boundary_regs { +struct Cache { + void* math_camera; // *math-camera* + void* sky_work; // *sky-work* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->load_symbol2(v1, cache.math_camera); // lw v1, *math-camera*(s7) + c->load_symbol2(a0, cache.sky_work); // lw a0, *sky-work*(s7) + c->daddiu(a0, a0, 1088); // daddiu a0, a0, 1088 + c->lwc1(f0, 908, v1); // lwc1 f0, 908(v1) + c->swc1(f0, 0, a0); // swc1 f0, 0(a0) + c->lwc1(f0, 128, v1); // lwc1 f0, 128(v1) + c->swc1(f0, 4, a0); // swc1 f0, 4(a0) + c->lwc1(f0, 124, v1); // lwc1 f0, 124(v1) + c->swc1(f0, 8, a0); // swc1 f0, 8(a0) + c->lui(a1, 17727); // lui a1, 17727 + c->ori(a1, a1, 61440); // ori a1, a1, 61440 + c->mtc1(f0, a1); // mtc1 f0, a1 + c->swc1(f0, 12, a0); // swc1 f0, 12(a0) + c->lqc2(vf31, 572, v1); // lqc2 vf31, 572(v1) + c->lqc2(vf30, 588, v1); // lqc2 vf30, 588(v1) + c->lqc2(vf29, 604, v1); // lqc2 vf29, 604(v1) + c->lqc2(vf28, 620, v1); // lqc2 vf28, 620(v1) + c->lqc2(vf14, 780, v1); // lqc2 vf14, 780(v1) + c->lqc2(vf26, 796, v1); // lqc2 vf26, 796(v1) + c->lqc2(vf25, 812, v1); // lqc2 vf25, 812(v1) + c->load_symbol2(v1, cache.sky_work); // lw v1, *sky-work*(s7) + c->lqc2(vf13, 1088, v1); // lqc2 vf13, 1088(v1) + c->vmul(DEST::xyzw, vf31, vf31, vf14); // vmul.xyzw vf31, vf31, vf14 + c->vmul(DEST::xyzw, vf30, vf30, vf14); // vmul.xyzw vf30, vf30, vf14 + c->vmul(DEST::xyzw, vf29, vf29, vf14); // vmul.xyzw vf29, vf29, vf14 + c->vmul(DEST::xyzw, vf28, vf28, vf14); // vmul.xyzw vf28, vf28, vf14 + c->vmove(DEST::xyzw, vf24, vf0); // vmove.xyzw vf24, vf0 + c->mov128_gpr_vf(v1, vf24); // qmfc2.i v1, vf24 + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + sky_regs_vfs.copy_vfs_from_other(c); + return c->gprs[v0].du64[0]; +} + +void link() { + cache.math_camera = intern_from_c(-1, 0, "*math-camera*").c(); + cache.sky_work = intern_from_c(-1, 0, "*sky-work*").c(); + gLinkedFunctionTable.reg("init-boundary-regs", execute, 128); +} + +} // namespace init_boundary_regs +} // namespace Mips2C + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace draw_boundary_polygon { +struct Cache { + void* clip_polygon_against_negative_hyperplane; // clip-polygon-against-negative-hyperplane + void* clip_polygon_against_positive_hyperplane; // clip-polygon-against-positive-hyperplane +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + // nop // sll r0, r0, 0 + c->daddiu(sp, sp, -8); // daddiu sp, sp, -8 + // nop // sll r0, r0, 0 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->load_symbol2(t9, cache.clip_polygon_against_positive_hyperplane);// lw t9, clip-polygon-against-positive-hyperplane(s7) + c->mov64(a2, t4); // or a2, t4, r0 + c->mov64(a3, t5); // or a3, t5, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->daddu(t2, a2, r0); // daddu t2, a2, r0 + // c->jalr(call_addr); // jalr ra, t9 + clip_polygon_against_positive_hyperplane::execute(ctxt); + bc = c->sgpr64(t0) == 0; // beq t0, r0, L36 + // nop // sll r0, r0, 0 + if (bc) {goto block_7;} // branch non-likely + + c->mov64(a2, t5); // or a2, t5, r0 + c->mov64(a3, t4); // or a3, t4, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->daddiu(t2, a2, 4); // daddiu t2, a2, 4 + // c->jalr(call_addr); // jalr ra, t9 + clip_polygon_against_positive_hyperplane::execute(ctxt); + bc = c->sgpr64(t0) == 0; // beq t0, r0, L36 + c->load_symbol2(t9, cache.clip_polygon_against_negative_hyperplane);// lw t9, clip-polygon-against-negative-hyperplane(s7) + if (bc) {goto block_7;} // branch non-likely + + c->mov64(a2, t4); // or a2, t4, r0 + c->mov64(a3, t5); // or a3, t5, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->daddu(t2, a2, r0); // daddu t2, a2, r0 + // c->jalr(call_addr); // jalr ra, t9 + clip_polygon_against_negative_hyperplane::execute(ctxt); + bc = c->sgpr64(t0) == 0; // beq t0, r0, L36 + // nop // sll r0, r0, 0 + if (bc) {goto block_7;} // branch non-likely + + c->mov64(a2, t5); // or a2, t5, r0 + c->mov64(a3, t4); // or a3, t4, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->daddiu(t2, a2, 4); // daddiu t2, a2, 4 + // c->jalr(call_addr); // jalr ra, t9 + clip_polygon_against_negative_hyperplane::execute(ctxt); + bc = c->sgpr64(t0) == 0; // beq t0, r0, L36 + c->lw(a3, 4, a1); // lw a3, 4(a1) + if (bc) {goto block_7;} // branch non-likely + + c->mov64(a2, t4); // or a2, t4, r0 + // nop // sll r0, r0, 0 + c->sqc2(vf27, 0, a3); // sqc2 vf27, 0(a3) + c->daddiu(a3, a3, 16); // daddiu a3, a3, 16 + c->sw(t0, -16, a3); // sw t0, -16(a3) + // nop // sll r0, r0, 0 + +block_5: + c->lqc2(vf1, 0, a2); // lqc2 vf1, 0(a2) + // nop // sll r0, r0, 0 + c->lqc2(vf2, 16, a2); // lqc2 vf2, 16(a2) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 32, a2); // lqc2 vf3, 32(a2) + c->vdiv(vf0, BC::w, vf1, BC::w); // vdiv Q, vf0.w, vf1.w + c->vmul(DEST::xyzw, vf1, vf1, vf26); // vmul.xyzw vf1, vf1, vf26 + // nop // sll r0, r0, 0 + c->vftoi0(DEST::xyzw, vf3, vf3); // vftoi0.xyzw vf3, vf3 + // nop // sll r0, r0, 0 + c->vadd(DEST::xyzw, vf2, vf2, vf24); // vadd.xyzw vf2, vf2, vf24 + // nop // sll r0, r0, 0 + c->vwaitq(); // vwaitq + // nop // sll r0, r0, 0 + c->vmulq(DEST::xyz, vf1, vf1); // vmulq.xyz vf1, vf1, Q + c->sqc2(vf3, 16, a3); // sqc2 vf3, 16(a3) + c->vmulq(DEST::xyzw, vf2, vf2); // vmulq.xyzw vf2, vf2, Q + c->daddiu(a2, a2, 48); // daddiu a2, a2, 48 + c->vadd(DEST::xyzw, vf1, vf1, vf25); // vadd.xyzw vf1, vf1, vf25 + c->daddiu(a3, a3, 48); // daddiu a3, a3, 48 + c->vmax_bc(DEST::z, BC::z, vf1, vf1, vf0); // vmaxz.z vf1, vf1, vf0 + // nop // sll r0, r0, 0 + c->vmini_bc(DEST::w, BC::z, vf1, vf1, vf13); // vminiz.w vf1, vf1, vf13 + // nop // sll r0, r0, 0 + c->vmax_bc(DEST::w, BC::y, vf1, vf1, vf13); // vmaxy.w vf1, vf1, vf13 + // nop // sll r0, r0, 0 + c->sqc2(vf2, -48, a3); // sqc2 vf2, -48(a3) + c->daddiu(t0, t0, -1); // daddiu t0, t0, -1 + c->vftoi4(DEST::xyzw, vf1, vf1); // vftoi4.xyzw vf1, vf1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t0) != 0; // bne t0, r0, L35 + c->sqc2(vf1, -16, a3); // sqc2 vf1, -16(a3) + if (bc) {goto block_5;} // branch non-likely + + c->sw(a3, 4, a1); // sw a3, 4(a1) + // nop // sll r0, r0, 0 + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->daddiu(v0, s7, 4); // daddiu v0, s7, 4 + //jr ra // jr ra + c->daddiu(sp, sp, 8); // daddiu sp, sp, 8 + goto end_of_function; // return + + +block_7: + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->mov64(v0, s7); // or v0, s7, r0 + //jr ra // jr ra + c->daddiu(sp, sp, 8); // daddiu sp, sp, 8 + goto end_of_function; // return + + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.clip_polygon_against_negative_hyperplane = intern_from_c(-1, 0, "clip-polygon-against-negative-hyperplane").c(); + cache.clip_polygon_against_positive_hyperplane = intern_from_c(-1, 0, "clip-polygon-against-positive-hyperplane").c(); + gLinkedFunctionTable.reg("draw-boundary-polygon", execute, 1024); +} + +} // namespace draw_boundary_polygon +} // namespace Mips2C + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace render_boundary_quad { +struct Cache { + void* fake_scratchpad_data; // *fake-scratchpad-data* + void* math_camera; // *math-camera* + void* draw_boundary_polygon; // draw-boundary-polygon +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + c->copy_vfs_from_other(&sky_regs_vfs); + bool bc = false; + u32 call_addr = 0; + c->mov64(v1, a0); // or v1, a0, r0 + c->load_symbol2(v1, cache.math_camera); // lw v1, *math-camera*(s7) + c->lqc2(vf14, 780, v1); // lqc2 vf14, 780(v1) + get_fake_spad_addr2(t4, cache.fake_scratchpad_data, 0, c);// lui t4, 28672 + c->ori(t4, t4, 12288); // ori t4, t4, 12288 + get_fake_spad_addr2(t5, cache.fake_scratchpad_data, 0, c);// lui t5, 28672 + c->ori(t5, t5, 14336); // ori t5, t5, 14336 + c->mov64(a3, t4); // or a3, t4, r0 + // nop // sll r0, r0, 0 + c->lqc2(vf1, 0, a0); // lqc2 vf1, 0(a0) + c->addiu(t0, r0, 4); // addiu t0, r0, 4 + c->lqc2(vf2, 16, a0); // lqc2 vf2, 16(a0) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 32, a0); // lqc2 vf3, 32(a0) + c->vmula_bc(DEST::xyzw, BC::x, vf31, vf1); // vmulax.xyzw acc, vf31, vf1 + c->lqc2(vf4, 48, a0); // lqc2 vf4, 48(a0) + c->vmadda_bc(DEST::xyzw, BC::y, vf30, vf1); // vmadday.xyzw acc, vf30, vf1 + c->lqc2(vf5, 64, a0); // lqc2 vf5, 64(a0) + c->vmadda_bc(DEST::xyzw, BC::z, vf29, vf1); // vmaddaz.xyzw acc, vf29, vf1 + c->lqc2(vf6, 80, a0); // lqc2 vf6, 80(a0) + c->vmadd_bc(DEST::xyzw, BC::w, vf1, vf28, vf1); // vmaddw.xyzw vf1, vf28, vf1 + c->lqc2(vf7, 96, a0); // lqc2 vf7, 96(a0) + // nop // sll r0, r0, 0 + c->lqc2(vf8, 112, a0); // lqc2 vf8, 112(a0) + c->vmula_bc(DEST::xyzw, BC::x, vf31, vf4); // vmulax.xyzw acc, vf31, vf4 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf30, vf4); // vmadday.xyzw acc, vf30, vf4 + c->lqc2(vf10, 144, a0); // lqc2 vf10, 144(a0) + c->vmadda_bc(DEST::xyzw, BC::z, vf29, vf4); // vmaddaz.xyzw acc, vf29, vf4 + c->lqc2(vf11, 160, a0); // lqc2 vf11, 160(a0) + c->vmadd_bc(DEST::xyzw, BC::w, vf4, vf28, vf4); // vmaddw.xyzw vf4, vf28, vf4 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sqc2(vf2, 16, a3); // sqc2 vf2, 16(a3) + c->vmula_bc(DEST::xyzw, BC::x, vf31, vf7); // vmulax.xyzw acc, vf31, vf7 + c->sqc2(vf3, 32, a3); // sqc2 vf3, 32(a3) + c->vmadda_bc(DEST::xyzw, BC::y, vf30, vf7); // vmadday.xyzw acc, vf30, vf7 + c->sqc2(vf5, 64, a3); // sqc2 vf5, 64(a3) + c->vmadda_bc(DEST::xyzw, BC::z, vf29, vf7); // vmaddaz.xyzw acc, vf29, vf7 + c->sqc2(vf3, 80, a3); // sqc2 vf3, 80(a3) + c->vmadd_bc(DEST::xyzw, BC::w, vf7, vf28, vf7); // vmaddw.xyzw vf7, vf28, vf7 + c->sqc2(vf8, 112, a3); // sqc2 vf8, 112(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf3, 128, a3); // sqc2 vf3, 128(a3) + c->vmula_bc(DEST::xyzw, BC::x, vf31, vf10); // vmulax.xyzw acc, vf31, vf10 + c->sqc2(vf11, 160, a3); // sqc2 vf11, 160(a3) + c->vmadda_bc(DEST::xyzw, BC::y, vf30, vf10); // vmadday.xyzw acc, vf30, vf10 + c->sqc2(vf3, 176, a3); // sqc2 vf3, 176(a3) + c->vmadda_bc(DEST::xyzw, BC::z, vf29, vf10); // vmaddaz.xyzw acc, vf29, vf10 + c->sqc2(vf2, 208, a3); // sqc2 vf2, 208(a3) + c->vmadd_bc(DEST::xyzw, BC::w, vf10, vf28, vf10); // vmaddw.xyzw vf10, vf28, vf10 + c->sqc2(vf3, 224, a3); // sqc2 vf3, 224(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf1, 0, a3); // sqc2 vf1, 0(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf1, 192, a3); // sqc2 vf1, 192(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf4, 48, a3); // sqc2 vf4, 48(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf7, 96, a3); // sqc2 vf7, 96(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf10, 144, a3); // sqc2 vf10, 144(a3) + c->load_symbol2(t9, cache.draw_boundary_polygon); // lw t9, draw-boundary-polygon(s7) + c->vsub(DEST::xyzw, vf4, vf4, vf1); // vsub.xyzw vf4, vf4, vf1 + // nop // sll r0, r0, 0 + c->vsub(DEST::xyzw, vf7, vf7, vf1); // vsub.xyzw vf7, vf7, vf1 + // nop // sll r0, r0, 0 + c->vopmula(vf4, vf7); // vopmula.xyz acc, vf4, vf7 + // nop // sll r0, r0, 0 + c->vopmsub(vf10, vf7, vf4); // vopmsub.xyz vf10, vf7, vf4 + // nop // sll r0, r0, 0 + c->vmul(DEST::xyzw, vf10, vf10, vf1); // vmul.xyzw vf10, vf10, vf1 + // nop // sll r0, r0, 0 + c->vadd_bc(DEST::y, BC::x, vf10, vf10, vf10); // vaddx.y vf10, vf10, vf10 + // nop // sll r0, r0, 0 + c->vadd_bc(DEST::y, BC::z, vf10, vf10, vf10); // vaddz.y vf10, vf10, vf10 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(v0, vf10); // qmfc2.i v0, vf10 + // nop // sll r0, r0, 0 + bc = ((s64)c->sgpr64(v0)) >= 0; // bgez v0, L33 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + // Unknown instr: jr t9 + draw_boundary_polygon::execute(ctxt); + // nop // sll r0, r0, 0 + +block_2: + c->sqc2(vf6, 32, a3); // sqc2 vf6, 32(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf6, 80, a3); // sqc2 vf6, 80(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf6, 128, a3); // sqc2 vf6, 128(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf6, 176, a3); // sqc2 vf6, 176(a3) + // nop // sll r0, r0, 0 + // Unknown instr: jr t9 + draw_boundary_polygon::execute(ctxt); + // nop // sll r0, r0, 0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.fake_scratchpad_data = intern_from_c(-1, 0, "*fake-scratchpad-data*").c(); + cache.math_camera = intern_from_c(-1, 0, "*math-camera*").c(); + cache.draw_boundary_polygon = intern_from_c(-1, 0, "draw-boundary-polygon").c(); + gLinkedFunctionTable.reg("render-boundary-quad", execute, 32); +} + +} // namespace render_boundary_quad +} // namespace Mips2C +// add render_boundary_quad::link to the link callback table for the object file. +// FWD DEC: + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace render_boundary_tri { +struct Cache { + void* fake_scratchpad_data; // *fake-scratchpad-data* + void* draw_boundary_polygon; // draw-boundary-polygon +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + c->copy_vfs_from_other(&sky_regs_vfs); + bool bc = false; + u32 call_addr = 0; + c->mov64(v1, a0); // or v1, a0, r0 + get_fake_spad_addr2(t4, cache.fake_scratchpad_data, 0, c);// lui t4, 28672 + c->ori(t4, t4, 12288); // ori t4, t4, 12288 + get_fake_spad_addr2(t5, cache.fake_scratchpad_data, 0, c);// lui t5, 28672 + c->ori(t5, t5, 14336); // ori t5, t5, 14336 + c->mov64(a3, t4); // or a3, t4, r0 + // nop // sll r0, r0, 0 + c->lqc2(vf1, 0, a0); // lqc2 vf1, 0(a0) + c->addiu(t0, r0, 3); // addiu t0, r0, 3 + c->lqc2(vf2, 16, a0); // lqc2 vf2, 16(a0) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 32, a0); // lqc2 vf3, 32(a0) + c->vmula_bc(DEST::xyzw, BC::x, vf31, vf1); // vmulax.xyzw acc, vf31, vf1 + c->lqc2(vf4, 48, a0); // lqc2 vf4, 48(a0) + c->vmadda_bc(DEST::xyzw, BC::y, vf30, vf1); // vmadday.xyzw acc, vf30, vf1 + c->lqc2(vf5, 64, a0); // lqc2 vf5, 64(a0) + c->vmadda_bc(DEST::xyzw, BC::z, vf29, vf1); // vmaddaz.xyzw acc, vf29, vf1 + c->lqc2(vf6, 80, a0); // lqc2 vf6, 80(a0) + c->vmadd_bc(DEST::xyzw, BC::w, vf1, vf28, vf1); // vmaddw.xyzw vf1, vf28, vf1 + c->lqc2(vf7, 96, a0); // lqc2 vf7, 96(a0) + // nop // sll r0, r0, 0 + c->lqc2(vf8, 112, a0); // lqc2 vf8, 112(a0) + c->vmula_bc(DEST::xyzw, BC::x, vf31, vf4); // vmulax.xyzw acc, vf31, vf4 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf30, vf4); // vmadday.xyzw acc, vf30, vf4 + c->sqc2(vf2, 16, a3); // sqc2 vf2, 16(a3) + c->vmadda_bc(DEST::xyzw, BC::z, vf29, vf4); // vmaddaz.xyzw acc, vf29, vf4 + c->sqc2(vf3, 32, a3); // sqc2 vf3, 32(a3) + c->vmadd_bc(DEST::xyzw, BC::w, vf4, vf28, vf4); // vmaddw.xyzw vf4, vf28, vf4 + c->sqc2(vf5, 64, a3); // sqc2 vf5, 64(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf3, 80, a3); // sqc2 vf3, 80(a3) + c->vmula_bc(DEST::xyzw, BC::x, vf31, vf7); // vmulax.xyzw acc, vf31, vf7 + c->sqc2(vf8, 112, a3); // sqc2 vf8, 112(a3) + c->vmadda_bc(DEST::xyzw, BC::y, vf30, vf7); // vmadday.xyzw acc, vf30, vf7 + c->sqc2(vf3, 128, a3); // sqc2 vf3, 128(a3) + c->vmadda_bc(DEST::xyzw, BC::z, vf29, vf7); // vmaddaz.xyzw acc, vf29, vf7 + c->sqc2(vf2, 160, a3); // sqc2 vf2, 160(a3) + c->vmadd_bc(DEST::xyzw, BC::w, vf7, vf28, vf7); // vmaddw.xyzw vf7, vf28, vf7 + c->sqc2(vf3, 176, a3); // sqc2 vf3, 176(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf1, 0, a3); // sqc2 vf1, 0(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf1, 144, a3); // sqc2 vf1, 144(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf4, 48, a3); // sqc2 vf4, 48(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf7, 96, a3); // sqc2 vf7, 96(a3) + c->load_symbol2(t9, cache.draw_boundary_polygon); // lw t9, draw-boundary-polygon(s7) + c->vsub(DEST::xyzw, vf4, vf4, vf1); // vsub.xyzw vf4, vf4, vf1 + // nop // sll r0, r0, 0 + c->vsub(DEST::xyzw, vf7, vf7, vf1); // vsub.xyzw vf7, vf7, vf1 + // nop // sll r0, r0, 0 + c->vopmula(vf4, vf7); // vopmula.xyz acc, vf4, vf7 + // nop // sll r0, r0, 0 + c->vopmsub(vf10, vf7, vf4); // vopmsub.xyz vf10, vf7, vf4 + // nop // sll r0, r0, 0 + c->vmul(DEST::xyzw, vf10, vf10, vf1); // vmul.xyzw vf10, vf10, vf1 + // nop // sll r0, r0, 0 + c->vadd_bc(DEST::y, BC::x, vf10, vf10, vf10); // vaddx.y vf10, vf10, vf10 + // nop // sll r0, r0, 0 + c->vadd_bc(DEST::y, BC::z, vf10, vf10, vf10); // vaddz.y vf10, vf10, vf10 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(v0, vf10); // qmfc2.i v0, vf10 + // nop // sll r0, r0, 0 + bc = ((s64)c->sgpr64(v0)) >= 0; // bgez v0, L31 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + // Unknown instr: jr t9 + // nop // sll r0, r0, 0 + +block_2: + c->sqc2(vf6, 32, a3); // sqc2 vf6, 32(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf6, 80, a3); // sqc2 vf6, 80(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf6, 128, a3); // sqc2 vf6, 128(a3) + // nop // sll r0, r0, 0 + c->sqc2(vf6, 176, a3); // sqc2 vf6, 176(a3) + // nop // sll r0, r0, 0 + // Unknown instr: jr t9 + // nop // sll r0, r0, 0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.fake_scratchpad_data = intern_from_c(-1, 0, "*fake-scratchpad-data*").c(); + cache.draw_boundary_polygon = intern_from_c(-1, 0, "draw-boundary-polygon").c(); + gLinkedFunctionTable.reg("render-boundary-tri", execute, 32); +} + +} // namespace render_boundary_tri +} // namespace Mips2C \ No newline at end of file diff --git a/game/mips2c/jak3_functions/sky.cpp b/game/mips2c/jak3_functions/sky.cpp new file mode 100644 index 000000000..b32f32d3b --- /dev/null +++ b/game/mips2c/jak3_functions/sky.cpp @@ -0,0 +1,54 @@ + +#include "sky.h" + +#include "game/kernel/jak3/kscheme.h" +#include "game/mips2c/mips2c_private.h" + +namespace Mips2C::jak3 { + +ExecutionContext sky_regs_vfs; + +namespace set_sky_vf27 { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + // sky_regs_vfs.vfs[27] + memcpy(&sky_regs_vfs.vfs[27].f[0], g_ee_main_mem + c->gpr_addr(a0), 16); + return 0; +} + +void link() { + gLinkedFunctionTable.reg("set-sky-vf27", execute, 64); +} + +} // namespace set_sky_vf27 +} // namespace Mips2C::jak3 + +namespace Mips2C::jak3 { +namespace set_sky_vf23_value { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + // sky_regs_vfs.vfs[27] + u64 value = c->sgpr64(a0); + memcpy(&sky_regs_vfs.vfs[23].f[0], &value, 8); + return 0; +} + +void link() { + gLinkedFunctionTable.reg("set-sky-vf23-value", execute, 64); +} + +} // namespace set_sky_vf23_value +} // namespace Mips2C::jak3 + +namespace Mips2C::jak3 { +namespace clip_polygon_against_positive_hyperplane { +u64 execute(void*) { + ASSERT_NOT_REACHED(); +} +} // namespace clip_polygon_against_positive_hyperplane +namespace clip_polygon_against_negative_hyperplane { +u64 execute(void*) { + ASSERT_NOT_REACHED(); +} +} // namespace clip_polygon_against_negative_hyperplane +} // namespace Mips2C::jak3 \ No newline at end of file diff --git a/game/mips2c/jak3_functions/sky.h b/game/mips2c/jak3_functions/sky.h new file mode 100644 index 000000000..b4419ee44 --- /dev/null +++ b/game/mips2c/jak3_functions/sky.h @@ -0,0 +1,14 @@ +#pragma once +#include "game/mips2c/mips2c_private.h" + +namespace Mips2C::jak3 { +extern ExecutionContext sky_regs_vfs; + +namespace clip_polygon_against_positive_hyperplane { +extern u64 execute(void* ctxt); +} + +namespace clip_polygon_against_negative_hyperplane { +extern u64 execute(void* ctxt); +} +} // namespace Mips2C::jak3 \ No newline at end of file diff --git a/game/mips2c/mips2c_table.cpp b/game/mips2c/mips2c_table.cpp index 83bd9b07f..1f6dd9002 100644 --- a/game/mips2c/mips2c_table.cpp +++ b/game/mips2c/mips2c_table.cpp @@ -262,7 +262,12 @@ namespace jak3 { namespace add_light_sphere_to_light_group { extern void link(); } namespace light_hash_count_items { extern void link(); } namespace light_hash_add_items { extern void link(); } - + namespace debug_line_clip { extern void link(); } + namespace init_boundary_regs { extern void link(); } + namespace draw_boundary_polygon { extern void link(); } + namespace render_boundary_quad { extern void link(); } + namespace render_boundary_tri { extern void link(); } + namespace set_sky_vf27 { extern void link(); } } // clang-format on @@ -434,7 +439,11 @@ PerGameVersion>> gMips2C /////////// JAK 3 {{"lights", {jak3::light_hash_get_bucket_index::link, jak3::add_light_sphere_to_light_group::link, - jak3::light_hash_count_items::link, jak3::light_hash_add_items::link}}}}; + jak3::light_hash_count_items::link, jak3::light_hash_add_items::link}}, + {"debug", + {jak3::debug_line_clip::link, jak3::init_boundary_regs::link, + jak3::draw_boundary_polygon::link, jak3::render_boundary_quad::link, + jak3::render_boundary_tri::link, jak3::set_sky_vf27::link}}}}; void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 stack_size) { const auto& it = m_executes.insert({name, {exec, Ptr()}}); diff --git a/goal_src/jak3/engine/camera/cam-debug-h.gc b/goal_src/jak3/engine/camera/cam-debug-h.gc index 12beacc05..06aed3a01 100644 --- a/goal_src/jak3/engine/camera/cam-debug-h.gc +++ b/goal_src/jak3/engine/camera/cam-debug-h.gc @@ -5,6 +5,8 @@ ;; name in dgo: cam-debug-h ;; dgos: GAME +(define-extern debug-set-camera-pos-rot! (function vector matrix vector)) + ;; DECOMP BEGINS ;; this file is debug only diff --git a/goal_src/jak3/engine/debug/debug-sphere.gc b/goal_src/jak3/engine/debug/debug-sphere.gc index 2a7fe8734..deaefee0f 100644 --- a/goal_src/jak3/engine/debug/debug-sphere.gc +++ b/goal_src/jak3/engine/debug/debug-sphere.gc @@ -7,3 +7,92 @@ ;; DECOMP BEGINS +(defun make-debug-sphere-table ((arg0 vector-array) (arg1 float) (arg2 float)) + "Create a table of lines on a sphere." + (local-vars (sv-80 vector) (sv-96 vector) (sv-112 int)) + (let ((s2-0 (new-stack-vector0)) + (f30-0 1.0) + (s5-0 0) + ) + (set-vector! s2-0 0.0 0.0 0.0 1.0) + (dotimes (s1-0 (the int arg2)) + (let ((f28-0 (* f30-0 (sin (* (the float s1-0) (/ 32768.0 arg2))))) + (f26-0 (* f30-0 (sin (* (the float (+ s1-0 1)) (/ 32768.0 arg2))))) + (s0-0 (new-stack-vector0)) + ) + (set! sv-80 (new 'stack-no-clear 'vector)) + (set! (-> sv-80 quad) (the-as uint128 0)) + (set! sv-96 (new 'stack-no-clear 'vector)) + (set! (-> sv-96 quad) (the-as uint128 0)) + (set! (-> s0-0 y) (+ (-> s2-0 y) (* (cos (* (the float s1-0) (/ 32768.0 arg2))) f30-0))) + (set! (-> sv-80 y) (-> s0-0 y)) + (set! (-> sv-96 y) (+ (-> s2-0 y) (* (cos (* (the float (+ s1-0 1)) (/ 32768.0 arg2))) f30-0))) + (set! sv-112 0) + (while (< sv-112 (the int arg1)) + (set! (-> s0-0 x) (+ (-> s2-0 x) (* (cos (* (the float sv-112) (/ 65536.0 arg1))) f28-0))) + (set! (-> s0-0 z) (+ (-> s2-0 z) (* (sin (* (the float sv-112) (/ 65536.0 arg1))) f28-0))) + (set! (-> sv-80 x) (+ (-> s2-0 x) (* (cos (* (the float (+ sv-112 1)) (/ 65536.0 arg1))) f28-0))) + (set! (-> sv-80 z) (+ (-> s2-0 z) (* (sin (* (the float (+ sv-112 1)) (/ 65536.0 arg1))) f28-0))) + (set! (-> sv-96 x) (+ (-> s2-0 x) (* (cos (* (the float sv-112) (/ 65536.0 arg1))) f26-0))) + (set! (-> sv-96 z) (+ (-> s2-0 z) (* (sin (* (the float sv-112) (/ 65536.0 arg1))) f26-0))) + (set! (-> arg0 data s5-0 quad) (-> s0-0 quad)) + (set! (-> arg0 data (+ s5-0 1) quad) (-> sv-80 quad)) + (set! (-> arg0 data (+ s5-0 2) quad) (-> sv-96 quad)) + (+! s5-0 3) + (set! sv-112 (+ sv-112 1)) + ) + ) + ) + (set! (-> arg0 length) s5-0) + ) + arg0 + ) + +(when *debug-segment* +(define *debug-sphere-table* (new 'debug 'boxed-array vector-array 10)) + +) +(defun add-debug-sphere-from-table ((arg0 bucket-id) (arg1 vector) (arg2 meters) (arg3 rgba) (arg4 int)) + "Draw a sphere out of debug lines, using the precomputed table of lines." + (local-vars (sv-32 vector-array) (sv-36 vector)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (if (zero? (-> *debug-sphere-table* arg4)) + (set! (-> *debug-sphere-table* arg4) + (make-debug-sphere-table (new 'debug 'vector-array (* (* 3 arg4) arg4)) (the float arg4) (the float arg4)) + ) + ) + (set! sv-32 (-> *debug-sphere-table* arg4)) + (set! sv-36 (the-as vector (new-stack-vector0))) + (let ((s2-1 (new-stack-vector0)) + (s1-1 (new-stack-vector0)) + (s0-0 (the-as object (-> sv-32 data))) + ) + (.lvf vf1 (&-> arg1 quad)) + (.mov vf2 arg2) + (countdown (s4-1 (/ (-> sv-32 length) 3)) + (.lvf vf3 (&-> (the-as (inline-array vector) s0-0) 0 quad)) + (.lvf vf4 (&-> (the-as (inline-array vector) s0-0) 1 quad)) + (.lvf vf5 (&-> (the-as (inline-array vector) s0-0) 2 quad)) + (set! s0-0 (-> (the-as (inline-array vector) s0-0) 3)) + (.mul.x.vf vf3 vf3 vf2) + (.mul.x.vf vf4 vf4 vf2) + (.mul.x.vf vf5 vf5 vf2) + (.add.vf vf3 vf3 vf1) + (.add.vf vf4 vf4 vf1) + (.add.vf vf5 vf5 vf1) + (.svf (&-> s2-1 quad) vf3) + (.svf (&-> s1-1 quad) vf4) + (.svf (&-> sv-36 quad) vf5) + (add-debug-line #t arg0 s2-1 s1-1 arg3 #f (the-as rgba -1)) + (add-debug-line #t arg0 s2-1 sv-36 arg3 #f (the-as rgba -1)) + ) + ) + 0 + (none) + ) + ) diff --git a/goal_src/jak3/engine/debug/debug.gc b/goal_src/jak3/engine/debug/debug.gc index affe09c20..250a7a505 100644 --- a/goal_src/jak3/engine/debug/debug.gc +++ b/goal_src/jak3/engine/debug/debug.gc @@ -7,3 +7,1773 @@ ;; DECOMP BEGINS +;; ERROR: Bad vector register dependency: vf1 +;; ERROR: Bad vector register dependency: vf2 +;; ERROR: Bad vector register dependency: vf3 +;; ERROR: Bad vector register dependency: vf4 +;; ERROR: Bad vector register dependency: vf6 +;; ERROR: Bad vector register dependency: vf8 +;; ERROR: Bad vector register dependency: vf9 +(defun transform-float-point ((src-world-pt vector) (dst-gs-screen-pt vector4w)) + "Transform a point, using the cached matrix in VU0 registers, set from init-for-transform. + The argument order is backward - be careful! + After transformation, point is constrained to be within some region, but this is not proper clipping, + so you should do this yourself." + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf5 (&-> src-world-pt quad)) + (.mul.w.vf acc vf4 vf5) + (.add.mul.x.vf acc vf1 vf5 acc) + (.add.mul.y.vf acc vf2 vf5 acc) + (.add.mul.z.vf vf5 vf3 vf5 acc) + (.div.vf Q vf9 vf5 :fsf #b0 :ftf #b11) + (.wait.vf) + (.mul.vf vf5 vf5 Q :mask #b111) + (.add.vf vf5 vf5 vf8) + (.max.x.vf vf5 vf5 vf0 :mask #b1000) + (.min.x.vf vf5 vf5 vf6 :mask #b1000) + (vftoi4.xyzw vf5 vf5) + (.svf (&-> dst-gs-screen-pt quad) vf5) + dst-gs-screen-pt + ) + ) + +(defun-debug add-debug-point ((enable symbol) (bucket bucket-id) (pt vector)) + "Draw a point." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((s5-0 (new 'stack 'vector4w-2)) + (a1-2 (new 'stack-no-clear 'vector)) + ) + (set! (-> a1-2 quad) (-> pt quad)) + (set! (-> a1-2 w) 1.0) + (when (transform-point-qword! (the-as vector4w (-> s5-0 vector)) a1-2) + (with-dma-buffer-add-bucket ((v1-11 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((a0-6 (-> v1-11 base))) + (let* ((a1-3 v1-11) + (a3-0 (the-as dma-packet (-> a1-3 base))) + ) + (set! (-> a3-0 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a3-0 vif0) (new 'static 'vif-tag)) + (set! (-> a3-0 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-3 base) (the-as pointer (&+ a3-0 16))) + ) + (let* ((a1-4 v1-11) + (a3-2 (the-as gs-gif-tag (-> a1-4 base))) + ) + (set! (-> a3-2 tag) (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :abe #x1) + :nreg #x8 + ) + ) + (set! (-> a3-2 regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id xyzf2) + :regs2 (gif-reg-id rgbaq) + :regs3 (gif-reg-id xyzf2) + :regs4 (gif-reg-id rgbaq) + :regs5 (gif-reg-id xyzf2) + :regs6 (gif-reg-id rgbaq) + :regs7 (gif-reg-id xyzf2) + ) + ) + (set! (-> a1-4 base) (the-as pointer (&+ a3-2 16))) + ) + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 128) + (set! (-> s5-0 vector 1 w) 128) + (+! (-> s5-0 vector 0 y) 288) + (let* ((a1-11 v1-11) + (a3-4 (the-as vector4w-2 (-> a1-11 base))) + ) + (set! (-> a3-4 vector 0 quad) (-> s5-0 vector 1 quad)) + (set! (-> a3-4 vector 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a1-11 base) (the-as pointer (&+ a3-4 32))) + ) + (+! (-> s5-0 vector 0 x) -256) + (+! (-> s5-0 vector 0 y) -288) + (set! (-> s5-0 vector 1 x) 128) + (set! (-> s5-0 vector 1 y) 255) + (let* ((a1-18 v1-11) + (a3-6 (the-as vector4w-2 (-> a1-18 base))) + ) + (set! (-> a3-6 vector 0 quad) (-> s5-0 vector 1 quad)) + (set! (-> a3-6 vector 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a1-18 base) (the-as pointer (&+ a3-6 32))) + ) + (+! (-> s5-0 vector 0 x) 512) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 255) + (let* ((a1-23 v1-11) + (a3-8 (the-as vector4w-2 (-> a1-23 base))) + ) + (set! (-> a3-8 vector 0 quad) (-> s5-0 vector 1 quad)) + (set! (-> a3-8 vector 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a1-23 base) (the-as pointer (&+ a3-8 32))) + ) + (+! (-> s5-0 vector 0 x) -256) + (+! (-> s5-0 vector 0 y) -288) + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (let* ((a3-10 v1-11) + (a1-30 (the-as vector4w-2 (-> a3-10 base))) + ) + (set! (-> a1-30 vector 0 quad) (-> s5-0 vector 1 quad)) + (set! (-> a1-30 vector 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a3-10 base) (the-as pointer (&+ a1-30 32))) + ) + (let ((a3-14 (/ (the-as int (+ (- -16 (the-as int a0-6)) (the-as int (-> v1-11 base)))) 16))) + (cond + ((nonzero? a3-14) + (logior! (-> (the-as (pointer uint64) a0-6) 0) (shr (shl a3-14 48) 48)) + (logior! (-> (the-as (pointer uint64) a0-6) 1) (shl (shr (shl a3-14 48) 48) 32)) + ) + (else + (set! (-> v1-11 base) a0-6) + ) + ) + ) + ) + ) + ) + ) + #f + ) + +(def-mips2c debug-line-clip? (function vector vector vector vector symbol)) + +;; WARN: Return type mismatch pointer vs symbol. +(defun-debug internal-draw-debug-line ((bucket bucket-id) (p0 vector) (p1 vector) (color rgba) (mode symbol) (color2 rgba)) + "Implementation of line drawing DMA." + (local-vars (sv-112 vector) (sv-128 vector) (sv-144 vector)) + (set! sv-112 p1) + (let ((s1-0 color) + (s2-0 mode) + (s5-0 color2) + ) + (let ((a0-2 (-> *display* frames (-> *display* on-screen) debug-buf))) + (if (< (the-as uint (shr (+ (&- (-> a0-2 end) (the-as uint (-> a0-2 base))) 15) 4)) (the-as uint #x8000)) + (return (the-as symbol #f)) + ) + ) + (if (or (= s5-0 -1) (= s5-0 (new 'static 'rgba :r #xff :g #xff :b #xff :a #xff))) + (set! s5-0 s1-0) + ) + (case s2-0 + (('fade) + (set! s5-0 + (new 'static 'rgba :r (shr (-> s5-0 r) 1) :g (shr (-> s5-0 g) 1) :b (shr (-> s5-0 b) 1) :a (-> s5-0 a)) + ) + ) + ) + (let ((s4-0 (new 'stack 'vector4w-2)) + (s3-0 (new 'stack 'vector4w-2)) + ) + (set! sv-128 (new 'stack-no-clear 'vector)) + (set! sv-144 (new 'stack-no-clear 'vector)) + (the-as + symbol + (when (debug-line-clip? sv-128 sv-144 p0 sv-112) + (set! (-> sv-128 w) 1.0) + (set! (-> sv-144 w) 1.0) + (when (and (transform-point-qword! (the-as vector4w (-> s4-0 vector)) sv-128) + (transform-point-qword! (-> s4-0 vector 1) sv-144) + ) + (with-dma-buffer-add-bucket ((v1-37 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((a0-28 (the-as (pointer uint64) (-> v1-37 base)))) + (let* ((a1-6 v1-37) + (a3-2 (the-as object (-> a1-6 base))) + ) + (set! (-> (the-as dma-packet a3-2) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a3-2) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a3-2) vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-6 base) (&+ (the-as pointer a3-2) 16)) + ) + (let* ((a1-7 v1-37) + (a3-4 (the-as object (-> a1-7 base))) + ) + (set! (-> (the-as gs-gif-tag a3-4) tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type line) :iip #x1 :abe #x1) + :nreg #x4 + ) + ) + (set! (-> (the-as gs-gif-tag a3-4) regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id xyzf2) + :regs2 (gif-reg-id rgbaq) + :regs3 (gif-reg-id xyzf2) + ) + ) + (set! (-> a1-7 base) (&+ (the-as pointer a3-4) 16)) + ) + (case s2-0 + (('fade-depth) + (let ((f0-3 (fmax 0.2 (fmin 1.0 (* 0.00000005960465 (the float (-> s4-0 vector 0 z))))))) + (set! (-> s3-0 vector 0 x) (the int (* (the float (-> s1-0 r)) f0-3))) + (set! (-> s3-0 vector 0 y) (the int (* (the float (-> s1-0 g)) f0-3))) + (set! (-> s3-0 vector 0 z) (the int (* (the float (-> s1-0 b)) f0-3))) + ) + (set! (-> s3-0 vector 0 w) (the-as int (-> s1-0 a))) + ) + (else + (set! (-> s3-0 vector 0 x) (the-as int (-> s1-0 r))) + (set! (-> s3-0 vector 0 y) (the-as int (-> s1-0 g))) + (set! (-> s3-0 vector 0 z) (the-as int (-> s1-0 b))) + (set! (-> s3-0 vector 0 w) (the-as int (-> s1-0 a))) + ) + ) + (cond + ((= s2-0 'fade-depth) + (let ((f0-7 (fmax 0.2 (fmin 1.0 (* 0.00000005960465 (the float (-> s4-0 vector 1 z))))))) + (set! (-> s3-0 vector 1 x) (the int (* (the float (-> s5-0 r)) f0-7))) + (set! (-> s3-0 vector 1 y) (the int (* (the float (-> s5-0 g)) f0-7))) + (set! (-> s3-0 vector 1 z) (the int (* (the float (-> s5-0 b)) f0-7))) + ) + (set! (-> s3-0 vector 1 w) (the-as int (-> s5-0 a))) + ) + (else + (set! (-> s3-0 vector 1 x) (the-as int (-> s5-0 r))) + (set! (-> s3-0 vector 1 y) (the-as int (-> s5-0 g))) + (set! (-> s3-0 vector 1 z) (the-as int (-> s5-0 b))) + (set! (-> s3-0 vector 1 w) (the-as int (-> s5-0 a))) + ) + ) + (+! (-> s4-0 vector 0 z) -8192) + (+! (-> s4-0 vector 1 z) -8192) + (let* ((a3-7 v1-37) + (a1-50 (the-as object (-> a3-7 base))) + ) + (set! (-> (the-as (inline-array vector4w-2) a1-50) 0 vector 0 quad) (-> s3-0 vector 0 quad)) + (set! (-> (the-as (inline-array vector4w-2) a1-50) 0 vector 1 quad) (-> s4-0 vector 0 quad)) + (set! (-> (the-as (inline-array vector4w-2) a1-50) 1 vector 0 quad) (-> s3-0 vector 1 quad)) + (set! (-> (the-as (inline-array vector4w-2) a1-50) 1 vector 1 quad) (-> s4-0 vector 1 quad)) + (set! (-> a3-7 base) (&+ (the-as pointer a1-50) 64)) + ) + (let ((a3-11 (/ (the-as int (+ (- -16 (the-as int a0-28)) (the-as int (-> v1-37 base)))) 16))) + (cond + ((nonzero? a3-11) + (logior! (-> a0-28 0) (shr (shl a3-11 48) 48)) + (logior! (-> a0-28 1) (shl (shr (shl a3-11 48) 48) 32)) + ) + (else + (set! (-> v1-37 base) a0-28) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + +(defun-debug internal-draw-debug-text-3d ((bucket bucket-id) (text string) (pos vector) (color font-color) (offset vector2h)) + "Implementation of 3D text drawing." + (let ((s2-0 (new 'stack-no-clear 'vector4w))) + (set! (-> s2-0 quad) (the-as uint128 0)) + (when (transform-point-qword! s2-0 pos) + (with-dma-buffer-add-bucket ((s3-0 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((s1-1 (new + 'stack + 'font-context + *font-default-matrix* + (+ (-> offset x) -1792 (/ (-> s2-0 x) 16)) + (+ (-> offset y) -1855 (/ (-> s2-0 y) 16)) + 0.0 + color + (font-flags shadow kerning) + ) + ) + ) + (let ((v1-10 s1-1)) + (set! (-> v1-10 origin z) (the float (/ (-> s2-0 z) 16))) + ) + (set-context! *font-work* s1-1) + (draw-string text s3-0 s1-1) + ) + ) + ) + ) + ) + +(defun-debug add-debug-outline-triangle ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (p2 vector) (color rgba)) + "Draw a wireframe triangle." + (when (and enable (not *display-capture-mode*)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (add-debug-line #t bucket p1 p2 color #f (the-as rgba -1)) + (add-debug-line #t bucket p2 p0 color #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-triangle-normal ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (p2 vector) (color rgba)) + "Draw the normal of a triangle." + (when (and enable (not *display-capture-mode*)) + (let ((s3-0 (new 'stack-no-clear 'vector)) + (s2-0 (vector-3pt-cross! (new 'stack-no-clear 'vector) p0 p1 p2)) + ) + (vector-float/! s2-0 s2-0 (* 0.00024414062 (vector-length s2-0))) + (vector+! s3-0 p0 p1) + (vector+! s3-0 s3-0 p2) + (vector-float/! s3-0 s3-0 3.0) + (vector+! s2-0 s2-0 s3-0) + (add-debug-line #t bucket s3-0 s2-0 color #f (the-as rgba -1)) + ) + ) + #f + ) + +(defun-debug add-debug-flat-triangle ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (p2 vector) (color rgba)) + "Draw a shaded triangle." + (local-vars (sv-160 vector) (sv-176 vector)) + (set! sv-160 p0) + (set! sv-176 p1) + (let ((s0-0 p2) + (s3-0 color) + ) + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((s5-0 (new 'stack 'vector4w-3)) + (s4-0 (new 'stack 'vector4w-3)) + (a1-3 (new 'stack-no-clear 'vector)) + (s2-0 (new 'stack-no-clear 'vector)) + (s1-0 (new 'stack-no-clear 'vector)) + ) + (set! (-> a1-3 quad) (-> sv-160 quad)) + (set! (-> s2-0 quad) (-> sv-176 quad)) + (set! (-> s1-0 quad) (-> s0-0 quad)) + (set! (-> a1-3 w) 1.0) + (set! (-> s2-0 w) 1.0) + (set! (-> s1-0 w) 1.0) + (when (and (transform-point-qword! (the-as vector4w (-> s5-0 vector)) a1-3) + (transform-point-qword! (-> s5-0 vector 1) s2-0) + (transform-point-qword! (-> s5-0 vector 2) s1-0) + ) + (with-dma-buffer-add-bucket ((v1-17 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((a0-12 (-> v1-17 base))) + (let* ((a1-6 v1-17) + (a3-1 (the-as dma-packet (-> a1-6 base))) + ) + (set! (-> a3-1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a3-1 vif0) (new 'static 'vif-tag)) + (set! (-> a3-1 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-6 base) (the-as pointer (&+ a3-1 16))) + ) + (let* ((a1-7 v1-17) + (a3-3 (the-as gs-gif-tag (-> a1-7 base))) + ) + (set! (-> a3-3 tag) (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri) :iip #x1 :abe #x1) + :nreg #x6 + ) + ) + (set! (-> a3-3 regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id xyzf2) + :regs2 (gif-reg-id rgbaq) + :regs3 (gif-reg-id xyzf2) + :regs4 (gif-reg-id rgbaq) + :regs5 (gif-reg-id xyzf2) + ) + ) + (set! (-> a1-7 base) (the-as pointer (&+ a3-3 16))) + ) + (set! (-> s4-0 vector 0 x) (the-as int (-> s3-0 r))) + (set! (-> s4-0 vector 0 y) (the-as int (-> s3-0 g))) + (set! (-> s4-0 vector 0 z) (the-as int (-> s3-0 b))) + (set! (-> s4-0 vector 0 w) (the-as int (-> s3-0 a))) + (+! (-> s5-0 vector 0 z) -8192) + (+! (-> s5-0 vector 1 z) -8192) + (+! (-> s5-0 vector 2 z) -8192) + (let* ((a1-21 v1-17) + (a3-5 (the-as (inline-array vector) (-> a1-21 base))) + ) + (set! (-> a3-5 0 quad) (-> s4-0 vector 0 quad)) + (set! (-> a3-5 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a3-5 2 quad) (-> s4-0 vector 0 quad)) + (set! (-> a3-5 3 quad) (-> s5-0 vector 1 quad)) + (set! (-> a3-5 4 quad) (-> s4-0 vector 0 quad)) + (set! (-> a3-5 5 quad) (-> s5-0 vector 2 quad)) + (set! (-> a1-21 base) (the-as pointer (-> a3-5 6))) + ) + (let ((a1-25 (/ (the-as int (+ (- -16 (the-as int a0-12)) (the-as int (-> v1-17 base)))) 16))) + (cond + ((nonzero? a1-25) + (logior! (-> (the-as (pointer uint64) a0-12) 0) (shr (shl a1-25 48) 48)) + (logior! (-> (the-as (pointer uint64) a0-12) 1) (shl (shr (shl a1-25 48) 48) 32)) + ) + (else + (set! (-> v1-17 base) a0-12) + ) + ) + ) + ) + ) + ) + ) + ) + #f + ) + +(when *debug-segment* +(deftype debug-line (structure) + ((flags int32) + (bucket bucket-id) + (v1 vector :inline) + (v2 vector :inline) + (color rgba) + (mode symbol) + (color2 rgba) + ) + ) + + +(deftype debug-text-3d (structure) + ((flags int32) + (bucket bucket-id) + (pos vector :inline) + (color font-color) + (offset vector2h :inline) + (str string) + ) + ) + + +(deftype debug-tracking-thang (basic) + ((length int32) + (allocated-length int32) + ) + ) + + +(define *debug-lines* (the-as (inline-array debug-line) (malloc 'debug #x100000))) + +(define *debug-lines-trk* (new 'debug 'debug-tracking-thang)) + +(set! (-> *debug-lines-trk* allocated-length) #x4000) + +(define *debug-text-3ds* (the-as (inline-array debug-text-3d) (malloc 'debug #x6000))) + +(define *debug-text-3d-trk* (new 'debug 'debug-tracking-thang)) + +(set! (-> *debug-text-3d-trk* allocated-length) 512) + +(dotimes (gp-0 (-> *debug-text-3d-trk* allocated-length)) + (set! (-> *debug-text-3ds* gp-0 str) (new 'debug 'string 80 (the-as string #f))) + ) + +) +(defun-debug get-debug-line () + "Allocate a record for a debug line. + This is used to persist debug drawing for paused objects." + (cond + ((< (-> *debug-lines-trk* length) (-> *debug-lines-trk* allocated-length)) + (+! (-> *debug-lines-trk* length) 1) + (-> *debug-lines* (+ (-> *debug-lines-trk* length) -1)) + ) + (else + (the-as debug-line #f) + ) + ) + ) + +(defun-debug get-debug-text-3d () + "Allocate a record for a debug 3d text. + This is used to persist debug drawing for paused objects." + (cond + ((< (-> *debug-text-3d-trk* length) (-> *debug-text-3d-trk* allocated-length)) + (+! (-> *debug-text-3d-trk* length) 1) + (-> *debug-text-3ds* (+ (-> *debug-text-3d-trk* length) -1)) + ) + (else + (the-as debug-text-3d #f) + ) + ) + ) + +(defun-debug debug-reset-buffers () + "Reset buffered debug drawing." + (set! (-> *debug-lines-trk* length) 0) + (set! (-> *debug-text-3d-trk* length) 0) + (set! *debug-draw-pauseable* #f) + #f + ) + +(defun-debug debug-draw-buffers () + "Draw all buffered debug drawing." + (dotimes (gp-0 (-> *debug-lines-trk* length)) + (let ((v1-1 (-> *debug-lines* gp-0))) + (internal-draw-debug-line + (-> v1-1 bucket) + (-> v1-1 v1) + (-> v1-1 v2) + (-> v1-1 color) + (-> v1-1 mode) + (-> v1-1 color2) + ) + ) + ) + (dotimes (gp-1 (-> *debug-text-3d-trk* length)) + (let ((v1-8 (-> *debug-text-3ds* gp-1))) + (internal-draw-debug-text-3d (-> v1-8 bucket) (-> v1-8 str) (-> v1-8 pos) (-> v1-8 color) (-> v1-8 offset)) + ) + ) + #f + ) + +(defun-debug add-debug-line ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (color rgba) (mode symbol) (color2 rgba)) + "Draw a line." + (when (and enable (not *display-capture-mode*)) + (cond + (*debug-draw-pauseable* + (let ((v1-4 (get-debug-line))) + (when v1-4 + (set! (-> v1-4 bucket) bucket) + (set! (-> v1-4 v1 quad) (-> p0 quad)) + (set! (-> v1-4 v2 quad) (-> p1 quad)) + (set! (-> v1-4 color) color) + (set! (-> v1-4 color2) color2) + (set! (-> v1-4 mode) mode) + ) + ) + ) + (else + (internal-draw-debug-line bucket p0 p1 color mode color2) + ) + ) + ) + #f + ) + +(defun-debug add-debug-line2d ((enable symbol) (bucket bucket-id) (p0 vector4w) (p1 vector4w) (color vector4w)) + "Draw a screen-space line." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (with-dma-buffer-add-bucket ((s4-0 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((s2-0 (new 'stack 'vector4w)) + (v1-10 (new 'stack 'vector4w)) + ) + (set! (-> s2-0 quad) (-> p0 quad)) + (set! (-> v1-10 quad) (-> p1 quad)) + (set! (-> s2-0 x) (* (+ (-> s2-0 x) 2048) 16)) + (set! (-> s2-0 y) (* -16 (- 2048 (-> s2-0 y)))) + (set! (-> s2-0 z) #x7fffff) + (set! (-> v1-10 x) (* (+ (-> v1-10 x) 2048) 16)) + (set! (-> v1-10 y) (* -16 (- 2048 (-> v1-10 y)))) + (set! (-> v1-10 z) #x7fffff) + (let ((a0-18 (-> s4-0 base))) + (let* ((a1-7 s4-0) + (a2-3 (the-as dma-packet (-> a1-7 base))) + ) + (set! (-> a2-3 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a2-3 vif0) (new 'static 'vif-tag)) + (set! (-> a2-3 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-7 base) (the-as pointer (&+ a2-3 16))) + ) + (let* ((a1-8 s4-0) + (a2-5 (the-as gs-gif-tag (-> a1-8 base))) + ) + (set! (-> a2-5 tag) (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type line) :iip #x1 :abe #x1) + :nreg #x4 + ) + ) + (set! (-> a2-5 regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id xyzf2) + :regs2 (gif-reg-id rgbaq) + :regs3 (gif-reg-id xyzf2) + ) + ) + (set! (-> a1-8 base) (the-as pointer (&+ a2-5 16))) + ) + (let* ((a1-9 s4-0) + (a2-7 (the-as vector4w-2 (-> a1-9 base))) + ) + (set! (-> a2-7 vector 0 quad) (-> color quad)) + (set! (-> a2-7 vector 1 quad) (-> s2-0 quad)) + (set! (-> a1-9 base) (the-as pointer (&+ a2-7 32))) + ) + (let* ((a1-10 s4-0) + (a2-9 (the-as vector4w-2 (-> a1-10 base))) + ) + (set! (-> a2-9 vector 0 quad) (-> color quad)) + (set! (-> a2-9 vector 1 quad) (-> v1-10 quad)) + (set! (-> a1-10 base) (the-as pointer (&+ a2-9 32))) + ) + (let ((a1-14 (/ (the-as int (+ (- -16 (the-as int a0-18)) (the-as int (-> s4-0 base)))) 16))) + (cond + ((nonzero? a1-14) + (logior! (-> (the-as (pointer uint64) a0-18) 0) (shr (shl a1-14 48) 48)) + (logior! (-> (the-as (pointer uint64) a0-18) 1) (shl (shr (shl a1-14 48) 48) 32)) + ) + (else + (set! (-> s4-0 base) a0-18) + ) + ) + ) + ) + ) + ) + #f + ) + +(defun-debug add-debug-box ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (color rgba)) + "Draw an axis-aligned box." + (let ((s5-0 (new-stack-vector0))) + (set! (-> s5-0 quad) (-> p0 quad)) + (let ((s1-0 (new-stack-vector0))) + (set! (-> s1-0 quad) (-> p0 quad)) + (when (and enable (not *display-capture-mode*)) + (set! (-> s1-0 x) (-> p1 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 x) (-> p0 x)) + (set! (-> s1-0 y) (-> p1 y)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> p0 y)) + (set! (-> s1-0 z) (-> p1 z)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s5-0 y) (-> p1 y)) + (set! (-> s1-0 y) (-> p1 y)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 z) (-> p0 z)) + (set! (-> s1-0 x) (-> p1 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> p0 y)) + (set! (-> s5-0 x) (-> p1 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s5-0 quad) (-> p1 quad)) + (set! (-> s1-0 quad) (-> p1 quad)) + (set! (-> s1-0 x) (-> p0 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 x) (-> p1 x)) + (set! (-> s1-0 y) (-> p0 y)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> p1 y)) + (set! (-> s1-0 z) (-> p0 z)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s5-0 y) (-> p0 y)) + (set! (-> s1-0 y) (-> p0 y)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 z) (-> p1 z)) + (set! (-> s1-0 x) (-> p0 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> p1 y)) + (set! (-> s5-0 x) (-> p0 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + ) + ) + ) + #f + ) + +;; WARN: Return type mismatch int vs symbol. +(defun-debug add-debug-box-with-transform ((enable symbol) (bucket bucket-id) (box bounding-box) (mat matrix) (color rgba)) + "Draw a box with arbitrary transform." + (b! (not enable) cfg-5 :delay (nop!)) + (let ((s4-0 (new 'stack-no-clear 'inline-array 'vector 8))) + (let ((s2-0 (new 'stack-no-clear 'inline-array 'vector 2)) + (s1-0 (new 'stack-no-clear 'vector)) + ) + (set! (-> s2-0 0 quad) (-> box min quad)) + (set! (-> s2-0 1 quad) (-> box max quad)) + (set! (-> s1-0 w) 1.0) + (dotimes (s0-0 8) + (set! (-> s1-0 x) (-> s2-0 (logand s0-0 1) x)) + (set! (-> s1-0 y) (-> s2-0 (logand (/ s0-0 2) 1) y)) + (set! (-> s1-0 z) (-> s2-0 (logand (/ s0-0 4) 1) z)) + (let ((a0-5 (-> s4-0 s0-0))) + (vector-matrix*! a0-5 s1-0 mat) + ) + ) + ) + (add-debug-line #t bucket (-> s4-0 0) (-> s4-0 1) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 1) (-> s4-0 3) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 3) (-> s4-0 2) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 2) (-> s4-0 0) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 4) (-> s4-0 5) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 5) (-> s4-0 7) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 7) (-> s4-0 6) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 6) (-> s4-0 4) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 0) (-> s4-0 4) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 1) (-> s4-0 5) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 3) (-> s4-0 7) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 2) (-> s4-0 6) color #f (the-as rgba -1)) + ) + (label cfg-5) + (the-as symbol 0) + ) + +(defun-debug add-debug-x ((enable symbol) (bucket bucket-id) (pos vector) (color rgba)) + "Draw an X." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((s3-0 (new-stack-vector0)) + (s2-0 (new-stack-vector0)) + ) + (vector+! s3-0 pos (new 'static 'vector :x -1228.8)) + (vector+! s2-0 pos (new 'static 'vector :x 1228.8)) + (add-debug-line #t bucket s3-0 s2-0 color #f (the-as rgba -1)) + (vector+! s3-0 pos (new 'static 'vector :z -1228.8)) + (vector+! s2-0 pos (new 'static 'vector :z 1228.8)) + (add-debug-line #t bucket s3-0 s2-0 color #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-cross ((enable symbol) (bucket bucket-id) (pos vector) (len float)) + "Draw a cross." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((s4-0 (new-stack-vector0)) + (s3-0 (new-stack-vector0)) + ) + (let ((a1-1 s4-0) + (v1-3 pos) + (a0-1 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-1 x) (- len)) + (set! (-> a0-1 y) 0.0) + (set! (-> a0-1 z) 0.0) + (set! (-> a0-1 w) 1.0) + (vector+! a1-1 v1-3 a0-1) + ) + (let ((a1-3 s3-0) + (v1-4 pos) + (a0-2 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-2 x) len) + (set! (-> a0-2 y) 0.0) + (set! (-> a0-2 z) 0.0) + (set! (-> a0-2 w) 1.0) + (vector+! a1-3 v1-4 a0-2) + ) + (add-debug-line #t bucket s4-0 s3-0 *color-red* #f (the-as rgba -1)) + (let ((a1-6 s4-0) + (v1-5 pos) + (a0-4 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-4 x) 0.0) + (set! (-> a0-4 y) (- len)) + (set! (-> a0-4 z) 0.0) + (set! (-> a0-4 w) 1.0) + (vector+! a1-6 v1-5 a0-4) + ) + (let ((a1-8 s3-0) + (v1-6 pos) + (a0-5 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-5 x) 0.0) + (set! (-> a0-5 y) len) + (set! (-> a0-5 z) 0.0) + (set! (-> a0-5 w) 1.0) + (vector+! a1-8 v1-6 a0-5) + ) + (add-debug-line #t bucket s4-0 s3-0 *color-green* #f (the-as rgba -1)) + (let ((a1-11 s4-0) + (v1-7 pos) + (a0-7 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-7 x) 0.0) + (set! (-> a0-7 y) 0.0) + (set! (-> a0-7 z) (- len)) + (set! (-> a0-7 w) 1.0) + (vector+! a1-11 v1-7 a0-7) + ) + (let ((a0-8 s3-0) + (v1-8 (new 'stack-no-clear 'vector)) + ) + (set! (-> v1-8 x) 0.0) + (set! (-> v1-8 y) 0.0) + (set! (-> v1-8 z) len) + (set! (-> v1-8 w) 1.0) + (vector+! a0-8 pos v1-8) + ) + (add-debug-line #t bucket s4-0 s3-0 *color-blue* #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-text-3d ((enable symbol) (bucket bucket-id) (text string) (pos vector) (color font-color) (offset vector2h)) + "Draw debug text." + (when (and enable (not *display-capture-mode*)) + (cond + (*debug-draw-pauseable* + (let ((v1-4 (get-debug-text-3d))) + (when v1-4 + (set! (-> v1-4 flags) 0) + (set! (-> v1-4 bucket) bucket) + (set! (-> v1-4 pos quad) (-> pos quad)) + (cond + (offset + (set! (-> v1-4 offset x) (-> offset x)) + (set! (-> v1-4 offset y) (-> offset y)) + ) + (else + (set! (-> v1-4 offset x) 0) + (set! (-> v1-4 offset y) 0) + 0 + ) + ) + (set! (-> v1-4 color) color) + (let ((a0-6 0) + (a1-2 (-> text data)) + (v1-6 (-> v1-4 str data)) + ) + (while (and (nonzero? (-> a1-2 0)) (< a0-6 79)) + (set! (-> v1-6 0) (-> a1-2 0)) + (set! a1-2 (&-> a1-2 1)) + (set! v1-6 (&-> v1-6 1)) + (+! a0-6 1) + ) + (set! (-> v1-6 0) (the-as uint 0)) + ) + 0 + ) + ) + ) + (else + (internal-draw-debug-text-3d bucket text pos color (cond + (offset + (empty) + offset + ) + (else + (new 'static 'vector2h) + ) + ) + ) + ) + ) + ) + #f + ) + +(defun-debug add-debug-sphere-with-transform ((enable symbol) (bucket bucket-id) (pos vector) (radius meters) (mat matrix) (color rgba)) + "Draw a debug sphere, applying a transform to the given point first." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (init-vf0-vector) + (when (and enable (not *display-capture-mode*)) + (.lvf vf5 (&-> pos quad)) + (.lvf vf1 (&-> mat rvec quad)) + (.lvf vf2 (&-> mat uvec quad)) + (.lvf vf3 (&-> mat fvec quad)) + (.lvf vf4 (&-> mat trans quad)) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf5 acc) + (.add.mul.y.vf acc vf2 vf5 acc) + (.add.mul.z.vf vf5 vf3 vf5 acc) + (let ((a2-1 (new 'stack-no-clear 'vector))) + (.svf (&-> a2-1 quad) vf5) + (add-debug-sphere enable bucket a2-1 radius color) + ) + ) + #f + ) + ) + +(defun-debug add-debug-sphere ((enable symbol) (bucket bucket-id) (pos vector) (radius meters) (color rgba)) + "Draw a debug sphere." + (if (and enable (not *display-capture-mode*)) + (add-debug-sphere-from-table bucket pos radius color 6) + ) + #f + ) + +(defun-debug add-debug-text-sphere ((enable symbol) (bucket bucket-id) (pos vector) (radius meters) (text string) (color rgba)) + "Draw a debug sphere with a text label." + (add-debug-sphere enable bucket pos radius color) + (add-debug-text-3d enable bucket text pos (font-color default) (the-as vector2h #f)) + #f + ) + +(defun-debug add-debug-spheres ((enable symbol) (bucket bucket-id) (spheres (inline-array vector)) (count int) (color rgba)) + "Draw from an array of spheres. The radius is stored in w." + (when (and enable (not *display-capture-mode*)) + (let ((s4-0 (-> spheres 0))) + (countdown (s3-0 count) + (add-debug-sphere #t bucket s4-0 (-> s4-0 w) color) + (&+! s4-0 16) + ) + ) + ) + #f + ) + +(defun-debug add-debug-line-sphere ((enable symbol) (bucket bucket-id) (base vector) (dir vector) (rad float) (color rgba)) + "Draw a capsule as a cylinder." + (local-vars + (sv-16 bucket-id) + (sv-24 vector) + (sv-28 vector) + (sv-32 float) + (sv-36 rgba) + (sv-112 matrix) + (sv-116 float) + ) + (b! (not enable) cfg-8 :delay (nop!)) + (set! sv-16 bucket) + (set! sv-24 base) + (set! sv-28 dir) + (set! sv-32 rad) + (set! sv-36 color) + (set! sv-112 (new 'stack-no-clear 'matrix)) + (set! sv-116 (vector-length sv-28)) + (let ((gp-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) + ) + (vector-normalize-copy! gp-0 sv-28 1.0) + (vector-reset! s5-0) + (let* ((f0-2 (-> gp-0 y)) + (f0-4 (* f0-2 f0-2)) + (f1-0 (-> gp-0 z)) + ) + (if (< f0-4 (* f1-0 f1-0)) + (set! (-> s5-0 y) -1.0) + (set! (-> s5-0 z) -1.0) + ) + ) + (forward-down->inv-matrix sv-112 gp-0 s5-0) + ) + (set! (-> sv-112 trans quad) (-> sv-24 quad)) + (set! (-> sv-112 trans w) 1.0) + (let ((gp-1 (new 'static 'inline-array vector 3 + (new 'static 'vector :y 0.5877 :z 0.951 :w 0.951) + (new 'static 'vector :x 0.5877 :z -0.5877 :w -0.951) + (new 'static 'vector :x -0.951 :y -0.5878) + ) + ) + (s5-1 (new 'static 'inline-array vector 3 + (new 'static 'vector :x 1.0 :y 0.809 :z 0.3089 :w -0.3088) + (new 'static 'vector :x -0.809 :y -1.0 :z -0.809 :w -0.309) + (new 'static 'vector :x 0.3089 :y 0.8089) + ) + ) + (s4-0 (new 'stack-no-clear 'vector)) + (s3-0 (new 'stack-no-clear 'vector)) + (s2-0 (new 'stack-no-clear 'vector)) + (s1-0 (new 'stack-no-clear 'vector)) + ) + (set! (-> s1-0 z) 0.0) + (set! (-> s1-0 w) 1.0) + (set! (-> s1-0 x) (* sv-32 (-> s5-1 2 y))) + (set! (-> s1-0 y) (* sv-32 (-> gp-1 2 y))) + (vector-matrix*! s3-0 s1-0 sv-112) + (dotimes (s0-0 10) + (set! (-> s4-0 quad) (-> s3-0 quad)) + (set! (-> s1-0 x) (* sv-32 (-> (&-> s5-1 0 data s0-0) 0))) + (set! (-> s1-0 y) (* sv-32 (-> (&-> gp-1 0 data s0-0) 0))) + (vector-matrix*! s3-0 s1-0 sv-112) + (add-debug-line #t sv-16 s4-0 s3-0 sv-36 #f (the-as rgba -1)) + (vector+float*! s2-0 s3-0 (-> sv-112 fvec) sv-116) + (add-debug-line #t sv-16 s3-0 s2-0 sv-36 #f (the-as rgba -1)) + (vector+float*! s4-0 s4-0 (-> sv-112 fvec) sv-116) + (add-debug-line #t sv-16 s4-0 s2-0 sv-36 #f (the-as rgba -1)) + ) + ) + (label cfg-8) + 0 + (none) + ) + +(defun-debug add-debug-circle ((enable symbol) (bucket bucket-id) (origin vector) (radius float) (color rgba) (mat matrix)) + "Draw a circle." + (local-vars (sv-48 int) (sv-64 vector) (sv-80 vector)) + "note: you may pass #f for orientation" + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((f30-0 0.0) + (s1-0 (new-stack-vector0)) + (s0-0 (new-stack-vector0)) + ) + (set! sv-48 0) + (while (< sv-48 12) + (set! sv-64 s1-0) + (set! (-> sv-64 x) (* radius (cos f30-0))) + (set! (-> sv-64 y) 0.0) + (set! (-> sv-64 z) (* radius (sin f30-0))) + (set! (-> sv-64 w) 1.0) + (set! f30-0 (+ 5461.3335 f30-0)) + (set! sv-80 s0-0) + (set! (-> sv-80 x) (* radius (cos f30-0))) + (set! (-> sv-80 y) 0.0) + (set! (-> sv-80 z) (* radius (sin f30-0))) + (set! (-> sv-80 w) 1.0) + (when mat + (vector-matrix*! s1-0 s1-0 mat) + (vector-matrix*! s0-0 s0-0 mat) + ) + (vector+! s1-0 s1-0 origin) + (vector+! s0-0 s0-0 origin) + (add-debug-line #t bucket s1-0 s0-0 color #f (the-as rgba -1)) + (set! sv-48 (+ sv-48 1)) + ) + ) + #f + ) + +(defun-debug add-debug-vector ((enable symbol) (bucket bucket-id) (base vector) (dir vector) (len-scale meters) (color rgba)) + "Draw a vector." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((v1-3 (new-stack-vector0))) + (set! (-> v1-3 x) (+ (-> base x) (* (-> dir x) len-scale))) + (set! (-> v1-3 y) (+ (-> base y) (* (-> dir y) len-scale))) + (set! (-> v1-3 z) (+ (-> base z) (* (-> dir z) len-scale))) + (add-debug-line #t bucket base v1-3 color #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-matrix ((enable symbol) (bucket bucket-id) (mat matrix) (len meters)) + "Draw a matrix as a coordinate frame." + (add-debug-vector enable bucket (-> mat trans) (-> mat rvec) len (new 'static 'rgba :r #xff :a #x80)) + (add-debug-vector enable bucket (-> mat trans) (-> mat uvec) len (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector enable bucket (-> mat trans) (-> mat fvec) len (new 'static 'rgba :b #xff :a #x80)) + mat + ) + +(defun-debug add-debug-rot-matrix ((enable symbol) (bucket bucket-id) (mat matrix) (len vector)) + "Draw a matrix as a coordinate frame, but use the given origin instead of the trans from the matrix." + (add-debug-vector enable bucket len (-> mat rvec) (meters 2) (new 'static 'rgba :r #xff :a #x80)) + (add-debug-vector enable bucket len (-> mat uvec) (meters 2) (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector enable bucket len (-> mat fvec) (meters 2) (new 'static 'rgba :b #xff :a #x80)) + mat + ) + +(defun-debug add-debug-quaternion ((enable symbol) (bucket bucket-id) (trans vector) (quat quaternion)) + "Draw a quaternion as a coordinate frame." + (when (and enable (not *display-capture-mode*)) + (let ((a2-1 (quaternion->matrix (new 'stack-no-clear 'matrix) quat))) + (add-debug-rot-matrix enable bucket a2-1 trans) + ) + ) + 0 + (none) + ) + +(defun-debug add-debug-cspace ((enable symbol) (bucket bucket-id) (cs cspace)) + "Draw a cspace as a matrix." + (add-debug-matrix enable bucket (-> cs bone transform) (meters 2)) + cs + ) + +;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16 +;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16 +;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16 +(defun-debug add-debug-yrot-vector ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 float) (arg4 float) (arg5 rgba)) + (local-vars (sv-32 float)) + (set! sv-32 arg3) + (let ((s0-0 arg4) + (s3-0 arg5) + ) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (let ((s1-0 (new-stack-vector0))) + (set-vector! s1-0 (+ (-> arg2 x) (* (sin sv-32) s0-0)) (-> arg2 y) (+ (-> arg2 z) (* (cos sv-32) s0-0)) 1.0) + (add-debug-line arg0 arg1 s1-0 arg2 s3-0 #f (the-as rgba -1)) + ) + ) + #f + ) + +(defun-debug add-debug-arc ((arg0 symbol) + (arg1 bucket-id) + (arg2 vector) + (arg3 float) + (arg4 float) + (arg5 float) + (arg6 rgba) + (arg7 matrix) + ) + "note: you may pass #f for orientation" + (local-vars (sv-48 vector) (sv-64 vector) (sv-80 int) (sv-96 vector) (sv-112 vector)) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (let ((f30-0 arg3)) + (set! sv-48 (new 'stack-no-clear 'vector)) + (set! (-> sv-48 quad) (the-as uint128 0)) + (set! sv-64 (new 'stack-no-clear 'vector)) + (set! (-> sv-64 quad) (the-as uint128 0)) + (set! sv-80 0) + (while (< sv-80 12) + (set! sv-96 sv-48) + (set! (-> sv-96 x) (* arg5 (sin f30-0))) + (set! (-> sv-96 y) 0.0) + (set! (-> sv-96 z) (* arg5 (cos f30-0))) + (set! (-> sv-96 w) 1.0) + (+! f30-0 (the float (/ (the int (- arg4 arg3)) 12))) + (set! sv-112 sv-64) + (set! (-> sv-112 x) (* arg5 (sin f30-0))) + (set! (-> sv-112 y) 0.0) + (set! (-> sv-112 z) (* arg5 (cos f30-0))) + (set! (-> sv-112 w) 1.0) + (when arg7 + (vector-matrix*! sv-48 sv-48 arg7) + (vector-matrix*! sv-64 sv-64 arg7) + ) + (vector+! sv-48 sv-48 arg2) + (vector+! sv-64 sv-64 arg2) + (add-debug-line #t arg1 sv-48 sv-64 arg6 #f (the-as rgba -1)) + (cond + ((zero? sv-80) + (add-debug-line #t arg1 sv-48 arg2 arg6 #f (the-as rgba -1)) + ) + ((= sv-80 11) + (add-debug-line #t arg1 sv-64 arg2 arg6 #f (the-as rgba -1)) + ) + ) + (set! sv-80 (+ sv-80 1)) + ) + ) + #f + ) + +(defun-debug add-debug-curve ((arg0 symbol) + (arg1 bucket-id) + (arg2 (inline-array vector)) + (arg3 int) + (arg4 (pointer float)) + (arg5 int) + (arg6 rgba) + ) + (local-vars (sv-48 vector) (sv-64 int) (sv-80 int)) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (let ((s0-0 (new-stack-vector0))) + (set! sv-48 (new 'stack-no-clear 'vector)) + (set! (-> sv-48 quad) (the-as uint128 0)) + (set! sv-64 (* arg3 4)) + (curve-evaluate! sv-48 (-> arg4 0) arg2 arg3 arg4 arg5) + (set! sv-80 0) + (while (< sv-80 sv-64) + (set! (-> s0-0 quad) (-> sv-48 quad)) + (curve-evaluate! sv-48 (/ (the float (+ sv-80 1)) (the float sv-64)) arg2 arg3 arg4 arg5) + (add-debug-line #t arg1 s0-0 sv-48 arg6 #f (the-as rgba -1)) + (set! sv-80 (+ sv-80 1)) + ) + ) + #f + ) + +(defun-debug add-debug-curve2 ((arg0 symbol) (arg1 bucket-id) (arg2 curve) (arg3 rgba) (arg4 symbol)) + (if (and arg0 (not *display-capture-mode*)) + (add-debug-curve #t arg1 (-> arg2 cverts) (-> arg2 num-cverts) (-> arg2 knots) (-> arg2 num-knots) arg3) + ) + #f + ) + +(defun-debug add-debug-points ((arg0 symbol) (arg1 bucket-id) (arg2 (inline-array vector)) (arg3 int) (arg4 rgba) (arg5 float) (arg6 int)) + (local-vars + (sv-32 (function symbol bucket-id string vector font-color vector2h symbol)) + (sv-48 symbol) + (sv-64 bucket-id) + (sv-80 (function _varargs_ object)) + (sv-96 vector) + ) + (when (and arg0 (not *display-capture-mode*)) + (dotimes (s0-0 arg3) + (set! sv-96 (new 'stack-no-clear 'vector)) + (set! (-> sv-96 quad) (the-as uint128 0)) + (set! (-> sv-96 quad) (-> arg2 s0-0 quad)) + (if (!= arg5 0.0) + (set! (-> sv-96 y) arg5) + ) + (set! sv-32 add-debug-text-3d) + (set! sv-48 #t) + (set! sv-64 arg1) + (set! sv-80 format) + (let ((a0-5 (clear *temp-string*)) + (a1-1 "~d") + (a2-1 s0-0) + ) + (sv-80 a0-5 a1-1 a2-1) + ) + (let ((a2-2 *temp-string*) + (a3-1 sv-96) + (t0-1 1) + (t1-1 #f) + ) + (sv-32 sv-48 sv-64 a2-2 a3-1 (the-as font-color t0-1) (the-as vector2h t1-1)) + ) + (let ((t9-3 add-debug-x) + (a0-7 #t) + (a1-3 arg1) + (a3-2 (if (= s0-0 arg6) + (the-as uint #x80ffffff) + (the-as uint arg4) + ) + ) + ) + (t9-3 a0-7 a1-3 sv-96 (the-as rgba a3-2)) + ) + ) + ) + #f + ) + +(defun-debug debug-percent-bar ((arg0 symbol) (arg1 bucket-id) (arg2 int) (arg3 int) (arg4 float) (arg5 rgba) (arg6 int) (arg7 int)) + (local-vars (sv-16 int) (sv-32 float)) + (set! sv-16 arg3) + (set! sv-32 arg4) + (let ((s3-0 arg5) + (s1-0 arg6) + (s2-0 arg7) + ) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (with-dma-buffer-add-bucket ((s0-0 (-> *display* frames (-> *display* on-screen) debug-buf)) + arg1 + ) + (draw-sprite2d-xy s0-0 arg2 sv-16 s1-0 s2-0 (new 'static 'rgba :a #x40) #x3fffff) + (draw-sprite2d-xy s0-0 arg2 (+ sv-16 2) (the int (* sv-32 (the float s1-0))) (+ s2-0 -4) s3-0 #x3fffff) + ) + ) + #f + ) + +(defun-debug debug-pad-display ((arg0 cpad-info)) + (let ((gp-0 (new 'static 'inline-array vector 32 + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + ) + ) + ) + (countdown (v1-0 31) + (let ((a0-3 (-> gp-0 v1-0 quad))) + (set! (-> gp-0 (+ v1-0 1) quad) a0-3) + ) + ) + (set! (-> gp-0 0 x) (* (sin (-> arg0 stick0-dir)) (-> arg0 stick0-speed))) + (set! (-> gp-0 0 y) (* (cos (-> arg0 stick0-dir)) (-> arg0 stick0-speed))) + (dotimes (s5-1 32) + (with-dma-buffer-add-bucket ((s3-0 (-> *display* frames (-> *display* on-screen) debug-buf)) + (bucket-id bucket583) + ) + (draw-sprite2d-xy + s3-0 + (the int (* 120.0 (-> gp-0 s5-1 x))) + (the int (* 144.0 (-> gp-0 s5-1 y))) + 10 + 10 + (new 'static 'rgba :a #x80 :r (- 255 (* 7 s5-1))) + #x3fffff + ) + ) + ) + ) + #f + ) + +(defun-debug add-debug-light ((arg0 symbol) (arg1 bucket-id) (arg2 light) (arg3 vector) (arg4 string)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + ) + (init-vf0-vector) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (when (!= (-> arg2 extra x) 0.0) + (add-debug-vector + arg0 + arg1 + arg3 + (-> arg2 direction) + (meters 3) + (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80) + ) + (let ((s2-0 (new-stack-vector0))) + (let ((v1-4 (-> arg2 direction))) + (let ((a0-3 (* 12288.0 (-> arg2 extra x)))) + (.mov vf7 a0-3) + ) + (.lvf vf5 (&-> v1-4 quad)) + ) + (.lvf vf4 (&-> arg3 quad)) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf5 vf7 :mask #b111) + (.add.mul.w.vf vf6 vf4 vf0 acc :mask #b111) + (.svf (&-> s2-0 quad) vf6) + (let ((s1-1 (logior (logior (logior (shr (shl (the int (* 128.0 (-> arg2 color w))) 56) 32) + (shr (shl (the int (* 128.0 (-> arg2 color z))) 56) 40) + ) + (shr (shl (the int (* 128.0 (-> arg2 color y))) 56) 48) + ) + (shr (shl (the int (* 128.0 (-> arg2 color x))) 56) 56) + ) + ) + ) + (format (clear *temp-string*) "~S ~,,2f" arg4 (-> arg2 extra x)) + (let ((t0-2 *temp-string*)) + (add-debug-text-sphere arg0 arg1 s2-0 (* 2048.0 (-> arg2 extra x)) t0-2 (the-as rgba s1-1)) + ) + ) + ) + ) + #f + ) + ) + +(defun-debug add-debug-lights ((arg0 symbol) (arg1 bucket-id) (arg2 (inline-array light)) (arg3 vector)) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (add-debug-light arg0 arg1 (-> arg2 0) arg3 "dir0") + (add-debug-light arg0 arg1 (-> arg2 1) arg3 "dir1") + (add-debug-light arg0 arg1 (-> arg2 2) arg3 "dir2") + (add-debug-light arg0 arg1 (-> arg2 3) arg3 "ambi") + #f + ) + +(defun-debug drawable-frag-count ((arg0 drawable)) + (let ((gp-0 0)) + (cond + ((not arg0) + ) + ((type? arg0 drawable-group) + (dotimes (s4-0 (-> (the-as drawable-group arg0) length)) + (+! gp-0 (drawable-frag-count (-> (the-as drawable-group arg0) data s4-0))) + ) + ) + (else + (+! gp-0 1) + ) + ) + gp-0 + ) + ) + + +(defun-debug history-init ((arg0 pos-history) (arg1 int)) + (set! (-> arg0 num-points) arg1) + (set! (-> arg0 points) (the-as (inline-array vector) #f)) + arg0 + ) + +(defun-debug history-draw-and-update ((arg0 pos-history) (arg1 symbol) (arg2 vector)) + (if (and arg1 (not (-> arg0 points))) + (set! (-> arg0 points) (the-as (inline-array vector) (malloc 'debug (* (-> arg0 num-points) 16)))) + ) + (when (-> arg0 points) + (set! (-> arg0 points (-> arg0 h-first) quad) (-> arg2 quad)) + (+! (-> arg0 h-first) 1) + (when (>= (-> arg0 h-first) (-> arg0 num-points)) + (set! (-> arg0 h-first) 0) + 0 + ) + ) + (when (and arg1 (not *display-capture-mode*)) + (dotimes (s5-1 (+ (-> arg0 num-points) -1)) + (if (!= (+ s5-1 1) (-> arg0 h-first)) + (add-debug-line + #t + (bucket-id debug-no-zbuf1) + (-> arg0 points s5-1) + (-> arg0 points (+ s5-1 1)) + (new 'static 'rgba :r #x80 :g #xc0 :b #x80 :a #x80) + #f + (the-as rgba -1) + ) + ) + ) + ) + #f + ) + +(defun-debug dma-timeout-cam () + (let ((a0-0 (new-stack-vector0)) + (a1-0 (new 'stack-no-clear 'matrix)) + ) + (set! (-> a1-0 rvec quad) (the-as uint128 0)) + (set! (-> a1-0 uvec quad) (the-as uint128 0)) + (set! (-> a1-0 fvec quad) (the-as uint128 0)) + (set! (-> a1-0 trans quad) (the-as uint128 0)) + (set! (-> a0-0 x) -666764.4) + (set! (-> a0-0 y) 21102.984) + (set! (-> a0-0 z) 51613.348) + (set! (-> a0-0 w) 1.0) + (set! (-> a1-0 rvec x) -0.911) + (set! (-> a1-0 rvec y) 0.0) + (set! (-> a1-0 rvec z) 0.4122) + (set! (-> a1-0 rvec w) 0.0) + (set! (-> a1-0 uvec x) -0.0984) + (set! (-> a1-0 uvec y) 0.971) + (set! (-> a1-0 uvec z) -0.2174) + (set! (-> a1-0 uvec w) 0.0) + (set! (-> a1-0 fvec x) -0.4003) + (set! (-> a1-0 fvec y) -0.2387) + (set! (-> a1-0 fvec z) -0.8847) + (set! (-> a1-0 fvec w) 0.0) + (set! (-> a1-0 trans x) 0.0) + (set! (-> a1-0 trans y) 0.0) + (set! (-> a1-0 trans z) 0.0) + (set! (-> a1-0 trans w) 1.0) + (debug-set-camera-pos-rot! a0-0 a1-0) + ) + ) + +(defun-debug display-file-info () + (when (and *display-file-info* (!= *master-mode* 'menu)) + (dotimes (gp-0 (-> *level* length)) + (let ((v1-7 (-> *level* level gp-0))) + (when (= (-> v1-7 status) 'active) + (let ((s5-0 (-> v1-7 bsp))) + (format *stdcon* "file name: ~S~%" (-> s5-0 info file-name)) + (format *stdcon* "version: ~D.~D~%" (-> s5-0 info major-version) (-> s5-0 info minor-version)) + (format *stdcon* "maya file: ~S~%" (-> s5-0 info maya-file-name)) + (format *stdcon* "mdb file: ~S~%" (-> s5-0 info mdb-file-name)) + (format *stdcon* "~S" (-> s5-0 info tool-debug)) + ) + ) + ) + ) + ) + 0 + ) + +(defun-debug add-debug-cursor ((arg0 symbol) (arg1 bucket-id) (arg2 int) (arg3 int) (arg4 mouse-buttons)) + (when (and arg0 (not *display-capture-mode*)) + (with-dma-buffer-add-bucket ((s4-0 (-> *display* frames (-> *display* on-screen) global-buf)) + arg1 + ) + (set! (-> (new 'stack-no-clear 'vector) quad) (the-as uint128 0)) + (let ((v1-9 arg4)) + (draw-string-xy + "X" + s4-0 + (+ arg2 -5) + (+ arg3 -4) + (cond + ((= v1-9 (mouse-buttons left)) + (font-color red) + ) + ((= v1-9 (mouse-buttons right)) + (font-color yellow) + ) + ((= v1-9 (mouse-buttons middle)) + (font-color green) + ) + (else + (font-color default) + ) + ) + (font-flags shadow) + ) + ) + ) + ) + 0 + ) + +(when *debug-segment* +(define *boundary-polygon* (the-as (inline-array sky-vertex) (malloc 'debug 768))) + +) +(def-mips2c init-boundary-regs (function none)) + +;; WARN: Return type mismatch pointer vs none. +(defun-debug add-boundary-shader ((arg0 texture-id) (arg1 dma-buffer)) + (let ((a1-1 (lookup-texture-by-id arg0))) + (when a1-1 + (let* ((v1-0 arg1) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as gs-gif-tag a0-1) tag) (new 'static 'gif-tag64 :nloop #x1 :nreg #x5)) + (set! (-> (the-as gs-gif-tag a0-1) regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + ) + ) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (let ((s5-0 (the-as adgif-shader (-> arg1 base)))) + (adgif-shader<-texture-simple! s5-0 a1-1) + (set! (-> s5-0 alpha) (new 'static 'gs-alpha :b #x1 :d #x1)) + (set! (-> s5-0 tex0 tfx) 0) + (set! (-> s5-0 tex1 mmag) 0) + (set! (-> s5-0 clamp) (new 'static 'gs-clamp)) + ) + 0 + (&+! (-> arg1 base) 80) + ) + ) + (none) + ) + +(def-mips2c draw-boundary-polygon function) + +(def-mips2c render-boundary-quad function) + +(def-mips2c render-boundary-tri (function sky-vertex dma-buffer none)) + +;; add-debug-bound-internal sneaks an extra value in vf27 - so this set-sky-vf27 function +;; was added so we can pass this value down to c++. +;; og:preserve-this +(def-mips2c set-sky-vf27 (function object none)) + + +;; WARN: Return type mismatch symbol vs none. +(defun-debug add-debug-bound-internal ((arg0 dma-buffer) (arg1 (inline-array vector)) (arg2 int) (arg3 rgba) (arg4 rgba) (arg5 int)) + (rlet ((vf27 :class vf)) + (cond + ((nonzero? arg5) + (set-vector! + (-> *boundary-polygon* 0 col) + (the float (-> arg3 r)) + (the float (-> arg3 g)) + (the float (-> arg3 b)) + (the float (-> arg3 a)) + ) + (set-vector! + (-> *boundary-polygon* 1 col) + (the float (-> arg4 r)) + (the float (-> arg4 g)) + (the float (-> arg4 b)) + (the float (-> arg4 a)) + ) + ) + (else + (set-vector! + (-> *boundary-polygon* 0 col) + (the float (-> arg3 r)) + (the float (-> arg3 g)) + (the float (-> arg3 b)) + (the float (shr (-> arg3 a) 1)) + ) + (set-vector! + (-> *boundary-polygon* 1 col) + (the float (-> arg4 r)) + (the float (-> arg4 g)) + (the float (-> arg4 b)) + (the float (shr (-> arg4 a) 1)) + ) + ) + ) + (init-boundary-regs) + ;(.lvf vf27 (&-> *sky-work* giftag-roof quad)) + ;; og:preserve-this + (set-sky-vf27 (&-> *sky-work* giftag-roof quad)) + (let ((s3-0 0) + (s2-0 (new 'static 'inline-array vector 4 + (new 'static 'vector :x 1.0 :y 8.0 :z 1.0 :w 1.0) + (new 'static 'vector :z 1.0 :w 1.0) + (new 'static 'vector :y 8.0 :z 1.0 :w 1.0) + (new 'static 'vector :x 1.0 :z 1.0 :w 1.0) + ) + ) + ) + (while (< s3-0 (+ arg2 -2)) + (cond + ((not (logtest? s3-0 1)) + (dotimes (v1-10 3) + (set! (-> *boundary-polygon* v1-10 pos quad) (-> arg1 (+ s3-0 v1-10) quad)) + (set! (-> *boundary-polygon* v1-10 stq quad) (-> s2-0 (+ s3-0 v1-10) quad)) + ) + ) + (else + (set! (-> *boundary-polygon* 0 pos quad) (-> arg1 (+ s3-0 1) quad)) + (set! (-> *boundary-polygon* 1 pos quad) (-> arg1 s3-0 quad)) + (set! (-> *boundary-polygon* 2 pos quad) (-> arg1 (+ s3-0 2) quad)) + (set! (-> *boundary-polygon* 0 stq quad) (-> s2-0 (+ s3-0 1) quad)) + (set! (-> *boundary-polygon* 1 stq quad) (-> s2-0 s3-0 quad)) + (set! (-> *boundary-polygon* 2 stq quad) (-> s2-0 (+ s3-0 2) quad)) + ) + ) + (render-boundary-tri (-> *boundary-polygon* 0) arg0) + (+! s3-0 1) + ) + ) + (none) + ) + ) + +;; WARN: Function add-debug-bound has a return type of none, but the expression builder found a return statement. +(defun-debug add-debug-bound ((arg0 bucket-id) (arg1 (inline-array vector)) (arg2 int) (arg3 rgba) (arg4 rgba) (arg5 int)) + (local-vars (sv-16 dma-packet) (sv-32 rgba) (sv-48 int) (sv-64 int) (sv-80 int)) + (set! sv-32 arg4) + (let ((s1-0 arg5)) + (if (< arg2 3) + (return 0) + ) + (with-dma-buffer-add-bucket ((s2-0 (-> *display* frames (-> *display* on-screen) global-buf)) + arg0 + ) + (dma-buffer-add-gs-set s2-0 + (zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24))) + (test-1 (new 'static 'gs-test :zte #x1 :ztst (gs-ztest greater-equal))) + (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) + ) + (set! sv-16 (the-as dma-packet (-> s2-0 base))) + (&+! (-> s2-0 base) 16) + (add-boundary-shader (new 'static 'texture-id :index #x3 :page #x1) s2-0) + (let ((t9-1 add-debug-bound-internal) + (a0-9 s2-0) + (a1-13 arg1) + (a2-1 arg2) + (t1-1 s1-0) + ) + (t9-1 a0-9 a1-13 a2-1 arg3 sv-32 t1-1) + ) + (close-sky-buffer s2-0) + (let ((v1-16 (/ (+ (- -16 (the-as int sv-16)) (the-as int (-> s2-0 base))) 16))) + (set! (-> sv-16 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc v1-16)) + (set! (-> sv-16 vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet sv-16) vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1 :imm v1-16)) + ) + (dma-buffer-add-gs-set s2-0 + (zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24))) + (test-1 (new 'static 'gs-test :zte #x1 :ztst (gs-ztest greater-equal))) + (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) + ) + (let ((s1-1 (if (= s1-0 1) + (the-as int (the-as uint #x80ffffff)) + #x60606060 + ) + ) + (s0-1 (/ arg2 4)) + ) + (add-debug-line #t arg0 (-> arg1 0) (-> arg1 1) (the-as rgba s1-1) #f (the-as rgba -1)) + (add-debug-line #t arg0 (-> arg1 0) (-> arg1 2) (the-as rgba s1-1) #f (the-as rgba -1)) + (add-debug-line #t arg0 (-> arg1 (+ arg2 -1)) (-> arg1 (+ arg2 -2)) (the-as rgba s1-1) #f (the-as rgba -1)) + (set! sv-48 0) + (while (< sv-48 s0-1) + (let* ((a2-5 (+ (* sv-48 2) 1)) + (v1-31 (+ a2-5 2)) + ) + (set! sv-64 (+ a2-5 1)) + (set! sv-80 (+ sv-64 2)) + (if (< sv-64 arg2) + (add-debug-line #t arg0 (-> arg1 a2-5) (-> arg1 v1-31) (the-as rgba s1-1) #f (the-as rgba -1)) + ) + ) + (if (< sv-80 arg2) + (add-debug-line #t arg0 (-> arg1 sv-64) (-> arg1 sv-80) (the-as rgba s1-1) #f (the-as rgba -1)) + ) + (set! sv-48 (+ sv-48 1)) + ) + ) + ) + ) + 0 + (none) + ) + +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; ERROR: function was not converted to expressions. Cannot decompile. + +; (defun-debug bugfix? () +; (let ((s5-0 (the-as int #xffffffff)) +; (gp-0 (the-as int #xffffffff)) +; (s4-0 (logior #x20000000 (logand (the-as uint #xffffffc0) (the int #f)))) +; ) +; 0 +; (let ((s3-0 (+ #x2000000 s4-0))) +; (dotimes (s2-0 100) +; (set! s5-0 (min s5-0 (qword-read-time (the-as (array uint128) s4-0) 128))) +; (set! gp-0 (min gp-0 (qword-read-time (the-as (array uint128) s3-0) 128))) +; ) +; (let ((f30-0 (/ (the float gp-0) (the float s5-0)))) +; (format #t "qword read times: hi #x~x ~d, lo #x~x ~d~%" s3-0 gp-0 s4-0 s5-0) +; (format #t "hi/lo memory bank uncached read speed ratio is ~f~%" f30-0) +; (format +; #t +; "If the workaround for the EE memory controller bug is turned on, this ratio should be about 1.3, otherwise about 1.0.~%" +; ) +; (< 1.15 f30-0) +; ) +; ) +; ) +; ) diff --git a/goal_src/jak3/engine/gfx/font-h.gc b/goal_src/jak3/engine/gfx/font-h.gc index 72ee36ae8..4c448ea76 100644 --- a/goal_src/jak3/engine/gfx/font-h.gc +++ b/goal_src/jak3/engine/gfx/font-h.gc @@ -301,7 +301,7 @@ (reg-save uint32 5) ) (:methods - (font-work-method-9 () none) + (set-context! (_type_ object) none) ) ) @@ -728,3 +728,6 @@ (set! (-> *font-work* color-table arg0 color 3) arg4) 0 ) + + +(define-extern draw-string (function string dma-buffer font-context draw-string-result)) diff --git a/goal_src/jak3/engine/gfx/sky/sky-h.gc b/goal_src/jak3/engine/gfx/sky/sky-h.gc index c03cf717b..11aca67ed 100644 --- a/goal_src/jak3/engine/gfx/sky/sky-h.gc +++ b/goal_src/jak3/engine/gfx/sky/sky-h.gc @@ -5,6 +5,8 @@ ;; name in dgo: sky-h ;; dgos: GAME +(define-extern close-sky-buffer (function dma-buffer none)) + ;; DECOMP BEGINS (deftype sky-color-hour (structure) @@ -224,3 +226,5 @@ (sky-work-method-38 () none) ) ) + +(define-extern *sky-work* sky-work) diff --git a/goal_src/jak3/engine/gfx/sprite/simple-sprite-h.gc b/goal_src/jak3/engine/gfx/sprite/simple-sprite-h.gc index 8c7f670e8..9367e04db 100644 --- a/goal_src/jak3/engine/gfx/sprite/simple-sprite-h.gc +++ b/goal_src/jak3/engine/gfx/sprite/simple-sprite-h.gc @@ -9,8 +9,8 @@ (deftype sprite-glow-data (structure) ((position vector :inline) - (size-x float :overlay-at (-> position data 3)) - (size-probe float :offset 16) + (size-x float :overlay-at (-> position data 3)) + (size-probe float :offset 16) (z-offset float) (rot-angle float) (size-y float) @@ -19,6 +19,7 @@ (fade-b float) (tex-id texture-id) (dummy uint32) + (quads vector 4 :inline :overlay-at position) ) (:methods (set-trans (_type_ vector) none) @@ -41,8 +42,8 @@ (data (inline-array sprite-glow-data)) ) (:methods - (simple-sprite-system-method-9 () none) + (add! (_type_ sprite-glow-data) none) (draw-all-sprites! (_type_ dma-buffer) none) - (simple-sprite-system-method-11 () none) + (clear! (_type_) none) ) ) diff --git a/goal_src/jak3/engine/gfx/sprite/sprite-distort.gc b/goal_src/jak3/engine/gfx/sprite/sprite-distort.gc index e77a991a6..600e10634 100644 --- a/goal_src/jak3/engine/gfx/sprite/sprite-distort.gc +++ b/goal_src/jak3/engine/gfx/sprite/sprite-distort.gc @@ -7,3 +7,347 @@ ;; DECOMP BEGINS +(deftype sprite-distorter-sine-tables (basic) + "Table of precomputed sine data for the sprite distorter renderer." + ((aspx float) + (aspy float) + (entry vector 128 :inline) + (ientry qword 9 :inline) + (giftag gs-gif-tag :inline) + (color qword :inline) + ) + ) + + +(kmemopen global "sprite-distort-tables") + +(define *sprite-distorter-sine-tables* (new 'global 'sprite-distorter-sine-tables)) + +(kmemclose) + +(defun sprite-distorter-generate-tables () + "Regenerate the sprite-distorter-sine-tables for the current camera settings." + (let ((gp-0 *sprite-distorter-sine-tables*)) + (let ((s3-0 0) + (s5-0 0) + (s4-0 3) + (f28-0 (- (-> *math-camera* perspective rvec x))) + (f30-0 (- (-> *math-camera* perspective uvec y))) + ) + (when (or (!= f28-0 (-> gp-0 aspx)) (!= f30-0 (-> gp-0 aspy))) + (set! (-> gp-0 aspx) f28-0) + (set! (-> gp-0 aspy) f30-0) + (while (< s4-0 12) + (set! (-> gp-0 ientry s5-0 vector4w x) (+ s3-0 352)) + (+! s5-0 1) + (dotimes (s2-0 s4-0) + (let ((f26-0 (* 65536.0 (/ (the float s2-0) (the float s4-0))))) + (set-vector! (-> gp-0 entry s3-0) (* (sin f26-0) f28-0) (* (cos f26-0) f30-0) 0.0 0.0) + (let ((s3-1 (+ s3-0 1))) + (set-vector! (-> gp-0 entry s3-1) (* 0.001953125 f28-0 (sin f26-0)) (* 0.001953125 f30-0 (cos f26-0)) 0.0 0.0) + (set! s3-0 (+ s3-1 1)) + ) + ) + ) + (+! s4-0 1) + ) + (set-vector! (-> gp-0 entry s3-0) 0.0 f30-0 0.0 0.0) + (let ((v1-20 (+ s3-0 1))) + (set-vector! (-> gp-0 entry v1-20) 0.0 (* 0.001953125 f30-0) 0.0 0.0) + (+ v1-20 1) + ) + ) + ) + (set! (-> gp-0 giftag tag) (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :tme #x1) + :nreg #xf + ) + ) + (set! (-> gp-0 giftag regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id st) + :regs1 (gif-reg-id rgbaq) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id rgbaq) + :regs5 (gif-reg-id xyzf2) + :regs6 (gif-reg-id st) + :regs7 (gif-reg-id rgbaq) + :regs8 (gif-reg-id xyzf2) + :regs9 (gif-reg-id st) + :regs10 (gif-reg-id rgbaq) + :regs11 (gif-reg-id xyzf2) + :regs12 (gif-reg-id st) + :regs13 (gif-reg-id rgbaq) + :regs14 (gif-reg-id xyzf2) + ) + ) + (set! (-> gp-0 color vector4w x) 128) + (set! (-> gp-0 color vector4w y) 128) + (set! (-> gp-0 color vector4w z) 128) + (set! (-> gp-0 color vector4w w) 128) + ) + 0 + (none) + ) + +(define sprite-distort-vu1-block (new 'static 'vu-function :length 63 :qlength 32)) + +(defun sprite-init-distorter ((arg0 dma-buffer)) + "Generate DMA to initialize the distort renderer." + (dma-buffer-add-gs-set arg0 + (zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24) :zmsk #x1)) + (tex0-1 (new 'static 'gs-tex0 :tbp0 #x3300 :tbw #x8 :tw #x9 :th #x9)) + (tex1-1 (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) + (miptbp1-1 (new 'static 'gs-miptbp)) + (clamp-1 (new 'static 'gs-clamp + :wms (gs-tex-wrap-mode region-clamp) + :wmt (gs-tex-wrap-mode region-clamp) + :maxu #x1ff + :maxv #x19f + ) + ) + (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) + ) + (let* ((v1-3 arg0) + (a1-6 (the-as dma-packet (-> v1-3 base))) + ) + (set! (-> a1-6 dma) (new 'static 'dma-tag + :qwc #x8b + :id (dma-tag-id ref) + :addr (the-as uint (-> *sprite-distorter-sine-tables* entry)) + ) + ) + (set! (-> a1-6 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> a1-6 vif1) (new 'static 'vif-tag :imm #x160 :num #x8b :cmd (vif-cmd unpack-v4-32))) + (set! (-> v1-3 base) (the-as pointer (&+ a1-6 16))) + ) + (dma-buffer-add-vu-function arg0 sprite-distort-vu1-block 1) + 0 + (none) + ) + +;; ERROR: Inline assembly instruction marked with TODO - [TODO.VCLIP] +;; ERROR: Unsupported inline assembly instruction kind - [cfc2.i v1, Clipping] +(defun sprite-draw-distorters ((arg0 dma-buffer)) + "Generate DMA to draw all distort sprites." + (local-vars + (v1-15 float) + (v1-21 float) + (v1-26 int) + (v1-65 float) + (sv-16 sprite-vec-data-2d) + (sv-32 vector) + (sv-48 vector) + ) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf8 (&-> *math-camera* hmge-scale quad)) + (let ((s0-0 (-> arg0 base)) + (s4-0 0) + (s5-0 0) + ) + (&+! (-> arg0 base) 16) + (let* ((s3-0 *sprite-aux-list*) + (s2-0 (-> s3-0 entry)) + ) + (dotimes (s1-0 s2-0) + (let ((v1-5 (-> s3-0 data s1-0))) + (when (= (-> v1-5 aux-type) (sprite-aux-type distort)) + (set! sv-16 (-> v1-5 vec-data)) + (let ((a0-3 (the-as object (-> arg0 base)))) + (set! sv-32 (the-as vector (&+ (the-as pointer a0-3) 16))) + (set! sv-48 (the-as vector (&+ (the-as pointer a0-3) 32))) + (cond + ((= (the-as int (-> sv-16 flag-rot-sy y)) 1) + (.lvf vf3 (&-> *math-camera* sprite-2d rvec quad)) + (.lvf vf4 (&-> *math-camera* sprite-2d uvec quad)) + (.lvf vf5 (&-> *math-camera* sprite-2d fvec quad)) + (.lvf vf6 (&-> *math-camera* sprite-2d trans quad)) + (.lvf vf9 (&-> *math-camera* sprite-2d-hvdf quad)) + (.mov v1-15 vf9) + ) + (else + (.lvf vf3 (&-> *math-camera* camera-temp rvec quad)) + (.lvf vf4 (&-> *math-camera* camera-temp uvec quad)) + (.lvf vf5 (&-> *math-camera* camera-temp fvec quad)) + (.lvf vf6 (&-> *math-camera* camera-temp trans quad)) + (.lvf vf9 (&-> *math-camera* hvdf-off quad)) + (.mov v1-21 vf9) + ) + ) + (.lvf vf1 (&-> sv-16 x-y-z-sx quad)) + (.lvf vf2 (&-> sv-16 r-g-b-a quad)) + (.mul.w.vf acc vf6 vf0) + (.add.mul.x.vf acc vf3 vf1 acc) + (.add.mul.y.vf acc vf4 vf1 acc) + (.add.mul.z.vf vf1 vf5 vf1 acc) + (.mul.vf vf10 vf1 vf8) + (.div.vf Q vf0 vf10 :fsf #b11 :ftf #b11) + ;; (TODO.VCLIP vf10 vf10) og:preserve-this + (b! (zero? (-> sv-16 flag-rot-sy x)) cfg-22 :delay (nop!)) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b111) + (.mul.vf vf2 vf2 Q :mask #b111) + (set! v1-26 (vu-clip vf10 0)) ;; safe to just drop the higher bits. og:preserve-this + ;; (.cfc2.i v1-26 Clipping) + (b! (logtest? v1-26 63) cfg-22 :delay (.add.vf vf1 vf1 vf9)) + (.max.x.vf vf1 vf1 vf0 :mask #b1000) + (.svf (&-> (the-as vector a0-3) quad) vf1) + (.svf (&-> sv-48 quad) vf2) + (set! (-> (the-as vector a0-3) w) 255.0) + (set! (-> sv-32 x) (+ 0.0009765625 (* 0.001953125 (+ -1792.0 (-> (the-as vector a0-3) x))))) + (set! (-> sv-32 y) (+ 0.0009765625 (* 0.001953125 (+ -1840.0 (-> (the-as vector a0-3) y))))) + ) + (set! (-> sv-32 z) 1.0) + (when (or (< (the-as int (-> sv-16 flag-rot-sy x)) 3) (< 11 (the-as int (-> sv-16 flag-rot-sy x)))) + (format 0 "Turns = ~D!!!~%" (-> sv-16 flag-rot-sy x)) + (set! (-> sv-16 flag-rot-sy x) (the-as float #xb)) + ) + (set! (-> sv-32 w) (-> sv-16 flag-rot-sy x)) + (let* ((f1-4 (- (-> *math-camera* perspective uvec y))) + (f2-4 (-> sv-32 y)) + (f4-0 (+ f2-4 (* (-> sv-48 x) f1-4))) + (f3-2 256.0) + (f0-9 (-> sv-48 x)) + ) + (if (< 416.0 f4-0) + (set! f3-2 (/ (- 416.0 f2-4) f1-4)) + ) + (if (< 128.0 f3-2) + (set! f3-2 128.0) + ) + (when (< f3-2 f0-9) + (let ((v1-63 (/ f3-2 f0-9))) + (.mov vf1 v1-63) + ) + (.mul.x.vf vf2 vf2 vf1) + (.svf (&-> sv-48 quad) vf2) + (.mov v1-65 vf2) + ) + ) + (&+! (-> arg0 base) 48) + (+! s4-0 1) + (when (= s4-0 85) + (let ((v1-70 (-> arg0 base))) + (set! (-> arg0 base) s0-0) + (let* ((a0-10 arg0) + (a1-3 (the-as dma-packet (-> a0-10 base))) + ) + (set! (-> a1-3 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc (* 3 s4-0))) + (set! (-> a1-3 vif0) (new 'static 'vif-tag)) + (set! (-> a1-3 vif1) + (new 'static 'vif-tag :cmd (vif-cmd unpack-v4-32) :imm (shr (shl (+ (* 3 s5-0) 512) 54) 54) :num (* 3 s4-0)) + ) + (set! (-> a0-10 base) (the-as pointer (&+ a1-3 16))) + ) + (set! (-> arg0 base) v1-70) + ) + (set! s4-0 0) + (+! s5-0 85) + (when (= s5-0 170) + (let* ((v1-73 arg0) + (a0-11 (the-as dma-packet (-> v1-73 base))) + ) + (set! (-> a0-11 dma) (new 'static 'dma-tag :qwc #x1 :id (dma-tag-id cnt))) + (set! (-> a0-11 vif0) (new 'static 'vif-tag)) + (set! (-> a0-11 vif1) (new 'static 'vif-tag :imm #x1ff :num #x1 :cmd (vif-cmd unpack-v4-32))) + (set! (-> v1-73 base) (the-as pointer (&+ a0-11 16))) + ) + (let* ((v1-74 arg0) + (a0-13 (the-as vector4w (-> v1-74 base))) + ) + (set! (-> a0-13 x) s5-0) + (set! (-> a0-13 y) 0) + (set! (-> a0-13 z) 0) + (set! (-> a0-13 w) 0) + (set! (-> v1-74 base) (the-as pointer (&+ a0-13 16))) + ) + (let* ((v1-75 arg0) + (a0-15 (the-as dma-packet (-> v1-75 base))) + ) + (set! (-> a0-15 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a0-15 vif0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> a0-15 vif1) (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1)) + (set! (-> v1-75 base) (the-as pointer (&+ a0-15 16))) + ) + (set! s5-0 0) + ) + (set! s0-0 (-> arg0 base)) + (&+! (-> arg0 base) 16) + ) + ) + ) + (label cfg-22) + 0 + ) + ) + (cond + ((zero? s4-0) + (set! (-> arg0 base) s0-0) + (nop!) + 0 + ) + (else + (let ((v1-83 (-> arg0 base))) + (set! (-> arg0 base) s0-0) + (let* ((a0-17 arg0) + (a1-10 (the-as dma-packet (-> a0-17 base))) + ) + (set! (-> a1-10 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc (* 3 s4-0))) + (set! (-> a1-10 vif0) (new 'static 'vif-tag)) + (set! (-> a1-10 vif1) + (new 'static 'vif-tag :cmd (vif-cmd unpack-v4-32) :imm (shr (shl (+ (* 3 s5-0) 512) 54) 54) :num (* 3 s4-0)) + ) + (set! (-> a0-17 base) (the-as pointer (&+ a1-10 16))) + ) + (set! (-> arg0 base) v1-83) + ) + ) + ) + (let ((v1-84 (+ s4-0 s5-0))) + (when (nonzero? v1-84) + (let* ((a0-19 arg0) + (a1-12 (the-as dma-packet (-> a0-19 base))) + ) + (set! (-> a1-12 dma) (new 'static 'dma-tag :qwc #x1 :id (dma-tag-id cnt))) + (set! (-> a1-12 vif0) (new 'static 'vif-tag)) + (set! (-> a1-12 vif1) (new 'static 'vif-tag :imm #x1ff :num #x1 :cmd (vif-cmd unpack-v4-32))) + (set! (-> a0-19 base) (the-as pointer (&+ a1-12 16))) + ) + (let* ((a0-20 arg0) + (a1-14 (the-as vector4w (-> a0-20 base))) + ) + (set! (-> a1-14 x) v1-84) + (set! (-> a1-14 y) 0) + (set! (-> a1-14 z) 0) + (set! (-> a1-14 w) 0) + (set! (-> a0-20 base) (the-as pointer (&+ a1-14 16))) + ) + (let ((v1-86 (the-as dma-packet (-> arg0 base)))) + (set! (-> v1-86 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> v1-86 vif0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> v1-86 vif1) (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1)) + (set! (-> arg0 base) (the-as pointer (&+ v1-86 16))) + ) + ) + ) + ) + 0 + (none) + ) + ) diff --git a/goal_src/jak3/engine/gfx/sprite/sprite-glow.gc b/goal_src/jak3/engine/gfx/sprite/sprite-glow.gc index 5e48d74c7..5a0813144 100644 --- a/goal_src/jak3/engine/gfx/sprite/sprite-glow.gc +++ b/goal_src/jak3/engine/gfx/sprite/sprite-glow.gc @@ -7,3 +7,761 @@ ;; DECOMP BEGINS +(deftype sprite-glow-template (structure) + "Sprite glow GS data templates sent to VU1." + ((clear-init-giftag gs-gif-tag :inline) + (clear-init-adcmds gs-adcmd 5 :inline) + (clear-draw-giftag gs-gif-tag :inline) + (clear-draw-clr-0 gs-packed-rgba :inline) + (clear-draw-xyz-0 gs-packed-xyzw 2 :inline) + (clear-draw-clr-1 gs-packed-rgba :inline) + (clear-draw-xyz-1 vector 2 :inline) + (offscr-setup-giftag gs-gif-tag :inline) + (offscr-setup-adcmds gs-adcmd 8 :inline) + (offscr-first-giftag gs-gif-tag :inline) + (offscr-first-clr gs-packed-rgba :inline) + (offscr-first-uv-0 gs-packed-uv :inline) + (offscr-first-xyzw-0 gs-packed-xyzw :inline) + (offscr-first-uv-1 gs-packed-uv :inline) + (offscr-first-xyzw-1 gs-packed-xyzw :inline) + (repeat-draw-giftag gs-gif-tag :inline) + (repeat-draw-adcmds gs-adcmd 29 :inline) + (flare-alpha-giftag gs-gif-tag :inline) + (flare-alpha-clr gs-packed-rgba :inline) + (flare-alpha-uv gs-packed-uv :inline) + (flare-alpha-xyzw-0 gs-packed-xyzw :inline) + (flare-alpha-xyzw-1 gs-packed-xyzw :inline) + (flare-alpha-xyzw-2 gs-packed-xyzw :inline) + (flare-alpha-xyzw-3 gs-packed-xyzw :inline) + (flare-init-giftag gs-gif-tag :inline) + (flare-init-adcmds gs-adcmd 8 :inline) + (flare-draw-giftag gs-gif-tag :inline) + (flare-draw-clr gs-packed-rgba :inline) + (flare-draw-stq-0 gs-packed-stq :inline) + (flare-draw-xyzw-0 gs-packed-xyzw :inline) + (flare-draw-stq-1 gs-packed-stq :inline) + (flare-draw-xyzw-1 gs-packed-xyzw :inline) + (flare-draw-stq-2 gs-packed-stq :inline) + (flare-draw-xyzw-2 gs-packed-xyzw :inline) + (flare-draw-stq-3 gs-packed-stq :inline) + (flare-draw-xyzw-3 gs-packed-xyzw :inline) + ) + ) + + +(deftype sprite-glow-consts (structure) + "Per-frame constants for sprite-glow VU1." + ((camera matrix :inline) + (perspective matrix :inline) + (hvdf-offset vector :inline) + (hmge-scale vector :inline) + (consts vector :inline) + (pfog0 float :overlay-at (-> consts data 0)) + (deg-to-rad float :overlay-at (-> consts data 1)) + (min-scale float :overlay-at (-> consts data 2)) + (inv-area float :overlay-at (-> consts data 3)) + (sincos-01 vector :inline) + (sincos-23 vector :inline) + (sincos-45 vector :inline) + (sincos-67 vector :inline) + (sincos-89 vector :inline) + (basis-x vector :inline) + (basis-y vector :inline) + (xy-array vector 4 :inline) + (clamp-min vector :inline) + (clamp-max vector :inline) + ) + ) + + +(define *sprite-glow-template* + (new 'static 'sprite-glow-template + :clear-init-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x5 :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :clear-init-adcmds (new 'static 'inline-array gs-adcmd 5 + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 alpha-1) :x #x6a) + (new 'static 'gs-adcmd :cmds (gs-reg64 test-1) :x #x51001) + (new 'static 'gs-adcmd :cmds (gs-reg64 zbuf-1) :x #x1000130 :y #x1) + (new 'static 'gs-adcmd :cmds (gs-reg64 frame-1) :x #x80198 :y #xffffff) + ) + :clear-draw-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x2 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite)) + :nreg #x3 + ) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) :regs1 (gif-reg-id xyzf2) :regs2 (gif-reg-id xyzf2)) + ) + :clear-draw-xyz-0 (new 'static 'inline-array gs-packed-xyzw 2 + (new 'static 'gs-packed-xyzw :iz -1) + (new 'static 'gs-packed-xyzw :iz -1) + ) + :clear-draw-clr-1 (new 'static 'gs-packed-rgba :x #xff :w #xff) + :offscr-setup-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x8 :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :offscr-setup-adcmds (new 'static 'inline-array gs-adcmd 8 + (new 'static 'gs-adcmd :cmds (gs-reg64 frame-2) :x #x10090 :y #xffffff) + (new 'static 'gs-adcmd :cmds (gs-reg64 zbuf-2) :x #x1000130) + (new 'static 'gs-adcmd :cmds (gs-reg64 tex1-2) :x #x60) + (new 'static 'gs-adcmd :cmds (gs-reg64 tex0-2) :x #x64023300 :y #xe) + (new 'static 'gs-adcmd :cmds (gs-reg64 clamp-2) :x #x5) + (new 'static 'gs-adcmd :cmds (gs-reg64 test-2) :x #x31001) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyoffset-2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + ) + :offscr-first-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1 :fst #x1 :ctxt #x1) + :nreg #x5 + ) + :regs (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id uv) + :regs2 (gif-reg-id xyz2) + :regs3 (gif-reg-id uv) + :regs4 (gif-reg-id xyz2) + ) + ) + :offscr-first-clr (new 'static 'gs-packed-rgba :x #x80 :y #x80 :z #x80 :w #x80) + :offscr-first-xyzw-1 (new 'static 'gs-packed-xyzw :ix #x200 :iy #x200) + :repeat-draw-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x1d :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :repeat-draw-adcmds (new 'static 'inline-array gs-adcmd 29 + (new 'static 'gs-adcmd :cmds (gs-reg64 tex0-2) :x #x54005200 :y #xd) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x100010) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x2100210) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2) :x #x1000100) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x100010) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x1100110) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2) :x #x800080) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x100010) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x900090) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2) :x #x400040) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x100010) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x500050) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2) :x #x200020) + (new 'static 'gs-adcmd :cmds (gs-reg64 frame-2) :x #x80198 :y #xffffff) + (new 'static 'gs-adcmd :cmds (gs-reg64 test-2) :x #x51001) + (new 'static 'gs-adcmd :cmds (gs-reg64 zbuf-2) :x #x1000130 :y #x1) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyoffset-2) :x #x7000 :y #x7300) + (new 'static 'gs-adcmd :cmds (gs-reg64 scissor-2) :x #x1ff0000 :y #x19f0000) + (new 'static 'gs-adcmd :cmds (gs-reg64 test-2) :x #x50000) + (new 'static 'gs-adcmd :cmds (gs-reg64 alpha-2) :x #x6a) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + ) + :flare-alpha-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fst #x1 :ctxt #x1) + :nreg #x6 + ) + :regs (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id uv) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id xyzf2) + :regs4 (gif-reg-id xyzf2) + :regs5 (gif-reg-id xyzf2) + ) + ) + :flare-alpha-clr (new 'static 'gs-packed-rgba :x #x80 :y #x80 :z #x80 :w #x80) + :flare-alpha-uv (new 'static 'gs-packed-uv :x (the-as float #x10) :y (the-as float #x10)) + :flare-alpha-xyzw-0 (new 'static 'gs-packed-xyzw :iz -1) + :flare-alpha-xyzw-1 (new 'static 'gs-packed-xyzw :iz -1) + :flare-alpha-xyzw-2 (new 'static 'gs-packed-xyzw :iz -1) + :flare-alpha-xyzw-3 (new 'static 'gs-packed-xyzw :iz -1) + :flare-init-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x8 :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :flare-init-adcmds (new 'static 'inline-array gs-adcmd 8 + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 frame-1) :x #x80198) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 alpha-1) :x #x58) + ) + :flare-draw-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :abe #x1) + :nreg #x9 + ) + :regs (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyzf2) + :regs5 (gif-reg-id st) + :regs6 (gif-reg-id xyzf2) + :regs7 (gif-reg-id st) + :regs8 (gif-reg-id xyzf2) + ) + ) + :flare-draw-clr (new 'static 'gs-packed-rgba :y 64 :w #x80) + :flare-draw-stq-0 (new 'static 'gs-packed-stq :z 1.0) + :flare-draw-xyzw-0 (new 'static 'gs-packed-xyzw :iz -1) + :flare-draw-stq-1 (new 'static 'gs-packed-stq :x 1.0 :z 1.0) + :flare-draw-xyzw-1 (new 'static 'gs-packed-xyzw :iz -1) + :flare-draw-stq-2 (new 'static 'gs-packed-stq :x 1.0 :y 1.0 :z 1.0) + :flare-draw-xyzw-2 (new 'static 'gs-packed-xyzw :iz -1) + :flare-draw-stq-3 (new 'static 'gs-packed-stq :y 1.0 :z 1.0) + :flare-draw-xyzw-3 (new 'static 'gs-packed-xyzw :iz -1) + ) + ) + +(define sprite-glow-vu1-block (new 'static 'vu-function :length #x86 :qlength 67)) + +;; WARN: Return type mismatch vector vs none. +(defun sprite-glow-init-consts ((arg0 sprite-glow-consts)) + "Fill out sprite-glow-consts to be sent to VU1." + (let ((v1-0 *math-camera*)) + (let* ((t0-0 (-> arg0 camera)) + (t1-0 (-> v1-0 camera-rot)) + (a1-0 (-> t1-0 rvec quad)) + (a2-0 (-> t1-0 uvec quad)) + (a3-0 (-> t1-0 fvec quad)) + (t1-1 (-> t1-0 trans quad)) + ) + (set! (-> t0-0 rvec quad) a1-0) + (set! (-> t0-0 uvec quad) a2-0) + (set! (-> t0-0 fvec quad) a3-0) + (set! (-> t0-0 trans quad) t1-1) + ) + (let* ((t0-1 (-> arg0 perspective)) + (t1-2 (-> v1-0 perspective)) + (a1-1 (-> t1-2 rvec quad)) + (a2-1 (-> t1-2 uvec quad)) + (a3-1 (-> t1-2 fvec quad)) + (t1-3 (-> t1-2 trans quad)) + ) + (set! (-> t0-1 rvec quad) a1-1) + (set! (-> t0-1 uvec quad) a2-1) + (set! (-> t0-1 fvec quad) a3-1) + (set! (-> t0-1 trans quad) t1-3) + ) + (set! (-> arg0 hvdf-offset quad) (-> v1-0 hvdf-off quad)) + (set! (-> arg0 hmge-scale quad) (-> v1-0 hmge-scale quad)) + (set! (-> arg0 basis-x quad) (the-as uint128 0)) + (set! (-> arg0 basis-x x) (- (-> *math-camera* perspective rvec x))) + (set! (-> arg0 basis-y quad) (the-as uint128 0)) + (set! (-> arg0 basis-y y) (- (-> *math-camera* perspective uvec y))) + (set! (-> arg0 consts x) (-> v1-0 pfog0)) + ) + (set! (-> arg0 consts y) 0.000095873795) + (set! (-> arg0 consts z) (sqrtf (* (/ 1.0 (-> arg0 basis-x x)) (/ 1.0 (-> arg0 basis-y y))))) + (set! (-> arg0 consts w) (/ 1.0 (* (-> arg0 consts z) (-> arg0 consts z)))) + (let ((v1-5 (-> arg0 sincos-01))) + (set! (-> v1-5 z) 0.999998) + (set! (-> v1-5 w) 1.0) + ) + (let ((v1-6 (-> arg0 sincos-23))) + (set! (-> v1-6 z) -0.16666014) + (set! (-> v1-6 w) -0.49998003) + ) + (let ((v1-7 (-> arg0 sincos-45))) + (set! (-> v1-7 z) 0.008326521) + (set! (-> v1-7 w) 0.041620404) + ) + (let ((v1-8 (-> arg0 sincos-67))) + (set! (-> v1-8 z) -0.0001956241) + (set! (-> v1-8 w) -0.0013636408) + ) + (let ((v1-9 (-> arg0 sincos-89))) + (set! (-> v1-9 z) 0.0000023042373) + (set! (-> v1-9 w) 0.000020170546) + ) + (set-vector! (-> arg0 xy-array 0) -0.5 -0.5 0.0 0.0) + (set-vector! (-> arg0 xy-array 1) 0.5 -0.5 0.0 0.0) + (set-vector! (-> arg0 xy-array 2) 0.5 0.5 0.0 0.0) + (set-vector! (-> arg0 xy-array 3) -0.5 0.5 0.0 0.0) + (set-vector! (-> arg0 clamp-min) 1792.0 1840.0 0.0 0.0) + (set-vector! (-> arg0 clamp-max) 2304.0 2256.0 2048.0 50.0) + (none) + ) + +(defun sprite-glow-init-engine ((arg0 dma-buffer)) + "Generate DMA to initialize sprite-glow VU1." + (dma-buffer-add-vu-function arg0 sprite-glow-vu1-block 1) + (let ((s5-0 24)) + (let* ((v1-0 arg0) + (a0-2 (the-as dma-packet (-> v1-0 base))) + ) + (set! (-> a0-2 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc s5-0)) + (set! (-> a0-2 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> a0-2 vif1) (new 'static 'vif-tag :imm #x3d4 :cmd (vif-cmd unpack-v4-32) :num s5-0)) + (set! (-> v1-0 base) (the-as pointer (&+ a0-2 16))) + ) + (sprite-glow-init-consts (the-as sprite-glow-consts (-> arg0 base))) + (&+! (-> arg0 base) (* s5-0 16)) + ) + (let ((v1-3 84)) + (let* ((a0-6 arg0) + (a1-6 (the-as dma-packet (-> a0-6 base))) + ) + (set! (-> a1-6 dma) + (new 'static 'dma-tag :id (dma-tag-id ref) :addr (the-as int *sprite-glow-template*) :qwc v1-3) + ) + (set! (-> a1-6 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> a1-6 vif1) (new 'static 'vif-tag :imm #x320 :cmd (vif-cmd unpack-v4-32) :num v1-3)) + (set! (-> a0-6 base) (the-as pointer (&+ a1-6 16))) + ) + (let* ((a0-7 arg0) + (a1-8 (the-as dma-packet (-> a0-7 base))) + ) + (set! (-> a1-8 dma) + (new 'static 'dma-tag :id (dma-tag-id ref) :addr (the-as int *sprite-glow-template*) :qwc v1-3) + ) + (set! (-> a1-8 vif0) (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm #x0)) + (set! (-> a1-8 vif1) (new 'static 'vif-tag :imm #x374 :cmd (vif-cmd unpack-v4-32) :num v1-3)) + (set! (-> a0-7 base) (the-as pointer (&+ a1-8 16))) + ) + ) + (let* ((v1-8 arg0) + (a0-8 (the-as dma-packet (-> v1-8 base))) + ) + (set! (-> a0-8 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a0-8 vif0) (new 'static 'vif-tag :cmd (vif-cmd base))) + (set! (-> a0-8 vif1) (new 'static 'vif-tag :imm #x190 :cmd (vif-cmd offset))) + (set! (-> v1-8 base) (the-as pointer (&+ a0-8 16))) + ) + (let ((v1-9 (the-as dma-packet (-> arg0 base)))) + (set! (-> v1-9 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> v1-9 vif0) (new 'static 'vif-tag)) + (set! (-> v1-9 vif1) (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1)) + (set! (-> arg0 base) (the-as pointer (&+ v1-9 16))) + ) + 0 + (none) + ) + +(deftype sprite-glow-dma-packet-data (structure) + "DMA templates for generating DMA to VU1." + ((control-packet dma-packet :inline) + (vecdata-packet dma-packet :inline) + (shader-cnt-packet dma-packet :inline) + (shader-ref-packet dma-packet :inline) + (mscal-packet dma-packet :inline) + ) + ) + + +(deftype sprite-glow-cnt-template (structure) + "DMA layout for sending a sprite to VU1, with inline shader." + ((control-packet dma-packet :inline) + (num-sprites uint32) + (dummys uint32 3) + (vecdata-packet dma-packet :inline) + (vecdata sprite-glow-data :inline) + (shader-packet dma-packet :inline) + (shader adgif-shader :inline) + (mscal-packet dma-packet :inline) + (quads vector 10 :inline :overlay-at (-> control-packet dma)) + ) + ) + + +(deftype sprite-glow-ref-template (structure) + "DMA layout for sending a sprite to VU1, with reference to shader." + ((control-packet dma-packet :inline) + (num-sprites uint32) + (dummys uint32 3) + (num-sprites-quad uint128 :overlay-at num-sprites) + (vecdata-packet dma-packet :inline) + (vecdata sprite-glow-data :inline) + (shader-packet dma-packet :inline) + (shader-packet-ptr pointer :offset 116) + (mscal-packet dma-packet :inline) + ) + ) + + +(define *sprite-glow-dma-packet-data* + (new 'static 'sprite-glow-dma-packet-data + :control-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x1 :id (dma-tag-id cnt)) + :vif0 (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + :vif1 (new 'static 'vif-tag :imm #x8000 :num #x1 :cmd (vif-cmd unpack-v4-32)) + ) + :vecdata-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif0 (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + :vif1 (new 'static 'vif-tag :imm #x8001 :num #x4 :cmd (vif-cmd unpack-v4-32)) + ) + :shader-cnt-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x5 :id (dma-tag-id cnt)) + :vif0 (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + :vif1 (new 'static 'vif-tag :imm #x8091 :num #x5 :cmd (vif-cmd unpack-v4-32)) + ) + :shader-ref-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x5 :id (dma-tag-id ref)) + :vif0 (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + :vif1 (new 'static 'vif-tag :imm #x8091 :num #x5 :cmd (vif-cmd unpack-v4-32)) + ) + :mscal-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1) + ) + ) + ) + +(set! (-> *sprite-glow-dma-packet-data* mscal-packet vif0) + (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1 :imm #xa) + ) + +;; WARN: Return type mismatch sprite-glow-cnt-template vs none. +(defun sprite-glow-add-sprite ((arg0 dma-buffer) (arg1 sprite-vec-data-2d) (arg2 float) (arg3 float) (arg4 float) (arg5 adgif-shader)) + "Generate DMA to draw a single sprite from the aux-list." + (let ((v1-0 (the-as sprite-glow-cnt-template (-> arg0 base)))) + (let* ((t5-0 *sprite-glow-dma-packet-data*) + (t2-0 (-> t5-0 control-packet quad)) + (t3-0 (-> t5-0 vecdata-packet quad)) + (t4-0 (-> t5-0 shader-cnt-packet quad)) + (t5-1 (-> t5-0 mscal-packet quad)) + ) + (set! (-> v1-0 control-packet quad) t2-0) + (set! (-> v1-0 quads 1 quad) (the-as uint128 0)) + (set! (-> v1-0 vecdata-packet quad) t3-0) + (set! (-> v1-0 shader-packet quad) t4-0) + (set! (-> v1-0 mscal-packet quad) t5-1) + ) + (let ((t2-1 (-> arg1 x-y-z-sx quad)) + (t3-1 (-> arg1 flag-rot-sy quad)) + (a1-1 (-> arg1 r-g-b-a quad)) + ) + (set! (-> v1-0 vecdata position quad) t2-1) + (set! (-> v1-0 vecdata quads 1 quad) t3-1) + (set! (-> v1-0 vecdata color quad) a1-1) + ) + (let ((a1-2 1)) + (set! (-> v1-0 vecdata z-offset) arg4) + (set! (-> v1-0 vecdata fade-a) arg2) + (set! (-> v1-0 vecdata fade-b) arg3) + (set! (-> v1-0 num-sprites) (the-as uint a1-2)) + ) + (let ((a1-3 (-> arg5 quad 0 quad)) + (a2-1 (-> arg5 quad 1 quad)) + (a3-1 (-> arg5 quad 2 quad)) + (t0-1 (-> arg5 quad 3 quad)) + (t1-1 (-> arg5 quad 4 quad)) + ) + (set! (-> v1-0 quads 8 quad) a1-3) + (set! (-> v1-0 quads 9 quad) a2-1) + (set! (-> v1-0 shader quad 2 quad) a3-1) + (set! (-> v1-0 shader quad 3 quad) t0-1) + (set! (-> v1-0 shader quad 4 quad) t1-1) + ) + (set! (-> arg0 base) (the-as pointer (&+ v1-0 224))) + ) + (none) + ) + +;; WARN: Return type mismatch sprite-glow-ref-template vs none. +(defun sprite-glow-add-simple-sprite ((arg0 dma-buffer) (arg1 sprite-glow-dma-packet-data) (arg2 sprite-glow-data) (arg3 pointer)) + "Generate DMA to draw a single sprite from the simple sprite system." + (let ((v1-0 (the-as sprite-glow-ref-template (-> arg0 base)))) + (let ((t0-0 (-> arg1 control-packet quad)) + (t1-0 (-> arg1 vecdata-packet quad)) + (t2-0 (-> arg1 shader-ref-packet quad)) + (a1-1 (-> arg1 mscal-packet quad)) + ) + (set! (-> v1-0 control-packet quad) t0-0) + (set! (-> v1-0 num-sprites-quad) (the-as uint128 0)) + (set! (-> v1-0 vecdata-packet quad) t1-0) + (set! (-> v1-0 shader-packet quad) t2-0) + (set! (-> v1-0 mscal-packet quad) a1-1) + ) + (let ((a1-2 (-> arg2 position quad)) + (t0-1 (-> arg2 quads 1 quad)) + (t1-1 (-> arg2 color quad)) + (a2-1 (-> arg2 quads 3 quad)) + (t2-1 1) + ) + (set! (-> v1-0 vecdata position quad) a1-2) + (set! (-> v1-0 vecdata quads 1 quad) t0-1) + (set! (-> v1-0 vecdata color quad) t1-1) + (set! (-> v1-0 vecdata quads 3 quad) a2-1) + (set! (-> v1-0 num-sprites) (the-as uint t2-1)) + ) + (set! (-> v1-0 shader-packet-ptr) arg3) + (set! (-> arg0 base) (the-as pointer (&+ v1-0 144))) + ) + (none) + ) + +(defun sprite-glow-draw ((arg0 dma-buffer)) + "Generate DMA for all glow sprites in the aux-list (from sparticle system)" + (local-vars (a2-0 float)) + (let* ((s5-0 *sprite-aux-list*) + (s4-0 (-> s5-0 entry)) + (s3-0 #f) + ) + (dotimes (s2-0 s4-0) + (let ((v1-2 (-> s5-0 data s2-0))) + (when (and (not s3-0) (= (-> v1-2 aux-type) (sprite-aux-type glow))) + (let* ((a0-5 (-> v1-2 aux-data omega)) + (a3-0 (cond + ((zero? a0-5) + (set! a2-0 0.0) + 1.0 + ) + (else + (let* ((f1-1 (* 0.00024414062 a0-5)) + (f0-4 (- f1-1 (the float (the int f1-1)))) + ) + (let ((f1-3 (* 4096.0 (- f1-1 f0-4)))) + (set! a2-0 (/ -1.0 (* (- 1.0 f0-4) f1-3))) + ) + (/ f0-4 (- 1.0 f0-4)) + ) + ) + ) + ) + ) + (sprite-glow-add-sprite arg0 (-> v1-2 vec-data) a2-0 a3-0 (-> v1-2 aux-data user-float) (-> v1-2 gif-data)) + ) + ) + ) + ) + ) + 0 + (none) + ) + +(defmethod add! ((this simple-sprite-system) (arg0 sprite-glow-data)) + "Add a sprite to the list, to be drawn later." + (let ((v1-0 (-> this count))) + (when (< v1-0 (-> this max-count)) + (let* ((a2-3 (-> this data v1-0)) + (v1-2 arg0) + (a1-1 a2-3) + (a2-4 (-> v1-2 position quad)) + (a3-0 (-> v1-2 quads 1 quad)) + (t0-0 (-> v1-2 color quad)) + (v1-3 (-> v1-2 quads 3 quad)) + ) + (set! (-> a1-1 position quad) a2-4) + (set! (-> a1-1 quads 1 quad) a3-0) + (set! (-> a1-1 color quad) t0-0) + (set! (-> a1-1 quads 3 quad) v1-3) + ) + (+! (-> this count) 1) + ) + ) + 0 + (none) + ) + +;; WARN: Return type mismatch pointer vs adgif-shader. +(defun add-shader-to-dma ((arg0 dma-buffer)) + (let* ((a1-0 (new 'static 'dma-packet :dma (new 'static 'dma-tag :id (dma-tag-id next)))) + (v1-0 (-> arg0 base)) + (a1-1 (-> a1-0 quad)) + (v0-0 (&+ v1-0 16)) + ) + (let ((a2-0 (&+ v1-0 96))) + (set! (-> (the-as (pointer uint128) v1-0)) a1-1) + (set! (-> (the-as (pointer uint32) v1-0) 1) (the-as uint a2-0)) + (set! (-> arg0 base) a2-0) + ) + (the-as adgif-shader v0-0) + ) + ) + +(defmethod draw-all-sprites! ((this simple-sprite-system) (arg0 dma-buffer)) + "Submit all sprites to the sprite-glow renderer" + (local-vars (sv-528 sprite-glow-dma-packet-data) (sv-532 (pointer texture-id)) (sv-536 pointer)) + (b! (zero? (-> this count)) cfg-13 :delay (nop!)) + (set! sv-528 *sprite-glow-dma-packet-data*) + (set! sv-532 (new 'stack-no-clear 'array 'texture-id 128)) + (set! sv-536 (-> arg0 base)) + (dotimes (v1-5 (-> this count)) + (set! (-> sv-532 v1-5) (-> this data v1-5 tex-id)) + ) + (countdown (s4-0 (-> this count)) + (let ((s3-0 (-> sv-532 s4-0))) + (when (nonzero? s3-0) + (let ((s2-0 (add-shader-to-dma arg0))) + (adgif-shader<-texture-simple! s2-0 (lookup-texture-by-id s3-0)) + (countdown (s1-1 (+ s4-0 1)) + (when (= s3-0 (-> sv-532 s1-1)) + (set! (-> sv-532 s1-1) (new 'static 'texture-id)) + (let ((a2-1 (-> this data s1-1))) + (sprite-glow-add-simple-sprite arg0 sv-528 a2-1 (the-as pointer s2-0)) + ) + ) + ) + ) + ) + ) + ) + (label cfg-13) + 0 + (none) + ) + +(defmethod clear! ((this simple-sprite-system)) + "Reset the list." + (set! (-> this count) 0) + 0 + (none) + ) + +(define *simple-sprite-system* + (new 'static 'simple-sprite-system :max-count #x80 :data (new 'static 'inline-array sprite-glow-data 128 + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + ) + ) + ) diff --git a/test/decompiler/reference/jak3/decompiler-macros.gc b/test/decompiler/reference/jak3/decompiler-macros.gc index 1baaac1b0..532e548ff 100644 --- a/test/decompiler/reference/jak3/decompiler-macros.gc +++ b/test/decompiler/reference/jak3/decompiler-macros.gc @@ -1538,4 +1538,20 @@ (defmacro current-frame () `(-> *display* frames (-> *display* on-screen)) - ) \ No newline at end of file + ) + +(defmacro vftoi4.xyzw (dst src) + "convert to 28.4 integer. This does the multiply while the number is still + a float. This will have issues for very large floats, but it seems like this + is how PCSX2 does it as well, so maybe it's right? + NOTE: this is the only version of the instruction used in Jak 1, so we + don't need to worry about masks." + + `(begin + (rlet ((temp :class vf)) + (set! temp 16.0) + (.mul.x.vf temp ,src temp) + (.ftoi.vf ,dst temp) + ) + ) + ) diff --git a/test/decompiler/reference/jak3/engine/debug/debug-sphere_REF.gc b/test/decompiler/reference/jak3/engine/debug/debug-sphere_REF.gc new file mode 100644 index 000000000..c621ffed7 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/debug/debug-sphere_REF.gc @@ -0,0 +1,103 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function make-debug-sphere-table +;; INFO: Used lq/sq +(defun make-debug-sphere-table ((arg0 vector-array) (arg1 float) (arg2 float)) + "Create a table of lines on a sphere." + (local-vars (sv-80 vector) (sv-96 vector) (sv-112 int)) + (let ((s2-0 (new-stack-vector0)) + (f30-0 1.0) + (s5-0 0) + ) + (set-vector! s2-0 0.0 0.0 0.0 1.0) + (dotimes (s1-0 (the int arg2)) + (let ((f28-0 (* f30-0 (sin (* (the float s1-0) (/ 32768.0 arg2))))) + (f26-0 (* f30-0 (sin (* (the float (+ s1-0 1)) (/ 32768.0 arg2))))) + (s0-0 (new-stack-vector0)) + ) + (set! sv-80 (new 'stack-no-clear 'vector)) + (set! (-> sv-80 quad) (the-as uint128 0)) + (set! sv-96 (new 'stack-no-clear 'vector)) + (set! (-> sv-96 quad) (the-as uint128 0)) + (set! (-> s0-0 y) (+ (-> s2-0 y) (* (cos (* (the float s1-0) (/ 32768.0 arg2))) f30-0))) + (set! (-> sv-80 y) (-> s0-0 y)) + (set! (-> sv-96 y) (+ (-> s2-0 y) (* (cos (* (the float (+ s1-0 1)) (/ 32768.0 arg2))) f30-0))) + (set! sv-112 0) + (while (< sv-112 (the int arg1)) + (set! (-> s0-0 x) (+ (-> s2-0 x) (* (cos (* (the float sv-112) (/ 65536.0 arg1))) f28-0))) + (set! (-> s0-0 z) (+ (-> s2-0 z) (* (sin (* (the float sv-112) (/ 65536.0 arg1))) f28-0))) + (set! (-> sv-80 x) (+ (-> s2-0 x) (* (cos (* (the float (+ sv-112 1)) (/ 65536.0 arg1))) f28-0))) + (set! (-> sv-80 z) (+ (-> s2-0 z) (* (sin (* (the float (+ sv-112 1)) (/ 65536.0 arg1))) f28-0))) + (set! (-> sv-96 x) (+ (-> s2-0 x) (* (cos (* (the float sv-112) (/ 65536.0 arg1))) f26-0))) + (set! (-> sv-96 z) (+ (-> s2-0 z) (* (sin (* (the float sv-112) (/ 65536.0 arg1))) f26-0))) + (set! (-> arg0 data s5-0 quad) (-> s0-0 quad)) + (set! (-> arg0 data (+ s5-0 1) quad) (-> sv-80 quad)) + (set! (-> arg0 data (+ s5-0 2) quad) (-> sv-96 quad)) + (+! s5-0 3) + (set! sv-112 (+ sv-112 1)) + ) + ) + ) + (set! (-> arg0 length) s5-0) + ) + arg0 + ) + +;; this part is debug only +(when *debug-segment* +;; definition for symbol *debug-sphere-table*, type (array vector-array) +(define *debug-sphere-table* (new 'debug 'boxed-array vector-array 10)) + +) +;; definition for function add-debug-sphere-from-table +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun add-debug-sphere-from-table ((arg0 bucket-id) (arg1 vector) (arg2 meters) (arg3 rgba) (arg4 int)) + "Draw a sphere out of debug lines, using the precomputed table of lines." + (local-vars (sv-32 vector-array) (sv-36 vector)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (if (zero? (-> *debug-sphere-table* arg4)) + (set! (-> *debug-sphere-table* arg4) + (make-debug-sphere-table (new 'debug 'vector-array (* (* 3 arg4) arg4)) (the float arg4) (the float arg4)) + ) + ) + (set! sv-32 (-> *debug-sphere-table* arg4)) + (set! sv-36 (the-as vector (new-stack-vector0))) + (let ((s2-1 (new-stack-vector0)) + (s1-1 (new-stack-vector0)) + (s0-0 (the-as object (-> sv-32 data))) + ) + (.lvf vf1 (&-> arg1 quad)) + (.mov vf2 arg2) + (countdown (s4-1 (/ (-> sv-32 length) 3)) + (.lvf vf3 (&-> (the-as (inline-array vector) s0-0) 0 quad)) + (.lvf vf4 (&-> (the-as (inline-array vector) s0-0) 1 quad)) + (.lvf vf5 (&-> (the-as (inline-array vector) s0-0) 2 quad)) + (set! s0-0 (-> (the-as (inline-array vector) s0-0) 3)) + (.mul.x.vf vf3 vf3 vf2) + (.mul.x.vf vf4 vf4 vf2) + (.mul.x.vf vf5 vf5 vf2) + (.add.vf vf3 vf3 vf1) + (.add.vf vf4 vf4 vf1) + (.add.vf vf5 vf5 vf1) + (.svf (&-> s2-1 quad) vf3) + (.svf (&-> s1-1 quad) vf4) + (.svf (&-> sv-36 quad) vf5) + (add-debug-line #t arg0 s2-1 s1-1 arg3 #f (the-as rgba -1)) + (add-debug-line #t arg0 s2-1 sv-36 arg3 #f (the-as rgba -1)) + ) + ) + 0 + (none) + ) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/debug/debug_REF.gc b/test/decompiler/reference/jak3/engine/debug/debug_REF.gc new file mode 100644 index 000000000..ca95dae97 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/debug/debug_REF.gc @@ -0,0 +1,1951 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function transform-float-point +;; ERROR: Bad vector register dependency: vf1 +;; ERROR: Bad vector register dependency: vf2 +;; ERROR: Bad vector register dependency: vf3 +;; ERROR: Bad vector register dependency: vf4 +;; ERROR: Bad vector register dependency: vf6 +;; ERROR: Bad vector register dependency: vf8 +;; ERROR: Bad vector register dependency: vf9 +(defun transform-float-point ((src-world-pt vector) (dst-gs-screen-pt vector4w)) + "Transform a point, using the cached matrix in VU0 registers, set from init-for-transform. + The argument order is backward - be careful! + After transformation, point is constrained to be within some region, but this is not proper clipping, + so you should do this yourself." + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf5 (&-> src-world-pt quad)) + (.mul.w.vf acc vf4 vf5) + (.add.mul.x.vf acc vf1 vf5 acc) + (.add.mul.y.vf acc vf2 vf5 acc) + (.add.mul.z.vf vf5 vf3 vf5 acc) + (.div.vf Q vf9 vf5 :fsf #b0 :ftf #b11) + (.wait.vf) + (.mul.vf vf5 vf5 Q :mask #b111) + (.add.vf vf5 vf5 vf8) + (.max.x.vf vf5 vf5 vf0 :mask #b1000) + (.min.x.vf vf5 vf5 vf6 :mask #b1000) + (vftoi4.xyzw vf5 vf5) + (.svf (&-> dst-gs-screen-pt quad) vf5) + dst-gs-screen-pt + ) + ) + +;; definition (debug) for function add-debug-point +;; INFO: Used lq/sq +(defun-debug add-debug-point ((enable symbol) (bucket bucket-id) (pt vector)) + "Draw a point." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((s5-0 (new 'stack 'vector4w-2)) + (a1-2 (new 'stack-no-clear 'vector)) + ) + (set! (-> a1-2 quad) (-> pt quad)) + (set! (-> a1-2 w) 1.0) + (when (transform-point-qword! (the-as vector4w (-> s5-0 vector)) a1-2) + (with-dma-buffer-add-bucket ((v1-11 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((a0-6 (-> v1-11 base))) + (let* ((a1-3 v1-11) + (a3-0 (the-as dma-packet (-> a1-3 base))) + ) + (set! (-> a3-0 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a3-0 vif0) (new 'static 'vif-tag)) + (set! (-> a3-0 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-3 base) (the-as pointer (&+ a3-0 16))) + ) + (let* ((a1-4 v1-11) + (a3-2 (the-as gs-gif-tag (-> a1-4 base))) + ) + (set! (-> a3-2 tag) (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :abe #x1) + :nreg #x8 + ) + ) + (set! (-> a3-2 regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id xyzf2) + :regs2 (gif-reg-id rgbaq) + :regs3 (gif-reg-id xyzf2) + :regs4 (gif-reg-id rgbaq) + :regs5 (gif-reg-id xyzf2) + :regs6 (gif-reg-id rgbaq) + :regs7 (gif-reg-id xyzf2) + ) + ) + (set! (-> a1-4 base) (the-as pointer (&+ a3-2 16))) + ) + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 128) + (set! (-> s5-0 vector 1 w) 128) + (+! (-> s5-0 vector 0 y) 288) + (let* ((a1-11 v1-11) + (a3-4 (the-as vector4w-2 (-> a1-11 base))) + ) + (set! (-> a3-4 vector 0 quad) (-> s5-0 vector 1 quad)) + (set! (-> a3-4 vector 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a1-11 base) (the-as pointer (&+ a3-4 32))) + ) + (+! (-> s5-0 vector 0 x) -256) + (+! (-> s5-0 vector 0 y) -288) + (set! (-> s5-0 vector 1 x) 128) + (set! (-> s5-0 vector 1 y) 255) + (let* ((a1-18 v1-11) + (a3-6 (the-as vector4w-2 (-> a1-18 base))) + ) + (set! (-> a3-6 vector 0 quad) (-> s5-0 vector 1 quad)) + (set! (-> a3-6 vector 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a1-18 base) (the-as pointer (&+ a3-6 32))) + ) + (+! (-> s5-0 vector 0 x) 512) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 255) + (let* ((a1-23 v1-11) + (a3-8 (the-as vector4w-2 (-> a1-23 base))) + ) + (set! (-> a3-8 vector 0 quad) (-> s5-0 vector 1 quad)) + (set! (-> a3-8 vector 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a1-23 base) (the-as pointer (&+ a3-8 32))) + ) + (+! (-> s5-0 vector 0 x) -256) + (+! (-> s5-0 vector 0 y) -288) + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (let* ((a3-10 v1-11) + (a1-30 (the-as vector4w-2 (-> a3-10 base))) + ) + (set! (-> a1-30 vector 0 quad) (-> s5-0 vector 1 quad)) + (set! (-> a1-30 vector 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a3-10 base) (the-as pointer (&+ a1-30 32))) + ) + (let ((a3-14 (/ (the-as int (+ (- -16 (the-as int a0-6)) (the-as int (-> v1-11 base)))) 16))) + (cond + ((nonzero? a3-14) + (logior! (-> (the-as (pointer uint64) a0-6) 0) (shr (shl a3-14 48) 48)) + (logior! (-> (the-as (pointer uint64) a0-6) 1) (shl (shr (shl a3-14 48) 48) 32)) + ) + (else + (set! (-> v1-11 base) a0-6) + ) + ) + ) + ) + ) + ) + ) + #f + ) + +;; definition (debug) for function debug-line-clip? +;; INFO: function output is handled by mips2c +(def-mips2c debug-line-clip? (function vector vector vector vector symbol)) + +;; definition (debug) for function internal-draw-debug-line +;; INFO: Used lq/sq +;; WARN: Return type mismatch pointer vs symbol. +(defun-debug internal-draw-debug-line ((bucket bucket-id) (p0 vector) (p1 vector) (color rgba) (mode symbol) (color2 rgba)) + "Implementation of line drawing DMA." + (local-vars (sv-112 vector) (sv-128 vector) (sv-144 vector)) + (set! sv-112 p1) + (let ((s1-0 color) + (s2-0 mode) + (s5-0 color2) + ) + (let ((a0-2 (-> *display* frames (-> *display* on-screen) debug-buf))) + (if (< (the-as uint (shr (+ (&- (-> a0-2 end) (the-as uint (-> a0-2 base))) 15) 4)) (the-as uint #x8000)) + (return (the-as symbol #f)) + ) + ) + (if (or (= s5-0 -1) (= s5-0 (new 'static 'rgba :r #xff :g #xff :b #xff :a #xff))) + (set! s5-0 s1-0) + ) + (case s2-0 + (('fade) + (set! s5-0 + (new 'static 'rgba :r (shr (-> s5-0 r) 1) :g (shr (-> s5-0 g) 1) :b (shr (-> s5-0 b) 1) :a (-> s5-0 a)) + ) + ) + ) + (let ((s4-0 (new 'stack 'vector4w-2)) + (s3-0 (new 'stack 'vector4w-2)) + ) + (set! sv-128 (new 'stack-no-clear 'vector)) + (set! sv-144 (new 'stack-no-clear 'vector)) + (the-as + symbol + (when (debug-line-clip? sv-128 sv-144 p0 sv-112) + (set! (-> sv-128 w) 1.0) + (set! (-> sv-144 w) 1.0) + (when (and (transform-point-qword! (the-as vector4w (-> s4-0 vector)) sv-128) + (transform-point-qword! (-> s4-0 vector 1) sv-144) + ) + (with-dma-buffer-add-bucket ((v1-37 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((a0-28 (the-as (pointer uint64) (-> v1-37 base)))) + (let* ((a1-6 v1-37) + (a3-2 (the-as object (-> a1-6 base))) + ) + (set! (-> (the-as dma-packet a3-2) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a3-2) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a3-2) vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-6 base) (&+ (the-as pointer a3-2) 16)) + ) + (let* ((a1-7 v1-37) + (a3-4 (the-as object (-> a1-7 base))) + ) + (set! (-> (the-as gs-gif-tag a3-4) tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type line) :iip #x1 :abe #x1) + :nreg #x4 + ) + ) + (set! (-> (the-as gs-gif-tag a3-4) regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id xyzf2) + :regs2 (gif-reg-id rgbaq) + :regs3 (gif-reg-id xyzf2) + ) + ) + (set! (-> a1-7 base) (&+ (the-as pointer a3-4) 16)) + ) + (case s2-0 + (('fade-depth) + (let ((f0-3 (fmax 0.2 (fmin 1.0 (* 0.00000005960465 (the float (-> s4-0 vector 0 z))))))) + (set! (-> s3-0 vector 0 x) (the int (* (the float (-> s1-0 r)) f0-3))) + (set! (-> s3-0 vector 0 y) (the int (* (the float (-> s1-0 g)) f0-3))) + (set! (-> s3-0 vector 0 z) (the int (* (the float (-> s1-0 b)) f0-3))) + ) + (set! (-> s3-0 vector 0 w) (the-as int (-> s1-0 a))) + ) + (else + (set! (-> s3-0 vector 0 x) (the-as int (-> s1-0 r))) + (set! (-> s3-0 vector 0 y) (the-as int (-> s1-0 g))) + (set! (-> s3-0 vector 0 z) (the-as int (-> s1-0 b))) + (set! (-> s3-0 vector 0 w) (the-as int (-> s1-0 a))) + ) + ) + (cond + ((= s2-0 'fade-depth) + (let ((f0-7 (fmax 0.2 (fmin 1.0 (* 0.00000005960465 (the float (-> s4-0 vector 1 z))))))) + (set! (-> s3-0 vector 1 x) (the int (* (the float (-> s5-0 r)) f0-7))) + (set! (-> s3-0 vector 1 y) (the int (* (the float (-> s5-0 g)) f0-7))) + (set! (-> s3-0 vector 1 z) (the int (* (the float (-> s5-0 b)) f0-7))) + ) + (set! (-> s3-0 vector 1 w) (the-as int (-> s5-0 a))) + ) + (else + (set! (-> s3-0 vector 1 x) (the-as int (-> s5-0 r))) + (set! (-> s3-0 vector 1 y) (the-as int (-> s5-0 g))) + (set! (-> s3-0 vector 1 z) (the-as int (-> s5-0 b))) + (set! (-> s3-0 vector 1 w) (the-as int (-> s5-0 a))) + ) + ) + (+! (-> s4-0 vector 0 z) -8192) + (+! (-> s4-0 vector 1 z) -8192) + (let* ((a3-7 v1-37) + (a1-50 (the-as object (-> a3-7 base))) + ) + (set! (-> (the-as (inline-array vector4w-2) a1-50) 0 vector 0 quad) (-> s3-0 vector 0 quad)) + (set! (-> (the-as (inline-array vector4w-2) a1-50) 0 vector 1 quad) (-> s4-0 vector 0 quad)) + (set! (-> (the-as (inline-array vector4w-2) a1-50) 1 vector 0 quad) (-> s3-0 vector 1 quad)) + (set! (-> (the-as (inline-array vector4w-2) a1-50) 1 vector 1 quad) (-> s4-0 vector 1 quad)) + (set! (-> a3-7 base) (&+ (the-as pointer a1-50) 64)) + ) + (let ((a3-11 (/ (the-as int (+ (- -16 (the-as int a0-28)) (the-as int (-> v1-37 base)))) 16))) + (cond + ((nonzero? a3-11) + (logior! (-> a0-28 0) (shr (shl a3-11 48) 48)) + (logior! (-> a0-28 1) (shl (shr (shl a3-11 48) 48) 32)) + ) + (else + (set! (-> v1-37 base) a0-28) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + +;; definition (debug) for function internal-draw-debug-text-3d +;; INFO: Used lq/sq +(defun-debug internal-draw-debug-text-3d ((bucket bucket-id) (text string) (pos vector) (color font-color) (offset vector2h)) + "Implementation of 3D text drawing." + (let ((s2-0 (new 'stack-no-clear 'vector4w))) + (set! (-> s2-0 quad) (the-as uint128 0)) + (when (transform-point-qword! s2-0 pos) + (with-dma-buffer-add-bucket ((s3-0 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((s1-1 (new + 'stack + 'font-context + *font-default-matrix* + (+ (-> offset x) -1792 (/ (-> s2-0 x) 16)) + (+ (-> offset y) -1855 (/ (-> s2-0 y) 16)) + 0.0 + color + (font-flags shadow kerning) + ) + ) + ) + (let ((v1-10 s1-1)) + (set! (-> v1-10 origin z) (the float (/ (-> s2-0 z) 16))) + ) + (set-context! *font-work* s1-1) + (draw-string text s3-0 s1-1) + ) + ) + ) + ) + ) + +;; definition (debug) for function add-debug-outline-triangle +(defun-debug add-debug-outline-triangle ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (p2 vector) (color rgba)) + "Draw a wireframe triangle." + (when (and enable (not *display-capture-mode*)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (add-debug-line #t bucket p1 p2 color #f (the-as rgba -1)) + (add-debug-line #t bucket p2 p0 color #f (the-as rgba -1)) + ) + #f + ) + +;; definition (debug) for function add-debug-triangle-normal +(defun-debug add-debug-triangle-normal ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (p2 vector) (color rgba)) + "Draw the normal of a triangle." + (when (and enable (not *display-capture-mode*)) + (let ((s3-0 (new 'stack-no-clear 'vector)) + (s2-0 (vector-3pt-cross! (new 'stack-no-clear 'vector) p0 p1 p2)) + ) + (vector-float/! s2-0 s2-0 (* 0.00024414062 (vector-length s2-0))) + (vector+! s3-0 p0 p1) + (vector+! s3-0 s3-0 p2) + (vector-float/! s3-0 s3-0 3.0) + (vector+! s2-0 s2-0 s3-0) + (add-debug-line #t bucket s3-0 s2-0 color #f (the-as rgba -1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-flat-triangle +;; INFO: Used lq/sq +(defun-debug add-debug-flat-triangle ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (p2 vector) (color rgba)) + "Draw a shaded triangle." + (local-vars (sv-160 vector) (sv-176 vector)) + (set! sv-160 p0) + (set! sv-176 p1) + (let ((s0-0 p2) + (s3-0 color) + ) + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((s5-0 (new 'stack 'vector4w-3)) + (s4-0 (new 'stack 'vector4w-3)) + (a1-3 (new 'stack-no-clear 'vector)) + (s2-0 (new 'stack-no-clear 'vector)) + (s1-0 (new 'stack-no-clear 'vector)) + ) + (set! (-> a1-3 quad) (-> sv-160 quad)) + (set! (-> s2-0 quad) (-> sv-176 quad)) + (set! (-> s1-0 quad) (-> s0-0 quad)) + (set! (-> a1-3 w) 1.0) + (set! (-> s2-0 w) 1.0) + (set! (-> s1-0 w) 1.0) + (when (and (transform-point-qword! (the-as vector4w (-> s5-0 vector)) a1-3) + (transform-point-qword! (-> s5-0 vector 1) s2-0) + (transform-point-qword! (-> s5-0 vector 2) s1-0) + ) + (with-dma-buffer-add-bucket ((v1-17 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((a0-12 (-> v1-17 base))) + (let* ((a1-6 v1-17) + (a3-1 (the-as dma-packet (-> a1-6 base))) + ) + (set! (-> a3-1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a3-1 vif0) (new 'static 'vif-tag)) + (set! (-> a3-1 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-6 base) (the-as pointer (&+ a3-1 16))) + ) + (let* ((a1-7 v1-17) + (a3-3 (the-as gs-gif-tag (-> a1-7 base))) + ) + (set! (-> a3-3 tag) (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri) :iip #x1 :abe #x1) + :nreg #x6 + ) + ) + (set! (-> a3-3 regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id xyzf2) + :regs2 (gif-reg-id rgbaq) + :regs3 (gif-reg-id xyzf2) + :regs4 (gif-reg-id rgbaq) + :regs5 (gif-reg-id xyzf2) + ) + ) + (set! (-> a1-7 base) (the-as pointer (&+ a3-3 16))) + ) + (set! (-> s4-0 vector 0 x) (the-as int (-> s3-0 r))) + (set! (-> s4-0 vector 0 y) (the-as int (-> s3-0 g))) + (set! (-> s4-0 vector 0 z) (the-as int (-> s3-0 b))) + (set! (-> s4-0 vector 0 w) (the-as int (-> s3-0 a))) + (+! (-> s5-0 vector 0 z) -8192) + (+! (-> s5-0 vector 1 z) -8192) + (+! (-> s5-0 vector 2 z) -8192) + (let* ((a1-21 v1-17) + (a3-5 (the-as (inline-array vector) (-> a1-21 base))) + ) + (set! (-> a3-5 0 quad) (-> s4-0 vector 0 quad)) + (set! (-> a3-5 1 quad) (-> s5-0 vector 0 quad)) + (set! (-> a3-5 2 quad) (-> s4-0 vector 0 quad)) + (set! (-> a3-5 3 quad) (-> s5-0 vector 1 quad)) + (set! (-> a3-5 4 quad) (-> s4-0 vector 0 quad)) + (set! (-> a3-5 5 quad) (-> s5-0 vector 2 quad)) + (set! (-> a1-21 base) (the-as pointer (-> a3-5 6))) + ) + (let ((a1-25 (/ (the-as int (+ (- -16 (the-as int a0-12)) (the-as int (-> v1-17 base)))) 16))) + (cond + ((nonzero? a1-25) + (logior! (-> (the-as (pointer uint64) a0-12) 0) (shr (shl a1-25 48) 48)) + (logior! (-> (the-as (pointer uint64) a0-12) 1) (shl (shr (shl a1-25 48) 48) 32)) + ) + (else + (set! (-> v1-17 base) a0-12) + ) + ) + ) + ) + ) + ) + ) + ) + #f + ) + +;; this part is debug only +(when *debug-segment* +;; definition of type debug-line +(deftype debug-line (structure) + ((flags int32) + (bucket bucket-id) + (v1 vector :inline) + (v2 vector :inline) + (color rgba) + (mode symbol) + (color2 rgba) + ) + ) + +;; definition for method 3 of type debug-line +(defmethod inspect ((this debug-line)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'debug-line) + (format #t "~1Tflags: ~D~%" (-> this flags)) + (format #t "~1Tbucket: ~D~%" (-> this bucket)) + (format #t "~1Tv1: #~%" (-> this v1)) + (format #t "~1Tv2: #~%" (-> this v2)) + (format #t "~1Tcolor: ~D~%" (-> this color)) + (format #t "~1Tmode: ~A~%" (-> this mode)) + (format #t "~1Tcolor2: ~D~%" (-> this color2)) + (label cfg-4) + this + ) + +;; definition of type debug-text-3d +(deftype debug-text-3d (structure) + ((flags int32) + (bucket bucket-id) + (pos vector :inline) + (color font-color) + (offset vector2h :inline) + (str string) + ) + ) + +;; definition for method 3 of type debug-text-3d +(defmethod inspect ((this debug-text-3d)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'debug-text-3d) + (format #t "~1Tflags: ~D~%" (-> this flags)) + (format #t "~1Tbucket: ~D~%" (-> this bucket)) + (format #t "~1Tpos: #~%" (-> this pos)) + (format #t "~1Tcolor: ~D~%" (-> this color)) + (format #t "~1Toffset: #~%" (-> this offset)) + (format #t "~1Tstr: ~A~%" (-> this str)) + (label cfg-4) + this + ) + +;; definition of type debug-tracking-thang +(deftype debug-tracking-thang (basic) + ((length int32) + (allocated-length int32) + ) + ) + +;; definition for method 3 of type debug-tracking-thang +(defmethod inspect ((this debug-tracking-thang)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Tlength: ~D~%" (-> this length)) + (format #t "~1Tallocated-length: ~D~%" (-> this allocated-length)) + (label cfg-4) + this + ) + +;; definition for symbol *debug-lines*, type (inline-array debug-line) +(define *debug-lines* (the-as (inline-array debug-line) (malloc 'debug #x100000))) + +;; definition for symbol *debug-lines-trk*, type debug-tracking-thang +(define *debug-lines-trk* (new 'debug 'debug-tracking-thang)) + +;; failed to figure out what this is: +(set! (-> *debug-lines-trk* allocated-length) #x4000) + +;; definition for symbol *debug-text-3ds*, type (inline-array debug-text-3d) +(define *debug-text-3ds* (the-as (inline-array debug-text-3d) (malloc 'debug #x6000))) + +;; definition for symbol *debug-text-3d-trk*, type debug-tracking-thang +(define *debug-text-3d-trk* (new 'debug 'debug-tracking-thang)) + +;; failed to figure out what this is: +(set! (-> *debug-text-3d-trk* allocated-length) 512) + +;; failed to figure out what this is: +(dotimes (gp-0 (-> *debug-text-3d-trk* allocated-length)) + (set! (-> *debug-text-3ds* gp-0 str) (new 'debug 'string 80 (the-as string #f))) + ) + +) +;; definition (debug) for function get-debug-line +(defun-debug get-debug-line () + "Allocate a record for a debug line. + This is used to persist debug drawing for paused objects." + (cond + ((< (-> *debug-lines-trk* length) (-> *debug-lines-trk* allocated-length)) + (+! (-> *debug-lines-trk* length) 1) + (-> *debug-lines* (+ (-> *debug-lines-trk* length) -1)) + ) + (else + (the-as debug-line #f) + ) + ) + ) + +;; definition (debug) for function get-debug-text-3d +(defun-debug get-debug-text-3d () + "Allocate a record for a debug 3d text. + This is used to persist debug drawing for paused objects." + (cond + ((< (-> *debug-text-3d-trk* length) (-> *debug-text-3d-trk* allocated-length)) + (+! (-> *debug-text-3d-trk* length) 1) + (-> *debug-text-3ds* (+ (-> *debug-text-3d-trk* length) -1)) + ) + (else + (the-as debug-text-3d #f) + ) + ) + ) + +;; definition (debug) for function debug-reset-buffers +(defun-debug debug-reset-buffers () + "Reset buffered debug drawing." + (set! (-> *debug-lines-trk* length) 0) + (set! (-> *debug-text-3d-trk* length) 0) + (set! *debug-draw-pauseable* #f) + #f + ) + +;; definition (debug) for function debug-draw-buffers +(defun-debug debug-draw-buffers () + "Draw all buffered debug drawing." + (dotimes (gp-0 (-> *debug-lines-trk* length)) + (let ((v1-1 (-> *debug-lines* gp-0))) + (internal-draw-debug-line + (-> v1-1 bucket) + (-> v1-1 v1) + (-> v1-1 v2) + (-> v1-1 color) + (-> v1-1 mode) + (-> v1-1 color2) + ) + ) + ) + (dotimes (gp-1 (-> *debug-text-3d-trk* length)) + (let ((v1-8 (-> *debug-text-3ds* gp-1))) + (internal-draw-debug-text-3d (-> v1-8 bucket) (-> v1-8 str) (-> v1-8 pos) (-> v1-8 color) (-> v1-8 offset)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-line +;; INFO: Used lq/sq +(defun-debug add-debug-line ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (color rgba) (mode symbol) (color2 rgba)) + "Draw a line." + (when (and enable (not *display-capture-mode*)) + (cond + (*debug-draw-pauseable* + (let ((v1-4 (get-debug-line))) + (when v1-4 + (set! (-> v1-4 bucket) bucket) + (set! (-> v1-4 v1 quad) (-> p0 quad)) + (set! (-> v1-4 v2 quad) (-> p1 quad)) + (set! (-> v1-4 color) color) + (set! (-> v1-4 color2) color2) + (set! (-> v1-4 mode) mode) + ) + ) + ) + (else + (internal-draw-debug-line bucket p0 p1 color mode color2) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-line2d +;; INFO: Used lq/sq +(defun-debug add-debug-line2d ((enable symbol) (bucket bucket-id) (p0 vector4w) (p1 vector4w) (color vector4w)) + "Draw a screen-space line." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (with-dma-buffer-add-bucket ((s4-0 (-> *display* frames (-> *display* on-screen) debug-buf)) + bucket + ) + (let ((s2-0 (new 'stack 'vector4w)) + (v1-10 (new 'stack 'vector4w)) + ) + (set! (-> s2-0 quad) (-> p0 quad)) + (set! (-> v1-10 quad) (-> p1 quad)) + (set! (-> s2-0 x) (* (+ (-> s2-0 x) 2048) 16)) + (set! (-> s2-0 y) (* -16 (- 2048 (-> s2-0 y)))) + (set! (-> s2-0 z) #x7fffff) + (set! (-> v1-10 x) (* (+ (-> v1-10 x) 2048) 16)) + (set! (-> v1-10 y) (* -16 (- 2048 (-> v1-10 y)))) + (set! (-> v1-10 z) #x7fffff) + (let ((a0-18 (-> s4-0 base))) + (let* ((a1-7 s4-0) + (a2-3 (the-as dma-packet (-> a1-7 base))) + ) + (set! (-> a2-3 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a2-3 vif0) (new 'static 'vif-tag)) + (set! (-> a2-3 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-7 base) (the-as pointer (&+ a2-3 16))) + ) + (let* ((a1-8 s4-0) + (a2-5 (the-as gs-gif-tag (-> a1-8 base))) + ) + (set! (-> a2-5 tag) (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type line) :iip #x1 :abe #x1) + :nreg #x4 + ) + ) + (set! (-> a2-5 regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id xyzf2) + :regs2 (gif-reg-id rgbaq) + :regs3 (gif-reg-id xyzf2) + ) + ) + (set! (-> a1-8 base) (the-as pointer (&+ a2-5 16))) + ) + (let* ((a1-9 s4-0) + (a2-7 (the-as vector4w-2 (-> a1-9 base))) + ) + (set! (-> a2-7 vector 0 quad) (-> color quad)) + (set! (-> a2-7 vector 1 quad) (-> s2-0 quad)) + (set! (-> a1-9 base) (the-as pointer (&+ a2-7 32))) + ) + (let* ((a1-10 s4-0) + (a2-9 (the-as vector4w-2 (-> a1-10 base))) + ) + (set! (-> a2-9 vector 0 quad) (-> color quad)) + (set! (-> a2-9 vector 1 quad) (-> v1-10 quad)) + (set! (-> a1-10 base) (the-as pointer (&+ a2-9 32))) + ) + (let ((a1-14 (/ (the-as int (+ (- -16 (the-as int a0-18)) (the-as int (-> s4-0 base)))) 16))) + (cond + ((nonzero? a1-14) + (logior! (-> (the-as (pointer uint64) a0-18) 0) (shr (shl a1-14 48) 48)) + (logior! (-> (the-as (pointer uint64) a0-18) 1) (shl (shr (shl a1-14 48) 48) 32)) + ) + (else + (set! (-> s4-0 base) a0-18) + ) + ) + ) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-box +;; INFO: Used lq/sq +(defun-debug add-debug-box ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (color rgba)) + "Draw an axis-aligned box." + (let ((s5-0 (new-stack-vector0))) + (set! (-> s5-0 quad) (-> p0 quad)) + (let ((s1-0 (new-stack-vector0))) + (set! (-> s1-0 quad) (-> p0 quad)) + (when (and enable (not *display-capture-mode*)) + (set! (-> s1-0 x) (-> p1 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 x) (-> p0 x)) + (set! (-> s1-0 y) (-> p1 y)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> p0 y)) + (set! (-> s1-0 z) (-> p1 z)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s5-0 y) (-> p1 y)) + (set! (-> s1-0 y) (-> p1 y)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 z) (-> p0 z)) + (set! (-> s1-0 x) (-> p1 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> p0 y)) + (set! (-> s5-0 x) (-> p1 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s5-0 quad) (-> p1 quad)) + (set! (-> s1-0 quad) (-> p1 quad)) + (set! (-> s1-0 x) (-> p0 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 x) (-> p1 x)) + (set! (-> s1-0 y) (-> p0 y)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> p1 y)) + (set! (-> s1-0 z) (-> p0 z)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s5-0 y) (-> p0 y)) + (set! (-> s1-0 y) (-> p0 y)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 z) (-> p1 z)) + (set! (-> s1-0 x) (-> p0 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> p1 y)) + (set! (-> s5-0 x) (-> p0 x)) + (add-debug-line #t bucket s5-0 s1-0 color #f (the-as rgba -1)) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-box-with-transform +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs symbol. +(defun-debug add-debug-box-with-transform ((enable symbol) (bucket bucket-id) (box bounding-box) (mat matrix) (color rgba)) + "Draw a box with arbitrary transform." + (b! (not enable) cfg-5 :delay (nop!)) + (let ((s4-0 (new 'stack-no-clear 'inline-array 'vector 8))) + (let ((s2-0 (new 'stack-no-clear 'inline-array 'vector 2)) + (s1-0 (new 'stack-no-clear 'vector)) + ) + (set! (-> s2-0 0 quad) (-> box min quad)) + (set! (-> s2-0 1 quad) (-> box max quad)) + (set! (-> s1-0 w) 1.0) + (dotimes (s0-0 8) + (set! (-> s1-0 x) (-> s2-0 (logand s0-0 1) x)) + (set! (-> s1-0 y) (-> s2-0 (logand (/ s0-0 2) 1) y)) + (set! (-> s1-0 z) (-> s2-0 (logand (/ s0-0 4) 1) z)) + (let ((a0-5 (-> s4-0 s0-0))) + (vector-matrix*! a0-5 s1-0 mat) + ) + ) + ) + (add-debug-line #t bucket (-> s4-0 0) (-> s4-0 1) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 1) (-> s4-0 3) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 3) (-> s4-0 2) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 2) (-> s4-0 0) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 4) (-> s4-0 5) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 5) (-> s4-0 7) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 7) (-> s4-0 6) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 6) (-> s4-0 4) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 0) (-> s4-0 4) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 1) (-> s4-0 5) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 3) (-> s4-0 7) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> s4-0 2) (-> s4-0 6) color #f (the-as rgba -1)) + ) + (label cfg-5) + (the-as symbol 0) + ) + +;; definition (debug) for function add-debug-x +;; INFO: Used lq/sq +(defun-debug add-debug-x ((enable symbol) (bucket bucket-id) (pos vector) (color rgba)) + "Draw an X." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((s3-0 (new-stack-vector0)) + (s2-0 (new-stack-vector0)) + ) + (vector+! s3-0 pos (new 'static 'vector :x -1228.8)) + (vector+! s2-0 pos (new 'static 'vector :x 1228.8)) + (add-debug-line #t bucket s3-0 s2-0 color #f (the-as rgba -1)) + (vector+! s3-0 pos (new 'static 'vector :z -1228.8)) + (vector+! s2-0 pos (new 'static 'vector :z 1228.8)) + (add-debug-line #t bucket s3-0 s2-0 color #f (the-as rgba -1)) + ) + #f + ) + +;; definition (debug) for function add-debug-cross +;; INFO: Used lq/sq +(defun-debug add-debug-cross ((enable symbol) (bucket bucket-id) (pos vector) (len float)) + "Draw a cross." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((s4-0 (new-stack-vector0)) + (s3-0 (new-stack-vector0)) + ) + (let ((a1-1 s4-0) + (v1-3 pos) + (a0-1 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-1 x) (- len)) + (set! (-> a0-1 y) 0.0) + (set! (-> a0-1 z) 0.0) + (set! (-> a0-1 w) 1.0) + (vector+! a1-1 v1-3 a0-1) + ) + (let ((a1-3 s3-0) + (v1-4 pos) + (a0-2 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-2 x) len) + (set! (-> a0-2 y) 0.0) + (set! (-> a0-2 z) 0.0) + (set! (-> a0-2 w) 1.0) + (vector+! a1-3 v1-4 a0-2) + ) + (add-debug-line #t bucket s4-0 s3-0 *color-red* #f (the-as rgba -1)) + (let ((a1-6 s4-0) + (v1-5 pos) + (a0-4 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-4 x) 0.0) + (set! (-> a0-4 y) (- len)) + (set! (-> a0-4 z) 0.0) + (set! (-> a0-4 w) 1.0) + (vector+! a1-6 v1-5 a0-4) + ) + (let ((a1-8 s3-0) + (v1-6 pos) + (a0-5 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-5 x) 0.0) + (set! (-> a0-5 y) len) + (set! (-> a0-5 z) 0.0) + (set! (-> a0-5 w) 1.0) + (vector+! a1-8 v1-6 a0-5) + ) + (add-debug-line #t bucket s4-0 s3-0 *color-green* #f (the-as rgba -1)) + (let ((a1-11 s4-0) + (v1-7 pos) + (a0-7 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-7 x) 0.0) + (set! (-> a0-7 y) 0.0) + (set! (-> a0-7 z) (- len)) + (set! (-> a0-7 w) 1.0) + (vector+! a1-11 v1-7 a0-7) + ) + (let ((a0-8 s3-0) + (v1-8 (new 'stack-no-clear 'vector)) + ) + (set! (-> v1-8 x) 0.0) + (set! (-> v1-8 y) 0.0) + (set! (-> v1-8 z) len) + (set! (-> v1-8 w) 1.0) + (vector+! a0-8 pos v1-8) + ) + (add-debug-line #t bucket s4-0 s3-0 *color-blue* #f (the-as rgba -1)) + ) + #f + ) + +;; definition (debug) for function add-debug-text-3d +;; INFO: Used lq/sq +(defun-debug add-debug-text-3d ((enable symbol) (bucket bucket-id) (text string) (pos vector) (color font-color) (offset vector2h)) + "Draw debug text." + (when (and enable (not *display-capture-mode*)) + (cond + (*debug-draw-pauseable* + (let ((v1-4 (get-debug-text-3d))) + (when v1-4 + (set! (-> v1-4 flags) 0) + (set! (-> v1-4 bucket) bucket) + (set! (-> v1-4 pos quad) (-> pos quad)) + (cond + (offset + (set! (-> v1-4 offset x) (-> offset x)) + (set! (-> v1-4 offset y) (-> offset y)) + ) + (else + (set! (-> v1-4 offset x) 0) + (set! (-> v1-4 offset y) 0) + 0 + ) + ) + (set! (-> v1-4 color) color) + (let ((a0-6 0) + (a1-2 (-> text data)) + (v1-6 (-> v1-4 str data)) + ) + (while (and (nonzero? (-> a1-2 0)) (< a0-6 79)) + (set! (-> v1-6 0) (-> a1-2 0)) + (set! a1-2 (&-> a1-2 1)) + (set! v1-6 (&-> v1-6 1)) + (+! a0-6 1) + ) + (set! (-> v1-6 0) (the-as uint 0)) + ) + 0 + ) + ) + ) + (else + (internal-draw-debug-text-3d bucket text pos color (cond + (offset + (empty) + offset + ) + (else + (new 'static 'vector2h) + ) + ) + ) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-sphere-with-transform +(defun-debug add-debug-sphere-with-transform ((enable symbol) (bucket bucket-id) (pos vector) (radius meters) (mat matrix) (color rgba)) + "Draw a debug sphere, applying a transform to the given point first." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (init-vf0-vector) + (when (and enable (not *display-capture-mode*)) + (.lvf vf5 (&-> pos quad)) + (.lvf vf1 (&-> mat rvec quad)) + (.lvf vf2 (&-> mat uvec quad)) + (.lvf vf3 (&-> mat fvec quad)) + (.lvf vf4 (&-> mat trans quad)) + (.mul.w.vf acc vf4 vf0) + (.add.mul.x.vf acc vf1 vf5 acc) + (.add.mul.y.vf acc vf2 vf5 acc) + (.add.mul.z.vf vf5 vf3 vf5 acc) + (let ((a2-1 (new 'stack-no-clear 'vector))) + (.svf (&-> a2-1 quad) vf5) + (add-debug-sphere enable bucket a2-1 radius color) + ) + ) + #f + ) + ) + +;; definition (debug) for function add-debug-sphere +(defun-debug add-debug-sphere ((enable symbol) (bucket bucket-id) (pos vector) (radius meters) (color rgba)) + "Draw a debug sphere." + (if (and enable (not *display-capture-mode*)) + (add-debug-sphere-from-table bucket pos radius color 6) + ) + #f + ) + +;; definition (debug) for function add-debug-text-sphere +(defun-debug add-debug-text-sphere ((enable symbol) (bucket bucket-id) (pos vector) (radius meters) (text string) (color rgba)) + "Draw a debug sphere with a text label." + (add-debug-sphere enable bucket pos radius color) + (add-debug-text-3d enable bucket text pos (font-color default) (the-as vector2h #f)) + #f + ) + +;; definition (debug) for function add-debug-spheres +(defun-debug add-debug-spheres ((enable symbol) (bucket bucket-id) (spheres (inline-array vector)) (count int) (color rgba)) + "Draw from an array of spheres. The radius is stored in w." + (when (and enable (not *display-capture-mode*)) + (let ((s4-0 (-> spheres 0))) + (countdown (s3-0 count) + (add-debug-sphere #t bucket s4-0 (-> s4-0 w) color) + (&+! s4-0 16) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-line-sphere +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun-debug add-debug-line-sphere ((enable symbol) (bucket bucket-id) (base vector) (dir vector) (rad float) (color rgba)) + "Draw a capsule as a cylinder." + (local-vars + (sv-16 bucket-id) + (sv-24 vector) + (sv-28 vector) + (sv-32 float) + (sv-36 rgba) + (sv-112 matrix) + (sv-116 float) + ) + (b! (not enable) cfg-8 :delay (nop!)) + (set! sv-16 bucket) + (set! sv-24 base) + (set! sv-28 dir) + (set! sv-32 rad) + (set! sv-36 color) + (set! sv-112 (new 'stack-no-clear 'matrix)) + (set! sv-116 (vector-length sv-28)) + (let ((gp-0 (new 'stack-no-clear 'vector)) + (s5-0 (new 'stack-no-clear 'vector)) + ) + (vector-normalize-copy! gp-0 sv-28 1.0) + (vector-reset! s5-0) + (let* ((f0-2 (-> gp-0 y)) + (f0-4 (* f0-2 f0-2)) + (f1-0 (-> gp-0 z)) + ) + (if (< f0-4 (* f1-0 f1-0)) + (set! (-> s5-0 y) -1.0) + (set! (-> s5-0 z) -1.0) + ) + ) + (forward-down->inv-matrix sv-112 gp-0 s5-0) + ) + (set! (-> sv-112 trans quad) (-> sv-24 quad)) + (set! (-> sv-112 trans w) 1.0) + (let ((gp-1 (new 'static 'inline-array vector 3 + (new 'static 'vector :y 0.5877 :z 0.951 :w 0.951) + (new 'static 'vector :x 0.5877 :z -0.5877 :w -0.951) + (new 'static 'vector :x -0.951 :y -0.5878) + ) + ) + (s5-1 (new 'static 'inline-array vector 3 + (new 'static 'vector :x 1.0 :y 0.809 :z 0.3089 :w -0.3088) + (new 'static 'vector :x -0.809 :y -1.0 :z -0.809 :w -0.309) + (new 'static 'vector :x 0.3089 :y 0.8089) + ) + ) + (s4-0 (new 'stack-no-clear 'vector)) + (s3-0 (new 'stack-no-clear 'vector)) + (s2-0 (new 'stack-no-clear 'vector)) + (s1-0 (new 'stack-no-clear 'vector)) + ) + (set! (-> s1-0 z) 0.0) + (set! (-> s1-0 w) 1.0) + (set! (-> s1-0 x) (* sv-32 (-> s5-1 2 y))) + (set! (-> s1-0 y) (* sv-32 (-> gp-1 2 y))) + (vector-matrix*! s3-0 s1-0 sv-112) + (dotimes (s0-0 10) + (set! (-> s4-0 quad) (-> s3-0 quad)) + (set! (-> s1-0 x) (* sv-32 (-> (&-> s5-1 0 data s0-0) 0))) + (set! (-> s1-0 y) (* sv-32 (-> (&-> gp-1 0 data s0-0) 0))) + (vector-matrix*! s3-0 s1-0 sv-112) + (add-debug-line #t sv-16 s4-0 s3-0 sv-36 #f (the-as rgba -1)) + (vector+float*! s2-0 s3-0 (-> sv-112 fvec) sv-116) + (add-debug-line #t sv-16 s3-0 s2-0 sv-36 #f (the-as rgba -1)) + (vector+float*! s4-0 s4-0 (-> sv-112 fvec) sv-116) + (add-debug-line #t sv-16 s4-0 s2-0 sv-36 #f (the-as rgba -1)) + ) + ) + (label cfg-8) + 0 + (none) + ) + +;; definition (debug) for function add-debug-circle +;; INFO: Used lq/sq +(defun-debug add-debug-circle ((enable symbol) (bucket bucket-id) (origin vector) (radius float) (color rgba) (mat matrix)) + "Draw a circle." + (local-vars (sv-48 int) (sv-64 vector) (sv-80 vector)) + "note: you may pass #f for orientation" + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((f30-0 0.0) + (s1-0 (new-stack-vector0)) + (s0-0 (new-stack-vector0)) + ) + (set! sv-48 0) + (while (< sv-48 12) + (set! sv-64 s1-0) + (set! (-> sv-64 x) (* radius (cos f30-0))) + (set! (-> sv-64 y) 0.0) + (set! (-> sv-64 z) (* radius (sin f30-0))) + (set! (-> sv-64 w) 1.0) + (set! f30-0 (+ 5461.3335 f30-0)) + (set! sv-80 s0-0) + (set! (-> sv-80 x) (* radius (cos f30-0))) + (set! (-> sv-80 y) 0.0) + (set! (-> sv-80 z) (* radius (sin f30-0))) + (set! (-> sv-80 w) 1.0) + (when mat + (vector-matrix*! s1-0 s1-0 mat) + (vector-matrix*! s0-0 s0-0 mat) + ) + (vector+! s1-0 s1-0 origin) + (vector+! s0-0 s0-0 origin) + (add-debug-line #t bucket s1-0 s0-0 color #f (the-as rgba -1)) + (set! sv-48 (+ sv-48 1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-vector +;; INFO: Used lq/sq +(defun-debug add-debug-vector ((enable symbol) (bucket bucket-id) (base vector) (dir vector) (len-scale meters) (color rgba)) + "Draw a vector." + (if (not (or enable *display-capture-mode*)) + (return #f) + ) + (let ((v1-3 (new-stack-vector0))) + (set! (-> v1-3 x) (+ (-> base x) (* (-> dir x) len-scale))) + (set! (-> v1-3 y) (+ (-> base y) (* (-> dir y) len-scale))) + (set! (-> v1-3 z) (+ (-> base z) (* (-> dir z) len-scale))) + (add-debug-line #t bucket base v1-3 color #f (the-as rgba -1)) + ) + #f + ) + +;; definition (debug) for function add-debug-matrix +(defun-debug add-debug-matrix ((enable symbol) (bucket bucket-id) (mat matrix) (len meters)) + "Draw a matrix as a coordinate frame." + (add-debug-vector enable bucket (-> mat trans) (-> mat rvec) len (new 'static 'rgba :r #xff :a #x80)) + (add-debug-vector enable bucket (-> mat trans) (-> mat uvec) len (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector enable bucket (-> mat trans) (-> mat fvec) len (new 'static 'rgba :b #xff :a #x80)) + mat + ) + +;; definition (debug) for function add-debug-rot-matrix +(defun-debug add-debug-rot-matrix ((enable symbol) (bucket bucket-id) (mat matrix) (len vector)) + "Draw a matrix as a coordinate frame, but use the given origin instead of the trans from the matrix." + (add-debug-vector enable bucket len (-> mat rvec) (meters 2) (new 'static 'rgba :r #xff :a #x80)) + (add-debug-vector enable bucket len (-> mat uvec) (meters 2) (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector enable bucket len (-> mat fvec) (meters 2) (new 'static 'rgba :b #xff :a #x80)) + mat + ) + +;; definition (debug) for function add-debug-quaternion +;; WARN: Return type mismatch int vs none. +(defun-debug add-debug-quaternion ((enable symbol) (bucket bucket-id) (trans vector) (quat quaternion)) + "Draw a quaternion as a coordinate frame." + (when (and enable (not *display-capture-mode*)) + (let ((a2-1 (quaternion->matrix (new 'stack-no-clear 'matrix) quat))) + (add-debug-rot-matrix enable bucket a2-1 trans) + ) + ) + 0 + (none) + ) + +;; definition (debug) for function add-debug-cspace +(defun-debug add-debug-cspace ((enable symbol) (bucket bucket-id) (cs cspace)) + "Draw a cspace as a matrix." + (add-debug-matrix enable bucket (-> cs bone transform) (meters 2)) + cs + ) + +;; definition (debug) for function add-debug-yrot-vector +;; INFO: Used lq/sq +;; WARN: Stack slot offset 32 signed mismatch +;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16 +;; WARN: Stack slot offset 32 signed mismatch +;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16 +;; WARN: Stack slot offset 32 signed mismatch +;; ERROR: Stack slot load at 32 mismatch: defined as size 4, got size 16 +(defun-debug add-debug-yrot-vector ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 float) (arg4 float) (arg5 rgba)) + (local-vars (sv-32 float)) + (set! sv-32 arg3) + (let ((s0-0 arg4) + (s3-0 arg5) + ) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (let ((s1-0 (new-stack-vector0))) + (set-vector! s1-0 (+ (-> arg2 x) (* (sin sv-32) s0-0)) (-> arg2 y) (+ (-> arg2 z) (* (cos sv-32) s0-0)) 1.0) + (add-debug-line arg0 arg1 s1-0 arg2 s3-0 #f (the-as rgba -1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-arc +;; INFO: Used lq/sq +(defun-debug add-debug-arc ((arg0 symbol) + (arg1 bucket-id) + (arg2 vector) + (arg3 float) + (arg4 float) + (arg5 float) + (arg6 rgba) + (arg7 matrix) + ) + "note: you may pass #f for orientation" + (local-vars (sv-48 vector) (sv-64 vector) (sv-80 int) (sv-96 vector) (sv-112 vector)) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (let ((f30-0 arg3)) + (set! sv-48 (new 'stack-no-clear 'vector)) + (set! (-> sv-48 quad) (the-as uint128 0)) + (set! sv-64 (new 'stack-no-clear 'vector)) + (set! (-> sv-64 quad) (the-as uint128 0)) + (set! sv-80 0) + (while (< sv-80 12) + (set! sv-96 sv-48) + (set! (-> sv-96 x) (* arg5 (sin f30-0))) + (set! (-> sv-96 y) 0.0) + (set! (-> sv-96 z) (* arg5 (cos f30-0))) + (set! (-> sv-96 w) 1.0) + (+! f30-0 (the float (/ (the int (- arg4 arg3)) 12))) + (set! sv-112 sv-64) + (set! (-> sv-112 x) (* arg5 (sin f30-0))) + (set! (-> sv-112 y) 0.0) + (set! (-> sv-112 z) (* arg5 (cos f30-0))) + (set! (-> sv-112 w) 1.0) + (when arg7 + (vector-matrix*! sv-48 sv-48 arg7) + (vector-matrix*! sv-64 sv-64 arg7) + ) + (vector+! sv-48 sv-48 arg2) + (vector+! sv-64 sv-64 arg2) + (add-debug-line #t arg1 sv-48 sv-64 arg6 #f (the-as rgba -1)) + (cond + ((zero? sv-80) + (add-debug-line #t arg1 sv-48 arg2 arg6 #f (the-as rgba -1)) + ) + ((= sv-80 11) + (add-debug-line #t arg1 sv-64 arg2 arg6 #f (the-as rgba -1)) + ) + ) + (set! sv-80 (+ sv-80 1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-curve +;; INFO: Used lq/sq +(defun-debug add-debug-curve ((arg0 symbol) + (arg1 bucket-id) + (arg2 (inline-array vector)) + (arg3 int) + (arg4 (pointer float)) + (arg5 int) + (arg6 rgba) + ) + (local-vars (sv-48 vector) (sv-64 int) (sv-80 int)) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (let ((s0-0 (new-stack-vector0))) + (set! sv-48 (new 'stack-no-clear 'vector)) + (set! (-> sv-48 quad) (the-as uint128 0)) + (set! sv-64 (* arg3 4)) + (curve-evaluate! sv-48 (-> arg4 0) arg2 arg3 arg4 arg5) + (set! sv-80 0) + (while (< sv-80 sv-64) + (set! (-> s0-0 quad) (-> sv-48 quad)) + (curve-evaluate! sv-48 (/ (the float (+ sv-80 1)) (the float sv-64)) arg2 arg3 arg4 arg5) + (add-debug-line #t arg1 s0-0 sv-48 arg6 #f (the-as rgba -1)) + (set! sv-80 (+ sv-80 1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-curve2 +(defun-debug add-debug-curve2 ((arg0 symbol) (arg1 bucket-id) (arg2 curve) (arg3 rgba) (arg4 symbol)) + (if (and arg0 (not *display-capture-mode*)) + (add-debug-curve #t arg1 (-> arg2 cverts) (-> arg2 num-cverts) (-> arg2 knots) (-> arg2 num-knots) arg3) + ) + #f + ) + +;; definition (debug) for function add-debug-points +;; INFO: Used lq/sq +(defun-debug add-debug-points ((arg0 symbol) (arg1 bucket-id) (arg2 (inline-array vector)) (arg3 int) (arg4 rgba) (arg5 float) (arg6 int)) + (local-vars + (sv-32 (function symbol bucket-id string vector font-color vector2h symbol)) + (sv-48 symbol) + (sv-64 bucket-id) + (sv-80 (function _varargs_ object)) + (sv-96 vector) + ) + (when (and arg0 (not *display-capture-mode*)) + (dotimes (s0-0 arg3) + (set! sv-96 (new 'stack-no-clear 'vector)) + (set! (-> sv-96 quad) (the-as uint128 0)) + (set! (-> sv-96 quad) (-> arg2 s0-0 quad)) + (if (!= arg5 0.0) + (set! (-> sv-96 y) arg5) + ) + (set! sv-32 add-debug-text-3d) + (set! sv-48 #t) + (set! sv-64 arg1) + (set! sv-80 format) + (let ((a0-5 (clear *temp-string*)) + (a1-1 "~d") + (a2-1 s0-0) + ) + (sv-80 a0-5 a1-1 a2-1) + ) + (let ((a2-2 *temp-string*) + (a3-1 sv-96) + (t0-1 1) + (t1-1 #f) + ) + (sv-32 sv-48 sv-64 a2-2 a3-1 (the-as font-color t0-1) (the-as vector2h t1-1)) + ) + (let ((t9-3 add-debug-x) + (a0-7 #t) + (a1-3 arg1) + (a3-2 (if (= s0-0 arg6) + (the-as uint #x80ffffff) + (the-as uint arg4) + ) + ) + ) + (t9-3 a0-7 a1-3 sv-96 (the-as rgba a3-2)) + ) + ) + ) + #f + ) + +;; definition (debug) for function debug-percent-bar +;; INFO: Used lq/sq +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +(defun-debug debug-percent-bar ((arg0 symbol) (arg1 bucket-id) (arg2 int) (arg3 int) (arg4 float) (arg5 rgba) (arg6 int) (arg7 int)) + (local-vars (sv-16 int) (sv-32 float)) + (set! sv-16 arg3) + (set! sv-32 arg4) + (let ((s3-0 arg5) + (s1-0 arg6) + (s2-0 arg7) + ) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (with-dma-buffer-add-bucket ((s0-0 (-> *display* frames (-> *display* on-screen) debug-buf)) + arg1 + ) + (draw-sprite2d-xy s0-0 arg2 sv-16 s1-0 s2-0 (new 'static 'rgba :a #x40) #x3fffff) + (draw-sprite2d-xy s0-0 arg2 (+ sv-16 2) (the int (* sv-32 (the float s1-0))) (+ s2-0 -4) s3-0 #x3fffff) + ) + ) + #f + ) + +;; definition (debug) for function debug-pad-display +;; INFO: Used lq/sq +(defun-debug debug-pad-display ((arg0 cpad-info)) + (let ((gp-0 (new 'static 'inline-array vector 32 + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + ) + ) + ) + (countdown (v1-0 31) + (let ((a0-3 (-> gp-0 v1-0 quad))) + (set! (-> gp-0 (+ v1-0 1) quad) a0-3) + ) + ) + (set! (-> gp-0 0 x) (* (sin (-> arg0 stick0-dir)) (-> arg0 stick0-speed))) + (set! (-> gp-0 0 y) (* (cos (-> arg0 stick0-dir)) (-> arg0 stick0-speed))) + (dotimes (s5-1 32) + (with-dma-buffer-add-bucket ((s3-0 (-> *display* frames (-> *display* on-screen) debug-buf)) + (bucket-id bucket583) + ) + (draw-sprite2d-xy + s3-0 + (the int (* 120.0 (-> gp-0 s5-1 x))) + (the int (* 144.0 (-> gp-0 s5-1 y))) + 10 + 10 + (new 'static 'rgba :a #x80 :r (- 255 (* 7 s5-1))) + #x3fffff + ) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-light +;; INFO: Used lq/sq +(defun-debug add-debug-light ((arg0 symbol) (arg1 bucket-id) (arg2 light) (arg3 vector) (arg4 string)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + ) + (init-vf0-vector) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (when (!= (-> arg2 extra x) 0.0) + (add-debug-vector + arg0 + arg1 + arg3 + (-> arg2 direction) + (meters 3) + (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80) + ) + (let ((s2-0 (new-stack-vector0))) + (let ((v1-4 (-> arg2 direction))) + (let ((a0-3 (* 12288.0 (-> arg2 extra x)))) + (.mov vf7 a0-3) + ) + (.lvf vf5 (&-> v1-4 quad)) + ) + (.lvf vf4 (&-> arg3 quad)) + (.add.x.vf vf6 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf5 vf7 :mask #b111) + (.add.mul.w.vf vf6 vf4 vf0 acc :mask #b111) + (.svf (&-> s2-0 quad) vf6) + (let ((s1-1 (logior (logior (logior (shr (shl (the int (* 128.0 (-> arg2 color w))) 56) 32) + (shr (shl (the int (* 128.0 (-> arg2 color z))) 56) 40) + ) + (shr (shl (the int (* 128.0 (-> arg2 color y))) 56) 48) + ) + (shr (shl (the int (* 128.0 (-> arg2 color x))) 56) 56) + ) + ) + ) + (format (clear *temp-string*) "~S ~,,2f" arg4 (-> arg2 extra x)) + (let ((t0-2 *temp-string*)) + (add-debug-text-sphere arg0 arg1 s2-0 (* 2048.0 (-> arg2 extra x)) t0-2 (the-as rgba s1-1)) + ) + ) + ) + ) + #f + ) + ) + +;; definition (debug) for function add-debug-lights +(defun-debug add-debug-lights ((arg0 symbol) (arg1 bucket-id) (arg2 (inline-array light)) (arg3 vector)) + (if (not (or arg0 *display-capture-mode*)) + (return #f) + ) + (add-debug-light arg0 arg1 (-> arg2 0) arg3 "dir0") + (add-debug-light arg0 arg1 (-> arg2 1) arg3 "dir1") + (add-debug-light arg0 arg1 (-> arg2 2) arg3 "dir2") + (add-debug-light arg0 arg1 (-> arg2 3) arg3 "ambi") + #f + ) + +;; definition (debug) for function drawable-frag-count +(defun-debug drawable-frag-count ((arg0 drawable)) + (let ((gp-0 0)) + (cond + ((not arg0) + ) + ((type? arg0 drawable-group) + (dotimes (s4-0 (-> (the-as drawable-group arg0) length)) + (+! gp-0 (drawable-frag-count (-> (the-as drawable-group arg0) data s4-0))) + ) + ) + (else + (+! gp-0 1) + ) + ) + gp-0 + ) + ) + +;; definition for method 3 of type debug-vertex-stats +(defmethod inspect ((this debug-vertex-stats)) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~Tlength: ~D~%" (-> this length)) + (format #t "~Tpos-count: ~D~%" (-> this pos-count)) + (format #t "~Tdata[~D]: @ #x~X~%" (-> this length) (-> this vertex)) + (dotimes (s5-0 (-> this length)) + (let ((s4-0 (-> this vertex s5-0))) + (format + #t + " ~D : trans: ~D ~D ~D ~D" + s5-0 + (-> s4-0 trans x) + (-> s4-0 trans y) + (-> s4-0 trans z) + (-> s4-0 trans w) + ) + (format #t " st: ~D ~D~%" (-> s4-0 st x) (-> s4-0 st y)) + (format + #t + " col: ~X norm: ~D ~D ~D~%" + (-> s4-0 color) + (-> s4-0 normal x) + (-> s4-0 normal y) + (-> s4-0 normal z) + ) + ) + ) + this + ) + +;; definition (debug) for function history-init +(defun-debug history-init ((arg0 pos-history) (arg1 int)) + (set! (-> arg0 num-points) arg1) + (set! (-> arg0 points) (the-as (inline-array vector) #f)) + arg0 + ) + +;; definition (debug) for function history-draw-and-update +;; INFO: Used lq/sq +(defun-debug history-draw-and-update ((arg0 pos-history) (arg1 symbol) (arg2 vector)) + (if (and arg1 (not (-> arg0 points))) + (set! (-> arg0 points) (the-as (inline-array vector) (malloc 'debug (* (-> arg0 num-points) 16)))) + ) + (when (-> arg0 points) + (set! (-> arg0 points (-> arg0 h-first) quad) (-> arg2 quad)) + (+! (-> arg0 h-first) 1) + (when (>= (-> arg0 h-first) (-> arg0 num-points)) + (set! (-> arg0 h-first) 0) + 0 + ) + ) + (when (and arg1 (not *display-capture-mode*)) + (dotimes (s5-1 (+ (-> arg0 num-points) -1)) + (if (!= (+ s5-1 1) (-> arg0 h-first)) + (add-debug-line + #t + (bucket-id debug-no-zbuf1) + (-> arg0 points s5-1) + (-> arg0 points (+ s5-1 1)) + (new 'static 'rgba :r #x80 :g #xc0 :b #x80 :a #x80) + #f + (the-as rgba -1) + ) + ) + ) + ) + #f + ) + +;; definition (debug) for function dma-timeout-cam +;; INFO: Used lq/sq +(defun-debug dma-timeout-cam () + (let ((a0-0 (new-stack-vector0)) + (a1-0 (new 'stack-no-clear 'matrix)) + ) + (set! (-> a1-0 rvec quad) (the-as uint128 0)) + (set! (-> a1-0 uvec quad) (the-as uint128 0)) + (set! (-> a1-0 fvec quad) (the-as uint128 0)) + (set! (-> a1-0 trans quad) (the-as uint128 0)) + (set! (-> a0-0 x) -666764.4) + (set! (-> a0-0 y) 21102.984) + (set! (-> a0-0 z) 51613.348) + (set! (-> a0-0 w) 1.0) + (set! (-> a1-0 rvec x) -0.911) + (set! (-> a1-0 rvec y) 0.0) + (set! (-> a1-0 rvec z) 0.4122) + (set! (-> a1-0 rvec w) 0.0) + (set! (-> a1-0 uvec x) -0.0984) + (set! (-> a1-0 uvec y) 0.971) + (set! (-> a1-0 uvec z) -0.2174) + (set! (-> a1-0 uvec w) 0.0) + (set! (-> a1-0 fvec x) -0.4003) + (set! (-> a1-0 fvec y) -0.2387) + (set! (-> a1-0 fvec z) -0.8847) + (set! (-> a1-0 fvec w) 0.0) + (set! (-> a1-0 trans x) 0.0) + (set! (-> a1-0 trans y) 0.0) + (set! (-> a1-0 trans z) 0.0) + (set! (-> a1-0 trans w) 1.0) + (debug-set-camera-pos-rot! a0-0 a1-0) + ) + ) + +;; definition (debug) for function display-file-info +(defun-debug display-file-info () + (when (and *display-file-info* (!= *master-mode* 'menu)) + (dotimes (gp-0 (-> *level* length)) + (let ((v1-7 (-> *level* level gp-0))) + (when (= (-> v1-7 status) 'active) + (let ((s5-0 (-> v1-7 bsp))) + (format *stdcon* "file name: ~S~%" (-> s5-0 info file-name)) + (format *stdcon* "version: ~D.~D~%" (-> s5-0 info major-version) (-> s5-0 info minor-version)) + (format *stdcon* "maya file: ~S~%" (-> s5-0 info maya-file-name)) + (format *stdcon* "mdb file: ~S~%" (-> s5-0 info mdb-file-name)) + (format *stdcon* "~S" (-> s5-0 info tool-debug)) + ) + ) + ) + ) + ) + 0 + ) + +;; definition (debug) for function add-debug-cursor +;; INFO: Used lq/sq +(defun-debug add-debug-cursor ((arg0 symbol) (arg1 bucket-id) (arg2 int) (arg3 int) (arg4 mouse-buttons)) + (when (and arg0 (not *display-capture-mode*)) + (with-dma-buffer-add-bucket ((s4-0 (-> *display* frames (-> *display* on-screen) global-buf)) + arg1 + ) + (set! (-> (new 'stack-no-clear 'vector) quad) (the-as uint128 0)) + (let ((v1-9 arg4)) + (draw-string-xy + "X" + s4-0 + (+ arg2 -5) + (+ arg3 -4) + (cond + ((= v1-9 (mouse-buttons left)) + (font-color red) + ) + ((= v1-9 (mouse-buttons right)) + (font-color yellow) + ) + ((= v1-9 (mouse-buttons middle)) + (font-color green) + ) + (else + (font-color default) + ) + ) + (font-flags shadow) + ) + ) + ) + ) + 0 + ) + +;; this part is debug only +(when *debug-segment* +;; definition for symbol *boundary-polygon*, type (inline-array sky-vertex) +(define *boundary-polygon* (the-as (inline-array sky-vertex) (malloc 'debug 768))) + +) +;; definition (debug) for function init-boundary-regs +;; INFO: function output is handled by mips2c +(def-mips2c init-boundary-regs (function none)) + +;; definition (debug) for function add-boundary-shader +;; WARN: Return type mismatch pointer vs none. +(defun-debug add-boundary-shader ((arg0 texture-id) (arg1 dma-buffer)) + (let ((a1-1 (lookup-texture-by-id arg0))) + (when a1-1 + (let* ((v1-0 arg1) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as gs-gif-tag a0-1) tag) (new 'static 'gif-tag64 :nloop #x1 :nreg #x5)) + (set! (-> (the-as gs-gif-tag a0-1) regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + ) + ) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (let ((s5-0 (the-as adgif-shader (-> arg1 base)))) + (adgif-shader<-texture-simple! s5-0 a1-1) + (set! (-> s5-0 alpha) (new 'static 'gs-alpha :b #x1 :d #x1)) + (set! (-> s5-0 tex0 tfx) 0) + (set! (-> s5-0 tex1 mmag) 0) + (set! (-> s5-0 clamp) (new 'static 'gs-clamp)) + ) + 0 + (&+! (-> arg1 base) 80) + ) + ) + (none) + ) + +;; definition (debug) for function draw-boundary-polygon +;; INFO: function output is handled by mips2c +(def-mips2c draw-boundary-polygon function) + +;; definition (debug) for function render-boundary-quad +;; INFO: function output is handled by mips2c +(def-mips2c render-boundary-quad function) + +;; definition (debug) for function render-boundary-tri +;; INFO: function output is handled by mips2c +(def-mips2c render-boundary-tri (function sky-vertex dma-buffer none)) + +;; definition (debug) for function add-debug-bound-internal +;; INFO: Used lq/sq +;; WARN: Return type mismatch symbol vs none. +(defun-debug add-debug-bound-internal ((arg0 dma-buffer) (arg1 (inline-array vector)) (arg2 int) (arg3 rgba) (arg4 rgba) (arg5 int)) + (rlet ((vf27 :class vf)) + (cond + ((nonzero? arg5) + (set-vector! + (-> *boundary-polygon* 0 col) + (the float (-> arg3 r)) + (the float (-> arg3 g)) + (the float (-> arg3 b)) + (the float (-> arg3 a)) + ) + (set-vector! + (-> *boundary-polygon* 1 col) + (the float (-> arg4 r)) + (the float (-> arg4 g)) + (the float (-> arg4 b)) + (the float (-> arg4 a)) + ) + ) + (else + (set-vector! + (-> *boundary-polygon* 0 col) + (the float (-> arg3 r)) + (the float (-> arg3 g)) + (the float (-> arg3 b)) + (the float (shr (-> arg3 a) 1)) + ) + (set-vector! + (-> *boundary-polygon* 1 col) + (the float (-> arg4 r)) + (the float (-> arg4 g)) + (the float (-> arg4 b)) + (the float (shr (-> arg4 a) 1)) + ) + ) + ) + (init-boundary-regs) + (.lvf vf27 (&-> *sky-work* giftag-roof quad)) + (let ((s3-0 0) + (s2-0 (new 'static 'inline-array vector 4 + (new 'static 'vector :x 1.0 :y 8.0 :z 1.0 :w 1.0) + (new 'static 'vector :z 1.0 :w 1.0) + (new 'static 'vector :y 8.0 :z 1.0 :w 1.0) + (new 'static 'vector :x 1.0 :z 1.0 :w 1.0) + ) + ) + ) + (while (< s3-0 (+ arg2 -2)) + (cond + ((not (logtest? s3-0 1)) + (dotimes (v1-10 3) + (set! (-> *boundary-polygon* v1-10 pos quad) (-> arg1 (+ s3-0 v1-10) quad)) + (set! (-> *boundary-polygon* v1-10 stq quad) (-> s2-0 (+ s3-0 v1-10) quad)) + ) + ) + (else + (set! (-> *boundary-polygon* 0 pos quad) (-> arg1 (+ s3-0 1) quad)) + (set! (-> *boundary-polygon* 1 pos quad) (-> arg1 s3-0 quad)) + (set! (-> *boundary-polygon* 2 pos quad) (-> arg1 (+ s3-0 2) quad)) + (set! (-> *boundary-polygon* 0 stq quad) (-> s2-0 (+ s3-0 1) quad)) + (set! (-> *boundary-polygon* 1 stq quad) (-> s2-0 s3-0 quad)) + (set! (-> *boundary-polygon* 2 stq quad) (-> s2-0 (+ s3-0 2) quad)) + ) + ) + (render-boundary-tri (-> *boundary-polygon* 0) arg0) + (+! s3-0 1) + ) + ) + (none) + ) + ) + +;; definition (debug) for function add-debug-bound +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +;; WARN: Function add-debug-bound has a return type of none, but the expression builder found a return statement. +(defun-debug add-debug-bound ((arg0 bucket-id) (arg1 (inline-array vector)) (arg2 int) (arg3 rgba) (arg4 rgba) (arg5 int)) + (local-vars (sv-16 dma-packet) (sv-32 rgba) (sv-48 int) (sv-64 int) (sv-80 int)) + (set! sv-32 arg4) + (let ((s1-0 arg5)) + (if (< arg2 3) + (return 0) + ) + (with-dma-buffer-add-bucket ((s2-0 (-> *display* frames (-> *display* on-screen) global-buf)) + arg0 + ) + (dma-buffer-add-gs-set s2-0 + (zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24))) + (test-1 (new 'static 'gs-test :zte #x1 :ztst (gs-ztest greater-equal))) + (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) + ) + (set! sv-16 (the-as dma-packet (-> s2-0 base))) + (&+! (-> s2-0 base) 16) + (add-boundary-shader (new 'static 'texture-id :index #x3 :page #x1) s2-0) + (let ((t9-1 add-debug-bound-internal) + (a0-9 s2-0) + (a1-13 arg1) + (a2-1 arg2) + (t1-1 s1-0) + ) + (t9-1 a0-9 a1-13 a2-1 arg3 sv-32 t1-1) + ) + (close-sky-buffer s2-0) + (let ((v1-16 (/ (+ (- -16 (the-as int sv-16)) (the-as int (-> s2-0 base))) 16))) + (set! (-> sv-16 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc v1-16)) + (set! (-> sv-16 vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet sv-16) vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1 :imm v1-16)) + ) + (dma-buffer-add-gs-set s2-0 + (zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24))) + (test-1 (new 'static 'gs-test :zte #x1 :ztst (gs-ztest greater-equal))) + (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) + ) + (let ((s1-1 (if (= s1-0 1) + (the-as int (the-as uint #x80ffffff)) + #x60606060 + ) + ) + (s0-1 (/ arg2 4)) + ) + (add-debug-line #t arg0 (-> arg1 0) (-> arg1 1) (the-as rgba s1-1) #f (the-as rgba -1)) + (add-debug-line #t arg0 (-> arg1 0) (-> arg1 2) (the-as rgba s1-1) #f (the-as rgba -1)) + (add-debug-line #t arg0 (-> arg1 (+ arg2 -1)) (-> arg1 (+ arg2 -2)) (the-as rgba s1-1) #f (the-as rgba -1)) + (set! sv-48 0) + (while (< sv-48 s0-1) + (let* ((a2-5 (+ (* sv-48 2) 1)) + (v1-31 (+ a2-5 2)) + ) + (set! sv-64 (+ a2-5 1)) + (set! sv-80 (+ sv-64 2)) + (if (< sv-64 arg2) + (add-debug-line #t arg0 (-> arg1 a2-5) (-> arg1 v1-31) (the-as rgba s1-1) #f (the-as rgba -1)) + ) + ) + (if (< sv-80 arg2) + (add-debug-line #t arg0 (-> arg1 sv-64) (-> arg1 sv-80) (the-as rgba s1-1) #f (the-as rgba -1)) + ) + (set! sv-48 (+ sv-48 1)) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition (debug) for function cpu-delay +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition (debug) for function qword-read-time +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition (debug) for function bugfix? +(defun-debug bugfix? () + (let ((s5-0 (the-as int #xffffffff)) + (gp-0 (the-as int #xffffffff)) + (s4-0 (logior #x20000000 (logand (the-as uint #xffffffc0) #f))) + ) + 0 + (let ((s3-0 (+ #x2000000 s4-0))) + (dotimes (s2-0 100) + (set! s5-0 (min s5-0 (qword-read-time (the-as (array uint128) s4-0) 128))) + (set! gp-0 (min gp-0 (qword-read-time (the-as (array uint128) s3-0) 128))) + ) + (let ((f30-0 (/ (the float gp-0) (the float s5-0)))) + (format #t "qword read times: hi #x~x ~d, lo #x~x ~d~%" s3-0 gp-0 s4-0 s5-0) + (format #t "hi/lo memory bank uncached read speed ratio is ~f~%" f30-0) + (format + #t + "If the workaround for the EE memory controller bug is turned on, this ratio should be about 1.3, otherwise about 1.0.~%" + ) + (< 1.15 f30-0) + ) + ) + ) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/gfx/font-h_REF.gc b/test/decompiler/reference/jak3/engine/gfx/font-h_REF.gc index 0dfe93a15..eaca2ff01 100644 --- a/test/decompiler/reference/jak3/engine/gfx/font-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/gfx/font-h_REF.gc @@ -284,7 +284,7 @@ (reg-save uint32 5) ) (:methods - (font-work-method-9 () none) + (set-context! (_type_ object) none) ) ) @@ -775,7 +775,3 @@ ;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak3/engine/gfx/sprite/particles/sparticle-h_REF.gc b/test/decompiler/reference/jak3/engine/gfx/sprite/particles/sparticle-h_REF.gc index 8be83c3a8..638eec1d7 100644 --- a/test/decompiler/reference/jak3/engine/gfx/sprite/particles/sparticle-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/gfx/sprite/particles/sparticle-h_REF.gc @@ -68,12 +68,12 @@ (format #t "~1Tfriction: ~f~%" (-> this friction)) (format #t "~1Ttimer: ~D~%" (-> this timer)) (format #t "~1Tflags: ~D~%" (-> this flags)) - (format #t "~1Tuser-int32: ~D~%" (-> this user-int32)) - (format #t "~1Tuser-uint32: ~D~%" (-> this user-uint32)) - (format #t "~1Tuser-float: ~f~%" (the-as float (-> this user-uint32))) - (format #t "~1Tuser-pntr: #x~X~%" (-> this user-uint32)) - (format #t "~1Tuser-object: ~A~%" (-> this user-int32)) - (format #t "~1Tuser-sprite: #~%" (-> this user-uint32)) + (format #t "~1Tuser-int32: ~D~%" (-> this user-float)) + (format #t "~1Tuser-uint32: ~D~%" (-> this user-float)) + (format #t "~1Tuser-float: ~f~%" (the-as float (-> this user-float))) + (format #t "~1Tuser-pntr: #x~X~%" (-> this user-float)) + (format #t "~1Tuser-object: ~A~%" (-> this user-float)) + (format #t "~1Tuser-sprite: #~%" (-> this user-float)) (format #t "~1Tsp-func: ~A~%" (-> this sp-func)) (format #t "~1Tnext-time: ~D~%" (-> this next-time)) (format #t "~1Tnext-launcher: ~A~%" (-> this next-launcher)) @@ -172,7 +172,3 @@ There are separate systems for different modes of sprite rendering: 2D/billboard ;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak3/engine/gfx/sprite/simple-sprite-h_REF.gc b/test/decompiler/reference/jak3/engine/gfx/sprite/simple-sprite-h_REF.gc index 98f9b54ee..72c40b2c3 100644 --- a/test/decompiler/reference/jak3/engine/gfx/sprite/simple-sprite-h_REF.gc +++ b/test/decompiler/reference/jak3/engine/gfx/sprite/simple-sprite-h_REF.gc @@ -4,8 +4,8 @@ ;; definition of type sprite-glow-data (deftype sprite-glow-data (structure) ((position vector :inline) - (size-x float :overlay-at (-> position data 3)) - (size-probe float :offset 16) + (size-x float :overlay-at (-> position data 3)) + (size-probe float :offset 16) (z-offset float) (rot-angle float) (size-y float) @@ -14,6 +14,7 @@ (fade-b float) (tex-id texture-id) (dummy uint32) + (quads vector 4 :inline :overlay-at position) ) (:methods (set-trans (_type_ vector) none) @@ -61,9 +62,9 @@ (data (inline-array sprite-glow-data)) ) (:methods - (simple-sprite-system-method-9 () none) + (add! (_type_ sprite-glow-data) none) (draw-all-sprites! (_type_ dma-buffer) none) - (simple-sprite-system-method-11 () none) + (clear! (_type_) none) ) ) diff --git a/test/decompiler/reference/jak3/engine/gfx/sprite/sprite-distort_REF.gc b/test/decompiler/reference/jak3/engine/gfx/sprite/sprite-distort_REF.gc new file mode 100644 index 000000000..a14dd1505 --- /dev/null +++ b/test/decompiler/reference/jak3/engine/gfx/sprite/sprite-distort_REF.gc @@ -0,0 +1,378 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type sprite-distorter-sine-tables +(deftype sprite-distorter-sine-tables (basic) + "Table of precomputed sine data for the sprite distorter renderer." + ((aspx float) + (aspy float) + (entry vector 128 :inline) + (ientry qword 9 :inline) + (giftag gs-gif-tag :inline) + (color qword :inline) + ) + ) + +;; definition for method 3 of type sprite-distorter-sine-tables +(defmethod inspect ((this sprite-distorter-sine-tables)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this (-> this type)) + (format #t "~1Taspx: ~f~%" (-> this aspx)) + (format #t "~1Taspy: ~f~%" (-> this aspy)) + (format #t "~1Tentry[128] @ #x~X~%" (-> this entry)) + (format #t "~1Tientry[9] @ #x~X~%" (-> this ientry)) + (format #t "~1Tgiftag: #~%" (-> this giftag)) + (format #t "~1Tcolor: #~%" (-> this color)) + (label cfg-4) + this + ) + +;; failed to figure out what this is: +(kmemopen global "sprite-distort-tables") + +;; definition for symbol *sprite-distorter-sine-tables*, type sprite-distorter-sine-tables +(define *sprite-distorter-sine-tables* (new 'global 'sprite-distorter-sine-tables)) + +;; failed to figure out what this is: +(kmemclose) + +;; definition for function sprite-distorter-generate-tables +;; WARN: Return type mismatch int vs none. +(defun sprite-distorter-generate-tables () + "Regenerate the sprite-distorter-sine-tables for the current camera settings." + (let ((gp-0 *sprite-distorter-sine-tables*)) + (let ((s3-0 0) + (s5-0 0) + (s4-0 3) + (f28-0 (- (-> *math-camera* perspective rvec x))) + (f30-0 (- (-> *math-camera* perspective uvec y))) + ) + (when (or (!= f28-0 (-> gp-0 aspx)) (!= f30-0 (-> gp-0 aspy))) + (set! (-> gp-0 aspx) f28-0) + (set! (-> gp-0 aspy) f30-0) + (while (< s4-0 12) + (set! (-> gp-0 ientry s5-0 vector4w x) (+ s3-0 352)) + (+! s5-0 1) + (dotimes (s2-0 s4-0) + (let ((f26-0 (* 65536.0 (/ (the float s2-0) (the float s4-0))))) + (set-vector! (-> gp-0 entry s3-0) (* (sin f26-0) f28-0) (* (cos f26-0) f30-0) 0.0 0.0) + (let ((s3-1 (+ s3-0 1))) + (set-vector! (-> gp-0 entry s3-1) (* 0.001953125 f28-0 (sin f26-0)) (* 0.001953125 f30-0 (cos f26-0)) 0.0 0.0) + (set! s3-0 (+ s3-1 1)) + ) + ) + ) + (+! s4-0 1) + ) + (set-vector! (-> gp-0 entry s3-0) 0.0 f30-0 0.0 0.0) + (let ((v1-20 (+ s3-0 1))) + (set-vector! (-> gp-0 entry v1-20) 0.0 (* 0.001953125 f30-0) 0.0 0.0) + (+ v1-20 1) + ) + ) + ) + (set! (-> gp-0 giftag tag) (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :tme #x1) + :nreg #xf + ) + ) + (set! (-> gp-0 giftag regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id st) + :regs1 (gif-reg-id rgbaq) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id rgbaq) + :regs5 (gif-reg-id xyzf2) + :regs6 (gif-reg-id st) + :regs7 (gif-reg-id rgbaq) + :regs8 (gif-reg-id xyzf2) + :regs9 (gif-reg-id st) + :regs10 (gif-reg-id rgbaq) + :regs11 (gif-reg-id xyzf2) + :regs12 (gif-reg-id st) + :regs13 (gif-reg-id rgbaq) + :regs14 (gif-reg-id xyzf2) + ) + ) + (set! (-> gp-0 color vector4w x) 128) + (set! (-> gp-0 color vector4w y) 128) + (set! (-> gp-0 color vector4w z) 128) + (set! (-> gp-0 color vector4w w) 128) + ) + 0 + (none) + ) + +;; definition for symbol sprite-distort-vu1-block, type vu-function +(define sprite-distort-vu1-block (new 'static 'vu-function :length 63 :qlength 32)) + +;; definition for function sprite-init-distorter +;; WARN: Return type mismatch int vs none. +(defun sprite-init-distorter ((arg0 dma-buffer)) + "Generate DMA to initialize the distort renderer." + (dma-buffer-add-gs-set arg0 + (zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24) :zmsk #x1)) + (tex0-1 (new 'static 'gs-tex0 :tbp0 #x3300 :tbw #x8 :tw #x9 :th #x9)) + (tex1-1 (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) + (miptbp1-1 (new 'static 'gs-miptbp)) + (clamp-1 (new 'static 'gs-clamp + :wms (gs-tex-wrap-mode region-clamp) + :wmt (gs-tex-wrap-mode region-clamp) + :maxu #x1ff + :maxv #x19f + ) + ) + (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) + ) + (let* ((v1-3 arg0) + (a1-6 (the-as dma-packet (-> v1-3 base))) + ) + (set! (-> a1-6 dma) (new 'static 'dma-tag + :qwc #x8b + :id (dma-tag-id ref) + :addr (the-as uint (-> *sprite-distorter-sine-tables* entry)) + ) + ) + (set! (-> a1-6 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> a1-6 vif1) (new 'static 'vif-tag :imm #x160 :num #x8b :cmd (vif-cmd unpack-v4-32))) + (set! (-> v1-3 base) (the-as pointer (&+ a1-6 16))) + ) + (dma-buffer-add-vu-function arg0 sprite-distort-vu1-block 1) + 0 + (none) + ) + +;; definition for function sprite-draw-distorters +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +;; ERROR: Inline assembly instruction marked with TODO - [TODO.VCLIP] +;; ERROR: Unsupported inline assembly instruction kind - [cfc2.i v1, Clipping] +(defun sprite-draw-distorters ((arg0 dma-buffer)) + "Generate DMA to draw all distort sprites." + (local-vars + (v1-15 float) + (v1-21 float) + (v1-26 int) + (v1-65 float) + (sv-16 sprite-vec-data-2d) + (sv-32 vector) + (sv-48 vector) + ) + (rlet ((acc :class vf) + (Q :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (.lvf vf8 (&-> *math-camera* hmge-scale quad)) + (let ((s0-0 (-> arg0 base)) + (s4-0 0) + (s5-0 0) + ) + (&+! (-> arg0 base) 16) + (let* ((s3-0 *sprite-aux-list*) + (s2-0 (-> s3-0 entry)) + ) + (dotimes (s1-0 s2-0) + (let ((v1-5 (-> s3-0 data s1-0))) + (when (= (-> v1-5 aux-type) (sprite-aux-type distort)) + (set! sv-16 (-> v1-5 vec-data)) + (let ((a0-3 (the-as object (-> arg0 base)))) + (set! sv-32 (the-as vector (&+ (the-as pointer a0-3) 16))) + (set! sv-48 (the-as vector (&+ (the-as pointer a0-3) 32))) + (cond + ((= (the-as int (-> sv-16 flag-rot-sy y)) 1) + (.lvf vf3 (&-> *math-camera* sprite-2d rvec quad)) + (.lvf vf4 (&-> *math-camera* sprite-2d uvec quad)) + (.lvf vf5 (&-> *math-camera* sprite-2d fvec quad)) + (.lvf vf6 (&-> *math-camera* sprite-2d trans quad)) + (.lvf vf9 (&-> *math-camera* sprite-2d-hvdf quad)) + (.mov v1-15 vf9) + ) + (else + (.lvf vf3 (&-> *math-camera* camera-temp rvec quad)) + (.lvf vf4 (&-> *math-camera* camera-temp uvec quad)) + (.lvf vf5 (&-> *math-camera* camera-temp fvec quad)) + (.lvf vf6 (&-> *math-camera* camera-temp trans quad)) + (.lvf vf9 (&-> *math-camera* hvdf-off quad)) + (.mov v1-21 vf9) + ) + ) + (.lvf vf1 (&-> sv-16 x-y-z-sx quad)) + (.lvf vf2 (&-> sv-16 r-g-b-a quad)) + (.mul.w.vf acc vf6 vf0) + (.add.mul.x.vf acc vf3 vf1 acc) + (.add.mul.y.vf acc vf4 vf1 acc) + (.add.mul.z.vf vf1 vf5 vf1 acc) + (.mul.vf vf10 vf1 vf8) + (.div.vf Q vf0 vf10 :fsf #b11 :ftf #b11) + (TODO.VCLIP vf10 vf10) + (b! (zero? (-> sv-16 flag-rot-sy x)) cfg-22 :delay (nop!)) + (.wait.vf) + (.mul.vf vf1 vf1 Q :mask #b111) + (.mul.vf vf2 vf2 Q :mask #b111) + (.cfc2.i v1-26 Clipping) + (b! (logtest? v1-26 63) cfg-22 :delay (.add.vf vf1 vf1 vf9)) + (.max.x.vf vf1 vf1 vf0 :mask #b1000) + (.svf (&-> (the-as vector a0-3) quad) vf1) + (.svf (&-> sv-48 quad) vf2) + (set! (-> (the-as vector a0-3) w) 255.0) + (set! (-> sv-32 x) (+ 0.0009765625 (* 0.001953125 (+ -1792.0 (-> (the-as vector a0-3) x))))) + (set! (-> sv-32 y) (+ 0.0009765625 (* 0.001953125 (+ -1840.0 (-> (the-as vector a0-3) y))))) + ) + (set! (-> sv-32 z) 1.0) + (when (or (< (the-as int (-> sv-16 flag-rot-sy x)) 3) (< 11 (the-as int (-> sv-16 flag-rot-sy x)))) + (format 0 "Turns = ~D!!!~%" (-> sv-16 flag-rot-sy x)) + (set! (-> sv-16 flag-rot-sy x) (the-as float #xb)) + ) + (set! (-> sv-32 w) (-> sv-16 flag-rot-sy x)) + (let* ((f1-4 (- (-> *math-camera* perspective uvec y))) + (f2-4 (-> sv-32 y)) + (f4-0 (+ f2-4 (* (-> sv-48 x) f1-4))) + (f3-2 256.0) + (f0-9 (-> sv-48 x)) + ) + (if (< 416.0 f4-0) + (set! f3-2 (/ (- 416.0 f2-4) f1-4)) + ) + (if (< 128.0 f3-2) + (set! f3-2 128.0) + ) + (when (< f3-2 f0-9) + (let ((v1-63 (/ f3-2 f0-9))) + (.mov vf1 v1-63) + ) + (.mul.x.vf vf2 vf2 vf1) + (.svf (&-> sv-48 quad) vf2) + (.mov v1-65 vf2) + ) + ) + (&+! (-> arg0 base) 48) + (+! s4-0 1) + (when (= s4-0 85) + (let ((v1-70 (-> arg0 base))) + (set! (-> arg0 base) s0-0) + (let* ((a0-10 arg0) + (a1-3 (the-as dma-packet (-> a0-10 base))) + ) + (set! (-> a1-3 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc (* 3 s4-0))) + (set! (-> a1-3 vif0) (new 'static 'vif-tag)) + (set! (-> a1-3 vif1) + (new 'static 'vif-tag :cmd (vif-cmd unpack-v4-32) :imm (shr (shl (+ (* 3 s5-0) 512) 54) 54) :num (* 3 s4-0)) + ) + (set! (-> a0-10 base) (the-as pointer (&+ a1-3 16))) + ) + (set! (-> arg0 base) v1-70) + ) + (set! s4-0 0) + (+! s5-0 85) + (when (= s5-0 170) + (let* ((v1-73 arg0) + (a0-11 (the-as dma-packet (-> v1-73 base))) + ) + (set! (-> a0-11 dma) (new 'static 'dma-tag :qwc #x1 :id (dma-tag-id cnt))) + (set! (-> a0-11 vif0) (new 'static 'vif-tag)) + (set! (-> a0-11 vif1) (new 'static 'vif-tag :imm #x1ff :num #x1 :cmd (vif-cmd unpack-v4-32))) + (set! (-> v1-73 base) (the-as pointer (&+ a0-11 16))) + ) + (let* ((v1-74 arg0) + (a0-13 (the-as vector4w (-> v1-74 base))) + ) + (set! (-> a0-13 x) s5-0) + (set! (-> a0-13 y) 0) + (set! (-> a0-13 z) 0) + (set! (-> a0-13 w) 0) + (set! (-> v1-74 base) (the-as pointer (&+ a0-13 16))) + ) + (let* ((v1-75 arg0) + (a0-15 (the-as dma-packet (-> v1-75 base))) + ) + (set! (-> a0-15 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a0-15 vif0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> a0-15 vif1) (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1)) + (set! (-> v1-75 base) (the-as pointer (&+ a0-15 16))) + ) + (set! s5-0 0) + ) + (set! s0-0 (-> arg0 base)) + (&+! (-> arg0 base) 16) + ) + ) + ) + (label cfg-22) + 0 + ) + ) + (cond + ((zero? s4-0) + (set! (-> arg0 base) s0-0) + (nop!) + 0 + ) + (else + (let ((v1-83 (-> arg0 base))) + (set! (-> arg0 base) s0-0) + (let* ((a0-17 arg0) + (a1-10 (the-as dma-packet (-> a0-17 base))) + ) + (set! (-> a1-10 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc (* 3 s4-0))) + (set! (-> a1-10 vif0) (new 'static 'vif-tag)) + (set! (-> a1-10 vif1) + (new 'static 'vif-tag :cmd (vif-cmd unpack-v4-32) :imm (shr (shl (+ (* 3 s5-0) 512) 54) 54) :num (* 3 s4-0)) + ) + (set! (-> a0-17 base) (the-as pointer (&+ a1-10 16))) + ) + (set! (-> arg0 base) v1-83) + ) + ) + ) + (let ((v1-84 (+ s4-0 s5-0))) + (when (nonzero? v1-84) + (let* ((a0-19 arg0) + (a1-12 (the-as dma-packet (-> a0-19 base))) + ) + (set! (-> a1-12 dma) (new 'static 'dma-tag :qwc #x1 :id (dma-tag-id cnt))) + (set! (-> a1-12 vif0) (new 'static 'vif-tag)) + (set! (-> a1-12 vif1) (new 'static 'vif-tag :imm #x1ff :num #x1 :cmd (vif-cmd unpack-v4-32))) + (set! (-> a0-19 base) (the-as pointer (&+ a1-12 16))) + ) + (let* ((a0-20 arg0) + (a1-14 (the-as vector4w (-> a0-20 base))) + ) + (set! (-> a1-14 x) v1-84) + (set! (-> a1-14 y) 0) + (set! (-> a1-14 z) 0) + (set! (-> a1-14 w) 0) + (set! (-> a0-20 base) (the-as pointer (&+ a1-14 16))) + ) + (let ((v1-86 (the-as dma-packet (-> arg0 base)))) + (set! (-> v1-86 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> v1-86 vif0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> v1-86 vif1) (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1)) + (set! (-> arg0 base) (the-as pointer (&+ v1-86 16))) + ) + ) + ) + ) + 0 + (none) + ) + ) + + + + diff --git a/test/decompiler/reference/jak3/engine/gfx/sprite/sprite-glow_REF.gc b/test/decompiler/reference/jak3/engine/gfx/sprite/sprite-glow_REF.gc new file mode 100644 index 000000000..da203da5e --- /dev/null +++ b/test/decompiler/reference/jak3/engine/gfx/sprite/sprite-glow_REF.gc @@ -0,0 +1,915 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type sprite-glow-template +(deftype sprite-glow-template (structure) + "Sprite glow GS data templates sent to VU1." + ((clear-init-giftag gs-gif-tag :inline) + (clear-init-adcmds gs-adcmd 5 :inline) + (clear-draw-giftag gs-gif-tag :inline) + (clear-draw-clr-0 gs-packed-rgba :inline) + (clear-draw-xyz-0 gs-packed-xyzw 2 :inline) + (clear-draw-clr-1 gs-packed-rgba :inline) + (clear-draw-xyz-1 vector 2 :inline) + (offscr-setup-giftag gs-gif-tag :inline) + (offscr-setup-adcmds gs-adcmd 8 :inline) + (offscr-first-giftag gs-gif-tag :inline) + (offscr-first-clr gs-packed-rgba :inline) + (offscr-first-uv-0 gs-packed-uv :inline) + (offscr-first-xyzw-0 gs-packed-xyzw :inline) + (offscr-first-uv-1 gs-packed-uv :inline) + (offscr-first-xyzw-1 gs-packed-xyzw :inline) + (repeat-draw-giftag gs-gif-tag :inline) + (repeat-draw-adcmds gs-adcmd 29 :inline) + (flare-alpha-giftag gs-gif-tag :inline) + (flare-alpha-clr gs-packed-rgba :inline) + (flare-alpha-uv gs-packed-uv :inline) + (flare-alpha-xyzw-0 gs-packed-xyzw :inline) + (flare-alpha-xyzw-1 gs-packed-xyzw :inline) + (flare-alpha-xyzw-2 gs-packed-xyzw :inline) + (flare-alpha-xyzw-3 gs-packed-xyzw :inline) + (flare-init-giftag gs-gif-tag :inline) + (flare-init-adcmds gs-adcmd 8 :inline) + (flare-draw-giftag gs-gif-tag :inline) + (flare-draw-clr gs-packed-rgba :inline) + (flare-draw-stq-0 gs-packed-stq :inline) + (flare-draw-xyzw-0 gs-packed-xyzw :inline) + (flare-draw-stq-1 gs-packed-stq :inline) + (flare-draw-xyzw-1 gs-packed-xyzw :inline) + (flare-draw-stq-2 gs-packed-stq :inline) + (flare-draw-xyzw-2 gs-packed-xyzw :inline) + (flare-draw-stq-3 gs-packed-stq :inline) + (flare-draw-xyzw-3 gs-packed-xyzw :inline) + ) + ) + +;; definition for method 3 of type sprite-glow-template +(defmethod inspect ((this sprite-glow-template)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'sprite-glow-template) + (format #t "~1Tclear-init-giftag: #~%" (-> this clear-init-giftag)) + (format #t "~1Tclear-init-adcmds[5] @ #x~X~%" (-> this clear-init-adcmds)) + (format #t "~1Tclear-draw-giftag: #~%" (-> this clear-draw-giftag)) + (format #t "~1Tclear-draw-clr-0: #~%" (-> this clear-draw-clr-0)) + (format #t "~1Tclear-draw-xyz-0[2] @ #x~X~%" (-> this clear-draw-xyz-0)) + (format #t "~1Tclear-draw-clr-1: #~%" (-> this clear-draw-clr-1)) + (format #t "~1Tclear-draw-xyz-1[2] @ #x~X~%" (-> this clear-draw-xyz-1)) + (format #t "~1Toffscr-setup-giftag: #~%" (-> this offscr-setup-giftag)) + (format #t "~1Toffscr-setup-adcmds[8] @ #x~X~%" (-> this offscr-setup-adcmds)) + (format #t "~1Toffscr-first-giftag: #~%" (-> this offscr-first-giftag)) + (format #t "~1Toffscr-first-clr: #~%" (-> this offscr-first-clr)) + (format #t "~1Toffscr-first-uv-0: #~%" (-> this offscr-first-uv-0)) + (format #t "~1Toffscr-first-xyzw-0: #~%" (-> this offscr-first-xyzw-0)) + (format #t "~1Toffscr-first-uv-1: #~%" (-> this offscr-first-uv-1)) + (format #t "~1Toffscr-first-xyzw-1: #~%" (-> this offscr-first-xyzw-1)) + (format #t "~1Trepeat-draw-giftag: #~%" (-> this repeat-draw-giftag)) + (format #t "~1Trepeat-draw-adcmds[29] @ #x~X~%" (-> this repeat-draw-adcmds)) + (format #t "~1Tflare-alpha-giftag: #~%" (-> this flare-alpha-giftag)) + (format #t "~1Tflare-alpha-clr: #~%" (-> this flare-alpha-clr)) + (format #t "~1Tflare-alpha-uv: #~%" (-> this flare-alpha-uv)) + (format #t "~1Tflare-alpha-xyzw-0: #~%" (-> this flare-alpha-xyzw-0)) + (format #t "~1Tflare-alpha-xyzw-1: #~%" (-> this flare-alpha-xyzw-1)) + (format #t "~1Tflare-alpha-xyzw-2: #~%" (-> this flare-alpha-xyzw-2)) + (format #t "~1Tflare-alpha-xyzw-3: #~%" (-> this flare-alpha-xyzw-3)) + (format #t "~1Tflare-init-giftag: #~%" (-> this flare-init-giftag)) + (format #t "~1Tflare-init-adcmds[8] @ #x~X~%" (-> this flare-init-adcmds)) + (format #t "~1Tflare-draw-giftag: #~%" (-> this flare-draw-giftag)) + (format #t "~1Tflare-draw-clr: #~%" (-> this flare-draw-clr)) + (format #t "~1Tflare-draw-stq-0: #~%" (-> this flare-draw-stq-0)) + (format #t "~1Tflare-draw-xyzw-0: #~%" (-> this flare-draw-xyzw-0)) + (format #t "~1Tflare-draw-stq-1: #~%" (-> this flare-draw-stq-1)) + (format #t "~1Tflare-draw-xyzw-1: #~%" (-> this flare-draw-xyzw-1)) + (format #t "~1Tflare-draw-stq-2: #~%" (-> this flare-draw-stq-2)) + (format #t "~1Tflare-draw-xyzw-2: #~%" (-> this flare-draw-xyzw-2)) + (format #t "~1Tflare-draw-stq-3: #~%" (-> this flare-draw-stq-3)) + (format #t "~1Tflare-draw-xyzw-3: #~%" (-> this flare-draw-xyzw-3)) + (label cfg-4) + this + ) + +;; definition of type sprite-glow-consts +(deftype sprite-glow-consts (structure) + "Per-frame constants for sprite-glow VU1." + ((camera matrix :inline) + (perspective matrix :inline) + (hvdf-offset vector :inline) + (hmge-scale vector :inline) + (consts vector :inline) + (pfog0 float :overlay-at (-> consts data 0)) + (deg-to-rad float :overlay-at (-> consts data 1)) + (min-scale float :overlay-at (-> consts data 2)) + (inv-area float :overlay-at (-> consts data 3)) + (sincos-01 vector :inline) + (sincos-23 vector :inline) + (sincos-45 vector :inline) + (sincos-67 vector :inline) + (sincos-89 vector :inline) + (basis-x vector :inline) + (basis-y vector :inline) + (xy-array vector 4 :inline) + (clamp-min vector :inline) + (clamp-max vector :inline) + ) + ) + +;; definition for method 3 of type sprite-glow-consts +(defmethod inspect ((this sprite-glow-consts)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'sprite-glow-consts) + (format #t "~1Tcamera: #~%" (-> this camera)) + (format #t "~1Tperspective: #~%" (-> this perspective)) + (format #t "~1Thvdf-offset: #~%" (-> this hvdf-offset)) + (format #t "~1Thmge-scale: #~%" (-> this hmge-scale)) + (format #t "~1Tconsts: #~%" (-> this consts)) + (format #t "~1Tpfog0: ~f~%" (-> this consts x)) + (format #t "~1Tdeg-to-rad: ~f~%" (-> this consts y)) + (format #t "~1Tmin-scale: ~f~%" (-> this consts z)) + (format #t "~1Tinv-area: ~f~%" (-> this consts w)) + (format #t "~1Tsincos-01: #~%" (-> this sincos-01)) + (format #t "~1Tsincos-23: #~%" (-> this sincos-23)) + (format #t "~1Tsincos-45: #~%" (-> this sincos-45)) + (format #t "~1Tsincos-67: #~%" (-> this sincos-67)) + (format #t "~1Tsincos-89: #~%" (-> this sincos-89)) + (format #t "~1Tbasis-x: #~%" (-> this basis-x)) + (format #t "~1Tbasis-y: #~%" (-> this basis-y)) + (format #t "~1Txy-array[4] @ #x~X~%" (-> this xy-array)) + (format #t "~1Tclamp-min: #~%" (-> this clamp-min)) + (format #t "~1Tclamp-max: #~%" (-> this clamp-max)) + (label cfg-4) + this + ) + +;; definition for symbol *sprite-glow-template*, type sprite-glow-template +(define *sprite-glow-template* + (new 'static 'sprite-glow-template + :clear-init-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x5 :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :clear-init-adcmds (new 'static 'inline-array gs-adcmd 5 + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 alpha-1) :x #x6a) + (new 'static 'gs-adcmd :cmds (gs-reg64 test-1) :x #x51001) + (new 'static 'gs-adcmd :cmds (gs-reg64 zbuf-1) :x #x1000130 :y #x1) + (new 'static 'gs-adcmd :cmds (gs-reg64 frame-1) :x #x80198 :y #xffffff) + ) + :clear-draw-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x2 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite)) + :nreg #x3 + ) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) :regs1 (gif-reg-id xyzf2) :regs2 (gif-reg-id xyzf2)) + ) + :clear-draw-xyz-0 (new 'static 'inline-array gs-packed-xyzw 2 + (new 'static 'gs-packed-xyzw :iz -1) + (new 'static 'gs-packed-xyzw :iz -1) + ) + :clear-draw-clr-1 (new 'static 'gs-packed-rgba :x #xff :w #xff) + :offscr-setup-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x8 :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :offscr-setup-adcmds (new 'static 'inline-array gs-adcmd 8 + (new 'static 'gs-adcmd :cmds (gs-reg64 frame-2) :x #x10090 :y #xffffff) + (new 'static 'gs-adcmd :cmds (gs-reg64 zbuf-2) :x #x1000130) + (new 'static 'gs-adcmd :cmds (gs-reg64 tex1-2) :x #x60) + (new 'static 'gs-adcmd :cmds (gs-reg64 tex0-2) :x #x64023300 :y #xe) + (new 'static 'gs-adcmd :cmds (gs-reg64 clamp-2) :x #x5) + (new 'static 'gs-adcmd :cmds (gs-reg64 test-2) :x #x31001) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyoffset-2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + ) + :offscr-first-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1 :fst #x1 :ctxt #x1) + :nreg #x5 + ) + :regs (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id uv) + :regs2 (gif-reg-id xyz2) + :regs3 (gif-reg-id uv) + :regs4 (gif-reg-id xyz2) + ) + ) + :offscr-first-clr (new 'static 'gs-packed-rgba :x #x80 :y #x80 :z #x80 :w #x80) + :offscr-first-xyzw-1 (new 'static 'gs-packed-xyzw :ix #x200 :iy #x200) + :repeat-draw-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x1d :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :repeat-draw-adcmds (new 'static 'inline-array gs-adcmd 29 + (new 'static 'gs-adcmd :cmds (gs-reg64 tex0-2) :x #x54005200 :y #xd) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x100010) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x2100210) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2) :x #x1000100) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x100010) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x1100110) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2) :x #x800080) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x100010) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x900090) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2) :x #x400040) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x100010) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2)) + (new 'static 'gs-adcmd :cmds (gs-reg64 uv) :x #x500050) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyz2) :x #x200020) + (new 'static 'gs-adcmd :cmds (gs-reg64 frame-2) :x #x80198 :y #xffffff) + (new 'static 'gs-adcmd :cmds (gs-reg64 test-2) :x #x51001) + (new 'static 'gs-adcmd :cmds (gs-reg64 zbuf-2) :x #x1000130 :y #x1) + (new 'static 'gs-adcmd :cmds (gs-reg64 xyoffset-2) :x #x7000 :y #x7300) + (new 'static 'gs-adcmd :cmds (gs-reg64 scissor-2) :x #x1ff0000 :y #x19f0000) + (new 'static 'gs-adcmd :cmds (gs-reg64 test-2) :x #x50000) + (new 'static 'gs-adcmd :cmds (gs-reg64 alpha-2) :x #x6a) + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + ) + :flare-alpha-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fst #x1 :ctxt #x1) + :nreg #x6 + ) + :regs (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id uv) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id xyzf2) + :regs4 (gif-reg-id xyzf2) + :regs5 (gif-reg-id xyzf2) + ) + ) + :flare-alpha-clr (new 'static 'gs-packed-rgba :x #x80 :y #x80 :z #x80 :w #x80) + :flare-alpha-uv (new 'static 'gs-packed-uv :x (the-as float #x10) :y (the-as float #x10)) + :flare-alpha-xyzw-0 (new 'static 'gs-packed-xyzw :iz -1) + :flare-alpha-xyzw-1 (new 'static 'gs-packed-xyzw :iz -1) + :flare-alpha-xyzw-2 (new 'static 'gs-packed-xyzw :iz -1) + :flare-alpha-xyzw-3 (new 'static 'gs-packed-xyzw :iz -1) + :flare-init-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x8 :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :flare-init-adcmds (new 'static 'inline-array gs-adcmd 8 + (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + (new 'static 'gs-adcmd :cmds (gs-reg64 frame-1) :x #x80198) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 hack)) + (new 'static 'gs-adcmd :cmds (gs-reg64 alpha-1) :x #x58) + ) + :flare-draw-giftag (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :abe #x1) + :nreg #x9 + ) + :regs (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyzf2) + :regs5 (gif-reg-id st) + :regs6 (gif-reg-id xyzf2) + :regs7 (gif-reg-id st) + :regs8 (gif-reg-id xyzf2) + ) + ) + :flare-draw-clr (new 'static 'gs-packed-rgba :y 64 :w #x80) + :flare-draw-stq-0 (new 'static 'gs-packed-stq :z 1.0) + :flare-draw-xyzw-0 (new 'static 'gs-packed-xyzw :iz -1) + :flare-draw-stq-1 (new 'static 'gs-packed-stq :x 1.0 :z 1.0) + :flare-draw-xyzw-1 (new 'static 'gs-packed-xyzw :iz -1) + :flare-draw-stq-2 (new 'static 'gs-packed-stq :x 1.0 :y 1.0 :z 1.0) + :flare-draw-xyzw-2 (new 'static 'gs-packed-xyzw :iz -1) + :flare-draw-stq-3 (new 'static 'gs-packed-stq :y 1.0 :z 1.0) + :flare-draw-xyzw-3 (new 'static 'gs-packed-xyzw :iz -1) + ) + ) + +;; definition for symbol sprite-glow-vu1-block, type vu-function +(define sprite-glow-vu1-block (new 'static 'vu-function :length #x86 :qlength 67)) + +;; definition for function sprite-glow-init-consts +;; INFO: Used lq/sq +;; WARN: Return type mismatch vector vs none. +(defun sprite-glow-init-consts ((arg0 sprite-glow-consts)) + "Fill out sprite-glow-consts to be sent to VU1." + (let ((v1-0 *math-camera*)) + (let* ((t0-0 (-> arg0 camera)) + (t1-0 (-> v1-0 camera-rot)) + (a1-0 (-> t1-0 rvec quad)) + (a2-0 (-> t1-0 uvec quad)) + (a3-0 (-> t1-0 fvec quad)) + (t1-1 (-> t1-0 trans quad)) + ) + (set! (-> t0-0 rvec quad) a1-0) + (set! (-> t0-0 uvec quad) a2-0) + (set! (-> t0-0 fvec quad) a3-0) + (set! (-> t0-0 trans quad) t1-1) + ) + (let* ((t0-1 (-> arg0 perspective)) + (t1-2 (-> v1-0 perspective)) + (a1-1 (-> t1-2 rvec quad)) + (a2-1 (-> t1-2 uvec quad)) + (a3-1 (-> t1-2 fvec quad)) + (t1-3 (-> t1-2 trans quad)) + ) + (set! (-> t0-1 rvec quad) a1-1) + (set! (-> t0-1 uvec quad) a2-1) + (set! (-> t0-1 fvec quad) a3-1) + (set! (-> t0-1 trans quad) t1-3) + ) + (set! (-> arg0 hvdf-offset quad) (-> v1-0 hvdf-off quad)) + (set! (-> arg0 hmge-scale quad) (-> v1-0 hmge-scale quad)) + (set! (-> arg0 basis-x quad) (the-as uint128 0)) + (set! (-> arg0 basis-x x) (- (-> *math-camera* perspective rvec x))) + (set! (-> arg0 basis-y quad) (the-as uint128 0)) + (set! (-> arg0 basis-y y) (- (-> *math-camera* perspective uvec y))) + (set! (-> arg0 consts x) (-> v1-0 pfog0)) + ) + (set! (-> arg0 consts y) 0.000095873795) + (set! (-> arg0 consts z) (sqrtf (* (/ 1.0 (-> arg0 basis-x x)) (/ 1.0 (-> arg0 basis-y y))))) + (set! (-> arg0 consts w) (/ 1.0 (* (-> arg0 consts z) (-> arg0 consts z)))) + (let ((v1-5 (-> arg0 sincos-01))) + (set! (-> v1-5 z) 0.999998) + (set! (-> v1-5 w) 1.0) + ) + (let ((v1-6 (-> arg0 sincos-23))) + (set! (-> v1-6 z) -0.16666014) + (set! (-> v1-6 w) -0.49998003) + ) + (let ((v1-7 (-> arg0 sincos-45))) + (set! (-> v1-7 z) 0.008326521) + (set! (-> v1-7 w) 0.041620404) + ) + (let ((v1-8 (-> arg0 sincos-67))) + (set! (-> v1-8 z) -0.0001956241) + (set! (-> v1-8 w) -0.0013636408) + ) + (let ((v1-9 (-> arg0 sincos-89))) + (set! (-> v1-9 z) 0.0000023042373) + (set! (-> v1-9 w) 0.000020170546) + ) + (set-vector! (-> arg0 xy-array 0) -0.5 -0.5 0.0 0.0) + (set-vector! (-> arg0 xy-array 1) 0.5 -0.5 0.0 0.0) + (set-vector! (-> arg0 xy-array 2) 0.5 0.5 0.0 0.0) + (set-vector! (-> arg0 xy-array 3) -0.5 0.5 0.0 0.0) + (set-vector! (-> arg0 clamp-min) 1792.0 1840.0 0.0 0.0) + (set-vector! (-> arg0 clamp-max) 2304.0 2256.0 2048.0 50.0) + (none) + ) + +;; definition for function sprite-glow-init-engine +;; WARN: Return type mismatch int vs none. +(defun sprite-glow-init-engine ((arg0 dma-buffer)) + "Generate DMA to initialize sprite-glow VU1." + (dma-buffer-add-vu-function arg0 sprite-glow-vu1-block 1) + (let ((s5-0 24)) + (let* ((v1-0 arg0) + (a0-2 (the-as dma-packet (-> v1-0 base))) + ) + (set! (-> a0-2 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc s5-0)) + (set! (-> a0-2 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> a0-2 vif1) (new 'static 'vif-tag :imm #x3d4 :cmd (vif-cmd unpack-v4-32) :num s5-0)) + (set! (-> v1-0 base) (the-as pointer (&+ a0-2 16))) + ) + (sprite-glow-init-consts (the-as sprite-glow-consts (-> arg0 base))) + (&+! (-> arg0 base) (* s5-0 16)) + ) + (let ((v1-3 84)) + (let* ((a0-6 arg0) + (a1-6 (the-as dma-packet (-> a0-6 base))) + ) + (set! (-> a1-6 dma) + (new 'static 'dma-tag :id (dma-tag-id ref) :addr (the-as int *sprite-glow-template*) :qwc v1-3) + ) + (set! (-> a1-6 vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> a1-6 vif1) (new 'static 'vif-tag :imm #x320 :cmd (vif-cmd unpack-v4-32) :num v1-3)) + (set! (-> a0-6 base) (the-as pointer (&+ a1-6 16))) + ) + (let* ((a0-7 arg0) + (a1-8 (the-as dma-packet (-> a0-7 base))) + ) + (set! (-> a1-8 dma) + (new 'static 'dma-tag :id (dma-tag-id ref) :addr (the-as int *sprite-glow-template*) :qwc v1-3) + ) + (set! (-> a1-8 vif0) (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm #x0)) + (set! (-> a1-8 vif1) (new 'static 'vif-tag :imm #x374 :cmd (vif-cmd unpack-v4-32) :num v1-3)) + (set! (-> a0-7 base) (the-as pointer (&+ a1-8 16))) + ) + ) + (let* ((v1-8 arg0) + (a0-8 (the-as dma-packet (-> v1-8 base))) + ) + (set! (-> a0-8 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> a0-8 vif0) (new 'static 'vif-tag :cmd (vif-cmd base))) + (set! (-> a0-8 vif1) (new 'static 'vif-tag :imm #x190 :cmd (vif-cmd offset))) + (set! (-> v1-8 base) (the-as pointer (&+ a0-8 16))) + ) + (let ((v1-9 (the-as dma-packet (-> arg0 base)))) + (set! (-> v1-9 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> v1-9 vif0) (new 'static 'vif-tag)) + (set! (-> v1-9 vif1) (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1)) + (set! (-> arg0 base) (the-as pointer (&+ v1-9 16))) + ) + 0 + (none) + ) + +;; definition of type sprite-glow-dma-packet-data +(deftype sprite-glow-dma-packet-data (structure) + "DMA templates for generating DMA to VU1." + ((control-packet dma-packet :inline) + (vecdata-packet dma-packet :inline) + (shader-cnt-packet dma-packet :inline) + (shader-ref-packet dma-packet :inline) + (mscal-packet dma-packet :inline) + ) + ) + +;; definition for method 3 of type sprite-glow-dma-packet-data +(defmethod inspect ((this sprite-glow-dma-packet-data)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'sprite-glow-dma-packet-data) + (format #t "~1Tcontrol-packet: #~%" (-> this control-packet)) + (format #t "~1Tvecdata-packet: #~%" (-> this vecdata-packet)) + (format #t "~1Tshader-cnt-packet: #~%" (-> this shader-cnt-packet)) + (format #t "~1Tshader-ref-packet: #~%" (-> this shader-ref-packet)) + (format #t "~1Tmscal-packet: #~%" (-> this mscal-packet)) + (label cfg-4) + this + ) + +;; definition of type sprite-glow-cnt-template +(deftype sprite-glow-cnt-template (structure) + "DMA layout for sending a sprite to VU1, with inline shader." + ((control-packet dma-packet :inline) + (num-sprites uint32) + (dummys uint32 3) + (vecdata-packet dma-packet :inline) + (vecdata sprite-glow-data :inline) + (shader-packet dma-packet :inline) + (shader adgif-shader :inline) + (mscal-packet dma-packet :inline) + (quads vector 10 :inline :overlay-at (-> control-packet dma)) + ) + ) + +;; definition for method 3 of type sprite-glow-cnt-template +(defmethod inspect ((this sprite-glow-cnt-template)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'sprite-glow-cnt-template) + (format #t "~1Tcontrol-packet: #~%" (-> this control-packet)) + (format #t "~1Tnum-sprites: ~D~%" (-> this num-sprites)) + (format #t "~1Tdummys[3] @ #x~X~%" (-> this dummys)) + (format #t "~1Tvecdata-packet: #~%" (-> this vecdata-packet)) + (format #t "~1Tvecdata: #~%" (-> this vecdata)) + (format #t "~1Tshader-packet: #~%" (-> this shader-packet)) + (format #t "~1Tshader: #~%" (-> this shader)) + (format #t "~1Tmscal-packet: #~%" (-> this mscal-packet)) + (label cfg-4) + this + ) + +;; definition of type sprite-glow-ref-template +(deftype sprite-glow-ref-template (structure) + "DMA layout for sending a sprite to VU1, with reference to shader." + ((control-packet dma-packet :inline) + (num-sprites uint32) + (dummys uint32 3) + (num-sprites-quad uint128 :overlay-at num-sprites) + (vecdata-packet dma-packet :inline) + (vecdata sprite-glow-data :inline) + (shader-packet dma-packet :inline) + (shader-packet-ptr pointer :offset 116) + (mscal-packet dma-packet :inline) + ) + ) + +;; definition for method 3 of type sprite-glow-ref-template +(defmethod inspect ((this sprite-glow-ref-template)) + (when (not this) + (set! this this) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" this 'sprite-glow-ref-template) + (format #t "~1Tcontrol-packet: #~%" (-> this control-packet)) + (format #t "~1Tnum-sprites: ~D~%" (-> this num-sprites)) + (format #t "~1Tdummys[3] @ #x~X~%" (-> this dummys)) + (format #t "~1Tvecdata-packet: #~%" (-> this vecdata-packet)) + (format #t "~1Tvecdata: #~%" (-> this vecdata)) + (format #t "~1Tshader-packet: #~%" (-> this shader-packet)) + (format #t "~1Tmscal-packet: #~%" (-> this mscal-packet)) + (label cfg-4) + this + ) + +;; definition for symbol *sprite-glow-dma-packet-data*, type sprite-glow-dma-packet-data +(define *sprite-glow-dma-packet-data* + (new 'static 'sprite-glow-dma-packet-data + :control-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x1 :id (dma-tag-id cnt)) + :vif0 (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + :vif1 (new 'static 'vif-tag :imm #x8000 :num #x1 :cmd (vif-cmd unpack-v4-32)) + ) + :vecdata-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif0 (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + :vif1 (new 'static 'vif-tag :imm #x8001 :num #x4 :cmd (vif-cmd unpack-v4-32)) + ) + :shader-cnt-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x5 :id (dma-tag-id cnt)) + :vif0 (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + :vif1 (new 'static 'vif-tag :imm #x8091 :num #x5 :cmd (vif-cmd unpack-v4-32)) + ) + :shader-ref-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x5 :id (dma-tag-id ref)) + :vif0 (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + :vif1 (new 'static 'vif-tag :imm #x8091 :num #x5 :cmd (vif-cmd unpack-v4-32)) + ) + :mscal-packet (new 'static 'dma-packet + :dma (new 'static 'dma-tag :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1) + ) + ) + ) + +;; failed to figure out what this is: +(set! (-> *sprite-glow-dma-packet-data* mscal-packet vif0) + (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1 :imm #xa) + ) + +;; definition for function sprite-glow-add-sprite +;; INFO: Used lq/sq +;; WARN: Return type mismatch sprite-glow-cnt-template vs none. +(defun sprite-glow-add-sprite ((arg0 dma-buffer) (arg1 sprite-vec-data-2d) (arg2 float) (arg3 float) (arg4 float) (arg5 adgif-shader)) + "Generate DMA to draw a single sprite from the aux-list." + (let ((v1-0 (the-as sprite-glow-cnt-template (-> arg0 base)))) + (let* ((t5-0 *sprite-glow-dma-packet-data*) + (t2-0 (-> t5-0 control-packet quad)) + (t3-0 (-> t5-0 vecdata-packet quad)) + (t4-0 (-> t5-0 shader-cnt-packet quad)) + (t5-1 (-> t5-0 mscal-packet quad)) + ) + (set! (-> v1-0 control-packet quad) t2-0) + (set! (-> v1-0 quads 1 quad) (the-as uint128 0)) + (set! (-> v1-0 vecdata-packet quad) t3-0) + (set! (-> v1-0 shader-packet quad) t4-0) + (set! (-> v1-0 mscal-packet quad) t5-1) + ) + (let ((t2-1 (-> arg1 x-y-z-sx quad)) + (t3-1 (-> arg1 flag-rot-sy quad)) + (a1-1 (-> arg1 r-g-b-a quad)) + ) + (set! (-> v1-0 vecdata position quad) t2-1) + (set! (-> v1-0 vecdata quads 1 quad) t3-1) + (set! (-> v1-0 vecdata color quad) a1-1) + ) + (let ((a1-2 1)) + (set! (-> v1-0 vecdata z-offset) arg4) + (set! (-> v1-0 vecdata fade-a) arg2) + (set! (-> v1-0 vecdata fade-b) arg3) + (set! (-> v1-0 num-sprites) (the-as uint a1-2)) + ) + (let ((a1-3 (-> arg5 quad 0 quad)) + (a2-1 (-> arg5 quad 1 quad)) + (a3-1 (-> arg5 quad 2 quad)) + (t0-1 (-> arg5 quad 3 quad)) + (t1-1 (-> arg5 quad 4 quad)) + ) + (set! (-> v1-0 quads 8 quad) a1-3) + (set! (-> v1-0 quads 9 quad) a2-1) + (set! (-> v1-0 shader quad 2 quad) a3-1) + (set! (-> v1-0 shader quad 3 quad) t0-1) + (set! (-> v1-0 shader quad 4 quad) t1-1) + ) + (set! (-> arg0 base) (the-as pointer (&+ v1-0 224))) + ) + (none) + ) + +;; definition for function sprite-glow-add-simple-sprite +;; INFO: Used lq/sq +;; WARN: Return type mismatch sprite-glow-ref-template vs none. +(defun sprite-glow-add-simple-sprite ((arg0 dma-buffer) (arg1 sprite-glow-dma-packet-data) (arg2 sprite-glow-data) (arg3 pointer)) + "Generate DMA to draw a single sprite from the simple sprite system." + (let ((v1-0 (the-as sprite-glow-ref-template (-> arg0 base)))) + (let ((t0-0 (-> arg1 control-packet quad)) + (t1-0 (-> arg1 vecdata-packet quad)) + (t2-0 (-> arg1 shader-ref-packet quad)) + (a1-1 (-> arg1 mscal-packet quad)) + ) + (set! (-> v1-0 control-packet quad) t0-0) + (set! (-> v1-0 num-sprites-quad) (the-as uint128 0)) + (set! (-> v1-0 vecdata-packet quad) t1-0) + (set! (-> v1-0 shader-packet quad) t2-0) + (set! (-> v1-0 mscal-packet quad) a1-1) + ) + (let ((a1-2 (-> arg2 position quad)) + (t0-1 (-> arg2 quads 1 quad)) + (t1-1 (-> arg2 color quad)) + (a2-1 (-> arg2 quads 3 quad)) + (t2-1 1) + ) + (set! (-> v1-0 vecdata position quad) a1-2) + (set! (-> v1-0 vecdata quads 1 quad) t0-1) + (set! (-> v1-0 vecdata color quad) t1-1) + (set! (-> v1-0 vecdata quads 3 quad) a2-1) + (set! (-> v1-0 num-sprites) (the-as uint t2-1)) + ) + (set! (-> v1-0 shader-packet-ptr) arg3) + (set! (-> arg0 base) (the-as pointer (&+ v1-0 144))) + ) + (none) + ) + +;; definition for function sprite-glow-draw +;; WARN: Return type mismatch int vs none. +(defun sprite-glow-draw ((arg0 dma-buffer)) + "Generate DMA for all glow sprites in the aux-list (from sparticle system)" + (local-vars (a2-0 float)) + (let* ((s5-0 *sprite-aux-list*) + (s4-0 (-> s5-0 entry)) + (s3-0 #f) + ) + (dotimes (s2-0 s4-0) + (let ((v1-2 (-> s5-0 data s2-0))) + (when (and (not s3-0) (= (-> v1-2 aux-type) (sprite-aux-type glow))) + (let* ((a0-5 (-> v1-2 aux-data omega)) + (a3-0 (cond + ((zero? a0-5) + (set! a2-0 0.0) + 1.0 + ) + (else + (let* ((f1-1 (* 0.00024414062 a0-5)) + (f0-4 (- f1-1 (the float (the int f1-1)))) + ) + (let ((f1-3 (* 4096.0 (- f1-1 f0-4)))) + (set! a2-0 (/ -1.0 (* (- 1.0 f0-4) f1-3))) + ) + (/ f0-4 (- 1.0 f0-4)) + ) + ) + ) + ) + ) + (sprite-glow-add-sprite arg0 (-> v1-2 vec-data) a2-0 a3-0 (-> v1-2 aux-data user-float) (-> v1-2 gif-data)) + ) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition for method 9 of type simple-sprite-system +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defmethod add! ((this simple-sprite-system) (arg0 sprite-glow-data)) + "Add a sprite to the list, to be drawn later." + (let ((v1-0 (-> this count))) + (when (< v1-0 (-> this max-count)) + (let* ((a2-3 (-> this data v1-0)) + (v1-2 arg0) + (a1-1 a2-3) + (a2-4 (-> v1-2 position quad)) + (a3-0 (-> v1-2 quads 1 quad)) + (t0-0 (-> v1-2 color quad)) + (v1-3 (-> v1-2 quads 3 quad)) + ) + (set! (-> a1-1 position quad) a2-4) + (set! (-> a1-1 quads 1 quad) a3-0) + (set! (-> a1-1 color quad) t0-0) + (set! (-> a1-1 quads 3 quad) v1-3) + ) + (+! (-> this count) 1) + ) + ) + 0 + (none) + ) + +;; definition for function add-shader-to-dma +;; INFO: Used lq/sq +;; WARN: Return type mismatch pointer vs adgif-shader. +(defun add-shader-to-dma ((arg0 dma-buffer)) + (let* ((a1-0 (new 'static 'dma-packet :dma (new 'static 'dma-tag :id (dma-tag-id next)))) + (v1-0 (-> arg0 base)) + (a1-1 (-> a1-0 quad)) + (v0-0 (&+ v1-0 16)) + ) + (let ((a2-0 (&+ v1-0 96))) + (set! (-> (the-as (pointer uint128) v1-0)) a1-1) + (set! (-> (the-as (pointer uint32) v1-0) 1) (the-as uint a2-0)) + (set! (-> arg0 base) a2-0) + ) + (the-as adgif-shader v0-0) + ) + ) + +;; definition for method 10 of type simple-sprite-system +;; WARN: Return type mismatch int vs none. +(defmethod draw-all-sprites! ((this simple-sprite-system) (arg0 dma-buffer)) + "Submit all sprites to the sprite-glow renderer" + (local-vars (sv-528 sprite-glow-dma-packet-data) (sv-532 (pointer texture-id)) (sv-536 pointer)) + (b! (zero? (-> this count)) cfg-13 :delay (nop!)) + (set! sv-528 *sprite-glow-dma-packet-data*) + (set! sv-532 (new 'stack-no-clear 'array 'texture-id 128)) + (set! sv-536 (-> arg0 base)) + (dotimes (v1-5 (-> this count)) + (set! (-> sv-532 v1-5) (-> this data v1-5 tex-id)) + ) + (countdown (s4-0 (-> this count)) + (let ((s3-0 (-> sv-532 s4-0))) + (when (nonzero? s3-0) + (let ((s2-0 (add-shader-to-dma arg0))) + (adgif-shader<-texture-simple! s2-0 (lookup-texture-by-id s3-0)) + (countdown (s1-1 (+ s4-0 1)) + (when (= s3-0 (-> sv-532 s1-1)) + (set! (-> sv-532 s1-1) (new 'static 'texture-id)) + (let ((a2-1 (-> this data s1-1))) + (sprite-glow-add-simple-sprite arg0 sv-528 a2-1 (the-as pointer s2-0)) + ) + ) + ) + ) + ) + ) + ) + (label cfg-13) + 0 + (none) + ) + +;; definition for method 11 of type simple-sprite-system +;; WARN: Return type mismatch int vs none. +(defmethod clear! ((this simple-sprite-system)) + "Reset the list." + (set! (-> this count) 0) + 0 + (none) + ) + +;; definition for symbol *simple-sprite-system*, type simple-sprite-system +(define *simple-sprite-system* + (new 'static 'simple-sprite-system :max-count #x80 :data (new 'static 'inline-array sprite-glow-data 128 + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + (new 'static 'sprite-glow-data) + ) + ) + ) diff --git a/test/offline/config/jak3/config.jsonc b/test/offline/config/jak3/config.jsonc index 7da643260..c3702b4ce 100644 --- a/test/offline/config/jak3/config.jsonc +++ b/test/offline/config/jak3/config.jsonc @@ -82,7 +82,9 @@ // find-nearest "find-nearest-focusable", - "(method 3 sprite-aux-list)" // appears twice. + "(method 3 sprite-aux-list)", // appears twice. + "sprite-draw-distorters", // asm + "bugfix?" ],