diff --git a/decompiler/IR2/AtomicOpTypeAnalysis.cpp b/decompiler/IR2/AtomicOpTypeAnalysis.cpp index 8ab8513282..4761dfa57c 100644 --- a/decompiler/IR2/AtomicOpTypeAnalysis.cpp +++ b/decompiler/IR2/AtomicOpTypeAnalysis.cpp @@ -2,6 +2,7 @@ #include "decompiler/ObjectFile/LinkedObjectFile.h" #include "common/log/log.h" #include "AtomicOp.h" +#include "decompiler/util/TP_Type.h" #include "decompiler/util/DecompilerTypeSystem.h" #include "decompiler/IR2/bitfields.h" diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index e5d8b0c762..418b30059d 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -495,7 +495,7 @@ ) (defenum bucket-id - :type uint32 + :type int32 :bitfield #f (tfrag-tex0 5) @@ -529,8 +529,10 @@ (water-tex1 60) ;; merc1 61 ;; generic1 62 + ;; debug spheres? 67 + (debug-draw0 67) ;; debug text 68 - (debug-draw 68) + (debug-draw1 68) ) (define-extern sinteger type) @@ -1267,7 +1269,7 @@ ) (deftype vector2h (structure) - ((data int16 2 :offset-assert 0) + ((data int16 2 :score -9999 :offset-assert 0) (x int16 :offset 0) (y int16 :offset 2) ) @@ -1290,7 +1292,7 @@ ) (deftype vector3h (structure) - ((data int16 2 :offset-assert 0) ;; probably a bug, should be 3. + ((data int16 2 :score -9999 :offset-assert 0) ;; probably a bug, should be 3. (x int16 :offset 0) (y int16 :offset 2) (z int16 :offset-assert 4) @@ -1301,7 +1303,7 @@ ) (deftype vector2w (structure) - ((data int32 2 :offset-assert 0) + ((data int32 2 :score -9999 :offset-assert 0) (x int32 :offset 0) (y int32 :offset 4) ) @@ -1312,7 +1314,7 @@ ) (deftype vector3w (structure) - ((data int32 3 :do-not-decompile :offset-assert 0) + ((data int32 3 :score -9999 :offset-assert 0) (x int32 :offset 0) (y int32 :offset 4) (z int32 :offset 8) @@ -1324,7 +1326,7 @@ ) (deftype vector4w (structure) - ((data int32 4 :do-not-decompile :offset-assert 0) + ((data int32 4 :score -9999 :offset-assert 0) (x int32 :offset 0) (y int32 :offset 4) (z int32 :offset 8) @@ -1338,9 +1340,9 @@ ) (deftype vector4w-2 (structure) - ((data int32 8 :offset-assert 0) + ((data int32 8 :score -9999 :offset-assert 0) (quad uint128 2 :offset 0) - (vector vector4w 2 :offset 0) + (vector vector4w 2 :inline :offset 0) ) :method-count-assert 9 :size-assert #x20 @@ -1348,9 +1350,9 @@ ) (deftype vector4w-3 (structure) - ((data int32 12 :offset-assert 0) + ((data int32 12 :score -9999 :offset-assert 0) (quad uint128 3 :offset 0) - (vector vector4w 3 :offset 0) + (vector vector4w 3 :inline :offset 0) ) :method-count-assert 9 :size-assert #x30 @@ -1358,9 +1360,9 @@ ) (deftype vector4w-4 (structure) - ((data int32 16 :offset-assert 0) + ((data int32 16 :score -9999 :offset-assert 0) (quad uint128 4 :offset 0) - (vector vector4w 4 :offset 0) + (vector vector4w 4 :inline :offset 0) ) :method-count-assert 9 :size-assert #x40 @@ -1400,8 +1402,7 @@ ) (deftype vector (structure) - ( - (data float 4 :do-not-decompile :offset-assert 0) + ((data float 4 :do-not-decompile :score -9999 :offset-assert 0) (x float :offset 0) (y float :offset 4) (z float :offset 8) @@ -1695,7 +1696,7 @@ (y float :offset-assert 4) (z float :offset-assert 8) (w float :offset-assert 12) - (data float 4 :do-not-decompile :offset 0) + (data float 4 :score -9999 :offset 0) (vec vector :inline :offset 0) (quad uint128 :offset 0) ) @@ -2057,7 +2058,7 @@ (define-extern curve-length function) (define-extern curve-get-pos! function) (define-extern vector-vector-distance-squared (function vector vector float)) -(define-extern curve-evaluate! function) +(define-extern curve-evaluate! (function vector float int int vector int int)) (define-extern vector-vector-distance (function vector vector float)) (define-extern circle-circle-xz-intersect (function vector vector vector vector int)) (define-extern vector-normalize-copy! (function vector vector float vector)) @@ -2093,7 +2094,7 @@ (define-extern vector-deg-slerp (function vector vector vector float vector)) (define-extern vector-vector-deg-slerp! function) ;; stack spills! (define-extern normal-of-plane (function vector vector vector vector vector)) -(define-extern vector-3pt-cross! (function vector vector vector vector)) +(define-extern vector-3pt-cross! (function vector vector vector vector vector)) (define-extern closest-pt-in-triangle function) ;; asm branches (define-extern point-in-triangle-cross (function vector vector vector vector vector symbol)) (define-extern point-in-plane-<-point+normal! (function vector vector vector vector)) @@ -2944,8 +2945,7 @@ ;; - Symbols -(define-extern *video-parms* video-parms) ;; unknown type - ;; unknown type +(define-extern *video-parms* video-parms) ;; ---------------------- @@ -5509,7 +5509,9 @@ ;; - Types (deftype drawable-group (drawable) - ((pad uint8 4)) + ((length int16 :offset 6) + (data drawable 1 :offset-assert 32) + ) :flag-assert #x1200000024 ) @@ -9989,7 +9991,7 @@ ;; - Types (deftype pos-history (structure) - ((points uint32 :offset-assert 0) + ((points (inline-array vector) :offset-assert 0) (num-points int32 :offset-assert 4) (h-first int32 :offset-assert 8) (h-last int32 :offset-assert 12) @@ -10018,7 +10020,6 @@ :method-count-assert 9 :size-assert #x4b10 :flag-assert #x900004b10 - ;; inspect method is overriden in debug.gc ) @@ -10158,13 +10159,13 @@ (define-extern joint-mod-set-local-callback (function cspace transformq none)) (define-extern joint-mod-wheel-callback (function cspace transformq none)) (define-extern vector<-cspace! (function vector cspace vector)) -(define-extern add-debug-text-sphere (function symbol bucket-id vector float string rgba none)) +(define-extern add-debug-text-sphere (function symbol bucket-id vector float string rgba symbol)) (define-extern joint-mod-look-at-handler (function cspace transformq none)) (define-extern joint-mod-world-look-at-handler (function cspace transformq none)) (define-extern joint-mod-rotate-handler (function cspace transformq none)) (define-extern joint-mod-joint-set-handler (function cspace transformq none)) (define-extern joint-mod-joint-set*-handler (function cspace transformq none)) -(define-extern add-debug-matrix (function symbol bucket-id matrix none)) +(define-extern add-debug-matrix (function symbol bucket-id matrix matrix)) (define-extern joint-mod-debug-draw (function joint-mod none)) ;; - Symbols @@ -11944,8 +11945,7 @@ ) (deftype drawable-tree-instance-tie (drawable-tree) - ((length int16 :offset 6) - (prototypes basic :offset 8) + ((prototypes basic :offset 8) ) :method-count-assert 18 :size-assert #x24 @@ -14843,9 +14843,9 @@ ;; - Functions -(define-extern add-debug-line (function symbol int vector vector rgba symbol int int)) +(define-extern add-debug-line (function symbol bucket-id vector vector rgba symbol rgba symbol)) (define-extern make-debug-sphere-table (function debug-sphere-table none)) -(define-extern add-debug-sphere-from-table (function int vector vector rgba none)) +(define-extern add-debug-sphere-from-table (function bucket-id vector float rgba none)) ;; - Symbols @@ -14862,12 +14862,12 @@ (deftype debug-line (structure) ((flags int32 :offset-assert 0) - (bucket int32 :offset-assert 4) + (bucket bucket-id :offset-assert 4) (v1 vector :inline :offset-assert 16) (v2 vector :inline :offset-assert 32) - (color uint32 :offset-assert 48) - (mode basic :offset-assert 52) - (color2 uint32 :offset-assert 56) + (color rgba :offset-assert 48) + (mode symbol :offset-assert 52) + (color2 rgba :offset-assert 56) ) :method-count-assert 9 :size-assert #x3c @@ -14876,11 +14876,11 @@ (deftype debug-text-3d (structure) ((flags int32 :offset-assert 0) - (bucket int32 :offset-assert 4) + (bucket bucket-id :offset-assert 4) (pos vector :inline :offset-assert 16) (color uint64 :offset-assert 32) (offset vector2h :inline :offset-assert 40) - (str basic :offset-assert 44) + (str string :offset-assert 44) ) :method-count-assert 9 :size-assert #x30 @@ -14898,50 +14898,50 @@ ;; - Functions -(define-extern debug-set-camera-pos-rot! function) -(define-extern drawable-frag-count function) -(define-extern add-debug-light function) -(define-extern add-debug-text-3d function) -(define-extern add-debug-x function) -(define-extern add-debug-curve function) -(define-extern add-debug-sphere (function symbol int vector float int int)) -(define-extern get-debug-text-3d function) -(define-extern internal-draw-debug-text-3d function) -(define-extern get-debug-line function) -(define-extern internal-draw-debug-line function) -(define-extern draw-string function) -(define-extern transform-float-point function) -(define-extern add-debug-point function) -(define-extern add-debug-outline-triangle function) -(define-extern add-debug-triangle-normal function) -(define-extern add-debug-flat-triangle function) -(define-extern debug-reset-buffers function) -(define-extern debug-draw-buffers function) -(define-extern add-debug-line2d function) -(define-extern add-debug-box function) -(define-extern add-debug-sphere-with-transform function) -(define-extern add-debug-spheres function) -(define-extern add-debug-circle function) -(define-extern add-debug-rot-matrix function) -(define-extern add-debug-yrot-vector function) -(define-extern add-debug-arc function) -(define-extern add-debug-curve2 function) -(define-extern add-debug-points function) -(define-extern debug-percent-bar function) -(define-extern debug-pad-display function) -(define-extern add-debug-lights function) -(define-extern history-init function) -(define-extern history-draw-and-update function) -(define-extern dma-timeout-cam function) -(define-extern display-file-info function) +(define-extern debug-set-camera-pos-rot! (function vector matrix int)) +(define-extern drawable-frag-count (function drawable int)) +(define-extern add-debug-light (function symbol bucket-id light vector string symbol)) +(define-extern add-debug-text-3d (function symbol bucket-id string vector rgba vector2h symbol)) +(define-extern add-debug-x (function symbol bucket-id vector rgba symbol)) +(define-extern add-debug-curve (function symbol bucket-id pointer int vector int rgba symbol)) +(define-extern add-debug-sphere (function symbol bucket-id vector float rgba symbol)) +(define-extern get-debug-text-3d (function debug-text-3d)) +(define-extern internal-draw-debug-text-3d (function bucket-id string vector rgba vector2h pointer)) +(define-extern get-debug-line (function debug-line)) +(define-extern internal-draw-debug-line (function bucket-id vector vector rgba symbol rgba object)) +(define-extern draw-string (function string dma-buffer int)) +(define-extern transform-float-point (function vector vector vector)) +(define-extern add-debug-point (function symbol bucket-id vector symbol)) ;; unused +(define-extern add-debug-outline-triangle (function symbol bucket-id vector vector vector rgba symbol)) +(define-extern add-debug-triangle-normal (function symbol bucket-id vector vector vector rgba symbol)) +(define-extern add-debug-flat-triangle (function symbol bucket-id vector vector vector rgba symbol)) +(define-extern debug-reset-buffers (function symbol)) +(define-extern debug-draw-buffers (function symbol)) +(define-extern add-debug-line2d (function symbol bucket-id vector vector vector symbol)) +(define-extern add-debug-box (function symbol bucket-id vector vector rgba symbol)) +(define-extern add-debug-sphere-with-transform (function symbol bucket-id vector float matrix rgba symbol)) +(define-extern add-debug-spheres (function symbol bucket-id (pointer float) int rgba symbol)) +(define-extern add-debug-circle (function symbol bucket-id vector float rgba matrix symbol)) +(define-extern add-debug-rot-matrix (function symbol bucket-id matrix vector matrix)) +(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-curve2 (function symbol bucket-id curve rgba symbol)) +(define-extern add-debug-points (function symbol bucket-id (inline-array vector) int rgba float int symbol)) ;; unused +(define-extern debug-percent-bar (function symbol bucket-id int int float rgba symbol)) +(define-extern debug-pad-display (function cpad-info symbol)) ;; unused +(define-extern add-debug-lights (function symbol bucket-id (inline-array light) vector symbol)) +(define-extern history-init (function pos-history int pos-history)) +(define-extern history-draw-and-update (function pos-history int vector symbol)) +(define-extern dma-timeout-cam (function int)) +(define-extern display-file-info (function int)) ;; - Unknowns -;;(define-extern add-debug-vector (function symbol int trajectory ? float float)) -;;(define-extern *debug-lines* object) ;; unknown type -;;(define-extern *debug-lines-trk* object) ;; unknown type -;;(define-extern *debug-text-3ds* object) ;; unknown type -;;(define-extern *debug-text-3d-trk* object) ;; unknown type +(define-extern add-debug-vector (function symbol bucket-id vector vector float 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) ;; ---------------------- diff --git a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc index 81f64ef386..fe92c09ebe 100644 --- a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc @@ -560,5 +560,26 @@ "navigate-h": [ ["L20", "float", true] + ], + + "debug": [ + ["L221", "float", true], + ["L217", "float", true], + ["L179", "vector2h", true], + ["L210", "float", true], + ["L209", "float", true], + ["L176", "(inline-array vector)", true, 8], + ["L180", "vector", true], + ["L181", "vector", true], + ["L182", "vector", true], + ["L183", "vector", true], + ["L223", "rgba", true], + ["L225", "rgba", true], + ["L224", "rgba", true], + ["L222", "rgba", true], + ["L226", "rgba", true], + ["L227", "uint64", true], + ["L228", "uint64", true], + ["L229", "uint64", true] ] } diff --git a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc index e77785a0ab..a972b8f582 100644 --- a/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/stack_structures.jsonc @@ -356,7 +356,25 @@ [16, "event-message-block"] ], - "(method 24 actor-link-info)": [ + "(method 24 actor-link-info)": [ [16, "event-message-block"] - ] + ], + + "internal-draw-debug-line": [[16, "vector4w-2"], [48, "vector4w-2"]], + "internal-draw-debug-text-3d": [[16, "vector4w"], [32, "font-context"]], + "add-debug-triangle-normal": [[16, "vector"], [32, "vector"]], + "add-debug-flat-triangle": [[16, "vector4w-3"], [64, "vector4w-3"]], + "add-debug-point": [[16, "vector4w-2"]], + "add-debug-line2d": [[16, "vector4w"], [32, "vector4w"]], + "add-debug-box": [[16, "vector"], [32, "vector"]], + "add-debug-x": [[16, "vector"], [32, "vector"]], + "add-debug-sphere-with-transform": [[16, "vector"]], + "add-debug-circle": [[16, "vector"], [32, "vector"]], + "add-debug-vector": [[16, "vector"]], + "add-debug-yrot-vector": [[16, "vector"]], + "add-debug-arc": [[16, "vector"], [32, "vector"]], + "add-debug-curve": [[16, "vector"], [32, "vector"]], + "add-debug-points": [[16, "vector"]], + "add-debug-light": [[16, "vector"]], + "dma-timeout-cam": [[16, "vector"], [32, "matrix"]] } diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index 9d798c845b..e393299bb1 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -635,5 +635,56 @@ "(method 0 nav-control)": [ [17, "t9", "(function string none)"] + ], + + "add-debug-point": [ + [125, "a3", "pointer"], + [[27, 144], "a0", "(pointer uint64)"], + [[147, 150], "a0", "dma-packet"], + [[31, 35], "a3", "dma-packet"], + [[41, 44], "a3", "gs-gif-tag"], + [[61, 65], "a3", "vector4w-2"], + [[81, 85], "a3", "vector4w-2"], + [[98, 102], "a3", "vector4w-2"], + [[118, 122], "a1", "vector4w-2"] + ], + "internal-draw-debug-line": [ + [[95, 101], "a3", "dma-packet"], + [[104, 110], "a3", "gs-gif-tag"], + [[212, 225], "a1", "(inline-array vector4w-2)"], + [228, "a3", "pointer"], + [[93, 246], "a0", "(pointer uint64)"], + [[250, 253], "a0", "dma-packet"], + [[3, 158], "s2", "rgba"], + [[5, 204], "s5", "rgba"] + ], + "add-debug-flat-triangle": [ + [[55, 61], "a3", "dma-packet"], + [[64, 70], "a3", "gs-gif-tag"], + [[93, 112], "a3", "(inline-array vector4w-3)"], + [[53, 133], "a0", "(pointer uint64)"], + [115, "a1", "pointer"], + [[135, 140], "a0", "dma-packet"] + ], + "add-debug-line2d": [ + [[58, 64], "a2", "dma-packet"], + [[67, 73], "a2", "gs-gif-tag"], + [[76, 81], "a2", "(inline-array vector4w)"], + [[84, 89], "a2", "(inline-array vector4w)"], + [[56, 110], "a0", "(pointer uint64)"], + [92, "a1", "pointer"], + [[112, 117], "v1", "dma-packet"] + ], + "debug-percent-bar": [ + [[32, 43], "v1", "dma-packet"] + ], + "debug-pad-display": [ + [[70, 75], "v1", "dma-packet"] + ], + "internal-draw-debug-text-3d": [ + [[54, 59], "v1", "dma-packet"] + ], + "drawable-frag-count": [ + [[14, 20], "s5", "drawable-group"] ] } diff --git a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc index fa0271f36c..aa7ad695a3 100644 --- a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc @@ -1974,7 +1974,66 @@ "(method 0 nav-control)": { "args":["allocation", "type-to-make", "shape", "sphere-count", "nearest-y-threshold-default"], "vars": {"s5-0":["obj", "nav-control"], "a0-3":"ent"} - } + }, + + "add-debug-point": { + "vars": { + "a0-6":["a0-6", "(pointer uint64)"], + "a0-7":["a0-7", "dma-packet"], + "a3-0":["a3-0", "dma-packet"], + "a3-2":["a3-2", "gs-gif-tag"], + "a3-4":["a3-4", "vector4w-2"], + "a3-6":["a3-6", "vector4w-2"], + "a3-8":["a3-8", "vector4w-2"], + "a1-30":["a1-30", "vector4w-2"] + } + }, + "internal-draw-debug-line": { + "vars": { + "s2-0":["s2-0", "rgba"], + "s5-0":["s5-0", "rgba"], + "a3-1":["a3-1", "dma-packet"], + "a3-3":["a3-3", "gs-gif-tag"], + "a1-43":["a1-43", "(inline-array vector4w-2)"], + "a0-31":["a0-31", "(pointer uint64)"], + "a0-32":["a0-32", "dma-packet"] + } + }, + "add-debug-flat-triangle": { + "vars": { + "a3-1":["a3-1", "dma-packet"], + "a3-3":["a3-3", "gs-gif-tag"], + "a3-5":["a3-5", "(inline-array vector4w-3)"], + "a0-9":["a0-9", "(pointer uint64)"], + "a0-10":["a0-10", "dma-packet"] + } + }, + "add-debug-line2d": { + "vars": { + "a2-3":["a2-3", "dma-packet"], + "a2-5":["a2-5", "gs-gif-tag"], + "a2-7":["a2-7", "(inline-array vector4w)"], + "a2-9":["a2-9", "(inline-array vector4w)"], + "a0-20":["a0-20", "(pointer uint64)"], + "v1-10":["v1-10", "dma-packet"] + } + }, + "debug-percent-bar": { + "vars": { + "v1-5":["v1-5", "dma-packet"] + } + }, + "debug-pad-display": { + "vars": { + "v1-12":["v1-12", "dma-packet"] + } + }, + "internal-draw-debug-text-3d": { + "vars": { + "v1-11":["v1-11", "dma-packet"] + } + }, + "add-debug-light": { "vars": { "s1-0":["s1-0", "rgba"]} } } diff --git a/decompiler/util/data_decompile.cpp b/decompiler/util/data_decompile.cpp index 7a03da91a5..1656ea15da 100644 --- a/decompiler/util/data_decompile.cpp +++ b/decompiler/util/data_decompile.cpp @@ -73,7 +73,8 @@ goos::Object decompile_at_label_with_hint(const LabelType& hint, } throw std::runtime_error( - fmt::format("Type {} is not yet supported by the data decompiler.", hint.type_name)); + fmt::format("Type `{}` with length {} is not yet supported by the data decompiler.", + hint.type_name, *hint.array_size)); } /*! diff --git a/goal_src/engine/camera/cam-debug-h.gc b/goal_src/engine/camera/cam-debug-h.gc index 3791fb4d73..6dd977ef3b 100644 --- a/goal_src/engine/camera/cam-debug-h.gc +++ b/goal_src/engine/camera/cam-debug-h.gc @@ -98,4 +98,5 @@ (define-perm *cam-layout* symbol #f) + (defun-extern debug-set-camera-pos-rot! vector matrix int) ) diff --git a/goal_src/engine/camera/math-camera.gc b/goal_src/engine/camera/math-camera.gc index 1eec9a9d39..2ddcd987fb 100644 --- a/goal_src/engine/camera/math-camera.gc +++ b/goal_src/engine/camera/math-camera.gc @@ -508,29 +508,6 @@ ) ) -;; In the original game, init-for-transform stashed a bunch of stuff in registers, to be used by other functions. -;; In OpenGOAL, this seems risky so we're going to back up this manually: - -(deftype transform-regs (structure) - ((vf1 uint128) - (vf2 uint128) - (vf3 uint128) - (vf4 uint128) - (vf17 uint128) - (vf18 uint128) - (vf19 uint128) - (vf23 uint128) - (vf24 uint128) - (vf25 uint128) - (vf26 uint128) - (vf27 uint128) - (vf28 uint128) - (vf29 uint128) - ) - ) - -(define *transform-regs* (new 'static 'transform-regs)) - (defun init-for-transform ((arg0 matrix)) (rlet ((vf1 :class vf) (vf17 :class vf) diff --git a/goal_src/engine/debug/debug-h.gc b/goal_src/engine/debug/debug-h.gc index 8899a54513..755310f02d 100644 --- a/goal_src/engine/debug/debug-h.gc +++ b/goal_src/engine/debug/debug-h.gc @@ -7,7 +7,7 @@ (deftype pos-history (structure) - ((points uint32 :offset-assert 0) + ((points (inline-array vector) :offset-assert 0) (num-points int32 :offset-assert 4) (h-first int32 :offset-assert 8) (h-last int32 :offset-assert 12) @@ -28,7 +28,6 @@ :flag-assert #x900000020 ) - (deftype debug-vertex-stats (basic) ((length int32 :offset-assert 4) (pos-count int32 :offset-assert 8) @@ -37,11 +36,12 @@ :method-count-assert 9 :size-assert #x4b10 :flag-assert #x900004b10 - ;; inspect method is overriden in debug.gc ) -(define-extern add-debug-matrix (function symbol bucket-id matrix none)) -(define-extern add-debug-text-sphere (function symbol bucket-id vector float string rgba none)) +(define-extern add-debug-matrix (function symbol bucket-id matrix matrix)) +(define-extern add-debug-text-sphere (function symbol bucket-id vector float string rgba symbol)) ;; TODO - for trajectory.gc -(define-extern add-debug-line (function symbol int vector vector rgba symbol int int)) +(define-extern add-debug-line (function symbol bucket-id vector vector rgba symbol rgba symbol)) + +(defun-extern add-debug-sphere symbol bucket-id vector float rgba symbol) \ No newline at end of file diff --git a/goal_src/engine/debug/debug-sphere.gc b/goal_src/engine/debug/debug-sphere.gc index 5f42d21d37..7c42b88064 100644 --- a/goal_src/engine/debug/debug-sphere.gc +++ b/goal_src/engine/debug/debug-sphere.gc @@ -96,7 +96,7 @@ ;; Used lq/sq (defun add-debug-sphere-from-table - ((arg0 int) (arg1 vector) (arg2 vector) (arg3 rgba)) + ((arg0 bucket-id) (arg1 vector) (arg2 float) (arg3 rgba)) (rlet ((vf1 :class vf) (vf2 :class vf) (vf3 :class vf) @@ -124,8 +124,8 @@ (.svf (&-> s4-0 quad) vf3) (.svf (&-> s3-0 quad) vf4) (.svf (&-> s2-0 quad) vf5) - (add-debug-line #t arg0 s4-0 s3-0 arg3 #f -1) - (add-debug-line #t arg0 s4-0 s2-0 arg3 #f -1) + (add-debug-line #t arg0 s4-0 s3-0 arg3 #f (the rgba -1)) + (add-debug-line #t arg0 s4-0 s2-0 arg3 #f (the rgba -1)) ) ) (let ((v0-2 0)) diff --git a/goal_src/engine/debug/debug.gc b/goal_src/engine/debug/debug.gc index 5e54599cdf..47cc9ef077 100644 --- a/goal_src/engine/debug/debug.gc +++ b/goal_src/engine/debug/debug.gc @@ -6,3 +6,1628 @@ ;; dgos: GAME, ENGINE +(defun transform-float-point ((arg0 vector) (arg1 vector)) + + (with-vf0 + (with-vf (vf4 vf1 vf2 vf3 vf9 vf8 vf6) + (rlet ((acc :class vf) + (Q :class vf) + (vf5 :class vf) + ) + (.lvf vf5 (&-> arg0 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 (&-> arg1 quad) vf5) + arg1 + ) + ) + ) + ) + + +(defun-debug add-debug-point ((arg0 symbol) (arg1 bucket-id) (arg2 vector)) + (if (not arg0) + (return #f) + ) + (let ((s5-0 (new 'stack 'vector4w-2))) + (set! (-> arg2 w) 1.0) + (when (transform-point-qword! (the-as vector (-> s5-0 quad)) arg2) + (let* ((v1-7 (-> *display* frames (-> *display* on-screen) frame debug-buf)) + (a2-1 (-> v1-7 base)) + ) + (let ((a0-6 (the-as (pointer uint64) (-> v1-7 base)))) + (let* ((a1-3 v1-7) + (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-7) + (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 #x4c + :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) + (set! (-> s5-0 vector 0 y) (+ (-> s5-0 vector 0 y) 160)) + (let* ((a1-11 v1-7) + (a3-4 (the-as vector4w-2 (-> a1-11 base))) + ) + (set! (-> a3-4 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a3-4 quad 1) (-> s5-0 quad 0)) + (set! (-> a1-11 base) (&+ (the-as pointer a3-4) 32)) + ) + (set! (-> s5-0 vector 0 x) (+ (-> s5-0 vector 0 x) -256)) + (set! (-> s5-0 vector 0 y) (+ (-> s5-0 vector 0 y) -160)) + (set! (-> s5-0 vector 1 x) 128) + (set! (-> s5-0 vector 1 y) 255) + (let* ((a1-18 v1-7) + (a3-6 (the-as vector4w-2 (-> a1-18 base))) + ) + (set! (-> a3-6 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a3-6 quad 1) (-> s5-0 quad 0)) + (set! (-> a1-18 base) (&+ (the-as pointer a3-6) 32)) + ) + (set! (-> s5-0 vector 0 x) (+ (-> s5-0 vector 0 x) 512)) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 255) + (let* ((a1-23 v1-7) + (a3-8 (the-as vector4w-2 (-> a1-23 base))) + ) + (set! (-> a3-8 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a3-8 quad 1) (-> s5-0 quad 0)) + (set! (-> a1-23 base) (&+ (the-as pointer a3-8) 32)) + ) + (set! (-> s5-0 vector 0 x) (+ (-> s5-0 vector 0 x) -256)) + (set! (-> s5-0 vector 0 y) (+ (-> s5-0 vector 0 y) -160)) + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (let* ((a3-10 v1-7) + (a1-30 (the-as vector4w-2 (-> a3-10 base))) + ) + (set! (-> a1-30 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a1-30 quad 1) (-> s5-0 quad 0)) + (set! (-> a3-10 base) (&+ (the-as pointer a1-30) 32)) + ) + (let ((a3-14 (/ (the-as int (+ (&- (the-as pointer -16) (the-as uint a0-6)) (the-as int (-> v1-7 base)))) 16))) + (cond + ((nonzero? a3-14) + (set! + (-> a0-6 0) + (logior (-> a0-6 0) (the-as uint (shr (shl a3-14 48) 48))) + ) + (set! + (-> a0-6 1) + (logior (-> a0-6 1) (the-as uint (shl (shr (shl a3-14 48) 48) 32))) + ) + ) + (else + (set! (-> v1-7 base) a0-6) + ) + ) + ) + ) + (let ((a3-20 (-> v1-7 base))) + (let ((a0-7 (the-as dma-packet (-> v1-7 base)))) + (set! (-> a0-7 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> a0-7 vif0) (new 'static 'vif-tag)) + (set! (-> a0-7 vif1) (new 'static 'vif-tag)) + (set! (-> v1-7 base) (&+ (the-as pointer a0-7) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + (the-as int arg1) + a2-1 + (the-as (pointer dma-tag) a3-20) + ) + ) + ) + ) + ) + #f + ) + +(defun-debug internal-draw-debug-line ((arg0 bucket-id) (arg1 vector) (arg2 vector) (arg3 rgba) (arg4 symbol) (arg5 rgba)) + (local-vars (sv-80 vector)) + (set! sv-80 arg2) + (let ((s2-0 arg3) + (s3-0 arg4) + (s5-0 arg5) + ) + (let ((a0-4 (-> *display* frames (-> *display* on-screen) frame debug-buf))) + (if + (< + (the-as + uint + (shr (+ (&- (-> a0-4 end) (the-as uint (-> a0-4 base))) 15) 4) + ) + (the-as uint #x8000) + ) + (return (the-as pointer #f)) + ) + ) + (if + (or + (zero? (+ (the-as uint s5-0) (the-as uint 1))) + (= s5-0 (new 'static 'rgba :r #xff :g #xff :b #xff :a #xff)) + ) + (set! s5-0 s2-0) + ) + (let ((v1-14 s3-0)) + (if (= v1-14 '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)) + (s1-0 (new 'stack 'vector4w-2)) + ) + (set! (-> arg1 w) 1.0) + (set! (-> sv-80 w) 1.0) + (the-as + int + (when + (and + (transform-point-qword! (the-as vector (-> s4-0 quad)) arg1) + (transform-point-qword! (the-as vector (&-> s4-0 quad 1)) sv-80) + ) + (let* + ((v1-28 (-> *display* frames (-> *display* on-screen) frame debug-buf)) + (a2-1 (-> v1-28 base)) + ) + (let ((a0-31 (the-as (pointer uint64) (-> v1-28 base)))) + (let* ((a1-5 v1-28) + (a3-1 (the-as dma-packet (-> a1-5 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-5 base) (&+ (the-as pointer a3-1) 16)) + ) + (let* ((a1-6 v1-28) + (a3-3 (the-as gs-gif-tag (-> a1-6 base))) + ) + (set! + (-> a3-3 tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim #x49 + :nreg #x4 + ) + ) + (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) + ) + ) + (set! (-> a1-6 base) (&+ (the-as pointer a3-3) 16)) + ) + (let ((a1-7 s3-0)) + (cond + ((= a1-7 'fade-depth) + (let + ((f0-3 + (fmax + 0.2 + (fmin 1.0 (* 0.00000005960465 (the float (-> s4-0 vector 0 z)))) + ) + ) + ) + (set! + (-> s1-0 vector 0 x) + (the int (* (the float (-> s2-0 r)) f0-3)) + ) + (set! + (-> s1-0 vector 0 y) + (the int (* (the float (-> s2-0 g)) f0-3)) + ) + (set! + (-> s1-0 vector 0 z) + (the int (* (the float (-> s2-0 b)) f0-3)) + ) + ) + (set! (-> s1-0 vector 0 w) (the-as int (-> s2-0 a))) + ) + (else + (set! (-> s1-0 vector 0 x) (the-as int (-> s2-0 r))) + (set! (-> s1-0 vector 0 y) (the-as int (-> s2-0 g))) + (set! (-> s1-0 vector 0 z) (the-as int (-> s2-0 b))) + (set! (-> s1-0 vector 0 w) (the-as int (-> s2-0 a))) + ) + ) + ) + (cond + ((= s3-0 'fade-depth) + (let + ((f0-7 + (fmax + 0.2 + (fmin 1.0 (* 0.00000005960465 (the float (-> s4-0 vector 1 z)))) + ) + ) + ) + (set! + (-> s1-0 vector 1 x) + (the int (* (the float (-> s5-0 r)) f0-7)) + ) + (set! + (-> s1-0 vector 1 y) + (the int (* (the float (-> s5-0 g)) f0-7)) + ) + (set! + (-> s1-0 vector 1 z) + (the int (* (the float (-> s5-0 b)) f0-7)) + ) + ) + (set! (-> s1-0 vector 1 w) (the-as int (-> s5-0 a))) + ) + (else + (set! (-> s1-0 vector 1 x) (the-as int (-> s5-0 r))) + (set! (-> s1-0 vector 1 y) (the-as int (-> s5-0 g))) + (set! (-> s1-0 vector 1 z) (the-as int (-> s5-0 b))) + (set! (-> s1-0 vector 1 w) (the-as int (-> s5-0 a))) + ) + ) + (set! (-> s4-0 vector 0 z) (+ (-> s4-0 vector 0 z) -8192)) + (set! (-> s4-0 vector 1 z) (+ (-> s4-0 vector 1 z) -8192)) + (let* ((a3-6 v1-28) + (a1-43 (the-as (inline-array vector4w-2) (-> a3-6 base))) + ) + (set! (-> a1-43 0 quad 0) (-> s1-0 quad 0)) + (set! (-> a1-43 0 quad 1) (-> s4-0 quad 0)) + (set! (-> a1-43 1 quad 0) (-> (&-> s1-0 quad 1) 0)) + (set! (-> a1-43 1 quad 1) (-> (&-> s4-0 quad 1) 0)) + (set! (-> a3-6 base) (&+ (the-as pointer a1-43) 64)) + ) + (let + ((a3-10 + (/ + (the-as + int + (+ + (&- (the-as pointer -16) (the-as uint a0-31)) + (the-as int (-> v1-28 base)) + ) + ) + 16 + ) + ) + ) + (cond + ((nonzero? a3-10) + (set! + (-> a0-31 0) + (logior (-> a0-31 0) (the-as uint (shr (shl a3-10 48) 48))) + ) + (set! + (-> a0-31 1) + (logior (-> a0-31 1) (the-as uint (shl (shr (shl a3-10 48) 48) 32))) + ) + ) + (else + (set! (-> v1-28 base) a0-31) + ) + ) + ) + ) + (let ((a3-16 (-> v1-28 base))) + (let ((a0-32 (the-as dma-packet (-> v1-28 base)))) + (set! (-> a0-32 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> a0-32 vif0) (new 'static 'vif-tag)) + (set! (-> a0-32 vif1) (new 'static 'vif-tag)) + (set! (-> v1-28 base) (&+ (the-as pointer a0-32) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + (the-as int arg0) + a2-1 + (the-as (pointer dma-tag) a3-16) + ) + ) + ) + ) + ) + ) + ) + ) + +(defun-debug internal-draw-debug-text-3d ((arg0 bucket-id) (arg1 string) (arg2 vector) (arg3 rgba) (arg4 vector2h)) + (let ((s2-0 (new 'stack-no-clear 'vector4w))) + (set! (-> s2-0 quad) (the-as uint128 0)) + (when (transform-point-qword! (the-as vector s2-0) arg2) + (let* ((s3-0 (-> *display* frames (-> *display* on-screen) frame debug-buf)) + (s5-0 (-> s3-0 base)) + ) + (let + ((v1-9 + (new + 'stack + 'font-context + *font-default-matrix* + (+ (+ (-> arg4 x) -1792) (/ (-> s2-0 x) 16)) + (- + (+ (+ (-> arg4 y) -8) (/ (-> s2-0 y) 16)) + (-> *video-parms* screen-miny) + ) + 0.0 + (the-as int arg3) + (the-as uint 3) + ) + ) + ) + (set! (-> v1-9 origin z) (the float (/ (-> s2-0 z) 16))) + ) + (draw-string arg1 s3-0) + (let ((a3-4 (-> s3-0 base))) + (let ((v1-11 (the-as dma-packet (-> s3-0 base)))) + (set! (-> v1-11 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> v1-11 vif0) (new 'static 'vif-tag)) + (set! (-> v1-11 vif1) (new 'static 'vif-tag)) + (set! (-> s3-0 base) (&+ (the-as pointer v1-11) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + (the-as int arg0) + s5-0 + (the-as (pointer dma-tag) a3-4) + ) + ) + ) + ) + ) + ) + +(defun-debug add-debug-outline-triangle ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 vector) (arg4 vector) (arg5 rgba)) + (when arg0 + (add-debug-line #t arg1 arg2 arg3 arg5 #f (the-as rgba -1)) + (add-debug-line #t arg1 arg3 arg4 arg5 #f (the-as rgba -1)) + (add-debug-line #t arg1 arg4 arg2 arg5 #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-triangle-normal ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 vector) (arg4 vector) (arg5 rgba)) + (local-vars + (sv-48 (function vector vector float vector)) + (sv-64 vector) + (sv-80 vector) + ) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (when arg0 + (let ((s4-0 (new 'stack-no-clear 'vector)) + (s3-0 + (vector-3pt-cross! (new 'stack-no-clear 'vector) arg2 arg3 arg4) + ) + ) + (set! sv-48 vector-float/!) + (set! sv-64 s3-0) + (set! sv-80 s3-0) + (let ((a2-2 (* 0.00024414062 (vector-length s3-0)))) + (sv-48 sv-64 sv-80 a2-2) + ) + (let ((v1-2 s4-0)) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> arg2 quad)) + (.lvf vf5 (&-> arg3 quad)) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> v1-2 quad) vf6) + ) + (let ((a0-4 s4-0)) + (let ((v1-3 s4-0)) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-3 quad)) + ) + (.lvf vf5 (&-> arg4 quad)) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a0-4 quad) vf6) + ) + (vector-float/! s4-0 s4-0 3.0) + (let ((a1-4 s3-0)) + (let ((v1-4 s3-0) + (a0-6 s4-0) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-4 quad)) + (.lvf vf5 (&-> a0-6 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-4 quad) vf6) + ) + (add-debug-line #t arg1 s4-0 s3-0 arg5 #f (the-as rgba -1)) + ) + ) + #f + ) + ) + +(defun-debug add-debug-flat-triangle ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 vector) (arg4 vector) (arg5 rgba)) + (if (not arg0) + (return #f) + ) + (let ((s5-0 (new 'stack 'vector4w-3)) + (s4-0 (new 'stack 'vector4w-3)) + ) + (set! (-> arg2 w) 1.0) + (set! (-> arg3 w) 1.0) + (set! (-> arg4 w) 1.0) + (when + (and + (transform-point-qword! (the-as vector (-> s5-0 quad)) arg2) + (transform-point-qword! (the-as vector (&-> s5-0 quad 1)) arg3) + (transform-point-qword! (the-as vector (&-> s5-0 quad 2)) arg4) + ) + (let* ((v1-9 (-> *display* frames (-> *display* on-screen) frame debug-buf)) + (a2-1 (-> v1-9 base)) + ) + (let ((a0-9 (the-as (pointer uint64) (-> v1-9 base)))) + (let* ((a1-6 v1-9) + (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-9) + (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 #x4b + :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 (-> arg5 r))) + (set! (-> s4-0 vector 0 y) (the-as int (-> arg5 g))) + (set! (-> s4-0 vector 0 z) (the-as int (-> arg5 b))) + (set! (-> s4-0 vector 0 w) (the-as int (-> arg5 a))) + (set! (-> s5-0 vector 0 z) (+ (-> s5-0 vector 0 z) -8192)) + (set! (-> s5-0 vector 1 z) (+ (-> s5-0 vector 1 z) -8192)) + (set! (-> s5-0 vector 2 z) (+ (-> s5-0 vector 2 z) -8192)) + (let* ((a1-21 v1-9) + (a3-5 (the-as (inline-array vector4w-3) (-> a1-21 base))) + ) + (set! (-> a3-5 0 quad 0) (-> s4-0 quad 0)) + (set! (-> a3-5 0 quad 1) (-> s5-0 quad 0)) + (set! (-> a3-5 0 quad 2) (-> s4-0 quad 0)) + (set! (-> a3-5 1 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a3-5 1 quad 1) (-> s4-0 quad 0)) + (set! (-> a3-5 1 quad 2) (-> (&-> s5-0 quad 2) 0)) + (set! (-> a1-21 base) (&+ (the-as pointer a3-5) 96)) + ) + (let + ((a1-25 + (/ + (the-as + int + (+ + (&- (the-as pointer -16) (the-as uint a0-9)) + (the-as int (-> v1-9 base)) + ) + ) + 16 + ) + ) + ) + (cond + ((nonzero? a1-25) + (set! + (-> a0-9 0) + (logior (-> a0-9 0) (the-as uint (shr (shl a1-25 48) 48))) + ) + (set! + (-> a0-9 1) + (logior (-> a0-9 1) (the-as uint (shl (shr (shl a1-25 48) 48) 32))) + ) + ) + (else + (set! (-> v1-9 base) a0-9) + ) + ) + ) + ) + (let ((a3-7 (-> v1-9 base))) + (let ((a0-10 (the-as dma-packet (-> v1-9 base)))) + (set! (-> a0-10 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> a0-10 vif0) (new 'static 'vif-tag)) + (set! (-> a0-10 vif1) (new 'static 'vif-tag)) + (set! (-> v1-9 base) (&+ (the-as pointer a0-10) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + (the-as int arg1) + a2-1 + (the-as (pointer dma-tag) a3-7) + ) + ) + ) + ) + ) + #f + ) + +(when *debug-segment* + +(deftype debug-line (structure) + ((flags int32 :offset-assert 0) + (bucket bucket-id :offset-assert 4) + (v1 vector :inline :offset-assert 16) + (v2 vector :inline :offset-assert 32) + (color rgba :offset-assert 48) + (mode symbol :offset-assert 52) + (color2 rgba :offset-assert 56) + ) + :method-count-assert 9 + :size-assert #x3c + :flag-assert #x90000003c + ) + +(deftype debug-text-3d (structure) + ((flags int32 :offset-assert 0) + (bucket bucket-id :offset-assert 4) + (pos vector :inline :offset-assert 16) + (color uint64 :offset-assert 32) + (offset vector2h :inline :offset-assert 40) + (str string :offset-assert 44) + ) + :method-count-assert 9 + :size-assert #x30 + :flag-assert #x900000030 + ) + +(deftype debug-tracking-thang (basic) + ((length int32 :offset-assert 4) + (allocated-length int32 :offset-assert 8) + ) + :method-count-assert 9 + :size-assert #xc + :flag-assert #x90000000c + ) + + (define *debug-lines* (the (inline-array debug-line) (malloc 'debug #x100000))) + (define *debug-lines-trk* (new 'debug 'debug-tracking-thang)) + (set! (-> *debug-lines-trk* allocated-length) 16384) + + (define *debug-text-3ds* (the (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 (i (-> *debug-text-3d-trk* allocated-length)) + (set! (-> *debug-text-3ds* i str) (new 'debug 'string 80 (the string #f))) + ) + ) + +(defun-debug get-debug-line () + (cond + ((< + (-> *debug-lines-trk* length) + (-> *debug-lines-trk* allocated-length) + ) + (set! + (-> *debug-lines-trk* 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 () + (cond + ((< + (-> *debug-text-3d-trk* length) + (-> *debug-text-3d-trk* allocated-length) + ) + (set! + (-> *debug-text-3d-trk* 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 () + (set! (-> *debug-lines-trk* length) 0) + (set! (-> *debug-text-3d-trk* length) 0) + (set! *debug-draw-pauseable* #f) + #f + ) + +(defun-debug debug-draw-buffers () + (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) + (the-as rgba (-> v1-8 color)) + (-> v1-8 offset) + ) + ) + ) + #f + ) + +(defun-debug add-debug-line ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 vector) (arg4 rgba) (arg5 symbol) (arg6 rgba)) + (when arg0 + (cond + (*debug-draw-pauseable* + (let ((v1-2 (get-debug-line))) + (when v1-2 + (set! (-> v1-2 bucket) arg1) + (set! (-> v1-2 v1 quad) (-> arg2 quad)) + (set! (-> v1-2 v2 quad) (-> arg3 quad)) + (set! (-> v1-2 color) arg4) + (set! (-> v1-2 color2) arg6) + (set! (-> v1-2 mode) arg5) + ) + ) + ) + (else + (internal-draw-debug-line arg1 arg2 arg3 arg4 arg5 arg6) + ) + ) + ) + #f + ) + +(defun-debug add-debug-line2d ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 vector) (arg4 vector)) + (if (not arg0) + (return #f) + ) + (let* ((s4-0 (-> *display* frames (-> *display* on-screen) frame debug-buf)) + (s5-0 (-> s4-0 base)) + ) + (let ((s2-0 (new 'stack 'vector4w)) + (v1-7 (new 'stack 'vector4w)) + ) + (set! (-> s2-0 quad) (-> arg2 quad)) + (set! (-> v1-7 quad) (-> arg3 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-7 x) (* (+ (-> v1-7 x) 2048) 16)) + (set! (-> v1-7 y) (* -16 (- 2048 (-> v1-7 y)))) + (set! (-> v1-7 z) #x7fffff) + (let ((a0-20 (the-as (pointer uint64) (-> 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 #x49 + :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 (inline-array vector4w) (-> a1-9 base))) + ) + (set! (-> a2-7 0 quad) (-> arg4 quad)) + (set! (-> a2-7 1 quad) (-> s2-0 quad)) + (set! (-> a1-9 base) (&+ (the-as pointer a2-7) 32)) + ) + (let* ((a1-10 s4-0) + (a2-9 (the-as (inline-array vector4w) (-> a1-10 base))) + ) + (set! (-> a2-9 0 quad) (-> arg4 quad)) + (set! (-> a2-9 1 quad) (-> v1-7 quad)) + (set! (-> a1-10 base) (&+ (the-as pointer a2-9) 32)) + ) + (let + ((a1-14 + (/ + (the-as + int + (+ + (&- (the-as pointer -16) (the-as uint a0-20)) + (the-as int (-> s4-0 base)) + ) + ) + 16 + ) + ) + ) + (cond + ((nonzero? a1-14) + (set! + (-> a0-20 0) + (logior (-> a0-20 0) (the-as uint (shr (shl a1-14 48) 48))) + ) + (set! + (-> a0-20 1) + (logior (-> a0-20 1) (the-as uint (shl (shr (shl a1-14 48) 48) 32))) + ) + ) + (else + (set! (-> s4-0 base) a0-20) + ) + ) + ) + ) + ) + (let ((a3-11 (-> s4-0 base))) + (let ((v1-10 (the-as dma-packet (-> s4-0 base)))) + (set! (-> v1-10 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> v1-10 vif0) (new 'static 'vif-tag)) + (set! (-> v1-10 vif1) (new 'static 'vif-tag)) + (set! (-> s4-0 base) (&+ (the-as pointer v1-10) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + (the-as int arg1) + s5-0 + (the-as (pointer dma-tag) a3-11) + ) + ) + ) + #f + ) + +(defun-debug add-debug-box ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 vector) (arg4 rgba)) + (let ((s5-0 (new-stack-vector0))) + (set! (-> s5-0 quad) (-> arg2 quad)) + (let ((s1-0 (new-stack-vector0))) + (set! (-> s1-0 quad) (-> arg2 quad)) + (when arg0 + (set! (-> s1-0 x) (-> arg3 x)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s1-0 x) (-> arg2 x)) + (set! (-> s1-0 y) (-> arg3 y)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> arg2 y)) + (set! (-> s1-0 z) (-> arg3 z)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s5-0 y) (-> arg3 y)) + (set! (-> s1-0 y) (-> arg3 y)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s1-0 z) (-> arg2 z)) + (set! (-> s1-0 x) (-> arg3 x)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> arg2 y)) + (set! (-> s5-0 x) (-> arg3 x)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s5-0 quad) (-> arg3 quad)) + (set! (-> s1-0 quad) (-> arg3 quad)) + (set! (-> s1-0 x) (-> arg2 x)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s1-0 x) (-> arg3 x)) + (set! (-> s1-0 y) (-> arg2 y)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> arg3 y)) + (set! (-> s1-0 z) (-> arg2 z)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s5-0 y) (-> arg2 y)) + (set! (-> s1-0 y) (-> arg2 y)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s1-0 z) (-> arg3 z)) + (set! (-> s1-0 x) (-> arg2 x)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + (set! (-> s1-0 y) (-> arg3 y)) + (set! (-> s5-0 x) (-> arg2 x)) + (add-debug-line #t arg1 s5-0 s1-0 arg4 #f (the-as rgba -1)) + ) + ) + ) + #f + ) + +(defun-debug add-debug-x ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 rgba)) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (if (not arg0) + (return #f) + ) + (let ((s3-0 (new-stack-vector0)) + (s2-0 (new-stack-vector0)) + ) + (let ((a1-1 s3-0)) + (let ((v1-2 arg2) + (a0-1 (new 'static 'vector :x -1228.8)) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-2 quad)) + (.lvf vf5 (&-> a0-1 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-1 quad) vf6) + ) + (let ((a1-2 s2-0)) + (let ((v1-3 arg2) + (a0-2 (new 'static 'vector :x 1228.8)) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-3 quad)) + (.lvf vf5 (&-> a0-2 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-2 quad) vf6) + ) + (add-debug-line #t arg1 s3-0 s2-0 arg3 #f (the-as rgba -1)) + (let ((a1-4 s3-0)) + (let ((v1-4 arg2) + (a0-4 (new 'static 'vector :z -1228.8)) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-4 quad)) + (.lvf vf5 (&-> a0-4 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-4 quad) vf6) + ) + (let ((a0-5 s2-0)) + (let ((v1-5 (new 'static 'vector :z 1228.8))) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> arg2 quad)) + (.lvf vf5 (&-> v1-5 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a0-5 quad) vf6) + ) + (add-debug-line #t arg1 s3-0 s2-0 arg3 #f (the-as rgba -1)) + ) + #f + ) + ) + +(defun-debug add-debug-text-3d ((arg0 symbol) (arg1 bucket-id) (arg2 string) (arg3 vector) (arg4 rgba) (arg5 vector2h)) + (when arg0 + (cond + (*debug-draw-pauseable* + (let ((v1-2 (get-debug-text-3d))) + (when v1-2 + (set! (-> v1-2 flags) 0) + (set! (-> v1-2 bucket) arg1) + (set! (-> v1-2 pos quad) (-> arg3 quad)) + (cond + (arg5 + (set! (-> v1-2 offset x) (-> arg5 x)) + (set! (-> v1-2 offset y) (-> arg5 y)) + ) + (else + (set! (-> v1-2 offset x) 0) + (set! (-> v1-2 offset y) 0) + (let ((a0-5 0)) + ) + ) + ) + (set! (-> v1-2 color) (the-as uint arg4)) + (let ((a0-6 0) + (a1-2 (-> arg2 data)) + (v1-4 (-> v1-2 str data)) + ) + (while (and (nonzero? (-> a1-2 0)) (< a0-6 79)) + (set! (-> v1-4 0) (-> a1-2 0)) + (set! a1-2 (&-> a1-2 1)) + (set! v1-4 (&-> v1-4 1)) + (+! a0-6 1) + ) + (set! (-> v1-4 0) (the-as uint 0)) + ) + (let ((a0-8 0)) + ) + ) + ) + ) + (else + (internal-draw-debug-text-3d arg1 arg2 arg3 arg4 (if arg5 + arg5 + (new 'static 'vector2h) + ) + ) + ) + ) + ) + #f + ) + +(defun-debug add-debug-sphere-with-transform ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 float) (arg4 matrix) (arg5 rgba)) + (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 arg0 + (.lvf vf5 (&-> arg2 quad)) + (.lvf vf1 (&-> arg4 vector 0 quad)) + (.lvf vf2 (&-> arg4 vector 1 quad)) + (.lvf vf3 (&-> arg4 vector 2 quad)) + (.lvf vf4 (&-> arg4 vector 3 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 arg0 arg1 a2-1 arg3 arg5) + ) + ) + #f + ) + ) + +(defun-debug add-debug-sphere ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 float) (arg4 rgba)) + (if arg0 + (add-debug-sphere-from-table arg1 arg2 arg3 arg4) + ) + #f + ) + +(defun-debug add-debug-text-sphere ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 float) (arg4 string) (arg5 rgba)) + (add-debug-sphere arg0 arg1 arg2 arg3 arg5) + (add-debug-text-3d arg0 arg1 arg4 arg2 (new 'static 'rgba) (the-as vector2h #f)) + #f + ) + +(defun-debug add-debug-spheres ((arg0 symbol) (arg1 bucket-id) (arg2 (pointer float)) (arg3 int) (arg4 rgba)) + (when arg0 + (let ((s4-0 (&-> arg2 0)) + (s3-0 arg3) + ) + (while (nonzero? s3-0) + (+! s3-0 -1) + (add-debug-sphere #t arg1 (the-as vector s4-0) (-> s4-0 3) arg4) + (set! s4-0 (&-> s4-0 4)) + ) + ) + ) + #f + ) + +(defun-debug add-debug-circle ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 float) (arg4 rgba) (arg5 matrix)) + "" + "note: you may pass #f for orientation" + + (local-vars (sv-48 int) (sv-64 vector) (sv-80 vector)) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (if (not arg0) + (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) (* arg3 (cos f30-0))) + (set! (-> sv-64 y) 0.0) + (set! (-> sv-64 z) (* arg3 (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) (* arg3 (cos f30-0))) + (set! (-> sv-80 y) 0.0) + (set! (-> sv-80 z) (* arg3 (sin f30-0))) + (set! (-> sv-80 w) 1.0) + (when arg5 + (vector-matrix*! s1-0 s1-0 arg5) + (vector-matrix*! s0-0 s0-0 arg5) + ) + (let ((a1-3 s1-0)) + (let ((v1-13 s1-0) + (a0-7 arg2) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-13 quad)) + (.lvf vf5 (&-> a0-7 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-3 quad) vf6) + ) + (let ((a1-4 s0-0)) + (let ((v1-14 s0-0) + (a0-8 arg2) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-14 quad)) + (.lvf vf5 (&-> a0-8 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-4 quad) vf6) + ) + (add-debug-line #t arg1 s1-0 s0-0 arg4 #f (the-as rgba -1)) + (set! sv-48 (+ sv-48 1)) + ) + ) + #f + ) + ) + +(defun-debug add-debug-vector ((arg0 symbol) (arg1 bucket-id) (arg2 vector) (arg3 vector) (arg4 float) (arg5 rgba)) + (if (not arg0) + (return #f) + ) + (let ((v1-2 (new-stack-vector0))) + (set! (-> v1-2 x) (+ (-> arg2 x) (* (-> arg3 x) arg4))) + (set! (-> v1-2 y) (+ (-> arg2 y) (* (-> arg3 y) arg4))) + (set! (-> v1-2 z) (+ (-> arg2 z) (* (-> arg3 z) arg4))) + (add-debug-line #t arg1 arg2 v1-2 arg5 #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-matrix ((arg0 symbol) (arg1 bucket-id) (arg2 matrix)) + (add-debug-vector arg0 arg1 (-> arg2 vector 3) (-> arg2 vector 0) (meters 2) (new 'static 'rgba :r #xff :a #x80)) + (add-debug-vector arg0 arg1 (-> arg2 vector 3) (-> arg2 vector 1) (meters 2) (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector arg0 arg1 (-> arg2 vector 3) (-> arg2 vector 2) (meters 2) (new 'static 'rgba :b #xff :a #x80)) + arg2 + ) + +(defun-debug add-debug-rot-matrix ((arg0 symbol) (arg1 bucket-id) (arg2 matrix) (arg3 vector)) + (add-debug-vector arg0 arg1 arg3 (-> arg2 vector 0) (meters 2) (new 'static 'rgba :r #xff :a #x80)) + (add-debug-vector arg0 arg1 arg3 (-> arg2 vector 1) (meters 2) (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector arg0 arg1 arg3 (-> arg2 vector 2) (meters 2) (new 'static 'rgba :b #xff :a #x80)) + arg2 + ) + +(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 arg0) + (return #f) + ) + (let ((s1-0 (new-stack-vector0))) + (let ((s2-0 s1-0)) + (set! (-> s2-0 x) (+ (-> arg2 x) (* (sin sv-32) s0-0))) + (set! (-> s2-0 y) (-> arg2 y)) + (set! (-> s2-0 z) (+ (-> arg2 z) (* (cos sv-32) s0-0))) + (set! (-> s2-0 w) 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) + ) + (rlet ((vf0 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + ) + (init-vf0-vector) + (if (not arg0) + (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) + ) + (let ((a1-3 sv-48)) + (let ((v1-21 sv-48) + (a0-8 arg2) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-21 quad)) + (.lvf vf5 (&-> a0-8 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-3 quad) vf6) + ) + (let ((a1-4 sv-64)) + (let ((v1-22 sv-64) + (a0-9 arg2) + ) + (.mov.vf vf6 vf0 :mask #b1000) + (.lvf vf4 (&-> v1-22 quad)) + (.lvf vf5 (&-> a0-9 quad)) + ) + (.add.vf vf6 vf4 vf5 :mask #b111) + (.svf (&-> a1-4 quad) vf6) + ) + (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 pointer) (arg3 int) (arg4 vector) (arg5 int) (arg6 rgba)) + (local-vars (sv-48 vector) (sv-64 int) (sv-80 int)) + (if (not arg0) + (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 x) (the-as int 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)) + (the-as int 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)) + (if arg0 + (add-debug-curve + #t + arg1 + (-> arg2 cverts) + (-> arg2 num-cverts) + (the-as vector (-> 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-96 vector) + ) + (when arg0 + (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) + ) + (add-debug-text-3d #t arg1 (string-format "~d" s0-0) sv-96 (the rgba 1) (the vector2h #f)) + (add-debug-x #t arg1 sv-96 (if (= s0-0 arg6) + (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80) + arg4 + )) + ) + ) + #f + ) + +(defun-debug debug-percent-bar ((arg0 symbol) (arg1 bucket-id) (arg2 int) (arg3 int) (arg4 float) (arg5 rgba)) + (if (not arg0) + (return #f) + ) + (let* ((s0-0 (-> *display* frames (-> *display* on-screen) frame debug-buf)) + (s5-0 (-> s0-0 base)) + ) + (draw-sprite2d-xy s0-0 arg2 arg3 255 14 (new 'static 'rgba :a #x40)) + (draw-sprite2d-xy s0-0 arg2 (+ arg3 2) (the int (* 255.0 arg4)) 10 arg5) + (let ((a3-3 (-> s0-0 base))) + (let ((v1-5 (the-as dma-packet (-> s0-0 base)))) + (set! (-> v1-5 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> v1-5 vif0) (new 'static 'vif-tag)) + (set! (-> v1-5 vif1) (new 'static 'vif-tag)) + (set! (-> s0-0 base) (&+ (the-as pointer v1-5) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + (the-as int arg1) + s5-0 + (the-as (pointer dma-tag) a3-3) + ) + ) + ) + #f + ) + +;; this function is broken and unused +;; TODO fix it (expand array) +(defun-debug debug-pad-display ((arg0 cpad-info)) + (let + ((gp-0 + (new 'static 'inline-array vector 8 + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + (new 'static 'vector) + ) + ) + ) + (let ((v1-0 31)) + (while (nonzero? v1-0) + (+! v1-0 -1) + (set! (-> gp-0 (+ v1-0 1) quad) (-> gp-0 v1-0 quad)) + ) + ) + (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) + (let* ((s3-0 (-> *display* frames (-> *display* on-screen) frame debug-buf)) + (s4-0 (-> s3-0 base)) + ) + (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))) + ) + (let ((a3-1 (-> s3-0 base))) + (let ((v1-12 (the-as dma-packet (-> s3-0 base)))) + (set! (-> v1-12 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> v1-12 vif0) (new 'static 'vif-tag)) + (set! (-> v1-12 vif1) (new 'static 'vif-tag)) + (set! (-> s3-0 base) (&+ (the-as pointer v1-12) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + 67 + s4-0 + (the-as (pointer dma-tag) a3-1) + ) + ) + ) + ) + ) + #f + ) + +(defun-debug add-debug-light ((arg0 symbol) (arg1 bucket-id) (arg2 light) (arg3 vector) (arg4 string)) + (if (not arg0) + (return #f) + ) + (when (!= (-> arg2 levels x) 0.0) + (add-debug-vector + arg0 + arg1 + arg3 + (-> arg2 direction) + (meters 3) + (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80) + ) + ;; this might be wrong + (let ((light-vec-end (vector+*! (new-stack-vector0) arg3 (-> arg2 direction) (* (meters 3) (-> arg2 levels x)))) + (light-rgba (new 'static 'rgba :r (the int (* 128.0 (-> arg2 color x))) + :g (the int (* 128.0 (-> arg2 color y))) + :b (the int (* 128.0 (-> arg2 color z))) + :a (the int (* 128.0 (-> arg2 color w))) + )) + ) + (add-debug-text-sphere + arg0 + arg1 + light-vec-end + (* (meters 0.5) (-> arg2 levels x)) + (string-format "~S ~,,2f" arg4 (-> arg2 levels x)) + light-rgba + ) + ) + ) + #f + ) + +(defun-debug add-debug-lights ((arg0 symbol) (arg1 bucket-id) (arg2 (inline-array light)) (arg3 vector)) + (if (not arg0) + (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-extern drawable-frag-count drawable int) +(defun-debug drawable-frag-count ((arg0 drawable)) + (let ((gp-0 0)) + (cond + ((not arg0) + ) + ((type-type? (-> arg0 type) drawable-group) + (dotimes (s4-0 (-> (the drawable-group arg0) length)) + (+! gp-0 (drawable-frag-count (-> (the drawable-group arg0) data s4-0))) + ) + ) + (else + (+! gp-0 1) + ) + ) + gp-0 + ) + ) + +(defmethod inspect debug-vertex-stats ((obj debug-vertex-stats)) + (format #t "[~8x] ~A~%" obj (-> obj type)) + (format #t "~Tlength: ~D~%" (-> obj length)) + (format #t "~Tpos-count: ~D~%" (-> obj pos-count)) + (format #t "~Tdata[~D]: @ #x~X~%" (-> obj length) (-> obj vertex)) + (dotimes (s5-0 (-> obj length)) + (let ((s4-0 (-> obj 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) + ) + ) + ) + obj + ) + +(defun-debug history-init ((arg0 pos-history) (arg1 int)) + (set! (-> arg0 num-points) arg1) + (set! (-> arg0 points) (the (inline-array vector) #f)) + arg0 + ) + +(defun-debug history-draw-and-update ((arg0 pos-history) (arg1 int) (arg2 vector)) + (if (and arg1 (not (-> arg0 points))) + (set! (-> arg0 points) (the (inline-array vector) (malloc 'debug (* (-> arg0 num-points) 16)))) + ) + (when (-> arg0 points) + (set! (-> (-> arg0 points) (-> arg0 h-first) quad) (-> arg2 quad)) + (set! (-> arg0 h-first) (+ (-> arg0 h-first) 1)) + (when (>= (-> arg0 h-first) (-> arg0 num-points)) + (set! (-> arg0 h-first) 0) + ) + ) + (when arg1 + (dotimes (s5-1 (1- (-> arg0 num-points))) + (if (!= (+ s5-1 1) (-> arg0 h-first)) + (add-debug-line + #t + (bucket-id debug-draw1) + (-> (-> 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-matrix0)) + ) + (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 vector 0 x) -0.911) + (set! (-> a1-0 vector 0 y) 0.0) + (set! (-> a1-0 vector 0 z) 0.4122) + (set! (-> a1-0 vector 0 w) 0.0) + (set! (-> a1-0 vector 1 x) -0.0984) + (set! (-> a1-0 vector 1 y) 0.971) + (set! (-> a1-0 vector 1 z) -0.2174) + (set! (-> a1-0 vector 1 w) 0.0) + (set! (-> a1-0 vector 2 x) -0.4003) + (set! (-> a1-0 vector 2 y) -0.2387) + (set! (-> a1-0 vector 2 z) -0.8847) + (set! (-> a1-0 vector 2 w) 0.0) + (set! (-> a1-0 vector 3 x) 0.0) + (set! (-> a1-0 vector 3 y) 0.0) + (set! (-> a1-0 vector 3 z) 0.0) + (set! (-> a1-0 vector 3 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 + ) + + + + diff --git a/goal_src/engine/dma/dma-h.gc b/goal_src/engine/dma/dma-h.gc index c136e70096..eec49d8601 100644 --- a/goal_src/engine/dma/dma-h.gc +++ b/goal_src/engine/dma/dma-h.gc @@ -199,6 +199,48 @@ :flag-assert #x900000008 ) + +(defenum bucket-id + :type int32 + :bitfield #f + + (tfrag-tex0 5) + ;; merc0 10 + ;; generic0 11 + + (tfrag-tex1 12) + ;; merc1 17 + ;; generic1 18 + + (shrub-tex0 19) + + (shrub-tex1 25) + + (alpha-tex0 31) + + (alpha-tex1 38) + + (pris-tex0 48) + ;; merc0 49 + ;; generic0 50 + + (pris-tex1 51) + ;; merc1 52 + ;; generic1 53 + + (water-tex0 57) + ;; merc0 58 (+ default) + ;; generic0 59 (+ default) + + (water-tex1 60) + ;; merc1 61 + ;; generic1 62 + ;; debug spheres? 67 + (debug-draw0 67) + ;; debug text 68 + (debug-draw1 68) + ) + ;; A DMA bucket is a way of organizing data within a dma buffer. ;; The buckets themselves live inside in the dma buffer. ;; the addr field of their tag should point to the next bucket. diff --git a/goal_src/engine/draw/drawable-group-h.gc b/goal_src/engine/draw/drawable-group-h.gc index 0a18b65b3e..d5c5eb4371 100644 --- a/goal_src/engine/draw/drawable-group-h.gc +++ b/goal_src/engine/draw/drawable-group-h.gc @@ -7,7 +7,9 @@ (deftype drawable-group (drawable) - ((pad uint8 4)) ;; todo - what's here? + ((length int16 :offset 6) + (data drawable 1 :offset-assert 32) + ) :flag-assert #x1200000024 ) diff --git a/goal_src/engine/geometry/geometry.gc b/goal_src/engine/geometry/geometry.gc index 199b07ea96..8f47bf449b 100644 --- a/goal_src/engine/geometry/geometry.gc +++ b/goal_src/engine/geometry/geometry.gc @@ -11,3 +11,7 @@ (define-extern forward-up-nopitch->quaternion (function quaternion vector vector quaternion)) (define-extern forward-up->quaternion (function quaternion vector vector quaternion)) (define-extern vector-flatten! (function vector vector vector vector)) + +;; TODO +(define-extern vector-3pt-cross! (function vector vector vector vector vector)) +(define-extern curve-evaluate! (function vector float int int vector int int)) \ No newline at end of file diff --git a/goal_src/engine/gfx/font-h.gc b/goal_src/engine/gfx/font-h.gc index 42a1412bf6..227b5b38bd 100644 --- a/goal_src/engine/gfx/font-h.gc +++ b/goal_src/engine/gfx/font-h.gc @@ -663,3 +663,5 @@ ) +(defun-extern draw-string string dma-buffer int) + diff --git a/goal_src/engine/gfx/tie/tie-h.gc b/goal_src/engine/gfx/tie/tie-h.gc index 7adbab273c..f1d748ec6a 100644 --- a/goal_src/engine/gfx/tie/tie-h.gc +++ b/goal_src/engine/gfx/tie/tie-h.gc @@ -48,9 +48,7 @@ ) (deftype drawable-tree-instance-tie (drawable-tree) - ((length int16 :offset 6) - (prototypes basic :offset 8) - ;; todo - maybe another data field + ((prototypes basic :offset 8) ) :method-count-assert 18 :size-assert #x24 diff --git a/goal_src/engine/level/level-h.gc b/goal_src/engine/level/level-h.gc index cb507a58f4..4f176df2f7 100644 --- a/goal_src/engine/level/level-h.gc +++ b/goal_src/engine/level/level-h.gc @@ -5,44 +5,6 @@ ;; name in dgo: level-h ;; dgos: GAME, ENGINE -(defenum bucket-id - :type uint32 - :bitfield #f - - (tfrag-tex0 5) - ;; merc0 10 - ;; generic0 11 - - (tfrag-tex1 12) - ;; merc1 17 - ;; generic1 18 - - (shrub-tex0 19) - - (shrub-tex1 25) - - (alpha-tex0 31) - - (alpha-tex1 38) - - (pris-tex0 48) - ;; merc0 49 - ;; generic0 50 - - (pris-tex1 51) - ;; merc1 52 - ;; generic1 53 - - (water-tex0 57) - ;; merc0 58 (+ default) - ;; generic0 59 (+ default) - - (water-tex1 60) - ;; merc1 61 - ;; generic1 62 - ;; debug text 68 - (debug-draw 68) - ) ;; Information related to visibility data for a level. ;; Unclear why there are 8 of these per level. diff --git a/goal_src/engine/math/quaternion-h.gc b/goal_src/engine/math/quaternion-h.gc index 5b5148e5d0..0b992c67ff 100644 --- a/goal_src/engine/math/quaternion-h.gc +++ b/goal_src/engine/math/quaternion-h.gc @@ -10,7 +10,7 @@ (y float :offset-assert 4) (z float :offset-assert 8) (w float :offset-assert 12) - (data float 4 :do-not-decompile :offset 0) + (data float 4 :score -9999 :offset 0) (vec vector :inline :offset 0) (quad uint128 :offset 0) ) diff --git a/goal_src/engine/math/vector-h.gc b/goal_src/engine/math/vector-h.gc index 99a10e89dd..761d343543 100644 --- a/goal_src/engine/math/vector-h.gc +++ b/goal_src/engine/math/vector-h.gc @@ -186,7 +186,7 @@ ;; Vector of 3 signed words (deftype vector3w (structure) - ((data int32 3 :do-not-decompile :offset-assert 0) + ((data int32 3 :score -9999 :offset-assert 0) (x int32 :offset 0) (y int32 :offset 4) (z int32 :offset 8) @@ -199,7 +199,7 @@ ;; Vector of 4 signed words (deftype vector4w (structure) - ((data int32 4 :do-not-decompile :offset-assert 0) + ((data int32 4 :score -9999 :offset-assert 0) (x int32 :offset 0) (y int32 :offset 4) (z int32 :offset 8) @@ -226,7 +226,7 @@ (deftype vector4w-2 (structure) ((data int32 8 :offset-assert 0) (quad uint128 2 :offset 0) - (vector vector4w 2 :offset 0) + (vector vector4w 2 :inline :offset 0) ) :method-count-assert 9 :size-assert #x20 @@ -237,7 +237,7 @@ (deftype vector4w-3 (structure) ((data int32 12 :offset-assert 0) (quad uint128 3 :offset 0) - (vector vector4w 3 :offset 0) + (vector vector4w 3 :inline :offset 0) ) :method-count-assert 9 :size-assert #x30 @@ -248,7 +248,7 @@ (deftype vector4w-4 (structure) ((data int32 16 :offset-assert 0) (quad uint128 4 :offset 0) - (vector vector4w 4 :offset 0) + (vector vector4w 4 :inline :offset 0) ) :method-count-assert 9 :size-assert #x40 @@ -296,7 +296,7 @@ ;; Vector of 4 floats. Shortened to "vector" because it is commonly used. (deftype vector (structure) - ((data float 4 :do-not-decompile :offset-assert 0) + ((data float 4 :do-not-decompile :score -9999 :offset-assert 0) (x float :offset 0) (y float :offset 4) (z float :offset 8) @@ -498,11 +498,6 @@ (set! (-> vec w) ,wv))) ) -(defmacro init-vf0-vector () - "Initializes the VF0 vector which is a constant vector in the VU set to <0,0,0,1>" - `(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) - ) - (defun vector-dot ((a vector) (b vector)) "Take the dot product of two vectors. Only does the x, y, z compoments. diff --git a/goal_src/engine/physics/trajectory.gc b/goal_src/engine/physics/trajectory.gc index 33b9cf8f55..221be2f584 100644 --- a/goal_src/engine/physics/trajectory.gc +++ b/goal_src/engine/physics/trajectory.gc @@ -148,7 +148,7 @@ ((f0-1 (* (-> obj time) (/ (+ 1.0 (the float s2-0)) (the float s3-0))))) ((method-of-type trajectory TODO-RENAME-9) obj f0-1 s4-0) ) - (add-debug-line #t 68 s5-0 s4-0 (new 'static 'rgba :r #xff :a #x80) #f -1) + (add-debug-line #t (the bucket-id 68) s5-0 s4-0 (new 'static 'rgba :r #xff :a #x80) #f (the rgba -1)) ) ) (let ((v0-2 0)) diff --git a/goal_src/engine/ps2/vu1-macros.gc b/goal_src/engine/ps2/vu1-macros.gc index e7c36a82d6..41210e2624 100644 --- a/goal_src/engine/ps2/vu1-macros.gc +++ b/goal_src/engine/ps2/vu1-macros.gc @@ -61,3 +61,103 @@ ) ) ) + + +;; In the original game, init-for-transform stashed a bunch of stuff in registers, to be used by other functions. +;; In OpenGOAL, this seems risky so we're going to back up this manually. +;; This does mean this file now has code, but it's not a big deal: +(deftype transform-regs (structure) + ;; Eventually we might want to actually name some of these fields to be more comprehensible? + (;; vf0 not included! + (vf1 uint128) + (vf2 uint128) + (vf3 uint128) + (vf4 uint128) + (vf5 uint128) + (vf6 uint128) + (vf7 uint128) + (vf8 uint128) + (vf9 uint128) + (vf10 uint128) + (vf11 uint128) + (vf12 uint128) + (vf13 uint128) + (vf14 uint128) + (vf15 uint128) + (vf16 uint128) + (vf17 uint128) + (vf18 uint128) + (vf19 uint128) + (vf20 uint128) + (vf21 uint128) + (vf22 uint128) + (vf23 uint128) + (vf24 uint128) + (vf25 uint128) + (vf26 uint128) + (vf27 uint128) + (vf28 uint128) + (vf29 uint128) + (vf30 uint128) + (vf31 uint128) + ) + ) + +(define *transform-regs* (new 'static 'transform-regs)) + +(defmacro init-vf0-vector () + "Initializes the VF0 vector which is a constant vector in the VU set to <0,0,0,1>" + `(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) + ) + +(defmacro with-vf0 (&rest body) + "Macro for using the ps2-style vf0 register." + + `(rlet ((vf0 :class vf)) + (init-vf0-vector) + ,@body + ) + ) + +(defmacro load-vf (reg) + "Load a vf from the preserved vf registers" + `(.lvf ,reg (&-> *transform-regs* ,reg)) + ) + +(defmacro save-vf (reg) + "Save a vf to the preserved vf registers" + `(.svf (&-> *transform-regs* ,reg) ,reg) + ) + +(defmacro with-vf (regs &key (rw 'read) &rest body) + "Macro for using the specified ps2-style vf registers. These are preserved in *transform-regs* + Each register name in regs must be a valid vf register name. vf0 CANNOT be used! Use with-vf0 for that instead. + rw specifies the read/write mode: + 'read means the registers will be read from the preserved registers. This is the default + 'write means the registers will be written to the preserved registers at the end + 'readwrite (or 'rw) means both + #f means neither, turning this into a fancy macro around rlet." + + `(rlet (,@(apply (lambda (x) `(,x :class vf)) regs)) + + ,@(if (or (eq? rw ''read) (eq? rw ''readwrite) (eq? rw ''rw)) + (apply (lambda (y) + `(load-vf ,y) + ) regs) + '() + ) + + ,@body + + ;; this will mess up the return value! + ,@(if (or (eq? rw ''write) (eq? rw ''readwrite) (eq? rw ''rw)) + (apply (lambda (y) + `(save-vf ,y) + ) regs) + '() + ) + + ) + ) + + diff --git a/goal_src/engine/target/joint-mod-h.gc b/goal_src/engine/target/joint-mod-h.gc index 978945c59c..54390765ef 100644 --- a/goal_src/engine/target/joint-mod-h.gc +++ b/goal_src/engine/target/joint-mod-h.gc @@ -70,7 +70,7 @@ (defun-debug joint-mod-debug-draw ((mod joint-mod)) "Draw a frame at the bone." ;; I believe this draws a set of coordinate axes that represent the transformation matrix. - (add-debug-matrix #t (bucket-id debug-draw) (-> mod joint bone transform)) + (add-debug-matrix #t (bucket-id debug-draw1) (-> mod joint bone transform)) (none) ) @@ -460,7 +460,7 @@ (if (and (= (-> gp-0 process type) target) (!= (-> gp-0 blend) 0.0)) (add-debug-text-sphere *display-target-marks* - (bucket-id debug-draw) + (bucket-id debug-draw1) (-> gp-0 target) 819.2 "look" @@ -589,7 +589,7 @@ (if (and (= (-> gp-0 process type) target) (!= (-> gp-0 blend) 0.0)) (add-debug-text-sphere *display-target-marks* - (bucket-id debug-draw) + (bucket-id debug-draw1) (-> gp-0 target) 819.2 "look" diff --git a/goal_src/kernel/gkernel-h.gc b/goal_src/kernel/gkernel-h.gc index 8c33013bdf..89e4cb17d9 100644 --- a/goal_src/kernel/gkernel-h.gc +++ b/goal_src/kernel/gkernel-h.gc @@ -54,7 +54,7 @@ ;; ENUMS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; bitfield enum to indicate proprties about a process-tree +;; bitfield enum to indicate properties about a process-tree (defenum process-mask :bitfield #t :type uint32 (execute 0) ;; 1 diff --git a/goalc/compiler/compilation/CompilerControl.cpp b/goalc/compiler/compilation/CompilerControl.cpp index 57fe827129..ae0b561b66 100644 --- a/goalc/compiler/compilation/CompilerControl.cpp +++ b/goalc/compiler/compilation/CompilerControl.cpp @@ -50,7 +50,7 @@ Val* Compiler::compile_seval(const goos::Object& form, const goos::Object& rest, m_goos.eval_with_rewind(o, m_goos.global_environment.as_env()); }); } catch (std::runtime_error& e) { - throw_compiler_error(form, "Error while evaluating GOOS: ", e.what()); + throw_compiler_error(form, "Error while evaluating GOOS: {}", e.what()); } return get_none(); } diff --git a/scripts/batch/test-offline.bat b/scripts/batch/test-offline.bat index 50f3ed8978..5f11e8525a 100644 --- a/scripts/batch/test-offline.bat +++ b/scripts/batch/test-offline.bat @@ -1,4 +1,4 @@ @echo off cd ..\.. -out\build\Release\bin\offline-test --dump-mode iso_data\jak1\ +out\build\Release\bin\offline-test iso_data\jak1\ pause \ No newline at end of file diff --git a/test/decompiler/reference/all_forward_declarations.gc b/test/decompiler/reference/all_forward_declarations.gc index 317b08c316..ba45f2411c 100644 --- a/test/decompiler/reference/all_forward_declarations.gc +++ b/test/decompiler/reference/all_forward_declarations.gc @@ -592,6 +592,47 @@ `(.lvf vf0 (new 'static 'vector :x 0.0 :y 0.0 :z 0.0 :w 1.0)) ) +(defenum bucket-id + :type int32 + :bitfield #f + + (tfrag-tex0 5) + ;; merc0 10 + ;; generic0 11 + + (tfrag-tex1 12) + ;; merc1 17 + ;; generic1 18 + + (shrub-tex0 19) + + (shrub-tex1 25) + + (alpha-tex0 31) + + (alpha-tex1 38) + + (pris-tex0 48) + ;; merc0 49 + ;; generic0 50 + + (pris-tex1 51) + ;; merc1 52 + ;; generic1 53 + + (water-tex0 57) + ;; merc0 58 (+ default) + ;; generic0 59 (+ default) + + (water-tex1 60) + ;; merc1 61 + ;; generic1 62 + ;; debug spheres? 67 + (debug-draw0 67) + ;; debug text 68 + (debug-draw1 68) + ) + ;; TODO - for trajectory.gc (declare-type trajectory structure) (deftype rgba (uint32) @@ -602,7 +643,7 @@ ) :flag-assert #x900000004 ) -(define-extern add-debug-line (function symbol int vector vector rgba symbol int int)) +(define-extern add-debug-line (function symbol bucket-id vector vector rgba symbol rgba symbol)) ;; early declarations for draw-control (declare-type ripple-control basic) @@ -613,7 +654,7 @@ (declare-type merc-ctrl basic) ;; TODO - for ripple -(define-extern add-debug-sphere (function symbol int vector float int int)) +(define-extern add-debug-sphere (function symbol bucket-id vector float rgba symbol)) (defconstant SYM_TO_STRING_OFFSET #xff38) (defmacro symbol->string (sym) @@ -758,50 +799,11 @@ (reset 7) ;; 128 ) -(defenum bucket-id - :type uint32 - :bitfield #f - - (tfrag-tex0 5) - ;; merc0 10 - ;; generic0 11 - - (tfrag-tex1 12) - ;; merc1 17 - ;; generic1 18 - - (shrub-tex0 19) - - (shrub-tex1 25) - - (alpha-tex0 31) - - (alpha-tex1 38) - - (pris-tex0 48) - ;; merc0 49 - ;; generic0 50 - - (pris-tex1 51) - ;; merc1 52 - ;; generic1 53 - - (water-tex0 57) - ;; merc0 58 (+ default) - ;; generic0 59 (+ default) - - (water-tex1 60) - ;; merc1 61 - ;; generic1 62 - ;; debug text 68 - (debug-draw 68) - ) - (define-extern cspace<-parented-transformq-joint! (function cspace transformq none)) (define-extern cspace<-transformq! (function cspace transformq matrix)) (define-extern vector<-cspace! (function vector cspace vector)) -(define-extern add-debug-text-sphere (function symbol bucket-id vector float string rgba none)) -(define-extern add-debug-matrix (function symbol bucket-id matrix none)) +(define-extern add-debug-text-sphere (function symbol bucket-id vector float string rgba symbol)) +(define-extern add-debug-matrix (function symbol bucket-id matrix matrix)) (define-extern vector-flatten! (function vector vector vector vector)) diff --git a/test/decompiler/reference/engine/ambient/mood-tables_REF.gc b/test/decompiler/reference/engine/ambient/mood-tables_REF.gc index 0909488230..1af27e5fe9 100644 --- a/test/decompiler/reference/engine/ambient/mood-tables_REF.gc +++ b/test/decompiler/reference/engine/ambient/mood-tables_REF.gc @@ -4465,7 +4465,3 @@ ;; failed to figure out what this is: (set! (-> *citadel-mood* num-stars) 0.0) - - - - diff --git a/test/decompiler/reference/engine/debug/debug-h_REF.gc b/test/decompiler/reference/engine/debug/debug-h_REF.gc index 105e319c98..e7abdec501 100644 --- a/test/decompiler/reference/engine/debug/debug-h_REF.gc +++ b/test/decompiler/reference/engine/debug/debug-h_REF.gc @@ -3,10 +3,10 @@ ;; definition of type pos-history (deftype pos-history (structure) - ((points uint32 :offset-assert 0) - (num-points int32 :offset-assert 4) - (h-first int32 :offset-assert 8) - (h-last int32 :offset-assert 12) + ((points (inline-array vector) :offset-assert 0) + (num-points int32 :offset-assert 4) + (h-first int32 :offset-assert 8) + (h-last int32 :offset-assert 12) ) :method-count-assert 9 :size-assert #x10 diff --git a/test/decompiler/reference/engine/debug/debug-sphere_REF.gc b/test/decompiler/reference/engine/debug/debug-sphere_REF.gc index 06518b0e15..362727dc8d 100644 --- a/test/decompiler/reference/engine/debug/debug-sphere_REF.gc +++ b/test/decompiler/reference/engine/debug/debug-sphere_REF.gc @@ -99,7 +99,7 @@ ;; Used lq/sq (defun add-debug-sphere-from-table - ((arg0 int) (arg1 vector) (arg2 vector) (arg3 rgba)) + ((arg0 bucket-id) (arg1 vector) (arg2 float) (arg3 rgba)) (rlet ((vf1 :class vf) (vf2 :class vf) (vf3 :class vf) @@ -127,8 +127,8 @@ (.svf (&-> s4-0 quad) vf3) (.svf (&-> s3-0 quad) vf4) (.svf (&-> s2-0 quad) vf5) - (add-debug-line #t arg0 s4-0 s3-0 arg3 #f -1) - (add-debug-line #t arg0 s4-0 s2-0 arg3 #f -1) + (add-debug-line #t arg0 s4-0 s3-0 arg3 #f (the-as rgba -1)) + (add-debug-line #t arg0 s4-0 s2-0 arg3 #f (the-as rgba -1)) ) ) (let ((v0-2 0)) @@ -136,7 +136,3 @@ (none) ) ) - - - - diff --git a/test/decompiler/reference/engine/draw/drawable-group-h_REF.gc b/test/decompiler/reference/engine/draw/drawable-group-h_REF.gc index 2b483f22a3..fd78a17332 100644 --- a/test/decompiler/reference/engine/draw/drawable-group-h_REF.gc +++ b/test/decompiler/reference/engine/draw/drawable-group-h_REF.gc @@ -3,7 +3,8 @@ ;; definition of type drawable-group (deftype drawable-group (drawable) - ((pad uint8 4 :offset-assert 32) + ((length int16 :offset 6) + (data drawable 1 :offset-assert 32) ) :method-count-assert 18 :size-assert #x24 @@ -16,7 +17,3 @@ ;; failed to figure out what this is: (let ((v0-1 0)) ) - - - - diff --git a/test/decompiler/reference/engine/gfx/font-h_REF.gc b/test/decompiler/reference/engine/gfx/font-h_REF.gc index 840ad3433f..9b9de3a163 100644 --- a/test/decompiler/reference/engine/gfx/font-h_REF.gc +++ b/test/decompiler/reference/engine/gfx/font-h_REF.gc @@ -396,7 +396,8 @@ (new 'static 'vector :z 1.0) ) ) - :color-shadow (new 'static 'vector4w :w #x80) + :color-shadow + (new 'static 'vector4w :data (new 'static 'array int32 4 0 0 0 #x80)) :color-table (new 'static 'inline-array char-color 64 (new 'static 'char-color diff --git a/test/decompiler/reference/engine/gfx/ripple_REF.gc b/test/decompiler/reference/engine/gfx/ripple_REF.gc index efe367714f..13a414584d 100644 --- a/test/decompiler/reference/engine/gfx/ripple_REF.gc +++ b/test/decompiler/reference/engine/gfx/ripple_REF.gc @@ -136,7 +136,7 @@ ;; ERROR: function was not converted to expressions. Cannot decompile. ;; definition (debug) for function ripple-add-debug-sphere -;; INFO: Return type mismatch int vs none. +;; INFO: Return type mismatch symbol vs none. ;; Used lq/sq (defun-debug ripple-add-debug-sphere @@ -169,7 +169,13 @@ (.add.vf vf6 vf4 vf5 :mask #b111) (.svf (&-> a0-6 quad) vf6) ) - (add-debug-sphere #t 67 s5-0 2048.0 (the-as int #x8000ffff)) + (add-debug-sphere + #t + (bucket-id debug-draw0) + s5-0 + 2048.0 + (new 'static 'rgba :r #xff :g #xff :a #x80) + ) ) (none) ) diff --git a/test/decompiler/reference/engine/gfx/tie/tie-h_REF.gc b/test/decompiler/reference/engine/gfx/tie/tie-h_REF.gc index fa0b4249bc..471618b89b 100644 --- a/test/decompiler/reference/engine/gfx/tie/tie-h_REF.gc +++ b/test/decompiler/reference/engine/gfx/tie/tie-h_REF.gc @@ -86,8 +86,7 @@ ;; definition of type drawable-tree-instance-tie (deftype drawable-tree-instance-tie (drawable-tree) - ((length int16 :offset 6) - (prototypes basic :offset 8) + ((prototypes basic :offset 8) ) :method-count-assert 18 :size-assert #x24 @@ -100,7 +99,7 @@ (format #t "~Tid: ~D~%" (-> obj id)) (format #t "~Tbsphere: ~`vector`P~%" (-> obj bsphere)) (format #t "~Tlength: ~D~%" (-> obj length)) - (format #t "~Tdata[1] @ #x~X~%" (-> obj pad)) + (format #t "~Tdata[1] @ #x~X~%" (-> obj data)) (format #t "~Tprototypes: ~A~%" (-> obj prototypes)) obj ) diff --git a/test/decompiler/reference/engine/math/matrix_REF.gc b/test/decompiler/reference/engine/math/matrix_REF.gc index 11b92f81a0..5ea6198612 100644 --- a/test/decompiler/reference/engine/math/matrix_REF.gc +++ b/test/decompiler/reference/engine/math/matrix_REF.gc @@ -337,9 +337,9 @@ ) ;; definition for function matrix-4x4-inverse! +;; WARN: Bad vector register dependency: vf5 ;; WARN: Bad vector register dependency: vf3 ;; WARN: Bad vector register dependency: vf4 -;; WARN: Bad vector register dependency: vf5 (defun matrix-4x4-inverse! ((dst matrix) (src matrix)) (rlet ((acc :class vf) (Q :class vf) diff --git a/test/decompiler/reference/engine/math/quaternion_REF.gc b/test/decompiler/reference/engine/math/quaternion_REF.gc index a5c1a82dc4..79c5c9d673 100644 --- a/test/decompiler/reference/engine/math/quaternion_REF.gc +++ b/test/decompiler/reference/engine/math/quaternion_REF.gc @@ -525,10 +525,7 @@ ) ) ) - (set! - (-> (the-as (pointer float) (+ (* a2-0 4) (the-as int arg0)))) - (* 0.5 f0-12) - ) + (set! (-> arg0 data a2-0) (* 0.5 f0-12)) (if (!= f0-12 0.0) (set! f0-12 (/ 0.5 f0-12)) ) @@ -553,7 +550,7 @@ ) ) (set! - (-> (the-as (pointer float) (+ (* a3-0 4) (the-as int arg0)))) + (-> arg0 data a3-0) (* (+ (-> @@ -573,7 +570,7 @@ ) ) (set! - (-> (the-as (pointer float) (+ (* v1-1 4) (the-as int arg0)))) + (-> arg0 data v1-1) (* (+ (-> diff --git a/test/decompiler/reference/engine/math/vector-h_REF.gc b/test/decompiler/reference/engine/math/vector-h_REF.gc index a0ee1b7e62..544f8ed81b 100644 --- a/test/decompiler/reference/engine/math/vector-h_REF.gc +++ b/test/decompiler/reference/engine/math/vector-h_REF.gc @@ -172,7 +172,7 @@ ;; definition for method 3 of type vector2h (defmethod inspect vector2h ((obj vector2h)) (format #t "[~8x] ~A~%" obj 'vector2h) - (format #t "~Tdata[2] @ #x~X~%" (-> obj data)) + (format #t "~Tdata[2] @ #x~X~%" (&-> obj x)) (format #t "~Tx: ~D~%" (-> obj x)) (format #t "~Ty: ~D~%" (-> obj y)) obj @@ -216,7 +216,7 @@ ;; definition for method 3 of type vector3h (defmethod inspect vector3h ((obj vector3h)) (format #t "[~8x] ~A~%" obj 'vector3h) - (format #t "~Tdata[2] @ #x~X~%" (-> obj data)) + (format #t "~Tdata[2] @ #x~X~%" (&-> obj x)) (format #t "~Tx: ~D~%" (-> obj x)) (format #t "~Ty: ~D~%" (-> obj y)) (format #t "~Tz: ~D~%" (-> obj z)) @@ -238,7 +238,7 @@ ;; definition for method 3 of type vector2w (defmethod inspect vector2w ((obj vector2w)) (format #t "[~8x] ~A~%" obj 'vector2w) - (format #t "~Tdata[2] @ #x~X~%" (-> obj data)) + (format #t "~Tdata[2] @ #x~X~%" (&-> obj x)) (format #t "~Tx: ~D~%" (-> obj x)) (format #t "~Ty: ~D~%" (-> obj y)) obj @@ -311,9 +311,9 @@ ;; definition of type vector4w-2 (deftype vector4w-2 (structure) - ((data int32 8 :offset-assert 0) + ((data int32 8 :offset-assert 0) (quad uint128 2 :offset 0) - (vector vector4w 2 :offset 0) + (vector vector4w 2 :inline :offset 0) ) :method-count-assert 9 :size-assert #x20 @@ -323,17 +323,17 @@ ;; definition for method 3 of type vector4w-2 (defmethod inspect vector4w-2 ((obj vector4w-2)) (format #t "[~8x] ~A~%" obj 'vector4w-2) - (format #t "~Tdata[8] @ #x~X~%" (-> obj data)) - (format #t "~Tquad[2] @ #x~X~%" (-> obj data)) - (format #t "~Tvector[2] @ #x~X~%" (-> obj data)) + (format #t "~Tdata[8] @ #x~X~%" (-> obj quad)) + (format #t "~Tquad[2] @ #x~X~%" (-> obj quad)) + (format #t "~Tvector[2] @ #x~X~%" (-> obj quad)) obj ) ;; definition of type vector4w-3 (deftype vector4w-3 (structure) - ((data int32 12 :offset-assert 0) + ((data int32 12 :offset-assert 0) (quad uint128 3 :offset 0) - (vector vector4w 3 :offset 0) + (vector vector4w 3 :inline :offset 0) ) :method-count-assert 9 :size-assert #x30 @@ -343,17 +343,17 @@ ;; definition for method 3 of type vector4w-3 (defmethod inspect vector4w-3 ((obj vector4w-3)) (format #t "[~8x] ~A~%" obj 'vector4w-3) - (format #t "~Tdata[12] @ #x~X~%" (-> obj data)) - (format #t "~Tquad[3] @ #x~X~%" (-> obj data)) - (format #t "~Tvector[3] @ #x~X~%" (-> obj data)) + (format #t "~Tdata[12] @ #x~X~%" (-> obj quad)) + (format #t "~Tquad[3] @ #x~X~%" (-> obj quad)) + (format #t "~Tvector[3] @ #x~X~%" (-> obj quad)) obj ) ;; definition of type vector4w-4 (deftype vector4w-4 (structure) - ((data int32 16 :offset-assert 0) + ((data int32 16 :offset-assert 0) (quad uint128 4 :offset 0) - (vector vector4w 4 :offset 0) + (vector vector4w 4 :inline :offset 0) ) :method-count-assert 9 :size-assert #x40 @@ -363,9 +363,9 @@ ;; definition for method 3 of type vector4w-4 (defmethod inspect vector4w-4 ((obj vector4w-4)) (format #t "[~8x] ~A~%" obj 'vector4w-4) - (format #t "~Tdata[16] @ #x~X~%" (-> obj data)) - (format #t "~Tquad[4] @ #x~X~%" (-> obj data)) - (format #t "~Tvector[4] @ #x~X~%" (-> obj data)) + (format #t "~Tdata[16] @ #x~X~%" (-> obj quad)) + (format #t "~Tquad[4] @ #x~X~%" (-> obj quad)) + (format #t "~Tvector[4] @ #x~X~%" (-> obj quad)) obj ) diff --git a/test/decompiler/reference/engine/physics/trajectory_REF.gc b/test/decompiler/reference/engine/physics/trajectory_REF.gc index aab21215fd..a17c3a580c 100644 --- a/test/decompiler/reference/engine/physics/trajectory_REF.gc +++ b/test/decompiler/reference/engine/physics/trajectory_REF.gc @@ -134,7 +134,15 @@ ((f0-1 (* (-> obj time) (/ (+ 1.0 (the float s2-0)) (the float s3-0))))) (TODO-RENAME-9 obj f0-1 s4-0) ) - (add-debug-line #t 68 s5-0 s4-0 (new 'static 'rgba :r #xff :a #x80) #f -1) + (add-debug-line + #t + (bucket-id debug-draw1) + s5-0 + s4-0 + (new 'static 'rgba :r #xff :a #x80) + #f + (the-as rgba -1) + ) ) ) (let ((v0-2 0)) diff --git a/test/decompiler/reference/engine/target/joint-mod-h_REF.gc b/test/decompiler/reference/engine/target/joint-mod-h_REF.gc index 73afb5e7d9..5b027562b6 100644 --- a/test/decompiler/reference/engine/target/joint-mod-h_REF.gc +++ b/test/decompiler/reference/engine/target/joint-mod-h_REF.gc @@ -66,7 +66,7 @@ ;; definition (debug) for function joint-mod-debug-draw ;; INFO: Return type mismatch int vs none. (defun-debug joint-mod-debug-draw ((mod joint-mod)) - (add-debug-matrix #t (bucket-id debug-draw) (-> mod joint bone transform)) + (add-debug-matrix #t (bucket-id debug-draw1) (-> mod joint bone transform)) (let ((v0-1 0)) ) (none) @@ -540,7 +540,7 @@ (if (and (= (-> gp-0 process type) target) (!= (-> gp-0 blend) 0.0)) (add-debug-text-sphere *display-target-marks* - (bucket-id debug-draw) + (bucket-id debug-draw1) (-> gp-0 target) 819.2 "look" @@ -701,7 +701,7 @@ (if (and (= (-> gp-0 process type) target) (!= (-> gp-0 blend) 0.0)) (add-debug-text-sphere *display-target-marks* - (bucket-id debug-draw) + (bucket-id debug-draw1) (-> gp-0 target) 819.2 "look"