diff --git a/decompiler/IR2/Form.cpp b/decompiler/IR2/Form.cpp index c719792d23..a846320d52 100644 --- a/decompiler/IR2/Form.cpp +++ b/decompiler/IR2/Form.cpp @@ -454,6 +454,13 @@ goos::Object SetFormFormElement::to_form_internal(const Env& env) const { goos::Object SetFormFormElement::to_form_for_define(const Env& env) const { if (m_cast_for_define) { + // for vu-function, we just put a 0. These aren't supported + if (*m_cast_for_define == TypeSpec("vu-function")) { + return pretty_print::build_list( + fmt::format("define"), m_dst->to_form(env), + pretty_print::build_list(fmt::format("the-as {}", m_cast_for_define->print()), + pretty_print::to_symbol("0"))); + } return pretty_print::build_list( fmt::format("define"), m_dst->to_form(env), pretty_print::build_list(fmt::format("the-as {}", m_cast_for_define->print()), diff --git a/decompiler/IR2/bitfields.cpp b/decompiler/IR2/bitfields.cpp index c426fe3140..04262241a5 100644 --- a/decompiler/IR2/bitfields.cpp +++ b/decompiler/IR2/bitfields.cpp @@ -647,7 +647,14 @@ BitFieldDef BitFieldDef::from_constant(const BitFieldConstantDef& constant, Form BitFieldDef bfd; bfd.field_name = constant.field_name; bfd.is_signed = constant.is_signed; - if (constant.enum_constant) { + if (constant.nested_field) { + std::vector defs; + for (auto& x : constant.nested_field->fields) { + defs.push_back(BitFieldDef::from_constant(x, pool)); + } + bfd.value = pool.alloc_single_element_form( + nullptr, constant.nested_field->field_type, defs); + } else if (constant.enum_constant) { bfd.value = pool.alloc_single_element_form(nullptr, *constant.enum_constant); } else { diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 586bab7b6d..4b6c78cac4 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -530,6 +530,7 @@ (water-tex1 60) ;; merc1 61 ;; generic1 62 + (depth-cue 64) (bucket-65 65) (sprite 66) ;; debug spheres? 67 @@ -5075,7 +5076,7 @@ (define-extern math-cam-start-smoothing (function float float quaternion)) (define-extern move-target-from-pad (function transform int transform)) (define-extern transform-point-vector! (function vector vector symbol)) -(define-extern transform-point-qword! (function vector vector symbol)) +(define-extern transform-point-qword! (function vector4w vector symbol)) (define-extern transform-point-vector-scale! (function vector vector float)) (define-extern init-for-transform (function matrix none)) @@ -15698,7 +15699,7 @@ ;; - Functions -(define-extern depth-cue-draw-front function) +(define-extern depth-cue-draw-front (function dma-buffer int float float uint int none)) (define-extern depth-cue-set-stencil function) (define-extern depth-cue-draw-depth function) (define-extern depth-cue-calc-z function) @@ -15706,7 +15707,7 @@ ;; - Unknowns -;;(define-extern *depth-cue-work* object) ;; unknown type +(define-extern *depth-cue-work* depth-cue-work) ;; ---------------------- diff --git a/decompiler/config/jak1_ntsc_black_label/hacks.jsonc b/decompiler/config/jak1_ntsc_black_label/hacks.jsonc index 523f54652c..79b444cd10 100644 --- a/decompiler/config/jak1_ntsc_black_label/hacks.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/hacks.jsonc @@ -97,10 +97,6 @@ // vector "vector=", // asm branching - // texture - // "adgif-shader<-texture-with-update!", // F: asm branching - // "(method 9 texture-page-dir)", - // collide-mesh-h "(method 11 collide-mesh-cache)", @@ -117,6 +113,9 @@ "clear-frame-accumulator", // F: asm branching "cspace<-parented-transformq-joint!", + // sprite + "add-to-sprite-aux-list", // fine, but don't know types yet. + // merc-blend-shape "setup-blerc-chains-for-one-fragment", // F: asm branching "blerc-execute", // F: asm branching @@ -526,8 +525,6 @@ "(method 12 perf-stat)": [0], "(method 11 perf-stat)": [0], - "(method 20 actor-link-info)": [2], - "(method 21 actor-link-info)": [2], "raw-ray-sphere-intersect": [0, 1, 2, 3, 4, 5], "ray-cylinder-intersect": [0, 1, 2, 3, 4, 5], "ray-triangle-intersect": [0, 1, 2, 3, 4], diff --git a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc index ba55d58085..992ae7b743 100644 --- a/decompiler/config/jak1_ntsc_black_label/label_types.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/label_types.jsonc @@ -1282,7 +1282,8 @@ ["L509", "(inline-array list-field)", true, 12], ["L123", "_lambda_", true], ["L119", "_lambda_", true], - ["L86", "_lambda_", true] + ["L86", "_lambda_", true], + ["L652", "float", true] ], // please do not add things after this entry! git is dumb. diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index 6de7e784a9..47c8233ad8 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -1266,20 +1266,20 @@ [23, "v1", "float"], [36, "v1", "uint"] ], - + "(method 0 anim-test-obj)": [ [9, "s4", "anim-test-obj"], [10, "s4", "anim-test-obj"], [13, "s4", "anim-test-obj"], [15, "s4", "anim-test-obj"] ], - + "(method 0 anim-test-sequence)": [ [8, "s5", "anim-test-sequence"], [11, "s5", "anim-test-sequence"], [13, "s5", "anim-test-sequence"] ], - + "(method 0 anim-test-seq-item)": [ [8, "v1", "anim-test-seq-item"], [10, "v0", "anim-test-seq-item"], @@ -1287,7 +1287,7 @@ [14, "v0", "anim-test-seq-item"], [17, "v0", "anim-test-seq-item"] ], - + "(method 3 anim-tester)": [ [12, "s5", "anim-test-obj"], [15, "s5", "anim-test-obj"], @@ -1311,7 +1311,7 @@ [126, "s3", "anim-test-seq-item"], [128, "s3", "anim-test-seq-item"] ], - + "anim-test-obj-item-valid?": [ [5, "s5", "anim-test-sequence"], [12, "s5", "anim-test-sequence"], @@ -1322,7 +1322,7 @@ [26, "v1", "anim-test-seq-item"], [28, "v1", "anim-test-seq-item"] ], - + "anim-test-obj-remove-invalid": [ [84, "v1", "anim-test-sequence"], [88, "v1", "anim-test-sequence"], @@ -1350,7 +1350,7 @@ [36, "s3", "anim-test-seq-item"], [61, "a0", "anim-test-seq-item"] ], - + "anim-tester-reset": [ [14, "v1", "anim-test-obj"], [30, "v1", "anim-test-obj"], @@ -1359,12 +1359,12 @@ [43, "v1", "anim-test-obj"], [[50, 53], "v1", "anim-test-obj"] ], - + "anim-tester-save-all-objects": [ [[4, 19], "gp", "anim-test-obj"], [17, "v1", "anim-test-obj"] ], - + "anim-tester-save-object-seqs": [ [63, "s5", "anim-test-sequence"], [69, "s5", "anim-test-sequence"], @@ -1386,7 +1386,7 @@ [121, "v1", "anim-test-seq-item"], [122, "s4", "anim-test-seq-item"] ], - + "anim-test-obj-list-handler": [ [25, "s5", "anim-test-obj"], [31, "s5", "anim-test-obj"], @@ -1394,7 +1394,7 @@ [166, "s5", "anim-test-obj"], [112, "v1", "anim-tester"] ], - + "anim-test-anim-list-handler": [ [2, "s5", "anim-test-obj"], [25, "s5", "anim-test-obj"], @@ -1413,7 +1413,7 @@ [171, "v1", "anim-test-obj"], [173, "v1", "anim-test-obj"] ], - + "anim-test-sequence-list-handler": [ [2, "s5", "anim-test-sequence"], [25, "s5", "anim-test-sequence"], @@ -1429,7 +1429,7 @@ [146, "v1", "anim-test-sequence"], [151, "v1", "anim-test-sequence"] ], - + "anim-test-edit-sequence-list-handler": [ [[122, 965], "s4", "anim-test-sequence"], [129, "v1", "glst-named-node"], @@ -1442,21 +1442,21 @@ [491, "s3", "anim-test-seq-item"], [502, "s3", "anim-test-seq-item"] ], - + "anim-tester-interface": [ [[34, 48], "gp", "anim-test-obj"], [[95, 109], "gp", "anim-test-obj"], [[156, 160], "v1", "anim-test-obj"], [[162, 165], "v1", "anim-test-sequence"] ], - + "anim-tester-get-playing-item": [ [7, "v0", "anim-test-seq-item"], [[5, 22], "s5", "anim-test-seq-item"], [21, "v0", "anim-test-seq-item"], [25, "v0", "anim-test-seq-item"] ], - + "anim-tester-add-newobj": [ [[2, 185], "s2", "anim-test-obj"], [[70, 193], "s5", "anim-test-obj"], @@ -1466,20 +1466,16 @@ [164, "a0", "art-joint-anim"], [170, "a0", "art-joint-anim"] ], - - "anim-tester-start": [ - [20, "t9", "(function process function none)"] - ], - + + "anim-tester-start": [[20, "t9", "(function process function none)"]], + "anim-tester-set-name": [ [[34, 51], "s3", "anim-test-obj"], [[40, 63], "s5", "anim-test-sequence"] ], - - "anim-tester-add-sequence": [ - [[33, 102], "s5", "anim-test-obj"] - ], - + + "anim-tester-add-sequence": [[[33, 102], "s5", "anim-test-obj"]], + "(anon-function 11 anim-tester)": [ [[23, 113], "s4", "anim-test-obj"], [[83, 338], "gp", "anim-test-sequence"], @@ -1579,5 +1575,17 @@ [[62, 67], "a1", "dma-packet"] ], + "sprite-draw-distorters": [ + [[70, 90], "a0", "vector"], + [72, "v1", "vector"], + [93, "v1", "vector"], + [96, "v1", "vector"], + [115, "v1", "(pointer int32)"], + [119, "a0", "(pointer int32)"], + [124, "v1", "vector"], + [154, "v1", "vector"], + [[172, 189], "a1", "dma-packet"] + ], + "placeholder-do-not-add-below": [] } diff --git a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc index 00c4f350ba..67f3e2adf0 100644 --- a/decompiler/config/jak1_ntsc_black_label/var_names.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/var_names.jsonc @@ -2162,6 +2162,7 @@ }, "add-debug-point": { + "args": ["enable-draw", "bucket", "pt"], "vars": { "a0-6": ["a0-6", "(pointer uint64)"], "a0-7": ["a0-7", "dma-packet"], diff --git a/decompiler/util/data_decompile.cpp b/decompiler/util/data_decompile.cpp index d31a4d4ce4..bb037e9e0e 100644 --- a/decompiler/util/data_decompile.cpp +++ b/decompiler/util/data_decompile.cpp @@ -1183,6 +1183,14 @@ std::optional> try_decompile_bitfield_from_int( auto name = decompile_int_enum_from_int(field.type(), ts, bitfield_value); def.enum_constant = fmt::format("({} {})", field.type().print(), name); } + + auto nested_bitfield_type = dynamic_cast(ts.lookup_type(field.type())); + if (nested_bitfield_type) { + BitFieldConstantDef::NestedField nested; + nested.field_type = field.type(); + nested.fields = *try_decompile_bitfield_from_int(field.type(), ts, bitfield_value, true); + def.nested_field = nested; + } result.push_back(def); } diff --git a/decompiler/util/data_decompile.h b/decompiler/util/data_decompile.h index 782f71c88a..7063c924dd 100644 --- a/decompiler/util/data_decompile.h +++ b/decompiler/util/data_decompile.h @@ -73,6 +73,13 @@ struct BitFieldConstantDef { u64 value = -1; std::optional enum_constant; std::string field_name; + + struct NestedField { + TypeSpec field_type; + std::vector fields; + }; + + std::optional nested_field; }; template diff --git a/goal_src/engine/camera/math-camera.gc b/goal_src/engine/camera/math-camera.gc index 5da9ba3c09..8648c84998 100644 --- a/goal_src/engine/camera/math-camera.gc +++ b/goal_src/engine/camera/math-camera.gc @@ -439,7 +439,7 @@ ) ) -(defun transform-point-qword! ((arg0 vector) (arg1 vector)) +(defun transform-point-qword! ((arg0 vector4w) (arg1 vector)) "Apply camera transformation to point, returning fixed point 28.4 position" (rlet ((acc :class vf) (Q :class vf) diff --git a/goal_src/engine/debug/debug-sphere.gc b/goal_src/engine/debug/debug-sphere.gc index 96b42fdba7..9bb1c7d506 100644 --- a/goal_src/engine/debug/debug-sphere.gc +++ b/goal_src/engine/debug/debug-sphere.gc @@ -5,7 +5,6 @@ ;; name in dgo: debug-sphere ;; dgos: GAME, ENGINE -;; definition of type debug-sphere-table (deftype debug-sphere-table (basic) ((point vector 300 :inline :offset-assert 16) ) @@ -14,9 +13,6 @@ :flag-assert #x9000012d0 ) -;; definition for function make-debug-sphere-table -;; INFO: Return type mismatch int vs none. -;; Used lq/sq (defun make-debug-sphere-table ((arg0 debug-sphere-table)) (local-vars (sv-80 int)) (let ((s5-0 (new-stack-vector0)) @@ -31,41 +27,17 @@ (s1-0 (new-stack-vector0)) (s0-0 (new-stack-vector0)) ) - (set! - (-> s2-0 y) - (+ (-> s5-0 y) (* (cos (* 3276.8 (the float s3-0))) f30-0)) - ) + (set! (-> s2-0 y) (+ (-> s5-0 y) (* (cos (* 3276.8 (the float s3-0))) f30-0))) (set! (-> s1-0 y) (-> s2-0 y)) - (set! - (-> s0-0 y) - (+ (-> s5-0 y) (* (cos (* 3276.8 (the float (+ s3-0 1)))) f30-0)) - ) + (set! (-> s0-0 y) (+ (-> s5-0 y) (* (cos (* 3276.8 (the float (+ s3-0 1)))) f30-0))) (set! sv-80 0) (while (< sv-80 10) - (set! - (-> s2-0 x) - (+ (-> s5-0 x) (* (cos (* 6553.6 (the float sv-80))) f28-0)) - ) - (set! - (-> s2-0 z) - (+ (-> s5-0 z) (* (sin (* 6553.6 (the float sv-80))) f28-0)) - ) - (set! - (-> s1-0 x) - (+ (-> s5-0 x) (* (cos (* 6553.6 (the float (+ sv-80 1)))) f28-0)) - ) - (set! - (-> s1-0 z) - (+ (-> s5-0 z) (* (sin (* 6553.6 (the float (+ sv-80 1)))) f28-0)) - ) - (set! - (-> s0-0 x) - (+ (-> s5-0 x) (* (cos (* 6553.6 (the float sv-80))) f26-0)) - ) - (set! - (-> s0-0 z) - (+ (-> s5-0 z) (* (sin (* 6553.6 (the float sv-80))) f26-0)) - ) + (set! (-> s2-0 x) (+ (-> s5-0 x) (* (cos (* 6553.6 (the float sv-80))) f28-0))) + (set! (-> s2-0 z) (+ (-> s5-0 z) (* (sin (* 6553.6 (the float sv-80))) f28-0))) + (set! (-> s1-0 x) (+ (-> s5-0 x) (* (cos (* 6553.6 (the float (+ sv-80 1)))) f28-0))) + (set! (-> s1-0 z) (+ (-> s5-0 z) (* (sin (* 6553.6 (the float (+ sv-80 1)))) f28-0))) + (set! (-> s0-0 x) (+ (-> s5-0 x) (* (cos (* 6553.6 (the float sv-80))) f26-0))) + (set! (-> s0-0 z) (+ (-> s5-0 z) (* (sin (* 6553.6 (the float sv-80))) f26-0))) (set! (-> arg0 point s4-0 quad) (-> s2-0 quad)) (set! (-> arg0 point (+ s4-0 1) quad) (-> s1-0 quad)) (set! (-> arg0 point (+ s4-0 2) quad) (-> s0-0 quad)) @@ -75,56 +47,45 @@ ) ) ) - (let ((v0-10 0)) - ) (none) ) -;; definition for symbol *debug-sphere-table*, type debug-sphere-table (define *debug-sphere-table* (new 'static 'debug-sphere-table)) - -;; failed to figure out what this is: (make-debug-sphere-table *debug-sphere-table*) -;; definition for function add-debug-sphere-from-table -;; INFO: Return type mismatch int vs none. -;; Used lq/sq -(defun - add-debug-sphere-from-table - ((arg0 bucket-id) (arg1 vector) (arg2 float) (arg3 rgba)) +(defun add-debug-sphere-from-table ((arg0 bucket-id) (arg1 vector) (arg2 float) (arg3 rgba)) + "Draw a wireframe sphere" (rlet ((vf1 :class vf) (vf2 :class vf) (vf3 :class vf) (vf4 :class vf) (vf5 :class vf) ) - (let ((s4-0 (new-stack-vector0)) - (s3-0 (new-stack-vector0)) - (s2-0 (new-stack-vector0)) - (points (-> *debug-sphere-table* point)) - ) - (.lvf vf1 (&-> arg1 quad)) - (.mov vf2 arg2) - (dotimes (s0-0 100) - (.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 (&-> s4-0 quad) vf3) - (.svf (&-> s3-0 quad) vf4) - (.svf (&-> s2-0 quad) vf5) - (add-debug-line #t arg0 s4-0 s3-0 arg3 #f (the rgba -1)) - (add-debug-line #t arg0 s4-0 s2-0 arg3 #f (the rgba -1)) - ) - ) - (let ((v0-2 0)) + (let ((s4-0 (new-stack-vector0)) + (s3-0 (new-stack-vector0)) + (s2-0 (new-stack-vector0)) + (points (-> *debug-sphere-table* point)) + ) + (.lvf vf1 (&-> arg1 quad)) + (.mov vf2 arg2) + (dotimes (s0-0 100) + (.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 (&-> s4-0 quad) vf3) + (.svf (&-> s3-0 quad) vf4) + (.svf (&-> s2-0 quad) vf5) + (add-debug-line #t arg0 s4-0 s3-0 arg3 #f (the rgba -1)) + (add-debug-line #t arg0 s4-0 s2-0 arg3 #f (the rgba -1)) + ) + ) + (none) ) - (none) - ) ) diff --git a/goal_src/engine/debug/debug.gc b/goal_src/engine/debug/debug.gc index f7420e26cd..66a4313784 100644 --- a/goal_src/engine/debug/debug.gc +++ b/goal_src/engine/debug/debug.gc @@ -6,15 +6,17 @@ ;; dgos: GAME, ENGINE -(defun transform-float-point ((arg0 vector) (arg1 vector)) - +(defun transform-float-point ((in vector) (out vector)) + "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" (with-vf0 (with-vf (vf4 vf1 vf2 vf3 vf9 vf8 vf6) (rlet ((acc :class vf) (Q :class vf) (vf5 :class vf) ) - (.lvf vf5 (&-> arg0 quad)) + (.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) @@ -26,146 +28,154 @@ (.max.x.vf vf5 vf5 vf0 :mask #b1000) (.min.x.vf vf5 vf5 vf6 :mask #b1000) (vftoi4.xyzw vf5 vf5) - (.svf (&-> arg1 quad) vf5) - arg1 + (.svf (&-> out quad) vf5) + out ) ) ) ) -(defun-debug add-debug-point ((arg0 symbol) (arg1 bucket-id) (arg2 vector)) - (if (not arg0) - (return #f) - ) +;;;;;;;;;;;;;;;;;; +;; 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." + (if (not enable-draw) + (return #f) + ) (let ((s5-0 (new 'stack 'vector4w-2))) - (set! (-> arg2 w) 1.0) - (when (transform-point-qword! (the-as vector (-> s5-0 quad)) arg2) - (let* ((v1-7 (-> *display* frames (-> *display* on-screen) frame debug-buf)) - (a2-1 (-> v1-7 base)) - ) - (let ((a0-6 (the-as (pointer uint64) (-> v1-7 base)))) - (let* ((a1-3 v1-7) - (a3-0 (the-as dma-packet (-> a1-3 base))) - ) - (set! (-> a3-0 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) - (set! (-> a3-0 vif0) (new 'static 'vif-tag)) - (set! - (-> a3-0 vif1) - (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1) - ) - (set! (-> a1-3 base) (&+ (the-as pointer a3-0) 16)) - ) - (let* ((a1-4 v1-7) - (a3-2 (the-as gs-gif-tag (-> a1-4 base))) - ) - (set! - (-> a3-2 tag) - (new 'static 'gif-tag64 - :nloop #x1 - :eop #x1 - :pre #x1 - :prim #x4c - :nreg #x8 - ) - ) - (set! - (-> a3-2 regs) - (new 'static 'gif-tag-regs - :regs0 (gif-reg-id rgbaq) - :regs1 (gif-reg-id xyzf2) - :regs2 (gif-reg-id rgbaq) - :regs3 (gif-reg-id xyzf2) - :regs4 (gif-reg-id rgbaq) - :regs5 (gif-reg-id xyzf2) - :regs6 (gif-reg-id rgbaq) - :regs7 (gif-reg-id xyzf2) - ) - ) - (set! (-> a1-4 base) (&+ (the-as pointer a3-2) 16)) - ) - (set! (-> s5-0 vector 1 x) 255) - (set! (-> s5-0 vector 1 y) 128) - (set! (-> s5-0 vector 1 z) 128) - (set! (-> s5-0 vector 1 w) 128) - (set! (-> s5-0 vector 0 y) (+ (-> s5-0 vector 0 y) 160)) - (let* ((a1-11 v1-7) - (a3-4 (the-as vector4w-2 (-> a1-11 base))) - ) - (set! (-> a3-4 quad 0) (-> (&-> s5-0 quad 1) 0)) - (set! (-> a3-4 quad 1) (-> s5-0 quad 0)) - (set! (-> a1-11 base) (&+ (the-as pointer a3-4) 32)) - ) - (set! (-> s5-0 vector 0 x) (+ (-> s5-0 vector 0 x) -256)) - (set! (-> s5-0 vector 0 y) (+ (-> s5-0 vector 0 y) -160)) - (set! (-> s5-0 vector 1 x) 128) - (set! (-> s5-0 vector 1 y) 255) - (let* ((a1-18 v1-7) - (a3-6 (the-as vector4w-2 (-> a1-18 base))) + ;; transform the input point and convert to fixed point + (set! (-> pt w) 1.0) + (when (transform-point-qword! (the-as vector4w (-> s5-0 quad)) pt) + (let* ((v1-7 (-> *display* frames (-> *display* on-screen) frame debug-buf)) + (a2-1 (-> v1-7 base)) ) - (set! (-> a3-6 quad 0) (-> (&-> s5-0 quad 1) 0)) - (set! (-> a3-6 quad 1) (-> s5-0 quad 0)) - (set! (-> a1-18 base) (&+ (the-as pointer a3-6) 32)) - ) - (set! (-> s5-0 vector 0 x) (+ (-> s5-0 vector 0 x) 512)) - (set! (-> s5-0 vector 1 y) 128) - (set! (-> s5-0 vector 1 z) 255) - (let* ((a1-23 v1-7) - (a3-8 (the-as vector4w-2 (-> a1-23 base))) + (let ((a0-6 (the-as (pointer uint64) (-> v1-7 base)))) + (let* ((a1-3 v1-7) + (a3-0 (the-as dma-packet (-> a1-3 base))) + ) + ;; for now, don't set the length + (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)) + ) + + ;; add a giftag to draw a primitive + (let* ((a1-4 v1-7) + (a3-2 (the-as gs-gif-tag (-> a1-4 base))) + ) + (set! (-> a3-2 tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim #x4c + :nreg #x8 + ) ) - (set! (-> a3-8 quad 0) (-> (&-> s5-0 quad 1) 0)) - (set! (-> a3-8 quad 1) (-> s5-0 quad 0)) - (set! (-> a1-23 base) (&+ (the-as pointer a3-8) 32)) - ) - (set! (-> s5-0 vector 0 x) (+ (-> s5-0 vector 0 x) -256)) - (set! (-> s5-0 vector 0 y) (+ (-> s5-0 vector 0 y) -160)) - (set! (-> s5-0 vector 1 x) 255) - (set! (-> s5-0 vector 1 y) 128) - (let* ((a3-10 v1-7) - (a1-30 (the-as vector4w-2 (-> a3-10 base))) + (set! (-> 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-30 quad 0) (-> (&-> s5-0 quad 1) 0)) - (set! (-> a1-30 quad 1) (-> s5-0 quad 0)) - (set! (-> a3-10 base) (&+ (the-as pointer a1-30) 32)) - ) - (let ((a3-14 (/ (the-as int (+ (&- (the-as pointer -16) (the-as uint a0-6)) (the-as int (-> v1-7 base)))) 16))) - (cond - ((nonzero? a3-14) - (set! - (-> a0-6 0) - (logior (-> a0-6 0) (the-as uint (shr (shl a3-14 48) 48))) + (set! (-> a1-4 base) (&+ (the-as pointer a3-2) 16)) + ) + + ;; add the data. + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 128) + (set! (-> s5-0 vector 1 w) 128) + (+! (-> s5-0 vector 0 y) 160) + (let* ((a1-11 v1-7) + (a3-4 (the-as vector4w-2 (-> a1-11 base))) + ) + (set! (-> a3-4 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a3-4 quad 1) (-> s5-0 quad 0)) + (set! (-> a1-11 base) (&+ (the-as pointer a3-4) 32)) + ) + (+! (-> s5-0 vector 0 x) -256) + (+! (-> s5-0 vector 0 y) -160) + (set! (-> s5-0 vector 1 x) 128) + (set! (-> s5-0 vector 1 y) 255) + (let* ((a1-18 v1-7) + (a3-6 (the-as vector4w-2 (-> a1-18 base))) + ) + (set! (-> a3-6 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a3-6 quad 1) (-> s5-0 quad 0)) + (set! (-> a1-18 base) (&+ (the-as pointer a3-6) 32)) + ) + (+! (-> s5-0 vector 0 x) 512) + (set! (-> s5-0 vector 1 y) 128) + (set! (-> s5-0 vector 1 z) 255) + (let* ((a1-23 v1-7) + (a3-8 (the-as vector4w-2 (-> a1-23 base))) + ) + (set! (-> a3-8 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a3-8 quad 1) (-> s5-0 quad 0)) + (set! (-> a1-23 base) (&+ (the-as pointer a3-8) 32)) + ) + (+! (-> s5-0 vector 0 x) -256) + (+! (-> s5-0 vector 0 y) -160) + (set! (-> s5-0 vector 1 x) 255) + (set! (-> s5-0 vector 1 y) 128) + (let* ((a3-10 v1-7) + (a1-30 (the-as vector4w-2 (-> a3-10 base))) + ) + (set! (-> a1-30 quad 0) (-> (&-> s5-0 quad 1) 0)) + (set! (-> a1-30 quad 1) (-> s5-0 quad 0)) + (set! (-> a3-10 base) (&+ (the-as pointer a1-30) 32)) + ) + + ;; update the lengths + (let ((a3-14 (/ (the-as int (+ (&- (the-as pointer -16) (the-as uint a0-6)) (the-as int (-> v1-7 base)))) 16))) + (cond + ((nonzero? a3-14) + (logior! (-> a0-6 0) (shr (shl a3-14 48) 48)) + (logior! (-> a0-6 1) (shl (shr (shl a3-14 48) 48) 32)) + ) + (else + (set! (-> v1-7 base) a0-6) + ) + ) + ) ) - (set! - (-> a0-6 1) - (logior (-> a0-6 1) (the-as uint (shl (shr (shl a3-14 48) 48) 32))) + + ;; add to bucket + (let ((a3-20 (-> v1-7 base))) + (let ((a0-7 (the-as dma-packet (-> v1-7 base)))) + (set! (-> a0-7 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> a0-7 vif0) (new 'static 'vif-tag)) + (set! (-> a0-7 vif1) (new 'static 'vif-tag)) + (set! (-> v1-7 base) (&+ (the-as pointer a0-7) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + bucket + a2-1 + (the-as (pointer dma-tag) a3-20) + ) ) - ) - (else - (set! (-> v1-7 base) a0-6) - ) ) - ) ) - (let ((a3-20 (-> v1-7 base))) - (let ((a0-7 (the-as dma-packet (-> v1-7 base)))) - (set! (-> a0-7 dma) (new 'static 'dma-tag :id (dma-tag-id next))) - (set! (-> a0-7 vif0) (new 'static 'vif-tag)) - (set! (-> a0-7 vif1) (new 'static 'vif-tag)) - (set! (-> v1-7 base) (&+ (the-as pointer a0-7) 16)) - ) - (dma-bucket-insert-tag - (-> *display* frames (-> *display* on-screen) frame bucket-group) - arg1 - a2-1 - (the-as (pointer dma-tag) a3-20) - ) - ) - ) ) - ) #f ) + (defun-debug internal-draw-debug-line ((arg0 bucket-id) (arg1 vector) (arg2 vector) (arg3 rgba) (arg4 symbol) (arg5 rgba)) (local-vars (sv-80 vector)) (set! sv-80 arg2) @@ -214,8 +224,8 @@ int (when (and - (transform-point-qword! (the-as vector (-> s4-0 quad)) arg1) - (transform-point-qword! (the-as vector (&-> s4-0 quad 1)) sv-80) + (transform-point-qword! (the-as vector4w (-> s4-0 quad)) arg1) + (transform-point-qword! (the-as vector4w (&-> s4-0 quad 1)) sv-80) ) (let* ((v1-28 (-> *display* frames (-> *display* on-screen) frame debug-buf)) @@ -389,7 +399,7 @@ (defun-debug internal-draw-debug-text-3d ((arg0 bucket-id) (arg1 string) (arg2 vector) (arg3 rgba) (arg4 vector2h)) (let ((s2-0 (new 'stack-no-clear 'vector4w))) (set! (-> s2-0 quad) (the-as uint128 0)) - (when (transform-point-qword! (the-as vector s2-0) arg2) + (when (transform-point-qword! (the-as vector4w s2-0) arg2) (let* ((s3-0 (-> *display* frames (-> *display* on-screen) frame debug-buf)) (s5-0 (-> s3-0 base)) ) @@ -514,9 +524,9 @@ (set! (-> arg4 w) 1.0) (when (and - (transform-point-qword! (the-as vector (-> s5-0 quad)) arg2) - (transform-point-qword! (the-as vector (&-> s5-0 quad 1)) arg3) - (transform-point-qword! (the-as vector (&-> s5-0 quad 2)) arg4) + (transform-point-qword! (the-as vector4w (-> s5-0 quad)) arg2) + (transform-point-qword! (the-as vector4w (&-> s5-0 quad 1)) arg3) + (transform-point-qword! (the-as vector4w (&-> s5-0 quad 2)) arg4) ) (let* ((v1-9 (-> *display* frames (-> *display* on-screen) frame debug-buf)) (a2-1 (-> v1-9 base)) diff --git a/goal_src/engine/dma/dma-h.gc b/goal_src/engine/dma/dma-h.gc index 4415a410cd..2bc9e6fde7 100644 --- a/goal_src/engine/dma/dma-h.gc +++ b/goal_src/engine/dma/dma-h.gc @@ -245,6 +245,7 @@ (water-tex1 60) ;; merc1 61 ;; generic1 62 + (depth-cue 64) (bucket-65 65) (sprite 66) ;; debug spheres? 67 diff --git a/goal_src/engine/gfx/merc/merc-vu1.gc b/goal_src/engine/gfx/merc/merc-vu1.gc index 06eab23821..ffe1eb5016 100644 --- a/goal_src/engine/gfx/merc/merc-vu1.gc +++ b/goal_src/engine/gfx/merc/merc-vu1.gc @@ -5,3 +5,4 @@ ;; name in dgo: merc-vu1 ;; dgos: GAME, ENGINE +;; all this contains is the merc-vu1-block diff --git a/goal_src/engine/gfx/sprite/sprite.gc b/goal_src/engine/gfx/sprite/sprite.gc index 149dc8ed31..bffc48b1d0 100644 --- a/goal_src/engine/gfx/sprite/sprite.gc +++ b/goal_src/engine/gfx/sprite/sprite.gc @@ -180,10 +180,16 @@ ) ;; I believe this is used for the group 0's in 2d - ;; TODO prim. (set! (-> data sprite-2d-giftag tag) - (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :pre #x1 :prim #x75 :nreg #x9) - ) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1) + :nreg #x9 + ) + + ) (set! (-> data sprite-2d-giftag regs) (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) @@ -201,8 +207,13 @@ ;; group 1's in 2d (set! (-> data sprite-2d-giftag-2 tag) - (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :pre #x1 :prim #x55 :nreg #x9) - ) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :abe #x1) + :nreg #x9) + ) (set! (-> data sprite-2d-giftag-2 regs) (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) @@ -219,8 +230,15 @@ ;; 3d's don't have different groups? (set! (-> data sprite-3d-giftag tag) - (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :pre #x1 :prim #x75 :nreg #xc) - ) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1) + :nreg #xc + ) + + ) ;; note that we have rgbaq's per vertex in 3d (set! (-> data sprite-3d-giftag regs) (new 'static 'gif-tag-regs @@ -241,10 +259,16 @@ ;; ?? (set! (-> data clipped-giftag tag) - (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :pre #x1 :prim #x75 :nreg #x3) - ) - (set! - (-> data clipped-giftag regs) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1) + :nreg #x3 + ) + ) + + (set! (-> data clipped-giftag regs) (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) @@ -254,8 +278,15 @@ ;; not sure what this is either (set! (-> data warp-giftag tag) - (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :pre #x1 :prim #x53 :nreg #xc) - ) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri) :tme #x1 :abe #x1) + :nreg #xc + ) + ) + (set! (-> data warp-giftag regs) (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) diff --git a/test/decompiler/reference/engine/camera/math-camera_REF.gc b/test/decompiler/reference/engine/camera/math-camera_REF.gc index 122419d2d1..bd90beab52 100644 --- a/test/decompiler/reference/engine/camera/math-camera_REF.gc +++ b/test/decompiler/reference/engine/camera/math-camera_REF.gc @@ -476,7 +476,7 @@ ;; WARN: Inline assembly instruction marked with TODO - [TODO.VCLIP] ;; WARN: Unsupported inline assembly instruction kind - [cfc2.i v1, Clipping] ;; WARN: Inline assembly instruction marked with TODO - [TODO.VFTOI4] -(defun transform-point-qword! ((arg0 vector) (arg1 vector)) +(defun transform-point-qword! ((arg0 vector4w) (arg1 vector)) (local-vars (v1-7 int)) (rlet ((acc :class vf) (Q :class vf) diff --git a/test/decompiler/reference/engine/gfx/sprite/sprite_REF.gc b/test/decompiler/reference/engine/gfx/sprite/sprite_REF.gc new file mode 100644 index 0000000000..86fabe7ca9 --- /dev/null +++ b/test/decompiler/reference/engine/gfx/sprite/sprite_REF.gc @@ -0,0 +1,1231 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition of type sprite-header +(deftype sprite-header (structure) + ((header qword 1 :inline :offset-assert 0) + (num-sprites int32 :offset 0) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + ) + +;; definition for method 3 of type sprite-header +(defmethod inspect sprite-header ((obj sprite-header)) + (format #t "[~8x] ~A~%" obj 'sprite-header) + (format #t "~Theader[1] @ #x~X~%" (-> obj header)) + (format #t "~Tnum-sprites: ~D~%" (-> obj num-sprites)) + obj + ) + +;; definition for function sprite-setup-header +;; INFO: Return type mismatch int vs none. +(defun sprite-setup-header ((hdr sprite-header) (num-sprites int)) + (set! (-> hdr num-sprites) num-sprites) + (none) + ) + +;; definition of type sprite-hvdf-data +(deftype sprite-hvdf-data (structure) + ((data qword 76 :inline :offset-assert 0) + ) + :method-count-assert 9 + :size-assert #x4c0 + :flag-assert #x9000004c0 + ) + +;; definition for method 3 of type sprite-hvdf-data +(defmethod inspect sprite-hvdf-data ((obj sprite-hvdf-data)) + (format #t "[~8x] ~A~%" obj 'sprite-hvdf-data) + (format #t "~Tdata[76] @ #x~X~%" (-> obj data)) + obj + ) + +;; definition of type sprite-hvdf-control +(deftype sprite-hvdf-control (structure) + ((alloc int8 76 :offset-assert 0) + ) + :method-count-assert 9 + :size-assert #x4c + :flag-assert #x90000004c + ) + +;; definition for method 3 of type sprite-hvdf-control +(defmethod inspect sprite-hvdf-control ((obj sprite-hvdf-control)) + (format #t "[~8x] ~A~%" obj 'sprite-hvdf-control) + (format #t "~Talloc[76] @ #x~X~%" (-> obj alloc)) + obj + ) + +;; definition for symbol *sprite-hvdf-data*, type sprite-hvdf-data +(define *sprite-hvdf-data* (new 'global 'sprite-hvdf-data)) + +;; definition for symbol *sprite-hvdf-control*, type sprite-hvdf-control +(define *sprite-hvdf-control* (new 'global 'sprite-hvdf-control)) + +;; failed to figure out what this is: +(dotimes (v1-6 76) + (set! (-> *sprite-hvdf-control* alloc v1-6) 0) + ) + +;; failed to figure out what this is: +(set! (-> *sprite-hvdf-control* alloc 0) 1) + +;; definition of type sprite-aux-list +(deftype sprite-aux-list (basic) + ((num-entries int32 :offset-assert 4) + (entry int32 :offset-assert 8) + (data sprite-vec-data-2d 1 :offset-assert 12) + ) + :method-count-assert 9 + :size-assert #x10 + :flag-assert #x900000010 + (:methods + (new (symbol type int) _type_ 0) + ) + ) + +;; definition for method 3 of type sprite-aux-list +;; INFO: this function exists in multiple non-identical object files +(defmethod inspect sprite-aux-list ((obj sprite-aux-list)) + (format #t "[~8x] ~A~%" obj (-> obj type)) + (format #t "~Tnum-entries: ~D~%" (-> obj num-entries)) + (format #t "~Tentry: ~D~%" (-> obj entry)) + (format #t "~Tdata[1] @ #x~X~%" (-> obj data)) + obj + ) + +;; definition for method 0 of type sprite-aux-list +(defmethod + new + sprite-aux-list + ((allocation symbol) (type-to-make type) (size int)) + (let + ((v0-0 + (object-new + allocation + type-to-make + (the-as int (+ (-> type-to-make size) (the-as uint (* (+ size -1) 4)))) + ) + ) + ) + (set! (-> v0-0 num-entries) size) + (set! (-> v0-0 entry) 0) + v0-0 + ) + ) + +;; definition for method 3 of type sprite-aux-list +;; INFO: this function exists in multiple non-identical object files +;; INFO: Return type mismatch symbol vs sprite-aux-list. +(defmethod inspect sprite-aux-list ((obj sprite-aux-list)) + (format #t "[~X] sprite-aux-list:~%" obj) + (format #t "~Tnum-entries: ~D~%" (-> obj num-entries)) + (format #t "~Tentry: ~D~%" (-> obj entry)) + (dotimes (s5-0 (-> obj entry)) + (format #t "~T~D : ~X~%" s5-0 (-> obj data s5-0)) + ) + (the-as sprite-aux-list #f) + ) + +;; definition for symbol *sprite-aux-list*, type sprite-aux-list +(define *sprite-aux-list* (new 'global 'sprite-aux-list 256)) + +;; definition for function clear-sprite-aux-list +;; INFO: Return type mismatch int vs none. +(defun clear-sprite-aux-list () + (set! (-> *sprite-aux-list* entry) 0) + 0 + (none) + ) + +;; definition for function add-to-sprite-aux-list +;; ERROR: function was not converted to expressions. Cannot decompile. + +;; definition of type sprite-frame-data +(deftype sprite-frame-data (structure) + ((cdata vector 16 :inline :offset-assert 0) + (hmge-scale vector :inline :offset 256) + (consts vector :inline :offset-assert 272) + (pfog0 float :offset 272) + (deg-to-rad float :offset 276) + (min-scale float :offset 280) + (inv-area float :offset 284) + (adgif-giftag gs-gif-tag :inline :offset-assert 288) + (sprite-2d-giftag gs-gif-tag :inline :offset-assert 304) + (sprite-2d-giftag-2 gs-gif-tag :inline :offset-assert 320) + (sincos-01 vector :inline :offset-assert 336) + (sincos-23 vector :inline :offset-assert 352) + (sincos-45 vector :inline :offset-assert 368) + (sincos-67 vector :inline :offset-assert 384) + (sincos-89 vector :inline :offset-assert 400) + (basis-x vector :inline :offset-assert 416) + (basis-y vector :inline :offset-assert 432) + (sprite-3d-giftag gs-gif-tag :inline :offset-assert 448) + (screen-shader adgif-shader :inline :offset-assert 464) + (clipped-giftag gs-gif-tag :inline :offset-assert 544) + (inv-hmge-scale vector :inline :offset-assert 560) + (stq-offset vector :inline :offset-assert 576) + (stq-scale vector :inline :offset-assert 592) + (rgba-plain qword :inline :offset-assert 608) + (warp-giftag gs-gif-tag :inline :offset-assert 624) + (fog-clamp vector :inline :offset-assert 640) + (fog-min float :offset 640) + (fog-max float :offset 644) + (max-scale float :offset 648) + ) + :method-count-assert 9 + :size-assert #x290 + :flag-assert #x900000290 + ) + +;; definition for method 3 of type sprite-frame-data +(defmethod inspect sprite-frame-data ((obj sprite-frame-data)) + (format #t "[~8x] ~A~%" obj 'sprite-frame-data) + (format #t "~Tdata[41] @ #x~X~%" (-> obj cdata)) + (format #t "~Tcdata[16] @ #x~X~%" (-> obj cdata)) + (format #t "~Tfdata[25] @ #x~X~%" (-> obj hmge-scale)) + (format #t "~Txy-array[8] @ #x~X~%" (-> obj cdata)) + (format #t "~Tst-array[4] @ #x~X~%" (-> obj cdata 8)) + (format #t "~Txyz-array[4] @ #x~X~%" (-> obj cdata 12)) + (format #t "~Thmge-scale: #~%" (-> obj hmge-scale)) + (format #t "~Tconsts: #~%" (&-> obj pfog0)) + (format #t "~Tpfog0: ~f~%" (-> obj pfog0)) + (format #t "~Tdeg-to-rad: ~f~%" (-> obj deg-to-rad)) + (format #t "~Tmin-scale: ~f~%" (-> obj min-scale)) + (format #t "~Tinv-area: ~f~%" (-> obj inv-area)) + (format #t "~Tadgif-giftag: #~%" (-> obj adgif-giftag)) + (format #t "~Tsprite-2d-giftag: #~%" (-> obj sprite-2d-giftag)) + (format + #t + "~Tsprite-2d-giftag-2: #~%" + (-> obj sprite-2d-giftag-2) + ) + (format #t "~Tsincos-01: #~%" (-> obj sincos-01)) + (format #t "~Tsincos-23: #~%" (-> obj sincos-23)) + (format #t "~Tsincos-45: #~%" (-> obj sincos-45)) + (format #t "~Tsincos-67: #~%" (-> obj sincos-67)) + (format #t "~Tsincos-89: #~%" (-> obj sincos-89)) + (format #t "~Tbasis-x: #~%" (-> obj basis-x)) + (format #t "~Tbasis-y: #~%" (-> obj basis-y)) + (format #t "~Tsprite-3d-giftag: #~%" (-> obj sprite-3d-giftag)) + (format #t "~Tscreen-shader: #~%" (-> obj screen-shader)) + (format #t "~Tclipped-giftag: #~%" (-> obj clipped-giftag)) + (format #t "~Tinv-hmge-scale: #~%" (-> obj inv-hmge-scale)) + (format #t "~Tstq-offset: #~%" (-> obj stq-offset)) + (format #t "~Tstq-scale: #~%" (-> obj stq-scale)) + (format #t "~Trgba-plain: #~%" (-> obj rgba-plain)) + (format #t "~Twarp-giftag: #~%" (-> obj warp-giftag)) + (format #t "~Tfog-clamp: #~%" (-> obj fog-clamp)) + (format #t "~Tfog-min: ~f~%" (-> obj fog-clamp x)) + (format #t "~Tfog-max: ~f~%" (-> obj fog-clamp y)) + (format #t "~Tmax-scale: ~f~%" (-> obj fog-clamp z)) + obj + ) + +;; definition for function sprite-setup-frame-data +;; INFO: Return type mismatch float vs none. +;; Used lq/sq +(defun sprite-setup-frame-data ((data sprite-frame-data) (tbp-offset int)) + (set! (-> data hmge-scale quad) (-> *math-camera* hmge-scale quad)) + (set! (-> data inv-hmge-scale quad) (-> *math-camera* inv-hmge-scale quad)) + (set! (-> data pfog0) (-> *math-camera* pfog0)) + (set! (-> data deg-to-rad) 0.000095873795) + (set! + (-> data adgif-giftag tag) + (new 'static 'gif-tag64 :nloop #x1 :nreg #x5) + ) + (set! + (-> data adgif-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! + (-> data sprite-2d-giftag tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1) + :nreg #x9 + ) + ) + (set! + (-> data sprite-2d-giftag regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyzf2) + :regs5 (gif-reg-id st) + :regs6 (gif-reg-id xyzf2) + :regs7 (gif-reg-id st) + :regs8 (gif-reg-id xyzf2) + ) + ) + (set! + (-> data sprite-2d-giftag-2 tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :abe #x1) + :nreg #x9 + ) + ) + (set! + (-> data sprite-2d-giftag-2 regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyzf2) + :regs5 (gif-reg-id st) + :regs6 (gif-reg-id xyzf2) + :regs7 (gif-reg-id st) + :regs8 (gif-reg-id xyzf2) + ) + ) + (set! + (-> data sprite-3d-giftag tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1) + :nreg #xc + ) + ) + (set! + (-> data sprite-3d-giftag regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id st) + :regs1 (gif-reg-id rgbaq) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id rgbaq) + :regs5 (gif-reg-id xyzf2) + :regs6 (gif-reg-id st) + :regs7 (gif-reg-id rgbaq) + :regs8 (gif-reg-id xyzf2) + :regs9 (gif-reg-id st) + :regs10 (gif-reg-id rgbaq) + :regs11 (gif-reg-id xyzf2) + ) + ) + (set! + (-> data clipped-giftag tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1 :fge #x1 :abe #x1) + :nreg #x3 + ) + ) + (set! + (-> data clipped-giftag regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id st) + :regs1 (gif-reg-id rgbaq) + :regs2 (gif-reg-id xyzf2) + ) + ) + (set! + (-> data warp-giftag tag) + (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri) :tme #x1 :abe #x1) + :nreg #xc + ) + ) + (set! + (-> data warp-giftag regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id st) + :regs1 (gif-reg-id rgbaq) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id rgbaq) + :regs5 (gif-reg-id xyzf2) + :regs6 (gif-reg-id st) + :regs7 (gif-reg-id rgbaq) + :regs8 (gif-reg-id xyzf2) + ) + ) + (set! (-> data screen-shader prims 1) (gs-reg64 tex0-1)) + (set! + (-> data screen-shader tex0) + (new 'static 'gs-tex0 :tbw #x8 :tw #xa :th #x8 :tbp0 (* tbp-offset 32)) + ) + (set! (-> data screen-shader prims 3) (gs-reg64 tex1-1)) + (set! (-> data screen-shader tex1) (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) + (set! (-> data screen-shader prims 5) (gs-reg64 miptbp1-1)) + (set! (-> data screen-shader miptbp1) (new 'static 'gs-miptbp)) + (set! (-> data screen-shader clamp-reg) (gs-reg64 clamp-1)) + (set! + (-> data screen-shader clamp) + (new 'static 'gs-clamp :wms #x2 :wmt #x2 :maxu #x27f :maxv #xef) + ) + (set! (-> data screen-shader prims 9) (gs-reg64 alpha-1)) + (set! (-> data screen-shader alpha) (new 'static 'gs-miptbp :tbp1 #x44)) + (set! (-> data sincos-01 z) 0.999998) + (set! (-> data sincos-23 z) -0.16666014) + (set! (-> data sincos-45 z) 0.008326521) + (set! (-> data sincos-67 z) -0.0001956241) + (set! (-> data sincos-89 z) 0.0000023042373) + (set! (-> data sincos-01 w) 1.0) + (set! (-> data sincos-23 w) -0.49998003) + (set! (-> data sincos-45 w) 0.041620404) + (set! (-> data sincos-67 w) -0.0013636408) + (set! (-> data sincos-89 w) 0.000020170546) + (set! (-> data basis-x quad) (the-as uint128 0)) + (set! (-> data basis-x x) (- (-> *math-camera* perspective vector 0 x))) + (set! (-> data basis-y quad) (the-as uint128 0)) + (set! (-> data basis-y y) (- (-> *math-camera* perspective vector 1 y))) + (set! + (-> data min-scale) + (sqrtf (* (/ 1.0 (-> data basis-x x)) (/ 1.0 (-> data basis-y y)))) + ) + (set! (-> data inv-area) (/ 1.0 (* (-> data min-scale) (-> data min-scale)))) + (set-vector! (-> data cdata 0) -0.5 -0.5 0.0 0.0) + (set-vector! (-> data cdata 1) 0.5 -0.5 0.0 0.0) + (set-vector! (-> data cdata 2) 0.5 0.5 0.0 0.0) + (set-vector! (-> data cdata 3) -0.5 0.5 0.0 0.0) + (set-vector! (-> data cdata 4) 0.0 -0.5 0.0 0.0) + (set-vector! (-> data cdata 5) 1.0 -0.5 0.0 0.0) + (set-vector! (-> data cdata 6) 1.0 0.5 0.0 0.0) + (set-vector! (-> data cdata 7) 0.0 0.5 0.0 0.0) + (set-vector! (-> data cdata 8) 0.0 0.0 1.0 0.0) + (set-vector! (-> data cdata 9) 1.0 0.0 1.0 0.0) + (set-vector! (-> data cdata 10) 1.0 1.0 1.0 0.0) + (set-vector! (-> data cdata 11) 0.0 1.0 1.0 0.0) + (set-vector! (-> data cdata 12) -0.5 0.0 -0.5 0.0) + (set-vector! (-> data cdata 13) 0.5 0.0 -0.5 0.0) + (set-vector! (-> data cdata 14) 0.5 0.0 0.5 0.0) + (set-vector! (-> data cdata 15) -0.5 0.0 0.5 0.0) + (set-vector! + (-> data stq-offset) + -1792.0 + (+ -2048.0 (the float (-> *video-parms* screen-hy))) + 0.0 + 0.0 + ) + (set-vector! (-> data stq-scale) 0.0009765625 0.00390625 1.0 1.0) + (set! (-> data rgba-plain vector4w x) 128) + (set! (-> data rgba-plain vector4w y) 128) + (set! (-> data rgba-plain vector4w z) 128) + (set! (-> data rgba-plain vector4w w) 64) + (set! (-> data fog-clamp x) (-> *math-camera* fog-min)) + (set! (-> data fog-clamp y) (-> *math-camera* fog-max)) + (set! (-> data fog-clamp z) 2048.0) + (none) + ) + +;; definition for symbol sprite-vu1-block, type vu-function +(define sprite-vu1-block (the-as vu-function 0)) + +;; definition for method 0 of type sprite-array-2d +(defmethod + new + sprite-array-2d + ((allocation symbol) + (type-to-make type) + (group-0-size int) + (group-1-size int) + ) + (let* ((sprite-count (+ group-0-size group-1-size)) + (vec-data-size (* 3 sprite-count)) + (adgif-data-size (* 5 sprite-count)) + (v0-0 + (object-new + allocation + type-to-make + (the-as + int + (+ + (-> type-to-make size) + (the-as uint (* (+ (+ adgif-data-size -1) vec-data-size) 16)) + ) + ) + ) + ) + ) + (set! (-> v0-0 num-sprites 0) group-0-size) + (set! (-> v0-0 num-sprites 1) group-1-size) + (set! (-> v0-0 num-valid 0) 0) + (set! (-> v0-0 num-valid 1) 0) + (set! (-> v0-0 vec-data) (the-as uint (-> v0-0 data))) + (set! (-> v0-0 adgif-data) (the-as uint (&-> v0-0 data vec-data-size))) + v0-0 + ) + ) + +;; definition for method 0 of type sprite-array-3d +(defmethod + new + sprite-array-3d + ((allocation symbol) + (type-to-make type) + (group-0-size int) + (group-1-size int) + ) + (let* ((sprite-count (+ group-0-size group-1-size)) + (vec-data-size (* 3 sprite-count)) + (adgif-data-size (* 5 sprite-count)) + (v0-0 + (object-new + allocation + type-to-make + (the-as + int + (+ + (-> type-to-make size) + (the-as uint (* (+ (+ adgif-data-size -1) vec-data-size) 16)) + ) + ) + ) + ) + ) + (set! (-> v0-0 num-sprites 0) group-0-size) + (set! (-> v0-0 num-sprites 1) group-1-size) + (set! (-> v0-0 num-valid 0) 0) + (set! (-> v0-0 num-valid 1) 0) + (set! (-> v0-0 vec-data) (the-as uint (-> v0-0 data))) + (set! (-> v0-0 adgif-data) (the-as uint (&-> v0-0 data vec-data-size))) + v0-0 + ) + ) + +;; definition for symbol *sprite-array-2d*, type sprite-array-2d +(define *sprite-array-2d* (new 'global 'sprite-array-2d 1920 128)) + +;; definition for symbol *sprite-array-3d*, type sprite-array-3d +(define *sprite-array-3d* (new 'global 'sprite-array-3d 256 0)) + +;; definition for function sprite-set-3d-quaternion! +(defun sprite-set-3d-quaternion! ((arg0 sprite-vec-data-3d) (arg1 quaternion)) + (local-vars (v1-0 float) (v1-1 float)) + (rlet ((vf0 :class vf) + (vf1 :class vf) + (vf2 :class vf) + ) + (init-vf0-vector) + (cond + ((< (-> arg1 w) 0.0) + (.lvf vf1 (&-> arg0 qx-qy-qz-sy quad)) + (.lvf vf2 (&-> arg1 vec quad)) + (.sub.vf vf1 vf0 vf2 :mask #b111) + (.svf (&-> arg0 qx-qy-qz-sy quad) vf1) + (.mov v1-0 vf1) + ) + (else + (.lvf vf1 (&-> arg0 qx-qy-qz-sy quad)) + (.lvf vf2 (&-> arg1 vec quad)) + (.add.vf vf1 vf0 vf2 :mask #b111) + (.svf (&-> arg0 qx-qy-qz-sy quad) vf1) + (.mov v1-1 vf1) + ) + ) + arg1 + ) + ) + +;; definition for function sprite-get-3d-quaternion! +(defun sprite-get-3d-quaternion! ((arg0 quaternion) (arg1 sprite-vec-data-3d)) + (let ((f0-0 (-> arg1 qx-qy-qz-sy x)) + (f1-0 (-> arg1 qx-qy-qz-sy y)) + (f3-0 (-> arg1 qx-qy-qz-sy z)) + ) + (set! (-> arg0 x) f0-0) + (set! (-> arg0 y) f1-0) + (set! (-> arg0 z) f3-0) + (set! + (-> arg0 w) + (sqrtf (- (- (- 1.0 (* f3-0 f3-0)) (* f1-0 f1-0)) (* f0-0 f0-0))) + ) + ) + arg0 + ) + +;; definition for function sprite-add-matrix-data +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defun sprite-add-matrix-data ((dma-buff dma-buffer) (matrix-mode uint)) + (let ((count 900)) + (cond + ((zero? matrix-mode) + (let* ((a1-1 dma-buff) + (pkt1 (the-as dma-packet (-> a1-1 base))) + ) + (set! (-> pkt1 dma) (new 'static 'dma-tag :qwc #x5 :id (dma-tag-id cnt))) + (set! + (-> pkt1 vif0) + (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + ) + (set! + (-> pkt1 vif1) + (new 'static 'vif-tag + :num #x5 + :cmd (vif-cmd unpack-v4-32) + :imm (shr (shl count 54) 54) + ) + ) + (set! (-> a1-1 base) (&+ (the-as pointer pkt1) 16)) + ) + (let* ((mtx (the-as matrix (-> dma-buff base))) + (t1-0 (-> *math-camera* camera-temp)) + (a2-4 (-> t1-0 vector 0 quad)) + (a3-4 (-> t1-0 vector 1 quad)) + (t0-4 (-> t1-0 vector 2 quad)) + (t1-1 (-> t1-0 vector 3 quad)) + ) + (set! (-> mtx vector 0 quad) a2-4) + (set! (-> mtx vector 1 quad) a3-4) + (set! (-> mtx vector 2 quad) t0-4) + (set! (-> mtx vector 3 quad) t1-1) + ) + (&+! (-> dma-buff base) 64) + (let ((v1-1 (+ count 4))) + (set! + (-> (the-as (pointer uint128) (-> dma-buff base))) + (-> *math-camera* hvdf-off quad) + ) + (&+! (-> dma-buff base) 16) + (+ v1-1 1) + ) + ) + ((= matrix-mode 1) + (let* ((a1-10 dma-buff) + (pkt2 (the-as dma-packet (-> a1-10 base))) + ) + (set! (-> pkt2 dma) (new 'static 'dma-tag :qwc #x50 :id (dma-tag-id cnt))) + (set! + (-> pkt2 vif0) + (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + ) + (set! + (-> pkt2 vif1) + (new 'static 'vif-tag + :num #x50 + :cmd (vif-cmd unpack-v4-32) + :imm (shr (shl count 54) 54) + ) + ) + (set! (-> a1-10 base) (&+ (the-as pointer pkt2) 16)) + ) + (let ((mtx2 (the-as matrix (-> dma-buff base))) + (f1-0 (-> *math-camera* perspective vector 0 x)) + (f2-0 (-> *math-camera* perspective vector 1 y)) + (f0-1 (* -1.9996 (-> *math-camera* perspective vector 0 x))) + ) + (set-vector! (-> mtx2 vector 0) f0-1 0.0 0.0 0.0) + (set-vector! (-> mtx2 vector 1) 0.0 (- (* (/ f2-0 f1-0) f0-1)) 0.0 0.0) + (set-vector! (-> mtx2 vector 2) 0.0 0.0 (- f0-1) 0.0) + (set-vector! + (-> mtx2 vector 3) + 0.0 + 0.0 + (* 500000000.0 f0-1) + (* (* 60.0 f0-1) (-> *math-camera* pfog0)) + ) + ) + (&+! (-> dma-buff base) 64) + (let ((v1-2 (+ count 4))) + (let ((a1-16 (the-as vector (-> dma-buff base)))) + (set! (-> a1-16 quad) (-> *math-camera* hvdf-off quad)) + (set! (-> a1-16 x) 2048.0) + (set! (-> a1-16 y) 2048.0) + (set! (-> a1-16 z) (-> *math-camera* hvdf-off z)) + ) + (&+! (-> dma-buff base) 16) + (let ((v1-3 (+ v1-2 1))) + (dotimes (hvdf-idx 75) + (set! + (-> (the-as (pointer uint128) (-> dma-buff base))) + (-> *sprite-hvdf-data* data (+ hvdf-idx 1) quad) + ) + (&+! (-> dma-buff base) 16) + (+! v1-3 1) + ) + ) + ) + ) + ) + ) + 0 + (none) + ) + +;; definition for function sprite-add-frame-data +;; INFO: Return type mismatch pointer vs none. +(defun sprite-add-frame-data ((dma-buff dma-buffer) (tbp-offset uint)) + (let ((s5-0 41)) + (let* ((v1-0 dma-buff) + (pkt (the-as dma-packet (-> v1-0 base))) + ) + (set! (-> pkt dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc s5-0)) + (set! (-> pkt vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! + (-> pkt vif1) + (new 'static 'vif-tag :imm #x3d4 :cmd (vif-cmd unpack-v4-32) :num s5-0) + ) + (set! (-> v1-0 base) (&+ (the-as pointer pkt) 16)) + ) + (sprite-setup-frame-data + (the-as sprite-frame-data (-> dma-buff base)) + (the-as int tbp-offset) + ) + (&+! (-> dma-buff base) (* s5-0 16)) + ) + (none) + ) + +;; definition for function sprite-add-2d-chunk +;; INFO: Return type mismatch pointer vs none. +(defun + sprite-add-2d-chunk + ((sprites sprite-array-2d) + (start-sprite-idx int) + (num-sprites int) + (dma-buff dma-buffer) + (mscal-addr int) + ) + (let ((qwc-pkt1 1)) + (let* ((v1-0 dma-buff) + (pkt1 (the-as dma-packet (-> v1-0 base))) + ) + (set! + (-> pkt1 dma) + (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc qwc-pkt1) + ) + (set! + (-> pkt1 vif0) + (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + ) + (set! + (-> pkt1 vif1) + (new 'static 'vif-tag + :imm #x8000 + :cmd (vif-cmd unpack-v4-32) + :num qwc-pkt1 + ) + ) + (set! (-> v1-0 base) (&+ (the-as pointer pkt1) 16)) + ) + (sprite-setup-header (the-as sprite-header (-> dma-buff base)) num-sprites) + (&+! (-> dma-buff base) (* qwc-pkt1 16)) + ) + (let* ((qwc-pkt2 (* 3 num-sprites)) + (v1-4 dma-buff) + (pkt2 (the-as dma-packet (-> v1-4 base))) + ) + (set! + (-> pkt2 dma) + (new 'static 'dma-tag + :id (dma-tag-id ref) + :addr (+ (-> sprites vec-data) (the-as uint (* 48 start-sprite-idx))) + :qwc qwc-pkt2 + ) + ) + (set! (-> pkt2 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt2 vif1) + (new 'static 'vif-tag :imm #x8001 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt2) + ) + (set! (-> v1-4 base) (&+ (the-as pointer pkt2) 16)) + ) + (let* ((qwc-pkt3 (* 5 num-sprites)) + (v1-6 dma-buff) + (pkt3 (the-as dma-packet (-> v1-6 base))) + ) + (set! + (-> pkt3 dma) + (new 'static 'dma-tag + :id (dma-tag-id ref) + :addr (+ (-> sprites adgif-data) (the-as uint (* 80 start-sprite-idx))) + :qwc qwc-pkt3 + ) + ) + (set! (-> pkt3 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt3 vif1) + (new 'static 'vif-tag :imm #x8091 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt3) + ) + (set! (-> v1-6 base) (&+ (the-as pointer pkt3) 16)) + ) + (let ((pkt4 (the-as dma-packet (-> dma-buff base)))) + (set! (-> pkt4 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt4 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt4 vif1) + (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm mscal-addr) + ) + (set! (-> dma-buff base) (&+ (the-as pointer pkt4) 16)) + ) + (none) + ) + +;; definition for function sprite-add-2d-all +(defun + sprite-add-2d-all + ((sprites sprite-array-2d) (dma-buff dma-buffer) (group-idx int)) + (when (> (-> sprites num-valid group-idx) 0) + (let ((current-sprite-idx 0) + (mscal-addr 3) + ) + (when (= group-idx 1) + (set! current-sprite-idx (-> sprites num-sprites 0)) + (set! mscal-addr 109) + ) + (let ((remaining-sprites (-> sprites num-valid group-idx))) + (while (< 48 remaining-sprites) + (sprite-add-2d-chunk sprites current-sprite-idx 48 dma-buff mscal-addr) + (+! current-sprite-idx 48) + (+! remaining-sprites -48) + ) + (sprite-add-2d-chunk + sprites + current-sprite-idx + remaining-sprites + dma-buff + mscal-addr + ) + ) + ) + ) + (none) + ) + +;; definition for function sprite-add-3d-chunk +;; INFO: Return type mismatch pointer vs none. +(defun + sprite-add-3d-chunk + ((sprites sprite-array-3d) + (start-sprite-idx int) + (num-sprites int) + (dma-buff dma-buffer) + ) + (let ((qwc-pkt1 1)) + (let* ((v1-0 dma-buff) + (pkt1 (the-as dma-packet (-> v1-0 base))) + ) + (set! + (-> pkt1 dma) + (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc qwc-pkt1) + ) + (set! + (-> pkt1 vif0) + (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + ) + (set! + (-> pkt1 vif1) + (new 'static 'vif-tag + :imm #x8000 + :cmd (vif-cmd unpack-v4-32) + :num qwc-pkt1 + ) + ) + (set! (-> v1-0 base) (&+ (the-as pointer pkt1) 16)) + ) + (sprite-setup-header (the-as sprite-header (-> dma-buff base)) num-sprites) + (&+! (-> dma-buff base) (* qwc-pkt1 16)) + ) + (let* ((qwc-pkt2 (* 3 num-sprites)) + (v1-4 dma-buff) + (pkt2 (the-as dma-packet (-> v1-4 base))) + ) + (set! + (-> pkt2 dma) + (new 'static 'dma-tag + :id (dma-tag-id ref) + :addr (+ (-> sprites vec-data) (the-as uint (* 48 start-sprite-idx))) + :qwc qwc-pkt2 + ) + ) + (set! (-> pkt2 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt2 vif1) + (new 'static 'vif-tag :imm #x8001 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt2) + ) + (set! (-> v1-4 base) (&+ (the-as pointer pkt2) 16)) + ) + (let* ((qwc-pkt3 (* 5 num-sprites)) + (v1-6 dma-buff) + (pkt3 (the-as dma-packet (-> v1-6 base))) + ) + (set! + (-> pkt3 dma) + (new 'static 'dma-tag + :id (dma-tag-id ref) + :addr (+ (-> sprites adgif-data) (the-as uint (* 80 start-sprite-idx))) + :qwc qwc-pkt3 + ) + ) + (set! (-> pkt3 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt3 vif1) + (new 'static 'vif-tag :imm #x8091 :cmd (vif-cmd unpack-v4-32) :num qwc-pkt3) + ) + (set! (-> v1-6 base) (&+ (the-as pointer pkt3) 16)) + ) + (let ((pkt4 (the-as dma-packet (-> dma-buff base)))) + (set! (-> pkt4 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt4 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt4 vif1) + (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm #xd3) + ) + (set! (-> dma-buff base) (&+ (the-as pointer pkt4) 16)) + ) + (none) + ) + +;; definition for function sprite-add-3d-all +(defun + sprite-add-3d-all + ((sprites sprite-array-3d) (dma-buff dma-buffer) (group-idx int)) + (when (> (-> sprites num-valid group-idx) 0) + (let ((current-sprite-idx (if (zero? group-idx) + 0 + (-> sprites num-sprites 0) + ) + ) + (remaining-sprites (-> sprites num-valid group-idx)) + ) + (while (< 48 remaining-sprites) + (sprite-add-3d-chunk sprites current-sprite-idx 48 dma-buff) + (+! current-sprite-idx 48) + (+! remaining-sprites -48) + ) + (sprite-add-3d-chunk sprites current-sprite-idx remaining-sprites dma-buff) + ) + ) + (none) + ) + +;; definition for function sprite-add-shadow-chunk +;; INFO: Return type mismatch pointer vs none. +(defun + sprite-add-shadow-chunk + ((shadow-buff fake-shadow-buffer) + (start-idx int) + (num-sprites int) + (dma-buff dma-buffer) + ) + (let ((pkt1-qwc 1)) + (let* ((v1-0 dma-buff) + (pkt1 (the-as dma-packet (-> v1-0 base))) + ) + (set! + (-> pkt1 dma) + (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc pkt1-qwc) + ) + (set! + (-> pkt1 vif0) + (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)) + ) + (set! + (-> pkt1 vif1) + (new 'static 'vif-tag + :imm #x8000 + :cmd (vif-cmd unpack-v4-32) + :num pkt1-qwc + ) + ) + (set! (-> v1-0 base) (&+ (the-as pointer pkt1) 16)) + ) + (sprite-setup-header (the-as sprite-header (-> dma-buff base)) num-sprites) + (&+! (-> dma-buff base) (* pkt1-qwc 16)) + ) + (let* ((pkt2-qwc (* 3 num-sprites)) + (v1-4 dma-buff) + (pkt2 (the-as dma-packet (-> v1-4 base))) + ) + (set! + (-> pkt2 dma) + (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc pkt2-qwc) + ) + (set! (-> pkt2 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt2 vif1) + (new 'static 'vif-tag :imm #x8001 :cmd (vif-cmd unpack-v4-32) :num pkt2-qwc) + ) + (set! (-> v1-4 base) (&+ (the-as pointer pkt2) 16)) + ) + (dotimes (sprite-idx num-sprites) + (let ((dma-vec-data (the-as (inline-array vector) (-> dma-buff base)))) + (let ((in-vec-data (-> shadow-buff data (+ start-idx sprite-idx)))) + (set! (-> dma-vec-data 0 x) (-> in-vec-data px)) + (set! (-> dma-vec-data 0 y) (-> in-vec-data py)) + (set! (-> dma-vec-data 0 z) (-> in-vec-data pz)) + (set! (-> dma-vec-data 0 w) (-> in-vec-data scale)) + (set! (-> dma-vec-data 1 x) (-> in-vec-data qx)) + (set! (-> dma-vec-data 1 y) (-> in-vec-data qy)) + (set! (-> dma-vec-data 1 z) (-> in-vec-data qz)) + (set! (-> dma-vec-data 1 w) (-> in-vec-data scale)) + ) + (set! (-> dma-vec-data 2 x) 128.0) + (set! (-> dma-vec-data 2 y) 128.0) + (set! (-> dma-vec-data 2 z) 128.0) + (set! (-> dma-vec-data 2 w) 40.0) + ) + (&+! (-> dma-buff base) 48) + ) + (let* ((a1-15 (* 5 num-sprites)) + (v1-9 dma-buff) + (pkt3 (the-as dma-packet (-> v1-9 base))) + ) + (set! (-> pkt3 dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc a1-15)) + (set! (-> pkt3 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt3 vif1) + (new 'static 'vif-tag :imm #x8091 :cmd (vif-cmd unpack-v4-32) :num a1-15) + ) + (set! (-> v1-9 base) (&+ (the-as pointer pkt3) 16)) + ) + (dotimes (si num-sprites) + (let ((dma-adgif-data (the-as adgif-shader (-> dma-buff base))) + (in-adgif-data (-> shadow-buff data (+ start-idx si))) + ) + (adgif-shader<-texture-simple! dma-adgif-data *shadow-middot-texture*) + (if (logtest? (-> in-adgif-data flags) 1) + (set! (-> dma-adgif-data alpha) (new 'static 'gs-miptbp :tbp1 #x48)) + (set! (-> dma-adgif-data alpha) (new 'static 'gs-miptbp :tbp1 #x42)) + ) + ) + (&+! (-> dma-buff base) 80) + ) + (let ((pkt4 (the-as dma-packet (-> dma-buff base)))) + (set! (-> pkt4 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt4 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt4 vif1) + (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm #xd3) + ) + (set! (-> dma-buff base) (&+ (the-as pointer pkt4) 16)) + ) + (none) + ) + +;; definition for function sprite-add-shadow-all +(defun + sprite-add-shadow-all + ((shadow-buff fake-shadow-buffer) (dma-buff dma-buffer)) + (when (> (-> shadow-buff num-shadows) 0) + (let ((current-shadow 0) + (remaining-shadows (-> shadow-buff num-shadows)) + ) + (while (< 48 remaining-shadows) + (sprite-add-shadow-chunk shadow-buff current-shadow 48 dma-buff) + (+! current-shadow 48) + (+! remaining-shadows -48) + ) + (sprite-add-shadow-chunk + shadow-buff + current-shadow + remaining-shadows + dma-buff + ) + ) + ) + (none) + ) + +;; definition for function sprite-draw +;; INFO: Return type mismatch int vs none. +(defun sprite-draw ((disp display)) + (let + ((dma-mem-begin + (-> *display* frames (-> *display* on-screen) frame global-buf base) + ) + ) + (let* + ((dma-buff (-> *display* frames (-> *display* on-screen) frame global-buf)) + (dma-bucket-begin (-> dma-buff base)) + ) + (sprite-init-distorter + dma-buff + (-> disp frames (-> disp on-screen) draw frame1 fbp) + ) + (sprite-draw-distorters dma-buff) + (let* ((v1-13 dma-buff) + (pkt1 (the-as dma-packet (-> v1-13 base))) + ) + (set! (-> pkt1 dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> pkt1 vif0) (new 'static 'vif-tag)) + (set! + (-> pkt1 vif1) + (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1) + ) + (set! (-> v1-13 base) (&+ (the-as pointer pkt1) 16)) + ) + (let* ((v1-14 dma-buff) + (giftag (the-as gs-gif-tag (-> v1-14 base))) + ) + (set! + (-> giftag tag) + (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2) + ) + (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) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-14 base) (&+ (the-as pointer giftag) 16)) + ) + (let* ((v1-15 dma-buff) + (a0-13 (-> v1-15 base)) + ) + (set! + (-> (the-as (pointer gs-test) a0-13) 0) + (new 'static 'gs-test + :ate #x1 + :atst #x5 + :aref #x26 + :afail #x1 + :zte #x1 + :ztst #x2 + ) + ) + (set! (-> (the-as (pointer gs-reg64) a0-13) 1) (gs-reg64 test-1)) + (set! + (-> (the-as (pointer gs-clamp) a0-13) 2) + (new 'static 'gs-clamp :wms #x1 :wmt #x1) + ) + (set! (-> (the-as (pointer gs-reg64) a0-13) 3) (gs-reg64 clamp-1)) + (set! (-> v1-15 base) (&+ a0-13 32)) + ) + (dma-buffer-add-vu-function dma-buff sprite-vu1-block 1) + (sprite-add-frame-data + dma-buff + (-> disp frames (-> disp on-screen) draw frame1 fbp) + ) + (let* ((v1-22 dma-buff) + (pkt2 (the-as dma-packet (-> v1-22 base))) + ) + (set! (-> pkt2 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! + (-> pkt2 vif0) + (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1 :imm #x0) + ) + (set! (-> pkt2 vif1) (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1)) + (set! (-> v1-22 base) (&+ (the-as pointer pkt2) 16)) + ) + (let* ((v1-23 dma-buff) + (pkt3 (the-as dma-packet (-> v1-23 base))) + ) + (set! (-> pkt3 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt3 vif0) (new 'static 'vif-tag :cmd (vif-cmd base))) + (set! + (-> pkt3 vif1) + (new 'static 'vif-tag :imm #x190 :cmd (vif-cmd offset)) + ) + (set! (-> v1-23 base) (&+ (the-as pointer pkt3) 16)) + ) + (sprite-add-matrix-data dma-buff (the-as uint 0)) + (sprite-add-3d-all *sprite-array-3d* dma-buff 0) + (sprite-add-2d-all *sprite-array-2d* dma-buff 0) + (sprite-add-shadow-all (if (= *fake-shadow-buffer* *fake-shadow-buffer-1*) + *fake-shadow-buffer-2* + *fake-shadow-buffer-1* + ) + dma-buff + ) + (let* ((v1-25 dma-buff) + (pkt4 (the-as dma-packet (-> v1-25 base))) + ) + (set! (-> pkt4 dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> pkt4 vif0) (new 'static 'vif-tag)) + (set! (-> pkt4 vif1) (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1)) + (set! (-> v1-25 base) (&+ (the-as pointer pkt4) 16)) + ) + (sprite-add-matrix-data dma-buff (the-as uint 1)) + (sprite-add-2d-all *sprite-array-2d* dma-buff 1) + (let ((a3-0 (-> dma-buff base))) + (let ((pkt5 (the-as dma-packet (-> dma-buff base)))) + (set! (-> pkt5 dma) (new 'static 'dma-tag :id (dma-tag-id next))) + (set! (-> pkt5 vif0) (new 'static 'vif-tag)) + (set! (-> pkt5 vif1) (new 'static 'vif-tag)) + (set! (-> dma-buff base) (&+ (the-as pointer pkt5) 16)) + ) + (dma-bucket-insert-tag + (-> *display* frames (-> *display* on-screen) frame bucket-group) + (bucket-id sprite) + dma-bucket-begin + (the-as (pointer dma-tag) a3-0) + ) + ) + ) + (let ((mem-use *dma-mem-usage*)) + (when (nonzero? mem-use) + (set! (-> mem-use length) (max 83 (-> mem-use length))) + (set! (-> mem-use data 82 name) "sprite") + (+! (-> mem-use data 82 count) 1) + (+! + (-> mem-use data 82 used) + (&- + (-> *display* frames (-> *display* on-screen) frame global-buf base) + (the-as uint dma-mem-begin) + ) + ) + (set! (-> mem-use data 82 total) (-> mem-use data 82 used)) + ) + ) + ) + 0 + (none) + ) + +;; definition for function sprite-allocate-user-hvdf +(defun sprite-allocate-user-hvdf () + (dotimes (v1-0 76) + (when (zero? (-> *sprite-hvdf-control* alloc v1-0)) + (set! (-> *sprite-hvdf-control* alloc v1-0) 1) + (return v1-0) + ) + ) + 0 + ) + +;; definition for function sprite-release-user-hvdf +;; INFO: Return type mismatch int vs none. +(defun sprite-release-user-hvdf ((arg0 int)) + (when (and (>= arg0 1) (< arg0 76)) + (set! (-> *sprite-hvdf-control* alloc arg0) 0) + 0 + ) + 0 + (none) + ) + +;; definition for function sprite-get-user-hvdf +(defun sprite-get-user-hvdf ((arg0 int)) + (-> *sprite-hvdf-data* data arg0) + ) diff --git a/test/offline/offline_test_main.cpp b/test/offline/offline_test_main.cpp index b05eb043ea..04016f7347 100644 --- a/test/offline/offline_test_main.cpp +++ b/test/offline/offline_test_main.cpp @@ -62,6 +62,8 @@ const std::unordered_set g_functions_expected_to_reject = { // display "vblank-handler", // asm "vif1-handler", "vif1-handler-debug", + // sprite. Don't know types yet. + "add-to-sprite-aux-list", // ripple - asm "ripple-execute-init", "ripple-create-wave-table", "ripple-apply-wave-table", "ripple-matrix-scale", @@ -153,6 +155,9 @@ const std::unordered_set g_functions_to_skip_compiling = { // float to int "(method 10 bsp-header)", + // multiply defined. + "(method 3 sprite-aux-list)", + // loader - decompiler bug with detecting handle macros "(method 10 external-art-buffer)"};