diff --git a/decompiler/config/jak2/all-types.gc b/decompiler/config/jak2/all-types.gc index ed55caef67..88efe99c85 100644 --- a/decompiler/config/jak2/all-types.gc +++ b/decompiler/config/jak2/all-types.gc @@ -1096,8 +1096,8 @@ ) (deftype vector4w-2 (structure) - ((data int32 8 :offset-assert 0) - (quad uint128 2 :offset 0) + ((data int32 8 :offset-assert 0 :score -2) + (quad uint128 2 :offset 0 :score -1) (vector vector4w 2 :inline :offset 0) ) :method-count-assert 9 @@ -1106,8 +1106,8 @@ ) (deftype vector4w-3 (structure) - ((data int32 12 :offset-assert 0) - (quad uint128 3 :offset 0) + ((data int32 12 :offset-assert 0 :score -2) + (quad uint128 3 :offset 0 :score -1) (vector vector4w 3 :inline :offset 0) ) :method-count-assert 9 @@ -7452,7 +7452,7 @@ (define-extern *shader-list* pair) (define-extern *edit-shader* texture-id) ;; (define-extern link-texture-by-id function) ;; (function texture-id adgif-shader texture-page-dir-entry) -(define-extern adgif-shader<-texture! (function adgif-shader texture adgif-shader)) ;; +(define-extern adgif-shader<-texture! (function adgif-shader texture adgif-shader)) (define-extern adgif-shader-update! (function adgif-shader texture none)) ;; (define-extern adgif-shader<-texture-with-update! function) ;; (function adgif-shader texture adgif-shader) ;; (define-extern hack-texture function) @@ -7460,7 +7460,7 @@ (define-extern adgif-shader-login-no-remap (function adgif-shader texture)) ;; (define-extern adgif-shader-login-fast function) ;; (function adgif-shader texture) ;; (define-extern adgif-shader-login-no-remap-fast function) ;; (function adgif-shader texture) -(define-extern adgif-shader<-texture-simple! (function adgif-shader texture adgif-shader)) ;; +(define-extern adgif-shader<-texture-simple! (function adgif-shader texture adgif-shader)) (define-extern set-dirty-mask! "First arg is the level name off the [[*level*]]'s `default-level`" (function string int int int none)) @@ -21572,46 +21572,41 @@ ;; debug-sphere ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern make-debug-sphere-table function) ;; (function debug-sphere-table none) -;; (define-extern *debug-sphere-table* object) ;; debug-sphere-table -;; (define-extern add-debug-sphere-from-table function) ;; (function bucket-id vector float rgba none) +(define-extern make-debug-sphere-table (function vector-array float float vector-array)) +(define-extern *debug-sphere-table* (array vector-array)) +(define-extern add-debug-sphere-from-table (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 - (mode symbol :offset-assert 52) ;; guessed by decompiler - (color2 rgba :offset-assert 56) ;; guessed by decompiler + (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 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 + (color font-color :offset-assert 32) (offset vector2h :inline :offset-assert 36) - (str string :offset-assert 40) ;; guessed by decompiler + (str string :offset-assert 40) ) :method-count-assert 9 :size-assert #x2c :flag-assert #x90000002c ) -|# -#| (deftype debug-tracking-thang (basic) ((length int32 :offset-assert 4) (allocated-length int32 :offset-assert 8) @@ -21620,78 +21615,67 @@ :size-assert #xc :flag-assert #x90000000c ) -|# - -#| -(deftype debug-vertex-stats (basic) - () - :method-count-assert 9 - :size-assert #x4b10 - :flag-assert #x900004b10 - ;; Failed to read fields. - ) -|# (define-extern transform-float-point (function vector vector4w vector4w)) -;; (define-extern add-debug-point function) ;; (function symbol bucket-id vector symbol) -;; (define-extern debug-line-clip? function) -;; (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 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 add-debug-point (function symbol bucket-id vector symbol)) +(define-extern debug-line-clip? (function vector vector vector vector symbol)) +(define-extern internal-draw-debug-line (function bucket-id vector vector rgba symbol rgba pointer)) +(define-extern internal-draw-debug-text-3d (function bucket-id string vector font-color vector2h pointer)) +(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-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 (function debug-line)) +(define-extern get-debug-text-3d (function debug-text-3d)) (define-extern debug-reset-buffers (function symbol)) (define-extern debug-draw-buffers (function symbol)) (define-extern add-debug-line (function symbol bucket-id vector vector rgba symbol rgba symbol)) (define-extern add-debug-line2d (function symbol bucket-id vector vector vector symbol)) -;; (define-extern add-debug-box function) ;; (function symbol bucket-id vector vector rgba symbol) -;; (define-extern add-debug-box-with-transform function) +(define-extern add-debug-box (function symbol bucket-id vector vector rgba symbol)) +(define-extern add-debug-box-with-transform (function symbol bucket-id bounding-box matrix rgba symbol)) ;; unsure if arg2 is bounding-box (define-extern add-debug-x (function symbol bucket-id vector rgba symbol)) -;; (define-extern add-debug-cross function) +(define-extern add-debug-cross (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 float rgba symbol)) -(define-extern add-debug-text-sphere (function symbol bucket-id vector float 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) -;; (define-extern add-debug-circle function) ;; (function symbol bucket-id vector float rgba matrix symbol) +(define-extern add-debug-sphere-with-transform (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 symbol bucket-id (inline-array vector) int rgba symbol)) +(define-extern add-debug-line-sphere (function symbol bucket-id vector vector float rgba none)) +(define-extern add-debug-circle (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 float matrix)) -;; (define-extern add-debug-rot-matrix function) ;; (function symbol bucket-id matrix vector matrix) -;; (define-extern add-debug-quaternion function) -;; (define-extern add-debug-cspace function) -;; (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 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 drawable-frag-count function) ;; (function drawable int) -;; (define-extern history-init function) ;; (function pos-history int pos-history) -;; (define-extern history-draw-and-update function) ;; (function pos-history int vector symbol) -;; (define-extern dma-timeout-cam function) ;; (function vector) +(define-extern add-debug-matrix (function symbol bucket-id matrix meters matrix)) +(define-extern add-debug-rot-matrix (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 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 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 int none)) -;; (define-extern *boundary-polygon* object) ;; (inline-array lbvtx) -;; (define-extern init-boundary-regs function) ;; (function none) -;; (define-extern add-boundary-shader function) ;; (function texture-id dma-buffer none) +(define-extern *boundary-polygon* none) ;; (inline-array lbvtx) ;; TODO: figure out what this actually is +(define-extern init-boundary-regs (function none)) +(define-extern add-boundary-shader (function texture-id dma-buffer none)) ;; (define-extern draw-boundary-polygon function) ;; function ;; (define-extern render-boundary-quad function) ;; (function lbvtx dma-buffer none) ;; (define-extern render-boundary-tri function) ;; (function lbvtx dma-buffer none) ;; (define-extern add-debug-bound-internal function) ;; (define-extern add-debug-bound function) -;; (define-extern cpu-delay function) -;; (define-extern qword-read-time function) -;; (define-extern bugfix? function) +(define-extern cpu-delay (function int none)) +(define-extern qword-read-time (function (array uint128) int int)) +(define-extern bugfix? (function symbol)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; history ;; diff --git a/decompiler/config/jak2/hacks.jsonc b/decompiler/config/jak2/hacks.jsonc index 8218ad8ed8..00ed4a68bb 100644 --- a/decompiler/config/jak2/hacks.jsonc +++ b/decompiler/config/jak2/hacks.jsonc @@ -103,6 +103,8 @@ "sign-float", "dma-count-until-done", "(method 11 collide-mesh-cache)", + "cpu-delay", + "qword-read-time", "symlink2", "blerc-a-fragment", @@ -123,6 +125,11 @@ "(method 17 collide-cache)", "(method 16 ocean)", + // unknown instructions + "debug-line-clip?", + // logand with #f arg + "bugfix?", + // "reset-target-tracking", "(anon-function 1 target)", "find-nearest-entity", @@ -219,6 +226,9 @@ "sprite-draw-distorters": [4, 5], + "add-debug-box-with-transform": [0, 3], + "add-debug-line-sphere": [0], + "(method 12 perf-stat)": [0], "(method 11 perf-stat)": [0], "(method 22 gui-control)": [117, 121, 127, 128, 129, 139], @@ -237,7 +247,8 @@ "collide-do-primitives", "moving-sphere-triangle-intersect", "calc-animation-from-spr", - "draw-string-asm", "draw-string", "get-string-length" + "draw-string-asm", "draw-string", "get-string-length", + "init-boundary-regs" ], "mips2c_jump_table_functions": {}, diff --git a/decompiler/config/jak2/label_types.jsonc b/decompiler/config/jak2/label_types.jsonc index ae9cfb5db4..e7ca9ba3de 100644 --- a/decompiler/config/jak2/label_types.jsonc +++ b/decompiler/config/jak2/label_types.jsonc @@ -65,6 +65,16 @@ "sprite": [["L51", "vu-function"]], "sprite-distort": [["L27", "vu-function"]], "sprite-glow": [["L29", "vu-function"]], + "debug": [ + ["L250", "(inline-array vector)", 32], + ["L254", "(inline-array vector)", 3], + ["L253", "(inline-array vector)", 3], + ["L255", "vector2h"], + ["L256", "vector"], + ["L257", "vector"], + ["L258", "vector"], + ["L259", "vector"] + ], "mood-funcs": [ ["L231", "vector"], ["L358", "(pointer uint64)", 1], diff --git a/decompiler/config/jak2/stack_structures.jsonc b/decompiler/config/jak2/stack_structures.jsonc index 65f6bf758b..0197c9d7e4 100644 --- a/decompiler/config/jak2/stack_structures.jsonc +++ b/decompiler/config/jak2/stack_structures.jsonc @@ -174,6 +174,122 @@ [368, "matrix"], [432, "vector"] ], + // debug + "add-debug-point": [ + [16, "vector4w-2"], + [48, "vector"] + ], + "internal-draw-debug-line": [ + [16, "vector4w-2"], + [48, "vector4w-2"], + [80, "vector"], + [96, "vector"] + ], + "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"], + [112, "vector"], + [128, "vector"], + [144, "vector"] + ], + "add-debug-line2d": [ + [16, "vector4w"], + [32, "vector4w"] + ], + "add-debug-box": [ + [16, "vector"], + [32, "vector"] + ], + "add-debug-box-with-transform": [ + [16, ["inline-array", "vector", 8]], + [144, ["inline-array", "vector", 2]], + [176, "vector"] + ], + "add-debug-x": [ + [16, "vector"], + [32, "vector"] + ], + "add-debug-cross": [ + [16, "vector"], + [32, "vector"], + [48, "vector"], + [64, "vector"], + [80, "vector"], + [96, "vector"], + [112, "vector"], + [128, "vector"] + ], + "add-debug-sphere-with-transform": [ + [16, "vector"] + ], + "add-debug-line-sphere": [ + [48, "matrix"], + [112, "matrix"], + [128, "vector"], + [144, "vector"], + [160, "vector"], + [176, "vector"], + [208, "vector"], + [192, "vector"] + ], + "add-debug-circle": [ + [16, "vector"], + [32, "vector"] + ], + "add-debug-vector": [ + [16, "vector"] + ], + "add-debug-quaternion": [ + [16, "matrix"] + ], + "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"] + ], + "add-debug-cursor": [ + [16, "vector"] + ], + "dma-timeout-cam": [ + [16, "vector"], + [32, "matrix"] + ], + // debug-sphere + "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"] + ], + "matrix-3x3-triple-transpose-product": [[16, ["inline-array", "matrix", 3]]], "(method 14 rigid-body)": [[16, "quaternion"]], "(method 19 rigid-body)": [ diff --git a/decompiler/config/jak2/type_casts.jsonc b/decompiler/config/jak2/type_casts.jsonc index c12be45f8c..bb30c4b6ea 100644 --- a/decompiler/config/jak2/type_casts.jsonc +++ b/decompiler/config/jak2/type_casts.jsonc @@ -898,7 +898,10 @@ [20, "s0", "fact-info-enemy"], [12, "s2", "process-drawable"] ], - "joint-mod-look-at-handler": [[[2, 406], "gp", "joint-mod"]], + "joint-mod-look-at-handler": [ + [[2, 406], "gp", "joint-mod"], + [409, "a3", "float"] + ], "real-joint-mod-gun-look-at-handler": [ [1, "v1", "joint-mod"], [2, "v1", "joint-mod"] @@ -913,15 +916,22 @@ "joint-mod-polar-look-at-guts": [ [1, "gp", "joint-mod"], [[1, 334], "gp", "joint-mod"], - [334, "gp", "joint-mod"] + [334, "gp", "joint-mod"], + [338, "a3", "float"] + ], + "joint-mod-world-look-at-handler": [ + [[0, 217], "gp", "joint-mod"], + [220, "a3", "float"] ], - "joint-mod-world-look-at-handler": [[[0, 217], "gp", "joint-mod"]], "joint-mod-rotate-handler": [[[2, 114], "s5", "joint-mod"]], "joint-mod-scale-handler": [[[1, 14], "s5", "joint-mod"]], "joint-mod-joint-set-handler": [[[2, 23], "s4", "joint-mod"]], "joint-mod-joint-set-world-handler": [[[6, 197], "s5", "joint-mod"]], "joint-mod-joint-set*-handler": [[[2, 39], "s5", "joint-mod"]], "joint-mod-joint-set*-world-handler": [[[4, 53], "s5", "joint-mod"]], + "joint-mod-debug-draw": [ + [8, "a3", "float"] + ], "glst-find-node-by-name": [ [6, "s5", "glst-named-node"], [7, "v1", "glst-named-node"] @@ -1406,6 +1416,7 @@ "(method 10 sparticle-launcher)": [[41, "gp", "(array float)"]], "birth-func-texture-group": [[3, "s5", "(pointer int32)"]], "(method 9 sparticle-launch-control)": [[22, "a2", "process-drawable"]], + "(method 10 sparticle-launch-control)": [[42, "a3", "float"]], "execute-part-engine": [ [11, "v1", "connection"], [137, "a3", "vector"] @@ -1426,6 +1437,82 @@ [35, "s3", "pointer"] ], "sp-process-particle-system": [[14, "a1", "vector"]], + + // debug + "add-debug-point": [ + [[35, 39], "a3", "dma-packet"], + [[45, 48], "a3", "gs-gif-tag"], + [[65, 69], "a3", "vector4w-2"], + [[85, 89], "a3", "vector4w-2"], + [[102, 106], "a3", "vector4w-2"], + [[122, 126], "a1", "vector4w-2"], + [[129, 148], "a0", "(pointer uint64)"], + [[151, 154], "a0", "dma-packet"] + ], + "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)"], + [[268, 273], "a0", "dma-packet"] + ], + "internal-draw-debug-text-3d": [ + [[53, 56], "v1", "dma-packet"] + ], + "add-debug-flat-triangle": [ + [[70, 76], "a3", "dma-packet"], + [[79, 85], "a3", "gs-gif-tag"], + [[108, 127], "a3", "(inline-array vector)"], + [[68, 149], "a0", "(pointer uint64)"], + [[150, 155], "a0", "dma-packet"] + ], + "add-debug-line2d": [ + [[60, 64], "a2", "dma-packet"], + [[70, 73], "a2", "gs-gif-tag"], + [[78, 81], "a2", "vector4w-2"], + [[86, 89], "a2", "vector4w-2"], + [[97, 111], "a0", "(pointer uint64)"], + [[114, 117], "v1", "dma-packet"] + ], + "add-debug-rot-matrix": [ + [[9, 12], "t0", "float"], + [[17, 20], "t0", "float"], + [[22, 29], "t0", "float"] + ], + "add-debug-cspace": [ + [[4, 6], "a3", "float"] + ], + "add-debug-points": [ + [[52, 57], "a3", "rgba"] + ], + "debug-percent-bar": [ + [[44, 49], "v1", "dma-packet"] + ], + "debug-pad-display": [ + [[72, 77], "v1", "dma-packet"] + ], + "add-debug-light": [ + [[17, 20], "t0", "float"] + ], + "drawable-frag-count": [ + [[14, 20], "s5", "drawable-group"] + ], + "add-debug-cursor": [ + [[35, 40], "v1", "dma-packet"] + ], + "add-boundary-shader": [ + [[6, 12], "a0", "gs-gif-tag"], + [[14, 31], "s5", "adgif-shader"] + ], + + // debug-sphere + "add-debug-sphere-from-table": [ + [[38, 41], "v1", "vector"], + [[55, 59], "s0", "(inline-array vector)"] + ], + "drawable-load": [[[25, 28], "s5", "drawable"]], "art-load": [[[13, 16], "s5", "art"]], "art-group-load-check": [[[43, 53], "s3", "art-group"]], diff --git a/decompiler/config/jak2/var_names.jsonc b/decompiler/config/jak2/var_names.jsonc index 33e27d2484..e6eddaf686 100644 --- a/decompiler/config/jak2/var_names.jsonc +++ b/decompiler/config/jak2/var_names.jsonc @@ -272,6 +272,340 @@ "args": ["search", "fallback"] }, + // debug + "transform-float-point": { + "args": ["in", "out"] + }, + "add-debug-point": { + "args": ["enable-draw", "bucket", "pt"], + "vars": { + "a1-2": "pt-copy", + "v1-11": "buf", + "a2-1": "tag-start", + "a3-20": "tag-end", + "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"], + "a0-6": ["a0-6", "dma-packet"], + "a0-5": ["a0-5", "(pointer uint64)"] + } + }, + "internal-draw-debug-line": { + "args": ["bucket", "start", "end", "start-color", "mode", "end-color"], + "vars": { + "a0-2": "buf", + "s1-0": "var-start-color", + "s2-0": "var-mode", + "s5-0": "var-end-color", + "sv-112": "var-end", + "v1-37": "buf2", + "a2-2": "tag-start", + "a3-17": "tag-end", + "a3-2": ["pkt1", "dma-packet"], + "a3-4": ["giftag", "gs-gif-tag"], + "a1-50": ["a1-50", "(inline-array vector4w-2)"], + "a0-29": ["pkt2", "dma-packet"] + } + }, + "internal-draw-debug-text-3d": { + "args": ["bucket", "text", "position", "color", "screen-offset"], + "vars": { + "v1-12": ["pkt", "dma-packet"], + "s5-0": "tag-start", + "a3-4": "tag-end", + "s2-0": "screen-pos", + "s3-0": "buf", + "a2-2": "font-ctx" + } + }, + "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"], + "vars": { + "v1-16": "buf", + "a2-1": "tag-start", + "a3-7": "tag-end", + "a3-1": ["pkt1", "dma-packet"], + "a3-3": ["giftag", "gs-gif-tag"], + "a3-5": ["a3-5", "(inline-array vector)"], + "a0-13": ["pkt2", "dma-packet"] + } + }, + "debug-draw-buffers": { + "vars": { + "gp-0": "i", + "gp-1": "j", + "v1-1": "line", + "v1-8": "text-3d" + } + }, + "add-debug-line": { + "args": ["enable", "bucket", "start", "end", "start-color", "mode", "end-color"], + "vars": { + "v1-2": "line" + } + }, + "add-debug-line2d": { + "args": ["enable", "bucket", "start", "end", "color"], + "vars": { + "a2-3": ["a2-3", "dma-packet"], + "a2-5": ["giftag", "gs-gif-tag"], + "a2-7": ["v0", "vector4w-2"], + "a2-9": ["v1", "vector4w-2"], + "a0-18": ["a0-18", "(pointer uint64)"], + "s5-0": "tag-start", + "a3-11": "tag-end", + "v1-12": ["v1-12", "dma-packet"], + "s2-0": "p0", + "v1-9": "p1", + "s4-0": "buf" + } + }, + "add-debug-box": { + "args": ["enable", "bucket", "c1", "c2", "color"], + "vars": { + "s5-0": "p0", + "s1-0": "p1" + } + }, + "add-debug-box-with-transform": { + "args": ["enable", "bucket", "box", "trans", "color"], + "vars": { + "s4-0": "points", + "s2-0": "corners", + "s1-0": "point", + "s0-0": "i" + } + }, + "add-debug-x": { + "args": ["enable", "bucket", "position", "color"], + "vars": { + "s3-0": "p0", + "s2-0": "p1" + } + }, + "add-debug-cross": { + "args": ["enable", "bucket", "position", "radius"], + "vars": { + "s4-0": "p0", + "s3-0": "p1" + } + }, + "add-debug-sphere-with-transform": { + "args": ["enable", "bucket", "position", "radius", "trans", "color"], + "vars": { + "a2-1": "position-transformed" + } + }, + "add-debug-sphere": { + "args": ["enable", "bucket", "position", "radius", "color"] + }, + "add-debug-text-sphere": { + "args": ["enable", "bucket", "position", "radius", "text", "color"] + }, + "add-debug-text-3d": { + "args": ["enable", "bucket", "text", "position", "color", "screen-offset"] + }, + "add-debug-spheres": { + "args": ["enable", "bucket", "origins", "count", "color"], + "vars": { + "s3-0": "i", + "s4-0": "origin" + } + }, + "add-debug-line-sphere": { + "args": ["enable", "bucket", "position", "forward", "arg4", "color"], + "vars": { + "sv-16": "var-bucket", + "sv-24": "var-position", + "sv-28": "var-forward", + "sv-32": "var-arg4", + "sv-36": "var-color", + "gp-0": "mat-forward", + "s5-0": "mat-down", + "sv-112": "mat", + "sv-116": "forward-length", + "s0-0": "i" + } + }, + "add-debug-circle": { + "args": ["enable", "bucket", "position", "radius", "color", "orientation"], + "vars": { + "s1-0": "line-start", + "s0-0": "line-end", + "sv-48": "i", + "f30-0": "angle" + } + }, + "add-debug-vector": { + "args": ["enable", "bucket", "position", "direction", "length", "color"], + "vars": { + "v1-2": "line-end" + } + }, + "add-debug-matrix": { + "args": ["enable", "bucket", "mat", "line-length"] + }, + "add-debug-rot-matrix": { + "args": ["enable", "bucket", "mat", "position"] + }, + "add-debug-quaternion": { + "args": ["enable", "bucket", "position", "quat"], + "vars": { + "a2-1": "mat" + } + }, + "add-debug-cspace": { + "args": ["enable", "bucket", "csp"] + }, + "add-debug-yrot-vector": { + "args": ["enable", "bucket", "position", "angle", "line-length", "color"], + "vars": { + "sv-32": "var-angle", + "s0-0": "var-line-length", + "s3-0": "var-color", + "s1-0": "line-start" + } + }, + "add-debug-arc": { + "args": ["enable", "bucket", "position", "start-angle", "end-angle", "radius", "color", "orientation"], + "vars": { + "f30-0": "angle", + "sv-80": "i", + "sv-48": "line-start", + "sv-64": "line-end" + } + }, + "add-debug-curve": { + "args": ["enable", "bucket", "cverts", "num-cverts", "knots", "num-knots", "color"], + "vars": { + "sv-80": "i", + "s0-0": "p0", + "sv-48": "p1", + "sv-64": "iterations" + } + }, + "add-debug-curve2": { + "args": ["enable", "bucket", "curve", "color", "arg4"] + }, + "add-debug-points": { + "args": ["enable", "bucket", "points", "num-points", "color", "y-override", "highlight"], + "vars": { + "s0-0": "i", + "sv-96": "position" + } + }, + "debug-percent-bar": { + "args": ["enable", "bucket", "x", "y", "percentage", "color", "width", "height"], + "vars": { + "s0-0": "buf", + "s5-0": "tag-start", + "a3-3": "tag-end", + "v1-9": ["pkt", "dma-packet"] + } + }, + "debug-pad-display": { + "args": ["pad"], + "vars": { + "gp-0": "stick-history", + "v1-0": "i", + "s5-1": "j", + "s3-0": "buf", + "s4-0": "tag-start", + "a3-1": "tag-end", + "v1-16": ["pkt", "dma-packet"] + } + }, + "add-debug-light": { + "args": ["enable", "bucket", "light", "position", "text"], + "vars": { + "s1-1": "color-rgba", + "s2-0": "sphere-pos" + } + }, + "add-debug-lights": { + "args": ["enable", "bucket", "lights", "position"] + }, + "drawable-frag-count": { + "args": ["drbl"], + "vars": { + "gp-0": "count", + "s4-0": "i" + } + }, + "history-init": { + "args": ["history", "num-points"] + }, + "history-draw-and-update": { + "args": ["history", "draw", "pos"], + "vars": { + "s5-1": "i" + } + }, + "dma-timeout-cam": { + "vars": { + "a0-0": "pos", + "a1-0": "rot" + } + }, + "display-file-info": { + "vars": { + "gp-0": "i", + "v1-7": "level", + "s5-0": "bsp" + } + }, + "add-debug-cursor": { + "args": ["enable", "bucket", "x", "y", "arg4"], + "vars": { + "s4-0": "buf", + "s5-0": "tag-start", + "a3-2": "tag-end", + "v1-9": ["pkt", "dma-packet"] + } + }, + "add-boundary-shader": { + "args": ["tex-id", "buf"], + "vars": { + "a1-1": "tex", + "a0-1": ["giftag", "gs-gif-tag"], + "s5-0": ["shader", "adgif-shader"] + } + }, + + // debug-sphere + "make-debug-sphere-table": { + "args": ["points", "h-lines", "v-lines"], + "vars": { + "s1-0": "v-line", + "sv-112": "h-line", + "s5-0": "num-points", + "f30-0": "scale", + "s2-0": "offset", + "s0-0": "current", + "sv-80": "next-hz", + "sv-96": "next-vt" + } + }, + "add-debug-sphere-from-table": { + "args": ["bucket", "position", "radius", "color", "table-idx"], + "vars": { + "sv-32": "sphere-points", + "s0-0": ["points", "(inline-array vector)"], + "s2-1": "point-1", + "s1-1": "point-2", + "sv-36": "point-3" + } + }, + "(method 10 cam-setting-data)": { "vars": { "v1-5": ["v1-5", "handle"], diff --git a/goal_src/jak2/engine/anim/joint-mod-h.gc b/goal_src/jak2/engine/anim/joint-mod-h.gc index 139669c696..1fa33827ee 100644 --- a/goal_src/jak2/engine/anim/joint-mod-h.gc +++ b/goal_src/jak2/engine/anim/joint-mod-h.gc @@ -126,7 +126,7 @@ (defun-debug joint-mod-debug-draw ((arg0 joint-mod)) - (add-debug-matrix #t (bucket-id bucket-318) (-> arg0 joint bone transform) 8192.0) + (add-debug-matrix #t (bucket-id bucket-318) (-> arg0 joint bone transform) (meters 2.0)) 0 (none) ) diff --git a/goal_src/jak2/engine/anim/joint-mod.gc b/goal_src/jak2/engine/anim/joint-mod.gc index b3cd35c927..cc865dfb0b 100644 --- a/goal_src/jak2/engine/anim/joint-mod.gc +++ b/goal_src/jak2/engine/anim/joint-mod.gc @@ -968,7 +968,7 @@ *display-target-marks* (bucket-id bucket-318) (-> gp-0 target) - 819.2 + (meters 0.2) "look" (new 'static 'rgba :r #xff :g #xff :a #x80) ) @@ -1092,7 +1092,7 @@ *display-target-marks* (bucket-id bucket-318) (-> gp-0 target) - 819.2 + (meters 0.2) "look" (new 'static 'rgba :r #xff :g #xff :a #x80) ) @@ -1204,7 +1204,7 @@ *display-target-marks* (bucket-id bucket-318) (-> gp-0 target) - 819.2 + (meters 0.2) "look" (new 'static 'rgba :r #xff :g #xff :a #x80) ) diff --git a/goal_src/jak2/engine/debug/debug-h.gc b/goal_src/jak2/engine/debug/debug-h.gc index 854c425cc2..32b8f29520 100644 --- a/goal_src/jak2/engine/debug/debug-h.gc +++ b/goal_src/jak2/engine/debug/debug-h.gc @@ -11,13 +11,12 @@ (define-extern transform-float-point (function vector vector4w vector4w)) (define-extern add-debug-line (function symbol bucket-id vector vector rgba symbol rgba symbol)) ;; NOTE - for sparticle-launcher -(define-extern add-debug-sphere (function symbol bucket-id vector float rgba symbol)) +(define-extern add-debug-sphere (function symbol bucket-id vector meters rgba symbol)) (define-extern add-debug-line2d (function symbol bucket-id vector vector vector symbol)) -(define-extern add-debug-sphere (function symbol bucket-id vector float rgba symbol)) (define-extern add-debug-text-3d (function symbol bucket-id string vector font-color vector2h symbol)) -(define-extern add-debug-text-sphere (function symbol bucket-id vector float string rgba symbol)) +(define-extern add-debug-text-sphere (function symbol bucket-id vector meters string rgba symbol)) ;; DECOMP BEGINS @@ -77,4 +76,4 @@ (define *color-dark-yellow* (new 'static 'rgba :r #x80 :g #x80 :a #x80)) (define *color-orange* (new 'static 'rgba :r #xff :g #x80 :a #x80)) -(define-extern add-debug-matrix (function symbol bucket-id matrix float matrix)) +(define-extern add-debug-matrix (function symbol bucket-id matrix meters matrix)) diff --git a/goal_src/jak2/engine/debug/debug-sphere.gc b/goal_src/jak2/engine/debug/debug-sphere.gc index c5743cecc8..374816f119 100644 --- a/goal_src/jak2/engine/debug/debug-sphere.gc +++ b/goal_src/jak2/engine/debug/debug-sphere.gc @@ -5,5 +5,108 @@ ;; name in dgo: debug-sphere ;; dgos: ENGINE, GAME +;; Functions for drawing wireframe spheres made up of debug lines. +;; Do not call these functions unless *debug-segment* is set. + ;; DECOMP BEGINS +(defun make-debug-sphere-table ((points vector-array) (h-lines float) (v-lines float)) + "Fills points with positions that make a wireframe sphere made of the given number of horizontal and vertical lines. + The points array is expected to have a capacity of at least (h-lines * v-lines * 3). + Both h-lines and v-lines should be whole numbers." + (local-vars (next-hz vector) (next-vt vector) (h-line int)) + (let ((offset (new-stack-vector0)) + (scale 1.0) + (num-points 0) + ) + (set-vector! offset 0.0 0.0 0.0 1.0) + (dotimes (v-line (the int v-lines)) + (let ((f28-0 (* scale (sin (* (the float v-line) (/ 32768.0 v-lines))))) + (f26-0 (* scale (sin (* (the float (+ v-line 1)) (/ 32768.0 v-lines))))) + (current (new-stack-vector0)) + ) + (set! next-hz (new 'stack-no-clear 'vector)) + (set! (-> next-hz quad) (the-as uint128 0)) + (set! next-vt (new 'stack-no-clear 'vector)) + (set! (-> next-vt quad) (the-as uint128 0)) + (set! (-> current y) (+ (-> offset y) (* (cos (* (the float v-line) (/ 32768.0 v-lines))) scale))) + (set! (-> next-hz y) (-> current y)) + (set! (-> next-vt y) (+ (-> offset y) (* (cos (* (the float (+ v-line 1)) (/ 32768.0 v-lines))) scale))) + (set! h-line 0) + (while (< h-line (the int h-lines)) + (set! (-> current x) (+ (-> offset x) (* (cos (* (the float h-line) (/ 65536.0 h-lines))) f28-0))) + (set! (-> current z) (+ (-> offset z) (* (sin (* (the float h-line) (/ 65536.0 h-lines))) f28-0))) + (set! (-> next-hz x) (+ (-> offset x) (* (cos (* (the float (+ h-line 1)) (/ 65536.0 h-lines))) f28-0))) + (set! (-> next-hz z) (+ (-> offset z) (* (sin (* (the float (+ h-line 1)) (/ 65536.0 h-lines))) f28-0))) + (set! (-> next-vt x) (+ (-> offset x) (* (cos (* (the float h-line) (/ 65536.0 h-lines))) f26-0))) + (set! (-> next-vt z) (+ (-> offset z) (* (sin (* (the float h-line) (/ 65536.0 h-lines))) f26-0))) + (set! (-> points data num-points quad) (-> current quad)) + (set! (-> points data (+ num-points 1) quad) (-> next-hz quad)) + (set! (-> points data (+ num-points 2) quad) (-> next-vt quad)) + (+! num-points 3) + (set! h-line (+ h-line 1)) + ) + ) + ) + (set! (-> points length) num-points) + ) + points + ) + +(when *debug-segment* +;; A table of 10 debug spheres whose vertical/horizontal line counts range from 0-9 depending on the index. +;; For example, the fifth element is a debug sphere whose v-lines and h-lines were set to 4. +;; +;; Each element is populated on demand from calling add-debug-sphere-from-table and as such this table +;; shouldn't be used directly. +(define *debug-sphere-table* (the-as (array vector-array) (new 'debug 'boxed-array vector-array 10))) +) + +(defun add-debug-sphere-from-table ((bucket bucket-id) (position vector) (radius meters) (color rgba) (table-idx int)) + "Adds a debug sphere to a bucket. + The table-idx specifies the resolution of the sphere and must be >= 0 and <= 9, where 9 would specify + the highest resolution available and 0 would draw nothing." + (local-vars (sphere-points vector-array) (point-3 vector)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (if (zero? (-> *debug-sphere-table* table-idx)) + (set! (-> *debug-sphere-table* table-idx) (make-debug-sphere-table + (new 'debug 'vector-array (* (* 3 table-idx) table-idx)) + (the float table-idx) + (the float table-idx) + ) + ) + ) + (set! sphere-points (-> *debug-sphere-table* table-idx)) + (set! point-3 (the-as vector (new-stack-vector0))) + (let ((point-1 (new-stack-vector0)) + (point-2 (new-stack-vector0)) + (points (-> sphere-points data)) + ) + (.lvf vf1 (&-> position quad)) + (.mov vf2 radius) + (countdown (s4-1 (/ (-> sphere-points length) 3)) + (.lvf vf3 (&-> points 0 quad)) + (.lvf vf4 (&-> points 1 quad)) + (.lvf vf5 (&-> points 2 quad)) + (set! points (the-as (inline-array vector) (-> points 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 (&-> point-1 quad) vf3) + (.svf (&-> point-2 quad) vf4) + (.svf (&-> point-3 quad) vf5) + (add-debug-line #t bucket point-1 point-2 color #f (the-as rgba -1)) + (add-debug-line #t bucket point-1 point-3 color #f (the-as rgba -1)) + ) + ) + ) + (none) + ) diff --git a/goal_src/jak2/engine/debug/debug.gc b/goal_src/jak2/engine/debug/debug.gc index 9bcf4b10a6..8b7b18350f 100644 --- a/goal_src/jak2/engine/debug/debug.gc +++ b/goal_src/jak2/engine/debug/debug.gc @@ -5,11 +5,1862 @@ ;; name in dgo: debug ;; dgos: ENGINE, GAME -(defun 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 (font-color default) (the-as vector2h #f)) - #f - ) +;; This file contains functions for debug drawing. +;; In general, the 3d functions draw using the camera and the 2d functions draw in screen coordinates. +;; Most functions take a boolean as their first argument. If the boolean is set to #f, it will skip drawing the point. + +(define-extern draw-string (function string dma-buffer font-context draw-string-result)) +(define-extern debug-set-camera-pos-rot! (function vector matrix vector)) +(define-extern lookup-texture-by-id (function texture-id texture)) +(define-extern adgif-shader<-texture-simple! (function adgif-shader texture adgif-shader)) ;; DECOMP BEGINS +(defun transform-float-point ((in vector) (out vector4w)) + "Transform point in and store the result in out. + This uses the cached vf register transformation matrix + Note that the input/output order of the arguments is swapped from usual" + (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 (&-> in 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 (&-> out quad) vf5) + out + ) + ) + + +;;;;;;;;;;;;;;;;;; +;; Debug Draw +;;;;;;;;;;;;;;;;;; + +;; All of these functions are super slow and probably very old. +;; They do a DMA packet per thing drawn. + +(defun-debug add-debug-point ((enable-draw symbol) (bucket bucket-id) (pt vector)) + "Draw a point. + The point is actually a pretty large square with some weird rgb gradient." + (if (not enable-draw) + (return #f) + ) + (let ((s5-0 (new 'stack 'vector4w-2)) + (pt-copy (new 'stack-no-clear 'vector)) + ) + (set! (-> pt-copy quad) (-> pt quad)) + (set! (-> pt-copy w) 1.0) + (when (transform-point-qword! (the-as vector4w (-> s5-0 vector)) pt-copy) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (let ((a0-5 (the-as (pointer uint64) (-> buf base)))) + (let* ((a1-3 buf) + (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 buf) + (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) + (set! (-> s5-0 vector 0 y) (the-as int (+ (-> s5-0 vector 0 y) 288))) + (let* ((a1-11 buf) + (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)) + ) + (set! (-> s5-0 vector 0 x) (the-as int (+ (-> s5-0 vector 0 x) -256))) + (set! (-> s5-0 vector 0 y) (the-as int (+ (-> s5-0 vector 0 y) -288))) + (set! (-> s5-0 vector 1 x) 128) + (set! (-> s5-0 vector 1 y) 255) + (let* ((a1-18 buf) + (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)) + ) + (set! (-> s5-0 vector 0 x) (the-as int (+ (-> s5-0 vector 0 x) 512))) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 255) + (let* ((a1-23 buf) + (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)) + ) + (set! (-> s5-0 vector 0 x) (the-as int (+ (-> s5-0 vector 0 x) -256))) + (set! (-> s5-0 vector 0 y) (the-as int (+ (-> s5-0 vector 0 y) -288))) + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (let* ((a3-10 buf) + (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-5)) (the-as int (-> buf base)))) 16))) + (cond + ((nonzero? a3-14) + (logior! (-> a0-5 0) (shr (shl a3-14 48) 48)) + (logior! (-> a0-5 1) (shl (shr (shl a3-14 48) 48) 32)) + ) + (else + (set! (-> buf base) a0-5) + ) + ) + ) + ) + (let ((tag-end (-> buf base))) + (let ((a0-6 (the-as dma-packet (-> buf base)))) + (set! (-> a0-6 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> a0-6 vif0) (new 'static 'vif-tag)) + (set! (-> a0-6 vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer a0-6) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + #f + ) + +(define-extern debug-line-clip? (function vector vector vector vector symbol)) + +(defun-debug internal-draw-debug-line ((bucket bucket-id) (start vector) (end vector) (start-color rgba) (mode symbol) (end-color rgba)) + "Draw a debug line from p0 to p1. Mode can be: + 'fade, 'fade-depth, or #f. + end-color can be -1 to just use the same color. + " + (local-vars (sv-128 vector) (sv-144 vector)) + (let ((var-start-color start-color) + (var-mode mode) + (var-end-color end-color) + ) + (let ((buf (-> *display* frames (-> *display* on-screen) debug-buf))) + (if (< (the-as uint (shr (+ (&- (-> buf end) (the-as uint (-> buf base))) 15) 4)) (the-as uint #x8000)) + (return (the-as pointer #f)) + ) + ) + (if (or (= var-end-color -1) (= var-end-color (new 'static 'rgba :r #xff :g #xff :b #xff :a #xff))) + (set! var-end-color var-start-color) + ) + (case var-mode + (('fade) + (set! var-end-color (new 'static 'rgba + :r (shr (-> var-end-color r) 1) + :g (shr (-> var-end-color g) 1) + :b (shr (-> var-end-color b) 1) + :a (-> var-end-color 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)) + (when (debug-line-clip? sv-128 sv-144 start end) + (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) + ) + (let* ((buf2 (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf2 base)) + ) + (let ((a0-28 (the-as (pointer uint64) (-> buf2 base)))) + (let* ((pkt1 (the-as dma-packet (-> buf2 base)))) + (set! (-> pkt1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt1 vif0) (new 'static 'vif-tag)) + (set! (-> pkt1 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> buf2 base) (&+ (the-as pointer pkt1) 16)) + ) + (let* ((giftag (the-as gs-gif-tag (-> buf2 base)))) + (set! (-> giftag 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! (-> giftag 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! (-> buf2 base) (&+ (the-as pointer giftag) 16)) + ) + (case var-mode + (('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 (-> var-start-color r)) f0-3))) + (set! (-> s3-0 vector 0 y) (the int (* (the float (-> var-start-color g)) f0-3))) + (set! (-> s3-0 vector 0 z) (the int (* (the float (-> var-start-color b)) f0-3))) + ) + (set! (-> s3-0 vector 0 w) (the-as int (-> var-start-color a))) + ) + (else + (set! (-> s3-0 vector 0 x) (the-as int (-> var-start-color r))) + (set! (-> s3-0 vector 0 y) (the-as int (-> var-start-color g))) + (set! (-> s3-0 vector 0 z) (the-as int (-> var-start-color b))) + (set! (-> s3-0 vector 0 w) (the-as int (-> var-start-color a))) + ) + ) + (cond + ((= var-mode '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 (-> var-end-color r)) f0-7))) + (set! (-> s3-0 vector 1 y) (the int (* (the float (-> var-end-color g)) f0-7))) + (set! (-> s3-0 vector 1 z) (the int (* (the float (-> var-end-color b)) f0-7))) + ) + (set! (-> s3-0 vector 1 w) (the-as int (-> var-end-color a))) + ) + (else + (set! (-> s3-0 vector 1 x) (the-as int (-> var-end-color r))) + (set! (-> s3-0 vector 1 y) (the-as int (-> var-end-color g))) + (set! (-> s3-0 vector 1 z) (the-as int (-> var-end-color b))) + (set! (-> s3-0 vector 1 w) (the-as int (-> var-end-color a))) + ) + ) + (set! (-> s4-0 vector 0 z) (the-as int (+ (-> s4-0 vector 0 z) -8192))) + (set! (-> s4-0 vector 1 z) (the-as int (+ (-> s4-0 vector 1 z) -8192))) + (let* ((a1-50 (the-as (inline-array vector4w-2) (-> buf2 base)))) + (set! (-> a1-50 0 vector 0 quad) (-> s3-0 vector 0 quad)) + (set! (-> a1-50 0 vector 1 quad) (-> s4-0 vector 0 quad)) + (set! (-> a1-50 1 vector 0 quad) (-> s3-0 vector 1 quad)) + (set! (-> a1-50 1 vector 1 quad) (-> s4-0 vector 1 quad)) + (set! (-> buf2 base) (&+ (the-as pointer a1-50) 64)) + ) + (let ((a3-11 (/ (the-as int (+ (- -16 (the-as int a0-28)) (the-as int (-> buf2 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! (-> buf2 base) a0-28) + ) + ) + ) + ) + (let ((tag-end (-> buf2 base))) + (let ((pkt2 (the-as dma-packet (-> buf2 base)))) + (set! (-> pkt2 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt2 vif0) (new 'static 'vif-tag)) + (set! (-> pkt2 vif1) (new 'static 'vif-tag)) + (set! (-> buf2 base) (&+ (the-as pointer pkt2) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + ) + ) + ) + +(defun-debug internal-draw-debug-text-3d ((bucket bucket-id) (text string) (position vector) (color font-color) (screen-offset vector2h)) + "Draw text at the given location (in 3D), with a 2D offset." + (let ((screen-pos (new 'stack-no-clear 'vector4w))) + (set! (-> screen-pos quad) (the-as uint128 0)) + (when (transform-point-qword! screen-pos position) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (let ((font-ctx (new + 'stack + 'font-context + *font-default-matrix* + (the-as int (+ (-> screen-offset x) -1792 (/ (-> screen-pos x) 16))) + (the-as int (+ (-> screen-offset y) -1855 (/ (-> screen-pos y) 16))) + 0.0 + color + (font-flags shadow kerning) + ) + ) + ) + (let ((v1-10 font-ctx)) + (set! (-> v1-10 origin z) (the float (/ (-> screen-pos z) 16))) + ) + (draw-string text buf font-ctx) + ) + (let ((tag-end (-> buf base))) + (let ((pkt (the-as dma-packet (-> buf base)))) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt vif0) (new 'static 'vif-tag)) + (set! (-> pkt vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + ) + +(defun-debug add-debug-outline-triangle ((enable symbol) (bucket bucket-id) (p0 vector) (p1 vector) (p2 vector) (color rgba)) + "Draw outline of a triangle using lines." + (when enable + (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, with length of 1 meter." + (when enable + (let ((s4-0 (new 'stack-no-clear 'vector)) + (s3-0 (vector-3pt-cross! (new 'stack-no-clear 'vector) p0 p1 p2)) + ) + (vector-float/! s3-0 s3-0 (* 0.00024414062 (vector-length s3-0))) + (vector+! s4-0 p0 p1) + (vector+! s4-0 s4-0 p2) + (vector-float/! s4-0 s4-0 3.0) + (vector+! s3-0 s3-0 s4-0) + (add-debug-line #t bucket s4-0 s3-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 triangle with flat shading" + (if (not enable) + (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) (-> p0 quad)) + (set! (-> s2-0 quad) (-> p1 quad)) + (set! (-> s1-0 quad) (-> p2 quad)) + (set! (-> a1-3 w) 1.0) + (set! (-> s2-0 w) 1.0) + (set! (-> s1-0 w) 1.0) + (when (and (transform-point-qword! (-> s5-0 vector 0) a1-3) + (transform-point-qword! (-> s5-0 vector 1) s2-0) + (transform-point-qword! (-> s5-0 vector 2) s1-0) + ) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (let ((a0-12 (the-as (pointer uint64) (-> buf base)))) + (let* ((pkt1 (the-as dma-packet (-> buf base)))) + (set! (-> pkt1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt1 vif0) (new 'static 'vif-tag)) + (set! (-> pkt1 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> buf base) (&+ (the-as pointer pkt1) 16)) + ) + (let* ((giftag (the-as gs-gif-tag (-> buf base)))) + (set! (-> giftag 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! (-> giftag 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! (-> buf base) (&+ (the-as pointer giftag) 16)) + ) + (set! (-> s4-0 vector 0 x) (the-as int (-> color r))) + (set! (-> s4-0 vector 0 y) (the-as int (-> color g))) + (set! (-> s4-0 vector 0 z) (the-as int (-> color b))) + (set! (-> s4-0 vector 0 w) (the-as int (-> color a))) + (set! (-> s5-0 vector 0 z) (the-as int (+ (-> s5-0 vector 0 z) -8192))) + (set! (-> s5-0 vector 1 z) (the-as int (+ (-> s5-0 vector 1 z) -8192))) + (set! (-> s5-0 vector 2 z) (the-as int (+ (-> s5-0 vector 2 z) -8192))) + (let* ((a3-5 (the-as (inline-array vector) (-> buf 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! (-> buf base) (&+ (the-as pointer a3-5) 96)) + ) + (let ((a1-25 (/ (the-as int (+ (- -16 (the-as int a0-12)) (the-as int (-> buf base)))) 16))) + (cond + ((nonzero? a1-25) + (logior! (-> a0-12 0) (shr (shl a1-25 48) 48)) + (logior! (-> a0-12 1) (shl (shr (shl a1-25 48) 48) 32)) + ) + (else + (set! (-> buf base) a0-12) + ) + ) + ) + ) + (let ((tag-end (-> buf base))) + (let ((pkt2 (the-as dma-packet (-> buf base)))) + (set! (-> pkt2 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt2 vif0) (new 'static 'vif-tag)) + (set! (-> pkt2 vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt2) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + #f + ) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Buffered debug draw +;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; Some of the debug draw stuff just adds a line to a list of lines to draw. +;; This is used when pausing - the actual calls to debug-draw-line won't happen, but +;; we won't clear the debug draw buffer so they will still be drawn. + +(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 + ) + +(defmethod inspect debug-line ((obj debug-line)) + (when (not obj) + (set! obj obj) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" obj 'debug-line) + (format #t "~1Tflags: ~D~%" (-> obj flags)) + (format #t "~1Tbucket: ~D~%" (-> obj bucket)) + (format #t "~1Tv1: #~%" (-> obj v1)) + (format #t "~1Tv2: #~%" (-> obj v2)) + (format #t "~1Tcolor: ~D~%" (-> obj color)) + (format #t "~1Tmode: ~A~%" (-> obj mode)) + (format #t "~1Tcolor2: ~D~%" (-> obj color2)) + (label cfg-4) + obj + ) + +(deftype debug-text-3d (structure) + ((flags int32 :offset-assert 0) + (bucket bucket-id :offset-assert 4) + (pos vector :inline :offset-assert 16) + (color font-color :offset-assert 32) + (offset vector2h :inline :offset-assert 36) + (str string :offset-assert 40) + ) + :method-count-assert 9 + :size-assert #x2c + :flag-assert #x90000002c + ) + +(defmethod inspect debug-text-3d ((obj debug-text-3d)) + (when (not obj) + (set! obj obj) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" obj 'debug-text-3d) + (format #t "~1Tflags: ~D~%" (-> obj flags)) + (format #t "~1Tbucket: ~D~%" (-> obj bucket)) + (format #t "~1Tpos: #~%" (-> obj pos)) + (format #t "~1Tcolor: ~D~%" (-> obj color)) + (format #t "~1Toffset: #~%" (-> obj offset)) + (format #t "~1Tstr: ~A~%" (-> obj str)) + (label cfg-4) + obj + ) + +(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 + ) + +(defmethod inspect debug-tracking-thang ((obj debug-tracking-thang)) + (when (not obj) + (set! obj obj) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" obj (-> obj type)) + (format #t "~1Tlength: ~D~%" (-> obj length)) + (format #t "~1Tallocated-length: ~D~%" (-> obj allocated-length)) + (label cfg-4) + obj + ) + +(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 debug-line from the list." + (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 debug text 3d from the list." + (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 () + "Clear all allocated debug things" + (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 debug lines and debug text." + (dotimes (i (-> *debug-lines-trk* length)) + (let ((line (-> *debug-lines* i))) + (internal-draw-debug-line + (-> line bucket) + (-> line v1) + (-> line v2) + (-> line color) + (-> line mode) + (-> line color2) + ) + ) + ) + (dotimes (j (-> *debug-text-3d-trk* length)) + (let ((text-3d (-> *debug-text-3ds* j))) + (internal-draw-debug-text-3d + (-> text-3d bucket) + (-> text-3d str) + (-> text-3d pos) + (-> text-3d color) + (-> text-3d offset) + ) + ) + ) + #f + ) + +(defun-debug add-debug-line ((enable symbol) + (bucket bucket-id) + (start vector) + (end vector) + (start-color rgba) + (mode symbol) + (end-color rgba) + ) + "Draw a debug line between p0 and p1, in 3D." + (when enable + (cond + (*debug-draw-pauseable* + (let ((line (get-debug-line))) + (when line + (set! (-> line bucket) bucket) + (set! (-> line v1 quad) (-> start quad)) + (set! (-> line v2 quad) (-> end quad)) + (set! (-> line color) start-color) + (set! (-> line color2) end-color) + (set! (-> line mode) mode) + ) + ) + ) + (else + (internal-draw-debug-line bucket start end start-color mode end-color) + ) + ) + ) + #f + ) + +(defun-debug add-debug-line2d ((enable symbol) (bucket bucket-id) (start vector) (end vector) (color vector)) + "Draw a line in screen coordinates" + (if (not enable) + (return #f) + ) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (let ((p0 (new 'stack 'vector4w)) + (p1 (new 'stack 'vector4w)) + ) + (set! (-> p0 quad) (-> start quad)) + (set! (-> p1 quad) (-> end quad)) + (set! (-> p0 x) (* (+ (-> p0 x) 2048) 16)) + (set! (-> p0 y) (* -16 (- 2048 (-> p0 y)))) + (set! (-> p0 z) #x7fffff) + (set! (-> p1 x) (* (+ (-> p1 x) 2048) 16)) + (set! (-> p1 y) (* -16 (- 2048 (-> p1 y)))) + (set! (-> p1 z) #x7fffff) + (let ((a0-18 (the-as (pointer uint64) (-> buf base)))) + (let* ((a1-7 buf) + (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 buf) + (giftag (the-as gs-gif-tag (-> a1-8 base))) + ) + (set! (-> giftag 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! (-> giftag 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 giftag) 16)) + ) + (let* ((a1-9 buf) + (v0 (the-as vector4w-2 (-> a1-9 base))) + ) + (set! (-> v0 vector 0 quad) (-> color quad)) + (set! (-> v0 vector 1 quad) (-> p0 quad)) + (set! (-> a1-9 base) (&+ (the-as pointer v0) 32)) + ) + (let* ((a1-10 buf) + (v1 (the-as vector4w-2 (-> a1-10 base))) + ) + (set! (-> v1 vector 0 quad) (-> color quad)) + (set! (-> v1 vector 1 quad) (-> p1 quad)) + (set! (-> a1-10 base) (&+ (the-as pointer v1) 32)) + ) + (let ((a1-14 (/ (the-as int (+ (- -16 (the-as int a0-18)) (the-as int (-> buf base)))) 16))) + (cond + ((nonzero? a1-14) + (logior! (-> a0-18 0) (shr (shl a1-14 48) 48)) + (logior! (-> a0-18 1) (shl (shr (shl a1-14 48) 48) 32)) + ) + (else + (set! (-> buf base) a0-18) + ) + ) + ) + ) + ) + (let ((tag-end (-> buf base))) + (let ((v1-12 (the-as dma-packet (-> buf 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! (-> buf base) (&+ (the-as pointer v1-12) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + #f + ) + +(defun-debug add-debug-box ((enable symbol) (bucket bucket-id) (c1 vector) (c2 vector) (color rgba)) + "Draw an axis-aligned box" + (let ((p0 (new-stack-vector0))) + (set! (-> p0 quad) (-> c1 quad)) + (let ((p1 (new-stack-vector0))) + (set! (-> p1 quad) (-> c1 quad)) + (when enable + (set! (-> p1 x) (-> c2 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 x) (-> c1 x)) + (set! (-> p1 y) (-> c2 y)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 y) (-> c1 y)) + (set! (-> p1 z) (-> c2 z)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p0 y) (-> c2 y)) + (set! (-> p1 y) (-> c2 y)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 z) (-> c1 z)) + (set! (-> p1 x) (-> c2 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 y) (-> c1 y)) + (set! (-> p0 x) (-> c2 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p0 quad) (-> c2 quad)) + (set! (-> p1 quad) (-> c2 quad)) + (set! (-> p1 x) (-> c1 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 x) (-> c2 x)) + (set! (-> p1 y) (-> c1 y)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 y) (-> c2 y)) + (set! (-> p1 z) (-> c1 z)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p0 y) (-> c1 y)) + (set! (-> p1 y) (-> c1 y)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 z) (-> c2 z)) + (set! (-> p1 x) (-> c1 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 y) (-> c2 y)) + (set! (-> p0 x) (-> c1 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + ) + ) + ) + #f + ) + +(defun-debug add-debug-box-with-transform ((enable symbol) (bucket bucket-id) (box bounding-box) (trans matrix) (color rgba)) + "Draw an oriented box" + (b! (not enable) cfg-5 :delay (nop!)) + (let ((points (new 'stack-no-clear 'inline-array 'vector 8))) + (let ((corners (new 'stack-no-clear 'inline-array 'vector 2)) + (point (new 'stack-no-clear 'vector)) + ) + (set! (-> corners 0 quad) (-> box min quad)) + (set! (-> corners 1 quad) (-> box max quad)) + (set! (-> point w) 1.0) + (dotimes (i 8) + (set! (-> point x) (-> corners (logand i 1) x)) + (set! (-> point y) (-> corners (logand (/ i 2) 1) y)) + (set! (-> point z) (-> corners (logand (/ i 4) 1) z)) + (let ((a0-5 (-> points i))) + (vector-matrix*! a0-5 point trans) + ) + ) + ) + (add-debug-line #t bucket (-> points 0) (-> points 1) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 1) (-> points 3) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 3) (-> points 2) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 2) (-> points 0) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 4) (-> points 5) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 5) (-> points 7) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 7) (-> points 6) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 6) (-> points 4) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 0) (-> points 4) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 1) (-> points 5) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 3) (-> points 7) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 2) (-> points 6) color #f (the-as rgba -1)) + ) + (label cfg-5) + (the-as symbol 0) + ) + +(defun-debug add-debug-x ((enable symbol) (bucket bucket-id) (position vector) (color rgba)) + "Draw an X in the xz plane" + (if (not enable) + (return #f) + ) + (let ((p0 (new-stack-vector0)) + (p1 (new-stack-vector0)) + ) + (vector+! p0 position (new 'static 'vector :x -1228.8)) + (vector+! p1 position (new 'static 'vector :x 1228.8)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (vector+! p0 position (new 'static 'vector :z -1228.8)) + (vector+! p1 position (new 'static 'vector :z 1228.8)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-cross ((enable symbol) (bucket bucket-id) (position vector) (radius float)) + "Draw an XYZ coordinate cross" + (if (not enable) + (return #f) + ) + (let ((p0 (new-stack-vector0)) + (p1 (new-stack-vector0)) + ) + (let ((a1-1 p0) + (v1-2 position) + (a0-1 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-1 x) (- radius)) + (set! (-> a0-1 y) 0.0) + (set! (-> a0-1 z) 0.0) + (set! (-> a0-1 w) 1.0) + (vector+! a1-1 v1-2 a0-1) + ) + (let ((a1-3 p1) + (v1-3 position) + (a0-2 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-2 x) radius) + (set! (-> a0-2 y) 0.0) + (set! (-> a0-2 z) 0.0) + (set! (-> a0-2 w) 1.0) + (vector+! a1-3 v1-3 a0-2) + ) + (add-debug-line #t bucket p0 p1 *color-red* #f (the-as rgba -1)) + (let ((a1-6 p0) + (v1-4 position) + (a0-4 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-4 x) 0.0) + (set! (-> a0-4 y) (- radius)) + (set! (-> a0-4 z) 0.0) + (set! (-> a0-4 w) 1.0) + (vector+! a1-6 v1-4 a0-4) + ) + (let ((a1-8 p1) + (v1-5 position) + (a0-5 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-5 x) 0.0) + (set! (-> a0-5 y) radius) + (set! (-> a0-5 z) 0.0) + (set! (-> a0-5 w) 1.0) + (vector+! a1-8 v1-5 a0-5) + ) + (add-debug-line #t bucket p0 p1 *color-green* #f (the-as rgba -1)) + (let ((a1-11 p0) + (v1-6 position) + (a0-7 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-7 x) 0.0) + (set! (-> a0-7 y) 0.0) + (set! (-> a0-7 z) (- radius)) + (set! (-> a0-7 w) 1.0) + (vector+! a1-11 v1-6 a0-7) + ) + (let ((a0-8 p1) + (v1-7 (new 'stack-no-clear 'vector)) + ) + (set! (-> v1-7 x) 0.0) + (set! (-> v1-7 y) 0.0) + (set! (-> v1-7 z) radius) + (set! (-> v1-7 w) 1.0) + (vector+! a0-8 position v1-7) + ) + (add-debug-line #t bucket p0 p1 *color-blue* #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-text-3d ((enable symbol) + (bucket bucket-id) + (text string) + (position vector) + (color font-color) + (screen-offset vector2h) + ) + "Draw text at the given point. screen-offset can be #f." + (when enable + (cond + (*debug-draw-pauseable* + (let ((v1-2 (get-debug-text-3d))) + (when v1-2 + (set! (-> v1-2 flags) 0) + (set! (-> v1-2 bucket) bucket) + (set! (-> v1-2 pos quad) (-> position quad)) + (cond + (screen-offset + (set! (-> v1-2 offset x) (the-as int (-> screen-offset x))) + (set! (-> v1-2 offset y) (the-as int (-> screen-offset y))) + ) + (else + (set! (-> v1-2 offset x) 0) + (set! (-> v1-2 offset y) 0) + 0 + ) + ) + (set! (-> v1-2 color) color) + (let ((a0-6 0) + (a1-2 (-> text 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)) + ) + 0 + ) + ) + ) + (else + (internal-draw-debug-text-3d bucket text position color (cond + (screen-offset + (empty) + screen-offset + ) + (else + (new 'static 'vector2h) + ) + ) + ) + ) + ) + ) + #f + ) + +(defun-debug add-debug-sphere-with-transform ((enable symbol) (bucket bucket-id) (position vector) (radius meters) (trans matrix) (color rgba)) + "Transform the given point by the given transform, then draw a debug sphere there. + The orientation of the debug sphere itself is not changed by the transform, just its origin." + (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 enable + (.lvf vf5 (&-> position quad)) + (.lvf vf1 (&-> trans vector 0 quad)) + (.lvf vf2 (&-> trans vector 1 quad)) + (.lvf vf3 (&-> trans vector 2 quad)) + (.lvf vf4 (&-> trans 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 ((position-transformed (new 'stack-no-clear 'vector))) + (.svf (&-> position-transformed quad) vf5) + (add-debug-sphere enable bucket position-transformed radius color) + ) + ) + #f + ) + ) + +(defun-debug add-debug-sphere ((enable symbol) (bucket bucket-id) (position vector) (radius meters) (color rgba)) + "Add a debug sphere at the given point." + (if enable + (add-debug-sphere-from-table bucket position radius color 6) + ) + #f + ) + +(defun-debug add-debug-text-sphere ((enable symbol) (bucket bucket-id) (position vector) (radius meters) (text string) (color rgba)) + "Add a debug sphere at the given point, with some text. The color is for the sphere - the text is color 0." + (add-debug-sphere enable bucket position radius color) + (add-debug-text-3d enable bucket text position (font-color default) (the-as vector2h #f)) + #f + ) + +(defun-debug add-debug-spheres ((enable symbol) (bucket bucket-id) (origins (inline-array vector)) (count int) (color rgba)) + "Add a bunch of spheres. The radius is taken from the w component of the origin." + (when enable + (let ((origin (-> origins 0))) + (countdown (i count) + (add-debug-sphere #t bucket origin (-> origin w) color) + (&+! origin 16) + ) + ) + ) + #f + ) + +(defun-debug add-debug-line-sphere ((enable symbol) (bucket bucket-id) (position vector) (forward vector) (arg4 float) (color rgba)) + (local-vars + (var-bucket bucket-id) + (var-position vector) + (var-forward vector) + (var-arg4 float) + (var-color rgba) + (mat matrix) + (forward-length float) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (init-vf0-vector) + (b! (not enable) cfg-8 :delay (nop!)) + (set! var-bucket bucket) + (set! var-position position) + (set! var-forward forward) + (set! var-arg4 arg4) + (set! var-color color) + (set! mat (new 'stack-no-clear 'matrix)) + (set! forward-length (vector-length var-forward)) + (let ((mat-forward (new 'stack-no-clear 'vector)) + (mat-down (new 'stack-no-clear 'vector)) + ) + (vector-normalize-copy! mat-forward var-forward 1.0) + (vector-reset! mat-down) + (let* ((f0-2 (-> mat-forward y)) + (f0-4 (* f0-2 f0-2)) + (f1-0 (-> mat-forward z)) + ) + (if (< f0-4 (* f1-0 f1-0)) + (set! (-> mat-down y) -1.0) + (set! (-> mat-down z) -1.0) + ) + ) + (forward-down->inv-matrix mat mat-forward mat-down) + ) + (set! (-> mat trans quad) (-> var-position quad)) + (set! (-> mat 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) (* var-arg4 (-> s5-1 2 y))) + (set! (-> s1-0 y) (* var-arg4 (-> gp-1 2 y))) + (vector-matrix*! s3-0 s1-0 mat) + (dotimes (i 10) + (set! (-> s4-0 quad) (-> s3-0 quad)) + (set! (-> s1-0 x) (* var-arg4 (-> (&-> s5-1 0 data i) 0))) + (set! (-> s1-0 y) (* var-arg4 (-> (&-> gp-1 0 data i) 0))) + (vector-matrix*! s3-0 s1-0 mat) + (add-debug-line #t var-bucket s4-0 s3-0 var-color #f (the-as rgba -1)) + (let ((v1-26 s2-0)) + (let ((a0-10 s3-0) + (a1-7 (-> mat vector 2)) + (f0-18 forward-length) + ) + (.lvf vf2 (&-> a1-7 quad)) + (.lvf vf1 (&-> a0-10 quad)) + (let ((a0-11 f0-18)) + (.mov vf3 a0-11) + ) + ) + (.add.x.vf vf4 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf2 vf3) + (.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111) + (.svf (&-> v1-26 quad) vf4) + ) + (add-debug-line #t var-bucket s3-0 s2-0 var-color #f (the-as rgba -1)) + (let ((v1-27 s4-0)) + (let ((a0-13 s4-0) + (a1-10 (-> mat vector 2)) + (f0-19 forward-length) + ) + (.lvf vf2 (&-> a1-10 quad)) + (.lvf vf1 (&-> a0-13 quad)) + (let ((a0-14 f0-19)) + (.mov vf3 a0-14) + ) + ) + (.add.x.vf vf4 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf2 vf3) + (.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111) + (.svf (&-> v1-27 quad) vf4) + ) + (add-debug-line #t var-bucket s4-0 s2-0 var-color #f (the-as rgba -1)) + ) + ) + (label cfg-8) + 0 + (none) + ) + ) + +(defun-debug add-debug-circle ((enable symbol) (bucket bucket-id) (position vector) (radius float) (color rgba) (orientation matrix)) + (local-vars (i int) (sv-64 vector) (sv-80 vector)) + "Draw a 2D circle in 3D. orientation may be #f, which will default to drawing in the xz plane." + (if (not enable) + (return #f) + ) + (let ((angle 0.0) + (line-start (new-stack-vector0)) + (line-end (new-stack-vector0)) + ) + (set! i 0) + (while (< i 12) + (set! sv-64 line-start) + (set! (-> sv-64 x) (* radius (cos angle))) + (set! (-> sv-64 y) 0.0) + (set! (-> sv-64 z) (* radius (sin angle))) + (set! (-> sv-64 w) 1.0) + (set! angle (+ 5461.3335 angle)) + (set! sv-80 line-end) + (set! (-> sv-80 x) (* radius (cos angle))) + (set! (-> sv-80 y) 0.0) + (set! (-> sv-80 z) (* radius (sin angle))) + (set! (-> sv-80 w) 1.0) + (when orientation + (vector-matrix*! line-start line-start orientation) + (vector-matrix*! line-end line-end orientation) + ) + (vector+! line-start line-start position) + (vector+! line-end line-end position) + (add-debug-line #t bucket line-start line-end color #f (the-as rgba -1)) + (set! i (+ i 1)) + ) + ) + #f + ) + +(defun-debug add-debug-vector ((enable symbol) (bucket bucket-id) (position vector) (direction vector) (length meters) (color rgba)) + "Draw a ray from the given position, direction, and length." + (if (not enable) + (return #f) + ) + (let ((line-end (new-stack-vector0))) + (set! (-> line-end x) (+ (-> position x) (* (-> direction x) length))) + (set! (-> line-end y) (+ (-> position y) (* (-> direction y) length))) + (set! (-> line-end z) (+ (-> position z) (* (-> direction z) length))) + (add-debug-line #t bucket position line-end color #f (the-as rgba -1)) + ) + #f + ) + +(defun-debug add-debug-matrix ((enable symbol) (bucket bucket-id) (mat matrix) (line-length meters)) + "Draw the rotation vectors of a matrix at its position." + (add-debug-vector enable bucket (-> mat trans) (-> mat vector 0) line-length (new 'static 'rgba :r #xff :a #x80)) + (add-debug-vector enable bucket (-> mat trans) (-> mat vector 1) line-length (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector enable bucket (-> mat trans) (-> mat vector 2) line-length (new 'static 'rgba :b #xff :a #x80)) + mat + ) + +(defun-debug add-debug-rot-matrix ((enable symbol) (bucket bucket-id) (mat matrix) (position vector)) + "Draw the rotation vectors of a matrix at the given position." + (add-debug-vector enable bucket position (-> mat vector 0) (meters 2.0) (new 'static 'rgba :r #xff :a #x80)) + (add-debug-vector enable bucket position (-> mat vector 1) (meters 2.0) (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector enable bucket position (-> mat vector 2) (meters 2.0) (new 'static 'rgba :b #xff :a #x80)) + mat + ) + +(defun-debug add-debug-quaternion ((enable symbol) (bucket bucket-id) (position vector) (quat quaternion)) + "Converts the quaternion to a matrix and draw its rotation vectors at the given position." + (when enable + (let ((mat (quaternion->matrix (new 'stack-no-clear 'matrix) quat))) + (add-debug-rot-matrix enable bucket mat position) + ) + ) + (none) + ) + +(defun-debug add-debug-cspace ((enable symbol) (bucket bucket-id) (csp cspace)) + "Draw the cspace bone transformation matrix." + (add-debug-matrix enable bucket (-> csp bone transform) (meters 2.0)) + csp + ) + +(defun-debug add-debug-yrot-vector ((enable symbol) (bucket bucket-id) (position vector) (angle float) (line-length float) (color rgba)) + "From the given position, draw a vector along the xz plane with the given angle around the Y-axis." + (local-vars (var-angle float)) + (set! var-angle angle) + (let ((var-line-length line-length) + (var-color color) + ) + (if (not enable) + (return #f) + ) + (let ((line-start (new-stack-vector0))) + (set-vector! + line-start + (+ (-> position x) (* (sin var-angle) var-line-length)) + (-> position y) + (+ (-> position z) (* (cos var-angle) var-line-length)) + 1.0 + ) + (add-debug-line enable bucket line-start position var-color #f (the-as rgba -1)) + ) + ) + #f + ) + +(defun-debug add-debug-arc ((enable symbol) + (bucket bucket-id) + (position vector) + (start-angle float) + (end-angle float) + (radius float) + (color rgba) + (orientation matrix) + ) + "Draw an arc with the given start and end angle. orientation may be #f, which defaults to drawing along the xz plane." + (local-vars (line-start vector) (line-end vector) (i int) (sv-96 vector) (sv-112 vector)) + (if (not enable) + (return #f) + ) + (let ((angle start-angle)) + (set! line-start (new 'stack-no-clear 'vector)) + (set! (-> line-start quad) (the-as uint128 0)) + (set! line-end (new 'stack-no-clear 'vector)) + (set! (-> line-end quad) (the-as uint128 0)) + (set! i 0) + (while (< i 12) + (set! sv-96 line-start) + (set! (-> sv-96 x) (* radius (sin angle))) + (set! (-> sv-96 y) 0.0) + (set! (-> sv-96 z) (* radius (cos angle))) + (set! (-> sv-96 w) 1.0) + (+! angle (the float (/ (the int (- end-angle start-angle)) 12))) + (set! sv-112 line-end) + (set! (-> sv-112 x) (* radius (sin angle))) + (set! (-> sv-112 y) 0.0) + (set! (-> sv-112 z) (* radius (cos angle))) + (set! (-> sv-112 w) 1.0) + (when orientation + (vector-matrix*! line-start line-start orientation) + (vector-matrix*! line-end line-end orientation) + ) + (vector+! line-start line-start position) + (vector+! line-end line-end position) + (add-debug-line #t bucket line-start line-end color #f (the-as rgba -1)) + (cond + ((zero? i) + (add-debug-line #t bucket line-start position color #f (the-as rgba -1)) + ) + ((= i 11) + (add-debug-line #t bucket line-end position color #f (the-as rgba -1)) + ) + ) + (set! i (+ i 1)) + ) + ) + #f + ) + +(defun-debug add-debug-curve ((enable symbol) + (bucket bucket-id) + (cverts (inline-array vector)) + (num-cverts int) + (knots (pointer float)) + (num-knots int) + (color rgba) + ) + "Draw a curve as a series of lines." + (local-vars (p1 vector) (iterations int) (i int)) + (if (not enable) + (return #f) + ) + (let ((p0 (new-stack-vector0))) + (set! p1 (new 'stack-no-clear 'vector)) + (set! (-> p1 quad) (the-as uint128 0)) + (set! iterations (* num-cverts 4)) + (curve-evaluate! p1 (-> knots 0) cverts num-cverts knots num-knots) + (set! i 0) + (while (< i iterations) + (set! (-> p0 quad) (-> p1 quad)) + (curve-evaluate! p1 (/ (the float (+ i 1)) (the float iterations)) cverts num-cverts knots num-knots) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! i (+ i 1)) + ) + ) + #f + ) + +(defun-debug add-debug-curve2 ((enable symbol) (bucket bucket-id) (curve curve) (color rgba) (arg4 symbol)) + "Draw a curve as a series of lines." + (if enable + (add-debug-curve + #t + bucket + (-> curve cverts) + (-> curve num-cverts) + (-> curve knots) + (-> curve num-knots) + color + ) + ) + #f + ) + +(defun-debug add-debug-points ((enable symbol) + (bucket bucket-id) + (points (inline-array vector)) + (num-points int) + (color rgba) + (y-override float) + (highlight int) + ) + "For each point, draw an X along the xz plane with the index of the point above it as text. + If y-override is not 0.0, the Y-coordinate of each point will use its value instead. + Specify highlight as the index of a point that should be drawn as a white X instead of using + the given color." + (local-vars (position vector)) + (when enable + (dotimes (i num-points) + (set! position (new 'stack-no-clear 'vector)) + (set! (-> position quad) (the-as uint128 0)) + (set! (-> position quad) (-> points i quad)) + (if (!= y-override 0.0) + (set! (-> position y) y-override) + ) + (format (clear *temp-string*) "~d" i) + (add-debug-text-3d #t bucket *temp-string* position (the-as font-color 1) (the-as vector2h #f)) + (let ((a3-2 (if (= i highlight) + (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80) + color + ) + ) + ) + (add-debug-x #t bucket position a3-2) + ) + ) + ) + #f + ) + +(defun-debug debug-percent-bar ((enable symbol) (bucket bucket-id) (x int) (y int) (percentage float) (color rgba) (width int) (height int)) + "Draw a rectangular percentage bar at the given location." + (local-vars (sv-16 int) (sv-32 float)) + (set! sv-16 y) + (set! sv-32 percentage) + (let ((s2-0 color) + (s1-0 width) + (s3-0 height) + ) + (if (not enable) + (return #f) + ) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (draw-sprite2d-xy buf x sv-16 s1-0 s3-0 (new 'static 'rgba :a #x40)) + (draw-sprite2d-xy buf x (+ sv-16 2) (the int (* sv-32 (the float s1-0))) (+ s3-0 -4) s2-0) + (let ((tag-end (-> buf base))) + (let ((pkt (the-as dma-packet (-> buf base)))) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt vif0) (new 'static 'vif-tag)) + (set! (-> pkt vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + #f + ) + +(defun-debug debug-pad-display ((pad cpad-info)) + "Call each frame to draw the history of stick 0 as a series of fading points." + (let ((stick-history (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 (i 31) + (let ((a0-3 (-> stick-history i quad))) + (set! (-> stick-history (+ i 1) quad) a0-3) + ) + ) + (set! (-> stick-history 0 x) (* (sin (-> pad stick0-dir)) (-> pad stick0-speed))) + (set! (-> stick-history 0 y) (* (cos (-> pad stick0-dir)) (-> pad stick0-speed))) + (dotimes (j 32) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (draw-sprite2d-xy + buf + (the int (* 120.0 (-> stick-history j x))) + (the int (* 144.0 (-> stick-history j y))) + 10 + 10 + (new 'static 'rgba :a #x80 :r (- 255 (* 7 j))) + ) + (let ((tag-end (-> buf base))) + (let ((pkt (the-as dma-packet (-> buf base)))) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt vif0) (new 'static 'vif-tag)) + (set! (-> pkt vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + (bucket-id bucket-324) + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + #f + ) + +(defun-debug add-debug-light ((enable symbol) (bucket bucket-id) (light light) (position vector) (text 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 enable) + (return #f) + ) + (when (!= (-> light extra x) 0.0) + (add-debug-vector + enable + bucket + position + (-> light direction) + (meters 3.0) + (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80) + ) + (let ((sphere-pos (new-stack-vector0))) + (let ((v1-3 (-> light direction))) + (let ((a0-3 (* 12288.0 (-> light extra x)))) + (.mov vf7 a0-3) + ) + (.lvf vf5 (&-> v1-3 quad)) + ) + (.lvf vf4 (&-> position 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 (&-> sphere-pos quad) vf6) + (let ((color-rgba (logior (logior (logior (shr (shl (the int (* 128.0 (-> light color w))) 56) 32) + (shr (shl (the int (* 128.0 (-> light color z))) 56) 40) + ) + (shr (shl (the int (* 128.0 (-> light color y))) 56) 48) + ) + (shr (shl (the int (* 128.0 (-> light color x))) 56) 56) + ) + ) + ) + (format (clear *temp-string*) "~S ~,,2f" text (-> light extra x)) + (let ((t0-2 *temp-string*)) + (add-debug-text-sphere enable bucket sphere-pos (* 2048.0 (-> light extra x)) t0-2 (the-as rgba color-rgba)) + ) + ) + ) + ) + #f + ) + ) + +(defun-debug add-debug-lights ((enable symbol) (bucket bucket-id) (lights (inline-array light)) (position vector)) + (if (not enable) + (return #f) + ) + (add-debug-light enable bucket (-> lights 0) position "dir0") + (add-debug-light enable bucket (-> lights 1) position "dir1") + (add-debug-light enable bucket (-> lights 2) position "dir2") + (add-debug-light enable bucket (-> lights 3) position "ambi") + #f + ) + +(define-extern drawable-frag-count (function drawable int)) +(defun-debug drawable-frag-count ((drbl drawable)) + (let ((count 0)) + (cond + ((not drbl) + ) + ((type? drbl drawable-group) + (dotimes (i (-> (the-as drawable-group drbl) length)) + (+! count (drawable-frag-count (-> (the-as drawable-group drbl) data i))) + ) + ) + (else + (+! count 1) + ) + ) + count + ) + ) + +(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 ((history pos-history) (num-points int)) + (set! (-> history num-points) num-points) + (set! (-> history points) (the-as (inline-array vector) #f)) + history + ) + +(defun-debug history-draw-and-update ((history pos-history) (draw symbol) (pos vector)) + (if (and draw (not (-> history points))) + (set! (-> history points) (the-as (inline-array vector) (malloc 'debug (* (-> history num-points) 16)))) + ) + (when (-> history points) + (set! (-> history points (-> history h-first) quad) (-> pos quad)) + (+! (-> history h-first) 1) + (when (>= (-> history h-first) (-> history num-points)) + (set! (-> history h-first) 0) + 0 + ) + ) + (when draw + (dotimes (i (+ (-> history num-points) -1)) + (if (!= (+ i 1) (-> history h-first)) + (add-debug-line + #t + (bucket-id bucket-318) + (-> history points i) + (-> history points (+ i 1)) + (new 'static 'rgba :r #x80 :g #xc0 :b #x80 :a #x80) + #f + (the-as rgba -1) + ) + ) + ) + ) + #f + ) + + +;;;;;;;;;;;;;;;;;; +;; Misc Debug +;;;;;;;;;;;;;;;;;; + +(defun-debug dma-timeout-cam () + (let ((pos (new-stack-vector0)) + (rot (new-stack-matrix0)) + ) + (set! (-> pos x) -666764.4) + (set! (-> pos y) 21102.984) + (set! (-> pos z) 51613.348) + (set! (-> pos w) 1.0) + (set! (-> rot vector 0 x) -0.911) + (set! (-> rot vector 0 y) 0.0) + (set! (-> rot vector 0 z) 0.4122) + (set! (-> rot vector 0 w) 0.0) + (set! (-> rot vector 1 x) -0.0984) + (set! (-> rot vector 1 y) 0.971) + (set! (-> rot vector 1 z) -0.2174) + (set! (-> rot vector 1 w) 0.0) + (set! (-> rot vector 2 x) -0.4003) + (set! (-> rot vector 2 y) -0.2387) + (set! (-> rot vector 2 z) -0.8847) + (set! (-> rot vector 2 w) 0.0) + (set! (-> rot trans x) 0.0) + (set! (-> rot trans y) 0.0) + (set! (-> rot trans z) 0.0) + (set! (-> rot trans w) 1.0) + (debug-set-camera-pos-rot! pos rot) + ) + ) + +(defun-debug display-file-info () + (when (and *display-file-info* (!= *master-mode* 'menu)) + (dotimes (i (-> *level* length)) + (let ((level (-> *level* level i))) + (when (= (-> level status) 'active) + (let ((bsp (-> level bsp))) + (format *stdcon* "file name: ~S~%" (-> bsp info file-name)) + (format *stdcon* "version: ~D.~D~%" (-> bsp info major-version) (-> bsp info minor-version)) + (format *stdcon* "maya file: ~S~%" (-> bsp info maya-file-name)) + (format *stdcon* "mdb file: ~S~%" (-> bsp info mdb-file-name)) + (format *stdcon* "~S" (-> bsp info tool-debug)) + ) + ) + ) + ) + ) + 0 + ) + +(defun-debug add-debug-cursor ((enable symbol) (bucket bucket-id) (x int) (y int) (arg4 int)) + (when enable + (let* ((buf (-> *display* frames (-> *display* on-screen) global-buf)) + (tag-start (-> buf base)) + ) + (set! (-> (new 'stack-no-clear 'vector) quad) (the-as uint128 0)) + (let ((v1-7 arg4)) + (draw-string-xy + "X" + buf + (+ x -5) + (+ y -4) + (the-as font-color (cond + ((= v1-7 1) + 3 + ) + ((= v1-7 2) + 5 + ) + ((= v1-7 4) + 6 + ) + (else + 0 + ) + ) + ) + (font-flags shadow) + ) + ) + (let ((tag-end (-> buf base))) + (let ((pkt (the-as dma-packet (-> buf base)))) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt vif0) (new 'static 'vif-tag)) + (set! (-> pkt vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + 0 + (none) + ) + + +;;;;;;;;;;;;;;;;;; +;; Boundary Debug +;;;;;;;;;;;;;;;;;; + +;; TODO: missing a bunch of functions here + +(define-extern init-boundary-regs (function none)) + +(defun-debug add-boundary-shader ((tex-id texture-id) (buf dma-buffer)) + (let ((tex (lookup-texture-by-id tex-id))) + (when tex + (let* ((v1-0 buf) + (giftag (the-as gs-gif-tag (-> v1-0 base))) + ) + (set! (-> giftag tag) (new 'static 'gif-tag64 :nloop #x1 :nreg #x5)) + (set! (-> giftag 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 giftag) 16)) + ) + (let ((shader (the-as adgif-shader (-> buf base)))) + (adgif-shader<-texture-simple! shader tex) + (set! (-> shader alpha) (new 'static 'gs-alpha :b #x1 :d #x1)) + (set! (-> shader tex0 tfx) 0) + (set! (-> shader tex1 mmag) 0) + (set! (-> shader clamp) (new 'static 'gs-clamp)) + ) + 0 + (&+! (-> buf base) 80) + ) + ) + (none) + ) + + +;;;;;;;;;;;;;;;;;; +;; More Misc +;;;;;;;;;;;;;;;;;; + +(define-extern cpu-delay (function int none)) + +(define-extern qword-read-time (function (array uint128) int int)) + +;; Returns whether some workaround for an EE memory controller bug is enabled. +(define-extern bugfix? (function symbol)) diff --git a/goal_src/jak2/engine/gfx/sprite/particles/sparticle-launcher.gc b/goal_src/jak2/engine/gfx/sprite/particles/sparticle-launcher.gc index 5d21519236..dfcfed7add 100644 --- a/goal_src/jak2/engine/gfx/sprite/particles/sparticle-launcher.gc +++ b/goal_src/jak2/engine/gfx/sprite/particles/sparticle-launcher.gc @@ -712,7 +712,7 @@ (-> s5-1 w) (new 'static 'rgba :g #xff :a #x80) ) - (add-debug-matrix *display-sprite-marks* (bucket-id bucket-324) (-> obj origin) 8192.0) + (add-debug-matrix *display-sprite-marks* (bucket-id bucket-324) (-> obj origin) (meters 2.0)) ) (sphere-in-view-frustum? (the-as sphere s5-1)) ) diff --git a/test/decompiler/reference/jak2/engine/anim/joint-mod-h_REF.gc b/test/decompiler/reference/jak2/engine/anim/joint-mod-h_REF.gc index fb7c6cdb8b..27abd1f900 100644 --- a/test/decompiler/reference/jak2/engine/anim/joint-mod-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/anim/joint-mod-h_REF.gc @@ -156,7 +156,7 @@ ;; definition (debug) for function joint-mod-debug-draw ;; WARN: Return type mismatch int vs none. (defun-debug joint-mod-debug-draw ((arg0 joint-mod)) - (add-debug-matrix #t (bucket-id bucket-318) (-> arg0 joint bone transform) 8192.0) + (add-debug-matrix #t (bucket-id bucket-318) (-> arg0 joint bone transform) (meters 2.0)) 0 (none) ) diff --git a/test/decompiler/reference/jak2/engine/anim/joint-mod_REF.gc b/test/decompiler/reference/jak2/engine/anim/joint-mod_REF.gc index 3358fb716d..cd893fd57d 100644 --- a/test/decompiler/reference/jak2/engine/anim/joint-mod_REF.gc +++ b/test/decompiler/reference/jak2/engine/anim/joint-mod_REF.gc @@ -1006,7 +1006,7 @@ *display-target-marks* (bucket-id bucket-318) (-> gp-0 target) - 819.2 + (meters 0.2) "look" (new 'static 'rgba :r #xff :g #xff :a #x80) ) @@ -1133,7 +1133,7 @@ *display-target-marks* (bucket-id bucket-318) (-> gp-0 target) - 819.2 + (meters 0.2) "look" (new 'static 'rgba :r #xff :g #xff :a #x80) ) @@ -1250,7 +1250,7 @@ *display-target-marks* (bucket-id bucket-318) (-> gp-0 target) - 819.2 + (meters 0.2) "look" (new 'static 'rgba :r #xff :g #xff :a #x80) ) diff --git a/test/decompiler/reference/jak2/engine/debug/debug-h_REF.gc b/test/decompiler/reference/jak2/engine/debug/debug-h_REF.gc index e89fe0f60c..5f159ed663 100644 --- a/test/decompiler/reference/jak2/engine/debug/debug-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/debug/debug-h_REF.gc @@ -67,6 +67,7 @@ ) ;; definition for method 3 of type debug-vertex-stats +;; INFO: this function exists in multiple non-identical object files (defmethod inspect debug-vertex-stats ((obj debug-vertex-stats)) (when (not obj) (set! obj obj) diff --git a/test/decompiler/reference/jak2/engine/debug/debug-sphere_REF.gc b/test/decompiler/reference/jak2/engine/debug/debug-sphere_REF.gc new file mode 100644 index 0000000000..9282c1f258 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/debug/debug-sphere_REF.gc @@ -0,0 +1,104 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function make-debug-sphere-table +;; INFO: Used lq/sq +(defun make-debug-sphere-table ((points vector-array) (h-lines float) (v-lines float)) + (local-vars (next-hz vector) (next-vt vector) (h-line int)) + (let ((offset (new-stack-vector0)) + (scale 1.0) + (num-points 0) + ) + (set-vector! offset 0.0 0.0 0.0 1.0) + (dotimes (v-line (the int v-lines)) + (let ((f28-0 (* scale (sin (* (the float v-line) (/ 32768.0 v-lines))))) + (f26-0 (* scale (sin (* (the float (+ v-line 1)) (/ 32768.0 v-lines))))) + (current (new-stack-vector0)) + ) + (set! next-hz (new 'stack-no-clear 'vector)) + (set! (-> next-hz quad) (the-as uint128 0)) + (set! next-vt (new 'stack-no-clear 'vector)) + (set! (-> next-vt quad) (the-as uint128 0)) + (set! (-> current y) (+ (-> offset y) (* (cos (* (the float v-line) (/ 32768.0 v-lines))) scale))) + (set! (-> next-hz y) (-> current y)) + (set! (-> next-vt y) (+ (-> offset y) (* (cos (* (the float (+ v-line 1)) (/ 32768.0 v-lines))) scale))) + (set! h-line 0) + (while (< h-line (the int h-lines)) + (set! (-> current x) (+ (-> offset x) (* (cos (* (the float h-line) (/ 65536.0 h-lines))) f28-0))) + (set! (-> current z) (+ (-> offset z) (* (sin (* (the float h-line) (/ 65536.0 h-lines))) f28-0))) + (set! (-> next-hz x) (+ (-> offset x) (* (cos (* (the float (+ h-line 1)) (/ 65536.0 h-lines))) f28-0))) + (set! (-> next-hz z) (+ (-> offset z) (* (sin (* (the float (+ h-line 1)) (/ 65536.0 h-lines))) f28-0))) + (set! (-> next-vt x) (+ (-> offset x) (* (cos (* (the float h-line) (/ 65536.0 h-lines))) f26-0))) + (set! (-> next-vt z) (+ (-> offset z) (* (sin (* (the float h-line) (/ 65536.0 h-lines))) f26-0))) + (set! (-> points data num-points quad) (-> current quad)) + (set! (-> points data (+ num-points 1) quad) (-> next-hz quad)) + (set! (-> points data (+ num-points 2) quad) (-> next-vt quad)) + (+! num-points 3) + (set! h-line (+ h-line 1)) + ) + ) + ) + (set! (-> points length) num-points) + ) + points + ) + +;; this part is debug only +(when *debug-segment* +;; definition for symbol *debug-sphere-table*, type (array vector-array) +(define *debug-sphere-table* (the-as (array vector-array) (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 ((bucket bucket-id) (position vector) (radius meters) (color rgba) (table-idx int)) + (local-vars (sphere-points vector-array) (point-3 vector)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + ) + (if (zero? (-> *debug-sphere-table* table-idx)) + (set! (-> *debug-sphere-table* table-idx) (make-debug-sphere-table + (new 'debug 'vector-array (* (* 3 table-idx) table-idx)) + (the float table-idx) + (the float table-idx) + ) + ) + ) + (set! sphere-points (-> *debug-sphere-table* table-idx)) + (set! point-3 (the-as vector (new-stack-vector0))) + (let ((point-1 (new-stack-vector0)) + (point-2 (new-stack-vector0)) + (points (-> sphere-points data)) + ) + (.lvf vf1 (&-> position quad)) + (.mov vf2 radius) + (countdown (s4-1 (/ (-> sphere-points length) 3)) + (.lvf vf3 (&-> points 0 quad)) + (.lvf vf4 (&-> points 1 quad)) + (.lvf vf5 (&-> points 2 quad)) + (set! points (the-as (inline-array vector) (-> points 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 (&-> point-1 quad) vf3) + (.svf (&-> point-2 quad) vf4) + (.svf (&-> point-3 quad) vf5) + (add-debug-line #t bucket point-1 point-2 color #f (the-as rgba -1)) + (add-debug-line #t bucket point-1 point-3 color #f (the-as rgba -1)) + ) + ) + 0 + (none) + ) + ) + + + + diff --git a/test/decompiler/reference/jak2/engine/debug/debug_REF.gc b/test/decompiler/reference/jak2/engine/debug/debug_REF.gc new file mode 100644 index 0000000000..65217c5f95 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/debug/debug_REF.gc @@ -0,0 +1,1994 @@ +;;-*-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 ((in vector) (out vector4w)) + (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 (&-> in 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 (&-> out quad) vf5) + out + ) + ) + +;; definition (debug) for function add-debug-point +;; INFO: Used lq/sq +(defun-debug add-debug-point ((enable-draw symbol) (bucket bucket-id) (pt vector)) + (if (not enable-draw) + (return #f) + ) + (let ((s5-0 (new 'stack 'vector4w-2)) + (pt-copy (new 'stack-no-clear 'vector)) + ) + (set! (-> pt-copy quad) (-> pt quad)) + (set! (-> pt-copy w) 1.0) + (when (transform-point-qword! (the-as vector4w (-> s5-0 vector)) pt-copy) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (let ((a0-5 (the-as (pointer uint64) (-> buf base)))) + (let* ((a1-3 buf) + (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 buf) + (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) + (set! (-> s5-0 vector 0 y) (the-as int (+ (-> s5-0 vector 0 y) 288))) + (let* ((a1-11 buf) + (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)) + ) + (set! (-> s5-0 vector 0 x) (the-as int (+ (-> s5-0 vector 0 x) -256))) + (set! (-> s5-0 vector 0 y) (the-as int (+ (-> s5-0 vector 0 y) -288))) + (set! (-> s5-0 vector 1 x) 128) + (set! (-> s5-0 vector 1 y) 255) + (let* ((a1-18 buf) + (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)) + ) + (set! (-> s5-0 vector 0 x) (the-as int (+ (-> s5-0 vector 0 x) 512))) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 255) + (let* ((a1-23 buf) + (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)) + ) + (set! (-> s5-0 vector 0 x) (the-as int (+ (-> s5-0 vector 0 x) -256))) + (set! (-> s5-0 vector 0 y) (the-as int (+ (-> s5-0 vector 0 y) -288))) + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (let* ((a3-10 buf) + (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-5)) (the-as int (-> buf base)))) 16))) + (cond + ((nonzero? a3-14) + (logior! (-> a0-5 0) (shr (shl a3-14 48) 48)) + (logior! (-> a0-5 1) (shl (shr (shl a3-14 48) 48) 32)) + ) + (else + (set! (-> buf base) a0-5) + ) + ) + ) + ) + (let ((tag-end (-> buf base))) + (let ((a0-6 (the-as dma-packet (-> buf base)))) + (set! (-> a0-6 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> a0-6 vif0) (new 'static 'vif-tag)) + (set! (-> a0-6 vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer a0-6) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + #f + ) + +;; definition (debug) for function debug-line-clip? +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition (debug) for function internal-draw-debug-line +;; INFO: Used lq/sq +(defun-debug internal-draw-debug-line ((bucket bucket-id) (start vector) (end vector) (start-color rgba) (mode symbol) (end-color rgba)) + (local-vars (var-end vector) (sv-128 vector) (sv-144 vector)) + (set! var-end end) + (let ((var-start-color start-color) + (var-mode mode) + (var-end-color end-color) + ) + (let ((buf (-> *display* frames (-> *display* on-screen) debug-buf))) + (if (< (the-as uint (shr (+ (&- (-> buf end) (the-as uint (-> buf base))) 15) 4)) (the-as uint #x8000)) + (return (the-as pointer #f)) + ) + ) + (if (or (= var-end-color -1) (= var-end-color (new 'static 'rgba :r #xff :g #xff :b #xff :a #xff))) + (set! var-end-color var-start-color) + ) + (case var-mode + (('fade) + (set! var-end-color (new 'static 'rgba + :r (shr (-> var-end-color r) 1) + :g (shr (-> var-end-color g) 1) + :b (shr (-> var-end-color b) 1) + :a (-> var-end-color 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)) + (when (debug-line-clip? sv-128 sv-144 start var-end) + (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) + ) + (let* ((buf2 (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf2 base)) + ) + (let ((a0-28 (the-as (pointer uint64) (-> buf2 base)))) + (let* ((a1-6 buf2) + (pkt1 (the-as dma-packet (-> a1-6 base))) + ) + (set! (-> pkt1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt1 vif0) (new 'static 'vif-tag)) + (set! (-> pkt1 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-6 base) (&+ (the-as pointer pkt1) 16)) + ) + (let* ((a1-7 buf2) + (giftag (the-as gs-gif-tag (-> a1-7 base))) + ) + (set! (-> giftag 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! (-> giftag 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 giftag) 16)) + ) + (case var-mode + (('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 (-> var-start-color r)) f0-3))) + (set! (-> s3-0 vector 0 y) (the int (* (the float (-> var-start-color g)) f0-3))) + (set! (-> s3-0 vector 0 z) (the int (* (the float (-> var-start-color b)) f0-3))) + ) + (set! (-> s3-0 vector 0 w) (the-as int (-> var-start-color a))) + ) + (else + (set! (-> s3-0 vector 0 x) (the-as int (-> var-start-color r))) + (set! (-> s3-0 vector 0 y) (the-as int (-> var-start-color g))) + (set! (-> s3-0 vector 0 z) (the-as int (-> var-start-color b))) + (set! (-> s3-0 vector 0 w) (the-as int (-> var-start-color a))) + ) + ) + (cond + ((= var-mode '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 (-> var-end-color r)) f0-7))) + (set! (-> s3-0 vector 1 y) (the int (* (the float (-> var-end-color g)) f0-7))) + (set! (-> s3-0 vector 1 z) (the int (* (the float (-> var-end-color b)) f0-7))) + ) + (set! (-> s3-0 vector 1 w) (the-as int (-> var-end-color a))) + ) + (else + (set! (-> s3-0 vector 1 x) (the-as int (-> var-end-color r))) + (set! (-> s3-0 vector 1 y) (the-as int (-> var-end-color g))) + (set! (-> s3-0 vector 1 z) (the-as int (-> var-end-color b))) + (set! (-> s3-0 vector 1 w) (the-as int (-> var-end-color a))) + ) + ) + (set! (-> s4-0 vector 0 z) (the-as int (+ (-> s4-0 vector 0 z) -8192))) + (set! (-> s4-0 vector 1 z) (the-as int (+ (-> s4-0 vector 1 z) -8192))) + (let* ((a3-7 buf2) + (a1-50 (the-as (inline-array vector4w-2) (-> a3-7 base))) + ) + (set! (-> a1-50 0 vector 0 quad) (-> s3-0 vector 0 quad)) + (set! (-> a1-50 0 vector 1 quad) (-> s4-0 vector 0 quad)) + (set! (-> a1-50 1 vector 0 quad) (-> s3-0 vector 1 quad)) + (set! (-> 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 (-> buf2 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! (-> buf2 base) a0-28) + ) + ) + ) + ) + (let ((tag-end (-> buf2 base))) + (let ((pkt2 (the-as dma-packet (-> buf2 base)))) + (set! (-> pkt2 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt2 vif0) (new 'static 'vif-tag)) + (set! (-> pkt2 vif1) (new 'static 'vif-tag)) + (set! (-> buf2 base) (&+ (the-as pointer pkt2) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + ) + ) + ) + +;; 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) (position vector) (color font-color) (screen-offset vector2h)) + (let ((screen-pos (new 'stack-no-clear 'vector4w))) + (set! (-> screen-pos quad) (the-as uint128 0)) + (when (transform-point-qword! screen-pos position) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (let ((font-ctx (new + 'stack + 'font-context + *font-default-matrix* + (the-as int (+ (-> screen-offset x) -1792 (/ (-> screen-pos x) 16))) + (the-as int (+ (-> screen-offset y) -1855 (/ (-> screen-pos y) 16))) + 0.0 + color + (font-flags shadow kerning) + ) + ) + ) + (let ((v1-10 font-ctx)) + (set! (-> v1-10 origin z) (the float (/ (-> screen-pos z) 16))) + ) + (draw-string text buf font-ctx) + ) + (let ((tag-end (-> buf base))) + (let ((pkt (the-as dma-packet (-> buf base)))) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt vif0) (new 'static 'vif-tag)) + (set! (-> pkt vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + ) + +;; 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)) + (when enable + (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)) + (when enable + (let ((s4-0 (new 'stack-no-clear 'vector)) + (s3-0 (vector-3pt-cross! (new 'stack-no-clear 'vector) p0 p1 p2)) + ) + (vector-float/! s3-0 s3-0 (* 0.00024414062 (vector-length s3-0))) + (vector+! s4-0 p0 p1) + (vector+! s4-0 s4-0 p2) + (vector-float/! s4-0 s4-0 3.0) + (vector+! s3-0 s3-0 s4-0) + (add-debug-line #t bucket s4-0 s3-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)) + (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 enable) + (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) + ) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (let ((a0-12 (the-as (pointer uint64) (-> buf base)))) + (let* ((a1-6 buf) + (pkt1 (the-as dma-packet (-> a1-6 base))) + ) + (set! (-> pkt1 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt1 vif0) (new 'static 'vif-tag)) + (set! (-> pkt1 vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-6 base) (&+ (the-as pointer pkt1) 16)) + ) + (let* ((a1-7 buf) + (giftag (the-as gs-gif-tag (-> a1-7 base))) + ) + (set! (-> giftag 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! (-> giftag 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 giftag) 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))) + (set! (-> s5-0 vector 0 z) (the-as int (+ (-> s5-0 vector 0 z) -8192))) + (set! (-> s5-0 vector 1 z) (the-as int (+ (-> s5-0 vector 1 z) -8192))) + (set! (-> s5-0 vector 2 z) (the-as int (+ (-> s5-0 vector 2 z) -8192))) + (let* ((a1-21 buf) + (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) 96)) + ) + (let ((a1-25 (/ (the-as int (+ (- -16 (the-as int a0-12)) (the-as int (-> buf base)))) 16))) + (cond + ((nonzero? a1-25) + (logior! (-> a0-12 0) (shr (shl a1-25 48) 48)) + (logior! (-> a0-12 1) (shl (shr (shl a1-25 48) 48) 32)) + ) + (else + (set! (-> buf base) a0-12) + ) + ) + ) + ) + (let ((tag-end (-> buf base))) + (let ((pkt2 (the-as dma-packet (-> buf base)))) + (set! (-> pkt2 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt2 vif0) (new 'static 'vif-tag)) + (set! (-> pkt2 vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt2) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + ) + #f + ) + +;; this part is debug only +(when *debug-segment* +;; definition of type debug-line +(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 + ) + +;; definition for method 3 of type debug-line +(defmethod inspect debug-line ((obj debug-line)) + (when (not obj) + (set! obj obj) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" obj 'debug-line) + (format #t "~1Tflags: ~D~%" (-> obj flags)) + (format #t "~1Tbucket: ~D~%" (-> obj bucket)) + (format #t "~1Tv1: #~%" (-> obj v1)) + (format #t "~1Tv2: #~%" (-> obj v2)) + (format #t "~1Tcolor: ~D~%" (-> obj color)) + (format #t "~1Tmode: ~A~%" (-> obj mode)) + (format #t "~1Tcolor2: ~D~%" (-> obj color2)) + (label cfg-4) + obj + ) + +;; definition of type debug-text-3d +(deftype debug-text-3d (structure) + ((flags int32 :offset-assert 0) + (bucket bucket-id :offset-assert 4) + (pos vector :inline :offset-assert 16) + (color font-color :offset-assert 32) + (offset vector2h :inline :offset-assert 36) + (str string :offset-assert 40) + ) + :method-count-assert 9 + :size-assert #x2c + :flag-assert #x90000002c + ) + +;; definition for method 3 of type debug-text-3d +(defmethod inspect debug-text-3d ((obj debug-text-3d)) + (when (not obj) + (set! obj obj) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" obj 'debug-text-3d) + (format #t "~1Tflags: ~D~%" (-> obj flags)) + (format #t "~1Tbucket: ~D~%" (-> obj bucket)) + (format #t "~1Tpos: #~%" (-> obj pos)) + (format #t "~1Tcolor: ~D~%" (-> obj color)) + (format #t "~1Toffset: #~%" (-> obj offset)) + (format #t "~1Tstr: ~A~%" (-> obj str)) + (label cfg-4) + obj + ) + +;; definition of type debug-tracking-thang +(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 + ) + +;; definition for method 3 of type debug-tracking-thang +(defmethod inspect debug-tracking-thang ((obj debug-tracking-thang)) + (when (not obj) + (set! obj obj) + (goto cfg-4) + ) + (format #t "[~8x] ~A~%" obj (-> obj type)) + (format #t "~1Tlength: ~D~%" (-> obj length)) + (format #t "~1Tallocated-length: ~D~%" (-> obj allocated-length)) + (label cfg-4) + obj + ) + +;; 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 () + (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 () + (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 () + (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 () + (dotimes (i (-> *debug-lines-trk* length)) + (let ((line (-> *debug-lines* i))) + (internal-draw-debug-line + (-> line bucket) + (-> line v1) + (-> line v2) + (-> line color) + (-> line mode) + (-> line color2) + ) + ) + ) + (dotimes (j (-> *debug-text-3d-trk* length)) + (let ((text-3d (-> *debug-text-3ds* j))) + (internal-draw-debug-text-3d + (-> text-3d bucket) + (-> text-3d str) + (-> text-3d pos) + (-> text-3d color) + (-> text-3d offset) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-line +;; INFO: Used lq/sq +(defun-debug add-debug-line ((enable symbol) + (bucket bucket-id) + (start vector) + (end vector) + (start-color rgba) + (mode symbol) + (end-color rgba) + ) + (when enable + (cond + (*debug-draw-pauseable* + (let ((line (get-debug-line))) + (when line + (set! (-> line bucket) bucket) + (set! (-> line v1 quad) (-> start quad)) + (set! (-> line v2 quad) (-> end quad)) + (set! (-> line color) start-color) + (set! (-> line color2) end-color) + (set! (-> line mode) mode) + ) + ) + ) + (else + (internal-draw-debug-line bucket start end start-color mode end-color) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-line2d +;; INFO: Used lq/sq +(defun-debug add-debug-line2d ((enable symbol) (bucket bucket-id) (start vector) (end vector) (color vector)) + (if (not enable) + (return #f) + ) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (let ((p0 (new 'stack 'vector4w)) + (p1 (new 'stack 'vector4w)) + ) + (set! (-> p0 quad) (-> start quad)) + (set! (-> p1 quad) (-> end quad)) + (set! (-> p0 x) (* (+ (-> p0 x) 2048) 16)) + (set! (-> p0 y) (* -16 (- 2048 (-> p0 y)))) + (set! (-> p0 z) #x7fffff) + (set! (-> p1 x) (* (+ (-> p1 x) 2048) 16)) + (set! (-> p1 y) (* -16 (- 2048 (-> p1 y)))) + (set! (-> p1 z) #x7fffff) + (let ((a0-18 (the-as (pointer uint64) (-> buf base)))) + (let* ((a1-7 buf) + (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 buf) + (giftag (the-as gs-gif-tag (-> a1-8 base))) + ) + (set! (-> giftag 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! (-> giftag 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 giftag) 16)) + ) + (let* ((a1-9 buf) + (v0 (the-as vector4w-2 (-> a1-9 base))) + ) + (set! (-> v0 vector 0 quad) (-> color quad)) + (set! (-> v0 vector 1 quad) (-> p0 quad)) + (set! (-> a1-9 base) (&+ (the-as pointer v0) 32)) + ) + (let* ((a1-10 buf) + (v1 (the-as vector4w-2 (-> a1-10 base))) + ) + (set! (-> v1 vector 0 quad) (-> color quad)) + (set! (-> v1 vector 1 quad) (-> p1 quad)) + (set! (-> a1-10 base) (&+ (the-as pointer v1) 32)) + ) + (let ((a1-14 (/ (the-as int (+ (- -16 (the-as int a0-18)) (the-as int (-> buf base)))) 16))) + (cond + ((nonzero? a1-14) + (logior! (-> a0-18 0) (shr (shl a1-14 48) 48)) + (logior! (-> a0-18 1) (shl (shr (shl a1-14 48) 48) 32)) + ) + (else + (set! (-> buf base) a0-18) + ) + ) + ) + ) + ) + (let ((tag-end (-> buf base))) + (let ((v1-12 (the-as dma-packet (-> buf 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! (-> buf base) (&+ (the-as pointer v1-12) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-box +;; INFO: Used lq/sq +(defun-debug add-debug-box ((enable symbol) (bucket bucket-id) (c1 vector) (c2 vector) (color rgba)) + (let ((p0 (new-stack-vector0))) + (set! (-> p0 quad) (-> c1 quad)) + (let ((p1 (new-stack-vector0))) + (set! (-> p1 quad) (-> c1 quad)) + (when enable + (set! (-> p1 x) (-> c2 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 x) (-> c1 x)) + (set! (-> p1 y) (-> c2 y)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 y) (-> c1 y)) + (set! (-> p1 z) (-> c2 z)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p0 y) (-> c2 y)) + (set! (-> p1 y) (-> c2 y)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 z) (-> c1 z)) + (set! (-> p1 x) (-> c2 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 y) (-> c1 y)) + (set! (-> p0 x) (-> c2 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p0 quad) (-> c2 quad)) + (set! (-> p1 quad) (-> c2 quad)) + (set! (-> p1 x) (-> c1 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 x) (-> c2 x)) + (set! (-> p1 y) (-> c1 y)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 y) (-> c2 y)) + (set! (-> p1 z) (-> c1 z)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p0 y) (-> c1 y)) + (set! (-> p1 y) (-> c1 y)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 z) (-> c2 z)) + (set! (-> p1 x) (-> c1 x)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! (-> p1 y) (-> c2 y)) + (set! (-> p0 x) (-> c1 x)) + (add-debug-line #t bucket p0 p1 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) (trans matrix) (color rgba)) + (b! (not enable) cfg-5 :delay (nop!)) + (let ((points (new 'stack-no-clear 'inline-array 'vector 8))) + (let ((corners (new 'stack-no-clear 'inline-array 'vector 2)) + (point (new 'stack-no-clear 'vector)) + ) + (set! (-> corners 0 quad) (-> box min quad)) + (set! (-> corners 1 quad) (-> box max quad)) + (set! (-> point w) 1.0) + (dotimes (i 8) + (set! (-> point x) (-> corners (logand i 1) x)) + (set! (-> point y) (-> corners (logand (/ i 2) 1) y)) + (set! (-> point z) (-> corners (logand (/ i 4) 1) z)) + (let ((a0-5 (-> points i))) + (vector-matrix*! a0-5 point trans) + ) + ) + ) + (add-debug-line #t bucket (-> points 0) (-> points 1) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 1) (-> points 3) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 3) (-> points 2) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 2) (-> points 0) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 4) (-> points 5) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 5) (-> points 7) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 7) (-> points 6) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 6) (-> points 4) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 0) (-> points 4) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 1) (-> points 5) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 3) (-> points 7) color #f (the-as rgba -1)) + (add-debug-line #t bucket (-> points 2) (-> points 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) (position vector) (color rgba)) + (if (not enable) + (return #f) + ) + (let ((p0 (new-stack-vector0)) + (p1 (new-stack-vector0)) + ) + (vector+! p0 position (new 'static 'vector :x -1228.8)) + (vector+! p1 position (new 'static 'vector :x 1228.8)) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (vector+! p0 position (new 'static 'vector :z -1228.8)) + (vector+! p1 position (new 'static 'vector :z 1228.8)) + (add-debug-line #t bucket p0 p1 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) (position vector) (radius float)) + (if (not enable) + (return #f) + ) + (let ((p0 (new-stack-vector0)) + (p1 (new-stack-vector0)) + ) + (let ((a1-1 p0) + (v1-2 position) + (a0-1 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-1 x) (- radius)) + (set! (-> a0-1 y) 0.0) + (set! (-> a0-1 z) 0.0) + (set! (-> a0-1 w) 1.0) + (vector+! a1-1 v1-2 a0-1) + ) + (let ((a1-3 p1) + (v1-3 position) + (a0-2 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-2 x) radius) + (set! (-> a0-2 y) 0.0) + (set! (-> a0-2 z) 0.0) + (set! (-> a0-2 w) 1.0) + (vector+! a1-3 v1-3 a0-2) + ) + (add-debug-line #t bucket p0 p1 *color-red* #f (the-as rgba -1)) + (let ((a1-6 p0) + (v1-4 position) + (a0-4 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-4 x) 0.0) + (set! (-> a0-4 y) (- radius)) + (set! (-> a0-4 z) 0.0) + (set! (-> a0-4 w) 1.0) + (vector+! a1-6 v1-4 a0-4) + ) + (let ((a1-8 p1) + (v1-5 position) + (a0-5 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-5 x) 0.0) + (set! (-> a0-5 y) radius) + (set! (-> a0-5 z) 0.0) + (set! (-> a0-5 w) 1.0) + (vector+! a1-8 v1-5 a0-5) + ) + (add-debug-line #t bucket p0 p1 *color-green* #f (the-as rgba -1)) + (let ((a1-11 p0) + (v1-6 position) + (a0-7 (new 'stack-no-clear 'vector)) + ) + (set! (-> a0-7 x) 0.0) + (set! (-> a0-7 y) 0.0) + (set! (-> a0-7 z) (- radius)) + (set! (-> a0-7 w) 1.0) + (vector+! a1-11 v1-6 a0-7) + ) + (let ((a0-8 p1) + (v1-7 (new 'stack-no-clear 'vector)) + ) + (set! (-> v1-7 x) 0.0) + (set! (-> v1-7 y) 0.0) + (set! (-> v1-7 z) radius) + (set! (-> v1-7 w) 1.0) + (vector+! a0-8 position v1-7) + ) + (add-debug-line #t bucket p0 p1 *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) + (position vector) + (color font-color) + (screen-offset vector2h) + ) + (when enable + (cond + (*debug-draw-pauseable* + (let ((v1-2 (get-debug-text-3d))) + (when v1-2 + (set! (-> v1-2 flags) 0) + (set! (-> v1-2 bucket) bucket) + (set! (-> v1-2 pos quad) (-> position quad)) + (cond + (screen-offset + (set! (-> v1-2 offset x) (the-as int (-> screen-offset x))) + (set! (-> v1-2 offset y) (the-as int (-> screen-offset y))) + ) + (else + (set! (-> v1-2 offset x) 0) + (set! (-> v1-2 offset y) 0) + 0 + ) + ) + (set! (-> v1-2 color) color) + (let ((a0-6 0) + (a1-2 (-> text 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)) + ) + 0 + ) + ) + ) + (else + (internal-draw-debug-text-3d bucket text position color (cond + (screen-offset + (empty) + screen-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) (position vector) (radius meters) (trans matrix) (color 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 enable + (.lvf vf5 (&-> position quad)) + (.lvf vf1 (&-> trans vector 0 quad)) + (.lvf vf2 (&-> trans vector 1 quad)) + (.lvf vf3 (&-> trans vector 2 quad)) + (.lvf vf4 (&-> trans 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 ((position-transformed (new 'stack-no-clear 'vector))) + (.svf (&-> position-transformed quad) vf5) + (add-debug-sphere enable bucket position-transformed radius color) + ) + ) + #f + ) + ) + +;; definition (debug) for function add-debug-sphere +(defun-debug add-debug-sphere ((enable symbol) (bucket bucket-id) (position vector) (radius meters) (color rgba)) + (if enable + (add-debug-sphere-from-table bucket position radius color 6) + ) + #f + ) + +;; definition (debug) for function add-debug-text-sphere +(defun-debug add-debug-text-sphere ((enable symbol) (bucket bucket-id) (position vector) (radius meters) (text string) (color rgba)) + (add-debug-sphere enable bucket position radius color) + (add-debug-text-3d enable bucket text position (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) (origins (inline-array vector)) (count int) (color rgba)) + (when enable + (let ((origin (-> origins 0))) + (countdown (i count) + (add-debug-sphere #t bucket origin (-> origin w) color) + (&+! origin 16) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-line-sphere +;; INFO: Used lq/sq +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Stack slot offset 32 signed mismatch +;; WARN: Return type mismatch int vs none. +(defun-debug add-debug-line-sphere ((enable symbol) (bucket bucket-id) (position vector) (forward vector) (arg4 float) (color rgba)) + (local-vars + (var-bucket bucket-id) + (var-position vector) + (var-forward vector) + (var-arg4 float) + (var-color rgba) + (mat matrix) + (forward-length float) + ) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + ) + (init-vf0-vector) + (b! (not enable) cfg-8 :delay (nop!)) + (set! var-bucket bucket) + (set! var-position position) + (set! var-forward forward) + (set! var-arg4 arg4) + (set! var-color color) + (set! mat (new 'stack-no-clear 'matrix)) + (set! forward-length (vector-length var-forward)) + (let ((mat-forward (new 'stack-no-clear 'vector)) + (mat-down (new 'stack-no-clear 'vector)) + ) + (vector-normalize-copy! mat-forward var-forward 1.0) + (vector-reset! mat-down) + (let* ((f0-2 (-> mat-forward y)) + (f0-4 (* f0-2 f0-2)) + (f1-0 (-> mat-forward z)) + ) + (if (< f0-4 (* f1-0 f1-0)) + (set! (-> mat-down y) -1.0) + (set! (-> mat-down z) -1.0) + ) + ) + (forward-down->inv-matrix mat mat-forward mat-down) + ) + (set! (-> mat trans quad) (-> var-position quad)) + (set! (-> mat 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) (* var-arg4 (-> s5-1 2 y))) + (set! (-> s1-0 y) (* var-arg4 (-> gp-1 2 y))) + (vector-matrix*! s3-0 s1-0 mat) + (dotimes (i 10) + (set! (-> s4-0 quad) (-> s3-0 quad)) + (set! (-> s1-0 x) (* var-arg4 (-> (&-> s5-1 0 data i) 0))) + (set! (-> s1-0 y) (* var-arg4 (-> (&-> gp-1 0 data i) 0))) + (vector-matrix*! s3-0 s1-0 mat) + (add-debug-line #t var-bucket s4-0 s3-0 var-color #f (the-as rgba -1)) + (let ((v1-26 s2-0)) + (let ((a0-10 s3-0) + (a1-7 (-> mat vector 2)) + (f0-18 forward-length) + ) + (.lvf vf2 (&-> a1-7 quad)) + (.lvf vf1 (&-> a0-10 quad)) + (let ((a0-11 f0-18)) + (.mov vf3 a0-11) + ) + ) + (.add.x.vf vf4 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf2 vf3) + (.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111) + (.svf (&-> v1-26 quad) vf4) + ) + (add-debug-line #t var-bucket s3-0 s2-0 var-color #f (the-as rgba -1)) + (let ((v1-27 s4-0)) + (let ((a0-13 s4-0) + (a1-10 (-> mat vector 2)) + (f0-19 forward-length) + ) + (.lvf vf2 (&-> a1-10 quad)) + (.lvf vf1 (&-> a0-13 quad)) + (let ((a0-14 f0-19)) + (.mov vf3 a0-14) + ) + ) + (.add.x.vf vf4 vf0 vf0 :mask #b1000) + (.mul.x.vf acc vf2 vf3) + (.add.mul.w.vf vf4 vf1 vf0 acc :mask #b111) + (.svf (&-> v1-27 quad) vf4) + ) + (add-debug-line #t var-bucket s4-0 s2-0 var-color #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) (position vector) (radius float) (color rgba) (orientation matrix)) + (local-vars (i int) (sv-64 vector) (sv-80 vector)) + "note: you may pass #f for orientation" + (if (not enable) + (return #f) + ) + (let ((angle 0.0) + (line-start (new-stack-vector0)) + (line-end (new-stack-vector0)) + ) + (set! i 0) + (while (< i 12) + (set! sv-64 line-start) + (set! (-> sv-64 x) (* radius (cos angle))) + (set! (-> sv-64 y) 0.0) + (set! (-> sv-64 z) (* radius (sin angle))) + (set! (-> sv-64 w) 1.0) + (set! angle (+ 5461.3335 angle)) + (set! sv-80 line-end) + (set! (-> sv-80 x) (* radius (cos angle))) + (set! (-> sv-80 y) 0.0) + (set! (-> sv-80 z) (* radius (sin angle))) + (set! (-> sv-80 w) 1.0) + (when orientation + (vector-matrix*! line-start line-start orientation) + (vector-matrix*! line-end line-end orientation) + ) + (vector+! line-start line-start position) + (vector+! line-end line-end position) + (add-debug-line #t bucket line-start line-end color #f (the-as rgba -1)) + (set! i (+ i 1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-vector +;; INFO: Used lq/sq +(defun-debug add-debug-vector ((enable symbol) (bucket bucket-id) (position vector) (direction vector) (length meters) (color rgba)) + (if (not enable) + (return #f) + ) + (let ((line-end (new-stack-vector0))) + (set! (-> line-end x) (+ (-> position x) (* (-> direction x) length))) + (set! (-> line-end y) (+ (-> position y) (* (-> direction y) length))) + (set! (-> line-end z) (+ (-> position z) (* (-> direction z) length))) + (add-debug-line #t bucket position line-end 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) (line-length meters)) + (add-debug-vector + enable + bucket + (-> mat trans) + (the-as vector (-> mat vector)) + line-length + (new 'static 'rgba :r #xff :a #x80) + ) + (add-debug-vector + enable + bucket + (-> mat trans) + (-> mat vector 1) + line-length + (new 'static 'rgba :g #xff :a #x80) + ) + (add-debug-vector + enable + bucket + (-> mat trans) + (-> mat vector 2) + line-length + (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) (position vector)) + (add-debug-vector + enable + bucket + position + (the-as vector (-> mat vector)) + (meters 2.0) + (new 'static 'rgba :r #xff :a #x80) + ) + (add-debug-vector enable bucket position (-> mat vector 1) (meters 2.0) (new 'static 'rgba :g #xff :a #x80)) + (add-debug-vector enable bucket position (-> mat vector 2) (meters 2.0) (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) (position vector) (quat quaternion)) + (when enable + (let ((mat (quaternion->matrix (new 'stack-no-clear 'matrix) quat))) + (add-debug-rot-matrix enable bucket mat position) + ) + ) + 0 + (none) + ) + +;; definition (debug) for function add-debug-cspace +(defun-debug add-debug-cspace ((enable symbol) (bucket bucket-id) (csp cspace)) + (add-debug-matrix enable bucket (-> csp bone transform) (meters 2.0)) + csp + ) + +;; 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 ((enable symbol) (bucket bucket-id) (position vector) (angle float) (line-length float) (color rgba)) + (local-vars (var-angle float)) + (set! var-angle angle) + (let ((var-line-length line-length) + (var-color color) + ) + (if (not enable) + (return #f) + ) + (let ((line-start (new-stack-vector0))) + (set-vector! + line-start + (+ (-> position x) (* (sin var-angle) var-line-length)) + (-> position y) + (+ (-> position z) (* (cos var-angle) var-line-length)) + 1.0 + ) + (add-debug-line enable bucket line-start position var-color #f (the-as rgba -1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-arc +;; INFO: Used lq/sq +(defun-debug add-debug-arc ((enable symbol) + (bucket bucket-id) + (position vector) + (start-angle float) + (end-angle float) + (radius float) + (color rgba) + (orientation matrix) + ) + (local-vars (line-start vector) (line-end vector) (i int) (sv-96 vector) (sv-112 vector)) + "note: you may pass #f for orientation" + (if (not enable) + (return #f) + ) + (let ((angle start-angle)) + (set! line-start (new 'stack-no-clear 'vector)) + (set! (-> line-start quad) (the-as uint128 0)) + (set! line-end (new 'stack-no-clear 'vector)) + (set! (-> line-end quad) (the-as uint128 0)) + (set! i 0) + (while (< i 12) + (set! sv-96 line-start) + (set! (-> sv-96 x) (* radius (sin angle))) + (set! (-> sv-96 y) 0.0) + (set! (-> sv-96 z) (* radius (cos angle))) + (set! (-> sv-96 w) 1.0) + (+! angle (the float (/ (the int (- end-angle start-angle)) 12))) + (set! sv-112 line-end) + (set! (-> sv-112 x) (* radius (sin angle))) + (set! (-> sv-112 y) 0.0) + (set! (-> sv-112 z) (* radius (cos angle))) + (set! (-> sv-112 w) 1.0) + (when orientation + (vector-matrix*! line-start line-start orientation) + (vector-matrix*! line-end line-end orientation) + ) + (vector+! line-start line-start position) + (vector+! line-end line-end position) + (add-debug-line #t bucket line-start line-end color #f (the-as rgba -1)) + (cond + ((zero? i) + (add-debug-line #t bucket line-start position color #f (the-as rgba -1)) + ) + ((= i 11) + (add-debug-line #t bucket line-end position color #f (the-as rgba -1)) + ) + ) + (set! i (+ i 1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-curve +;; INFO: Used lq/sq +(defun-debug add-debug-curve ((enable symbol) + (bucket bucket-id) + (cverts (inline-array vector)) + (num-cverts int) + (knots (pointer float)) + (num-knots int) + (color rgba) + ) + (local-vars (p1 vector) (iterations int) (i int)) + (if (not enable) + (return #f) + ) + (let ((p0 (new-stack-vector0))) + (set! p1 (new 'stack-no-clear 'vector)) + (set! (-> p1 quad) (the-as uint128 0)) + (set! iterations (* num-cverts 4)) + (curve-evaluate! p1 (-> knots 0) cverts num-cverts knots num-knots) + (set! i 0) + (while (< i iterations) + (set! (-> p0 quad) (-> p1 quad)) + (curve-evaluate! p1 (/ (the float (+ i 1)) (the float iterations)) cverts num-cverts knots num-knots) + (add-debug-line #t bucket p0 p1 color #f (the-as rgba -1)) + (set! i (+ i 1)) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-curve2 +(defun-debug add-debug-curve2 ((enable symbol) (bucket bucket-id) (curve curve) (color rgba) (arg4 symbol)) + (if enable + (add-debug-curve + #t + bucket + (-> curve cverts) + (-> curve num-cverts) + (-> curve knots) + (-> curve num-knots) + color + ) + ) + #f + ) + +;; definition (debug) for function add-debug-points +;; INFO: Used lq/sq +(defun-debug add-debug-points ((enable symbol) + (bucket bucket-id) + (points (inline-array vector)) + (num-points int) + (color rgba) + (y-override float) + (highlight 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)) + (position vector) + ) + (when enable + (dotimes (i num-points) + (set! position (new 'stack-no-clear 'vector)) + (set! (-> position quad) (the-as uint128 0)) + (set! (-> position quad) (-> points i quad)) + (if (!= y-override 0.0) + (set! (-> position y) y-override) + ) + (set! sv-32 add-debug-text-3d) + (set! sv-48 #t) + (set! sv-64 bucket) + (set! sv-80 format) + (let ((a0-5 (clear *temp-string*)) + (a1-1 "~d") + (a2-1 i) + ) + (sv-80 a0-5 a1-1 a2-1) + ) + (let ((a2-2 *temp-string*) + (a3-1 position) + (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 bucket) + (a3-2 (if (= i highlight) + (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80) + color + ) + ) + ) + (t9-3 a0-7 a1-3 position 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 ((enable symbol) (bucket bucket-id) (x int) (y int) (percentage float) (color rgba) (width int) (height int)) + (local-vars (sv-16 int) (sv-32 float)) + (set! sv-16 y) + (set! sv-32 percentage) + (let ((s2-0 color) + (s1-0 width) + (s3-0 height) + ) + (if (not enable) + (return #f) + ) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (draw-sprite2d-xy buf x sv-16 s1-0 s3-0 (new 'static 'rgba :a #x40)) + (draw-sprite2d-xy buf x (+ sv-16 2) (the int (* sv-32 (the float s1-0))) (+ s3-0 -4) s2-0) + (let ((tag-end (-> buf base))) + (let ((pkt (the-as dma-packet (-> buf base)))) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt vif0) (new 'static 'vif-tag)) + (set! (-> pkt vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + #f + ) + +;; definition (debug) for function debug-pad-display +;; INFO: Used lq/sq +(defun-debug debug-pad-display ((pad cpad-info)) + (let ((stick-history (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 (i 31) + (let ((a0-3 (-> stick-history i quad))) + (set! (-> stick-history (+ i 1) quad) a0-3) + ) + ) + (set! (-> stick-history 0 x) (* (sin (-> pad stick0-dir)) (-> pad stick0-speed))) + (set! (-> stick-history 0 y) (* (cos (-> pad stick0-dir)) (-> pad stick0-speed))) + (dotimes (j 32) + (let* ((buf (-> *display* frames (-> *display* on-screen) debug-buf)) + (tag-start (-> buf base)) + ) + (draw-sprite2d-xy + buf + (the int (* 120.0 (-> stick-history j x))) + (the int (* 144.0 (-> stick-history j y))) + 10 + 10 + (new 'static 'rgba :a #x80 :r (- 255 (* 7 j))) + ) + (let ((tag-end (-> buf base))) + (let ((pkt (the-as dma-packet (-> buf base)))) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt vif0) (new 'static 'vif-tag)) + (set! (-> pkt vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + (bucket-id bucket-324) + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + ) + #f + ) + +;; definition (debug) for function add-debug-light +;; INFO: Used lq/sq +(defun-debug add-debug-light ((enable symbol) (bucket bucket-id) (light light) (position vector) (text 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 enable) + (return #f) + ) + (when (!= (-> light extra x) 0.0) + (add-debug-vector + enable + bucket + position + (-> light direction) + (meters 3.0) + (new 'static 'rgba :r #xff :g #xff :b #xff :a #x80) + ) + (let ((sphere-pos (new-stack-vector0))) + (let ((v1-3 (-> light direction))) + (let ((a0-3 (* 12288.0 (-> light extra x)))) + (.mov vf7 a0-3) + ) + (.lvf vf5 (&-> v1-3 quad)) + ) + (.lvf vf4 (&-> position 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 (&-> sphere-pos quad) vf6) + (let ((color-rgba (logior (logior (logior (shr (shl (the int (* 128.0 (-> light color w))) 56) 32) + (shr (shl (the int (* 128.0 (-> light color z))) 56) 40) + ) + (shr (shl (the int (* 128.0 (-> light color y))) 56) 48) + ) + (shr (shl (the int (* 128.0 (-> light color x))) 56) 56) + ) + ) + ) + (format (clear *temp-string*) "~S ~,,2f" text (-> light extra x)) + (let ((t0-2 *temp-string*)) + (add-debug-text-sphere enable bucket sphere-pos (* 2048.0 (-> light extra x)) t0-2 (the-as rgba color-rgba)) + ) + ) + ) + ) + #f + ) + ) + +;; definition (debug) for function add-debug-lights +(defun-debug add-debug-lights ((enable symbol) (bucket bucket-id) (lights (inline-array light)) (position vector)) + (if (not enable) + (return #f) + ) + (add-debug-light enable bucket (-> lights 0) position "dir0") + (add-debug-light enable bucket (-> lights 1) position "dir1") + (add-debug-light enable bucket (-> lights 2) position "dir2") + (add-debug-light enable bucket (-> lights 3) position "ambi") + #f + ) + +;; definition (debug) for function drawable-frag-count +(defun-debug drawable-frag-count ((drbl drawable)) + (let ((count 0)) + (cond + ((not drbl) + ) + ((type? drbl drawable-group) + (dotimes (i (-> (the-as drawable-group drbl) length)) + (+! count (drawable-frag-count (-> (the-as drawable-group drbl) data i))) + ) + ) + (else + (+! count 1) + ) + ) + count + ) + ) + +;; definition for method 3 of type debug-vertex-stats +;; INFO: this function exists in multiple non-identical object files +(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 + ) + +;; definition (debug) for function history-init +(defun-debug history-init ((history pos-history) (num-points int)) + (set! (-> history num-points) num-points) + (set! (-> history points) (the-as (inline-array vector) #f)) + history + ) + +;; definition (debug) for function history-draw-and-update +;; INFO: Used lq/sq +(defun-debug history-draw-and-update ((history pos-history) (draw symbol) (pos vector)) + (if (and draw (not (-> history points))) + (set! (-> history points) (the-as (inline-array vector) (malloc 'debug (* (-> history num-points) 16)))) + ) + (when (-> history points) + (set! (-> history points (-> history h-first) quad) (-> pos quad)) + (+! (-> history h-first) 1) + (when (>= (-> history h-first) (-> history num-points)) + (set! (-> history h-first) 0) + 0 + ) + ) + (when draw + (dotimes (i (+ (-> history num-points) -1)) + (if (!= (+ i 1) (-> history h-first)) + (add-debug-line + #t + (bucket-id bucket-318) + (-> history points i) + (-> history points (+ i 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 ((pos (new-stack-vector0)) + (rot (new-stack-matrix0)) + ) + (set! (-> pos x) -666764.4) + (set! (-> pos y) 21102.984) + (set! (-> pos z) 51613.348) + (set! (-> pos w) 1.0) + (set! (-> rot vector 0 x) -0.911) + (set! (-> rot vector 0 y) 0.0) + (set! (-> rot vector 0 z) 0.4122) + (set! (-> rot vector 0 w) 0.0) + (set! (-> rot vector 1 x) -0.0984) + (set! (-> rot vector 1 y) 0.971) + (set! (-> rot vector 1 z) -0.2174) + (set! (-> rot vector 1 w) 0.0) + (set! (-> rot vector 2 x) -0.4003) + (set! (-> rot vector 2 y) -0.2387) + (set! (-> rot vector 2 z) -0.8847) + (set! (-> rot vector 2 w) 0.0) + (set! (-> rot trans x) 0.0) + (set! (-> rot trans y) 0.0) + (set! (-> rot trans z) 0.0) + (set! (-> rot trans w) 1.0) + (debug-set-camera-pos-rot! pos rot) + ) + ) + +;; definition (debug) for function display-file-info +(defun-debug display-file-info () + (when (and *display-file-info* (!= *master-mode* 'menu)) + (dotimes (i (-> *level* length)) + (let ((level (-> *level* level i))) + (when (= (-> level status) 'active) + (let ((bsp (-> level bsp))) + (format *stdcon* "file name: ~S~%" (-> bsp info file-name)) + (format *stdcon* "version: ~D.~D~%" (-> bsp info major-version) (-> bsp info minor-version)) + (format *stdcon* "maya file: ~S~%" (-> bsp info maya-file-name)) + (format *stdcon* "mdb file: ~S~%" (-> bsp info mdb-file-name)) + (format *stdcon* "~S" (-> bsp info tool-debug)) + ) + ) + ) + ) + ) + 0 + ) + +;; definition (debug) for function add-debug-cursor +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun-debug add-debug-cursor ((enable symbol) (bucket bucket-id) (x int) (y int) (arg4 int)) + (when enable + (let* ((buf (-> *display* frames (-> *display* on-screen) global-buf)) + (tag-start (-> buf base)) + ) + (set! (-> (new 'stack-no-clear 'vector) quad) (the-as uint128 0)) + (let ((v1-7 arg4)) + (draw-string-xy + "X" + buf + (+ x -5) + (+ y -4) + (the-as font-color (cond + ((= v1-7 1) + 3 + ) + ((= v1-7 2) + 5 + ) + ((= v1-7 4) + 6 + ) + (else + 0 + ) + ) + ) + (font-flags shadow) + ) + ) + (let ((tag-end (-> buf base))) + (let ((pkt (the-as dma-packet (-> buf base)))) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt vif0) (new 'static 'vif-tag)) + (set! (-> pkt vif1) (new 'static 'vif-tag)) + (set! (-> buf base) (&+ (the-as pointer pkt) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) bucket-group) + bucket + tag-start + (the-as (pointer dma-tag) tag-end) + ) + ) + ) + ) + 0 + (none) + ) + +;; this part is debug only +(when *debug-segment* +;; definition for symbol *boundary-polygon*, type none +(define *boundary-polygon* (the-as none (malloc 'debug 768))) + +) +;; definition (debug) for function init-boundary-regs +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition (debug) for function add-boundary-shader +;; WARN: Return type mismatch pointer vs none. +(defun-debug add-boundary-shader ((tex-id texture-id) (buf dma-buffer)) + (let ((tex (lookup-texture-by-id tex-id))) + (when tex + (let* ((v1-0 buf) + (giftag (the-as gs-gif-tag (-> v1-0 base))) + ) + (set! (-> giftag tag) (new 'static 'gif-tag64 :nloop #x1 :nreg #x5)) + (set! (-> giftag 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 giftag) 16)) + ) + (let ((shader (the-as adgif-shader (-> buf base)))) + (adgif-shader<-texture-simple! shader tex) + (set! (-> shader alpha) (new 'static 'gs-alpha :b #x1 :d #x1)) + (set! (-> shader tex0 tfx) 0) + (set! (-> shader tex1 mmag) 0) + (set! (-> shader clamp) (new 'static 'gs-clamp)) + ) + 0 + (&+! (-> buf base) 80) + ) + ) + (none) + ) + +;; definition (debug) for function draw-boundary-polygon +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition (debug) for function render-boundary-quad +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition (debug) for function render-boundary-tri +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition (debug) for function add-debug-bound-internal +;; ERROR: function has no type analysis. Cannot decompile. + +;; definition (debug) for function add-debug-bound +;; ERROR: function has no type analysis. Cannot decompile. + +;; 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? +;; ERROR: function was not converted to expressions. Cannot decompile. + + + + diff --git a/test/decompiler/reference/jak2/engine/gfx/sprite/particles/sparticle-launcher_REF.gc b/test/decompiler/reference/jak2/engine/gfx/sprite/particles/sparticle-launcher_REF.gc index 4270b943ff..667287fa31 100644 --- a/test/decompiler/reference/jak2/engine/gfx/sprite/particles/sparticle-launcher_REF.gc +++ b/test/decompiler/reference/jak2/engine/gfx/sprite/particles/sparticle-launcher_REF.gc @@ -1283,7 +1283,7 @@ (-> s5-1 w) (new 'static 'rgba :g #xff :a #x80) ) - (add-debug-matrix *display-sprite-marks* (bucket-id bucket-324) (-> obj origin) 8192.0) + (add-debug-matrix *display-sprite-marks* (bucket-id bucket-324) (-> obj origin) (meters 2.0)) ) (sphere-in-view-frustum? (the-as sphere s5-1)) ) diff --git a/test/decompiler/reference/jak2/engine/math/vector-h_REF.gc b/test/decompiler/reference/jak2/engine/math/vector-h_REF.gc index afd65819c3..ae7a0f7bda 100644 --- a/test/decompiler/reference/jak2/engine/math/vector-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/math/vector-h_REF.gc @@ -530,9 +530,9 @@ (goto cfg-4) ) (format #t "[~8x] ~A~%" obj 'vector4w-2) - (format #t "~1Tdata[8] @ #x~X~%" (-> obj data)) - (format #t "~1Tquad[2] @ #x~X~%" (-> obj data)) - (format #t "~1Tvector[2] @ #x~X~%" (-> obj data)) + (format #t "~1Tdata[8] @ #x~X~%" (-> obj vector)) + (format #t "~1Tquad[2] @ #x~X~%" (-> obj vector)) + (format #t "~1Tvector[2] @ #x~X~%" (-> obj vector)) (label cfg-4) obj ) @@ -555,9 +555,9 @@ (goto cfg-4) ) (format #t "[~8x] ~A~%" obj 'vector4w-3) - (format #t "~1Tdata[12] @ #x~X~%" (-> obj data)) - (format #t "~1Tquad[3] @ #x~X~%" (-> obj data)) - (format #t "~1Tvector[3] @ #x~X~%" (-> obj data)) + (format #t "~1Tdata[12] @ #x~X~%" (-> obj vector)) + (format #t "~1Tquad[3] @ #x~X~%" (-> obj vector)) + (format #t "~1Tvector[3] @ #x~X~%" (-> obj vector)) (label cfg-4) obj ) diff --git a/test/offline/config/jak2/config.jsonc b/test/offline/config/jak2/config.jsonc index f0a41c1a89..f8eabe3331 100644 --- a/test/offline/config/jak2/config.jsonc +++ b/test/offline/config/jak2/config.jsonc @@ -41,6 +41,8 @@ "(method 3 sprite-aux-list)", // sprite-distort "sprite-draw-distorters", // uses clipping flag. + // debug + "(method 3 debug-vertex-stats)", // multiple defined // asm, weird vector dot "(method 17 trsqv)", // history - rgba issues