diff --git a/decompiler/IR2/Form.h b/decompiler/IR2/Form.h index 47ada03075..87f6c7509d 100644 --- a/decompiler/IR2/Form.h +++ b/decompiler/IR2/Form.h @@ -1422,6 +1422,7 @@ class LetElement : public FormElement { void collect_vars(RegAccessSet& vars, bool recursive) const override; void get_modified_regs(RegSet& regs) const override; Form* body() { return m_body; } + const Form* body() const { return m_body; } void set_body(Form* new_body); bool allow_in_if() const override { return false; } @@ -1430,6 +1431,7 @@ class LetElement : public FormElement { Form* src = nullptr; }; std::vector& entries() { return m_entries; } + const std::vector& entries() const { return m_entries; } void add_entry(const Entry& e); bool is_star() const { return m_star; } diff --git a/decompiler/IR2/OpenGoalMapping.cpp b/decompiler/IR2/OpenGoalMapping.cpp index 5b5bbe8284..071c41cbcc 100644 --- a/decompiler/IR2/OpenGoalMapping.cpp +++ b/decompiler/IR2/OpenGoalMapping.cpp @@ -51,6 +51,9 @@ const std::map MIPS_ASM_TO_OPEN_GOAL_FUN {InstructionKind::PCPYLD, {".pcpyld", {}}}, {InstructionKind::PCPYUD, {".pcpyud", {}}}, + // MMI Add + {InstructionKind::PADDB, {".paddb", {}}}, + // NOTE - depending on how this is used, this may case issues! Be Warned! // lots of implicit logic in OpenGOAL depending on argument types! {InstructionKind::MFC1, {".mov", {}}}, diff --git a/decompiler/analysis/atomic_op_builder.cpp b/decompiler/analysis/atomic_op_builder.cpp index 3f76496a32..7b872de69e 100644 --- a/decompiler/analysis/atomic_op_builder.cpp +++ b/decompiler/analysis/atomic_op_builder.cpp @@ -346,6 +346,7 @@ std::unique_ptr make_asm_op(const Instruction& i0, int idx) { case InstructionKind::PPACB: case InstructionKind::PADDW: case InstructionKind::PADDH: + case InstructionKind::PADDB: case InstructionKind::PMAXW: case InstructionKind::PPACW: case InstructionKind::PCEQW: diff --git a/decompiler/analysis/insert_lets.cpp b/decompiler/analysis/insert_lets.cpp index a23c3b444f..4b08f90148 100644 --- a/decompiler/analysis/insert_lets.cpp +++ b/decompiler/analysis/insert_lets.cpp @@ -2583,6 +2583,7 @@ FormElement* rewrite_dma_buffer_add_gs_set(const std::vector& in, {"dthe", "gs-dthe"}, {"colclamp", "gs-color-clamp"}, {"xyzf3", "gs-xyzf"}, + {"xyz2", "gs-xyz"}, {"xyz3", "gs-xyz"}, {"bitbltbuf", "gs-bitbltbuf"}, {"trxpos", "gs-trxpos"}, diff --git a/decompiler/config/jak2/all-types.gc b/decompiler/config/jak2/all-types.gc index 2484c54852..01cc314d8a 100644 --- a/decompiler/config/jak2/all-types.gc +++ b/decompiler/config/jak2/all-types.gc @@ -5149,8 +5149,13 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (deftype texture-anim-layer (structure) - ((extra vector :inline :offset 240) - (func (function texture-anim-layer int) :offset 256) + ((interpolated-color vector :inline) ;; added + (interpolated-scale-offset vector :inline) + (interpolated-st-scale-offset vector :inline) + (interpolated-qs vector :inline) + (interpolated-rot vector :inline) + (extra vector :inline :offset 240) + (func (function dma-buffer uint int int texture-anim-layer float int) :offset 256) (func-id symbol :offset 256) (init-func (function texture-anim-layer int) :offset 260) (init-func-id symbol :offset 260) @@ -5161,6 +5166,9 @@ (test gs-test :offset 280) (alpha gs-alpha :offset 288) (clamp gs-clamp :offset 296) + + (start-vectors vector 5 :inline :offset 80 :score -10) ;; added + (start-color vector :inline :offset 80) (start-scale vector2 :inline :offset 96) (start-offset vector2 :inline :offset 104) @@ -5169,9 +5177,13 @@ (start-qs vector :inline :offset 128) (start-rot degrees :offset 144) (start-st-rot degrees :offset 148) + + (end-vectors vector 5 :inline :offset 160 :score -10) ;; added + (end-color vector :inline :offset 160) (end-scale vector2 :inline :offset 176) (end-offset vector2 :inline :offset 184) + (end-scale-offset vector :inline :offset 176) (end-st-scale vector2 :inline :offset 192) (end-st-offset vector2 :inline :offset 200) (end-qs vector :inline :offset 208) @@ -5182,14 +5194,14 @@ :size-assert #x130 :flag-assert #xb00000130 (:methods - (texture-anim-layer-method-9 (_type_) _type_ 9) - (texture-anim-layer-method-10 (_type_) _type_ 10) + (initialize-texture! (_type_) _type_ 9) + (clear-texture! (_type_) _type_ 10) ) ) (deftype texture-anim (structure) ((num-layers uint32 :offset-assert 0) - (func (function texture-anim int) :offset-assert 4) + (func (function dma-buffer texture-anim int) :offset-assert 4) (func-id symbol :offset 4) (init-func (function texture-anim int) :offset-assert 8) (init-func-id symbol :offset 8) @@ -5209,8 +5221,8 @@ :size-assert #x58 :flag-assert #xb00000058 (:methods - (texture-anim-method-9 (_type_) _type_ 9) - (texture-anim-method-10 (_type_) _type_ 10) + (init-textures! (_type_) _type_ 9) + (clear-textures! (_type_) _type_ 10) ) ) @@ -5221,8 +5233,8 @@ :size-assert #x10 :flag-assert #xb00000010 (:methods - (texture-anim-array-method-9 (_type_) _type_ 9) - (texture-anim-array-method-10 (_type_) _type_ 10) + (init! (_type_) _type_ 9) + (clear! (_type_) _type_ 10) ) ) @@ -5321,7 +5333,7 @@ :flag-assert #x90000008c ) -(define-extern *clut-translate* (pointer uint32)) +(define-extern *clut-translate* (pointer uint8)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; lights-h ;; @@ -24883,49 +24895,49 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-extern *texture-anim-work* texture-anim-work) -;; (define-extern texture-anim-layer-interp function) -;; (define-extern texture-anim-layer-add-shader function) -;; (define-extern texture-anim-layer-add-clut-shader function) -;; (define-extern texture-anim-layer-draw function) -;; (define-extern default-texture-anim-layer-func function) -;; (define-extern blend-clut-texture-anim-layer-func function) -;; (define-extern move-rg-to-ba-texture-anim-layer-func function) -;; (define-extern fill-rgb-texture-anim-layer-func function) -(define-extern update-texture-anim (function bucket-id none)) -;; (define-extern no-alpha-texture-anim-layer-func function) -;; (define-extern copy-alpha-texture-anim-layer-func function) -;; (define-extern copy-clut-alpha-texture-anim-layer-func function) -;; (define-extern set-alpha-texture-anim-layer-func function) -;; (define-extern set-clut-alpha-texture-anim-layer-func function) -;; (define-extern dest-texture-init function) -;; (define-extern src-texture-init function) -;; (define-extern src-texture-init-mt8 function) -;; (define-extern make-noise-texture function) -;; (define-extern make-cloud-clut function) -;; (define-extern texture-anim-cloud-clut-upload function) -;; (define-extern texture-anim-cloud-clut-init function) -;; (define-extern make-slime-clut function) -;; (define-extern texture-anim-slime-clut-upload function) -;; (define-extern texture-anim-slime-clut-init function) -;; (define-extern make-ramp-clut function) -;; (define-extern make-alpha-ramp-clut function) -;; (define-extern noise-texture-init function) -;; (define-extern texture-anim-alpha-ramp-clut-upload function) -;; (define-extern texture-anim-alpha-ramp-clut-init function) -;; (define-extern texture-anim-overide-size-init function) -;; (define-extern texture-anim-change-mt8h-init function) +(define-extern texture-anim-layer-interp (function texture-anim-layer float none)) +(define-extern texture-anim-layer-add-shader (function dma-buffer texture-anim-layer int none)) +(define-extern texture-anim-layer-add-clut-shader (function dma-buffer texture-anim-layer int none)) +(define-extern texture-anim-layer-draw (function dma-buffer int int texture-anim-layer none)) +(define-extern default-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern blend-clut-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern move-rg-to-ba-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern fill-rgb-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern update-texture-anim (function bucket-id texture-anim-array none)) +(define-extern no-alpha-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern copy-alpha-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern copy-clut-alpha-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern set-alpha-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern set-clut-alpha-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern dest-texture-init (function texture-anim none)) +(define-extern src-texture-init (function texture-anim-layer none)) +(define-extern src-texture-init-mt8 (function texture-anim-layer none)) +(define-extern make-noise-texture (function pointer int int int none)) +(define-extern make-cloud-clut (function (pointer uint32) float float none)) +(define-extern texture-anim-cloud-clut-upload (function dma-buffer texture-anim none)) +(define-extern texture-anim-cloud-clut-init (function texture-anim none)) +(define-extern make-slime-clut (function (pointer uint32) none)) +(define-extern texture-anim-slime-clut-upload (function dma-buffer texture-anim none)) +(define-extern texture-anim-slime-clut-init (function texture-anim none)) +(define-extern make-ramp-clut (function (pointer uint32) pointer object none)) +(define-extern make-alpha-ramp-clut (function (pointer uint32) none)) +(define-extern noise-texture-init (function texture-anim-layer none)) +(define-extern texture-anim-alpha-ramp-clut-upload (function dma-buffer texture-anim none)) +(define-extern texture-anim-alpha-ramp-clut-init (function texture-anim none)) +(define-extern texture-anim-overide-size-init (function texture-anim none)) +(define-extern texture-anim-change-mt8h-init (function texture-anim none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; texture-anim-funcs ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; (define-extern noise-texture-anim-layer-func function) -;; (define-extern cloud-texture-anim-layer-func function) -;; (define-extern cloud-texture-anim-func function) -;; (define-extern fog-texture-anim-init function) +(define-extern noise-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern cloud-texture-anim-layer-func (function dma-buffer uint int int texture-anim-layer float int)) +(define-extern cloud-texture-anim-func (function dma-buffer texture-anim int)) +(define-extern fog-texture-anim-init (function texture-anim int)) (define-extern *fog-texture-work* fog-texture-work) -;; (define-extern real-fog-texture-anim-func function) -;; (define-extern fog-texture-anim-func function) +(define-extern real-fog-texture-anim-func (function dma-buffer texture-anim int)) +(define-extern fog-texture-anim-func (function dma-buffer texture-anim int)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; texture-anim-tables ;; diff --git a/decompiler/config/jak2/ntsc_v1/label_types.jsonc b/decompiler/config/jak2/ntsc_v1/label_types.jsonc index a7779e4a1e..951c3aa444 100644 --- a/decompiler/config/jak2/ntsc_v1/label_types.jsonc +++ b/decompiler/config/jak2/ntsc_v1/label_types.jsonc @@ -19,7 +19,7 @@ ["L6", "texture-base"], ["L5", "texture-base"] ], - "texture-anim-h": [["L1", "(pointer uint32)", 64]], + "texture-anim-h": [["L1", "(pointer uint8)", 256]], "main-h": [["L3", "frame-stats"]], "font-h": [ ["L20", "matrix"], diff --git a/decompiler/config/jak2/ntsc_v1/stack_structures.jsonc b/decompiler/config/jak2/ntsc_v1/stack_structures.jsonc index abadb78de7..2448513d95 100644 --- a/decompiler/config/jak2/ntsc_v1/stack_structures.jsonc +++ b/decompiler/config/jak2/ntsc_v1/stack_structures.jsonc @@ -2232,5 +2232,6 @@ [16, "event-message-block"], [112, ["array", "collide-shape", 32]] ], - "(code impact gun-dark-shot)": [[160, ["array", "collide-shape", 16]]] + "(code impact gun-dark-shot)": [[160, ["array", "collide-shape", 16]]], + "texture-anim-layer-draw": [[16, "matrix"], [80, "matrix"], [144, "matrix"], [208, "matrix"]] } diff --git a/decompiler/config/jak2/ntsc_v1/type_casts.jsonc b/decompiler/config/jak2/ntsc_v1/type_casts.jsonc index 62f3e3c2b1..8ac466e42e 100644 --- a/decompiler/config/jak2/ntsc_v1/type_casts.jsonc +++ b/decompiler/config/jak2/ntsc_v1/type_casts.jsonc @@ -10383,5 +10383,114 @@ "(method 9 texture-anim-layer)": [ [5, "v1", "symbol"], [11, "v1", "symbol"] + ], + "make-noise-texture": [ + [32, "t6", "(pointer uint128)"], + [34, "t7", "(pointer uint128)"], + [36, "t4", "(pointer uint128)"], + [42, "t3", "(pointer uint128)"], + [44, "t2", "(pointer uint128)"] + ], + "texture-anim-layer-draw": [ + [[4, 162], "s4", "(pointer uint128)"] + ], + "move-rg-to-ba-texture-anim-layer-func": [ + [[305, 313], "a0", "dma-packet"], + [[315, 322], "a0", "gs-gif-tag"], + [325, "v1", "(pointer gs-xy-offset)"], + [327, "v1", "(pointer gs-reg64)"], + [335, "v1", "(pointer gs-frame)"], + [337, "v1", "(pointer gs-reg64)"] + ], + + "fill-rgb-texture-anim-layer-func": [ + [59, "v1", "(pointer uint128)"], + [66, "v1", "(pointer uint128)"], + [[67, 75], "t0", "vector4w"], + [[75, 81], "v1", "vector4w"], + [[85, 93], "a0", "dma-packet"], + [[95, 102], "a0", "gs-gif-tag"], + [109, "v1", "(pointer gs-frame)"], + [111, "v1", "(pointer gs-reg64)"], + [112, "v1", "(pointer uint64)"], + [114, "v1", "(pointer gs-reg64)"] + ], + + "update-texture-anim": [ + [135, "a1", "(pointer uint128)"], + [[137, 152], "t0", "vector4w"], + [[152, 160], "t0", "vector4w"], + [[161, 168], "a1", "vector4w"] + ], + + "copy-alpha-texture-anim-layer-func": [ + [72, "v1", "(pointer uint128)"], + [[73, 86], "t0", "vector4w"], + [[86, 96], "t0", "vector"], + [[96, 102], "t0", "vector4w"], + [[102, 113], "t0", "vector"], + [[113, 119], "t0", "vector4w"], + [[119, 130], "a3", "vector"], + [[130, 136], "a3", "vector4w"], + [[136, 148], "a2", "vector"], + [[149, 155], "v1", "vector4w"], + [[158, 165], "a0", "dma-packet"], + [[167, 173], "a0", "gs-gif-tag"], + [181, "v1", "(pointer gs-frame)"], + [183, "v1", "(pointer gs-reg64)"] + ], + + "copy-clut-alpha-texture-anim-layer-func": [ + [67, "a1", "(pointer uint128)"], + [[68, 81], "t0", "vector4w"], + [[81, 91], "t0", "vector"], + [[91, 97], "t0", "vector4w"], + [[97, 108], "t0", "vector"], + [[108, 114], "t0", "vector4w"], + [[114, 125], "a3", "vector"], + [[125, 131], "a3", "vector4w"], + [[131, 143], "a2", "vector"], + [[144, 149], "a1", "vector4w"], + [[153, 161], "a0", "dma-packet"], + [[162, 168], "a0", "gs-gif-tag"], + [176, "v1", "(pointer gs-frame)"], + [178, "v1", "(pointer gs-reg64)"] + ], + + "set-alpha-texture-anim-layer-func": [ + [49, "t0", "(pointer uint128)"], + [[50, 56], "t4", "vector4w"], + [[56, 64], "t3", "vector4w"], + [[65, 73], "t0", "vector4w"], + [[76, 82], "a3", "dma-packet"], + [[85, 91], "a3", "gs-gif-tag"], + [99, "a2", "(pointer gs-frame)"], + [101, "a2", "(pointer gs-reg64)"] + ], + + "set-clut-alpha-texture-anim-layer-func": [ + [48, "t0", "(pointer uint128)"], + [[48, 55], "t4", "vector4w"], + [[55, 63], "t3", "vector4w"], + [[64, 72], "t0", "vector4w"], + [[75, 81], "a3", "dma-packet"], + [[84, 90], "a3", "gs-gif-tag"], + [98, "a2", "(pointer gs-frame)"], + [100, "a2", "(pointer gs-reg64)"] + ], + + "noise-texture-anim-layer-func": [ + [[104, 110], "a0", "dma-packet"], + [[113, 119], "a0", "gs-gif-tag"], + [127, "v1", "(pointer gs-frame)"], + [129, "v1", "(pointer gs-reg64)"] + ], + + "real-fog-texture-anim-func": [ + [[0, 256], "s2", "(pointer uint32)"], + [[239, 245], "a0", "dma-packet"], + [[248, 254], "a0", "gs-gif-tag"], + [259, "v1", "(pointer gs-reg64)"] ] + } diff --git a/decompiler/config/jak2/ntsc_v1/var_names.jsonc b/decompiler/config/jak2/ntsc_v1/var_names.jsonc index ff29597d52..f6ea3e6a7a 100644 --- a/decompiler/config/jak2/ntsc_v1/var_names.jsonc +++ b/decompiler/config/jak2/ntsc_v1/var_names.jsonc @@ -4248,5 +4248,65 @@ "vars": { "v1-7": ["enm-options", "enemy-option"] } + }, + "texture-anim-layer-draw": { + "args": ["dma-buf", "width", "height", "layer"] + }, + "default-texture-anim-layer-func": { + "args": ["dma-buf", "arg1", "width", "height", "layer", "time"] + }, + "blend-clut-texture-anim-layer-func": { + "args": ["dma-buf", "arg1", "width", "height", "layer", "time"] + }, + "move-rg-to-ba-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"], + "vars": { + "s2-0": "tw", + "v1-1": "th", + "a1-1": "tbp", + "a0-6": "tbw", + "a2-1": "fbmask" + } + }, + "fill-rgb-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"] + }, + "update-texture-anim": { + "args": ["bucket", "anim-array"], + "vars": {"s3-0": "dma-buf", "s2-0": "anim-idx", "s1-0": "anim", "v1-11": "dest-tex", "s0-0": "tex-width", "sv-16": "tex-height", + "sv-32": "fbp-for-tex", "sv-48": "layer-idx", "t0-6": "layer"} + }, + "no-alpha-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"] + }, + "dest-texture-init": { + "args": ["tex-anim"], + "vars": {"v1-1":"dest-tex", "a0-2": "size", "a1-1": "dest"} + }, + "src-texture-init": { + "args": ["layer"], + "vars": {"v1-1": "tex", "a0-2":"size", "a1-1":"addr"} + }, + "copy-alpha-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"] + }, + "copy-clut-alpha-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"] + }, + "set-alpha-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"] + }, + "set-clut-alpha-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"] + }, + "src-texture-init-mt8": { + "args": ["layer"], + "vars" : {"v1-1": "tex", "a0-2": "width", "a1-1": "height", "a2-0": "dest", "a3-0":"clutdest"} + }, + "noise-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"] + }, + "cloud-texture-anim-layer-func": { + "args": ["dma-buf", "fbp-to-draw", "width", "height", "layer", "time"] } } diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 70fec8ec06..37a878c11f 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -58,6 +58,7 @@ set(RUNTIME_SOURCE graphics/opengl_renderer/sprite/Sprite3_Distort.cpp graphics/opengl_renderer/sprite/Sprite3_Glow.cpp graphics/opengl_renderer/sprite/Sprite3.cpp + graphics/opengl_renderer/TextureAnimator.cpp graphics/opengl_renderer/TextureUploadHandler.cpp graphics/opengl_renderer/VisDataHandler.cpp graphics/opengl_renderer/Warp.cpp diff --git a/game/graphics/opengl_renderer/BucketRenderer.h b/game/graphics/opengl_renderer/BucketRenderer.h index 773d764318..78c03e9072 100644 --- a/game/graphics/opengl_renderer/BucketRenderer.h +++ b/game/graphics/opengl_renderer/BucketRenderer.h @@ -7,6 +7,7 @@ #include "game/graphics/opengl_renderer/Profiler.h" #include "game/graphics/opengl_renderer/Shader.h" +#include "game/graphics/opengl_renderer/TextureAnimator.h" #include "game/graphics/opengl_renderer/buckets.h" #include "game/graphics/opengl_renderer/loader/Loader.h" #include "game/graphics/texture/TexturePool.h" @@ -31,6 +32,7 @@ struct SharedRenderState { ShaderLibrary shaders; std::shared_ptr texture_pool; std::shared_ptr loader; + std::shared_ptr texture_animator; u32 buckets_base = 0; // address of buckets array. u32 next_bucket = 0; // address of next bucket that we haven't started rendering in buckets diff --git a/game/graphics/opengl_renderer/OpenGLRenderer.cpp b/game/graphics/opengl_renderer/OpenGLRenderer.cpp index 5f2ccb1073..abaf5f8aec 100644 --- a/game/graphics/opengl_renderer/OpenGLRenderer.cpp +++ b/game/graphics/opengl_renderer/OpenGLRenderer.cpp @@ -92,6 +92,7 @@ OpenGLRenderer::OpenGLRenderer(std::shared_ptr texture_pool, init_bucket_renderers_jak1(); break; case GameVersion::Jak2: + m_render_state.texture_animator = std::make_shared(); init_bucket_renderers_jak2(); break; default: @@ -1181,6 +1182,8 @@ void OpenGLRenderer::finish_screenshot(const std::string& output_name, // copy to clipboard (windows only) copy_texture_to_clipboard(width, height, buffer); } +#else + (void)quick_screenshot; #endif // flip upside down in place diff --git a/game/graphics/opengl_renderer/TextureAnimator.cpp b/game/graphics/opengl_renderer/TextureAnimator.cpp new file mode 100644 index 0000000000..4c064d996f --- /dev/null +++ b/game/graphics/opengl_renderer/TextureAnimator.cpp @@ -0,0 +1,10 @@ +#include "TextureAnimator.h" + +void TextureAnimator::handle_texture_anim_data(DmaFollower& dma) { + auto vif0 = dma.current_tag_vifcode0(); + while (vif0.kind != VifCode::Kind::PC_PORT || vif0.immediate != 13) { + dma.read_and_advance(); + vif0 = dma.current_tag_vifcode0(); + } + dma.read_and_advance(); +} \ No newline at end of file diff --git a/game/graphics/opengl_renderer/TextureAnimator.h b/game/graphics/opengl_renderer/TextureAnimator.h new file mode 100644 index 0000000000..30c29449ab --- /dev/null +++ b/game/graphics/opengl_renderer/TextureAnimator.h @@ -0,0 +1,8 @@ +#pragma once + +#include "common/dma/dma_chain_read.h" + +class TextureAnimator { + public: + void handle_texture_anim_data(DmaFollower& dma); +}; diff --git a/game/graphics/opengl_renderer/TextureUploadHandler.cpp b/game/graphics/opengl_renderer/TextureUploadHandler.cpp index 97ee641aca..cda48dae7e 100644 --- a/game/graphics/opengl_renderer/TextureUploadHandler.cpp +++ b/game/graphics/opengl_renderer/TextureUploadHandler.cpp @@ -22,6 +22,11 @@ void TextureUploadHandler::render(DmaFollower& dma, while (dma.current_tag_offset() != render_state->next_bucket) { auto dma_tag = dma.current_tag(); + auto vif0 = dma.current_tag_vifcode0(); + if (vif0.kind == VifCode::Kind::PC_PORT && vif0.immediate == 12) { + dma.read_and_advance(); + render_state->texture_animator->handle_texture_anim_data(dma); + } // does it look like data to do eye rendering? if (dma_tag.qwc == (128 / 16)) { // note: these uploads may have texture that we need for eye rendering. diff --git a/game/graphics/opengl_renderer/Warp.cpp b/game/graphics/opengl_renderer/Warp.cpp index 7c4db32a51..0b68a888ab 100644 --- a/game/graphics/opengl_renderer/Warp.cpp +++ b/game/graphics/opengl_renderer/Warp.cpp @@ -8,7 +8,7 @@ void Warp::draw_debug_window() { } void Warp::render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) { - m_fb_copier.copy_now(render_state->render_fb_w, render_state->render_fb_h, 0, 0, + m_fb_copier.copy_now(render_state->render_fb_w, render_state->render_fb_h, render_state->render_fb); render_state->texture_pool->move_existing_to_vram(m_warp_src_tex, m_tbp); m_generic->render_in_mode(dma, render_state, prof, Generic2::Mode::WARP); diff --git a/game/graphics/opengl_renderer/opengl_utils.cpp b/game/graphics/opengl_renderer/opengl_utils.cpp index 1dee050f3a..4c5464768c 100644 --- a/game/graphics/opengl_renderer/opengl_utils.cpp +++ b/game/graphics/opengl_renderer/opengl_utils.cpp @@ -177,11 +177,7 @@ FramebufferCopier::~FramebufferCopier() { glDeleteFramebuffers(1, &m_fbo); } -void FramebufferCopier::copy_now(int render_fb_w, - int render_fb_h, - int render_fb_x, - int render_fb_y, - GLuint render_fb) { +void FramebufferCopier::copy_now(int render_fb_w, int render_fb_h, GLuint render_fb) { if (m_fbo_width != render_fb_w || m_fbo_height != render_fb_h) { m_fbo_width = render_fb_w; m_fbo_height = render_fb_h; diff --git a/game/graphics/opengl_renderer/opengl_utils.h b/game/graphics/opengl_renderer/opengl_utils.h index d5be2d8add..07efa96212 100644 --- a/game/graphics/opengl_renderer/opengl_utils.h +++ b/game/graphics/opengl_renderer/opengl_utils.h @@ -64,11 +64,7 @@ class FramebufferCopier { ~FramebufferCopier(); FramebufferCopier(const FramebufferCopier&) = delete; FramebufferCopier& operator=(const FramebufferCopier&) = delete; - void copy_now(int render_fb_w, - int render_fb_h, - int render_fb_x, - int render_fb_y, - GLuint render_fb); + void copy_now(int render_fb_w, int render_fb_h, GLuint render_fb); u64 texture() const { return m_fbo_texture; } private: diff --git a/game/kernel/jak2/kmachine.cpp b/game/kernel/jak2/kmachine.cpp index 68984ad2ce..0c66dde2f2 100644 --- a/game/kernel/jak2/kmachine.cpp +++ b/game/kernel/jak2/kmachine.cpp @@ -525,7 +525,6 @@ void update_discord_rpc(u32 discord_info) { // Get the data from GOAL int orbs = (int)info->orb_count; int gems = (int)info->gem_count; - u32 deaths = info->death_count; // convert encodings std::string status = get_font_bank(GameTextVersion::JAK2) ->convert_game_to_utf8(Ptr(info->status).c()->data()); diff --git a/game/mips2c/jak2_functions/merc_blend_shape.cpp b/game/mips2c/jak2_functions/merc_blend_shape.cpp index 18594771e6..2c854815d7 100644 --- a/game/mips2c/jak2_functions/merc_blend_shape.cpp +++ b/game/mips2c/jak2_functions/merc_blend_shape.cpp @@ -93,10 +93,10 @@ void simplified1(BlercContext* context, u8* ee_buffer) { } } +} // namespace void blerc_c(void* a, void* b) { simplified1((BlercContext*)a, (u8*)b); } -} // namespace // clang-format off diff --git a/game/system/hid/display_manager.cpp b/game/system/hid/display_manager.cpp index d019193c02..fd6adee73a 100644 --- a/game/system/hid/display_manager.cpp +++ b/game/system/hid/display_manager.cpp @@ -173,7 +173,7 @@ void DisplayManager::set_window_size(int width, int height) { void DisplayManager::enqueue_set_window_display_mode(WindowDisplayMode mode) { const std::lock_guard lock(event_queue_mtx); - ee_event_queue.push({EEDisplayEventType::SET_WINDOW_DISPLAY_MODE, mode}); + ee_event_queue.push({EEDisplayEventType::SET_WINDOW_DISPLAY_MODE, mode, {}}); } void DisplayManager::set_window_display_mode(WindowDisplayMode mode) { @@ -235,7 +235,7 @@ void DisplayManager::set_window_display_mode(WindowDisplayMode mode) { void DisplayManager::enqueue_set_fullscreen_display_id(int display_id) { const std::lock_guard lock(event_queue_mtx); - ee_event_queue.push({EEDisplayEventType::SET_FULLSCREEN_DISPLAY_ID, display_id}); + ee_event_queue.push({EEDisplayEventType::SET_FULLSCREEN_DISPLAY_ID, display_id, {}}); } void DisplayManager::set_fullscreen_display_id(int display_id) { diff --git a/game/system/hid/input_manager.cpp b/game/system/hid/input_manager.cpp index b22b124b9b..5d5ba3caa4 100644 --- a/game/system/hid/input_manager.cpp +++ b/game/system/hid/input_manager.cpp @@ -111,7 +111,7 @@ void InputManager::refresh_device_list() { void InputManager::enqueue_ignore_background_controller_events(const bool ignore) { const std::lock_guard lock(m_event_queue_mtx); - ee_event_queue.push({EEInputEventType::IGNORE_BACKGROUND_CONTROLLER_EVENTS, ignore}); + ee_event_queue.push({EEInputEventType::IGNORE_BACKGROUND_CONTROLLER_EVENTS, ignore, {}, {}, {}}); } void InputManager::ignore_background_controller_events(const bool ignore) { @@ -347,7 +347,7 @@ void InputManager::enqueue_update_rumble(const int port, const u8 low_intensity, const u8 high_intensity) { const std::lock_guard lock(m_event_queue_mtx); - ee_event_queue.push({EEInputEventType::UPDATE_RUMBLE, port, low_intensity, high_intensity}); + ee_event_queue.push({EEInputEventType::UPDATE_RUMBLE, port, low_intensity, high_intensity, {}}); } int InputManager::update_rumble(int port, u8 low_intensity, u8 high_intensity) { @@ -371,7 +371,7 @@ void InputManager::enqueue_update_mouse_options(const bool enabled, const bool control_movement) { const std::lock_guard lock(m_event_queue_mtx); ee_event_queue.push( - {EEInputEventType::UPDATE_MOUSE_OPTIONS, enabled, control_camera, control_movement}); + {EEInputEventType::UPDATE_MOUSE_OPTIONS, enabled, control_camera, control_movement, {}}); } void InputManager::update_mouse_options(const bool enabled, @@ -436,7 +436,7 @@ void InputManager::reset_input_bindings_to_defaults(const int port, void InputManager::enqueue_set_auto_hide_mouse(const bool auto_hide_mouse) { const std::lock_guard lock(m_event_queue_mtx); - ee_event_queue.push({EEInputEventType::SET_AUTO_HIDE_MOUSE, auto_hide_mouse}); + ee_event_queue.push({EEInputEventType::SET_AUTO_HIDE_MOUSE, auto_hide_mouse, {}, {}, {}}); } void InputManager::set_auto_hide_mouse(const bool auto_hide_mouse) { diff --git a/goal_src/jak2/engine/gfx/ocean/ocean-texture.gc b/goal_src/jak2/engine/gfx/ocean/ocean-texture.gc index 88c0cac5f2..2ca68694bf 100644 --- a/goal_src/jak2/engine/gfx/ocean/ocean-texture.gc +++ b/goal_src/jak2/engine/gfx/ocean/ocean-texture.gc @@ -282,7 +282,7 @@ (defmethod ocean-method-80 ocean ((obj ocean) (arg0 (pointer rgba))) (dotimes (v1-0 256) - (let ((a0-3 (-> (the-as (pointer uint8) (&+ *clut-translate* v1-0))))) + (let ((a0-3 (-> *clut-translate* v1-0))) (set! (-> arg0 a0-3 r) v1-0) (set! (-> arg0 a0-3 g) v1-0) (set! (-> arg0 a0-3 b) v1-0) @@ -434,9 +434,9 @@ (dotimes (a3-9 (/ s5-1 16)) (dma-buffer-add-gs-set arg0 (uv (new 'static 'gs-uv :v #x8 :u (+ (* a3-9 256) 8))) - (xyz2 (shr (shl (+ (* a3-9 256) 128) 48) 48)) + (xyz2 (new 'static 'gs-xyz :x (+ (* a3-9 256) 128))) (uv (new 'static 'gs-uv :u (+ (* a3-9 256) 136) :v (+ (* a2-6 16) 8))) - (xyz2 (logior (shr (shl (+ (* a3-9 256) 256) 48) 48) (shr (shl (* a2-6 16) 48) 32))) + (xyz2 (new 'static 'gs-xyz :y (* a2-6 16) :x (+ (* a3-9 256) 256))) ) ) ) @@ -453,9 +453,9 @@ (dotimes (v1-73 (/ s5-1 16)) (dma-buffer-add-gs-set arg0 (uv (new 'static 'gs-uv :v #x8 :u (+ (* v1-73 256) 8))) - (xyz2 (shr (shl (+ (* v1-73 256) 128) 48) 48)) + (xyz2 (new 'static 'gs-xyz :x (+ (* v1-73 256) 128))) (uv (new 'static 'gs-uv :u (+ (* v1-73 256) 136) :v (+ (* s4-3 16) 8))) - (xyz2 (logior (shr (shl (+ (* v1-73 256) 256) 48) 48) (shr (shl (* s4-3 16) 48) 32))) + (xyz2 (new 'static 'gs-xyz :y (* s4-3 16) :x (+ (* v1-73 256) 256))) ) ) ) diff --git a/goal_src/jak2/engine/gfx/texture/texture-anim-funcs.gc b/goal_src/jak2/engine/gfx/texture/texture-anim-funcs.gc index 871fbe1116..3a12c90aed 100644 --- a/goal_src/jak2/engine/gfx/texture/texture-anim-funcs.gc +++ b/goal_src/jak2/engine/gfx/texture/texture-anim-funcs.gc @@ -5,8 +5,239 @@ ;; name in dgo: texture-anim-funcs ;; dgos: ENGINE, GAME -;; temp -(define *fog-texture-work* (new 'static 'fog-texture-work :const (new 'static 'vector :x 0.00390625))) - ;; DECOMP BEGINS +(defun noise-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (< time (-> layer end-time))) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (upload-vram-data dma-buf (the-as int (-> layer tex dest 0)) (the-as pointer (-> layer tex pad 0)) 32 32) + (dma-buffer-add-gs-set dma-buf (texflush 0)) + (texture-anim-layer-add-shader dma-buf layer 1) + (let ((s1-0 (/ (+ width 63) 64))) + (dma-buffer-add-gs-set dma-buf (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw s1-0 :fbp fbp-to-draw))) + (texture-anim-layer-draw dma-buf width height layer) + (let* ((v1-13 dma-buf) + (a0-17 (the-as object (-> v1-13 base))) + ) + (set! (-> (the-as dma-packet a0-17) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-17) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-17) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-13 base) (&+ (the-as pointer a0-17) 16)) + ) + (let* ((v1-14 dma-buf) + (a0-19 (the-as object (-> v1-14 base))) + ) + (set! (-> (the-as gs-gif-tag a0-19) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a0-19) regs) GIF_REGS_ALL_AD) + (set! (-> v1-14 base) (&+ (the-as pointer a0-19) 16)) + ) + (let ((v1-15 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-frame) v1-15) 0) (new 'static 'gs-frame :fbw s1-0 :fbp fbp-to-draw)) + (set! (-> (the-as (pointer gs-reg64) v1-15) 1) (gs-reg64 frame-1)) + (set! (-> dma-buf base) (&+ v1-15 16)) + ) + ) + ) + ) + 0 + ) + +(defun cloud-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (< time (-> layer end-time))) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (let* ((v1-4 (-> layer tex)) + (t0-1 (/ (-> v1-4 w) 2)) + (a3-1 (/ (-> v1-4 h) 2)) + ) + (upload-vram-data dma-buf (the-as int (-> v1-4 dest 0)) (the-as pointer (-> v1-4 pad 0)) a3-1 t0-1) + ) + (dma-buffer-add-gs-set dma-buf (texflush 0)) + (texture-anim-layer-add-shader dma-buf layer 1) + (texture-anim-layer-draw dma-buf width height layer) + ) + ) + 0 + ) + +(defun cloud-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim)) + (with-pp + (when (>= (+ (-> arg1 frame-time) (* (-> arg1 frame-delta) (-> pp clock seconds-per-frame))) (-> arg1 frame-mod)) + (let ((s5-0 (-> arg1 data 0 tex)) + (s4-0 (-> arg1 data 1 tex)) + (s3-0 (-> arg1 data 0 tex w)) + ) + (when (not (paused?)) + (set! (-> arg1 data 0 tex) s4-0) + (set! (-> arg1 data 1 tex) s5-0) + (make-noise-texture (the-as pointer (-> s5-0 pad 0)) s3-0 s3-0 s3-0) + ) + ) + ) + 0 + ) + ) + +(defun fog-texture-anim-init ((arg0 texture-anim)) + (let ((gp-0 (new 'loading-level 'fog8x256)) + (s4-0 (new 'loading-level 'clut16x16)) + ) + (when (and gp-0 s4-0) + (let ((v1-5 (new 'loading-level 'texture))) + (let ((a0-4 (the int (-> arg0 extra x))) + (a1-3 (the int (-> arg0 extra y))) + ) + (set! (-> arg0 tex) v1-5) + (set! (-> v1-5 pad 0) (the-as uint gp-0)) + (set! (-> v1-5 pad 1) (the-as uint s4-0)) + (set! (-> v1-5 w) 256) + (set! (-> v1-5 h) 1) + (set! (-> v1-5 num-mips) (the-as uint 1)) + (set! (-> v1-5 psm) (gs-psm mt8)) + (set! (-> v1-5 clutpsm) (the-as uint 0)) + (set! (-> v1-5 dest 0) (the-as uint (* a0-4 32))) + (set! (-> v1-5 clutdest) (the-as uint (* a1-3 32))) + ) + (set! (-> v1-5 width 0) (the-as uint 4)) + (set! (-> v1-5 masks data 0 mask quad) (the-as uint128 0)) + (set! (-> v1-5 masks data 1 mask quad) (the-as uint128 0)) + (set! (-> v1-5 masks data 2 mask quad) (the-as uint128 0)) + ) + 0 + (dotimes (v1-7 256) + (nop!) + (nop!) + (nop!) + (nop!) + (set! (-> gp-0 image v1-7) (the-as uint v1-7)) + ) + ) + ) + 0 + ) + +(define *fog-texture-work* (new 'static 'fog-texture-work :const (new 'static 'vector :x 0.00390625))) + +;; WARN: Return type mismatch symbol vs int. +(defun real-fog-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim)) + (local-vars (sv-48 int)) + (let ((s4-0 (new 'stack-no-clear 'vector)) + (s3-0 (new 'stack-no-clear 'vector)) + (s1-0 *fog-texture-work*) + (s2-0 (the-as (pointer uint32) (-> arg1 tex pad 1))) + ) + (let ((v1-1 (-> s1-0 color))) + (dotimes (a0-1 256) + (set! (-> s2-0 a0-1) v1-1) + ) + ) + (set! sv-48 0) + (let ((s0-0 0)) + (let ((f0-0 40955904.0) + (f1-0 -40955904.0) + ) + (dotimes (v1-7 4) + (let ((f2-0 (-> *fog-texture-work* corner v1-7 y))) + (when (< f2-0 f0-0) + (set! f0-0 f2-0) + (set! sv-48 v1-7) + sv-48 + ) + (when (< f1-0 f2-0) + (set! f1-0 f2-0) + (set! s0-0 v1-7) + ) + ) + ) + ) + (set! (-> s4-0 quad) (-> *fog-texture-work* corner sv-48 quad)) + (vector-! s3-0 (-> *fog-texture-work* corner s0-0) (-> *fog-texture-work* corner sv-48)) + (vector-float/! s3-0 s3-0 256.0) + (set! (-> *fog-texture-work* min-corner quad) (-> *fog-texture-work* corner sv-48 quad)) + (set! (-> *fog-texture-work* max-corner quad) (-> *fog-texture-work* corner s0-0 quad)) + ) + 0.0 + 0.0 + (let ((f0-4 (fmax 4096.0 (-> *math-camera* trans y))) + (f1-2 (-> arg1 extra z)) + (f2-1 (-> s1-0 alpha-near)) + (f3-0 (-> s1-0 alpha-far)) + (f4-0 (-> s1-0 alpha-delta)) + (f5-0 (-> s1-0 fog-near)) + (f6-0 (-> s1-0 fog-far)) + (f7-0 (-> s1-0 fog-delta)) + ) + (dotimes (v1-19 256) + (let* ((f8-0 (-> s4-0 y)) + (f8-1 (cond + ((= f8-0 0.0) + f3-0 + ) + ((< f8-0 0.0) + (let ((f9-4 (fmin f6-0 (/ (* f0-4 (vector-length s4-0)) (- f8-0))))) + (+ f2-1 (* f4-0 (/ (fmax 0.0 (- f9-4 f5-0)) f7-0))) + ) + ) + (else + (let ((f9-8 (fmin f6-0 (/ (* f1-2 (vector-length s4-0)) f8-0)))) + (+ f2-1 (* f4-0 (/ (fmax 0.0 (- f9-8 f5-0)) f7-0))) + ) + ) + ) + ) + ) + (set! (-> s2-0 (-> *clut-translate* v1-19)) + (logior (logand (-> s2-0 (-> *clut-translate* v1-19)) (the-as uint #xffffffff00ffffff)) + (shr (shl (the int (* 128.0 f8-1)) 56) 32) + ) + ) + ) + (vector+! s4-0 s4-0 s3-0) + ) + ) + ) + (let ((s5-1 (-> arg1 tex))) + (dma-buffer-add-gs-set arg0 + (bitbltbuf + (new 'static 'gs-bitbltbuf :dpsm (the-as int (-> s5-1 psm)) :dbp (-> s5-1 dest 0) :dbw (-> s5-1 width 0)) + ) + (trxpos (new 'static 'gs-trxpos)) + (trxreg (new 'static 'gs-trxreg :rrw (-> s5-1 w) :rrh (-> s5-1 h))) + (trxdir (new 'static 'gs-trxdir)) + ) + (dma-buffer-add-ref-texture arg0 (the-as pointer (-> s5-1 pad 0)) (-> s5-1 w) (-> s5-1 h) (-> s5-1 psm)) + (upload-vram-data arg0 (the-as int (-> s5-1 clutdest)) (the-as pointer (-> s5-1 pad 1)) 16 16) + (set! (-> *texture-pool* ids (shr (-> s5-1 clutdest) 6)) (the-as uint 0)) + (let* ((v1-29 arg0) + (a0-51 (the-as object (-> v1-29 base))) + ) + (set! (-> (the-as dma-packet a0-51) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-51) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-51) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-29 base) (&+ (the-as pointer a0-51) 16)) + ) + (let* ((v1-30 arg0) + (a0-53 (the-as object (-> v1-30 base))) + ) + (set! (-> (the-as gs-gif-tag a0-53) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a0-53) regs) GIF_REGS_ALL_AD) + (set! (-> v1-30 base) (&+ (the-as pointer a0-53) 16)) + ) + (let ((v1-31 (-> arg0 base))) + (set! (-> (the-as (pointer int64) v1-31)) 0) + (set! (-> (the-as (pointer gs-reg64) v1-31) 1) (gs-reg64 texflush)) + (set! (-> arg0 base) (&+ v1-31 16)) + ) + (let ((v1-34 (shr (-> s5-1 dest 0) 6))) + (dotimes (a0-56 3) + (set! (-> *texture-pool* ids (+ v1-34 a0-56)) (the-as uint 0)) + ) + ) + ) + (the-as int #f) + ) + +(defun fog-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim)) + (real-fog-texture-anim-func arg0 arg1) + ) diff --git a/goal_src/jak2/engine/gfx/texture/texture-anim-h.gc b/goal_src/jak2/engine/gfx/texture/texture-anim-h.gc index 3dd9c6ba15..3c06d86d2c 100644 --- a/goal_src/jak2/engine/gfx/texture/texture-anim-h.gc +++ b/goal_src/jak2/engine/gfx/texture/texture-anim-h.gc @@ -5,7 +5,7 @@ ;; name in dgo: texture-anim-h ;; dgos: ENGINE, GAME -(define-extern update-texture-anim (function bucket-id none)) +(define-extern update-texture-anim (function bucket-id texture-anim-array none)) ;; NOTE - for intro-scenes (define-extern set-jakb-prison-texture-morph! (function float none)) @@ -13,48 +13,60 @@ ;; DECOMP BEGINS (deftype texture-anim-layer (structure) - ((extra vector :inline :offset 240) - (func (function texture-anim-layer int) :offset 256) - (func-id symbol :offset 256) - (init-func (function texture-anim-layer int) :offset 260) - (init-func-id symbol :offset 260) - (tex texture :offset 264) - (start-time float :offset 268) - (end-time float :offset 272) - (tex-name string :offset 276) - (test gs-test :offset 280) - (alpha gs-alpha :offset 288) - (clamp gs-clamp :offset 296) - (start-color vector :inline :offset 80) - (start-scale vector2 :inline :offset 96) - (start-offset vector2 :inline :offset 104) - (start-st-scale vector2 :inline :offset 112) - (start-st-offset vector2 :inline :offset 120) - (start-qs vector :inline :offset 128) - (start-rot degrees :offset 144) - (start-st-rot degrees :offset 148) - (end-color vector :inline :offset 160) - (end-scale vector2 :inline :offset 176) - (end-offset vector2 :inline :offset 184) - (end-st-scale vector2 :inline :offset 192) - (end-st-offset vector2 :inline :offset 200) - (end-qs vector :inline :offset 208) - (end-rot degrees :offset 224) - (end-st-rot degrees :offset 228) + ((interpolated-color vector :inline) ;; added + (interpolated-scale-offset vector :inline) + (interpolated-st-scale-offset vector :inline) + (interpolated-qs vector :inline) + (interpolated-rot vector :inline) + (extra vector :inline :offset 240) + (func (function dma-buffer uint int int texture-anim-layer float int) :offset 256) + (func-id symbol :offset 256) + (init-func (function texture-anim-layer int) :offset 260) + (init-func-id symbol :offset 260) + (tex texture :offset 264) + (start-time float :offset 268) + (end-time float :offset 272) + (tex-name string :offset 276) + (test gs-test :offset 280) + (alpha gs-alpha :offset 288) + (clamp gs-clamp :offset 296) + + (start-vectors vector 5 :inline :offset 80) ;; added + + (start-color vector :inline :offset 80) + (start-scale vector2 :inline :offset 96) + (start-offset vector2 :inline :offset 104) + (start-st-scale vector2 :inline :offset 112) + (start-st-offset vector2 :inline :offset 120) + (start-qs vector :inline :offset 128) + (start-rot degrees :offset 144) + (start-st-rot degrees :offset 148) + + (end-vectors vector 5 :inline :offset 160) ;; added + + (end-color vector :inline :offset 160) + (end-scale vector2 :inline :offset 176) + (end-offset vector2 :inline :offset 184) + (end-scale-offset vector :inline :offset 176) + (end-st-scale vector2 :inline :offset 192) + (end-st-offset vector2 :inline :offset 200) + (end-qs vector :inline :offset 208) + (end-rot degrees :offset 224) + (end-st-rot degrees :offset 228) ) :method-count-assert 11 :size-assert #x130 :flag-assert #xb00000130 (:methods - (texture-anim-layer-method-9 (_type_) _type_ 9) - (texture-anim-layer-method-10 (_type_) _type_ 10) + (initialize-texture! (_type_) _type_ 9) + (clear-texture! (_type_) _type_ 10) ) ) (deftype texture-anim (structure) ((num-layers uint32 :offset-assert 0) - (func (function texture-anim int) :offset-assert 4) + (func (function dma-buffer texture-anim int) :offset-assert 4) (func-id symbol :offset 4) (init-func (function texture-anim int) :offset-assert 8) (init-func-id symbol :offset 8) @@ -74,8 +86,8 @@ :size-assert #x58 :flag-assert #xb00000058 (:methods - (texture-anim-method-9 (_type_) _type_ 9) - (texture-anim-method-10 (_type_) _type_ 10) + (init-textures! (_type_) _type_ 9) + (clear-textures! (_type_) _type_ 10) ) ) @@ -87,8 +99,8 @@ :size-assert #x10 :flag-assert #xb00000010 (:methods - (texture-anim-array-method-9 (_type_) _type_ 9) - (texture-anim-array-method-10 (_type_) _type_ 10) + (init! (_type_) _type_ 9) + (clear! (_type_) _type_ 10) ) ) @@ -195,70 +207,262 @@ ) -(define *clut-translate* (new 'static 'array uint32 64 - #x3020100 - #x7060504 - #x13121110 - #x17161514 - #xb0a0908 - #xf0e0d0c - #x1b1a1918 - #x1f1e1d1c - #x23222120 - #x27262524 - #x33323130 - #x37363534 - #x2b2a2928 - #x2f2e2d2c - #x3b3a3938 - #x3f3e3d3c - #x43424140 - #x47464544 - #x53525150 - #x57565554 - #x4b4a4948 - #x4f4e4d4c - #x5b5a5958 - #x5f5e5d5c - #x63626160 - #x67666564 - #x73727170 - #x77767574 - #x6b6a6968 - #x6f6e6d6c - #x7b7a7978 - #x7f7e7d7c - #x83828180 - #x87868584 - #x93929190 - #x97969594 - #x8b8a8988 - #x8f8e8d8c - #x9b9a9998 - #x9f9e9d9c - #xa3a2a1a0 - #xa7a6a5a4 - #xb3b2b1b0 - #xb7b6b5b4 - #xabaaa9a8 - #xafaeadac - #xbbbab9b8 - #xbfbebdbc - #xc3c2c1c0 - #xc7c6c5c4 - #xd3d2d1d0 - #xd7d6d5d4 - #xcbcac9c8 - #xcfcecdcc - #xdbdad9d8 - #xdfdedddc - #xe3e2e1e0 - #xe7e6e5e4 - #xf3f2f1f0 - #xf7f6f5f4 - #xebeae9e8 - #xefeeedec - #xfbfaf9f8 - #xfffefdfc +(define *clut-translate* (new 'static 'array uint8 256 + #x0 + #x1 + #x2 + #x3 + #x4 + #x5 + #x6 + #x7 + #x10 + #x11 + #x12 + #x13 + #x14 + #x15 + #x16 + #x17 + #x8 + #x9 + #xa + #xb + #xc + #xd + #xe + #xf + #x18 + #x19 + #x1a + #x1b + #x1c + #x1d + #x1e + #x1f + #x20 + #x21 + #x22 + #x23 + #x24 + #x25 + #x26 + #x27 + #x30 + #x31 + #x32 + #x33 + #x34 + #x35 + #x36 + #x37 + #x28 + #x29 + #x2a + #x2b + #x2c + #x2d + #x2e + #x2f + #x38 + #x39 + #x3a + #x3b + #x3c + #x3d + #x3e + #x3f + #x40 + #x41 + #x42 + #x43 + #x44 + #x45 + #x46 + #x47 + #x50 + #x51 + #x52 + #x53 + #x54 + #x55 + #x56 + #x57 + #x48 + #x49 + #x4a + #x4b + #x4c + #x4d + #x4e + #x4f + #x58 + #x59 + #x5a + #x5b + #x5c + #x5d + #x5e + #x5f + #x60 + #x61 + #x62 + #x63 + #x64 + #x65 + #x66 + #x67 + #x70 + #x71 + #x72 + #x73 + #x74 + #x75 + #x76 + #x77 + #x68 + #x69 + #x6a + #x6b + #x6c + #x6d + #x6e + #x6f + #x78 + #x79 + #x7a + #x7b + #x7c + #x7d + #x7e + #x7f + #x80 + #x81 + #x82 + #x83 + #x84 + #x85 + #x86 + #x87 + #x90 + #x91 + #x92 + #x93 + #x94 + #x95 + #x96 + #x97 + #x88 + #x89 + #x8a + #x8b + #x8c + #x8d + #x8e + #x8f + #x98 + #x99 + #x9a + #x9b + #x9c + #x9d + #x9e + #x9f + #xa0 + #xa1 + #xa2 + #xa3 + #xa4 + #xa5 + #xa6 + #xa7 + #xb0 + #xb1 + #xb2 + #xb3 + #xb4 + #xb5 + #xb6 + #xb7 + #xa8 + #xa9 + #xaa + #xab + #xac + #xad + #xae + #xaf + #xb8 + #xb9 + #xba + #xbb + #xbc + #xbd + #xbe + #xbf + #xc0 + #xc1 + #xc2 + #xc3 + #xc4 + #xc5 + #xc6 + #xc7 + #xd0 + #xd1 + #xd2 + #xd3 + #xd4 + #xd5 + #xd6 + #xd7 + #xc8 + #xc9 + #xca + #xcb + #xcc + #xcd + #xce + #xcf + #xd8 + #xd9 + #xda + #xdb + #xdc + #xdd + #xde + #xdf + #xe0 + #xe1 + #xe2 + #xe3 + #xe4 + #xe5 + #xe6 + #xe7 + #xf0 + #xf1 + #xf2 + #xf3 + #xf4 + #xf5 + #xf6 + #xf7 + #xe8 + #xe9 + #xea + #xeb + #xec + #xed + #xee + #xef + #xf8 + #xf9 + #xfa + #xfb + #xfc + #xfd + #xfe + #xff ) ) diff --git a/goal_src/jak2/engine/gfx/texture/texture-anim.gc b/goal_src/jak2/engine/gfx/texture/texture-anim.gc index 347cae833f..aaa48e6c39 100644 --- a/goal_src/jak2/engine/gfx/texture/texture-anim.gc +++ b/goal_src/jak2/engine/gfx/texture/texture-anim.gc @@ -6,37 +6,1325 @@ ;; dgos: ENGINE, GAME ;; DECOMP BEGINS -(defun update-texture-anim ((id bucket-id)) - ;; hack! + +;; The "texture animation" system modifies a texture according to a series of layers. + +(define *texture-anim-work* + (new 'static 'texture-anim-work + :erase-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite)) + :nreg #x3 + ) + :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) :regs1 (gif-reg-id xyz2) :regs2 (gif-reg-id xyz2)) + ) + :draw-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #xa :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #xa :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :tme #x1 :abe #x1) + :nreg #x9 + ) + :gif1 (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyz2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyz2) + :regs5 (gif-reg-id st) + :regs6 (gif-reg-id xyz2) + :regs7 (gif-reg-id st) + :regs8 (gif-reg-id xyz2) + ) + ) + :draw2-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1) + :nreg #x5 + ) + :gif1 (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyz2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyz2) + ) + ) + :fill-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite)) + :nreg #x3 + ) + :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) :regs1 (gif-reg-id xyz2) :regs2 (gif-reg-id xyz2)) + ) + :adgif-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 :nloop #x5 :eop #x1 :nreg #x1) + :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :corner0 (new 'static 'vector :x -0.5 :y -0.5 :w 1.0) + :corner1 (new 'static 'vector :x 0.5 :y -0.5 :w 1.0) + :corner2 (new 'static 'vector :x -0.5 :y 0.5 :w 1.0) + :corner3 (new 'static 'vector :x 0.5 :y 0.5 :w 1.0) + :const (new 'static 'vector :x 128.0 :z 1.9921 :w 1.0) + :random (new 'static 'inline-array vector4w 8 + (new 'static 'vector4w :x #x17181920 :y #x13141516 :z -1995435758 :w #x1234567) + (new 'static 'vector4w :x #x23878237 :y #x32048778 :z -1740074601 :w -2021050320) + (new 'static 'vector4w :x #x62024762 :y -1876389256 :z #x28724781 :w #x68712983) + (new 'static 'vector4w :x #x62176128 :y #x12387487 :z #x12780983 :w -2139999882) + (new 'static 'vector4w :x #x34987239 :y #x78699872 :z -2087161499 :w #x1982397) + (new 'static 'vector4w :x -1737344873 :y -1742502109 :z #x20987293 :w #x62102981) + (new 'static 'vector4w :x -2110229208 :y -2022559591 :z -1743517309 :w #x29874310) + (new 'static 'vector4w :x -2030034041 :y -1743611880 :z -2094950384 :w #x71623790) + ) + ) + ) + +(defun texture-anim-layer-interp ((arg0 texture-anim-layer) (arg1 float)) + "Interpolate between start and end, and store the results in layer's interpolated-vectors array." + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (set! (-> *texture-anim-work* const y) + (/ (- arg1 (-> arg0 start-time)) (- (-> arg0 end-time) (-> arg0 start-time))) + ) + (.lvf vf1 (&-> *texture-anim-work* const quad)) + (.lvf vf2 (&-> arg0 start-color quad)) + (.lvf vf3 (&-> arg0 start-vectors 1 quad)) + (.lvf vf4 (&-> arg0 start-vectors 2 quad)) + (.lvf vf5 (&-> arg0 start-qs quad)) + (.lvf vf6 (&-> arg0 start-vectors 4 quad)) + (.lvf vf7 (&-> arg0 end-color quad)) + (.lvf vf8 (&-> arg0 end-scale-offset quad)) + (.lvf vf9 (&-> arg0 end-vectors 2 quad)) + (.lvf vf10 (&-> arg0 end-qs quad)) + (.lvf vf11 (&-> arg0 end-vectors 4 quad)) + (.sub.vf vf7 vf7 vf2) + (.sub.vf vf8 vf8 vf3) + (.sub.vf vf9 vf9 vf4) + (.sub.vf vf10 vf10 vf5) + (.sub.vf vf11 vf11 vf6) + (.mul.y.vf acc vf7 vf1) + (.add.mul.w.vf vf2 vf2 vf0 acc) + (.mul.y.vf acc vf8 vf1) + (.add.mul.w.vf vf3 vf3 vf0 acc) + (.mul.y.vf acc vf9 vf1) + (.add.mul.w.vf vf4 vf4 vf0 acc) + (.mul.y.vf acc vf10 vf1) + (.add.mul.w.vf vf5 vf5 vf0 acc) + (.mul.y.vf acc vf11 vf1) + (.add.mul.w.vf vf6 vf6 vf0 acc) + (.max.x.vf vf2 vf2 vf0) + (.min.z.vf vf2 vf2 vf1) + (.svf (&-> arg0 interpolated-color quad) vf2) + (.svf (&-> arg0 interpolated-scale-offset quad) vf3) + (.svf (&-> arg0 interpolated-st-scale-offset quad) vf4) + (.svf (&-> arg0 interpolated-qs quad) vf5) + (.svf (&-> arg0 interpolated-rot quad) vf6) + (none) + ) + ) + +(defun texture-anim-layer-add-shader ((arg0 dma-buffer) (arg1 texture-anim-layer) (arg2 int)) + "Add DMA to set the GS to use the given shader. This can be used to read from the texture." + (let ((s5-0 (-> arg1 tex))) + (if s5-0 + (dma-buffer-add-gs-set arg0 + (tex0-1 (new 'static 'gs-tex0 + :cld #x1 + :psm (the-as int (-> s5-0 psm)) + :cpsm (-> s5-0 clutpsm) + :cbp (-> s5-0 clutdest) + :tcc arg2 + :th (log2 (-> s5-0 h)) + :tw (log2 (-> s5-0 w)) + :tbw (-> s5-0 width 0) + :tbp0 (-> s5-0 dest 0) + ) + ) + (tex1-1 (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) + (test-1 (-> arg1 test)) + (clamp-1 (-> arg1 clamp)) + (alpha-1 (-> arg1 alpha)) + ) + ) + ) + (none) + ) + +(defun texture-anim-layer-add-clut-shader ((arg0 dma-buffer) (arg1 texture-anim-layer) (arg2 int)) + "Add DMA to set the GS to use the clut as a ct32 texture. This is used to abuse the GS to blend cluts by pretending they are ct32's." + (let ((a1-1 (-> arg1 tex))) + (if a1-1 + (dma-buffer-add-gs-set arg0 + (tex0-1 (new 'static 'gs-tex0 :tbw #x1 :tw #x4 :th #x4 :tcc arg2 :tbp0 (-> a1-1 clutdest))) + (tex1-1 (new 'static 'gs-tex1)) + (test-1 (new 'static 'gs-test :ate #x1 :afail #x1 :zte #x1 :ztst (gs-ztest always))) + (clamp-1 (new 'static 'gs-clamp :wms (gs-tex-wrap-mode clamp) :wmt (gs-tex-wrap-mode clamp))) + (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) + ) + ) + ) + (none) + ) + +(defun texture-anim-layer-draw ((dma-buf dma-buffer) (width int) (height int) (layer texture-anim-layer)) + "Add DMA to do a rectangular draw. + Uses the interpolated quantities for sizes/rotations/positions. + Always draws a tristrip with two triangles. + " + (local-vars (v1-27 float) (sv-224 matrix) (sv-228 matrix) (sv-232 matrix) (sv-236 matrix)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (let ((s4-0 (the-as (pointer uint128) (-> dma-buf base)))) + (set! (-> s4-0 0) (-> *texture-anim-work* draw-tmpl dma-vif quad)) + (set! (-> s4-0 1) (-> *texture-anim-work* draw-tmpl quad 1)) + (set! sv-224 (new 'stack-no-clear 'matrix)) + (set! sv-228 (new 'stack-no-clear 'matrix)) + (set! sv-232 (new 'stack-no-clear 'matrix)) + (let ((v1-7 (new 'stack-no-clear 'matrix))) + (set! (-> v1-7 quad 0) (the-as uint128 0)) + (set! sv-236 v1-7) + ) + (let ((s3-0 *texture-anim-work*)) + (.lvf vf1 (&-> s3-0 const quad)) + (.lvf vf2 (&-> layer interpolated-color quad)) + (.mul.x.vf vf2 vf2 vf1) + (.ftoi.vf vf2 vf2) + (.svf (&-> s4-0 2) vf2) + (matrix-rotate-z! sv-224 (-> layer interpolated-rot x)) + (set! (-> sv-236 vector 0 x) (* (-> layer interpolated-scale-offset x) (the float width))) + (set! (-> sv-236 vector 0 y) (* (-> layer interpolated-scale-offset y) (the float height))) + (matrix-scale! sv-232 (the-as vector sv-236)) + (matrix*! sv-224 sv-232 sv-224) + (set! (-> sv-224 trans x) (+ 2048.0 (* (-> layer interpolated-scale-offset z) (the float width)))) + (set! (-> sv-224 trans y) (+ 2048.0 (* (-> layer interpolated-scale-offset w) (the float height)))) + (set! (-> sv-224 trans z) 1048575.94) + (matrix-rotate-z! sv-228 (-> layer interpolated-rot y)) + (set! (-> sv-236 vector 0 x) (-> layer interpolated-st-scale-offset x)) + (set! (-> sv-236 vector 0 y) (-> layer interpolated-st-scale-offset y)) + (matrix-scale! sv-232 (the-as vector sv-236)) + (matrix*! sv-228 sv-232 sv-228) + (set! (-> sv-228 trans x) (-> layer interpolated-st-scale-offset z)) + (set! (-> sv-228 trans y) (-> layer interpolated-st-scale-offset w)) + (.lvf vf11 (&-> sv-224 quad 0)) + (.lvf vf12 (&-> sv-224 quad 1)) + (.lvf vf14 (&-> sv-224 trans quad)) + (.lvf vf15 (&-> sv-228 quad 0)) + (.lvf vf16 (&-> sv-228 quad 1)) + (.lvf vf18 (&-> sv-228 trans quad)) + (.lvf vf7 (&-> s3-0 corner0 quad)) + (.lvf vf8 (&-> s3-0 corner1 quad)) + (.lvf vf9 (&-> s3-0 corner2 quad)) + (.lvf vf10 (&-> s3-0 corner3 quad)) + ) + (.lvf vf19 (&-> layer interpolated-qs quad)) + (.mul.x.vf acc vf11 vf7) + (.add.mul.y.vf acc vf12 vf7 acc) + (.add.mul.w.vf vf3 vf14 vf0 acc) + (.mul.x.vf acc vf11 vf8) + (.add.mul.y.vf acc vf12 vf8 acc) + (.add.mul.w.vf vf4 vf14 vf0 acc) + (.mul.x.vf acc vf11 vf9) + (.add.mul.y.vf acc vf12 vf9 acc) + (.add.mul.w.vf vf5 vf14 vf0 acc) + (.mul.x.vf acc vf11 vf10) + (.add.mul.y.vf acc vf12 vf10 acc) + (.add.mul.w.vf vf6 vf14 vf0 acc) + (.mul.x.vf acc vf15 vf7) + (.add.mul.y.vf acc vf16 vf7 acc) + (.add.mul.w.vf vf7 vf18 vf0 acc) + (vftoi4.xyzw vf3 vf3) + (.mul.x.vf acc vf15 vf8) + (.add.mul.y.vf acc vf16 vf8 acc) + (.add.mul.w.vf vf8 vf18 vf0 acc) + (vftoi4.xyzw vf4 vf4) + (.mul.x.vf acc vf15 vf9) + (.add.mul.y.vf acc vf16 vf9 acc) + (.add.mul.w.vf vf9 vf18 vf0 acc) + (vftoi4.xyzw vf5 vf5) + (.mul.x.vf acc vf15 vf10) + (.add.mul.y.vf acc vf16 vf10 acc) + (.add.mul.w.vf vf10 vf18 vf0 acc) + (vftoi4.xyzw vf6 vf6) + (.add.x.vf vf7 vf0 vf19 :mask #b100) + (.add.y.vf vf8 vf0 vf19 :mask #b100) + (.add.z.vf vf9 vf0 vf19 :mask #b100) + (.add.w.vf vf10 vf0 vf19 :mask #b100) + (.mul.z.vf vf7 vf7 vf7 :mask #b11) + (.mul.z.vf vf8 vf8 vf8 :mask #b11) + (.mul.z.vf vf9 vf9 vf9 :mask #b11) + (.mul.z.vf vf10 vf10 vf10 :mask #b11) + (.svf (&-> s4-0 3) vf7) + (.svf (&-> s4-0 4) vf3) + (.svf (&-> s4-0 5) vf8) + (.svf (&-> s4-0 6) vf4) + (.svf (&-> s4-0 7) vf9) + (.svf (&-> s4-0 8) vf5) + (.svf (&-> s4-0 9) vf10) + (.svf (&-> s4-0 10) vf6) + ) + (.mov v1-27 vf6) + (&+! (-> dma-buf base) 176) + (none) + ) + ) + +(defun default-texture-anim-layer-func ((dma-buf dma-buffer) (arg1 uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Apply texture animation layer. This interpolates the layer given the time, sets up the GS to _read_ from the given texture, then + does the draw." + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (texture-anim-layer-add-shader dma-buf layer 1) + (texture-anim-layer-draw dma-buf width height layer) + ) + ) + 0 + ) + +(defun blend-clut-texture-anim-layer-func ((dma-buf dma-buffer) (arg1 uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Apply texture animation layer to the clut. This interpolates the layer, sets up the GS to _read_ from the given texture's + clut as a 16x16 psm32, then does the draw." + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (texture-anim-layer-add-clut-shader dma-buf layer 0) + (texture-anim-layer-draw dma-buf 16 16 layer) + ) + ) + 0 + ) + +(defun move-rg-to-ba-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Some cursed texture drawing." + (-> layer tex) + (let ((tw (log2 (* width 2))) + (th (log2 height)) + (tbp (-> layer tex dest 0)) + (tbw (/ (+ (* width 2) 63) 64)) + (fbmask #x3fff) + ) + (dma-buffer-add-gs-set-flusha dma-buf + (xyoffset-1 (new 'static 'gs-xy-offset)) + (frame-1 (new 'static 'gs-frame :psm (gs-psm ct16) :fbmsk fbmask :fbw tbw :fbp fbp-to-draw)) + (scissor-1 (new 'static 'gs-scissor :scax1 (+ width -1) :scay1 (+ height -1))) + (test-1 (new 'static 'gs-test :ate #x1 :afail #x1 :zte #x1 :ztst (gs-ztest always))) + (alpha-1 (new 'static 'gs-alpha :a #x2 :b #x2 :c #x2 :fix #x80)) + (tex0-1 (new 'static 'gs-tex0 :psm #x2 :tcc #x1 :tfx #x1 :th th :tw tw :tbw tbw :tbp0 tbp)) + (fba-1 0) + (texa (new 'static 'gs-texa :ta1 #x80)) + (tex1-1 (new 'static 'gs-tex1 :lcm #x1)) + (texflush 0) + (prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1 :abe #x1 :fst #x1)) + ) + (let ((a3-4 height)) + (dotimes (t0-7 (/ width 16)) + (dma-buffer-add-gs-set dma-buf + (uv (new 'static 'gs-uv :v #x8 :u (+ (* t0-7 256) 8))) + (xyz2 (new 'static 'gs-xyz :x (+ (* t0-7 256) 128))) + (uv (new 'static 'gs-uv :u (+ (* t0-7 256) 136) :v (+ (* a3-4 16) 8))) + (xyz2 (new 'static 'gs-xyz :y (* a3-4 16) :x (+ (* t0-7 256) 256))) + ) + ) + ) + (let ((t1-40 (/ width 64))) + (dma-buffer-add-gs-set dma-buf + (frame-1 (new 'static 'gs-frame :psm (gs-psm ct16) :fbmsk fbmask :fbw tbw :fbp (+ fbp-to-draw t1-40))) + (tex0-1 (new 'static 'gs-tex0 :psm #x2 :tcc #x1 :tfx #x1 :th th :tw tw :tbw tbw :tbp0 (+ tbp (* t1-40 32)))) + (prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1 :abe #x1 :fst #x1)) + ) + ) + ) + (dotimes (v1-8 (/ width 16)) + (dma-buffer-add-gs-set dma-buf + (uv (new 'static 'gs-uv :v #x8 :u (+ (* v1-8 256) 8))) + (xyz2 (new 'static 'gs-xyz :x (+ (* v1-8 256) 128))) + (uv (new 'static 'gs-uv :u (+ (* v1-8 256) 136) :v (+ (* height 16) 8))) + (xyz2 (new 'static 'gs-xyz :y (* height 16) :x (+ (* v1-8 256) 256))) + ) + ) + + ;; manually done from the stuff below. + (dma-buffer-add-gs-set-flusha dma-buf + (xyoffset-1 (new 'static 'gs-xy-offset :ofx #x7000 :ofy #x7300)) + (frame-1 (new 'static 'gs-frame :fbw (/ (+ width 63) 64) :fbp fbp-to-draw)) + ) + #| + ;; not sure why this doesn't become a macro + (let* ((v1-11 dma-buf) + (a0-15 (the-as dma-packet (-> v1-11 base))) + ) + (set! (-> a0-15 dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> a0-15 vif0) (new 'static 'vif-tag :cmd (vif-cmd flusha) :msk #x1)) + (set! (-> a0-15 vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-11 base) (the-as pointer (&+ a0-15 16))) + ) + (let* ((v1-12 dma-buf) + (a0-17 (the-as gs-gif-tag (-> v1-12 base))) + ) + (set! (-> a0-17 tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> a0-17 regs) GIF_REGS_ALL_AD) + (set! (-> v1-12 base) (the-as pointer (&+ a0-17 16))) + ) + (let ((v1-13 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-xy-offset) v1-13) 0) (new 'static 'gs-xy-offset :ofx #x7000 :ofy #x7300)) + (set! (-> (the-as (pointer gs-reg64) v1-13) 1) (gs-reg64 xyoffset-1)) + (set! (-> (the-as (pointer gs-frame) v1-13) 2) + (new 'static 'gs-frame :fbw (/ (+ width 63) 64) :fbp fbp-to-draw) + ) + (set! (-> (the-as (pointer gs-reg64) v1-13) 3) (gs-reg64 frame-1)) + (set! (-> dma-buf base) (&+ v1-13 32)) + ) + |# + 0 + ) + +(defun fill-rgb-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Layer function to just draw RGB. This uses a full size sprite and ignores the offset/rotations." + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (let ((s5-0 (/ (+ width 63) 64))) + ;; set frame to mask alpha + (dma-buffer-add-gs-set-flusha dma-buf + (frame-1 (new 'static 'gs-frame :fbmsk #xff000000 :fbw s5-0 :fbp fbp-to-draw)) + (texflush 0) + ) + ;; make sure interp is up to date + (texture-anim-layer-interp layer time) + ;; sprite coordinates. + (let ((v1-4 (-> dma-buf base)) + (a3-1 2048) + (a2-5 2048) + (a0-8 (+ width 2048)) + (a1-15 (+ height 2048)) + ) + (set! (-> (the-as (pointer uint128) v1-4)) (-> *texture-anim-work* fill-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-4) 1) (-> *texture-anim-work* fill-tmpl quad 1)) + (.lvf vf1 (&-> *texture-anim-work* const quad)) + (.lvf vf2 (&-> layer interpolated-color quad)) + (.mul.x.vf vf2 vf2 vf1) + (.ftoi.vf vf2 vf2) + (.svf (&-> (the-as (pointer uint128) v1-4) 2) vf2) + (set-vector! (the-as vector4w (&+ v1-4 48)) (* a3-1 16) (* a2-5 16) 0 0) + (set-vector! (the-as vector4w (&+ v1-4 64)) (* a0-8 16) (* a1-15 16) 0 0) + ) + (&+! (-> dma-buf base) 80) + ;; reset frame. + (dma-buffer-add-gs-set-flusha dma-buf + (frame-1 (new 'static 'gs-frame :fbw s5-0 :fbp fbp-to-draw)) + (texflush 0) + ) + ; (let* ((v1-8 dma-buf) + ; (a0-11 (the-as dma-packet (-> v1-8 base))) + ; ) + ; (set! (-> a0-11 dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + ; (set! (-> a0-11 vif0) (new 'static 'vif-tag :cmd (vif-cmd flusha) :msk #x1)) + ; (set! (-> a0-11 vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-8 base) (the-as pointer (&+ a0-11 16))) + ; ) + ; (let* ((v1-9 dma-buf) + ; (a0-13 (the-as gs-gif-tag (-> v1-9 base))) + ; ) + ; (set! (-> a0-13 tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + ; (set! (-> a0-13 regs) GIF_REGS_ALL_AD) + ; (set! (-> v1-9 base) (the-as pointer (&+ a0-13 16))) + ; ) + ; (let ((v1-10 (-> dma-buf base))) + ; (set! (-> (the-as (pointer gs-frame) v1-10) 0) (new 'static 'gs-frame :fbw s5-0 :fbp fbp-to-draw)) + ; (set! (-> (the-as (pointer gs-reg64) v1-10) 1) (gs-reg64 frame-1)) + ; (set! (-> (the-as (pointer uint64) v1-10) 2) (the-as uint 0)) + ; (set! (-> (the-as (pointer gs-reg64) v1-10) 3) (gs-reg64 texflush)) + ; (set! (-> dma-buf base) (&+ v1-10 32)) + ; ) + ) + 0 + ) + ) + +(defun update-texture-anim ((bucket bucket-id) (anim-array texture-anim-array)) + "Generate all DMA to update all textures in the given list for the given bucket." + + ;; + ;; (return #f) + ;; + (local-vars (tex-height int) (fbp-for-tex uint) (layer-idx int)) + (with-pp + (if (-> *blit-displays-work* menu-mode) + (return #f) + ) + + + + (with-dma-buffer-add-bucket ((dma-buf (-> *display* frames (-> *display* on-screen) global-buf)) + bucket + ) + ;; added: flag for the PC port to indicate start of texture anim data: + (dma-buffer-add-cnt-vif2 + dma-buf + 0 + (new 'static 'vif-tag :cmd (vif-cmd pc-port) :imm 12) + (new 'static 'vif-tag :cmd (vif-cmd pc-port)) + ) + ;; loop over animated textures. Each will produce a single texture. + (dotimes (anim-idx (-> anim-array length)) + (let* ((anim (-> anim-array array-data anim-idx)) + (dest-tex (-> anim tex)) + ) + (when dest-tex + 0 + (let ((tex-width (-> dest-tex w))) + (set! tex-height (-> dest-tex h)) + (cond + ((or (= (-> dest-tex psm) (gs-psm ct32)) (= (-> dest-tex psm) (gs-psm mt8h))) + ;; animating the actual texture data. + (set! fbp-for-tex (shr (-> dest-tex dest 0) 5)) + fbp-for-tex + ) + (else + ;; animating the clut. + (set! fbp-for-tex (shr (-> dest-tex clutdest) 5)) + (set! tex-width 16) + (set! tex-height 16) + tex-height + ) + ) + (when (and (nonzero? tex-width) (nonzero? tex-height)) + ;; configure for drawing to this texture. + (dma-buffer-add-gs-set-flusha dma-buf + (scissor-1 (new 'static 'gs-scissor :scax1 (+ tex-width -1) :scay1 (+ tex-height -1))) + (xyoffset-1 (new 'static 'gs-xy-offset :ofx #x8000 :ofy #x8000)) + ;; setting fbp here is what makes it draw to the texture, not frambeuffer. + (frame-1 (new 'static 'gs-frame :fbw (/ (+ tex-width 63) 64) :fbp fbp-for-tex)) + (test-1 (-> anim test)) + (alpha-1 (-> anim alpha)) + (clamp-1 (-> anim clamp)) + (texa (new 'static 'gs-texa :ta0 #x80 :ta1 #x80)) + (zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24) :zmsk #x1)) + (texflush 0) + ) + ;; erase whatever was here previously + (let ((a1-32 (-> dma-buf base)) + (a3-0 2048) + (a2-7 2048) + (v1-25 (+ tex-width 2048)) + (a0-16 (+ tex-height 2048)) + ) + (set! (-> (the-as (pointer uint128) a1-32)) (-> *texture-anim-work* erase-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) a1-32) 1) (-> *texture-anim-work* erase-tmpl quad 1)) + (set-vector! + (the-as vector4w (&+ a1-32 32)) + (the-as int (-> anim color r)) + (the-as int (-> anim color g)) + (the-as int (-> anim color b)) + (the-as int (-> anim color a)) + ) + (set-vector! (the-as vector4w (&+ a1-32 48)) (* a3-0 16) (* a2-7 16) #xffffff 0) + (set-vector! (the-as vector4w (&+ a1-32 64)) (* v1-25 16) (* a0-16 16) #xffffff 0) + ) + (&+! (-> dma-buf base) 80) + ) + + ;; this animated texture may overlap with other textures from other pages. + ;; we're writing over this from outside of the usual texture page upload system. + ;; so we should manually clear the id arrays for our pages, to make sure the texture + ;; system re-uploads textures if needed. + (let ((v1-32 (/ (the-as int fbp-for-tex) 2)) + (a0-19 (* (/ (+ tex-width 63) 64) (/ (+ tex-height 63) 64))) + ) + (if (and (logtest? fbp-for-tex 1) (< 32 tex-width)) + (+! a0-19 1) + ) + (dotimes (a1-43 a0-19) + (set! (-> *texture-pool* ids (+ v1-32 a1-43)) (the-as uint 0)) + ) + ) + + ;; loop over layers + (set! layer-idx 0) + (while (< layer-idx (the-as int (-> anim num-layers))) + (let ((layer (-> anim data layer-idx))) + ;; generate DMA for this layer's effect + ((-> layer func) dma-buf fbp-for-tex tex-width tex-height layer (-> anim frame-time)) + ) + (set! layer-idx (+ layer-idx 1)) + ) + ) + ;; some sort of final function (TODO args here) + (if (-> anim func) + ((-> anim func) dma-buf anim) + ) + + ;; advance animation. + (when (not (paused?)) + (let ((f0-2 (+ (-> anim frame-time) (* (-> anim frame-delta) (-> pp clock seconds-per-frame)))) + (f1-2 (-> anim frame-mod)) + ) + (set! (-> anim frame-time) (- f0-2 (* (the float (the int (/ f0-2 f1-2))) f1-2))) + ) + (if (< (-> anim frame-time) 0.0) + (+! (-> anim frame-time) (-> anim frame-mod)) + ) + ) + ) + ) + ) + + ;; reset GS registers - we messed with frame/scissor. + (reset-display-gs-state *display* dma-buf) + + ;; added: flag for the PC port to indicate end of texture anim data: + (dma-buffer-add-cnt-vif2 + dma-buf + 0 + (new 'static 'vif-tag :cmd (vif-cmd pc-port) :imm 13) + (new 'static 'vif-tag :cmd (vif-cmd pc-port)) + ) + ) + 0 + (none) + ) + ) + +(defun no-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Like others, but the tcc value is 0" + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (texture-anim-layer-add-shader dma-buf layer 0) + (texture-anim-layer-draw dma-buf width height layer) + ) + ) + 0 + ) + +(defun copy-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Copy only alpha from the layer source texture. Does a draw, possibly blending if that's how the layer is configured. + Draw is always axis aligned, full size." + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + + ;; compute layer values for this frame + (texture-anim-layer-interp layer time) + + (let ((s4-0 (/ (+ width 63) 64))) + ;; set up fbmask for alpha only + (dma-buffer-add-gs-set dma-buf (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw s4-0 :fbp fbp-to-draw))) + ;; set up shader to sample from the layer's texture + (texture-anim-layer-add-shader dma-buf layer 1) + + (let ((v1-7 (-> dma-buf base)) + (a2-6 #x8000) + (a3-1 #x8000) + (a0-10 (* (+ width 2048) 16)) + (a1-14 (* (+ height 2048) 16)) + ) + ;; generate drawing. + (set! (-> (the-as (pointer uint128) v1-7)) (-> *texture-anim-work* draw-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-7) 1) (-> *texture-anim-work* draw-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-7 32)) 128 128 128 (the int (* 128.0 (-> layer interpolated-color w)))) + (set-vector! (the-as vector (&+ v1-7 48)) 0.0 0.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ v1-7 64)) a2-6 a3-1 #xffffff 0) + (set-vector! (the-as vector (&+ v1-7 80)) 1.0 0.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ v1-7 96)) a0-10 a3-1 #xffffff 0) + (set-vector! (the-as vector (&+ v1-7 112)) 0.0 1.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ v1-7 128)) a2-6 a1-14 #xffffff 0) + (set-vector! (the-as vector (&+ v1-7 144)) 1.0 1.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ v1-7 160)) a0-10 a1-14 #xffffff 0) + ) + (&+! (-> dma-buf base) 176) + + ;; reset frame. + (dma-buffer-add-gs-set dma-buf + (frame-1 (new 'static 'gs-frame :fbw s4-0 :fbp fbp-to-draw)) + ) + ; (let* ((v1-11 dma-buf) + ; (a0-12 (the-as dma-packet (-> v1-11 base))) + ; ) + ; (set! (-> a0-12 dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + ; (set! (-> a0-12 vif0) (new 'static 'vif-tag)) + ; (set! (-> a0-12 vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-11 base) (the-as pointer (&+ a0-12 16))) + ; ) + ; (let* ((v1-12 dma-buf) + ; (a0-14 (the-as object (-> v1-12 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a0-14) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + ; (set! (-> (the-as gs-gif-tag a0-14) regs) GIF_REGS_ALL_AD) + ; (set! (-> v1-12 base) (&+ (the-as pointer a0-14) 16)) + ; ) + ; (let ((v1-13 (-> dma-buf base))) + ; (set! (-> (the-as (pointer gs-frame) v1-13) 0) (new 'static 'gs-frame :fbw s4-0 :fbp fbp-to-draw)) + ; (set! (-> (the-as (pointer gs-reg64) v1-13) 1) (gs-reg64 frame-1)) + ; (set! (-> dma-buf base) (&+ v1-13 16)) + ; ) + ) + ) + 0 + ) + +(defun copy-clut-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Copy only alpha from the layer source clut." + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (let ((s4-0 1)) + (dma-buffer-add-gs-set dma-buf (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw s4-0 :fbp fbp-to-draw))) + (texture-anim-layer-add-clut-shader dma-buf layer 1) + (let ((a1-13 (-> dma-buf base)) + (a2-6 #x8000) + (a3-1 #x8000) + (v1-6 #x8100) + (a0-9 #x8100) + ) + (set! (-> (the-as (pointer uint128) a1-13)) (-> *texture-anim-work* draw-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) a1-13) 1) (-> *texture-anim-work* draw-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ a1-13 32)) 128 128 128 (the int (* 128.0 (-> layer interpolated-color w)))) + (set-vector! (the-as vector (&+ a1-13 48)) 0.0 0.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ a1-13 64)) a2-6 a3-1 #xffffff 0) + (set-vector! (the-as vector (&+ a1-13 80)) 1.0 0.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ a1-13 96)) v1-6 a3-1 #xffffff 0) + (set-vector! (the-as vector (&+ a1-13 112)) 0.0 1.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ a1-13 128)) a2-6 a0-9 #xffffff 0) + (set-vector! (the-as vector (&+ a1-13 144)) 1.0 1.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ a1-13 160)) v1-6 a0-9 #xffffff 0) + ) + (&+! (-> dma-buf base) 176) + (dma-buffer-add-gs-set dma-buf + (frame-1 (new 'static 'gs-frame :fbw s4-0 :fbp fbp-to-draw)) + ) + ; (let* ((v1-10 dma-buf) + ; (a0-10 (the-as dma-packet (-> v1-10 base))) + ; ) + ; (set! (-> a0-10 dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + ; (set! (-> a0-10 vif0) (new 'static 'vif-tag)) + ; (set! (-> a0-10 vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-10 base) (the-as pointer (the-as dma-packet (&+ a0-10 16)))) + ; ) + ; (let* ((v1-11 dma-buf) + ; (a0-12 (the-as object (-> v1-11 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a0-12) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + ; (set! (-> (the-as gs-gif-tag a0-12) regs) GIF_REGS_ALL_AD) + ; (set! (-> v1-11 base) (&+ (the-as pointer a0-12) 16)) + ; ) + ; (let ((v1-12 (-> dma-buf base))) + ; (set! (-> (the-as (pointer gs-frame) v1-12) 0) (new 'static 'gs-frame :fbw s4-0 :fbp fbp-to-draw)) + ; (set! (-> (the-as (pointer gs-reg64) v1-12) 1) (gs-reg64 frame-1)) + ; (set! (-> dma-buf base) (&+ v1-12 16)) + ; ) + ) + ) + 0 + ) + +(defun set-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Set alpha to 128 for the texture." + (let ((v1-1 (/ (+ width 63) 64))) + ;; make sure alpha test is off, and set frame to allow only alpha writes + (dma-buffer-add-gs-set dma-buf + (test-1 (new 'static 'gs-test :ate #x1 :afail #x1 :zte #x1 :ztst (gs-ztest always))) + (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw v1-1 :fbp fbp-to-draw)) + ) + ;; draw the sprite. + (let ((t0-4 (-> dma-buf base)) + (t2-12 2048) + (t1-7 2048) + (a2-1 (+ width 2048)) + (a3-1 (+ height 2048)) + ) + (set! (-> (the-as (pointer uint128) t0-4)) (-> *texture-anim-work* erase-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) t0-4) 1) (-> *texture-anim-work* erase-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ t0-4 32)) 0 0 0 128) ;; rgba + (set-vector! (the-as vector4w (&+ t0-4 48)) (* t2-12 16) (* t1-7 16) #xffffff 0) + (set-vector! (the-as vector4w (&+ t0-4 64)) (* a2-1 16) (* a3-1 16) #xffffff 0) + ) + (&+! (-> dma-buf base) 80) + (dma-buffer-add-gs-set dma-buf + (frame-1 (new 'static 'gs-frame :fbw v1-1 :fbp fbp-to-draw)) + ) + 0 + ; (let* ((a2-7 dma-buf) + ; (a3-2 (the-as object (-> a2-7 base))) + ; ) + ; (set! (-> (the-as dma-packet a3-2) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a3-2) vif0) (new 'static 'vif-tag)) + ; (set! (-> (the-as dma-packet a3-2) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> a2-7 base) (&+ (the-as pointer a3-2) 16)) + ; ) + ; (let* ((a2-8 dma-buf) + ; (a3-4 (the-as object (-> a2-8 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a3-4) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + ; (set! (-> (the-as gs-gif-tag a3-4) regs) GIF_REGS_ALL_AD) + ; (set! (-> a2-8 base) (&+ (the-as pointer a3-4) 16)) + ; ) + ; (let ((a2-9 (-> dma-buf base))) + ; (set! (-> (the-as (pointer gs-frame) a2-9) 0) (new 'static 'gs-frame :fbw v1-1 :fbp fbp-to-draw)) + ; (set! (-> (the-as (pointer gs-reg64) a2-9) 1) (gs-reg64 frame-1)) + ; (let ((v0-0 (&+ a2-9 16))) + ; (set! (-> dma-buf base) v0-0) + ; (the-as int v0-0) + ; ) + ; ) + ) + ) + +(defun set-clut-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + "Set clut alpha to 128." + (let ((v1-0 1)) + (dma-buffer-add-gs-set dma-buf + (test-1 (new 'static 'gs-test :ate #x1 :afail #x1 :zte #x1 :ztst (gs-ztest always))) + (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw v1-0 :fbp fbp-to-draw)) + ) + (let ((t0-13 (-> dma-buf base)) + (t2-0 2048) + (t1-5 2048) + (a3-7 2064) + (a2-4 2064) + ) + (set! (-> (the-as (pointer uint128) t0-13)) (-> *texture-anim-work* erase-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) t0-13) 1) (-> *texture-anim-work* erase-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ t0-13 32)) 0 0 0 128) + (set-vector! (the-as vector4w (&+ t0-13 48)) (* t2-0 16) (* t1-5 16) #xffffff 0) + (set-vector! (the-as vector4w (&+ t0-13 64)) (* a3-7 16) (* a2-4 16) #xffffff 0) + ) + (&+! (-> dma-buf base) 80) + (dma-buffer-add-gs-set dma-buf + (frame-1 (new 'static 'gs-frame :fbw v1-0 :fbp fbp-to-draw)) + ) + 0 + ; (let* ((a2-9 dma-buf) + ; (a3-9 (the-as object (-> a2-9 base))) + ; ) + ; (set! (-> (the-as dma-packet a3-9) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a3-9) vif0) (new 'static 'vif-tag)) + ; (set! (-> (the-as dma-packet a3-9) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> a2-9 base) (&+ (the-as pointer a3-9) 16)) + ; ) + ; (let* ((a2-10 dma-buf) + ; (a3-11 (the-as object (-> a2-10 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a3-11) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + ; (set! (-> (the-as gs-gif-tag a3-11) regs) GIF_REGS_ALL_AD) + ; (set! (-> a2-10 base) (&+ (the-as pointer a3-11) 16)) + ; ) + ; (let ((a2-11 (-> dma-buf base))) + ; (set! (-> (the-as (pointer gs-frame) a2-11) 0) (new 'static 'gs-frame :fbw v1-0 :fbp fbp-to-draw)) + ; (set! (-> (the-as (pointer gs-reg64) a2-11) 1) (gs-reg64 frame-1)) + ; (let ((v0-0 (&+ a2-11 16))) + ; (set! (-> dma-buf base) v0-0) + ; (the-as int v0-0) + ; ) + ; ) + ) + ) + +(defun dest-texture-init ((tex-anim texture-anim)) + "Set up the texture object to hold the destination (result) texture." + (let ((dest-tex (new 'loading-level 'texture))) + (let ((size (the int (-> tex-anim extra x)))) + (let ((dest (the int (-> tex-anim extra y)))) ;; dest vram addr is stashed here. + (set! (-> tex-anim tex) dest-tex) + (set! (-> dest-tex w) size) + (set! (-> dest-tex h) size) + (set! (-> dest-tex num-mips) (the-as uint 1)) + (set! (-> dest-tex psm) (gs-psm ct32)) + (set! (-> dest-tex dest 0) (the-as uint (* dest 32))) + ) + (set! (-> dest-tex width 0) (the-as uint (/ (+ size 63) 64))) + ) + (set! (-> dest-tex masks data 0 mask quad) (the-as uint128 0)) + (set! (-> dest-tex masks data 1 mask quad) (the-as uint128 0)) + (set! (-> dest-tex masks data 2 mask quad) (the-as uint128 0)) + ) + 0 + 0 + (none) + ) + +(defun src-texture-init ((layer texture-anim-layer)) + "Allocate a texture object to hold a source texture. This is only used for source textures that are generated at runtime, + like random noise. Layers may include a reference to an existing texture instead. Always psm32." + (let ((tex (new 'loading-level 'texture))) + (let ((size (the int (-> layer extra x)))) + (let ((addr (the int (-> layer extra y)))) + (set! (-> layer tex) tex) + (set! (-> tex w) size) + (set! (-> tex h) size) + (set! (-> tex num-mips) (the-as uint 1)) + (set! (-> tex psm) (gs-psm ct32)) + (set! (-> tex dest 0) (the-as uint (* addr 32))) + ) + (set! (-> tex width 0) (the-as uint (/ (+ size 63) 64))) + ) + (set! (-> tex masks data 0 mask quad) (the-as uint128 0)) + (set! (-> tex masks data 1 mask quad) (the-as uint128 0)) + (set! (-> tex masks data 2 mask quad) (the-as uint128 0)) + ) + 0 + 0 (none) ) +(defun src-texture-init-mt8 ((layer texture-anim-layer)) + "Like src-texture-init, but sets up a mt8 (pallete) texture." + (let ((tex (new 'loading-level 'texture))) + (let ((width (the int (-> layer extra x)))) + (let ((height (the int (-> layer extra y))) + (dest (the int (-> layer extra z))) + (clutdest (the int (-> layer extra w))) + ) + (set! (-> layer tex) tex) + (set! (-> tex w) width) + (set! (-> tex h) height) + (set! (-> tex num-mips) (the-as uint 1)) + (set! (-> tex psm) (gs-psm mt8)) + (set! (-> tex dest 0) (the-as uint (* dest 32))) + (set! (-> tex clutpsm) (the-as uint 0)) + (set! (-> tex clutdest) (the-as uint (* clutdest 32))) + ) + (set! (-> tex width 0) (the-as uint (/ (+ width 63) 64))) + ) + (set! (-> tex masks data 0 mask quad) (the-as uint128 0)) + (set! (-> tex masks data 1 mask quad) (the-as uint128 0)) + (set! (-> tex masks data 2 mask quad) (the-as uint128 0)) + ) + 0 + 0 + (none) + ) -;; definition for method 9 of type texture-anim-array -(defmethod texture-anim-array-method-9 texture-anim-array ((obj texture-anim-array)) +(defun make-noise-texture ((arg0 pointer) (arg1 int) (arg2 int) (arg3 int)) + "Generate 'random' noise texture." + (local-vars (t4-5 uint128) (t5-3 uint128)) + (let ((v1-0 (/ arg1 16)) + (a3-1 (/ arg3 16)) + ) + (when (< arg1 16) + (set! a3-1 1) + (set! v1-0 1) + (set! arg2 (/ (* arg2 arg1) 16)) + ) + (let* ((a1-5 *texture-anim-work*) + (v0-0 (-> a1-5 random-index)) + ) + (dotimes (t0-1 arg2) + (let ((t1-0 0)) + (goto cfg-6) + (until (>= t1-0 v1-0) + (let* ((t2-0 (* t0-1 a3-1)) + (t3-0 (+ v0-0 3)) + (t4-0 (+ v0-0 5)) + (t5-0 (+ v0-0 7)) + (t3-1 (logand t3-0 7)) + (t4-1 (logand t4-0 7)) + (t7-0 (logand t5-0 7)) + (t6-0 (* v0-0 16)) + (t5-1 (* t3-1 16)) + (t4-2 (* t4-1 16)) + (t3-2 (* t7-0 16)) + (t2-1 (+ t2-0 t1-0)) + (t6-1 (the-as object (+ t6-0 (the-as uint a1-5)))) + (t2-2 (* t2-1 16)) + (t7-1 (the-as object (+ t5-1 (the-as uint a1-5)))) + (t5-2 (-> (the-as (pointer uint128) t6-1) 15)) + (t4-3 (the-as object (+ t4-2 (the-as uint a1-5)))) + (t6-2 (-> (the-as (pointer uint128) t7-1) 15)) + (t3-3 (the-as object (+ t3-2 (the-as uint a1-5)))) + ) + (let ((t4-4 (-> (the-as (pointer uint128) t4-3) 15))) + (.paddb t5-3 t5-2 t6-2) + (nop!) + (.paddb t4-5 t5-3 t4-4) + ) + (nop!) + (let ((t2-3 (+ t2-2 (the-as int arg0)))) + (set! (-> (the-as (pointer uint128) t3-3) 15) t4-5) + (let ((t3-4 (+ v0-0 1))) + (set! (-> (the-as (pointer uint128) t2-3) 0) t4-5) + (set! v0-0 (logand t3-4 7)) + ) + ) + ) + (nop!) + (+! t1-0 1) + (label cfg-6) + ) + ) + ) + (set! (-> a1-5 random-index) v0-0) + ) + ) + (none) + ) + +(defun make-cloud-clut ((arg0 (pointer uint32)) (arg1 float) (arg2 float)) + "Generate clut for the cloud texture." + (local-vars (v1-10 int)) + 0 + (let* ((s5-0 (the int (* 255.0 arg1))) + (s4-1 (max (the int (* 255.0 arg2)) s5-0)) + (f30-0 (/ 128.0 (the float (- s4-1 s5-0)))) + ) + (dotimes (s3-0 256) + (let ((s2-0 (-> *clut-translate* s3-0))) + (cond + ((and (>= s5-0 s3-0) (nonzero? s4-1)) + (set! v1-10 0) + ) + ((>= s3-0 s4-1) + (set! v1-10 128) + ) + (else + (let* ((f0-9 (sin (* 128.0 (fmin 128.0 (* (the float (- s3-0 s5-0)) f30-0))))) + (f0-11 (* f0-9 f0-9)) + ) + (set! v1-10 (the int (* 128.0 f0-11))) + ) + ) + ) + (set! (-> arg0 s2-0) (logior (logand (-> arg0 s2-0) -256) 128)) + (set! (-> arg0 s2-0) (logior (logand (-> arg0 s2-0) -65281) #x8000)) + (set! (-> arg0 s2-0) (logior (logand (-> arg0 s2-0) -16711681) #x800000)) + (set! (-> arg0 s2-0) + (logior (logand (-> arg0 s2-0) (the-as uint #xffffffff00ffffff)) (shr (shl v1-10 56) 32)) + ) + ) + ) + ) + (none) + ) + +(defun texture-anim-cloud-clut-upload ((arg0 dma-buffer) (arg1 texture-anim)) + "Upload the clut for the clouds." + (when (-> arg1 tex) + (make-cloud-clut (the-as (pointer uint32) (-> arg1 tex pad 0)) (-> arg1 extra y) (-> arg1 extra z)) + (upload-vram-data arg0 (the-as int (-> arg1 tex clutdest)) (the-as pointer (-> arg1 tex pad 0)) 16 16) + (set! (-> *texture-pool* ids (shr (-> arg1 tex clutdest) 6)) (the-as uint 0)) + 0 + ) + (none) + ) + +(defun texture-anim-cloud-clut-init ((arg0 texture-anim)) + (let ((s5-0 (new 'loading-level 'texture)) + (s4-0 (the int (-> arg0 extra x))) + (v1-2 (new 'loading-level 'clut16x16)) + ) + (set! (-> arg0 tex) s5-0) + (set! (-> s5-0 clutdest) (the-as uint (* s4-0 32))) + (set! (-> s5-0 pad 0) (the-as uint v1-2)) + ) + 0 + (none) + ) + +;; definition for function make-slime-clut +;; WARN: Return type mismatch symbol vs none. +(define-extern *slime-clut* clut16x16) +(defun make-slime-clut ((arg0 (pointer uint32))) + (dotimes (v1-0 256) + (let ((a1-2 (-> *clut-translate* v1-0)) + (a2-2 (-> *slime-clut* clut v1-0)) + ) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -256) (shr (shl (-> a2-2 r) 56) 56))) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -65281) (shr (shl (-> a2-2 g) 56) 48))) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -16711681) (shr (shl (-> a2-2 b) 56) 40))) + (set! (-> arg0 a1-2) + (logior (logand (-> arg0 a1-2) (the-as uint #xffffffff00ffffff)) (shr (shl (-> a2-2 a) 56) 32)) + ) + ) + ) + (none) + ) + +;; definition for function texture-anim-slime-clut-upload +;; WARN: Return type mismatch int vs none. +(defun texture-anim-slime-clut-upload ((arg0 dma-buffer) (arg1 texture-anim)) + (when (-> arg1 tex) + (make-slime-clut (the-as (pointer uint32) (-> arg1 tex pad 0))) + (upload-vram-data arg0 (the-as int (-> arg1 tex clutdest)) (the-as pointer (-> arg1 tex pad 0)) 16 16) + (set! (-> *texture-pool* ids (shr (-> arg1 tex clutdest) 6)) (the-as uint 0)) + 0 + ) + (none) + ) + +;; definition for function texture-anim-slime-clut-init +;; WARN: Return type mismatch int vs none. +(defun texture-anim-slime-clut-init ((arg0 texture-anim)) + (let ((s5-0 (new 'loading-level 'texture)) + (s4-0 (the int (-> arg0 extra x))) + (v1-2 (new 'loading-level 'clut16x16)) + ) + (set! (-> arg0 tex) s5-0) + (set! (-> s5-0 clutdest) (the-as uint (* s4-0 32))) + (set! (-> s5-0 pad 0) (the-as uint v1-2)) + ) + 0 + (none) + ) + +;; definition for function make-ramp-clut +;; WARN: Return type mismatch symbol vs none. +(defun make-ramp-clut ((arg0 (pointer uint32)) (arg1 pointer) (arg2 object)) + (dotimes (v1-0 256) + (let ((a1-3 (-> *clut-translate* v1-0))) + (set! (-> arg0 a1-3) (logior (logand (-> arg0 a1-3) -256) (shr (shl v1-0 56) 56))) + (set! (-> arg0 a1-3) (logior (logand (-> arg0 a1-3) -65281) (shr (shl v1-0 56) 48))) + (set! (-> arg0 a1-3) (logior (logand (-> arg0 a1-3) -16711681) (shr (shl v1-0 56) 40))) + (set! (-> arg0 a1-3) (logior (logand (-> arg0 a1-3) (the-as uint #xffffffff00ffffff)) (shr (shl v1-0 56) 32))) + ) + ) + (none) + ) + +(defun make-alpha-ramp-clut ((arg0 (pointer uint32))) + (dotimes (v1-0 256) + (let ((a1-2 (-> *clut-translate* v1-0))) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -256) 128)) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -65281) #x8000)) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -16711681) #x800000)) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) (the-as uint #xffffffff00ffffff)) (shr (shl v1-0 56) 32))) + ) + ) + (none) + ) + +(defun noise-texture-init ((arg0 texture-anim-layer)) + (let ((gp-0 (the int (-> arg0 extra x))) + (s4-0 (the-as structure #f)) + ) + (case gp-0 + ((8) + (set! s4-0 (new 'loading-level 'noise8x8)) + ) + ((16) + (set! s4-0 (new 'loading-level 'noise16x16)) + ) + ((32) + (set! s4-0 (new 'loading-level 'noise32x32)) + ) + ((64) + (set! s4-0 (new 'loading-level 'noise64x64)) + ) + ((128) + (set! s4-0 (new 'loading-level 'noise128x128)) + ) + ) + (when s4-0 + (let ((v1-14 (new 'loading-level 'texture))) + (let ((a0-16 (the int (-> arg0 extra y))) + (a1-6 (the int (-> arg0 extra z))) + ) + (set! (-> arg0 tex) v1-14) + (set! (-> v1-14 pad 0) (the-as uint s4-0)) + (set! (-> v1-14 w) gp-0) + (set! (-> v1-14 h) gp-0) + (set! (-> v1-14 num-mips) (the-as uint 1)) + (set! (-> v1-14 psm) (gs-psm mt8)) + (set! (-> v1-14 clutpsm) (the-as uint 0)) + (set! (-> v1-14 dest 0) (the-as uint (* a0-16 32))) + (set! (-> v1-14 clutdest) (the-as uint (* a1-6 32))) + ) + (set! (-> v1-14 width 0) (the-as uint 1)) + (set! (-> v1-14 masks data 0 mask quad) (the-as uint128 0)) + (set! (-> v1-14 masks data 1 mask quad) (the-as uint128 0)) + (set! (-> v1-14 masks data 2 mask quad) (the-as uint128 0)) + (make-noise-texture (the-as pointer (-> v1-14 pad 0)) gp-0 gp-0 gp-0) + ) + ) + ) + 0 + (none) + ) + +(defun texture-anim-alpha-ramp-clut-upload ((arg0 dma-buffer) (arg1 texture-anim)) + (when (-> arg1 tex) + (upload-vram-data arg0 (the-as int (-> arg1 tex clutdest)) (the-as pointer (-> arg1 tex pad 0)) 16 16) + (set! (-> *texture-pool* ids (shr (-> arg1 tex clutdest) 6)) (the-as uint 0)) + 0 + ) + (none) + ) + +(defun texture-anim-alpha-ramp-clut-init ((arg0 texture-anim)) + (let ((s5-0 (new 'loading-level 'texture)) + (s4-0 (the int (-> arg0 extra x))) + (a0-3 (new 'loading-level 'clut16x16)) + ) + (set! (-> arg0 tex) s5-0) + (set! (-> s5-0 clutdest) (the-as uint (* s4-0 32))) + (set! (-> s5-0 pad 0) (the-as uint a0-3)) + (make-alpha-ramp-clut (the-as (pointer uint32) a0-3)) + ) + 0 + (none) + ) + +(defun texture-anim-overide-size-init ((arg0 texture-anim)) + (when (-> arg0 tex-name) + (let ((v1-2 (lookup-level-texture-by-name + (-> arg0 tex-name) + (-> *level* loading-level) + (the-as (pointer texture-page) #f) + ) + ) + ) + (when v1-2 + (let ((a0-2 (the int (-> arg0 extra x)))) + (let ((a1-1 (the int (-> arg0 extra y)))) + (set! (-> v1-2 w) a0-2) + (set! (-> v1-2 h) a1-1) + ) + (set! (-> v1-2 dest 0) (the-as uint 1)) + (set! (-> v1-2 width 0) (the-as uint (/ a0-2 64))) + ) + (set! (-> v1-2 masks data 0 mask quad) (the-as uint128 0)) + (set! (-> v1-2 masks data 1 mask quad) (the-as uint128 0)) + (set! (-> v1-2 masks data 2 mask quad) (the-as uint128 0)) + 0 + ) + ) + ) + (none) + ) + +(defun texture-anim-change-mt8h-init ((arg0 texture-anim)) + (when (-> arg0 tex-name) + (let ((v1-2 (lookup-level-texture-by-name + (-> arg0 tex-name) + (-> *level* loading-level) + (the-as (pointer texture-page) #f) + ) + ) + ) + (when v1-2 + (let ((a0-2 (the int (-> arg0 extra x))) + (a1-1 (the int (-> arg0 extra y))) + (a2-1 (the int (-> arg0 extra z))) + ) + (let ((a3-0 (the int (-> arg0 extra w)))) + (set! (-> v1-2 clutdest) (the-as uint (* a0-2 32))) + (set! (-> v1-2 clutpsm) (the-as uint 0)) + (set! (-> v1-2 dest 0) (the-as uint (* a1-1 32))) + (set! (-> v1-2 psm) (gs-psm mt8h)) + (set! (-> v1-2 w) a2-1) + (set! (-> v1-2 h) a3-0) + ) + (set! (-> v1-2 width 0) (the-as uint (/ a2-1 64))) + ) + (set! (-> v1-2 masks data 0 mask quad) (the-as uint128 0)) + (set! (-> v1-2 masks data 1 mask quad) (the-as uint128 0)) + (set! (-> v1-2 masks data 2 mask quad) (the-as uint128 0)) + 0 + ) + ) + ) + (none) + ) + +(defmethod init! texture-anim-array ((obj texture-anim-array)) (dotimes (s5-0 (-> obj length)) - (texture-anim-method-9 (-> obj array-data s5-0)) + (init-textures! (-> obj array-data s5-0)) ) obj ) ;; definition for method 10 of type texture-anim-array -(defmethod texture-anim-array-method-10 texture-anim-array ((obj texture-anim-array)) +(defmethod clear! texture-anim-array ((obj texture-anim-array)) (dotimes (s5-0 (-> obj length)) - (texture-anim-method-10 (-> obj array-data s5-0)) + (clear-textures! (-> obj array-data s5-0)) ) obj ) +(defmacro assert-symbol-is-function (sym) + `(begin + (let ((sym-val (-> (the symbol ,sym) value))) + (when (zero? sym-val) + (format 0 "symbol ~A is 0~%" ,sym) + (break!) + ) + (when (and sym-val (!= function (rtype-of sym-val))) + (format 0 "symbol ~A is not a function~%" ,sym) + (break!) + ) + ) + ) + ) + ;; definition for method 9 of type texture-anim ;; INFO: Used lq/sq -(defmethod texture-anim-method-9 texture-anim ((obj texture-anim)) +(defmethod init-textures! texture-anim ((obj texture-anim)) (local-vars (a3-3 uint128) (sv-16 texture-page)) - (if (logtest? (the-as int (-> obj func)) 1) - (set! (-> obj func) (the-as (function texture-anim int) (-> (the-as symbol (-> obj func)) value))) + (when (logtest? (the-as int (-> obj func)) 1) + (assert-symbol-is-function (-> obj func)) ;; added + (set! (-> obj func) (the-as (function dma-buffer texture-anim int) (-> (the-as symbol (-> obj func)) value))) ) (when (logtest? (the-as int (-> obj init-func)) 1) + (assert-symbol-is-function (-> obj init-func)) ;; added (set! (-> obj init-func) (the-as (function texture-anim int) (-> (the-as symbol (-> obj init-func)) value))) (if (-> obj init-func) ((-> obj init-func) obj) @@ -82,7 +1370,7 @@ ) ) (dotimes (s5-0 (the-as int (-> obj num-layers))) - (texture-anim-layer-method-9 (-> obj data s5-0)) + (initialize-texture! (-> obj data s5-0)) ) (let ((v1-34 (-> obj tex))) (when v1-34 @@ -109,20 +1397,26 @@ ) ;; definition for method 10 of type texture-anim -(defmethod texture-anim-method-10 texture-anim ((obj texture-anim)) +(defmethod clear-textures! texture-anim ((obj texture-anim)) (set! (-> obj tex) #f) (dotimes (s5-0 (the-as int (-> obj num-layers))) - (texture-anim-layer-method-10 (-> obj data s5-0)) + (clear-texture! (-> obj data s5-0)) ) obj ) ;; definition for method 9 of type texture-anim-layer -(defmethod texture-anim-layer-method-9 texture-anim-layer ((obj texture-anim-layer)) - (if (logtest? (the-as int (-> obj func)) 1) - (set! (-> obj func) (the-as (function texture-anim-layer int) (-> (the-as symbol (-> obj func)) value))) +(defmethod initialize-texture! texture-anim-layer ((obj texture-anim-layer)) + (when (logtest? (the-as int (-> obj func)) 1) + (assert-symbol-is-function (-> obj func)) ;; added + (set! (-> obj func) (the-as + (function dma-buffer uint int int texture-anim-layer float int) + (-> (the-as symbol (-> obj func)) value) + ) + ) ) (when (logtest? (the-as int (-> obj init-func)) 1) + (assert-symbol-is-function (-> obj init-func)) ;; added (set! (-> obj init-func) (the-as (function texture-anim-layer int) (-> (the-as symbol (-> obj init-func)) value)) ) @@ -139,8 +1433,7 @@ ) ;; definition for method 10 of type texture-anim-layer -(defmethod texture-anim-layer-method-10 texture-anim-layer ((obj texture-anim-layer)) +(defmethod clear-texture! texture-anim-layer ((obj texture-anim-layer)) (set! (-> obj tex) #f) obj - ) - + ) \ No newline at end of file diff --git a/goal_src/jak2/engine/gfx/texture/texture-finish.gc b/goal_src/jak2/engine/gfx/texture/texture-finish.gc index 48adc4cfea..3af3bcaace 100644 --- a/goal_src/jak2/engine/gfx/texture/texture-finish.gc +++ b/goal_src/jak2/engine/gfx/texture/texture-finish.gc @@ -11,20 +11,24 @@ (setup-font-texture *texture-pool*) -;; (let ((v1-2 (lookup-texture-by-id (new 'static 'texture-id :index #x4 :page #x70c)))) -;; (when v1-2 -;; (set! (-> v1-2 w) 32) -;; (set! (-> v1-2 h) 32) -;; (set! (-> v1-2 dest 0) (-> *skull-gem-texture-base* vram-block)) -;; ) -;; ) +(let ((v1-2 (lookup-texture-by-id (new 'static 'texture-id :index #x4 :page #x70c)))) + (when v1-2 + (set! (-> v1-2 w) 32) + (set! (-> v1-2 h) 32) + (set! (-> v1-2 dest 0) (-> *skull-gem-texture-base* vram-block)) + ) + ) -;; (texture-anim-array-method-9 *sky-texture-anim-array*) +;; failed to figure out what this is: +(init! *sky-texture-anim-array*) -;; (texture-anim-array-method-9 *darkjak-texture-anim-array*) +;; failed to figure out what this is: +(init! *darkjak-texture-anim-array*) -;; (texture-anim-array-method-9 *skull-gem-texture-anim-array*) +;; failed to figure out what this is: +(init! *skull-gem-texture-anim-array*) -;; (texture-anim-array-method-9 *bomb-texture-anim-array*) +;; failed to figure out what this is: +(init! *bomb-texture-anim-array*) (kmemclose) diff --git a/goal_src/jak2/engine/gfx/texture/texture.gc b/goal_src/jak2/engine/gfx/texture/texture.gc index d9a9ac21de..9b88594460 100644 --- a/goal_src/jak2/engine/gfx/texture/texture.gc +++ b/goal_src/jak2/engine/gfx/texture/texture.gc @@ -1672,9 +1672,11 @@ additionally, some texture pages have a chunk system that allows more specific c (dotimes (s2-1 LEVEL_TOTAL) (let ((v1-54 (-> *level* level s2-1))) (when (or (= (-> v1-54 status) 'active) (= (-> v1-54 status) 'reserved)) - (if (-> v1-54 texture-anim-array 5) - (update-texture-anim bucket) - ) + (let ((a1-26 (-> v1-54 texture-anim-array 5))) + (if a1-26 + (update-texture-anim bucket a1-26) + ) + ) ) ) ) @@ -1687,14 +1689,14 @@ additionally, some texture pages have a chunk system that allows more specific c (let ((f30-0 (-> pp clock seconds-per-frame))) (set! (-> pp clock seconds-per-frame) (* 10.0 (-> pp clock seconds-per-frame))) (if s2-0 - (update-texture-anim bucket) + (update-texture-anim bucket s2-0) ) (set! (-> pp clock seconds-per-frame) f30-0) ) ) (else (if s2-0 - (update-texture-anim bucket) + (update-texture-anim bucket s2-0) ) ) ) @@ -1702,7 +1704,7 @@ additionally, some texture pages have a chunk system that allows more specific c (else ;; otherwise, just update if there's any anims. (if s2-0 - (update-texture-anim bucket) + (update-texture-anim bucket s2-0) ) ) ) diff --git a/goal_src/jak2/engine/level/level.gc b/goal_src/jak2/engine/level/level.gc index 76d5a198d5..55d685e76f 100644 --- a/goal_src/jak2/engine/level/level.gc +++ b/goal_src/jak2/engine/level/level.gc @@ -1075,9 +1075,9 @@ into 7 sections, which might explain the weird sizes in the center. (let ((a0-8 (-> obj info texture-anim s4-0))) (when a0-8 (set! (-> obj info texture-anim s4-0) #f) - #|(set! (-> obj texture-anim-array s4-0) - (texture-anim-array-method-9 (the-as texture-anim-array (-> a0-8 value))) - )|# + (set! (-> obj texture-anim-array s4-0) + (init! (the-as texture-anim-array (-> a0-8 value))) + ) ) ) ) @@ -1636,7 +1636,7 @@ into 7 sections, which might explain the weird sizes in the center. (let ((a0-37 (-> obj info texture-anim s5-3))) (if a0-37 (set! (-> obj texture-anim-array s5-3) - (texture-anim-array-method-10 (the-as texture-anim-array (-> a0-37 value))) + (clear! (the-as texture-anim-array (-> a0-37 value))) ) ) ) diff --git a/goalc/compiler/Compiler.h b/goalc/compiler/Compiler.h index cea6242542..a3ffd4dfdb 100644 --- a/goalc/compiler/Compiler.h +++ b/goalc/compiler/Compiler.h @@ -575,6 +575,8 @@ class Compiler { Val* compile_asm_pextlh(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_asm_pextlw(const goos::Object& form, const goos::Object& rest, Env* env); + Val* compile_asm_paddb(const goos::Object& form, const goos::Object& rest, Env* env); + Val* compile_asm_pcpyud(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_asm_pcpyld(const goos::Object& form, const goos::Object& rest, Env* env); Val* compile_asm_ppach(const goos::Object& form, const goos::Object& rest, Env* env); diff --git a/goalc/compiler/IR.cpp b/goalc/compiler/IR.cpp index 70c4c6dca0..624acf98e0 100644 --- a/goalc/compiler/IR.cpp +++ b/goalc/compiler/IR.cpp @@ -1608,6 +1608,9 @@ std::string IR_Int128Math3Asm::print() { case Kind::PACKUSWB: function = ".packuswb"; break; + case Kind::PADDB: + function = ".paddb"; + break; default: ASSERT(false); } @@ -1698,6 +1701,9 @@ void IR_Int128Math3Asm::do_codegen(emitter::ObjectGenerator* gen, case Kind::PACKUSWB: gen->add_instr(IGen::vpackuswb(dst, src1, src2), irec); break; + case Kind::PADDB: + gen->add_instr(IGen::parallel_add_byte(dst, src1, src2), irec); + break; default: ASSERT(false); } diff --git a/goalc/compiler/IR.h b/goalc/compiler/IR.h index bfdd7c901d..5691bb729a 100644 --- a/goalc/compiler/IR.h +++ b/goalc/compiler/IR.h @@ -584,7 +584,8 @@ class IR_Int128Math3Asm : public IR_Asm { POR, PXOR, PAND, - PACKUSWB + PACKUSWB, + PADDB, }; IR_Int128Math3Asm(bool use_color, const RegVal* dst, diff --git a/goalc/compiler/compilation/Asm.cpp b/goalc/compiler/compilation/Asm.cpp index ccfca06e64..17dbf35f74 100644 --- a/goalc/compiler/compilation/Asm.cpp +++ b/goalc/compiler/compilation/Asm.cpp @@ -748,6 +748,10 @@ Val* Compiler::compile_asm_psubw(const goos::Object& form, const goos::Object& r return compile_asm_int128_math3(form, rest, IR_Int128Math3Asm::Kind::PSUBW, env); } +Val* Compiler::compile_asm_paddb(const goos::Object& form, const goos::Object& rest, Env* env) { + return compile_asm_int128_math3(form, rest, IR_Int128Math3Asm::Kind::PADDB, env); +} + Val* Compiler::compile_asm_ppach(const goos::Object& form, const goos::Object& rest, Env* env) { auto args = get_va(form, rest); va_check(form, args, {{}, {}, {}}, {}); diff --git a/goalc/compiler/compilation/Atoms.cpp b/goalc/compiler/compilation/Atoms.cpp index 1482fca9e8..6e32683ae8 100644 --- a/goalc/compiler/compilation/Atoms.cpp +++ b/goalc/compiler/compilation/Atoms.cpp @@ -129,6 +129,7 @@ const std::unordered_map< {".ppach", {"", &Compiler::compile_asm_ppach}}, {".ppacb", {"", &Compiler::compile_asm_ppacb}}, {".psubw", {"", &Compiler::compile_asm_psubw}}, + {".paddb", {"", &Compiler::compile_asm_paddb}}, // BLOCK FORMS {"top-level", {"", &Compiler::compile_top_level}}, diff --git a/goalc/emitter/IGen.h b/goalc/emitter/IGen.h index a9d2faf089..334666c62e 100644 --- a/goalc/emitter/IGen.h +++ b/goalc/emitter/IGen.h @@ -2456,6 +2456,18 @@ class IGen { return instr; } + static Instruction parallel_add_byte(Register dst, Register src0, Register src1) { + ASSERT(dst.is_xmm()); + ASSERT(src0.is_xmm()); + ASSERT(src1.is_xmm()); + // VEX.128.66.0F.WIG FC /r VPADDB xmm1, xmm2, xmm3/m128 + // reg, vex, r/m + Instruction instr(0xFC); + instr.set_vex_modrm_and_rex(dst.hw_id(), src1.hw_id(), VEX3::LeadingBytes::P_0F, src0.hw_id(), + false, VexPrefix::P_66); + return instr; + } + static Instruction parallel_bitwise_or(Register dst, Register src0, Register src1) { ASSERT(dst.is_xmm()); ASSERT(src0.is_xmm()); diff --git a/test/decompiler/reference/jak2/engine/gfx/ocean/ocean-texture_REF.gc b/test/decompiler/reference/jak2/engine/gfx/ocean/ocean-texture_REF.gc index ad890afad1..297b7fed3d 100644 --- a/test/decompiler/reference/jak2/engine/gfx/ocean/ocean-texture_REF.gc +++ b/test/decompiler/reference/jak2/engine/gfx/ocean/ocean-texture_REF.gc @@ -162,7 +162,6 @@ ;; definition for method 78 of type ocean ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-3 8) 0) at op 21 (defmethod draw-ocean-texture ocean ((obj ocean) (arg0 dma-buffer) (arg1 int)) (set-display-gs-state arg0 21 128 128 0 0) (ocean-texture-add-envmap obj arg0) @@ -204,7 +203,6 @@ ;; definition for method 79 of type ocean ;; INFO: Used lq/sq ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-2 8) 0) at op 14 (defmethod ocean-method-79 ocean ((obj ocean) (arg0 dma-buffer)) (set-display-gs-state arg0 53 64 64 0 0) (dma-buffer-add-gs-set arg0 @@ -303,7 +301,7 @@ ;; WARN: Return type mismatch int vs none. (defmethod ocean-method-80 ocean ((obj ocean) (arg0 (pointer rgba))) (dotimes (v1-0 256) - (let ((a0-3 (-> (the-as (pointer uint8) (&+ *clut-translate* v1-0))))) + (let ((a0-3 (-> *clut-translate* v1-0))) (set! (-> arg0 a0-3 r) v1-0) (set! (-> arg0 a0-3 g) v1-0) (set! (-> arg0 a0-3 b) v1-0) @@ -339,7 +337,6 @@ ;; definition for method 81 of type ocean ;; INFO: Used lq/sq -;; ERROR: Failed store: (s.w! (+ a0-2 8) 0) at op 14 (defmethod ocean-method-81 ocean ((obj ocean) (arg0 dma-buffer)) (set-display-gs-state arg0 53 128 128 0 0) (dma-buffer-add-gs-set arg0 @@ -460,9 +457,9 @@ (dotimes (a3-9 (/ s5-1 16)) (dma-buffer-add-gs-set arg0 (uv (new 'static 'gs-uv :v #x8 :u (+ (* a3-9 256) 8))) - (xyz2 (shr (shl (+ (* a3-9 256) 128) 48) 48)) + (xyz2 (new 'static 'gs-xyz :x (+ (* a3-9 256) 128))) (uv (new 'static 'gs-uv :u (+ (* a3-9 256) 136) :v (+ (* a2-6 16) 8))) - (xyz2 (logior (shr (shl (+ (* a3-9 256) 256) 48) 48) (shr (shl (* a2-6 16) 48) 32))) + (xyz2 (new 'static 'gs-xyz :y (* a2-6 16) :x (+ (* a3-9 256) 256))) ) ) ) @@ -479,9 +476,9 @@ (dotimes (v1-73 (/ s5-1 16)) (dma-buffer-add-gs-set arg0 (uv (new 'static 'gs-uv :v #x8 :u (+ (* v1-73 256) 8))) - (xyz2 (shr (shl (+ (* v1-73 256) 128) 48) 48)) + (xyz2 (new 'static 'gs-xyz :x (+ (* v1-73 256) 128))) (uv (new 'static 'gs-uv :u (+ (* v1-73 256) 136) :v (+ (* s4-3 16) 8))) - (xyz2 (logior (shr (shl (+ (* v1-73 256) 256) 48) 48) (shr (shl (* s4-3 16) 48) 32))) + (xyz2 (new 'static 'gs-xyz :y (* s4-3 16) :x (+ (* v1-73 256) 256))) ) ) ) @@ -491,7 +488,6 @@ ;; definition for method 82 of type ocean ;; INFO: Used lq/sq ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-2 8) 0) at op 11 (defmethod draw-envmap-debug ocean ((obj ocean) (arg0 dma-buffer)) (format *stdcon* "draw-envmap-debug~%") (-> arg0 base) @@ -547,7 +543,6 @@ ;; definition for method 83 of type ocean ;; INFO: Used lq/sq ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-1 8) 0) at op 14 (defmethod ocean-method-83 ocean ((obj ocean) (arg0 dma-buffer) (arg1 float)) (let* ((s4-0 64) (s3-0 0) @@ -640,7 +635,6 @@ ;; definition for method 85 of type ocean ;; INFO: Used lq/sq ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-1 8) 0) at op 6 (defmethod ocean-method-85 ocean ((obj ocean) (arg0 dma-buffer)) (local-vars (sv-48 vector4w) (sv-64 vector4w)) (dma-buffer-add-gs-set arg0 (alpha-1 (new 'static 'gs-alpha :b #x2 :d #x1))) @@ -794,7 +788,6 @@ ;; definition for method 88 of type ocean ;; INFO: Used lq/sq ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-1 8) 0) at op 6 (defmethod ocean-method-88 ocean ((obj ocean) (arg0 dma-buffer)) (local-vars (sv-48 vector) (sv-64 uint) (sv-80 vector) (sv-96 vector) (sv-112 vector)) (dma-buffer-add-gs-set arg0 @@ -930,7 +923,6 @@ ;; definition for method 89 of type ocean ;; INFO: Used lq/sq ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-4 8) 0) at op 40 (defmethod ocean-method-89 ocean ((obj ocean) (arg0 dma-buffer)) (set-display-gs-state arg0 (the-as int (+ (-> *ocean-texture-base* vram-page) 8)) 64 64 0 0) (vector-float*! (-> obj sky-color) (-> *time-of-day-context* current-sky-color) 0.25) @@ -1381,7 +1373,3 @@ v0-0 ) ) - - - - diff --git a/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim-funcs_REF.gc b/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim-funcs_REF.gc new file mode 100644 index 0000000000..d9406dddb1 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim-funcs_REF.gc @@ -0,0 +1,250 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for function noise-texture-anim-layer-func +(defun noise-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (< time (-> layer end-time))) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (upload-vram-data dma-buf (the-as int (-> layer tex dest 0)) (the-as pointer (-> layer tex pad 0)) 32 32) + (dma-buffer-add-gs-set dma-buf (texflush 0)) + (texture-anim-layer-add-shader dma-buf layer 1) + (let ((s1-0 (/ (+ width 63) 64))) + (dma-buffer-add-gs-set dma-buf (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw s1-0 :fbp fbp-to-draw))) + (texture-anim-layer-draw dma-buf width height layer) + (let* ((v1-13 dma-buf) + (a0-17 (the-as object (-> v1-13 base))) + ) + (set! (-> (the-as dma-packet a0-17) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-17) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-17) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-13 base) (&+ (the-as pointer a0-17) 16)) + ) + (let* ((v1-14 dma-buf) + (a0-19 (the-as object (-> v1-14 base))) + ) + (set! (-> (the-as gs-gif-tag a0-19) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a0-19) regs) GIF_REGS_ALL_AD) + (set! (-> v1-14 base) (&+ (the-as pointer a0-19) 16)) + ) + (let ((v1-15 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-frame) v1-15) 0) (new 'static 'gs-frame :fbw s1-0 :fbp fbp-to-draw)) + (set! (-> (the-as (pointer gs-reg64) v1-15) 1) (gs-reg64 frame-1)) + (set! (-> dma-buf base) (&+ v1-15 16)) + ) + ) + ) + ) + 0 + ) + +;; definition for function cloud-texture-anim-layer-func +(defun cloud-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (< time (-> layer end-time))) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (let* ((v1-4 (-> layer tex)) + (t0-1 (/ (-> v1-4 w) 2)) + (a3-1 (/ (-> v1-4 h) 2)) + ) + (upload-vram-data dma-buf (the-as int (-> v1-4 dest 0)) (the-as pointer (-> v1-4 pad 0)) a3-1 t0-1) + ) + (dma-buffer-add-gs-set dma-buf (texflush 0)) + (texture-anim-layer-add-shader dma-buf layer 1) + (texture-anim-layer-draw dma-buf width height layer) + ) + ) + 0 + ) + +;; definition for function cloud-texture-anim-func +(defun cloud-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim)) + (with-pp + (when (>= (+ (-> arg1 frame-time) (* (-> arg1 frame-delta) (-> pp clock seconds-per-frame))) (-> arg1 frame-mod)) + (let ((s5-0 (-> arg1 data 0 tex)) + (s4-0 (-> arg1 data 1 tex)) + (s3-0 (-> arg1 data 0 tex w)) + ) + (when (not (paused?)) + (set! (-> arg1 data 0 tex) s4-0) + (set! (-> arg1 data 1 tex) s5-0) + (make-noise-texture (the-as pointer (-> s5-0 pad 0)) s3-0 s3-0 s3-0) + ) + ) + ) + 0 + ) + ) + +;; definition for function fog-texture-anim-init +;; INFO: Used lq/sq +(defun fog-texture-anim-init ((arg0 texture-anim)) + (let ((gp-0 (new 'loading-level 'fog8x256)) + (s4-0 (new 'loading-level 'clut16x16)) + ) + (when (and gp-0 s4-0) + (let ((v1-5 (new 'loading-level 'texture))) + (let ((a0-4 (the int (-> arg0 extra x))) + (a1-3 (the int (-> arg0 extra y))) + ) + (set! (-> arg0 tex) v1-5) + (set! (-> v1-5 pad 0) (the-as uint gp-0)) + (set! (-> v1-5 pad 1) (the-as uint s4-0)) + (set! (-> v1-5 w) 256) + (set! (-> v1-5 h) 1) + (set! (-> v1-5 num-mips) (the-as uint 1)) + (set! (-> v1-5 psm) (gs-psm mt8)) + (set! (-> v1-5 clutpsm) (the-as uint 0)) + (set! (-> v1-5 dest 0) (the-as uint (* a0-4 32))) + (set! (-> v1-5 clutdest) (the-as uint (* a1-3 32))) + ) + (set! (-> v1-5 width 0) (the-as uint 4)) + (set! (-> v1-5 masks data 0 mask quad) (the-as uint128 0)) + (set! (-> v1-5 masks data 1 mask quad) (the-as uint128 0)) + (set! (-> v1-5 masks data 2 mask quad) (the-as uint128 0)) + ) + 0 + (dotimes (v1-7 256) + (nop!) + (nop!) + (nop!) + (nop!) + (set! (-> gp-0 image v1-7) (the-as uint v1-7)) + ) + ) + ) + 0 + ) + +;; definition for symbol *fog-texture-work*, type fog-texture-work +(define *fog-texture-work* (new 'static 'fog-texture-work :const (new 'static 'vector :x 0.00390625))) + +;; definition for function real-fog-texture-anim-func +;; INFO: Used lq/sq +;; WARN: Return type mismatch symbol vs int. +(defun real-fog-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim)) + (local-vars (sv-48 int)) + (let ((s4-0 (new 'stack-no-clear 'vector)) + (s3-0 (new 'stack-no-clear 'vector)) + (s1-0 *fog-texture-work*) + (s2-0 (the-as (pointer uint32) (-> arg1 tex pad 1))) + ) + (let ((v1-1 (-> s1-0 color))) + (dotimes (a0-1 256) + (set! (-> s2-0 a0-1) v1-1) + ) + ) + (set! sv-48 0) + (let ((s0-0 0)) + (let ((f0-0 40955904.0) + (f1-0 -40955904.0) + ) + (dotimes (v1-7 4) + (let ((f2-0 (-> *fog-texture-work* corner v1-7 y))) + (when (< f2-0 f0-0) + (set! f0-0 f2-0) + (set! sv-48 v1-7) + sv-48 + ) + (when (< f1-0 f2-0) + (set! f1-0 f2-0) + (set! s0-0 v1-7) + ) + ) + ) + ) + (set! (-> s4-0 quad) (-> *fog-texture-work* corner sv-48 quad)) + (vector-! s3-0 (-> *fog-texture-work* corner s0-0) (-> *fog-texture-work* corner sv-48)) + (vector-float/! s3-0 s3-0 256.0) + (set! (-> *fog-texture-work* min-corner quad) (-> *fog-texture-work* corner sv-48 quad)) + (set! (-> *fog-texture-work* max-corner quad) (-> *fog-texture-work* corner s0-0 quad)) + ) + 0.0 + 0.0 + (let ((f0-4 (fmax 4096.0 (-> *math-camera* trans y))) + (f1-2 (-> arg1 extra z)) + (f2-1 (-> s1-0 alpha-near)) + (f3-0 (-> s1-0 alpha-far)) + (f4-0 (-> s1-0 alpha-delta)) + (f5-0 (-> s1-0 fog-near)) + (f6-0 (-> s1-0 fog-far)) + (f7-0 (-> s1-0 fog-delta)) + ) + (dotimes (v1-19 256) + (let* ((f8-0 (-> s4-0 y)) + (f8-1 (cond + ((= f8-0 0.0) + f3-0 + ) + ((< f8-0 0.0) + (let ((f9-4 (fmin f6-0 (/ (* f0-4 (vector-length s4-0)) (- f8-0))))) + (+ f2-1 (* f4-0 (/ (fmax 0.0 (- f9-4 f5-0)) f7-0))) + ) + ) + (else + (let ((f9-8 (fmin f6-0 (/ (* f1-2 (vector-length s4-0)) f8-0)))) + (+ f2-1 (* f4-0 (/ (fmax 0.0 (- f9-8 f5-0)) f7-0))) + ) + ) + ) + ) + ) + (set! (-> s2-0 (-> *clut-translate* v1-19)) + (logior (logand (-> s2-0 (-> *clut-translate* v1-19)) (the-as uint #xffffffff00ffffff)) + (shr (shl (the int (* 128.0 f8-1)) 56) 32) + ) + ) + ) + (vector+! s4-0 s4-0 s3-0) + ) + ) + ) + (let ((s5-1 (-> arg1 tex))) + (dma-buffer-add-gs-set arg0 + (bitbltbuf + (new 'static 'gs-bitbltbuf :dpsm (the-as int (-> s5-1 psm)) :dbp (-> s5-1 dest 0) :dbw (-> s5-1 width 0)) + ) + (trxpos (new 'static 'gs-trxpos)) + (trxreg (new 'static 'gs-trxreg :rrw (-> s5-1 w) :rrh (-> s5-1 h))) + (trxdir (new 'static 'gs-trxdir)) + ) + (dma-buffer-add-ref-texture arg0 (the-as pointer (-> s5-1 pad 0)) (-> s5-1 w) (-> s5-1 h) (-> s5-1 psm)) + (upload-vram-data arg0 (the-as int (-> s5-1 clutdest)) (the-as pointer (-> s5-1 pad 1)) 16 16) + (set! (-> *texture-pool* ids (shr (-> s5-1 clutdest) 6)) (the-as uint 0)) + (let* ((v1-29 arg0) + (a0-51 (the-as object (-> v1-29 base))) + ) + (set! (-> (the-as dma-packet a0-51) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-51) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-51) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-29 base) (&+ (the-as pointer a0-51) 16)) + ) + (let* ((v1-30 arg0) + (a0-53 (the-as object (-> v1-30 base))) + ) + (set! (-> (the-as gs-gif-tag a0-53) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a0-53) regs) GIF_REGS_ALL_AD) + (set! (-> v1-30 base) (&+ (the-as pointer a0-53) 16)) + ) + (let ((v1-31 (-> arg0 base))) + (set! (-> (the-as (pointer int64) v1-31)) 0) + (set! (-> (the-as (pointer gs-reg64) v1-31) 1) (gs-reg64 texflush)) + (set! (-> arg0 base) (&+ v1-31 16)) + ) + (let ((v1-34 (shr (-> s5-1 dest 0) 6))) + (dotimes (a0-56 3) + (set! (-> *texture-pool* ids (+ v1-34 a0-56)) (the-as uint 0)) + ) + ) + ) + (the-as int #f) + ) + +;; definition for function fog-texture-anim-func +(defun fog-texture-anim-func ((arg0 dma-buffer) (arg1 texture-anim)) + (real-fog-texture-anim-func arg0 arg1) + ) + + + + diff --git a/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim-h_REF.gc b/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim-h_REF.gc index 2edbd05cd1..f43db7eb64 100644 --- a/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim-h_REF.gc +++ b/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim-h_REF.gc @@ -3,41 +3,49 @@ ;; definition of type texture-anim-layer (deftype texture-anim-layer (structure) - ((extra vector :inline :offset 240) - (func (function texture-anim-layer int) :offset 256) - (func-id symbol :offset 256) - (init-func (function texture-anim-layer int) :offset 260) - (init-func-id symbol :offset 260) - (tex texture :offset 264) - (start-time float :offset 268) - (end-time float :offset 272) - (tex-name string :offset 276) - (test gs-test :offset 280) - (alpha gs-alpha :offset 288) - (clamp gs-clamp :offset 296) - (start-color vector :inline :offset 80) - (start-scale vector2 :inline :offset 96) - (start-offset vector2 :inline :offset 104) - (start-st-scale vector2 :inline :offset 112) - (start-st-offset vector2 :inline :offset 120) - (start-qs vector :inline :offset 128) - (start-rot degrees :offset 144) - (start-st-rot degrees :offset 148) - (end-color vector :inline :offset 160) - (end-scale vector2 :inline :offset 176) - (end-offset vector2 :inline :offset 184) - (end-st-scale vector2 :inline :offset 192) - (end-st-offset vector2 :inline :offset 200) - (end-qs vector :inline :offset 208) - (end-rot degrees :offset 224) - (end-st-rot degrees :offset 228) + ((interpolated-color vector :inline :offset-assert 0) + (interpolated-scale-offset vector :inline :offset-assert 16) + (interpolated-st-scale-offset vector :inline :offset-assert 32) + (interpolated-qs vector :inline :offset-assert 48) + (interpolated-rot vector :inline :offset-assert 64) + (extra vector :inline :offset 240) + (func (function dma-buffer uint int int texture-anim-layer float int) :offset 256) + (func-id symbol :offset 256) + (init-func (function texture-anim-layer int) :offset 260) + (init-func-id symbol :offset 260) + (tex texture :offset 264) + (start-time float :offset 268) + (end-time float :offset 272) + (tex-name string :offset 276) + (test gs-test :offset 280) + (alpha gs-alpha :offset 288) + (clamp gs-clamp :offset 296) + (start-vectors vector 5 :inline :offset 80) + (start-color vector :inline :offset 80) + (start-scale vector2 :inline :offset 96) + (start-offset vector2 :inline :offset 104) + (start-st-scale vector2 :inline :offset 112) + (start-st-offset vector2 :inline :offset 120) + (start-qs vector :inline :offset 128) + (start-rot degrees :offset 144) + (start-st-rot degrees :offset 148) + (end-vectors vector 5 :inline :offset 160) + (end-color vector :inline :offset 160) + (end-scale vector2 :inline :offset 176) + (end-offset vector2 :inline :offset 184) + (end-scale-offset vector :inline :offset 176) + (end-st-scale vector2 :inline :offset 192) + (end-st-offset vector2 :inline :offset 200) + (end-qs vector :inline :offset 208) + (end-rot degrees :offset 224) + (end-st-rot degrees :offset 228) ) :method-count-assert 11 :size-assert #x130 :flag-assert #xb00000130 (:methods - (texture-anim-layer-method-9 (_type_) _type_ 9) - (texture-anim-layer-method-10 (_type_) _type_ 10) + (initialize-texture! (_type_) _type_ 9) + (clear-texture! (_type_) _type_ 10) ) ) @@ -82,29 +90,29 @@ ;; definition of type texture-anim (deftype texture-anim (structure) - ((num-layers uint32 :offset-assert 0) - (func (function texture-anim int) :offset-assert 4) - (func-id symbol :offset 4) - (init-func (function texture-anim int) :offset-assert 8) - (init-func-id symbol :offset 8) - (tex texture :offset-assert 12) - (tex-name string :offset-assert 16) - (extra vector :inline :offset-assert 32) - (color rgba :offset-assert 48) - (frame-time float :offset-assert 52) - (frame-delta float :offset-assert 56) - (frame-mod float :offset-assert 60) - (test gs-test :offset-assert 64) - (alpha gs-alpha :offset-assert 72) - (clamp gs-clamp :offset-assert 80) - (data texture-anim-layer :dynamic :offset-assert 88) + ((num-layers uint32 :offset-assert 0) + (func (function dma-buffer texture-anim int) :offset-assert 4) + (func-id symbol :offset 4) + (init-func (function texture-anim int) :offset-assert 8) + (init-func-id symbol :offset 8) + (tex texture :offset-assert 12) + (tex-name string :offset-assert 16) + (extra vector :inline :offset-assert 32) + (color rgba :offset-assert 48) + (frame-time float :offset-assert 52) + (frame-delta float :offset-assert 56) + (frame-mod float :offset-assert 60) + (test gs-test :offset-assert 64) + (alpha gs-alpha :offset-assert 72) + (clamp gs-clamp :offset-assert 80) + (data texture-anim-layer :dynamic :offset-assert 88) ) :method-count-assert 11 :size-assert #x58 :flag-assert #xb00000058 (:methods - (texture-anim-method-9 (_type_) _type_ 9) - (texture-anim-method-10 (_type_) _type_ 10) + (init-textures! (_type_) _type_ 9) + (clear-textures! (_type_) _type_ 10) ) ) @@ -143,8 +151,8 @@ :size-assert #x10 :flag-assert #xb00000010 (:methods - (texture-anim-array-method-9 (_type_) _type_ 9) - (texture-anim-array-method-10 (_type_) _type_ 10) + (init! (_type_) _type_ 9) + (clear! (_type_) _type_ 10) ) ) @@ -394,78 +402,266 @@ obj ) -;; definition for symbol *clut-translate*, type (pointer uint32) -(define *clut-translate* (new 'static 'array uint32 64 - #x3020100 - #x7060504 - #x13121110 - #x17161514 - #xb0a0908 - #xf0e0d0c - #x1b1a1918 - #x1f1e1d1c - #x23222120 - #x27262524 - #x33323130 - #x37363534 - #x2b2a2928 - #x2f2e2d2c - #x3b3a3938 - #x3f3e3d3c - #x43424140 - #x47464544 - #x53525150 - #x57565554 - #x4b4a4948 - #x4f4e4d4c - #x5b5a5958 - #x5f5e5d5c - #x63626160 - #x67666564 - #x73727170 - #x77767574 - #x6b6a6968 - #x6f6e6d6c - #x7b7a7978 - #x7f7e7d7c - #x83828180 - #x87868584 - #x93929190 - #x97969594 - #x8b8a8988 - #x8f8e8d8c - #x9b9a9998 - #x9f9e9d9c - #xa3a2a1a0 - #xa7a6a5a4 - #xb3b2b1b0 - #xb7b6b5b4 - #xabaaa9a8 - #xafaeadac - #xbbbab9b8 - #xbfbebdbc - #xc3c2c1c0 - #xc7c6c5c4 - #xd3d2d1d0 - #xd7d6d5d4 - #xcbcac9c8 - #xcfcecdcc - #xdbdad9d8 - #xdfdedddc - #xe3e2e1e0 - #xe7e6e5e4 - #xf3f2f1f0 - #xf7f6f5f4 - #xebeae9e8 - #xefeeedec - #xfbfaf9f8 - #xfffefdfc +;; definition for symbol *clut-translate*, type (pointer uint8) +(define *clut-translate* (new 'static 'array uint8 256 + #x0 + #x1 + #x2 + #x3 + #x4 + #x5 + #x6 + #x7 + #x10 + #x11 + #x12 + #x13 + #x14 + #x15 + #x16 + #x17 + #x8 + #x9 + #xa + #xb + #xc + #xd + #xe + #xf + #x18 + #x19 + #x1a + #x1b + #x1c + #x1d + #x1e + #x1f + #x20 + #x21 + #x22 + #x23 + #x24 + #x25 + #x26 + #x27 + #x30 + #x31 + #x32 + #x33 + #x34 + #x35 + #x36 + #x37 + #x28 + #x29 + #x2a + #x2b + #x2c + #x2d + #x2e + #x2f + #x38 + #x39 + #x3a + #x3b + #x3c + #x3d + #x3e + #x3f + #x40 + #x41 + #x42 + #x43 + #x44 + #x45 + #x46 + #x47 + #x50 + #x51 + #x52 + #x53 + #x54 + #x55 + #x56 + #x57 + #x48 + #x49 + #x4a + #x4b + #x4c + #x4d + #x4e + #x4f + #x58 + #x59 + #x5a + #x5b + #x5c + #x5d + #x5e + #x5f + #x60 + #x61 + #x62 + #x63 + #x64 + #x65 + #x66 + #x67 + #x70 + #x71 + #x72 + #x73 + #x74 + #x75 + #x76 + #x77 + #x68 + #x69 + #x6a + #x6b + #x6c + #x6d + #x6e + #x6f + #x78 + #x79 + #x7a + #x7b + #x7c + #x7d + #x7e + #x7f + #x80 + #x81 + #x82 + #x83 + #x84 + #x85 + #x86 + #x87 + #x90 + #x91 + #x92 + #x93 + #x94 + #x95 + #x96 + #x97 + #x88 + #x89 + #x8a + #x8b + #x8c + #x8d + #x8e + #x8f + #x98 + #x99 + #x9a + #x9b + #x9c + #x9d + #x9e + #x9f + #xa0 + #xa1 + #xa2 + #xa3 + #xa4 + #xa5 + #xa6 + #xa7 + #xb0 + #xb1 + #xb2 + #xb3 + #xb4 + #xb5 + #xb6 + #xb7 + #xa8 + #xa9 + #xaa + #xab + #xac + #xad + #xae + #xaf + #xb8 + #xb9 + #xba + #xbb + #xbc + #xbd + #xbe + #xbf + #xc0 + #xc1 + #xc2 + #xc3 + #xc4 + #xc5 + #xc6 + #xc7 + #xd0 + #xd1 + #xd2 + #xd3 + #xd4 + #xd5 + #xd6 + #xd7 + #xc8 + #xc9 + #xca + #xcb + #xcc + #xcd + #xce + #xcf + #xd8 + #xd9 + #xda + #xdb + #xdc + #xdd + #xde + #xdf + #xe0 + #xe1 + #xe2 + #xe3 + #xe4 + #xe5 + #xe6 + #xe7 + #xf0 + #xf1 + #xf2 + #xf3 + #xf4 + #xf5 + #xf6 + #xf7 + #xe8 + #xe9 + #xea + #xeb + #xec + #xed + #xee + #xef + #xf8 + #xf9 + #xfa + #xfb + #xfc + #xfd + #xfe + #xff ) ) ;; failed to figure out what this is: 0 - - - - diff --git a/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim_REF.gc b/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim_REF.gc new file mode 100644 index 0000000000..7b9c2ae4b1 --- /dev/null +++ b/test/decompiler/reference/jak2/engine/gfx/texture/texture-anim_REF.gc @@ -0,0 +1,1370 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for symbol *texture-anim-work*, type texture-anim-work +(define *texture-anim-work* + (new 'static 'texture-anim-work + :erase-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite)) + :nreg #x3 + ) + :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) :regs1 (gif-reg-id xyz2) :regs2 (gif-reg-id xyz2)) + ) + :draw-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #xa :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #xa :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :tme #x1 :abe #x1) + :nreg #x9 + ) + :gif1 (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyz2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyz2) + :regs5 (gif-reg-id st) + :regs6 (gif-reg-id xyz2) + :regs7 (gif-reg-id st) + :regs8 (gif-reg-id xyz2) + ) + ) + :draw2-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1) + :nreg #x5 + ) + :gif1 (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyz2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyz2) + ) + ) + :fill-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite)) + :nreg #x3 + ) + :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) :regs1 (gif-reg-id xyz2) :regs2 (gif-reg-id xyz2)) + ) + :adgif-tmpl (new 'static 'dma-gif-packet + :dma-vif (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 :nloop #x5 :eop #x1 :nreg #x1) + :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :corner0 (new 'static 'vector :x -0.5 :y -0.5 :w 1.0) + :corner1 (new 'static 'vector :x 0.5 :y -0.5 :w 1.0) + :corner2 (new 'static 'vector :x -0.5 :y 0.5 :w 1.0) + :corner3 (new 'static 'vector :x 0.5 :y 0.5 :w 1.0) + :const (new 'static 'vector :x 128.0 :z 1.9921 :w 1.0) + :random (new 'static 'inline-array vector4w 8 + (new 'static 'vector4w :x #x17181920 :y #x13141516 :z -1995435758 :w #x1234567) + (new 'static 'vector4w :x #x23878237 :y #x32048778 :z -1740074601 :w -2021050320) + (new 'static 'vector4w :x #x62024762 :y -1876389256 :z #x28724781 :w #x68712983) + (new 'static 'vector4w :x #x62176128 :y #x12387487 :z #x12780983 :w -2139999882) + (new 'static 'vector4w :x #x34987239 :y #x78699872 :z -2087161499 :w #x1982397) + (new 'static 'vector4w :x -1737344873 :y -1742502109 :z #x20987293 :w #x62102981) + (new 'static 'vector4w :x -2110229208 :y -2022559591 :z -1743517309 :w #x29874310) + (new 'static 'vector4w :x -2030034041 :y -1743611880 :z -2094950384 :w #x71623790) + ) + ) + ) + +;; definition for function texture-anim-layer-interp +;; WARN: Return type mismatch float vs none. +(defun texture-anim-layer-interp ((arg0 texture-anim-layer) (arg1 float)) + (local-vars (v0-0 float)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (set! (-> *texture-anim-work* const y) + (/ (- arg1 (-> arg0 start-time)) (- (-> arg0 end-time) (-> arg0 start-time))) + ) + (.lvf vf1 (&-> *texture-anim-work* const quad)) + (.lvf vf2 (&-> arg0 start-color quad)) + (.lvf vf3 (&-> arg0 start-vectors 1 quad)) + (.lvf vf4 (&-> arg0 start-vectors 2 quad)) + (.lvf vf5 (&-> arg0 start-qs quad)) + (.lvf vf6 (&-> arg0 start-vectors 4 quad)) + (.lvf vf7 (&-> arg0 end-color quad)) + (.lvf vf8 (&-> arg0 end-scale-offset quad)) + (.lvf vf9 (&-> arg0 end-vectors 2 quad)) + (.lvf vf10 (&-> arg0 end-qs quad)) + (.lvf vf11 (&-> arg0 end-vectors 4 quad)) + (.sub.vf vf7 vf7 vf2) + (.sub.vf vf8 vf8 vf3) + (.sub.vf vf9 vf9 vf4) + (.sub.vf vf10 vf10 vf5) + (.sub.vf vf11 vf11 vf6) + (.mul.y.vf acc vf7 vf1) + (.add.mul.w.vf vf2 vf2 vf0 acc) + (.mul.y.vf acc vf8 vf1) + (.add.mul.w.vf vf3 vf3 vf0 acc) + (.mul.y.vf acc vf9 vf1) + (.add.mul.w.vf vf4 vf4 vf0 acc) + (.mul.y.vf acc vf10 vf1) + (.add.mul.w.vf vf5 vf5 vf0 acc) + (.mul.y.vf acc vf11 vf1) + (.add.mul.w.vf vf6 vf6 vf0 acc) + (.max.x.vf vf2 vf2 vf0) + (.min.z.vf vf2 vf2 vf1) + (.svf (&-> arg0 interpolated-color quad) vf2) + (.svf (&-> arg0 interpolated-scale-offset quad) vf3) + (.svf (&-> arg0 interpolated-st-scale-offset quad) vf4) + (.svf (&-> arg0 interpolated-qs quad) vf5) + (.svf (&-> arg0 interpolated-rot quad) vf6) + (.mov v0-0 vf6) + (none) + ) + ) + +;; definition for function texture-anim-layer-add-shader +;; WARN: Return type mismatch pointer vs none. +(defun texture-anim-layer-add-shader ((arg0 dma-buffer) (arg1 texture-anim-layer) (arg2 int)) + (let ((s5-0 (-> arg1 tex))) + (if s5-0 + (dma-buffer-add-gs-set arg0 + (tex0-1 (new 'static 'gs-tex0 + :cld #x1 + :psm (the-as int (-> s5-0 psm)) + :cpsm (-> s5-0 clutpsm) + :cbp (-> s5-0 clutdest) + :tcc arg2 + :th (log2 (-> s5-0 h)) + :tw (log2 (-> s5-0 w)) + :tbw (-> s5-0 width 0) + :tbp0 (-> s5-0 dest 0) + ) + ) + (tex1-1 (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) + (test-1 (-> arg1 test)) + (clamp-1 (-> arg1 clamp)) + (alpha-1 (-> arg1 alpha)) + ) + ) + ) + (none) + ) + +;; definition for function texture-anim-layer-add-clut-shader +;; WARN: Return type mismatch pointer vs none. +(defun texture-anim-layer-add-clut-shader ((arg0 dma-buffer) (arg1 texture-anim-layer) (arg2 int)) + (let ((a1-1 (-> arg1 tex))) + (if a1-1 + (dma-buffer-add-gs-set arg0 + (tex0-1 (new 'static 'gs-tex0 :tbw #x1 :tw #x4 :th #x4 :tcc arg2 :tbp0 (-> a1-1 clutdest))) + (tex1-1 (new 'static 'gs-tex1)) + (test-1 (new 'static 'gs-test :ate #x1 :afail #x1 :zte #x1 :ztst (gs-ztest always))) + (clamp-1 (new 'static 'gs-clamp :wms (gs-tex-wrap-mode clamp) :wmt (gs-tex-wrap-mode clamp))) + (alpha-1 (new 'static 'gs-alpha :b #x1 :d #x1)) + ) + ) + ) + (none) + ) + +;; definition for function texture-anim-layer-draw +;; INFO: Used lq/sq +;; WARN: Return type mismatch pointer vs none. +(defun texture-anim-layer-draw ((dma-buf dma-buffer) (width int) (height int) (layer texture-anim-layer)) + (local-vars (v1-27 float) (sv-224 matrix) (sv-228 matrix) (sv-232 matrix) (sv-236 matrix)) + (rlet ((acc :class vf) + (vf0 :class vf) + (vf1 :class vf) + (vf10 :class vf) + (vf11 :class vf) + (vf12 :class vf) + (vf14 :class vf) + (vf15 :class vf) + (vf16 :class vf) + (vf18 :class vf) + (vf19 :class vf) + (vf2 :class vf) + (vf3 :class vf) + (vf4 :class vf) + (vf5 :class vf) + (vf6 :class vf) + (vf7 :class vf) + (vf8 :class vf) + (vf9 :class vf) + ) + (init-vf0-vector) + (let ((s4-0 (the-as (pointer uint128) (-> dma-buf base)))) + (set! (-> s4-0 0) (-> *texture-anim-work* draw-tmpl dma-vif quad)) + (set! (-> s4-0 1) (-> *texture-anim-work* draw-tmpl quad 1)) + (set! sv-224 (new 'stack-no-clear 'matrix)) + (set! sv-228 (new 'stack-no-clear 'matrix)) + (set! sv-232 (new 'stack-no-clear 'matrix)) + (let ((v1-7 (new 'stack-no-clear 'matrix))) + (set! (-> v1-7 quad 0) (the-as uint128 0)) + (set! sv-236 v1-7) + ) + (let ((s3-0 *texture-anim-work*)) + (.lvf vf1 (&-> s3-0 const quad)) + (.lvf vf2 (&-> layer interpolated-color quad)) + (.mul.x.vf vf2 vf2 vf1) + (.ftoi.vf vf2 vf2) + (.svf (&-> s4-0 2) vf2) + (matrix-rotate-z! sv-224 (-> layer interpolated-rot x)) + (set! (-> sv-236 vector 0 x) (* (-> layer interpolated-scale-offset x) (the float width))) + (set! (-> sv-236 vector 0 y) (* (-> layer interpolated-scale-offset y) (the float height))) + (matrix-scale! sv-232 (the-as vector sv-236)) + (matrix*! sv-224 sv-232 sv-224) + (set! (-> sv-224 trans x) (+ 2048.0 (* (-> layer interpolated-scale-offset z) (the float width)))) + (set! (-> sv-224 trans y) (+ 2048.0 (* (-> layer interpolated-scale-offset w) (the float height)))) + (set! (-> sv-224 trans z) 1048575.94) + (matrix-rotate-z! sv-228 (-> layer interpolated-rot y)) + (set! (-> sv-236 vector 0 x) (-> layer interpolated-st-scale-offset x)) + (set! (-> sv-236 vector 0 y) (-> layer interpolated-st-scale-offset y)) + (matrix-scale! sv-232 (the-as vector sv-236)) + (matrix*! sv-228 sv-232 sv-228) + (set! (-> sv-228 trans x) (-> layer interpolated-st-scale-offset z)) + (set! (-> sv-228 trans y) (-> layer interpolated-st-scale-offset w)) + (.lvf vf11 (&-> sv-224 quad 0)) + (.lvf vf12 (&-> sv-224 quad 1)) + (.lvf vf14 (&-> sv-224 trans quad)) + (.lvf vf15 (&-> sv-228 quad 0)) + (.lvf vf16 (&-> sv-228 quad 1)) + (.lvf vf18 (&-> sv-228 trans quad)) + (.lvf vf7 (&-> s3-0 corner0 quad)) + (.lvf vf8 (&-> s3-0 corner1 quad)) + (.lvf vf9 (&-> s3-0 corner2 quad)) + (.lvf vf10 (&-> s3-0 corner3 quad)) + ) + (.lvf vf19 (&-> layer interpolated-qs quad)) + (.mul.x.vf acc vf11 vf7) + (.add.mul.y.vf acc vf12 vf7 acc) + (.add.mul.w.vf vf3 vf14 vf0 acc) + (.mul.x.vf acc vf11 vf8) + (.add.mul.y.vf acc vf12 vf8 acc) + (.add.mul.w.vf vf4 vf14 vf0 acc) + (.mul.x.vf acc vf11 vf9) + (.add.mul.y.vf acc vf12 vf9 acc) + (.add.mul.w.vf vf5 vf14 vf0 acc) + (.mul.x.vf acc vf11 vf10) + (.add.mul.y.vf acc vf12 vf10 acc) + (.add.mul.w.vf vf6 vf14 vf0 acc) + (.mul.x.vf acc vf15 vf7) + (.add.mul.y.vf acc vf16 vf7 acc) + (.add.mul.w.vf vf7 vf18 vf0 acc) + (vftoi4.xyzw vf3 vf3) + (.mul.x.vf acc vf15 vf8) + (.add.mul.y.vf acc vf16 vf8 acc) + (.add.mul.w.vf vf8 vf18 vf0 acc) + (vftoi4.xyzw vf4 vf4) + (.mul.x.vf acc vf15 vf9) + (.add.mul.y.vf acc vf16 vf9 acc) + (.add.mul.w.vf vf9 vf18 vf0 acc) + (vftoi4.xyzw vf5 vf5) + (.mul.x.vf acc vf15 vf10) + (.add.mul.y.vf acc vf16 vf10 acc) + (.add.mul.w.vf vf10 vf18 vf0 acc) + (vftoi4.xyzw vf6 vf6) + (.add.x.vf vf7 vf0 vf19 :mask #b100) + (.add.y.vf vf8 vf0 vf19 :mask #b100) + (.add.z.vf vf9 vf0 vf19 :mask #b100) + (.add.w.vf vf10 vf0 vf19 :mask #b100) + (.mul.z.vf vf7 vf7 vf7 :mask #b11) + (.mul.z.vf vf8 vf8 vf8 :mask #b11) + (.mul.z.vf vf9 vf9 vf9 :mask #b11) + (.mul.z.vf vf10 vf10 vf10 :mask #b11) + (.svf (&-> s4-0 3) vf7) + (.svf (&-> s4-0 4) vf3) + (.svf (&-> s4-0 5) vf8) + (.svf (&-> s4-0 6) vf4) + (.svf (&-> s4-0 7) vf9) + (.svf (&-> s4-0 8) vf5) + (.svf (&-> s4-0 9) vf10) + (.svf (&-> s4-0 10) vf6) + ) + (.mov v1-27 vf6) + (&+! (-> dma-buf base) 176) + (none) + ) + ) + +;; definition for function default-texture-anim-layer-func +(defun default-texture-anim-layer-func ((dma-buf dma-buffer) (arg1 uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (texture-anim-layer-add-shader dma-buf layer 1) + (texture-anim-layer-draw dma-buf width height layer) + ) + ) + 0 + ) + +;; definition for function blend-clut-texture-anim-layer-func +(defun blend-clut-texture-anim-layer-func ((dma-buf dma-buffer) (arg1 uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (texture-anim-layer-add-clut-shader dma-buf layer 0) + (texture-anim-layer-draw dma-buf 16 16 layer) + ) + ) + 0 + ) + +;; definition for function move-rg-to-ba-texture-anim-layer-func +(defun move-rg-to-ba-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (-> layer tex) + (let ((tw (log2 (* width 2))) + (th (log2 height)) + (tbp (-> layer tex dest 0)) + (tbw (/ (+ (* width 2) 63) 64)) + (fbmask #x3fff) + ) + (dma-buffer-add-gs-set-flusha dma-buf + (xyoffset-1 (new 'static 'gs-xy-offset)) + (frame-1 (new 'static 'gs-frame :psm (gs-psm ct16) :fbmsk fbmask :fbw tbw :fbp fbp-to-draw)) + (scissor-1 (new 'static 'gs-scissor :scax1 (+ width -1) :scay1 (+ height -1))) + (test-1 (new 'static 'gs-test :ate #x1 :afail #x1 :zte #x1 :ztst (gs-ztest always))) + (alpha-1 (new 'static 'gs-alpha :a #x2 :b #x2 :c #x2 :fix #x80)) + (tex0-1 (new 'static 'gs-tex0 :psm #x2 :tcc #x1 :tfx #x1 :th th :tw tw :tbw tbw :tbp0 tbp)) + (fba-1 0) + (texa (new 'static 'gs-texa :ta1 #x80)) + (tex1-1 (new 'static 'gs-tex1 :lcm #x1)) + (texflush 0) + (prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1 :abe #x1 :fst #x1)) + ) + (let ((a3-4 height)) + (dotimes (t0-7 (/ width 16)) + (dma-buffer-add-gs-set dma-buf + (uv (new 'static 'gs-uv :v #x8 :u (+ (* t0-7 256) 8))) + (xyz2 (new 'static 'gs-xyz :x (+ (* t0-7 256) 128))) + (uv (new 'static 'gs-uv :u (+ (* t0-7 256) 136) :v (+ (* a3-4 16) 8))) + (xyz2 (new 'static 'gs-xyz :y (* a3-4 16) :x (+ (* t0-7 256) 256))) + ) + ) + ) + (let ((t1-40 (/ width 64))) + (dma-buffer-add-gs-set dma-buf + (frame-1 (new 'static 'gs-frame :psm (gs-psm ct16) :fbmsk fbmask :fbw tbw :fbp (+ fbp-to-draw t1-40))) + (tex0-1 (new 'static 'gs-tex0 :psm #x2 :tcc #x1 :tfx #x1 :th th :tw tw :tbw tbw :tbp0 (+ tbp (* t1-40 32)))) + (prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1 :abe #x1 :fst #x1)) + ) + ) + ) + (dotimes (v1-8 (/ width 16)) + (dma-buffer-add-gs-set dma-buf + (uv (new 'static 'gs-uv :v #x8 :u (+ (* v1-8 256) 8))) + (xyz2 (new 'static 'gs-xyz :x (+ (* v1-8 256) 128))) + (uv (new 'static 'gs-uv :u (+ (* v1-8 256) 136) :v (+ (* height 16) 8))) + (xyz2 (new 'static 'gs-xyz :y (* height 16) :x (+ (* v1-8 256) 256))) + ) + ) + (let* ((v1-11 dma-buf) + (a0-15 (the-as dma-packet (-> v1-11 base))) + ) + (set! (-> a0-15 dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> a0-15 vif0) (new 'static 'vif-tag :cmd (vif-cmd flusha) :msk #x1)) + (set! (-> a0-15 vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-11 base) (the-as pointer (&+ a0-15 16))) + ) + (let* ((v1-12 dma-buf) + (a0-17 (the-as gs-gif-tag (-> v1-12 base))) + ) + (set! (-> a0-17 tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> a0-17 regs) GIF_REGS_ALL_AD) + (set! (-> v1-12 base) (the-as pointer (&+ a0-17 16))) + ) + (let ((v1-13 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-xy-offset) v1-13) 0) (new 'static 'gs-xy-offset :ofx #x7000 :ofy #x7300)) + (set! (-> (the-as (pointer gs-reg64) v1-13) 1) (gs-reg64 xyoffset-1)) + (set! (-> (the-as (pointer gs-frame) v1-13) 2) + (new 'static 'gs-frame :fbw (/ (+ width 63) 64) :fbp fbp-to-draw) + ) + (set! (-> (the-as (pointer gs-reg64) v1-13) 3) (gs-reg64 frame-1)) + (set! (-> dma-buf base) (&+ v1-13 32)) + ) + 0 + ) + +;; definition for function fill-rgb-texture-anim-layer-func +;; INFO: Used lq/sq +(defun fill-rgb-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (rlet ((vf1 :class vf) + (vf2 :class vf) + ) + (let ((s5-0 (/ (+ width 63) 64))) + (dma-buffer-add-gs-set-flusha dma-buf + (frame-1 (new 'static 'gs-frame :fbmsk #xff000000 :fbw s5-0 :fbp fbp-to-draw)) + (texflush 0) + ) + (texture-anim-layer-interp layer time) + (let ((v1-4 (-> dma-buf base)) + (a3-1 2048) + (a2-5 2048) + (a0-8 (+ width 2048)) + (a1-15 (+ height 2048)) + ) + (set! (-> (the-as (pointer uint128) v1-4)) (-> *texture-anim-work* fill-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-4) 1) (-> *texture-anim-work* fill-tmpl quad 1)) + (.lvf vf1 (&-> *texture-anim-work* const quad)) + (.lvf vf2 (&-> layer interpolated-color quad)) + (.mul.x.vf vf2 vf2 vf1) + (.ftoi.vf vf2 vf2) + (.svf (&-> (the-as (pointer uint128) v1-4) 2) vf2) + (set-vector! (the-as vector4w (&+ v1-4 48)) (* a3-1 16) (* a2-5 16) 0 0) + (set-vector! (the-as vector4w (&+ v1-4 64)) (* a0-8 16) (* a1-15 16) 0 0) + ) + (&+! (-> dma-buf base) 80) + (let* ((v1-8 dma-buf) + (a0-11 (the-as dma-packet (-> v1-8 base))) + ) + (set! (-> a0-11 dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> a0-11 vif0) (new 'static 'vif-tag :cmd (vif-cmd flusha) :msk #x1)) + (set! (-> a0-11 vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-8 base) (the-as pointer (&+ a0-11 16))) + ) + (let* ((v1-9 dma-buf) + (a0-13 (the-as gs-gif-tag (-> v1-9 base))) + ) + (set! (-> a0-13 tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> a0-13 regs) GIF_REGS_ALL_AD) + (set! (-> v1-9 base) (the-as pointer (&+ a0-13 16))) + ) + (let ((v1-10 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-frame) v1-10) 0) (new 'static 'gs-frame :fbw s5-0 :fbp fbp-to-draw)) + (set! (-> (the-as (pointer gs-reg64) v1-10) 1) (gs-reg64 frame-1)) + (set! (-> (the-as (pointer uint64) v1-10) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) v1-10) 3) (gs-reg64 texflush)) + (set! (-> dma-buf base) (&+ v1-10 32)) + ) + ) + 0 + ) + ) + +;; definition for function update-texture-anim +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +;; WARN: Function update-texture-anim has a return type of none, but the expression builder found a return statement. +(defun update-texture-anim ((bucket bucket-id) (anim-array texture-anim-array)) + (local-vars (tex-height int) (fbp-for-tex uint) (layer-idx int)) + (with-pp + (if (-> *blit-displays-work* menu-mode) + (return #f) + ) + (with-dma-buffer-add-bucket ((dma-buf (-> *display* frames (-> *display* on-screen) global-buf)) + bucket + ) + (dotimes (anim-idx (-> anim-array length)) + (let* ((anim (-> anim-array array-data anim-idx)) + (dest-tex (-> anim tex)) + ) + (when dest-tex + 0 + (let ((tex-width (-> dest-tex w))) + (set! tex-height (-> dest-tex h)) + (cond + ((or (= (-> dest-tex psm) (gs-psm ct32)) (= (-> dest-tex psm) (gs-psm mt8h))) + (set! fbp-for-tex (shr (-> dest-tex dest 0) 5)) + fbp-for-tex + ) + (else + (set! fbp-for-tex (shr (-> dest-tex clutdest) 5)) + (set! tex-width 16) + (set! tex-height 16) + tex-height + ) + ) + (when (and (nonzero? tex-width) (nonzero? tex-height)) + (dma-buffer-add-gs-set-flusha dma-buf + (scissor-1 (new 'static 'gs-scissor :scax1 (+ tex-width -1) :scay1 (+ tex-height -1))) + (xyoffset-1 (new 'static 'gs-xy-offset :ofx #x8000 :ofy #x8000)) + (frame-1 (new 'static 'gs-frame :fbw (/ (+ tex-width 63) 64) :fbp fbp-for-tex)) + (test-1 (-> anim test)) + (alpha-1 (-> anim alpha)) + (clamp-1 (-> anim clamp)) + (texa (new 'static 'gs-texa :ta0 #x80 :ta1 #x80)) + (zbuf-1 (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24) :zmsk #x1)) + (texflush 0) + ) + (let ((a1-32 (-> dma-buf base)) + (a3-0 2048) + (a2-7 2048) + (v1-25 (+ tex-width 2048)) + (a0-16 (+ tex-height 2048)) + ) + (set! (-> (the-as (pointer uint128) a1-32)) (-> *texture-anim-work* erase-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) a1-32) 1) (-> *texture-anim-work* erase-tmpl quad 1)) + (set-vector! + (the-as vector4w (&+ a1-32 32)) + (the-as int (-> anim color r)) + (the-as int (-> anim color g)) + (the-as int (-> anim color b)) + (the-as int (-> anim color a)) + ) + (set-vector! (the-as vector4w (&+ a1-32 48)) (* a3-0 16) (* a2-7 16) #xffffff 0) + (set-vector! (the-as vector4w (&+ a1-32 64)) (* v1-25 16) (* a0-16 16) #xffffff 0) + ) + (&+! (-> dma-buf base) 80) + ) + (let ((v1-32 (/ (the-as int fbp-for-tex) 2)) + (a0-19 (* (/ (+ tex-width 63) 64) (/ (+ tex-height 63) 64))) + ) + (if (and (logtest? fbp-for-tex 1) (< 32 tex-width)) + (+! a0-19 1) + ) + (dotimes (a1-43 a0-19) + (set! (-> *texture-pool* ids (+ v1-32 a1-43)) (the-as uint 0)) + ) + ) + (set! layer-idx 0) + (while (< layer-idx (the-as int (-> anim num-layers))) + (let ((layer (-> anim data layer-idx))) + ((-> layer func) dma-buf fbp-for-tex tex-width tex-height layer (-> anim frame-time)) + ) + (set! layer-idx (+ layer-idx 1)) + ) + ) + (if (-> anim func) + ((-> anim func) dma-buf anim) + ) + (when (not (paused?)) + (let ((f0-2 (+ (-> anim frame-time) (* (-> anim frame-delta) (-> pp clock seconds-per-frame)))) + (f1-2 (-> anim frame-mod)) + ) + (set! (-> anim frame-time) (- f0-2 (* (the float (the int (/ f0-2 f1-2))) f1-2))) + ) + (if (< (-> anim frame-time) 0.0) + (+! (-> anim frame-time) (-> anim frame-mod)) + ) + ) + ) + ) + ) + (reset-display-gs-state *display* dma-buf) + ) + 0 + (none) + ) + ) + +;; definition for function no-alpha-texture-anim-layer-func +(defun no-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (when (!= (-> layer interpolated-color w) 0.0) + (texture-anim-layer-add-shader dma-buf layer 0) + (texture-anim-layer-draw dma-buf width height layer) + ) + ) + 0 + ) + +;; definition for function copy-alpha-texture-anim-layer-func +;; INFO: Used lq/sq +(defun copy-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (let ((s4-0 (/ (+ width 63) 64))) + (dma-buffer-add-gs-set dma-buf (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw s4-0 :fbp fbp-to-draw))) + (texture-anim-layer-add-shader dma-buf layer 1) + (let ((v1-7 (-> dma-buf base)) + (a2-6 #x8000) + (a3-1 #x8000) + (a0-10 (* (+ width 2048) 16)) + (a1-14 (* (+ height 2048) 16)) + ) + (set! (-> (the-as (pointer uint128) v1-7)) (-> *texture-anim-work* draw-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-7) 1) (-> *texture-anim-work* draw-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-7 32)) 128 128 128 (the int (* 128.0 (-> layer interpolated-color w)))) + (set-vector! (the-as vector (&+ v1-7 48)) 0.0 0.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ v1-7 64)) a2-6 a3-1 #xffffff 0) + (set-vector! (the-as vector (&+ v1-7 80)) 1.0 0.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ v1-7 96)) a0-10 a3-1 #xffffff 0) + (set-vector! (the-as vector (&+ v1-7 112)) 0.0 1.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ v1-7 128)) a2-6 a1-14 #xffffff 0) + (set-vector! (the-as vector (&+ v1-7 144)) 1.0 1.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ v1-7 160)) a0-10 a1-14 #xffffff 0) + ) + (&+! (-> dma-buf base) 176) + (let* ((v1-11 dma-buf) + (a0-12 (the-as dma-packet (-> v1-11 base))) + ) + (set! (-> a0-12 dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + (set! (-> a0-12 vif0) (new 'static 'vif-tag)) + (set! (-> a0-12 vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-11 base) (the-as pointer (&+ a0-12 16))) + ) + (let* ((v1-12 dma-buf) + (a0-14 (the-as object (-> v1-12 base))) + ) + (set! (-> (the-as gs-gif-tag a0-14) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a0-14) regs) GIF_REGS_ALL_AD) + (set! (-> v1-12 base) (&+ (the-as pointer a0-14) 16)) + ) + (let ((v1-13 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-frame) v1-13) 0) (new 'static 'gs-frame :fbw s4-0 :fbp fbp-to-draw)) + (set! (-> (the-as (pointer gs-reg64) v1-13) 1) (gs-reg64 frame-1)) + (set! (-> dma-buf base) (&+ v1-13 16)) + ) + ) + ) + 0 + ) + +;; definition for function copy-clut-alpha-texture-anim-layer-func +;; INFO: Used lq/sq +(defun copy-clut-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (when (and (>= time (-> layer start-time)) (>= (-> layer end-time) time)) + (texture-anim-layer-interp layer time) + (let ((s4-0 1)) + (dma-buffer-add-gs-set dma-buf (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw s4-0 :fbp fbp-to-draw))) + (texture-anim-layer-add-clut-shader dma-buf layer 1) + (let ((a1-13 (-> dma-buf base)) + (a2-6 #x8000) + (a3-1 #x8000) + (v1-6 #x8100) + (a0-9 #x8100) + ) + (set! (-> (the-as (pointer uint128) a1-13)) (-> *texture-anim-work* draw-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) a1-13) 1) (-> *texture-anim-work* draw-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ a1-13 32)) 128 128 128 (the int (* 128.0 (-> layer interpolated-color w)))) + (set-vector! (the-as vector (&+ a1-13 48)) 0.0 0.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ a1-13 64)) a2-6 a3-1 #xffffff 0) + (set-vector! (the-as vector (&+ a1-13 80)) 1.0 0.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ a1-13 96)) v1-6 a3-1 #xffffff 0) + (set-vector! (the-as vector (&+ a1-13 112)) 0.0 1.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ a1-13 128)) a2-6 a0-9 #xffffff 0) + (set-vector! (the-as vector (&+ a1-13 144)) 1.0 1.0 1.0 0.0) + (set-vector! (the-as vector4w (&+ a1-13 160)) v1-6 a0-9 #xffffff 0) + ) + (&+! (-> dma-buf base) 176) + (let* ((v1-10 dma-buf) + (a0-10 (the-as dma-packet (-> v1-10 base))) + ) + (set! (-> a0-10 dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + (set! (-> a0-10 vif0) (new 'static 'vif-tag)) + (set! (-> a0-10 vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-10 base) (the-as pointer (the-as dma-packet (&+ a0-10 16)))) + ) + (let* ((v1-11 dma-buf) + (a0-12 (the-as object (-> v1-11 base))) + ) + (set! (-> (the-as gs-gif-tag a0-12) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a0-12) regs) GIF_REGS_ALL_AD) + (set! (-> v1-11 base) (&+ (the-as pointer a0-12) 16)) + ) + (let ((v1-12 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-frame) v1-12) 0) (new 'static 'gs-frame :fbw s4-0 :fbp fbp-to-draw)) + (set! (-> (the-as (pointer gs-reg64) v1-12) 1) (gs-reg64 frame-1)) + (set! (-> dma-buf base) (&+ v1-12 16)) + ) + ) + ) + 0 + ) + +;; definition for function set-alpha-texture-anim-layer-func +;; INFO: Used lq/sq +;; WARN: Return type mismatch pointer vs int. +(defun set-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (let ((v1-1 (/ (+ width 63) 64))) + (dma-buffer-add-gs-set dma-buf + (test-1 (new 'static 'gs-test :ate #x1 :afail #x1 :zte #x1 :ztst (gs-ztest always))) + (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw v1-1 :fbp fbp-to-draw)) + ) + (let ((t0-4 (-> dma-buf base)) + (t2-12 2048) + (t1-7 2048) + (a2-1 (+ width 2048)) + (a3-1 (+ height 2048)) + ) + (set! (-> (the-as (pointer uint128) t0-4)) (-> *texture-anim-work* erase-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) t0-4) 1) (-> *texture-anim-work* erase-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ t0-4 32)) 0 0 0 128) + (set-vector! (the-as vector4w (&+ t0-4 48)) (* t2-12 16) (* t1-7 16) #xffffff 0) + (set-vector! (the-as vector4w (&+ t0-4 64)) (* a2-1 16) (* a3-1 16) #xffffff 0) + ) + (&+! (-> dma-buf base) 80) + (let* ((a2-7 dma-buf) + (a3-2 (the-as object (-> a2-7 base))) + ) + (set! (-> (the-as dma-packet a3-2) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a3-2) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a3-2) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a2-7 base) (&+ (the-as pointer a3-2) 16)) + ) + (let* ((a2-8 dma-buf) + (a3-4 (the-as object (-> a2-8 base))) + ) + (set! (-> (the-as gs-gif-tag a3-4) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a3-4) regs) GIF_REGS_ALL_AD) + (set! (-> a2-8 base) (&+ (the-as pointer a3-4) 16)) + ) + (let ((a2-9 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-frame) a2-9) 0) (new 'static 'gs-frame :fbw v1-1 :fbp fbp-to-draw)) + (set! (-> (the-as (pointer gs-reg64) a2-9) 1) (gs-reg64 frame-1)) + (let ((v0-0 (&+ a2-9 16))) + (set! (-> dma-buf base) v0-0) + (the-as int v0-0) + ) + ) + ) + ) + +;; definition for function set-clut-alpha-texture-anim-layer-func +;; INFO: Used lq/sq +;; WARN: Return type mismatch pointer vs int. +(defun set-clut-alpha-texture-anim-layer-func ((dma-buf dma-buffer) (fbp-to-draw uint) (width int) (height int) (layer texture-anim-layer) (time float)) + (let ((v1-0 1)) + (dma-buffer-add-gs-set dma-buf + (test-1 (new 'static 'gs-test :ate #x1 :afail #x1 :zte #x1 :ztst (gs-ztest always))) + (frame-1 (new 'static 'gs-frame :fbmsk #xffffff :fbw v1-0 :fbp fbp-to-draw)) + ) + (let ((t0-13 (-> dma-buf base)) + (t2-0 2048) + (t1-5 2048) + (a3-7 2064) + (a2-4 2064) + ) + (set! (-> (the-as (pointer uint128) t0-13)) (-> *texture-anim-work* erase-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) t0-13) 1) (-> *texture-anim-work* erase-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ t0-13 32)) 0 0 0 128) + (set-vector! (the-as vector4w (&+ t0-13 48)) (* t2-0 16) (* t1-5 16) #xffffff 0) + (set-vector! (the-as vector4w (&+ t0-13 64)) (* a3-7 16) (* a2-4 16) #xffffff 0) + ) + (&+! (-> dma-buf base) 80) + (let* ((a2-9 dma-buf) + (a3-9 (the-as object (-> a2-9 base))) + ) + (set! (-> (the-as dma-packet a3-9) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a3-9) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a3-9) vif1) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a2-9 base) (&+ (the-as pointer a3-9) 16)) + ) + (let* ((a2-10 dma-buf) + (a3-11 (the-as object (-> a2-10 base))) + ) + (set! (-> (the-as gs-gif-tag a3-11) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a3-11) regs) GIF_REGS_ALL_AD) + (set! (-> a2-10 base) (&+ (the-as pointer a3-11) 16)) + ) + (let ((a2-11 (-> dma-buf base))) + (set! (-> (the-as (pointer gs-frame) a2-11) 0) (new 'static 'gs-frame :fbw v1-0 :fbp fbp-to-draw)) + (set! (-> (the-as (pointer gs-reg64) a2-11) 1) (gs-reg64 frame-1)) + (let ((v0-0 (&+ a2-11 16))) + (set! (-> dma-buf base) v0-0) + (the-as int v0-0) + ) + ) + ) + ) + +;; definition for function dest-texture-init +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun dest-texture-init ((tex-anim texture-anim)) + (let ((dest-tex (new 'loading-level 'texture))) + (let ((size (the int (-> tex-anim extra x)))) + (let ((dest (the int (-> tex-anim extra y)))) + (set! (-> tex-anim tex) dest-tex) + (set! (-> dest-tex w) size) + (set! (-> dest-tex h) size) + (set! (-> dest-tex num-mips) (the-as uint 1)) + (set! (-> dest-tex psm) (gs-psm ct32)) + (set! (-> dest-tex dest 0) (the-as uint (* dest 32))) + ) + (set! (-> dest-tex width 0) (the-as uint (/ (+ size 63) 64))) + ) + (set! (-> dest-tex masks data 0 mask quad) (the-as uint128 0)) + (set! (-> dest-tex masks data 1 mask quad) (the-as uint128 0)) + (set! (-> dest-tex masks data 2 mask quad) (the-as uint128 0)) + ) + 0 + 0 + (none) + ) + +;; definition for function src-texture-init +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun src-texture-init ((layer texture-anim-layer)) + (let ((tex (new 'loading-level 'texture))) + (let ((size (the int (-> layer extra x)))) + (let ((addr (the int (-> layer extra y)))) + (set! (-> layer tex) tex) + (set! (-> tex w) size) + (set! (-> tex h) size) + (set! (-> tex num-mips) (the-as uint 1)) + (set! (-> tex psm) (gs-psm ct32)) + (set! (-> tex dest 0) (the-as uint (* addr 32))) + ) + (set! (-> tex width 0) (the-as uint (/ (+ size 63) 64))) + ) + (set! (-> tex masks data 0 mask quad) (the-as uint128 0)) + (set! (-> tex masks data 1 mask quad) (the-as uint128 0)) + (set! (-> tex masks data 2 mask quad) (the-as uint128 0)) + ) + 0 + 0 + (none) + ) + +;; definition for function src-texture-init-mt8 +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun src-texture-init-mt8 ((layer texture-anim-layer)) + (let ((tex (new 'loading-level 'texture))) + (let ((width (the int (-> layer extra x)))) + (let ((height (the int (-> layer extra y))) + (dest (the int (-> layer extra z))) + (clutdest (the int (-> layer extra w))) + ) + (set! (-> layer tex) tex) + (set! (-> tex w) width) + (set! (-> tex h) height) + (set! (-> tex num-mips) (the-as uint 1)) + (set! (-> tex psm) (gs-psm mt8)) + (set! (-> tex dest 0) (the-as uint (* dest 32))) + (set! (-> tex clutpsm) (the-as uint 0)) + (set! (-> tex clutdest) (the-as uint (* clutdest 32))) + ) + (set! (-> tex width 0) (the-as uint (/ (+ width 63) 64))) + ) + (set! (-> tex masks data 0 mask quad) (the-as uint128 0)) + (set! (-> tex masks data 1 mask quad) (the-as uint128 0)) + (set! (-> tex masks data 2 mask quad) (the-as uint128 0)) + ) + 0 + 0 + (none) + ) + +;; definition for function make-noise-texture +;; INFO: Used lq/sq +;; WARN: Return type mismatch uint vs none. +(defun make-noise-texture ((arg0 pointer) (arg1 int) (arg2 int) (arg3 int)) + (local-vars (t4-5 uint128) (t5-3 uint128)) + (let ((v1-0 (/ arg1 16)) + (a3-1 (/ arg3 16)) + ) + (when (< arg1 16) + (set! a3-1 1) + (set! v1-0 1) + (set! arg2 (/ (* arg2 arg1) 16)) + ) + (let* ((a1-5 *texture-anim-work*) + (v0-0 (-> a1-5 random-index)) + ) + (dotimes (t0-1 arg2) + (let ((t1-0 0)) + (goto cfg-6) + (until (>= t1-0 v1-0) + (let* ((t2-0 (* t0-1 a3-1)) + (t3-0 (+ v0-0 3)) + (t4-0 (+ v0-0 5)) + (t5-0 (+ v0-0 7)) + (t3-1 (logand t3-0 7)) + (t4-1 (logand t4-0 7)) + (t7-0 (logand t5-0 7)) + (t6-0 (* v0-0 16)) + (t5-1 (* t3-1 16)) + (t4-2 (* t4-1 16)) + (t3-2 (* t7-0 16)) + (t2-1 (+ t2-0 t1-0)) + (t6-1 (the-as object (+ t6-0 (the-as uint a1-5)))) + (t2-2 (* t2-1 16)) + (t7-1 (the-as object (+ t5-1 (the-as uint a1-5)))) + (t5-2 (-> (the-as (pointer uint128) t6-1) 15)) + (t4-3 (the-as object (+ t4-2 (the-as uint a1-5)))) + (t6-2 (-> (the-as (pointer uint128) t7-1) 15)) + (t3-3 (the-as object (+ t3-2 (the-as uint a1-5)))) + ) + (let ((t4-4 (-> (the-as (pointer uint128) t4-3) 15))) + (.paddb t5-3 t5-2 t6-2) + (nop!) + (.paddb t4-5 t5-3 t4-4) + ) + (nop!) + (let ((t2-3 (+ t2-2 (the-as int arg0)))) + (set! (-> (the-as (pointer uint128) t3-3) 15) t4-5) + (let ((t3-4 (+ v0-0 1))) + (set! (-> (the-as (pointer uint128) t2-3) 0) t4-5) + (set! v0-0 (logand t3-4 7)) + ) + ) + ) + (nop!) + (+! t1-0 1) + (label cfg-6) + ) + ) + ) + (set! (-> a1-5 random-index) v0-0) + ) + ) + (none) + ) + +;; definition for function make-cloud-clut +;; WARN: Return type mismatch symbol vs none. +(defun make-cloud-clut ((arg0 (pointer uint32)) (arg1 float) (arg2 float)) + (local-vars (v1-10 int)) + 0 + (let* ((s5-0 (the int (* 255.0 arg1))) + (s4-1 (max (the int (* 255.0 arg2)) s5-0)) + (f30-0 (/ 128.0 (the float (- s4-1 s5-0)))) + ) + (dotimes (s3-0 256) + (let ((s2-0 (-> *clut-translate* s3-0))) + (cond + ((and (>= s5-0 s3-0) (nonzero? s4-1)) + (set! v1-10 0) + ) + ((>= s3-0 s4-1) + (set! v1-10 128) + ) + (else + (let* ((f0-9 (sin (* 128.0 (fmin 128.0 (* (the float (- s3-0 s5-0)) f30-0))))) + (f0-11 (* f0-9 f0-9)) + ) + (set! v1-10 (the int (* 128.0 f0-11))) + ) + ) + ) + (set! (-> arg0 s2-0) (logior (logand (-> arg0 s2-0) -256) 128)) + (set! (-> arg0 s2-0) (logior (logand (-> arg0 s2-0) -65281) #x8000)) + (set! (-> arg0 s2-0) (logior (logand (-> arg0 s2-0) -16711681) #x800000)) + (set! (-> arg0 s2-0) + (logior (logand (-> arg0 s2-0) (the-as uint #xffffffff00ffffff)) (shr (shl v1-10 56) 32)) + ) + ) + ) + ) + (none) + ) + +;; definition for function texture-anim-cloud-clut-upload +;; WARN: Return type mismatch int vs none. +(defun texture-anim-cloud-clut-upload ((arg0 dma-buffer) (arg1 texture-anim)) + (when (-> arg1 tex) + (make-cloud-clut (the-as (pointer uint32) (-> arg1 tex pad 0)) (-> arg1 extra y) (-> arg1 extra z)) + (upload-vram-data arg0 (the-as int (-> arg1 tex clutdest)) (the-as pointer (-> arg1 tex pad 0)) 16 16) + (set! (-> *texture-pool* ids (shr (-> arg1 tex clutdest) 6)) (the-as uint 0)) + 0 + ) + (none) + ) + +;; definition for function texture-anim-cloud-clut-init +;; WARN: Return type mismatch int vs none. +(defun texture-anim-cloud-clut-init ((arg0 texture-anim)) + (let ((s5-0 (new 'loading-level 'texture)) + (s4-0 (the int (-> arg0 extra x))) + (v1-2 (new 'loading-level 'clut16x16)) + ) + (set! (-> arg0 tex) s5-0) + (set! (-> s5-0 clutdest) (the-as uint (* s4-0 32))) + (set! (-> s5-0 pad 0) (the-as uint v1-2)) + ) + 0 + (none) + ) + +;; definition for function make-slime-clut +;; WARN: Return type mismatch symbol vs none. +(defun make-slime-clut ((arg0 (pointer uint32))) + (dotimes (v1-0 256) + (let ((a1-2 (-> *clut-translate* v1-0)) + (a2-2 (-> *slime-clut* clut v1-0)) + ) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -256) (shr (shl (-> a2-2 r) 56) 56))) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -65281) (shr (shl (-> a2-2 g) 56) 48))) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -16711681) (shr (shl (-> a2-2 b) 56) 40))) + (set! (-> arg0 a1-2) + (logior (logand (-> arg0 a1-2) (the-as uint #xffffffff00ffffff)) (shr (shl (-> a2-2 a) 56) 32)) + ) + ) + ) + (none) + ) + +;; definition for function texture-anim-slime-clut-upload +;; WARN: Return type mismatch int vs none. +(defun texture-anim-slime-clut-upload ((arg0 dma-buffer) (arg1 texture-anim)) + (when (-> arg1 tex) + (make-slime-clut (the-as (pointer uint32) (-> arg1 tex pad 0))) + (upload-vram-data arg0 (the-as int (-> arg1 tex clutdest)) (the-as pointer (-> arg1 tex pad 0)) 16 16) + (set! (-> *texture-pool* ids (shr (-> arg1 tex clutdest) 6)) (the-as uint 0)) + 0 + ) + (none) + ) + +;; definition for function texture-anim-slime-clut-init +;; WARN: Return type mismatch int vs none. +(defun texture-anim-slime-clut-init ((arg0 texture-anim)) + (let ((s5-0 (new 'loading-level 'texture)) + (s4-0 (the int (-> arg0 extra x))) + (v1-2 (new 'loading-level 'clut16x16)) + ) + (set! (-> arg0 tex) s5-0) + (set! (-> s5-0 clutdest) (the-as uint (* s4-0 32))) + (set! (-> s5-0 pad 0) (the-as uint v1-2)) + ) + 0 + (none) + ) + +;; definition for function make-ramp-clut +;; WARN: Return type mismatch symbol vs none. +(defun make-ramp-clut ((arg0 (pointer uint32)) (arg1 pointer) (arg2 object)) + (dotimes (v1-0 256) + (let ((a1-3 (-> *clut-translate* v1-0))) + (set! (-> arg0 a1-3) (logior (logand (-> arg0 a1-3) -256) (shr (shl v1-0 56) 56))) + (set! (-> arg0 a1-3) (logior (logand (-> arg0 a1-3) -65281) (shr (shl v1-0 56) 48))) + (set! (-> arg0 a1-3) (logior (logand (-> arg0 a1-3) -16711681) (shr (shl v1-0 56) 40))) + (set! (-> arg0 a1-3) (logior (logand (-> arg0 a1-3) (the-as uint #xffffffff00ffffff)) (shr (shl v1-0 56) 32))) + ) + ) + (none) + ) + +;; definition for function make-alpha-ramp-clut +;; WARN: Return type mismatch symbol vs none. +(defun make-alpha-ramp-clut ((arg0 (pointer uint32))) + (dotimes (v1-0 256) + (let ((a1-2 (-> *clut-translate* v1-0))) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -256) 128)) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -65281) #x8000)) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) -16711681) #x800000)) + (set! (-> arg0 a1-2) (logior (logand (-> arg0 a1-2) (the-as uint #xffffffff00ffffff)) (shr (shl v1-0 56) 32))) + ) + ) + (none) + ) + +;; definition for function noise-texture-init +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun noise-texture-init ((arg0 texture-anim-layer)) + (let ((gp-0 (the int (-> arg0 extra x))) + (s4-0 (the-as structure #f)) + ) + (case gp-0 + ((8) + (set! s4-0 (new 'loading-level 'noise8x8)) + ) + ((16) + (set! s4-0 (new 'loading-level 'noise16x16)) + ) + ((32) + (set! s4-0 (new 'loading-level 'noise32x32)) + ) + ((64) + (set! s4-0 (new 'loading-level 'noise64x64)) + ) + ((128) + (set! s4-0 (new 'loading-level 'noise128x128)) + ) + ) + (when s4-0 + (let ((v1-14 (new 'loading-level 'texture))) + (let ((a0-16 (the int (-> arg0 extra y))) + (a1-6 (the int (-> arg0 extra z))) + ) + (set! (-> arg0 tex) v1-14) + (set! (-> v1-14 pad 0) (the-as uint s4-0)) + (set! (-> v1-14 w) gp-0) + (set! (-> v1-14 h) gp-0) + (set! (-> v1-14 num-mips) (the-as uint 1)) + (set! (-> v1-14 psm) (gs-psm mt8)) + (set! (-> v1-14 clutpsm) (the-as uint 0)) + (set! (-> v1-14 dest 0) (the-as uint (* a0-16 32))) + (set! (-> v1-14 clutdest) (the-as uint (* a1-6 32))) + ) + (set! (-> v1-14 width 0) (the-as uint 1)) + (set! (-> v1-14 masks data 0 mask quad) (the-as uint128 0)) + (set! (-> v1-14 masks data 1 mask quad) (the-as uint128 0)) + (set! (-> v1-14 masks data 2 mask quad) (the-as uint128 0)) + (make-noise-texture (the-as pointer (-> v1-14 pad 0)) gp-0 gp-0 gp-0) + ) + ) + ) + 0 + (none) + ) + +;; definition for function texture-anim-alpha-ramp-clut-upload +;; WARN: Return type mismatch int vs none. +(defun texture-anim-alpha-ramp-clut-upload ((arg0 dma-buffer) (arg1 texture-anim)) + (when (-> arg1 tex) + (upload-vram-data arg0 (the-as int (-> arg1 tex clutdest)) (the-as pointer (-> arg1 tex pad 0)) 16 16) + (set! (-> *texture-pool* ids (shr (-> arg1 tex clutdest) 6)) (the-as uint 0)) + 0 + ) + (none) + ) + +;; definition for function texture-anim-alpha-ramp-clut-init +;; WARN: Return type mismatch int vs none. +(defun texture-anim-alpha-ramp-clut-init ((arg0 texture-anim)) + (let ((s5-0 (new 'loading-level 'texture)) + (s4-0 (the int (-> arg0 extra x))) + (a0-3 (new 'loading-level 'clut16x16)) + ) + (set! (-> arg0 tex) s5-0) + (set! (-> s5-0 clutdest) (the-as uint (* s4-0 32))) + (set! (-> s5-0 pad 0) (the-as uint a0-3)) + (make-alpha-ramp-clut (the-as (pointer uint32) a0-3)) + ) + 0 + (none) + ) + +;; definition for function texture-anim-overide-size-init +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun texture-anim-overide-size-init ((arg0 texture-anim)) + (when (-> arg0 tex-name) + (let ((v1-2 (lookup-level-texture-by-name + (-> arg0 tex-name) + (-> *level* loading-level) + (the-as (pointer texture-page) #f) + ) + ) + ) + (when v1-2 + (let ((a0-2 (the int (-> arg0 extra x)))) + (let ((a1-1 (the int (-> arg0 extra y)))) + (set! (-> v1-2 w) a0-2) + (set! (-> v1-2 h) a1-1) + ) + (set! (-> v1-2 dest 0) (the-as uint 1)) + (set! (-> v1-2 width 0) (the-as uint (/ a0-2 64))) + ) + (set! (-> v1-2 masks data 0 mask quad) (the-as uint128 0)) + (set! (-> v1-2 masks data 1 mask quad) (the-as uint128 0)) + (set! (-> v1-2 masks data 2 mask quad) (the-as uint128 0)) + 0 + ) + ) + ) + (none) + ) + +;; definition for function texture-anim-change-mt8h-init +;; INFO: Used lq/sq +;; WARN: Return type mismatch int vs none. +(defun texture-anim-change-mt8h-init ((arg0 texture-anim)) + (when (-> arg0 tex-name) + (let ((v1-2 (lookup-level-texture-by-name + (-> arg0 tex-name) + (-> *level* loading-level) + (the-as (pointer texture-page) #f) + ) + ) + ) + (when v1-2 + (let ((a0-2 (the int (-> arg0 extra x))) + (a1-1 (the int (-> arg0 extra y))) + (a2-1 (the int (-> arg0 extra z))) + ) + (let ((a3-0 (the int (-> arg0 extra w)))) + (set! (-> v1-2 clutdest) (the-as uint (* a0-2 32))) + (set! (-> v1-2 clutpsm) (the-as uint 0)) + (set! (-> v1-2 dest 0) (the-as uint (* a1-1 32))) + (set! (-> v1-2 psm) (gs-psm mt8h)) + (set! (-> v1-2 w) a2-1) + (set! (-> v1-2 h) a3-0) + ) + (set! (-> v1-2 width 0) (the-as uint (/ a2-1 64))) + ) + (set! (-> v1-2 masks data 0 mask quad) (the-as uint128 0)) + (set! (-> v1-2 masks data 1 mask quad) (the-as uint128 0)) + (set! (-> v1-2 masks data 2 mask quad) (the-as uint128 0)) + 0 + ) + ) + ) + (none) + ) + +;; definition for method 9 of type texture-anim-array +(defmethod init! texture-anim-array ((obj texture-anim-array)) + (dotimes (s5-0 (-> obj length)) + (init-textures! (-> obj array-data s5-0)) + ) + obj + ) + +;; definition for method 10 of type texture-anim-array +(defmethod clear! texture-anim-array ((obj texture-anim-array)) + (dotimes (s5-0 (-> obj length)) + (clear-textures! (-> obj array-data s5-0)) + ) + obj + ) + +;; definition for method 9 of type texture-anim +;; INFO: Used lq/sq +(defmethod init-textures! texture-anim ((obj texture-anim)) + (local-vars (a3-3 uint128) (sv-16 texture-page)) + (if (logtest? (the-as int (-> obj func)) 1) + (set! (-> obj func) (the-as (function dma-buffer texture-anim int) (-> (the-as symbol (-> obj func)) value))) + ) + (when (logtest? (the-as int (-> obj init-func)) 1) + (set! (-> obj init-func) (the-as (function texture-anim int) (-> (the-as symbol (-> obj init-func)) value))) + (if (-> obj init-func) + ((-> obj init-func) obj) + ) + ) + (when (-> obj tex-name) + (set! sv-16 (the-as texture-page #f)) + (let ((a0-3 (lookup-level-texture-by-name (-> obj tex-name) (-> *level* loading-level) (& sv-16)))) + (set! (-> obj tex) a0-3) + (when (and a0-3 sv-16) + 0 + (cond + ((= (-> a0-3 psm) (gs-psm mt8)) + (let ((v1-20 (-> a0-3 clutdest))) + (when (!= v1-20 (* (/ (the-as int v1-20) 32) 32)) + (let* ((v1-22 (-> sv-16 segment 2)) + (a1-5 (+ (-> v1-22 dest) (-> v1-22 size))) + (a0-7 2048) + ) + (set! (-> obj tex clutdest) (* (shr (+ a1-5 2047) 11) 32)) + (+! (-> sv-16 size) a0-7) + (+! (-> v1-22 size) a0-7) + ) + ) + ) + ) + ((= (-> a0-3 psm) (gs-psm ct32)) + (let ((v1-24 (-> a0-3 dest 0))) + (when (!= v1-24 (* (/ (the-as int v1-24) 32) 32)) + (let* ((v1-26 (-> sv-16 segment 2)) + (a1-19 (+ (-> v1-26 dest) (-> v1-26 size))) + (a0-12 (shl (sar (+ (* (-> a0-3 w) (-> a0-3 h)) 2047) 11) 11)) + ) + (set! (-> obj tex dest 0) (* (shr (+ a1-19 2047) 11) 32)) + (+! (-> sv-16 size) a0-12) + (+! (-> v1-26 size) a0-12) + ) + ) + ) + ) + ) + ) + ) + ) + (dotimes (s5-0 (the-as int (-> obj num-layers))) + (initialize-texture! (-> obj data s5-0)) + ) + (let ((v1-34 (-> obj tex))) + (when v1-34 + (dotimes (a0-15 3) + (set! (-> v1-34 masks data a0-15 mask quad) (the-as uint128 0)) + ) + (dotimes (a0-18 (the-as int (-> obj num-layers))) + (let ((a1-33 (-> obj data a0-18 tex))) + (when a1-33 + (dotimes (a2-8 3) + (let ((a3-2 (-> v1-34 masks data a2-8 mask quad)) + (t0-2 (-> a1-33 masks data a2-8 mask quad)) + ) + (.por a3-3 a3-2 t0-2) + ) + (set! (-> v1-34 masks data a2-8 mask quad) a3-3) + ) + ) + ) + ) + ) + ) + obj + ) + +;; definition for method 10 of type texture-anim +(defmethod clear-textures! texture-anim ((obj texture-anim)) + (set! (-> obj tex) #f) + (dotimes (s5-0 (the-as int (-> obj num-layers))) + (clear-texture! (-> obj data s5-0)) + ) + obj + ) + +;; definition for method 9 of type texture-anim-layer +(defmethod initialize-texture! texture-anim-layer ((obj texture-anim-layer)) + (if (logtest? (the-as int (-> obj func)) 1) + (set! (-> obj func) (the-as + (function dma-buffer uint int int texture-anim-layer float int) + (-> (the-as symbol (-> obj func)) value) + ) + ) + ) + (when (logtest? (the-as int (-> obj init-func)) 1) + (set! (-> obj init-func) + (the-as (function texture-anim-layer int) (-> (the-as symbol (-> obj init-func)) value)) + ) + (if (-> obj init-func) + ((-> obj init-func) obj) + ) + ) + (if (-> obj tex-name) + (set! (-> obj tex) + (lookup-level-texture-by-name (-> obj tex-name) (-> *level* loading-level) (the-as (pointer texture-page) #f)) + ) + ) + obj + ) + +;; definition for method 10 of type texture-anim-layer +(defmethod clear-texture! texture-anim-layer ((obj texture-anim-layer)) + (set! (-> obj tex) #f) + obj + ) + + + + diff --git a/test/decompiler/reference/jak2/engine/gfx/texture/texture-finish_REF.gc b/test/decompiler/reference/jak2/engine/gfx/texture/texture-finish_REF.gc index 1c5ea555df..3a1f6bdd9a 100644 --- a/test/decompiler/reference/jak2/engine/gfx/texture/texture-finish_REF.gc +++ b/test/decompiler/reference/jak2/engine/gfx/texture/texture-finish_REF.gc @@ -1,7 +1,10 @@ +;;-*-Lisp-*- (in-package goal) +;; failed to figure out what this is: (setup-font-texture *texture-pool*) +;; failed to figure out what this is: (let ((v1-2 (lookup-texture-by-id (new 'static 'texture-id :index #x4 :page #x70c)))) (when v1-2 (set! (-> v1-2 w) 32) @@ -10,12 +13,17 @@ ) ) -(texture-anim-array-method-9 *sky-texture-anim-array*) +;; failed to figure out what this is: +(init! *sky-texture-anim-array*) -(texture-anim-array-method-9 *darkjak-texture-anim-array*) +;; failed to figure out what this is: +(init! *darkjak-texture-anim-array*) -(texture-anim-array-method-9 *skull-gem-texture-anim-array*) +;; failed to figure out what this is: +(init! *skull-gem-texture-anim-array*) -(texture-anim-array-method-9 *bomb-texture-anim-array*) +;; failed to figure out what this is: +(init! *bomb-texture-anim-array*) +;; failed to figure out what this is: (kmemclose) diff --git a/test/decompiler/reference/jak2/engine/gfx/texture/texture_REF.gc b/test/decompiler/reference/jak2/engine/gfx/texture/texture_REF.gc index 66b869f808..eb1c6fbe33 100644 --- a/test/decompiler/reference/jak2/engine/gfx/texture/texture_REF.gc +++ b/test/decompiler/reference/jak2/engine/gfx/texture/texture_REF.gc @@ -682,7 +682,6 @@ ;; definition for function upload-vram-data ;; WARN: Return type mismatch symbol vs none. -;; ERROR: Failed store: (s.w! (+ a0-1 8) 0) at op 13 (defun upload-vram-data ((buf dma-buffer) (dest int) (data pointer) (height int) (width int)) (while (> height 0) (let ((height-this-time (min 2048 height))) @@ -702,7 +701,6 @@ ) ;; definition for function upload-vram-pages -;; ERROR: Failed store: (s.w! (+ a0-24 8) 0) at op 143 (defun upload-vram-pages ((pool texture-pool) (dest-seg texture-pool-segment) (tpage texture-page) @@ -848,7 +846,6 @@ ) ;; definition for function upload-vram-pages-pris -;; ERROR: Failed store: (s.w! (+ a0-27 8) 0) at op 137 (defun upload-vram-pages-pris ((pool texture-pool) (dest-seg texture-pool-segment) (tpage texture-page) @@ -1251,9 +1248,11 @@ (dotimes (s2-1 7) (let ((v1-54 (-> *level* level s2-1))) (when (or (= (-> v1-54 status) 'active) (= (-> v1-54 status) 'reserved)) - (if (-> v1-54 texture-anim-array 5) - (update-texture-anim bucket) - ) + (let ((a1-26 (-> v1-54 texture-anim-array 5))) + (if a1-26 + (update-texture-anim bucket a1-26) + ) + ) ) ) ) @@ -1265,21 +1264,21 @@ (let ((f30-0 (-> pp clock seconds-per-frame))) (set! (-> pp clock seconds-per-frame) (* 10.0 (-> pp clock seconds-per-frame))) (if s2-0 - (update-texture-anim bucket) + (update-texture-anim bucket s2-0) ) (set! (-> pp clock seconds-per-frame) f30-0) ) ) (else (if s2-0 - (update-texture-anim bucket) + (update-texture-anim bucket s2-0) ) ) ) ) (else (if s2-0 - (update-texture-anim bucket) + (update-texture-anim bucket s2-0) ) ) ) @@ -1409,7 +1408,6 @@ ;; definition for method 13 of type texture-page ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-1 8) 0) at op 19 (defmethod upload-now! texture-page ((obj texture-page) (arg0 tex-upload-mode)) (let ((gp-0 *txt-dma-list*)) (let ((v1-0 gp-0)) @@ -1462,7 +1460,6 @@ ) ;; definition for function texture-relocate -;; ERROR: Failed store: (s.w! (+ t4-0 8) 0) at op 18 (defun texture-relocate ((dma-buff dma-buffer) (tex texture) (dest-loc int) (dest-fmt gs-psm) (clut-dst int)) (dotimes (v1-0 (the-as int (-> tex num-mips))) (let ((t1-1 (ash (-> tex w) (- v1-0))) @@ -1551,7 +1548,6 @@ ;; WARN: Stack slot offset 16 signed mismatch ;; WARN: Stack slot offset 16 signed mismatch ;; WARN: Return type mismatch int vs none. -;; ERROR: Failed store: (s.w! (+ a0-26 8) 0) at op 192 (defmethod setup-font-texture texture-pool ((obj texture-pool)) (local-vars (sv-16 int) (sv-20 int)) (let ((s3-0 (-> obj font-palette))) @@ -2270,7 +2266,3 @@ ;; definition for symbol *texture-pool*, type texture-pool (define *texture-pool* (new 'global 'texture-pool)) - - - - diff --git a/test/decompiler/reference/jak2/engine/level/level_REF.gc b/test/decompiler/reference/jak2/engine/level/level_REF.gc index a625d8b1d8..46681b4bac 100644 --- a/test/decompiler/reference/jak2/engine/level/level_REF.gc +++ b/test/decompiler/reference/jak2/engine/level/level_REF.gc @@ -792,9 +792,7 @@ (dotimes (s4-0 10) (let ((a0-8 (-> obj info texture-anim s4-0))) (if a0-8 - (set! (-> obj texture-anim-array s4-0) - (texture-anim-array-method-9 (the-as texture-anim-array (-> a0-8 value))) - ) + (set! (-> obj texture-anim-array s4-0) (init! (the-as texture-anim-array (-> a0-8 value)))) ) ) ) @@ -1278,9 +1276,7 @@ (dotimes (s5-3 10) (let ((a0-37 (-> obj info texture-anim s5-3))) (if a0-37 - (set! (-> obj texture-anim-array s5-3) - (texture-anim-array-method-10 (the-as texture-anim-array (-> a0-37 value))) - ) + (set! (-> obj texture-anim-array s5-3) (clear! (the-as texture-anim-array (-> a0-37 value)))) ) ) ) diff --git a/test/goalc/source_templates/with_game/test-pextlw.gc b/test/goalc/source_templates/with_game/test-pextlw.gc index 5a5e095275..4c477298b5 100644 --- a/test/goalc/source_templates/with_game/test-pextlw.gc +++ b/test/goalc/source_templates/with_game/test-pextlw.gc @@ -74,3 +74,21 @@ ) ) ) + + +(let ((s1 (new 'static 'array uint8 16 + 1 2 3 4 0 0 0 0 8 8 8 8 240 240 241 243 9 8 7 6)) + (s2 (new 'static 'array uint8 16 + 7 8 3 4 1 2 3 4 9 8 7 6 240 240 241 243 9 8 1 2)) + (s3 (new 'static 'array uint8 16))) + (let ((v1 (-> (the (pointer uint128) s1))) + (v2 (-> (the (pointer uint128) s2))) + (v3 (the uint128 0))) + (.paddb v3 v2 v1) + (set! (-> (the (pointer uint128) s3)) v3) + (dotimes (i 16) + (format #t "~X + ~X = ~X (~X)~%" (-> s1 i) (-> s2 i) (-> s3 i) (logand #xff (+ (-> s1 i) (-> s2 i)))) + ) + 0 + ) + ) diff --git a/test/goalc/test_with_game.cpp b/test/goalc/test_with_game.cpp index afd99dbc47..8611800d7b 100644 --- a/test/goalc/test_with_game.cpp +++ b/test/goalc/test_with_game.cpp @@ -648,16 +648,20 @@ TEST_F(WithGameTests, I128Simple) { // TODO - add tests TEST_F(WithGameTests, Pextlw) { - shared_compiler->runner.run_static_test(testCategory, "test-pextlw.gc", - {"#x07060504171615140302010013121110\n" - "#x0f0e0d0c1f1e1d1c0b0a09081b1a1918\n" - "#x07060504030201001716151413121110\n" - "#x1f1e1d1c1b1a19180f0e0d0c0b0a0908\n" - "#x0d0c0908050401001d1c191815141110\n" - "#x0e0c0a08060402001e1c1a1816141210\n" - "#xffffffff00000000ffffffff00000000\n" - "#x00090000000000fefffffffe000002ff\n" - "0\n"}); + shared_compiler->runner.run_static_test( + testCategory, "test-pextlw.gc", + {"#x07060504171615140302010013121110\n" + "#x0f0e0d0c1f1e1d1c0b0a09081b1a1918\n" + "#x07060504030201001716151413121110\n" + "#x1f1e1d1c1b1a19180f0e0d0c0b0a0908\n" + "#x0d0c0908050401001d1c191815141110\n" + "#x0e0c0a08060402001e1c1a1816141210\n" + "#xffffffff00000000ffffffff00000000\n" + "#x00090000000000fefffffffe000002ff\n" + "1 + 7 = 8 (8)\n2 + 8 = a (a)\n3 + 3 = 6 (6)\n4 + 4 = 8 (8)\n0 + 1 = 1 (1)\n0 + 2 = 2 " + "(2)\n0 + 3 = 3 (3)\n0 + 4 = 4 (4)\n8 + 9 = 11 (11)\n8 + 8 = 10 (10)\n8 + 7 = f (f)\n8 + 6 " + "= e (e)\nf0 + f0 = e0 (e0)\nf0 + f0 = e0 (e0)\nf1 + f1 = e2 (e2)\nf3 + f3 = e6 (e6)\n" + "0\n"}); } TEST_F(WithGameTests, Matrix) { diff --git a/test/test_emitter_avx.cpp b/test/test_emitter_avx.cpp index c71595f5ea..393ce9ed05 100644 --- a/test/test_emitter_avx.cpp +++ b/test/test_emitter_avx.cpp @@ -673,6 +673,21 @@ TEST(EmitterAVX, VPOR) { "C5E1EBDBC4C161EBDDC591EBDBC4C111EBDDC561EBEBC44161EBEDC511EBEBC44111EBED"); } +TEST(EmitterAVX, VPADDB) { + CodeTester tester; + tester.init_code_buffer(1024); + tester.emit(IGen::parallel_add_byte(XMM0 + 3, XMM0 + 3, XMM0 + 3)); + tester.emit(IGen::parallel_add_byte(XMM0 + 3, XMM0 + 3, XMM0 + 13)); + tester.emit(IGen::parallel_add_byte(XMM0 + 3, XMM0 + 13, XMM0 + 3)); + tester.emit(IGen::parallel_add_byte(XMM0 + 3, XMM0 + 13, XMM0 + 13)); + tester.emit(IGen::parallel_add_byte(XMM0 + 13, XMM0 + 3, XMM0 + 3)); + tester.emit(IGen::parallel_add_byte(XMM0 + 13, XMM0 + 3, XMM0 + 13)); + tester.emit(IGen::parallel_add_byte(XMM0 + 13, XMM0 + 13, XMM0 + 3)); + tester.emit(IGen::parallel_add_byte(XMM0 + 13, XMM0 + 13, XMM0 + 13)); + EXPECT_EQ(tester.dump_to_hex_string(true), + "C5E1FCDBC4C161FCDDC591FCDBC4C111FCDDC561FCEBC44161FCEDC511FCEBC44111FCED"); +} + TEST(EmitterAVX, VPXOR) { CodeTester tester; tester.init_code_buffer(1024);