diff --git a/decompiler/config/jak3/all-types.gc b/decompiler/config/jak3/all-types.gc index 815e6af79..cf71d777b 100644 --- a/decompiler/config/jak3/all-types.gc +++ b/decompiler/config/jak3/all-types.gc @@ -30849,7 +30849,6 @@ ;; shadow-cpu ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype shadow-stats (structure) ((num-single-tris uint32 :offset-assert 0) (num-double-tris uint32 :offset-assert 4) @@ -30862,9 +30861,7 @@ :size-assert #x14 :flag-assert #x900000014 ) -|# -#| (deftype shadow-dcache (structure) ((vtx-table uint32 :offset-assert 0) (single-edge-table uint32 :offset-assert 4) @@ -30892,40 +30889,38 @@ :size-assert #xb0 :flag-assert #x9000000b0 ) -|# -;; (define-extern *shadow-data* object) ;; shadow-data -;; (define-extern shadow-invert-z-buf function) ;; (function dma-buffer none) -;; (define-extern shadow-make-invert-buf function) ;; (function none) -;; (define-extern *shadow-dma-invert-call* object) ;; pointer -;; (define-extern shadow-dma-init function) ;; (function dma-buffer none) -;; (define-extern shadow-dma-end function) ;; (function dma-buffer gs-rgbaq symbol int none) -;; (define-extern shadow-vu0-block object) ;; vu-function -;; (define-extern shadow-xform-verts function) ;; function -;; (define-extern shadow-calc-dual-verts function) ;; function -;; (define-extern shadow-scissor-edges function) ;; function -;; (define-extern shadow-scissor-top function) ;; function -;; (define-extern shadow-init-vars function) ;; function -;; (define-extern shadow-find-facing-single-tris function) ;; function -;; (define-extern shadow-find-single-edges function) ;; function -;; (define-extern shadow-find-facing-double-tris function) ;; function -;; (define-extern shadow-find-double-edges function) ;; function -;; (define-extern shadow-add-verts function) ;; function -;; (define-extern shadow-add-facing-single-tris function) ;; function -;; (define-extern shadow-add-single-edges function) ;; function -;; (define-extern shadow-add-single-tris function) ;; function -;; (define-extern shadow-add-double-tris function) ;; function -;; (define-extern shadow-add-double-edges function) ;; function -;; (define-extern debug-draw-settings function) ;; (function shadow-settings symbol) -;; (define-extern shadow-execute function) ;; (function shadow-dma-packet pointer pointer) -;; (define-extern shadow-vu0-upload function) ;; (function none) +(define-extern *shadow-data* shadow-data) +(define-extern shadow-invert-z-buf (function dma-buffer none)) +(define-extern shadow-make-invert-buf (function none)) +(define-extern *shadow-dma-invert-call* pointer) +(define-extern shadow-dma-init (function dma-buffer none)) +(define-extern shadow-dma-end (function dma-buffer gs-rgbaq symbol int none)) +(define-extern shadow-vu0-block vu-function) +(define-extern shadow-xform-verts function) +(define-extern shadow-calc-dual-verts function) +(define-extern shadow-scissor-edges function) +(define-extern shadow-scissor-top function) +(define-extern shadow-init-vars function) +(define-extern shadow-find-facing-single-tris function) +(define-extern shadow-find-single-edges function) +(define-extern shadow-find-facing-double-tris function) +(define-extern shadow-find-double-edges function) +(define-extern shadow-add-verts function) +(define-extern shadow-add-facing-single-tris function) +(define-extern shadow-add-single-edges function) +(define-extern shadow-add-single-tris function) +(define-extern shadow-add-double-tris function) +(define-extern shadow-add-double-edges function) +(define-extern debug-draw-settings (function shadow-settings symbol)) +(define-extern shadow-execute (function shadow-dma-packet pointer pointer)) +(define-extern shadow-vu0-upload (function none)) (define-extern shadow-execute-all (function dma-buffer none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; shadow-vu1 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -#| (deftype shadow-vu1-constants (structure) ((hmgescale vector :inline :offset-assert 0) (invhscale vector :inline :offset-assert 16) @@ -30933,7 +30928,7 @@ (texscale vector :inline :offset-assert 48) (hvdfoff vector :inline :offset-assert 64) (fog vector :inline :offset-assert 80) - (clrs vector 2 :offset-assert 96) ;; guessed by decompiler + (clrs vector 2 :inline :offset-assert 96) ;; guessed by decompiler (adgif gs-gif-tag :inline :offset-assert 128) (texflush gs-adcmd :inline :offset-assert 144) (flush gs-adcmd :inline :offset-assert 160) @@ -30944,9 +30939,7 @@ :size-assert #xd0 :flag-assert #x9000000d0 ) -|# -#| (deftype shadow-vu1-data (structure) ((adgif gs-gif-tag :inline :offset-assert 0) (ad gs-adcmd :inline :offset-assert 16) @@ -30955,20 +30948,19 @@ (quadgif gs-gif-tag :inline :offset-assert 64) (texoffset vector :inline :offset-assert 80) (texscale vector :inline :offset-assert 96) - (clrs qword 2 :offset-assert 112) ;; guessed by decompiler + (clrs qword 2 :inline :offset-assert 112) ;; guessed by decompiler ) :method-count-assert 9 :size-assert #x90 :flag-assert #x900000090 ) -|# -;; (define-extern *shadow-vu1-data* object) ;; shadow-vu1-data -;; (define-extern shadow-vu1-block object) ;; vu-function -;; (define-extern shadow-vu1-add-constants function) ;; (function dma-buffer int none) -;; (define-extern shadow-vu1-patch-consts function) ;; (function symbol int none) -;; (define-extern shadow-vu1-add-matrix function) ;; (function dma-buffer math-camera none) -;; (define-extern shadow-vu1-init-buffer function) ;; (function dma-buffer int none) +(define-extern *shadow-vu1-data* shadow-vu1-data) +(define-extern shadow-vu1-block vu-function) +(define-extern shadow-vu1-add-constants (function dma-buffer int none)) +(define-extern shadow-vu1-patch-consts (function symbol int none)) +(define-extern shadow-vu1-add-matrix (function dma-buffer math-camera none)) +(define-extern shadow-vu1-init-buffer (function dma-buffer int none)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; warp ;; diff --git a/decompiler/config/jak3/ntsc_v1/hacks.jsonc b/decompiler/config/jak3/ntsc_v1/hacks.jsonc index 1a37dbec9..9707fcb79 100644 --- a/decompiler/config/jak3/ntsc_v1/hacks.jsonc +++ b/decompiler/config/jak3/ntsc_v1/hacks.jsonc @@ -78,10 +78,6 @@ "blerc-execute", "foreground-check-longest-edge-asm", "generic-light-proc", - "shadow-add-single-edges", - "shadow-add-facing-single-tris", - "shadow-add-double-tris", - "shadow-add-double-edges", "(method 17 collide-edge-work)", "(method 10 collide-cache-prim)", "(method 17 collide-cache)", @@ -715,7 +711,23 @@ "live-func-curve", "birth-func-curve", "sparticle-motion-blur-dirt", - "foreground-draw-hud" + "foreground-draw-hud", + "shadow-execute", + "shadow-add-double-edges", + "shadow-add-single-edges", + "shadow-add-facing-single-tris", + "shadow-add-double-tris", + "shadow-xform-verts", + "shadow-calc-dual-verts", + "shadow-scissor-edges", + "shadow-scissor-top", + "shadow-init-vars", + "shadow-find-facing-single-tris", + "shadow-find-single-edges", + "shadow-find-facing-double-tris", + "shadow-find-double-edges", + "shadow-add-verts", + "shadow-add-single-tris" ], "mips2c_jump_table_functions": {}, diff --git a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc index 937dbecca..9a65fdbee 100644 --- a/decompiler/config/jak3/ntsc_v1/type_casts.jsonc +++ b/decompiler/config/jak3/ntsc_v1/type_casts.jsonc @@ -11138,6 +11138,132 @@ [11, "v1", "symbol"], ["_stack_", 16, "texture-page"] ], + "shadow-vu1-init-buffer": [[[18, 27], "a0", "dma-packet"]], + "shadow-vu1-add-constants": [ + [[7, 16], "a2", "dma-packet"], + [[20, 66], "v1", "shadow-vu1-constants"], + [[72, 77], "a1", "dma-packet"], + [[82, 94], "a1", "shadow-vu1-data"] + ], + "shadow-vu1-add-matrix": [ + [[11, 19], "a3", "dma-packet"], + [[26, 30], "v1", "matrix"] + ], + "shadow-vu0-upload": [[[16, 18], "a0", "dma-packet"]], + "shadow-make-invert-buf": [[[13, 16], "v1", "dma-packet"]], + "shadow-invert-z-buf": [ + [[4, 8], "a2", "dma-packet"], + [[13, 16], "a2", "gs-gif-tag"], + [27, "t1", "(pointer gs-reg)"], + [28, "t1", "(pointer gs-reg64)"], + [30, "t1", "(pointer gs-reg)"], + [32, "t1", "(pointer gs-frame)"], + [34, "t1", "(pointer gs-reg)"], + [38, "t1", "(pointer gs-reg)"], + [42, "t1", "(pointer gs-reg)"], + [36, "t1", "(pointer gs-zbuf)"], + [40, "t1", "(pointer gs-test)"], + [44, "t1", "(pointer gs-alpha)"], + [45, "t1", "(pointer gs-reg)"], + [47, "t1", "(pointer gs-reg64)"], + [49, "t1", "(pointer gs-reg)"], + [51, "t1", "(pointer gs-rgbaq)"], + [[61, 64], "t2", "gs-gif-tag"], + [89, "t4", "(pointer gs-xyzf)"], + [79, "t4", "(pointer gs-xyzf)"], + [[106, 117], "v1", "(pointer uint64)"] + ], + "shadow-dma-init": [ + [[18, 21], "t4", "dma-packet"], + [[27, 31], "t6", "dma-packet"], + [[36, 39], "t6", "gs-gif-tag"], + [43, "t4", "(pointer gs-reg64)"], + [47, "t4", "(pointer gs-test)"], + [45, "t4", "(pointer gs-reg64)"], + [49, "t4", "(pointer gs-reg64)"], + [51, "t4", "(pointer gs-alpha)"], + [53, "t4", "(pointer gs-reg64)"], + [58, "t4", "(pointer gs-frame)"], + [60, "t4", "(pointer gs-reg64)"], + [64, "t4", "(pointer gs-reg64)"], + [73, "t4", "(pointer gs-reg64)"], + [81, "t4", "(pointer gs-reg)"], + [84, "t4", "(pointer gs-reg)"], + [62, "t4", "(pointer gs-zbuf)"], + [71, "t4", "(pointer gs-xy-offset)"], + [79, "t4", "(pointer gs-tex0)"], + [82, "t4", "(pointer gs-tex1)"], + [85, "t4", "(pointer gs-miptbp)"], + [87, "t4", "(pointer gs-reg)"], + [96, "t4", "(pointer gs-clamp)"], + [[103, 106], "t3", "gs-gif-tag"], + [[122, 125], "t3", "gs-gif-tag"], + [111, "t3", "(pointer gs-prim)"], + [113, "t3", "(pointer gs-rgbaq)"], + [143, "t5", "(pointer gs-xyzf)"], + [156, "t5", "(pointer gs-xyzf)"], + [[167, 170], "a3", "gs-gif-tag"], + [177, "a3", "(pointer gs-test)"], + [179, "a3", "(pointer gs-reg64)"], + [183, "a3", "(pointer gs-reg64)"], + [193, "a3", "(pointer gs-reg64)"], + [190, "a3", "(pointer gs-reg64)"], + [202, "a3", "(pointer gs-reg64)"], + [181, "a3", "(pointer gs-zbuf)"], + [188, "a3", "(pointer gs-frame)"], + [191, "a3", "(pointer uint64)"], + [206, "a3", "(pointer gs-reg64)"], + [213, "a3", "(pointer gs-reg64)"], + [214, "a3", "(pointer uint64)"], + [216, "a3", "(pointer gs-reg64)"], + [211, "a3", "(pointer gs-frame)"], + [204, "a3", "(pointer gs-zbuf)"], + [200, "a3", "(pointer gs-test)"], + [229, "v1", "(pointer uint64)"], + [225, "v1", "(pointer uint64)"], + [230, "v1", "(pointer uint64)"], + [235, "v1", "(pointer uint64)"] + ], + "shadow-dma-end": [ + [34, "a1", "dma-packet"], + [33, "a1", "dma-packet"], + [36, "a1", "dma-packet"], + [25, "v1", "(pointer uint64)"], + [41, "v1", "dma-packet"], + [42, "v1", "(pointer uint64)"], + [[113, 116], "a0", "gs-gif-tag"], + [[102, 107], "a0", "dma-packet"], + [120, "a0", "(pointer uint64)"], + [122, "a0", "(pointer gs-reg64)"], + [126, "a0", "(pointer gs-reg64)"], + [133, "a0", "(pointer gs-reg64)"], + [134, "a0", "(pointer uint64)"], + [136, "a0", "(pointer gs-reg64)"], + [137, "a0", "(pointer uint64)"], + [139, "a0", "(pointer gs-reg64)"], + [124, "a0", "(pointer gs-test)"], + [131, "a0", "(pointer gs-frame)"], + [[146, 151], "a1", "dma-packet"], + [201, "t0", "(pointer uint64)"], + [214, "t0", "(pointer uint64)"], + [237, "t0", "(pointer uint64)"], + [250, "t0", "(pointer uint64)"], + [[156, 159], "a1", "gs-gif-tag"], + [160, "a1", "(pointer gs-prim)"], + [161, "a1", "(pointer gs-rgbaq)"], + [[166, 169], "a1", "(inline-array gs-gif-tag)"], + [268, "v1", "(pointer uint64)"], + [264, "v1", "(pointer uint64)"], + [269, "v1", "(pointer uint64)"], + [274, "v1", "(pointer uint64)"] + ], + "shadow-execute-all": [ + [[56, 63], "v1", "shadow-dcache"], + [114, "v1", "shadow-dcache"], + [119, "a0", "uint32"], + [[191, 249], "gp", "shadow-dcache"], + [96, "v1", "shadow-dcache"] + ], "real-fog-texture-anim-func": [ [[6, 160], "s2", "(pointer uint32)"] ] diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index f1e572559..63e301592 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -213,6 +213,7 @@ set(RUNTIME_SOURCE mips2c/jak3_functions/merc_blend_shape.cpp mips2c/jak3_functions/wvehicle_part.cpp mips2c/jak3_functions/ripple.cpp + mips2c/jak3_functions/shadow.cpp mips2c/jak3_functions/ocean.cpp mips2c/jak3_functions/ocean_vu0.cpp mips2c/jak3_functions/generic_merc.cpp diff --git a/game/graphics/opengl_renderer/OpenGLRenderer.cpp b/game/graphics/opengl_renderer/OpenGLRenderer.cpp index 2d82e8b09..efa134bef 100644 --- a/game/graphics/opengl_renderer/OpenGLRenderer.cpp +++ b/game/graphics/opengl_renderer/OpenGLRenderer.cpp @@ -239,6 +239,10 @@ void OpenGLRenderer::init_bucket_renderers_jak3() { BucketId::TEX_LCOM_SHRUB, m_texture_animator); init_bucket_renderer("merc-lcom-shrub", BucketCategory::MERC, BucketId::MERC_LCOM_SHRUB, m_merc2); + + // 350 + init_bucket_renderer("shadow", BucketCategory::OTHER, BucketId::SHADOW); + // 351 for (int i = 0; i < LEVEL_MAX; i++) { #define GET_BUCKET_ID_FOR_LIST(bkt1, bkt2, idx) ((int)(bkt1) + ((int)(bkt2) - (int)(bkt1)) * (idx)) @@ -317,6 +321,9 @@ void OpenGLRenderer::init_bucket_renderers_jak3() { init_bucket_renderer("generic-sprite-3", BucketCategory::OTHER, BucketId::GENERIC_SPRITE_3, m_generic2, Generic2::Mode::LIGHTNING); + + init_bucket_renderer("shadow2", BucketCategory::OTHER, BucketId::SHADOW2); + init_bucket_renderer("shadow3", BucketCategory::OTHER, BucketId::SHADOW3); // 575 init_bucket_renderer("tex-warp", BucketCategory::TEX, BucketId::TEX_WARP, m_texture_animator); diff --git a/game/graphics/opengl_renderer/foreground/Shadow2.cpp b/game/graphics/opengl_renderer/foreground/Shadow2.cpp index dcd65b39e..61607423b 100644 --- a/game/graphics/opengl_renderer/foreground/Shadow2.cpp +++ b/game/graphics/opengl_renderer/foreground/Shadow2.cpp @@ -551,8 +551,8 @@ void Shadow2::draw_buffers(SharedRenderState* render_state, if (have_darken) { glColorMask(darken_channel[0], darken_channel[1], darken_channel[2], false); - glUniform4f(m_ogl.uniforms.color, (128 - m_color[0]) / 256.f, (128 - m_color[1]) / 256.f, - (128 - m_color[2]) / 256.f, 0); + glUniform4f(m_ogl.uniforms.color, (m_color[3] - m_color[0]) / 256.f, + (m_color[3] - m_color[1]) / 256.f, (m_color[3] - m_color[2]) / 256.f, 0); glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, (void*)(sizeof(u32) * (m_front_index_buffer_used - 6))); @@ -560,8 +560,8 @@ void Shadow2::draw_buffers(SharedRenderState* render_state, if (have_lighten) { glColorMask(lighten_channel[0], lighten_channel[1], lighten_channel[2], false); - glUniform4f(m_ogl.uniforms.color, (m_color[0] - 128) / 256.f, (m_color[1] - 128) / 256.f, - (m_color[2] - 128) / 256.f, 0); + glUniform4f(m_ogl.uniforms.color, (m_color[0] - m_color[3]) / 256.f, + (m_color[1] - m_color[3]) / 256.f, (m_color[2] - m_color[3]) / 256.f, 0); glBlendEquation(GL_FUNC_ADD); glDrawElements(GL_TRIANGLE_STRIP, 6, GL_UNSIGNED_INT, (void*)(sizeof(u32) * (m_front_index_buffer_used - 6))); diff --git a/game/mips2c/jak3_functions/shadow.cpp b/game/mips2c/jak3_functions/shadow.cpp new file mode 100644 index 000000000..d64b773e5 --- /dev/null +++ b/game/mips2c/jak3_functions/shadow.cpp @@ -0,0 +1,2834 @@ +//--------------------------MIPS2C--------------------- +#include "game/kernel/jak3/kscheme.h" +#include "game/mips2c/mips2c_private.h" +namespace Mips2C::jak3 { +// clang-format off +namespace { +void exec_0(ExecutionContext* c) { + // nop | sub.xyzw vf05, vf03, vf02 0 + c->vfs[vf05].vf.sub(Mask::xyzw, c->vf_src(vf03).vf, c->vf_src(vf02).vf); + // nop | sub.xyzw vf06, vf04, vf02 1 + c->vfs[vf06].vf.sub(Mask::xyzw, c->vf_src(vf04).vf, c->vf_src(vf02).vf); + // nop | sub.xyzw vf10, vf08, vf07 2 + c->vfs[vf10].vf.sub(Mask::xyzw, c->vf_src(vf08).vf, c->vf_src(vf07).vf); + // nop | sub.xyzw vf11, vf09, vf07 3 + c->vfs[vf11].vf.sub(Mask::xyzw, c->vf_src(vf09).vf, c->vf_src(vf07).vf); + // nop | sub.xyzw vf15, vf13, vf12 4 + c->vfs[vf15].vf.sub(Mask::xyzw, c->vf_src(vf13).vf, c->vf_src(vf12).vf); + // nop | sub.xyzw vf16, vf14, vf12 5 + c->vfs[vf16].vf.sub(Mask::xyzw, c->vf_src(vf14).vf, c->vf_src(vf12).vf); + // nop | sub.xyzw vf20, vf18, vf17 6 + c->vfs[vf20].vf.sub(Mask::xyzw, c->vf_src(vf18).vf, c->vf_src(vf17).vf); + // nop | sub.xyzw vf21, vf19, vf17 7 + c->vfs[vf21].vf.sub(Mask::xyzw, c->vf_src(vf19).vf, c->vf_src(vf17).vf); + // nop | opmula.xyz ACC, vf05, vf06 8 + c->vopmula(vf05, vf06); // ASSERT(false); + // nop | opmsub.xyz vf05, vf06, vf05 9 + c->vopmsub(vf05, vf06, vf05); //ASSERT(false); + // nop | opmula.xyz ACC, vf10, vf11 10 + c->vopmula(vf10, vf11); // ASSERT(false); + // nop | opmsub.xyz vf10, vf11, vf10 11 + c->vopmsub(vf10, vf11, vf10); // ASSERT(false); + // nop | opmula.xyz ACC, vf15, vf16 12 + c->vopmula(vf15, vf16); // ASSERT(false); + // nop | opmsub.xyz vf15, vf16, vf15 13 + c->vopmsub(vf15, vf16, vf15); // ASSERT(false); + // nop | opmula.xyz ACC, vf20, vf21 14 + c->vopmula(vf20, vf21); // ASSERT(false); + // nop | opmsub.xyz vf20, vf21, vf20 15 + c->vopmsub(vf20, vf21, vf20); // ASSERT(false); + // nop | mul.xyz vf05, vf05, vf01 16 + c->vfs[vf05].vf.mul(Mask::xyz, c->vf_src(vf05).vf, c->vf_src(vf01).vf); + // nop | mul.xyz vf10, vf10, vf01 17 + c->vfs[vf10].vf.mul(Mask::xyz, c->vf_src(vf10).vf, c->vf_src(vf01).vf); + // nop | mul.xyz vf15, vf15, vf01 18 + c->vfs[vf15].vf.mul(Mask::xyz, c->vf_src(vf15).vf, c->vf_src(vf01).vf); + // nop | mul.xyz vf20, vf20, vf01 19 + c->vfs[vf20].vf.mul(Mask::xyz, c->vf_src(vf20).vf, c->vf_src(vf01).vf); + // nop | addx.y vf05, vf05, vf05 20 + c->vfs[vf05].vf.add(Mask::y, c->vf_src(vf05).vf, c->vf_src(vf05).vf.x()); + // nop | addx.y vf10, vf10, vf10 21 + c->vfs[vf10].vf.add(Mask::y, c->vf_src(vf10).vf, c->vf_src(vf10).vf.x()); + // nop | addx.y vf15, vf15, vf15 22 + c->vfs[vf15].vf.add(Mask::y, c->vf_src(vf15).vf, c->vf_src(vf15).vf.x()); + // nop | addx.y vf20, vf20, vf20 23 + c->vfs[vf20].vf.add(Mask::y, c->vf_src(vf20).vf, c->vf_src(vf20).vf.x()); + // nop | addz.y vf22, vf05, vf05 24 + c->vfs[vf22].vf.add(Mask::y, c->vf_src(vf05).vf, c->vf_src(vf05).vf.z()); + // nop | addz.y vf23, vf10, vf10 25 + c->vfs[vf23].vf.add(Mask::y, c->vf_src(vf10).vf, c->vf_src(vf10).vf.z()); + // nop | addz.y vf24, vf15, vf15 :e 26 + c->vfs[vf24].vf.add(Mask::y, c->vf_src(vf15).vf, c->vf_src(vf15).vf.z()); + // nop | addz.y vf25, vf20, vf20 27 + c->vfs[vf25].vf.add(Mask::y, c->vf_src(vf20).vf, c->vf_src(vf20).vf.z()); +} + +void exec_28(ExecutionContext* c) { +// nop | mul.xyzw vf27, vf20, Q 28 + c->vfs[vf27].vf.mul(Mask::xyzw, c->vf_src(vf20).vf, c->Q); + // div Q, vf13.x, vf17.x | sub.xyzw vf19, vf01, vf03 29 + c->vfs[vf19].vf.sub(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf03).vf); c->Q = c->vfs[vf13].vf.x() / c->vfs[vf17].vf.x(); + // move.xyzw vf23, vf07 | sub.xyzw vf20, vf01, vf04 30 + c->vfs[vf20].vf.sub(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf04).vf); c->vfs[vf23].vf.move(Mask::xyzw, c->vf_src(vf07).vf); + // nop | sub.xyzw vf21, vf01, vf05 31 + c->vfs[vf21].vf.sub(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf05).vf); + // move.xyzw vf25, vf09 | sub.xyzw vf22, vf01, vf06 32 + c->vfs[vf22].vf.sub(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf06).vf); c->vfs[vf25].vf.move(Mask::xyzw, c->vf_src(vf09).vf); + // move.xyzw vf26, vf10 | sub.xyzw vf24, vf08, vf27 33 + c->vfs[vf24].vf.sub(Mask::xyzw, c->vf_src(vf08).vf, c->vf_src(vf27).vf); c->vfs[vf26].vf.move(Mask::xyzw, c->vf_src(vf10).vf); + // nop | mul.xyzw vf11, vf03, vf02 34 + c->vfs[vf11].vf.mul(Mask::xyzw, c->vf_src(vf03).vf, c->vf_src(vf02).vf); + // nop | mul.xyz vf15, vf19, vf02 35 + c->vfs[vf15].vf.mul(Mask::xyz, c->vf_src(vf19).vf, c->vf_src(vf02).vf); + // div Q, vf14.x, vf18.x | mul.xyzw vf12, vf04, vf02 36 + float oldQ = c->Q; + c->vfs[vf12].vf.mul(Mask::xyzw, c->vf_src(vf04).vf, c->vf_src(vf02).vf); c->Q = c->vfs[vf14].vf.x() / c->vfs[vf18].vf.x(); + // move.xyzw vf07, vf03 | mul.xyzw vf28, vf28, Q 37 + c->vfs[vf28].vf.mul(Mask::xyzw, c->vf_src(vf28).vf, oldQ); c->vfs[vf07].vf.move(Mask::xyzw, c->vf_src(vf03).vf); + // move.xyzw vf08, vf04 | mul.xyz vf16, vf20, vf02 38 + c->vfs[vf16].vf.mul(Mask::xyz, c->vf_src(vf20).vf, c->vf_src(vf02).vf); c->vfs[vf08].vf.move(Mask::xyzw, c->vf_src(vf04).vf); + // move.xyzw vf09, vf05 | addy.x vf11, vf11, vf11 39 + c->vfs[vf11].vf.add(Mask::x, c->vf_src(vf11).vf, c->vf_src(vf11).vf.y()); c->vfs[vf09].vf.move(Mask::xyzw, c->vf_src(vf05).vf); + // move.xyzw vf10, vf06 | addy.x vf15, vf15, vf15 40 + c->vfs[vf15].vf.add(Mask::x, c->vf_src(vf15).vf, c->vf_src(vf15).vf.y()); c->vfs[vf10].vf.move(Mask::xyzw, c->vf_src(vf06).vf); + // nop | sub.xyzw vf25, vf25, vf28 41 + c->vfs[vf25].vf.sub(Mask::xyzw, c->vf_src(vf25).vf, c->vf_src(vf28).vf); + // nop | addy.x vf12, vf12, vf12 42 + c->vfs[vf12].vf.add(Mask::x, c->vf_src(vf12).vf, c->vf_src(vf12).vf.y()); + // nop | mul.xyzw vf29, vf29, Q 43 + c->vfs[vf29].vf.mul(Mask::xyzw, c->vf_src(vf29).vf, c->Q); + // nop | addy.x vf16, vf16, vf16 44 + c->vfs[vf16].vf.add(Mask::x, c->vf_src(vf16).vf, c->vf_src(vf16).vf.y()); + // nop | addz.x vf11, vf11, vf11 45 + c->vfs[vf11].vf.add(Mask::x, c->vf_src(vf11).vf, c->vf_src(vf11).vf.z()); + // nop | addz.x vf15, vf15, vf15 46 + c->vfs[vf15].vf.add(Mask::x, c->vf_src(vf15).vf, c->vf_src(vf15).vf.z()); + // nop | sub.xyzw vf26, vf26, vf29 47 + c->vfs[vf26].vf.sub(Mask::xyzw, c->vf_src(vf26).vf, c->vf_src(vf29).vf); + // nop | addz.x vf12, vf12, vf12 48 + c->vfs[vf12].vf.add(Mask::x, c->vf_src(vf12).vf, c->vf_src(vf12).vf.z()); + // nop | addz.x vf16, vf16, vf16 49 + c->vfs[vf16].vf.add(Mask::x, c->vf_src(vf16).vf, c->vf_src(vf16).vf.z()); + // nop | addw.x vf11, vf11, vf11 50 + c->vfs[vf11].vf.add(Mask::x, c->vf_src(vf11).vf, c->vf_src(vf11).vf.w()); + // nop | mul.xyzw vf13, vf09, vf02 51 + + c->vfs[vf13].vf.mul(Mask::xyzw, c->vf_src(vf09).vf, c->vf_src(vf02).vf); + c->vfs[vf13].vf.saturate_infs(); + + // nop | addw.x vf12, vf12, vf12 52 + c->vfs[vf12].vf.add(Mask::x, c->vf_src(vf12).vf, c->vf_src(vf12).vf.w()); + // nop | mul.xyz vf17, vf21, vf02 53 + c->vfs[vf17].vf.mul(Mask::xyz, c->vf_src(vf21).vf, c->vf_src(vf02).vf); + // nop | mul.xyzw vf14, vf10, vf02 54 + c->vfs[vf14].vf.mul(Mask::xyzw, c->vf_src(vf10).vf, c->vf_src(vf02).vf); + c->vfs[vf14].vf.saturate_infs(); + + // div Q, vf11.x, vf15.x | mul.xyz vf18, vf22, vf02 55 + c->vfs[vf18].vf.mul(Mask::xyz, c->vf_src(vf22).vf, c->vf_src(vf02).vf); c->Q = c->vfs[vf11].vf.x() / c->vfs[vf15].vf.x(); + // nop | addy.x vf13, vf13, vf13 56 + c->vfs[vf13].vf.add(Mask::x, c->vf_src(vf13).vf, c->vf_src(vf13).vf.y()); + + // nop | addy.x vf17, vf17, vf17 57 + c->vfs[vf17].vf.add(Mask::x, c->vf_src(vf17).vf, c->vf_src(vf17).vf.y()); + // nop | addy.x vf14, vf14, vf14 58 + c->vfs[vf14].vf.add(Mask::x, c->vf_src(vf14).vf, c->vf_src(vf14).vf.y()); + + // nop | addy.x vf18, vf18, vf18 59 + c->vfs[vf18].vf.add(Mask::x, c->vf_src(vf18).vf, c->vf_src(vf18).vf.y()); + // nop | addz.x vf13, vf13, vf13 60 + c->vfs[vf13].vf.add(Mask::x, c->vf_src(vf13).vf, c->vf_src(vf13).vf.z()); + + // nop | addz.x vf17, vf17, vf17 61 + c->vfs[vf17].vf.add(Mask::x, c->vf_src(vf17).vf, c->vf_src(vf17).vf.z()); + // div Q, vf12.x, vf16.x | addz.x vf14, vf14, vf14 62 + oldQ = c->Q; + c->vfs[vf14].vf.add(Mask::x, c->vf_src(vf14).vf, c->vf_src(vf14).vf.z()); c->Q = c->vfs[vf12].vf.x() / c->vfs[vf16].vf.x(); + + // nop | mul.xyzw vf19, vf19, Q 63 + c->vfs[vf19].vf.mul(Mask::xyzw, c->vf_src(vf19).vf, oldQ); + // move.xyzw vf28, vf21 | addz.x vf18, vf18, vf18 64 + c->vfs[vf18].vf.add(Mask::x, c->vf_src(vf18).vf, c->vf_src(vf18).vf.z()); c->vfs[vf28].vf.move(Mask::xyzw, c->vf_src(vf21).vf); + // move.xyzw vf29, vf22 | addw.x vf13, vf13, vf13 65 + c->vfs[vf13].vf.add(Mask::x, c->vf_src(vf13).vf, c->vf_src(vf13).vf.w()); c->vfs[vf29].vf.move(Mask::xyzw, c->vf_src(vf22).vf); + c->vfs[vf13].vf.saturate_infs(); + + // nop | addw.x vf14, vf14, vf14 :e 66 + c->vfs[vf14].vf.add(Mask::x, c->vf_src(vf14).vf, c->vf_src(vf14).vf.w()); + c->vfs[vf14].vf.saturate_infs(); + + // nop | sub.xyzw vf07, vf07, vf19 67 + c->vfs[vf07].vf.sub(Mask::xyzw, c->vf_src(vf07).vf, c->vf_src(vf19).vf); +} + +void exec_68(ExecutionContext* c) { + // nop | mul.xyzw vf27, vf20, Q 68 + c->vfs[vf27].vf.mul(Mask::xyzw, c->vf_src(vf20).vf, c->Q); + // div Q, vf13.x, vf17.x | nop 69 + c->Q = c->vfs[vf13].vf.x() / c->vfs[vf17].vf.x(); + // move.xyzw vf23, vf07 | nop 70 + c->vfs[vf23].vf.move(Mask::xyzw, c->vf_src(vf07).vf); + // nop | nop 71 + + // move.xyzw vf25, vf09 | nop 72 + c->vfs[vf25].vf.move(Mask::xyzw, c->vf_src(vf09).vf); + // move.xyzw vf26, vf10 | sub.xyzw vf24, vf08, vf27 73 + c->vfs[vf24].vf.sub(Mask::xyzw, c->vf_src(vf08).vf, c->vf_src(vf27).vf); c->vfs[vf26].vf.move(Mask::xyzw, c->vf_src(vf10).vf); + // nop | nop 74 + + // nop | nop 75 + + // div Q, vf14.x, vf18.x | nop 76 + float oldQ = c->Q; + c->Q = c->vfs[vf14].vf.x() / c->vfs[vf18].vf.x(); + // nop | mul.xyzw vf28, vf28, Q 77 + c->vfs[vf28].vf.mul(Mask::xyzw, c->vf_src(vf28).vf, oldQ); + // nop | nop 78 + + // nop | nop 79 + + // nop | nop 80 + + // nop | sub.xyzw vf25, vf25, vf28 81 + c->vfs[vf25].vf.sub(Mask::xyzw, c->vf_src(vf25).vf, c->vf_src(vf28).vf); // was bad + // nop | nop 82 + + // nop | mul.xyzw vf29, vf29, Q 83 + c->vfs[vf29].vf.mul(Mask::xyzw, c->vf_src(vf29).vf, c->Q); + // nop | nop 84 + + // nop | nop 85 + + // nop | nop :e 86 + + // nop | sub.xyzw vf26, vf26, vf29 87 + c->vfs[vf26].vf.sub(Mask::xyzw, c->vf_src(vf26).vf, c->vf_src(vf29).vf); + +} +} // namespace +} // namespace Mips2C::jak3 + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_xform_verts { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + // nop // sll r0, r0, 0 + c->lw(v1, 68, a1); // lw v1, 68(a1) + // nop // sll r0, r0, 0 + c->lw(a2, 20, a0); // lw a2, 20(a0) + c->dsll(v1, v1, 4); // dsll v1, v1, 4 + c->lw(t0, 24, a0); // lw t0, 24(a0) + c->daddu(a2, a2, a0); // daddu a2, a2, a0 + c->lh(a3, 8, a0); // lh a3, 8(a0) + c->daddu(t0, t0, a0); // daddu t0, t0, a0 + // nop // sll r0, r0, 0 + c->daddu(v1, a0, v1); // daddu v1, a0, v1 + c->sw(a2, 0, a1); // sw a2, 0(a1) + c->daddiu(v1, v1, 144); // daddiu v1, v1, 144 + // nop // sll r0, r0, 0 + c->mov64(a1, t0); // or a1, t0, r0 + c->lh(t0, 10, a0); // lh t0, 10(a0) + c->mov64(a2, a2); // or a2, a2, r0 + // nop // sll r0, r0, 0 + c->dsubu(a3, a3, t0); // dsubu a3, a3, t0 + // nop // sll r0, r0, 0 + bc = c->sgpr64(a3) == 0; // beq a3, r0, L117 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + +block_1: + c->daddiu(a3, a3, -1); // daddiu a3, a3, -1 + c->lbu(t0, 0, a1); // lbu t0, 0(a1) + // nop // sll r0, r0, 0 + c->lbu(t1, 1, a1); // lbu t1, 1(a1) + // nop // sll r0, r0, 0 + c->daddiu(a1, a1, 2); // daddiu a1, a1, 2 + c->dsll(t0, t0, 7); // dsll t0, t0, 7 + // nop // sll r0, r0, 0 + c->daddu(t0, t0, v1); // daddu t0, t0, v1 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->lqc2(vf1, 0, t0); // lqc2 vf1, 0(t0) + // nop // sll r0, r0, 0 + c->lqc2(vf2, 16, t0); // lqc2 vf2, 16(t0) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 32, t0); // lqc2 vf3, 32(t0) + // nop // sll r0, r0, 0 + c->lqc2(vf4, 48, t0); // lqc2 vf4, 48(t0) + // nop // sll r0, r0, 0 + c->lqc2(vf9, 0, a2); // lqc2 vf9, 0(a2) + c->vmula_bc(DEST::xyzw, BC::w, vf4, vf0); // vmulaw.xyzw acc, vf4, vf0 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::x, vf1, vf9); // vmaddax.xyzw acc, vf1, vf9 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf2, vf9); // vmadday.xyzw acc, vf2, vf9 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyz, BC::z, vf9, vf3, vf9); // vmaddz.xyz vf9, vf3, vf9 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sqc2(vf9, 0, a2); // sqc2 vf9, 0(a2) + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + // nop // sll r0, r0, 0 + bc = c->sgpr64(a3) != 0; // bne a3, r0, L116 + // nop // sll r0, r0, 0 + if (bc) {goto block_1;} // branch non-likely + + +block_2: + // nop // sll r0, r0, 0 + c->lh(a0, 10, a0); // lh a0, 10(a0) + bc = c->sgpr64(a0) == 0; // beq a0, r0, L119 + // nop // sll r0, r0, 0 + if (bc) {goto block_5;} // branch non-likely + + +block_3: + c->daddiu(a0, a0, -1); // daddiu a0, a0, -1 + c->lbu(t0, 0, a1); // lbu t0, 0(a1) + // nop // sll r0, r0, 0 + c->lbu(a3, 1, a1); // lbu a3, 1(a1) + c->dsll(t0, t0, 7); // dsll t0, t0, 7 + c->daddiu(a1, a1, 2); // daddiu a1, a1, 2 + c->dsll(a3, a3, 7); // dsll a3, a3, 7 + c->daddu(t0, t0, v1); // daddu t0, t0, v1 + c->daddu(a3, a3, v1); // daddu a3, a3, v1 + c->lqc2(vf1, 0, t0); // lqc2 vf1, 0(t0) + // nop // sll r0, r0, 0 + c->lqc2(vf2, 16, t0); // lqc2 vf2, 16(t0) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 32, t0); // lqc2 vf3, 32(t0) + // nop // sll r0, r0, 0 + c->lqc2(vf4, 48, t0); // lqc2 vf4, 48(t0) + // nop // sll r0, r0, 0 + c->lqc2(vf9, 0, a2); // lqc2 vf9, 0(a2) + // nop // sll r0, r0, 0 + c->lqc2(vf5, 0, a3); // lqc2 vf5, 0(a3) + // nop // sll r0, r0, 0 + c->lqc2(vf6, 16, a3); // lqc2 vf6, 16(a3) + // nop // sll r0, r0, 0 + c->lqc2(vf7, 32, a3); // lqc2 vf7, 32(a3) + // nop // sll r0, r0, 0 + c->lqc2(vf8, 48, a3); // lqc2 vf8, 48(a3) + c->vsub_bc(DEST::w, BC::w, vf10, vf0, vf9); // vsubw.w vf10, vf0, vf9 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::w, vf4, vf0); // vmulaw.xyzw acc, vf4, vf0 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::x, vf1, vf9); // vmaddax.xyzw acc, vf1, vf9 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf2, vf9); // vmadday.xyzw acc, vf2, vf9 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyz, BC::z, vf10, vf3, vf9); // vmaddz.xyz vf10, vf3, vf9 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyzw, BC::w, vf8, vf0); // vmulaw.xyzw acc, vf8, vf0 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::x, vf5, vf9); // vmaddax.xyzw acc, vf5, vf9 + // nop // sll r0, r0, 0 + c->vmadda_bc(DEST::xyzw, BC::y, vf6, vf9); // vmadday.xyzw acc, vf6, vf9 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyz, BC::z, vf9, vf7, vf9); // vmaddz.xyz vf9, vf7, vf9 + // nop // sll r0, r0, 0 + c->vmula_bc(DEST::xyz, BC::w, vf10, vf9); // vmulaw.xyz acc, vf10, vf9 + // nop // sll r0, r0, 0 + c->vmadd_bc(DEST::xyz, BC::w, vf9, vf9, vf10); // vmaddw.xyz vf9, vf9, vf10 + // nop // sll r0, r0, 0 + c->vadd_bc(DEST::w, BC::x, vf9, vf0, vf0); // vaddx.w vf9, vf0, vf0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sqc2(vf9, 0, a2); // sqc2 vf9, 0(a2) + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + // nop // sll r0, r0, 0 + bc = c->sgpr64(a0) != 0; // bne a0, r0, L118 + // nop // sll r0, r0, 0 + if (bc) {goto block_3;} // branch non-likely + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + +block_5: + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + gLinkedFunctionTable.reg("shadow-xform-verts", execute, 128); +} + +} // namespace shadow_xform_verts +} // namespace Mips2C + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_calc_dual_verts { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + // nop // sll r0, r0, 0 + c->lw(v1, 16, a1); // lw v1, 16(a1) + // nop // sll r0, r0, 0 + c->lw(a2, 0, a1); // lw a2, 0(a1) + c->daddiu(v1, v1, 15); // daddiu v1, v1, 15 + c->lqc2(vf1, 80, a1); // lqc2 vf1, 80(a1) + c->dsra(v1, v1, 4); // dsra v1, v1, 4 + c->lqc2(vf2, 96, a1); // lqc2 vf2, 96(a1) + c->dsll(a3, v1, 4); // dsll a3, v1, 4 + c->lh(a0, 8, a0); // lh a0, 8(a0) + c->mov64(v1, a3); // or v1, a3, r0 + c->sw(a3, 44, a1); // sw a3, 44(a1) + c->mov64(a2, a2); // or a2, a2, r0 + // nop // sll r0, r0, 0 + bc = c->sgpr64(a0) == 0; // beq a0, r0, L114 + // nop // sll r0, r0, 0 + if (bc) {goto block_9;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lq(a3, 0, a2); // lq a3, 0(a2) + // nop // sll r0, r0, 0 + c->lq(t0, 16, a2); // lq t0, 16(a2) + // nop // sll r0, r0, 0 + c->lq(t1, 32, a2); // lq t1, 32(a2) + // nop // sll r0, r0, 0 + c->lq(t2, 48, a2); // lq t2, 48(a2) + c->daddiu(a2, a2, 64); // daddiu a2, a2, 64 + c->mov128_vf_gpr(vf3, a3); // qmtc2.i vf3, a3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf4, t0); // qmtc2.ni vf4, t0 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf5, t1); // qmtc2.ni vf5, t1 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf6, t2); // qmtc2.ni vf6, t2 + exec_28(c); + // nop // sll r0, r0, 0 + c->daddiu(a0, a0, -4); // daddiu a0, a0, -4 + c->lq(a3, 0, a2); // lq a3, 0(a2) + bc = ((s64)c->sgpr64(a0)) <= 0; // blez a0, L112 + c->lq(t0, 16, a2); // lq t0, 16(a2) + if (bc) {goto block_4;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lq(t1, 32, a2); // lq t1, 32(a2) + // nop // sll r0, r0, 0 + c->lq(t2, 48, a2); // lq t2, 48(a2) + c->daddiu(a2, a2, 64); // daddiu a2, a2, 64 + c->mov128_vf_gpr(vf3, a3); // qmtc2.i vf3, a3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf4, t0); // qmtc2.ni vf4, t0 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf5, t1); // qmtc2.ni vf5, t1 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf6, t2); // qmtc2.ni vf6, t2 + +block_3: + exec_28(c); + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf23); // qmfc2.i a3, vf23 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sq(a3, 0, v1); // sq a3, 0(v1) + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf24); // qmfc2.ni a3, vf24 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sq(a3, 16, v1); // sq a3, 16(v1) + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf25); // qmfc2.ni a3, vf25 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sq(a3, 32, v1); // sq a3, 32(v1) + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf26); // qmfc2.ni a3, vf26 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sq(a3, 48, v1); // sq a3, 48(v1) + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->lq(a3, 0, a2); // lq a3, 0(a2) + // nop // sll r0, r0, 0 + c->lq(t0, 16, a2); // lq t0, 16(a2) + // nop // sll r0, r0, 0 + c->lq(t1, 32, a2); // lq t1, 32(a2) + c->daddiu(a0, a0, -4); // daddiu a0, a0, -4 + c->lq(t2, 48, a2); // lq t2, 48(a2) + c->daddiu(a2, a2, 64); // daddiu a2, a2, 64 + c->daddiu(v1, v1, 64); // daddiu v1, v1, 64 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf3, a3); // qmtc2.ni vf3, a3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf4, t0); // qmtc2.ni vf4, t0 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf5, t1); // qmtc2.ni vf5, t1 + bc = ((s64)c->sgpr64(a0)) > 0; // bgtz a0, L111 + c->mov128_vf_gpr(vf6, t2); // qmtc2.ni vf6, t2 + if (bc) {goto block_3;} // branch non-likely + + +block_4: + exec_68(c); + // nop // sll r0, r0, 0 + // nop // vnop + // nop // sll r0, r0, 0 + c->daddiu(a2, a0, 3); // daddiu a2, a0, 3 + c->mov128_gpr_vf(a3, vf23); // qmfc2.i a3, vf23 + c->daddiu(t0, a0, 2); // daddiu t0, a0, 2 + c->mov128_gpr_vf(t1, vf24); // qmfc2.i t1, vf24 + c->daddiu(t2, a0, 1); // daddiu t2, a0, 1 + c->mov128_gpr_vf(t3, vf25); // qmfc2.i t3, vf25 + c->daddiu(a0, a0, 4); // daddiu a0, a0, 4 + c->mov128_gpr_vf(t4, vf26); // qmfc2.i t4, vf26 + bc = c->sgpr64(a2) == 0; // beq a2, r0, L113 + c->sq(a3, 0, v1); // sq a3, 0(v1) + if (bc) {goto block_8;} // branch non-likely + + bc = c->sgpr64(t0) == 0; // beq t0, r0, L113 + c->sq(t1, 16, v1); // sq t1, 16(v1) + if (bc) {goto block_8;} // branch non-likely + + bc = c->sgpr64(t2) == 0; // beq t2, r0, L113 + c->sq(t3, 32, v1); // sq t3, 32(v1) + if (bc) {goto block_8;} // branch non-likely + + // nop // sll r0, r0, 0 + c->sq(t4, 48, v1); // sq t4, 48(v1) + +block_8: + c->dsll(a0, a0, 4); // dsll a0, a0, 4 + // nop // sll r0, r0, 0 + c->daddu(v1, v1, a0); // daddu v1, v1, a0 + // nop // sll r0, r0, 0 + +block_9: + c->sw(v1, 16, a1); // sw v1, 16(a1) + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + gLinkedFunctionTable.reg("shadow-calc-dual-verts", execute, 128); +} + +} // namespace shadow_calc_dual_verts +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_scissor_edges { +struct Cache { + void* fake_scratchpad_data; // *fake-scratchpad-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + get_fake_spad_addr2(v1, cache.fake_scratchpad_data, 0, c);// lui v1, 28672 + c->lw(a3, 44, a1); // lw a3, 44(a1) + // nop // sll r0, r0, 0 + c->lw(a2, 0, a1); // lw a2, 0(a1) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 128, a1); // lqc2 vf3, 128(a1) + // nop // sll r0, r0, 0 + c->lh(a0, 8, a0); // lh a0, 8(a0) + c->mov64(a1, a3); // or a1, a3, r0 + c->lw(a3, 44, v1); // lw a3, 44(v1) + c->mov64(a2, a2); // or a2, a2, r0 + // nop // sll r0, r0, 0 + bc = c->sgpr64(a0) == 0; // beq a0, r0, L109 + // nop // sll r0, r0, 0 + if (bc) {goto block_7;} // branch non-likely + + +block_1: + c->lqc2(vf1, 0, a2); // lqc2 vf1, 0(a2) + c->lqc2(vf2, 0, a1); // lqc2 vf2, 0(a1) + c->vadd_bc(DEST::z, BC::w, vf7, vf1, vf3); // vaddw.z vf7, vf1, vf3 + c->vadd_bc(DEST::z, BC::w, vf8, vf2, vf3); // vaddw.z vf8, vf2, vf3 + c->vsub_bc(DEST::z, BC::z, vf6, vf1, vf2); // vsubz.z vf6, vf1, vf2 + c->vadd_bc(DEST::z, BC::w, vf5, vf1, vf3); // vaddw.z vf5, vf1, vf3 + c->vadd_bc(DEST::y, BC::z, vf7, vf0, vf7); // vaddz.y vf7, vf0, vf7 + c->vadd_bc(DEST::y, BC::z, vf8, vf0, vf8); // vaddz.y vf8, vf0, vf8 + c->vsub(DEST::xyz, vf4, vf2, vf1); // vsub.xyz vf4, vf2, vf1 + c->mov128_gpr_vf(t0, vf7); // qmfc2.i t0, vf7 + c->mov128_gpr_vf(t1, vf8); // qmfc2.i t1, vf8 + bc = ((s64)c->sgpr64(t0)) < 0; // bltz t0, L107 + // nop // sll r0, r0, 0 + if (bc) {goto block_4;} // branch non-likely + + bc = ((s64)c->sgpr64(t1)) > 0; // bgtz t1, L108 + // nop // sll r0, r0, 0 + if (bc) {goto block_5;} // branch non-likely + + //beq r0, r0, L108 // beq r0, r0, L108 + c->daddiu(a3, a3, 1); // daddiu a3, a3, 1 + goto block_5; // branch always + + +block_4: + bc = ((s64)c->sgpr64(t1)) < 0; // bltz t1, L108 + c->daddiu(a3, a3, 1); // daddiu a3, a3, 1 + if (bc) {goto block_5;} // branch non-likely + + +block_5: + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->daddiu(a1, a1, 16); // daddiu a1, a1, 16 + c->daddiu(a0, a0, -1); // daddiu a0, a0, -1 + bc = c->sgpr64(a0) != 0; // bne a0, r0, L106 + // nop // sll r0, r0, 0 + if (bc) {goto block_1;} // branch non-likely + + c->sw(a3, 44, v1); // sw a3, 44(v1) + +block_7: + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.fake_scratchpad_data = intern_from_c(-1, 0, "*fake-scratchpad-data*").c(); + gLinkedFunctionTable.reg("shadow-scissor-edges", execute, 128); +} + +} // namespace shadow_scissor_edges +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_scissor_top { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + // nop // sll r0, r0, 0 + c->lw(a2, 44, a1); // lw a2, 44(a1) + // nop // sll r0, r0, 0 + c->lw(v1, 0, a1); // lw v1, 0(a1) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 112, a1); // lqc2 vf3, 112(a1) + // nop // sll r0, r0, 0 + c->lh(a0, 8, a0); // lh a0, 8(a0) + c->mov64(a1, a2); // or a1, a2, r0 + // nop // sll r0, r0, 0 + c->mov64(v1, v1); // or v1, v1, r0 + // nop // sll r0, r0, 0 + bc = c->sgpr64(a0) == 0; // beq a0, r0, L104 + // nop // sll r0, r0, 0 + if (bc) {goto block_4;} // branch non-likely + + +block_1: + c->lqc2(vf1, 0, v1); // lqc2 vf1, 0(v1) + c->lqc2(vf2, 0, a1); // lqc2 vf2, 0(a1) + c->vsub(DEST::xyzw, vf4, vf2, vf1); // vsub.xyzw vf4, vf2, vf1 + c->vmul(DEST::xyzw, vf5, vf1, vf3); // vmul.xyzw vf5, vf1, vf3 + c->vmul(DEST::xyz, vf6, vf4, vf3); // vmul.xyz vf6, vf4, vf3 + c->vadd_bc(DEST::y, BC::x, vf5, vf5, vf5); // vaddx.y vf5, vf5, vf5 + c->vadd_bc(DEST::x, BC::y, vf6, vf6, vf6); // vaddy.x vf6, vf6, vf6 + c->vadd_bc(DEST::y, BC::z, vf5, vf5, vf5); // vaddz.y vf5, vf5, vf5 + c->vadd_bc(DEST::x, BC::z, vf6, vf6, vf6); // vaddz.x vf6, vf6, vf6 + c->vadd_bc(DEST::y, BC::w, vf5, vf5, vf5); // vaddw.y vf5, vf5, vf5 + c->mov128_gpr_vf(a2, vf5); // qmfc2.i a2, vf5 + // nop // sll r0, r0, 0 + bc = ((s64)c->sgpr64(a2)) < 0; // bltz a2, L103 + // nop // sll r0, r0, 0 + if (bc) {goto block_3;} // branch non-likely + + c->vdiv(vf5, BC::y, vf6, BC::x); // vdiv Q, vf5.y, vf6.x + c->vwaitq(); // vwaitq + c->vmulq(DEST::xyzw, vf4, vf4); // vmulq.xyzw vf4, vf4, Q + c->vsub(DEST::xyzw, vf1, vf1, vf4); // vsub.xyzw vf1, vf1, vf4 + c->sqc2(vf1, 0, v1); // sqc2 vf1, 0(v1) + +block_3: + c->daddiu(v1, v1, 16); // daddiu v1, v1, 16 + c->daddiu(a1, a1, 16); // daddiu a1, a1, 16 + c->daddiu(a0, a0, -1); // daddiu a0, a0, -1 + bc = c->sgpr64(a0) != 0; // bne a0, r0, L102 + // nop // sll r0, r0, 0 + if (bc) {goto block_1;} // branch non-likely + + +block_4: + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + gLinkedFunctionTable.reg("shadow-scissor-top", execute, 128); +} + +} // namespace shadow_scissor_top +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_init_vars { +struct Cache { + void* math_camera; // *math-camera* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->load_symbol2(v1, cache.math_camera); // lw v1, *math-camera*(s7) + c->mov64(v1, v1); // or v1, v1, r0 + c->lqc2(vf7, 364, v1); // lqc2 vf7, 364(v1) + c->lqc2(vf8, 380, v1); // lqc2 vf8, 380(v1) + c->lqc2(vf9, 396, v1); // lqc2 vf9, 396(v1) + c->lqc2(vf10, 412, v1); // lqc2 vf10, 412(v1) + c->lqc2(vf1, 144, a1); // lqc2 vf1, 144(a1) + c->lqc2(vf11, 96, a1); // lqc2 vf11, 96(a1) + c->lqc2(vf12, 112, a1); // lqc2 vf12, 112(a1) + c->lqc2(vf2, 80, a1); // lqc2 vf2, 80(a1) + c->vmula_bc(DEST::xyzw, BC::x, vf7, vf1); // vmulax.xyzw acc, vf7, vf1 + c->vmadda_bc(DEST::xyzw, BC::y, vf8, vf1); // vmadday.xyzw acc, vf8, vf1 + c->vmadd_bc(DEST::xyzw, BC::z, vf1, vf9, vf1); // vmaddz.xyzw vf1, vf9, vf1 + c->vmula_bc(DEST::xyzw, BC::x, vf7, vf11); // vmulax.xyzw acc, vf7, vf11 + c->vmadda_bc(DEST::xyzw, BC::y, vf8, vf11); // vmadday.xyzw acc, vf8, vf11 + c->vmadd_bc(DEST::xyz, BC::z, vf11, vf9, vf11); // vmaddz.xyz vf11, vf9, vf11 + c->vmula_bc(DEST::xyzw, BC::x, vf7, vf12); // vmulax.xyzw acc, vf7, vf12 + c->vmadda_bc(DEST::xyzw, BC::y, vf8, vf12); // vmadday.xyzw acc, vf8, vf12 + c->vmadd_bc(DEST::xyz, BC::z, vf12, vf9, vf12); // vmaddz.xyz vf12, vf9, vf12 + c->vmul(DEST::xyzw, vf13, vf10, vf11); // vmul.xyzw vf13, vf10, vf11 + c->vmula_bc(DEST::xyzw, BC::w, vf10, vf0); // vmulaw.xyzw acc, vf10, vf0 + c->vmadda_bc(DEST::xyzw, BC::x, vf7, vf2); // vmaddax.xyzw acc, vf7, vf2 + c->vmul(DEST::xyzw, vf14, vf10, vf12); // vmul.xyzw vf14, vf10, vf12 + c->vsub_bc(DEST::w, BC::x, vf13, vf13, vf13); // vsubx.w vf13, vf13, vf13 + c->vsub_bc(DEST::w, BC::x, vf14, vf14, vf14); // vsubx.w vf14, vf14, vf14 + c->vmadda_bc(DEST::xyzw, BC::y, vf8, vf2); // vmadday.xyzw acc, vf8, vf2 + c->vmadd_bc(DEST::xyzw, BC::z, vf2, vf9, vf2); // vmaddz.xyzw vf2, vf9, vf2 + c->vsub_bc(DEST::w, BC::y, vf13, vf13, vf13); // vsuby.w vf13, vf13, vf13 + c->vsub_bc(DEST::w, BC::y, vf14, vf14, vf14); // vsuby.w vf14, vf14, vf14 + c->vsub_bc(DEST::w, BC::z, vf11, vf13, vf13); // vsubz.w vf11, vf13, vf13 + c->vsub_bc(DEST::w, BC::z, vf12, vf14, vf14); // vsubz.w vf12, vf14, vf14 + c->sqc2(vf2, 80, a1); // sqc2 vf2, 80(a1) + c->sqc2(vf1, 144, a1); // sqc2 vf1, 144(a1) + c->sqc2(vf11, 96, a1); // sqc2 vf11, 96(a1) + c->sqc2(vf12, 112, a1); // sqc2 vf12, 112(a1) + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.math_camera = intern_from_c(-1, 0, "*math-camera*").c(); + gLinkedFunctionTable.reg("shadow-init-vars", execute, 128); +} + +} // namespace shadow_init_vars +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_find_facing_single_tris { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -64); // daddiu sp, sp, -64 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->sq(s4, 16, sp); // sq s4, 16(sp) + c->sq(s5, 32, sp); // sq s5, 32(sp) + c->sq(gp, 48, sp); // sq gp, 48(sp) + c->lw(v1, 16, a1); // lw v1, 16(a1) + c->lh(t0, 12, a0); // lh t0, 12(a0) + c->mov64(a2, v1); // or a2, v1, r0 + c->lw(a3, 28, a0); // lw a3, 28(a0) + c->daddu(a0, a3, a0); // daddu a0, a3, a0 + c->mov64(a3, a0); // or a3, a0, r0 + c->lqc2(vf2, 80, a1); // lqc2 vf2, 80(a1) + c->lqc2(vf1, 144, a1); // lqc2 vf1, 144(a1) + c->lqc2(vf11, 96, a1); // lqc2 vf11, 96(a1) + c->lw(a0, 0, a1); // lw a0, 0(a1) + c->pextlw(a0, a0, a0); // pextlw a0, a0, a0 + c->pextlw(a0, a0, a0); // pextlw a0, a0, a0 + c->daddiu(t0, t0, -4); // daddiu t0, t0, -4 + c->addiu(t1, r0, 1); // addiu t1, r0, 1 + bc = ((s64)c->sgpr64(t0)) < 0; // bltz t0, L96 + c->daddiu(t0, t0, 4); // daddiu t0, t0, 4 + if (bc) {goto block_11;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lq(t3, 0, a3); // lq t3, 0(a3) + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->pextub(t2, r0, t3); // pextub t2, r0, t3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlb(t3, r0, t3); // pextlb t3, r0, t3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->psllh(t2, t2, 4); // psllh t2, t2, 4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->psllh(t4, t3, 4); // psllh t4, t3, 4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextuh(t3, r0, t4); // pextuh t3, r0, t4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlh(t4, r0, t4); // pextlh t4, r0, t4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextuh(t7, r0, t2); // pextuh t7, r0, t2 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlh(t5, r0, t2); // pextlh t5, r0, t2 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->paddw(t6, t4, a0); // paddw t6, t4, a0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pcpyud(t4, t6, r0); // pcpyud t4, t6, r0 + c->lq(t2, 0, t6); // lq t2, 0(t6) + c->paddw(t8, t3, a0); // paddw t8, t3, a0 + c->lq(t3, 0, t4); // lq t3, 0(t4) + c->pcpyud(t9, t8, r0); // pcpyud t9, t8, r0 + c->lq(t4, 0, t8); // lq t4, 0(t8) + c->dsra32(t6, t6, 0); // dsra32 t6, t6, 0 + c->dsra32(t8, t8, 0); // dsra32 t8, t8, 0 + c->paddw(s5, t5, a0); // paddw s5, t5, a0 + c->lq(t5, 0, t9); // lq t5, 0(t9) + c->pcpyud(t9, s5, r0); // pcpyud t9, s5, r0 + c->lq(t6, 0, t6); // lq t6, 0(t6) + c->paddw(gp, t7, a0); // paddw gp, t7, a0 + c->lq(t7, 0, t8); // lq t7, 0(t8) + c->pcpyud(ra, gp, r0); // pcpyud ra, gp, r0 + c->lq(t8, 0, s5); // lq t8, 0(s5) + c->dsra32(s5, s5, 0); // dsra32 s5, s5, 0 + c->dsra32(s4, gp, 0); // dsra32 s4, gp, 0 + // nop // sll r0, r0, 0 + c->lq(s5, 0, s5); // lq s5, 0(s5) + // nop // sll r0, r0, 0 + c->lq(t9, 0, t9); // lq t9, 0(t9) + // nop // sll r0, r0, 0 + c->lq(gp, 0, gp); // lq gp, 0(gp) + // nop // sll r0, r0, 0 + c->lq(s4, 0, s4); // lq s4, 0(s4) + // nop // sll r0, r0, 0 + c->lq(ra, 0, ra); // lq ra, 0(ra) + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf2, t2); // qmtc2.ni vf2, t2 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf3, t6); // qmtc2.ni vf3, t6 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf4, t3); // qmtc2.ni vf4, t3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf7, t4); // qmtc2.ni vf7, t4 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf8, t7); // qmtc2.ni vf8, t7 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf9, t5); // qmtc2.ni vf9, t5 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf12, t8); // qmtc2.ni vf12, t8 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf13, s5); // qmtc2.ni vf13, s5 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf14, t9); // qmtc2.ni vf14, t9 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf17, gp); // qmtc2.ni vf17, gp + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf18, s4); // qmtc2.ni vf18, s4 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf19, ra); // qmtc2.ni vf19, ra + +block_2: + // nop // sll r0, r0, 0 + c->lq(t3, 16, a3); // lq t3, 16(a3) + c->daddiu(t0, t0, -4); // daddiu t0, t0, -4 + exec_0(c); + c->pextub(t2, r0, t3); // pextub t2, r0, t3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlb(t3, r0, t3); // pextlb t3, r0, t3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->psllh(t2, t2, 4); // psllh t2, t2, 4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->psllh(t4, t3, 4); // psllh t4, t3, 4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextuh(t3, r0, t4); // pextuh t3, r0, t4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlh(t4, r0, t4); // pextlh t4, r0, t4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextuh(t7, r0, t2); // pextuh t7, r0, t2 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlh(t5, r0, t2); // pextlh t5, r0, t2 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->paddw(t6, t4, a0); // paddw t6, t4, a0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pcpyud(t4, t6, r0); // pcpyud t4, t6, r0 + c->lq(t2, 0, t6); // lq t2, 0(t6) + c->paddw(t8, t3, a0); // paddw t8, t3, a0 + c->lq(t3, 0, t4); // lq t3, 0(t4) + c->pcpyud(t9, t8, r0); // pcpyud t9, t8, r0 + c->lq(t4, 0, t8); // lq t4, 0(t8) + c->dsra32(t6, t6, 0); // dsra32 t6, t6, 0 + c->dsra32(t8, t8, 0); // dsra32 t8, t8, 0 + c->paddw(s5, t5, a0); // paddw s5, t5, a0 + c->lq(t5, 0, t9); // lq t5, 0(t9) + c->pcpyud(t9, s5, r0); // pcpyud t9, s5, r0 + c->lq(t6, 0, t6); // lq t6, 0(t6) + c->paddw(gp, t7, a0); // paddw gp, t7, a0 + c->lq(t7, 0, t8); // lq t7, 0(t8) + c->pcpyud(ra, gp, r0); // pcpyud ra, gp, r0 + c->lq(t8, 0, s5); // lq t8, 0(s5) + c->dsra32(s5, s5, 0); // dsra32 s5, s5, 0 + c->dsra32(s4, gp, 0); // dsra32 s4, gp, 0 + // nop // sll r0, r0, 0 + c->lq(s5, 0, s5); // lq s5, 0(s5) + // nop // sll r0, r0, 0 + c->lq(t9, 0, t9); // lq t9, 0(t9) + // nop // sll r0, r0, 0 + c->lq(gp, 0, gp); // lq gp, 0(gp) + // nop // sll r0, r0, 0 + c->lq(s4, 0, s4); // lq s4, 0(s4) + // nop // sll r0, r0, 0 + c->lq(ra, 0, ra); // lq ra, 0(ra) + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf2, t2); // qmtc2.ni vf2, t2 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf3, t6); // qmtc2.ni vf3, t6 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf4, t3); // qmtc2.ni vf4, t3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf7, t4); // qmtc2.ni vf7, t4 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf8, t7); // qmtc2.ni vf8, t7 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf9, t5); // qmtc2.ni vf9, t5 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf12, t8); // qmtc2.ni vf12, t8 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf13, s5); // qmtc2.ni vf13, s5 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf14, t9); // qmtc2.ni vf14, t9 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf17, gp); // qmtc2.ni vf17, gp + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf18, s4); // qmtc2.ni vf18, s4 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf19, ra); // qmtc2.ni vf19, ra + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t3, vf22); // qmfc2.ni t3, vf22 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t4, vf23); // qmfc2.ni t4, vf23 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t2, vf24); // qmfc2.ni t2, vf24 + bc = ((s64)c->sgpr64(t3)) >= 0; // bgez t3, L92 + c->mov128_gpr_vf(t3, vf25); // qmfc2.ni t3, vf25 + if (bc) {goto block_4;} // branch non-likely + + c->sb(t1, 3, a3); // sb t1, 3(a3) + // nop // sll r0, r0, 0 + c->sw(a3, 0, a2); // sw a3, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + +block_4: + bc = ((s64)c->sgpr64(t4)) >= 0; // bgez t4, L93 + c->daddiu(a3, a3, 4); // daddiu a3, a3, 4 + if (bc) {goto block_6;} // branch non-likely + + c->sb(t1, 3, a3); // sb t1, 3(a3) + // nop // sll r0, r0, 0 + c->sw(a3, 0, a2); // sw a3, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + +block_6: + bc = ((s64)c->sgpr64(t2)) >= 0; // bgez t2, L94 + c->daddiu(a3, a3, 4); // daddiu a3, a3, 4 + if (bc) {goto block_8;} // branch non-likely + + c->sb(t1, 3, a3); // sb t1, 3(a3) + // nop // sll r0, r0, 0 + c->sw(a3, 0, a2); // sw a3, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + +block_8: + bc = ((s64)c->sgpr64(t3)) >= 0; // bgez t3, L95 + c->daddiu(a3, a3, 4); // daddiu a3, a3, 4 + if (bc) {goto block_10;} // branch non-likely + + c->sb(t1, 3, a3); // sb t1, 3(a3) + // nop // sll r0, r0, 0 + c->sw(a3, 0, a2); // sw a3, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + +block_10: + bc = ((s64)c->sgpr64(t0)) > 0; // bgtz t0, L91 + c->daddiu(a3, a3, 4); // daddiu a3, a3, 4 + if (bc) {goto block_2;} // branch non-likely + + +block_11: + bc = ((s64)c->sgpr64(t0)) <= 0; // blez t0, L99 + // nop // sll r0, r0, 0 + if (bc) {goto block_15;} // branch non-likely + + +block_12: + c->lbu(t2, 0, a3); // lbu t2, 0(a3) + c->lbu(t3, 1, a3); // lbu t3, 1(a3) + c->lbu(t1, 2, a3); // lbu t1, 2(a3) + c->dsll(t2, t2, 4); // dsll t2, t2, 4 + c->dsll(t3, t3, 4); // dsll t3, t3, 4 + c->dsll(t1, t1, 4); // dsll t1, t1, 4 + c->daddu(t2, t2, a0); // daddu t2, t2, a0 + c->daddu(t3, t3, a0); // daddu t3, t3, a0 + c->daddu(t1, t1, a0); // daddu t1, t1, a0 + c->lqc2(vf2, 0, t2); // lqc2 vf2, 0(t2) + c->lqc2(vf3, 0, t3); // lqc2 vf3, 0(t3) + c->lqc2(vf4, 0, t1); // lqc2 vf4, 0(t1) + c->vsub(DEST::xyzw, vf5, vf3, vf2); // vsub.xyzw vf5, vf3, vf2 + c->vsub(DEST::xyzw, vf6, vf4, vf2); // vsub.xyzw vf6, vf4, vf2 + c->vopmula(vf5, vf6); // vopmula.xyz acc, vf5, vf6 + c->vopmsub(vf5, vf6, vf5); // vopmsub.xyz vf5, vf6, vf5 + c->vmul(DEST::xyz, vf5, vf5, vf1); // vmul.xyz vf5, vf5, vf1 + c->vadd_bc(DEST::y, BC::x, vf5, vf5, vf5); // vaddx.y vf5, vf5, vf5 + c->vadd_bc(DEST::y, BC::z, vf5, vf5, vf5); // vaddz.y vf5, vf5, vf5 + c->mov128_gpr_vf(t1, vf5); // qmfc2.i t1, vf5 + // nop // sll r0, r0, 0 + bc = ((s64)c->sgpr64(t1)) >= 0; // bgez t1, L98 + c->addiu(t1, r0, 1); // addiu t1, r0, 1 + if (bc) {goto block_14;} // branch non-likely + + c->sw(a3, 0, a2); // sw a3, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + c->sb(t1, 3, a3); // sb t1, 3(a3) + +block_14: + c->daddiu(t0, t0, -1); // daddiu t0, t0, -1 + bc = c->sgpr64(t0) != 0; // bne t0, r0, L97 + c->daddiu(a3, a3, 4); // daddiu a3, a3, 4 + if (bc) {goto block_12;} // branch non-likely + + +block_15: + c->dsubu(a0, a2, v1); // dsubu a0, a2, v1 + c->dsra(a0, a0, 2); // dsra a0, a0, 2 + c->sw(a0, 20, a1); // sw a0, 20(a1) + c->sw(v1, 32, a1); // sw v1, 32(a1) + c->sw(a2, 16, a1); // sw a2, 16(a1) + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->lq(gp, 48, sp); // lq gp, 48(sp) + c->lq(s5, 32, sp); // lq s5, 32(sp) + c->lq(s4, 16, sp); // lq s4, 16(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 64); // daddiu sp, sp, 64 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + gLinkedFunctionTable.reg("shadow-find-facing-single-tris", execute, 128); +} + +} // namespace shadow_find_facing_single_tris +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_find_single_edges { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->lw(a2, 16, a1); // lw a2, 16(a1) + c->lh(a3, 14, a0); // lh a3, 14(a0) + c->mov64(v1, a2); // or v1, a2, r0 + c->lw(t0, 32, a0); // lw t0, 32(a0) + bc = c->sgpr64(a3) == 0; // beq a3, r0, L89 + c->lw(t1, 28, a0); // lw t1, 28(a0) + if (bc) {goto block_8;} // branch non-likely + + c->daddu(t0, t0, a0); // daddu t0, t0, a0 + c->sw(a2, 36, a1); // sw a2, 36(a1) + c->daddu(a0, t1, a0); // daddu a0, t1, a0 + c->sw(t0, 4, a1); // sw t0, 4(a1) + c->mov64(t1, t0); // or t1, t0, r0 + c->addiu(t2, r0, 255); // addiu t2, r0, 255 + // nop // sll r0, r0, 0 + +block_2: + c->daddiu(a3, a3, -1); // daddiu a3, a3, -1 + c->lbu(t4, 3, t1); // lbu t4, 3(t1) + // nop // sll r0, r0, 0 + c->lbu(t5, 2, t1); // lbu t5, 2(t1) + bc = c->sgpr64(t4) == c->sgpr64(t2); // beq t4, t2, L86 + c->gprs[t3].du64[0] = 0; // or t3, r0, r0 + if (bc) {goto block_5;} // branch non-likely + + c->dsll(t3, t5, 2); // dsll t3, t5, 2 + c->dsll(t4, t4, 2); // dsll t4, t4, 2 + c->daddu(t3, t3, a0); // daddu t3, t3, a0 + c->daddu(t5, t4, a0); // daddu t5, t4, a0 + // nop // sll r0, r0, 0 + c->lbu(t4, 3, t3); // lbu t4, 3(t3) + // nop // sll r0, r0, 0 + c->lbu(t5, 3, t5); // lbu t5, 3(t5) + c->sltiu(t3, t4, 1); // sltiu t3, t4, 1 + // nop // sll r0, r0, 0 + bc = c->sgpr64(t4) == c->sgpr64(t5); // beq t4, t5, L88 + // nop // sll r0, r0, 0 + if (bc) {goto block_7;} // branch non-likely + + //beq r0, r0, L87 // beq r0, r0, L87 + // nop // sll r0, r0, 0 + goto block_6; // branch always + + +block_5: + c->dsll(t4, t5, 2); // dsll t4, t5, 2 + // nop // sll r0, r0, 0 + c->daddu(t4, t4, a0); // daddu t4, t4, a0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->lbu(t4, 3, t4); // lbu t4, 3(t4) + bc = c->sgpr64(t4) == 0; // beq t4, r0, L88 + // nop // sll r0, r0, 0 + if (bc) {goto block_7;} // branch non-likely + + +block_6: + c->dsubu(t4, t1, t0); // dsubu t4, t1, t0 + c->sh(t3, 2, v1); // sh t3, 2(v1) + c->sh(t4, 0, v1); // sh t4, 0(v1) + c->daddiu(v1, v1, 4); // daddiu v1, v1, 4 + +block_7: + bc = c->sgpr64(a3) != 0; // bne a3, r0, L85 + c->daddiu(t1, t1, 4); // daddiu t1, t1, 4 + if (bc) {goto block_2;} // branch non-likely + + +block_8: + c->dsubu(a0, v1, a2); // dsubu a0, v1, a2 + c->dsra(a0, a0, 2); // dsra a0, a0, 2 + c->sw(a0, 24, a1); // sw a0, 24(a1) + c->sw(v1, 16, a1); // sw v1, 16(a1) + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + gLinkedFunctionTable.reg("shadow-find-single-edges", execute, 128); +} + +} // namespace shadow_find_single_edges +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_find_facing_double_tris { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -16); // daddiu sp, sp, -16 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->lh(a2, 16, a0); // lh a2, 16(a0) + c->lw(v1, 36, a0); // lw v1, 36(a0) + c->daddu(a0, v1, a0); // daddu a0, v1, a0 + c->mov64(v1, a0); // or v1, a0, r0 + c->sw(a0, 12, a1); // sw a0, 12(a1) + c->lqc2(vf1, 144, a1); // lqc2 vf1, 144(a1) + c->lqc2(vf2, 80, a1); // lqc2 vf2, 80(a1) + c->lqc2(vf11, 96, a1); // lqc2 vf11, 96(a1) + c->lw(a0, 0, a1); // lw a0, 0(a1) + c->pextlw(a0, a0, a0); // pextlw a0, a0, a0 + c->pextlw(a0, a0, a0); // pextlw a0, a0, a0 + c->daddiu(a1, a2, -4); // daddiu a1, a2, -4 + c->addiu(a2, r0, 1); // addiu a2, r0, 1 + bc = ((s64)c->sgpr64(a1)) < 0; // bltz a1, L80 + c->daddiu(a1, a1, 4); // daddiu a1, a1, 4 + if (bc) {goto block_11;} // branch non-likely + + // nop // sll r0, r0, 0 + c->lq(t0, 0, v1); // lq t0, 0(v1) + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->pextub(a3, r0, t0); // pextub a3, r0, t0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlb(t0, r0, t0); // pextlb t0, r0, t0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->psllh(a3, a3, 4); // psllh a3, a3, 4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->psllh(t1, t0, 4); // psllh t1, t0, 4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextuh(t0, r0, t1); // pextuh t0, r0, t1 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlh(t1, r0, t1); // pextlh t1, r0, t1 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextuh(t4, r0, a3); // pextuh t4, r0, a3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlh(t2, r0, a3); // pextlh t2, r0, a3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->paddw(t3, t1, a0); // paddw t3, t1, a0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pcpyud(t1, t3, r0); // pcpyud t1, t3, r0 + c->lq(a3, 0, t3); // lq a3, 0(t3) + c->paddw(t5, t0, a0); // paddw t5, t0, a0 + c->lq(t0, 0, t1); // lq t0, 0(t1) + c->pcpyud(t6, t5, r0); // pcpyud t6, t5, r0 + c->lq(t1, 0, t5); // lq t1, 0(t5) + c->dsra32(t3, t3, 0); // dsra32 t3, t3, 0 + c->dsra32(t5, t5, 0); // dsra32 t5, t5, 0 + c->paddw(t9, t2, a0); // paddw t9, t2, a0 + c->lq(t2, 0, t6); // lq t2, 0(t6) + c->pcpyud(t6, t9, r0); // pcpyud t6, t9, r0 + c->lq(t3, 0, t3); // lq t3, 0(t3) + c->paddw(t8, t4, a0); // paddw t8, t4, a0 + c->lq(t4, 0, t5); // lq t4, 0(t5) + c->pcpyud(t7, t8, r0); // pcpyud t7, t8, r0 + c->lq(t5, 0, t9); // lq t5, 0(t9) + c->dsra32(t9, t9, 0); // dsra32 t9, t9, 0 + c->dsra32(ra, t8, 0); // dsra32 ra, t8, 0 + // nop // sll r0, r0, 0 + c->lq(t9, 0, t9); // lq t9, 0(t9) + // nop // sll r0, r0, 0 + c->lq(t6, 0, t6); // lq t6, 0(t6) + // nop // sll r0, r0, 0 + c->lq(t8, 0, t8); // lq t8, 0(t8) + // nop // sll r0, r0, 0 + c->lq(ra, 0, ra); // lq ra, 0(ra) + // nop // sll r0, r0, 0 + c->lq(t7, 0, t7); // lq t7, 0(t7) + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf2, a3); // qmtc2.ni vf2, a3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf3, t3); // qmtc2.ni vf3, t3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf4, t0); // qmtc2.ni vf4, t0 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf7, t1); // qmtc2.ni vf7, t1 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf8, t4); // qmtc2.ni vf8, t4 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf9, t2); // qmtc2.ni vf9, t2 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf12, t5); // qmtc2.ni vf12, t5 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf13, t9); // qmtc2.ni vf13, t9 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf14, t6); // qmtc2.ni vf14, t6 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf17, t8); // qmtc2.ni vf17, t8 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf18, ra); // qmtc2.ni vf18, ra + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf19, t7); // qmtc2.ni vf19, t7 + +block_2: + // nop // sll r0, r0, 0 + c->lq(t0, 16, v1); // lq t0, 16(v1) + c->daddiu(a1, a1, -4); // daddiu a1, a1, -4 + exec_0(c); + c->pextub(a3, r0, t0); // pextub a3, r0, t0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlb(t0, r0, t0); // pextlb t0, r0, t0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->psllh(a3, a3, 4); // psllh a3, a3, 4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->psllh(t1, t0, 4); // psllh t1, t0, 4 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextuh(t0, r0, t1); // pextuh t0, r0, t1 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlh(t1, r0, t1); // pextlh t1, r0, t1 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextuh(t4, r0, a3); // pextuh t4, r0, a3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pextlh(t2, r0, a3); // pextlh t2, r0, a3 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->paddw(t3, t1, a0); // paddw t3, t1, a0 + c->mfc1(r0, f31); // mfc1 r0, f31 + c->pcpyud(t1, t3, r0); // pcpyud t1, t3, r0 + c->lq(a3, 0, t3); // lq a3, 0(t3) + c->paddw(t5, t0, a0); // paddw t5, t0, a0 + c->lq(t0, 0, t1); // lq t0, 0(t1) + c->pcpyud(t6, t5, r0); // pcpyud t6, t5, r0 + c->lq(t1, 0, t5); // lq t1, 0(t5) + c->dsra32(t3, t3, 0); // dsra32 t3, t3, 0 + c->dsra32(t5, t5, 0); // dsra32 t5, t5, 0 + c->paddw(t9, t2, a0); // paddw t9, t2, a0 + c->lq(t2, 0, t6); // lq t2, 0(t6) + c->pcpyud(t6, t9, r0); // pcpyud t6, t9, r0 + c->lq(t3, 0, t3); // lq t3, 0(t3) + c->paddw(t8, t4, a0); // paddw t8, t4, a0 + c->lq(t4, 0, t5); // lq t4, 0(t5) + c->pcpyud(t7, t8, r0); // pcpyud t7, t8, r0 + c->lq(t5, 0, t9); // lq t5, 0(t9) + c->dsra32(t9, t9, 0); // dsra32 t9, t9, 0 + c->dsra32(ra, t8, 0); // dsra32 ra, t8, 0 + // nop // sll r0, r0, 0 + c->lq(t9, 0, t9); // lq t9, 0(t9) + // nop // sll r0, r0, 0 + c->lq(t6, 0, t6); // lq t6, 0(t6) + // nop // sll r0, r0, 0 + c->lq(t8, 0, t8); // lq t8, 0(t8) + // nop // sll r0, r0, 0 + c->lq(ra, 0, ra); // lq ra, 0(ra) + // nop // sll r0, r0, 0 + c->lq(t7, 0, t7); // lq t7, 0(t7) + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf2, a3); // qmtc2.ni vf2, a3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf3, t3); // qmtc2.ni vf3, t3 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf4, t0); // qmtc2.ni vf4, t0 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf7, t1); // qmtc2.ni vf7, t1 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf8, t4); // qmtc2.ni vf8, t4 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf9, t2); // qmtc2.ni vf9, t2 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf12, t5); // qmtc2.ni vf12, t5 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf13, t9); // qmtc2.ni vf13, t9 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf14, t6); // qmtc2.ni vf14, t6 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf17, t8); // qmtc2.ni vf17, t8 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf18, ra); // qmtc2.ni vf18, ra + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf19, t7); // qmtc2.ni vf19, t7 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t0, vf22); // qmfc2.ni t0, vf22 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t1, vf23); // qmfc2.ni t1, vf23 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf24); // qmfc2.ni a3, vf24 + bc = ((s64)c->sgpr64(t0)) >= 0; // bgez t0, L76 + c->mov128_gpr_vf(t0, vf25); // qmfc2.ni t0, vf25 + if (bc) {goto block_4;} // branch non-likely + + c->sb(a2, 3, v1); // sb a2, 3(v1) + // nop // sll r0, r0, 0 + +block_4: + bc = ((s64)c->sgpr64(t1)) >= 0; // bgez t1, L77 + c->daddiu(v1, v1, 4); // daddiu v1, v1, 4 + if (bc) {goto block_6;} // branch non-likely + + c->sb(a2, 3, v1); // sb a2, 3(v1) + // nop // sll r0, r0, 0 + +block_6: + bc = ((s64)c->sgpr64(a3)) >= 0; // bgez a3, L78 + c->daddiu(v1, v1, 4); // daddiu v1, v1, 4 + if (bc) {goto block_8;} // branch non-likely + + c->sb(a2, 3, v1); // sb a2, 3(v1) + // nop // sll r0, r0, 0 + +block_8: + bc = ((s64)c->sgpr64(t0)) >= 0; // bgez t0, L79 + c->daddiu(v1, v1, 4); // daddiu v1, v1, 4 + if (bc) {goto block_10;} // branch non-likely + + c->sb(a2, 3, v1); // sb a2, 3(v1) + // nop // sll r0, r0, 0 + +block_10: + bc = ((s64)c->sgpr64(a1)) > 0; // bgtz a1, L75 + c->daddiu(v1, v1, 4); // daddiu v1, v1, 4 + if (bc) {goto block_2;} // branch non-likely + + +block_11: + bc = ((s64)c->sgpr64(a1)) <= 0; // blez a1, L83 + // nop // sll r0, r0, 0 + if (bc) {goto block_15;} // branch non-likely + + +block_12: + c->lbu(a3, 0, v1); // lbu a3, 0(v1) + c->lbu(t0, 1, v1); // lbu t0, 1(v1) + c->lbu(a2, 2, v1); // lbu a2, 2(v1) + c->dsll(a3, a3, 4); // dsll a3, a3, 4 + c->dsll(t0, t0, 4); // dsll t0, t0, 4 + c->dsll(a2, a2, 4); // dsll a2, a2, 4 + c->daddu(a3, a3, a0); // daddu a3, a3, a0 + c->daddu(t0, t0, a0); // daddu t0, t0, a0 + c->daddu(a2, a2, a0); // daddu a2, a2, a0 + c->lqc2(vf2, 0, a3); // lqc2 vf2, 0(a3) + c->lqc2(vf3, 0, t0); // lqc2 vf3, 0(t0) + c->lqc2(vf4, 0, a2); // lqc2 vf4, 0(a2) + c->vsub(DEST::xyzw, vf5, vf3, vf2); // vsub.xyzw vf5, vf3, vf2 + c->vsub(DEST::xyzw, vf6, vf4, vf2); // vsub.xyzw vf6, vf4, vf2 + c->vopmula(vf5, vf6); // vopmula.xyz acc, vf5, vf6 + c->vopmsub(vf5, vf6, vf5); // vopmsub.xyz vf5, vf6, vf5 + c->vmul(DEST::xyz, vf5, vf5, vf1); // vmul.xyz vf5, vf5, vf1 + c->vadd_bc(DEST::y, BC::x, vf5, vf5, vf5); // vaddx.y vf5, vf5, vf5 + c->vadd_bc(DEST::y, BC::z, vf5, vf5, vf5); // vaddz.y vf5, vf5, vf5 + c->mov128_gpr_vf(a2, vf5); // qmfc2.i a2, vf5 + // nop // sll r0, r0, 0 + bc = ((s64)c->sgpr64(a2)) >= 0; // bgez a2, L82 + c->addiu(a2, r0, 1); // addiu a2, r0, 1 + if (bc) {goto block_14;} // branch non-likely + + c->sb(a2, 3, v1); // sb a2, 3(v1) + +block_14: + c->daddiu(a1, a1, -1); // daddiu a1, a1, -1 + bc = c->sgpr64(a1) != 0; // bne a1, r0, L81 + c->daddiu(v1, v1, 4); // daddiu v1, v1, 4 + if (bc) {goto block_12;} // branch non-likely + + +block_15: + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + c->ld(ra, 0, sp); // ld ra, 0(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 16); // daddiu sp, sp, 16 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + gLinkedFunctionTable.reg("shadow-find-facing-double-tris", execute, 128); +} + +} // namespace shadow_find_facing_double_tris +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_find_double_edges { +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->lw(a2, 16, a1); // lw a2, 16(a1) + c->lh(a3, 18, a0); // lh a3, 18(a0) + c->mov64(v1, a2); // or v1, a2, r0 + c->lw(t1, 40, a0); // lw t1, 40(a0) + bc = c->sgpr64(a3) == 0; // beq a3, r0, L73 + c->lw(t0, 12, a1); // lw t0, 12(a1) + if (bc) {goto block_7;} // branch non-likely + + c->daddu(a0, t1, a0); // daddu a0, t1, a0 + c->sw(a2, 40, a1); // sw a2, 40(a1) + c->sw(a0, 8, a1); // sw a0, 8(a1) + c->mov64(t1, a0); // or t1, a0, r0 + c->addiu(t2, r0, 255); // addiu t2, r0, 255 + +block_2: + c->daddiu(a3, a3, -1); // daddiu a3, a3, -1 + c->lbu(t3, 3, t1); // lbu t3, 3(t1) + // nop // sll r0, r0, 0 + c->lbu(t4, 2, t1); // lbu t4, 2(t1) + bc = c->sgpr64(t3) == c->sgpr64(t2); // beq t3, t2, L71 + c->gprs[t5].du64[0] = 0; // or t5, r0, r0 + if (bc) {goto block_5;} // branch non-likely + + c->dsll(t4, t4, 2); // dsll t4, t4, 2 + c->dsll(t3, t3, 2); // dsll t3, t3, 2 + c->daddu(t4, t4, t0); // daddu t4, t4, t0 + c->daddu(t3, t3, t0); // daddu t3, t3, t0 + // nop // sll r0, r0, 0 + c->lbu(t4, 3, t4); // lbu t4, 3(t4) + // nop // sll r0, r0, 0 + c->lbu(t3, 3, t3); // lbu t3, 3(t3) + bc = c->sgpr64(t4) == c->sgpr64(t3); // beq t4, t3, L72 + // nop // sll r0, r0, 0 + if (bc) {goto block_6;} // branch non-likely + + c->sltiu(t4, t4, 1); // sltiu t4, t4, 1 + // nop // sll r0, r0, 0 + c->sltu(t3, r0, t3); // sltu t3, r0, t3 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sh(t4, 2, v1); // sh t4, 2(v1) + c->dsubu(t4, t1, a0); // dsubu t4, t1, a0 + c->sh(t3, 6, v1); // sh t3, 6(v1) + // nop // sll r0, r0, 0 + c->sh(t4, 0, v1); // sh t4, 0(v1) + // nop // sll r0, r0, 0 + c->sh(t4, 4, v1); // sh t4, 4(v1) + //beq r0, r0, L72 // beq r0, r0, L72 + c->daddiu(v1, v1, 8); // daddiu v1, v1, 8 + goto block_6; // branch always + + +block_5: + c->dsll(t3, t4, 2); // dsll t3, t4, 2 + // nop // sll r0, r0, 0 + c->daddu(t3, t3, t0); // daddu t3, t3, t0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->lbu(t3, 3, t3); // lbu t3, 3(t3) + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->sltiu(t3, t3, 1); // sltiu t3, t3, 1 + c->dsubu(t4, t1, a0); // dsubu t4, t1, a0 + c->sh(t3, 2, v1); // sh t3, 2(v1) + c->sh(t4, 0, v1); // sh t4, 0(v1) + c->daddiu(v1, v1, 4); // daddiu v1, v1, 4 + +block_6: + bc = c->sgpr64(a3) != 0; // bne a3, r0, L70 + c->daddiu(t1, t1, 4); // daddiu t1, t1, 4 + if (bc) {goto block_2;} // branch non-likely + + +block_7: + c->dsubu(a0, v1, a2); // dsubu a0, v1, a2 + c->dsra(a0, a0, 2); // dsra a0, a0, 2 + c->sw(a0, 28, a1); // sw a0, 28(a1) + c->sw(v1, 16, a1); // sw v1, 16(a1) + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + gLinkedFunctionTable.reg("shadow-find-double-edges", execute, 128); +} + +} // namespace shadow_find_double_edges +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_add_verts { +struct Cache { + void* shadow_data; // *shadow-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->load_symbol2(v1, cache.shadow_data); // lw v1, *shadow-data*(s7) + c->mov64(v1, v1); // or v1, v1, r0 + c->lh(a0, 8, a0); // lh a0, 8(a0) + c->addiu(t1, r0, 4); // addiu t1, r0, 4 + c->lq(t0, 0, v1); // lq t0, 0(v1) + // nop // sll r0, r0, 0 + c->sq(t0, 0, a2); // sq t0, 0(a2) + c->sh(a0, 0, a2); // sh a0, 0(a2) + c->sb(a0, 14, a2); // sb a0, 14(a2) + c->sh(t1, 12, a2); // sh t1, 12(a2) + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->lw(t3, 0, a1); // lw t3, 0(a1) + c->sll(v1, a0, 4); // sll v1, a0, 4 + c->mov64(t2, a2); // or t2, a2, r0 + c->mov64(t1, a0); // or t1, a0, r0 + c->daddiu(t4, t1, -4); // daddiu t4, t1, -4 + c->mov64(t2, t2); // or t2, t2, r0 + bc = ((s64)c->sgpr64(t4)) < 0; // bltz t4, L63 + c->mov64(t3, t3); // or t3, t3, r0 + if (bc) {goto block_2;} // branch non-likely + + +block_1: + // nop // sll r0, r0, 0 + c->lq(t7, 0, t3); // lq t7, 0(t3) + // nop // sll r0, r0, 0 + c->lq(t4, 16, t3); // lq t4, 16(t3) + c->daddiu(t1, t1, -4); // daddiu t1, t1, -4 + c->lq(t5, 32, t3); // lq t5, 32(t3) + c->daddiu(t2, t2, 64); // daddiu t2, t2, 64 + c->lq(t6, 48, t3); // lq t6, 48(t3) + c->daddiu(t3, t3, 64); // daddiu t3, t3, 64 + c->sq(t7, -64, t2); // sq t7, -64(t2) + c->daddiu(t7, t1, -4); // daddiu t7, t1, -4 + c->sq(t4, -48, t2); // sq t4, -48(t2) + // nop // sll r0, r0, 0 + c->sq(t5, -32, t2); // sq t5, -32(t2) + bc = ((s64)c->sgpr64(t7)) >= 0; // bgez t7, L62 + c->sq(t6, -16, t2); // sq t6, -16(t2) + if (bc) {goto block_1;} // branch non-likely + + +block_2: + bc = c->sgpr64(t1) == 0; // beq t1, r0, L64 + c->lq(t4, 0, t3); // lq t4, 0(t3) + if (bc) {goto block_7;} // branch non-likely + + c->daddiu(t3, t3, 16); // daddiu t3, t3, 16 + c->daddiu(t2, t2, 16); // daddiu t2, t2, 16 + c->daddiu(t1, t1, -1); // daddiu t1, t1, -1 + c->sq(t4, -16, t2); // sq t4, -16(t2) + bc = c->sgpr64(t1) == 0; // beq t1, r0, L64 + c->lq(t4, 0, t3); // lq t4, 0(t3) + if (bc) {goto block_7;} // branch non-likely + + c->daddiu(t3, t3, 16); // daddiu t3, t3, 16 + c->daddiu(t2, t2, 16); // daddiu t2, t2, 16 + c->daddiu(t1, t1, -1); // daddiu t1, t1, -1 + c->sq(t4, -16, t2); // sq t4, -16(t2) + bc = c->sgpr64(t1) == 0; // beq t1, r0, L64 + c->lq(t4, 0, t3); // lq t4, 0(t3) + if (bc) {goto block_7;} // branch non-likely + + c->daddiu(t3, t3, 16); // daddiu t3, t3, 16 + c->daddiu(t2, t2, 16); // daddiu t2, t2, 16 + c->daddiu(t1, t1, -1); // daddiu t1, t1, -1 + c->sq(t4, -16, t2); // sq t4, -16(t2) + bc = c->sgpr64(t1) == 0; // beq t1, r0, L64 + c->lq(t4, 0, t3); // lq t4, 0(t3) + if (bc) {goto block_7;} // branch non-likely + + c->daddiu(t3, t3, 16); // daddiu t3, t3, 16 + c->daddiu(t2, t2, 16); // daddiu t2, t2, 16 + c->daddiu(t1, t1, -1); // daddiu t1, t1, -1 + c->sq(t4, -16, t2); // sq t4, -16(t2) + +block_7: + c->gprs[t1].du64[0] = 0; // or t1, r0, r0 + c->daddu(v0, a2, v1); // daddu v0, a2, v1 + bc = c->sgpr64(a3) != 0; // bne a3, r0, L68 + c->addiu(a2, r0, 174); // addiu a2, r0, 174 + if (bc) {goto block_16;} // branch non-likely + + c->sq(t0, 0, v0); // sq t0, 0(v0) + c->sh(a0, 0, v0); // sh a0, 0(v0) + c->sb(a0, 14, v0); // sb a0, 14(v0) + c->sw(r0, 8, v0); // sw r0, 8(v0) + c->sh(a2, 12, v0); // sh a2, 12(v0) + c->lw(a3, 44, a1); // lw a3, 44(a1) + c->daddiu(a1, v0, 16); // daddiu a1, v0, 16 + c->mov64(a2, a1); // or a2, a1, r0 + c->daddiu(t0, a0, -4); // daddiu t0, a0, -4 + c->mov64(a2, a2); // or a2, a2, r0 + bc = ((s64)c->sgpr64(t0)) < 0; // bltz t0, L66 + c->mov64(a3, a3); // or a3, a3, r0 + if (bc) {goto block_10;} // branch non-likely + + +block_9: + // nop // sll r0, r0, 0 + c->lq(t3, 0, a3); // lq t3, 0(a3) + // nop // sll r0, r0, 0 + c->lq(t0, 16, a3); // lq t0, 16(a3) + c->daddiu(a0, a0, -4); // daddiu a0, a0, -4 + c->lq(t1, 32, a3); // lq t1, 32(a3) + c->daddiu(a2, a2, 64); // daddiu a2, a2, 64 + c->lq(t2, 48, a3); // lq t2, 48(a3) + c->daddiu(a3, a3, 64); // daddiu a3, a3, 64 + c->sq(t3, -64, a2); // sq t3, -64(a2) + c->daddiu(t3, a0, -4); // daddiu t3, a0, -4 + c->sq(t0, -48, a2); // sq t0, -48(a2) + // nop // sll r0, r0, 0 + c->sq(t1, -32, a2); // sq t1, -32(a2) + bc = ((s64)c->sgpr64(t3)) >= 0; // bgez t3, L65 + c->sq(t2, -16, a2); // sq t2, -16(a2) + if (bc) {goto block_9;} // branch non-likely + + +block_10: + bc = c->sgpr64(a0) == 0; // beq a0, r0, L67 + c->lq(t0, 0, a3); // lq t0, 0(a3) + if (bc) {goto block_15;} // branch non-likely + + c->daddiu(a3, a3, 16); // daddiu a3, a3, 16 + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->daddiu(a0, a0, -1); // daddiu a0, a0, -1 + c->sq(t0, -16, a2); // sq t0, -16(a2) + bc = c->sgpr64(a0) == 0; // beq a0, r0, L67 + c->lq(t0, 0, a3); // lq t0, 0(a3) + if (bc) {goto block_15;} // branch non-likely + + c->daddiu(a3, a3, 16); // daddiu a3, a3, 16 + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->daddiu(a0, a0, -1); // daddiu a0, a0, -1 + c->sq(t0, -16, a2); // sq t0, -16(a2) + bc = c->sgpr64(a0) == 0; // beq a0, r0, L67 + c->lq(t0, 0, a3); // lq t0, 0(a3) + if (bc) {goto block_15;} // branch non-likely + + c->daddiu(a3, a3, 16); // daddiu a3, a3, 16 + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->daddiu(a0, a0, -1); // daddiu a0, a0, -1 + c->sq(t0, -16, a2); // sq t0, -16(a2) + bc = c->sgpr64(a0) == 0; // beq a0, r0, L67 + c->lq(t0, 0, a3); // lq t0, 0(a3) + if (bc) {goto block_15;} // branch non-likely + + c->daddiu(a3, a3, 16); // daddiu a3, a3, 16 + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->daddiu(a0, a0, -1); // daddiu a0, a0, -1 + c->sq(t0, -16, a2); // sq t0, -16(a2) + +block_15: + c->gprs[a0].du64[0] = 0; // or a0, r0, r0 + c->daddu(v0, a1, v1); // daddu v0, a1, v1 + +block_16: + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.shadow_data = intern_from_c(-1, 0, "*shadow-data*").c(); + gLinkedFunctionTable.reg("shadow-add-verts", execute, 128); +} + +} // namespace shadow_add_verts +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_add_facing_single_tris { +struct Cache { + void* shadow_data; // *shadow-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->load_symbol2(v1, cache.shadow_data); // lw v1, *shadow-data*(s7) + c->mov64(a3, v1); // or a3, v1, r0 + c->lw(v1, 20, a1); // lw v1, 20(a1) + c->lw(a0, 32, a1); // lw a0, 32(a1) + bc = c->sgpr64(v1) == 0; // beq v1, r0, L60 + c->daddiu(a1, v1, 1); // daddiu a1, v1, 1 + if (bc) {goto block_4;} // branch non-likely + + c->daddiu(a1, a1, 3); // daddiu a1, a1, 3 + c->dsra(t0, a1, 2); // dsra t0, a1, 2 + c->dsll(a1, t0, 2); // dsll a1, t0, 2 + c->daddiu(t0, t0, 1); // daddiu t0, t0, 1 + c->ld(t1, 16, a3); // ld t1, 16(a3) + c->daddu(t0, t1, t0); // daddu t0, t1, t0 + c->lw(a3, 28, a3); // lw a3, 28(a3) + c->sd(t0, 0, a2); // sd t0, 0(a2) + c->addiu(t0, r0, 16728); // addiu t0, r0, 16728 + c->sw(r0, 8, a2); // sw r0, 8(a2) + c->sw(a3, 12, a2); // sw a3, 12(a2) + c->sb(a1, 14, a2); // sb a1, 14(a2) + c->dsll(a1, a1, 2); // dsll a1, a1, 2 + c->sh(t0, 12, a2); // sh t0, 12(a2) + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->daddu(a1, a2, a1); // daddu a1, a2, a1 + c->sq(r0, -16, a1); // sq r0, -16(a1) + c->sw(v1, 0, a2); // sw v1, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + +block_2: + c->lw(a3, 0, a0); // lw a3, 0(a0) + c->daddiu(a0, a0, 4); // daddiu a0, a0, 4 + c->lw(a3, 0, a3); // lw a3, 0(a3) + c->daddiu(v1, v1, -1); // daddiu v1, v1, -1 + c->sw(a3, 0, a2); // sw a3, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + bc = ((s64)c->sgpr64(v1)) > 0; // bgtz v1, L59 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + c->mov64(v1, a1); // or v1, a1, r0 + c->lui(a0, 5376); // lui a0, 5376 + c->ori(a0, a0, 2); // ori a0, a0, 2 + c->sq(r0, 0, v1); // sq r0, 0(v1) + c->sw(a0, 12, v1); // sw a0, 12(v1) + c->daddiu(a2, v1, 16); // daddiu a2, v1, 16 + +block_4: + c->mov64(v0, a2); // or v0, a2, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.shadow_data = intern_from_c(-1, 0, "*shadow-data*").c(); + gLinkedFunctionTable.reg("shadow-add-facing-single-tris", execute, 128); +} + +} // namespace shadow_add_facing_single_tris +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_add_single_edges { +struct Cache { + void* shadow_data; // *shadow-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->load_symbol2(v1, cache.shadow_data); // lw v1, *shadow-data*(s7) + c->mov64(a3, v1); // or a3, v1, r0 + c->lw(v1, 24, a1); // lw v1, 24(a1) + c->lw(a0, 36, a1); // lw a0, 36(a1) + c->lw(a1, 4, a1); // lw a1, 4(a1) + bc = c->sgpr64(v1) == 0; // beq v1, r0, L57 + c->daddiu(t0, v1, 1); // daddiu t0, v1, 1 + if (bc) {goto block_4;} // branch non-likely + + c->daddiu(t0, t0, 3); // daddiu t0, t0, 3 + c->dsra(t1, t0, 2); // dsra t1, t0, 2 + c->dsll(t0, t1, 2); // dsll t0, t1, 2 + c->daddiu(t1, t1, 1); // daddiu t1, t1, 1 + c->ld(t2, 16, a3); // ld t2, 16(a3) + c->daddu(t1, t2, t1); // daddu t1, t2, t1 + c->lw(a3, 28, a3); // lw a3, 28(a3) + c->sd(t1, 0, a2); // sd t1, 0(a2) + c->addiu(t1, r0, 16984); // addiu t1, r0, 16984 + c->sw(r0, 8, a2); // sw r0, 8(a2) + c->sw(a3, 12, a2); // sw a3, 12(a2) + c->sb(t0, 14, a2); // sb t0, 14(a2) + c->dsll(a3, t0, 2); // dsll a3, t0, 2 + c->sh(t1, 12, a2); // sh t1, 12(a2) + c->daddiu(t0, a2, 16); // daddiu t0, a2, 16 + c->daddu(a2, t0, a3); // daddu a2, t0, a3 + c->sq(r0, -16, a2); // sq r0, -16(a2) + c->sw(v1, 0, t0); // sw v1, 0(t0) + c->daddiu(a3, t0, 4); // daddiu a3, t0, 4 + +block_2: + c->lh(t1, 0, a0); // lh t1, 0(a0) + c->lh(t0, 2, a0); // lh t0, 2(a0) + c->daddiu(a0, a0, 4); // daddiu a0, a0, 4 + c->daddu(t1, t1, a1); // daddu t1, t1, a1 + c->lhu(t1, 0, t1); // lhu t1, 0(t1) + c->sh(t0, 2, a3); // sh t0, 2(a3) + c->sh(t1, 0, a3); // sh t1, 0(a3) + c->daddiu(v1, v1, -1); // daddiu v1, v1, -1 + c->daddiu(a3, a3, 4); // daddiu a3, a3, 4 + bc = ((s64)c->sgpr64(v1)) > 0; // bgtz v1, L56 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + c->mov64(v1, a2); // or v1, a2, r0 + c->lui(a0, 5376); // lui a0, 5376 + c->ori(a0, a0, 4); // ori a0, a0, 4 + c->sq(r0, 0, v1); // sq r0, 0(v1) + c->sw(a0, 12, v1); // sw a0, 12(v1) + c->daddiu(a2, v1, 16); // daddiu a2, v1, 16 + +block_4: + c->mov64(v0, a2); // or v0, a2, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.shadow_data = intern_from_c(-1, 0, "*shadow-data*").c(); + gLinkedFunctionTable.reg("shadow-add-single-edges", execute, 128); +} + +} // namespace shadow_add_single_edges +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_add_single_tris { +struct Cache { + void* shadow_data; // *shadow-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->load_symbol2(v1, cache.shadow_data); // lw v1, *shadow-data*(s7) + c->mov64(a3, v1); // or a3, v1, r0 + c->lh(a1, 12, a0); // lh a1, 12(a0) + c->lw(v1, 28, a0); // lw v1, 28(a0) + bc = c->sgpr64(a1) == 0; // beq a1, r0, L54 + c->daddu(v1, v1, a0); // daddu v1, v1, a0 + if (bc) {goto block_4;} // branch non-likely + + c->daddiu(a0, a1, 1); // daddiu a0, a1, 1 + c->daddiu(a0, a0, 3); // daddiu a0, a0, 3 + c->dsra(t0, a0, 2); // dsra t0, a0, 2 + c->dsll(a0, t0, 2); // dsll a0, t0, 2 + c->daddiu(t0, t0, 1); // daddiu t0, t0, 1 + c->ld(t1, 16, a3); // ld t1, 16(a3) + c->daddu(t0, t1, t0); // daddu t0, t1, t0 + c->lw(a3, 28, a3); // lw a3, 28(a3) + c->sd(t0, 0, a2); // sd t0, 0(a2) + c->addiu(t0, r0, 16728); // addiu t0, r0, 16728 + c->sw(r0, 8, a2); // sw r0, 8(a2) + c->sw(a3, 12, a2); // sw a3, 12(a2) + c->sb(a0, 14, a2); // sb a0, 14(a2) + c->dsll(a0, a0, 2); // dsll a0, a0, 2 + c->sh(t0, 12, a2); // sh t0, 12(a2) + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->daddu(a0, a2, a0); // daddu a0, a2, a0 + c->sq(r0, -16, a0); // sq r0, -16(a0) + c->ori(a1, a1, 256); // ori a1, a1, 256 + c->sw(a1, 0, a2); // sw a1, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + +block_2: + c->lw(a3, 0, v1); // lw a3, 0(v1) + c->daddiu(v1, v1, 4); // daddiu v1, v1, 4 + c->daddiu(a1, a1, -1); // daddiu a1, a1, -1 + c->sw(a3, 0, a2); // sw a3, 0(a2) + bc = ((s64)c->sgpr64(a1)) > 0; // bgtz a1, L53 + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + if (bc) {goto block_2;} // branch non-likely + + c->mov64(v1, a0); // or v1, a0, r0 + c->lui(a0, 5376); // lui a0, 5376 + c->ori(a0, a0, 6); // ori a0, a0, 6 + c->sq(r0, 0, v1); // sq r0, 0(v1) + c->sw(a0, 12, v1); // sw a0, 12(v1) + c->daddiu(a2, v1, 16); // daddiu a2, v1, 16 + +block_4: + c->mov64(v0, a2); // or v0, a2, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.shadow_data = intern_from_c(-1, 0, "*shadow-data*").c(); + gLinkedFunctionTable.reg("shadow-add-single-tris", execute, 128); +} + +} // namespace shadow_add_single_tris +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_add_double_tris { +struct Cache { + void* shadow_data; // *shadow-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->load_symbol2(v1, cache.shadow_data); // lw v1, *shadow-data*(s7) + c->mov64(a3, v1); // or a3, v1, r0 + c->lh(v1, 16, a0); // lh v1, 16(a0) + c->lw(a0, 12, a1); // lw a0, 12(a1) + bc = c->sgpr64(v1) == 0; // beq v1, r0, L51 + c->daddiu(a1, v1, 1); // daddiu a1, v1, 1 + if (bc) {goto block_4;} // branch non-likely + + c->daddiu(a1, a1, 3); // daddiu a1, a1, 3 + c->dsra(t0, a1, 2); // dsra t0, a1, 2 + c->dsll(a1, t0, 2); // dsll a1, t0, 2 + c->daddiu(t0, t0, 1); // daddiu t0, t0, 1 + c->ld(t1, 16, a3); // ld t1, 16(a3) + c->daddu(t0, t1, t0); // daddu t0, t1, t0 + c->lw(a3, 28, a3); // lw a3, 28(a3) + c->sd(t0, 0, a2); // sd t0, 0(a2) + c->addiu(t0, r0, 16728); // addiu t0, r0, 16728 + c->sw(r0, 8, a2); // sw r0, 8(a2) + c->sw(a3, 12, a2); // sw a3, 12(a2) + c->sb(a1, 14, a2); // sb a1, 14(a2) + c->dsll(a1, a1, 2); // dsll a1, a1, 2 + c->sh(t0, 12, a2); // sh t0, 12(a2) + c->daddiu(a2, a2, 16); // daddiu a2, a2, 16 + c->daddu(a1, a2, a1); // daddu a1, a2, a1 + c->sq(r0, -16, a1); // sq r0, -16(a1) + c->sw(v1, 0, a2); // sw v1, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + +block_2: + c->lw(a3, 0, a0); // lw a3, 0(a0) + c->daddiu(a0, a0, 4); // daddiu a0, a0, 4 + c->daddiu(v1, v1, -1); // daddiu v1, v1, -1 + c->sw(a3, 0, a2); // sw a3, 0(a2) + c->daddiu(a2, a2, 4); // daddiu a2, a2, 4 + bc = ((s64)c->sgpr64(v1)) > 0; // bgtz v1, L50 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + c->mov64(v1, a1); // or v1, a1, r0 + c->lui(a0, 5376); // lui a0, 5376 + c->ori(a0, a0, 6); // ori a0, a0, 6 + c->sq(r0, 0, v1); // sq r0, 0(v1) + c->sw(a0, 12, v1); // sw a0, 12(v1) + c->daddiu(a2, v1, 16); // daddiu a2, v1, 16 + +block_4: + c->mov64(v0, a2); // or v0, a2, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.shadow_data = intern_from_c(-1, 0, "*shadow-data*").c(); + gLinkedFunctionTable.reg("shadow-add-double-tris", execute, 128); +} + +} // namespace shadow_add_double_tris +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_add_double_edges { +struct Cache { + void* shadow_data; // *shadow-data* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->load_symbol2(v1, cache.shadow_data); // lw v1, *shadow-data*(s7) + c->mov64(a3, v1); // or a3, v1, r0 + c->lw(v1, 28, a1); // lw v1, 28(a1) + c->lw(a0, 40, a1); // lw a0, 40(a1) + c->lw(a1, 8, a1); // lw a1, 8(a1) + bc = c->sgpr64(v1) == 0; // beq v1, r0, L48 + c->daddiu(t0, v1, 1); // daddiu t0, v1, 1 + if (bc) {goto block_4;} // branch non-likely + + c->daddiu(t0, t0, 3); // daddiu t0, t0, 3 + c->dsra(t1, t0, 2); // dsra t1, t0, 2 + c->dsll(t0, t1, 2); // dsll t0, t1, 2 + c->daddiu(t1, t1, 1); // daddiu t1, t1, 1 + c->ld(t2, 16, a3); // ld t2, 16(a3) + c->daddu(t1, t2, t1); // daddu t1, t2, t1 + c->lw(a3, 28, a3); // lw a3, 28(a3) + c->sd(t1, 0, a2); // sd t1, 0(a2) + c->addiu(t1, r0, 16984); // addiu t1, r0, 16984 + c->sw(r0, 8, a2); // sw r0, 8(a2) + c->sw(a3, 12, a2); // sw a3, 12(a2) + c->sb(t0, 14, a2); // sb t0, 14(a2) + c->dsll(a3, t0, 2); // dsll a3, t0, 2 + c->sh(t1, 12, a2); // sh t1, 12(a2) + c->daddiu(t0, a2, 16); // daddiu t0, a2, 16 + c->daddu(a2, t0, a3); // daddu a2, t0, a3 + c->sq(r0, -16, a2); // sq r0, -16(a2) + c->sw(v1, 0, t0); // sw v1, 0(t0) + c->daddiu(a3, t0, 4); // daddiu a3, t0, 4 + +block_2: + c->lh(t1, 0, a0); // lh t1, 0(a0) + c->lh(t0, 2, a0); // lh t0, 2(a0) + c->daddiu(a0, a0, 4); // daddiu a0, a0, 4 + c->daddu(t1, t1, a1); // daddu t1, t1, a1 + c->lhu(t1, 0, t1); // lhu t1, 0(t1) + c->sh(t0, 2, a3); // sh t0, 2(a3) + c->sh(t1, 0, a3); // sh t1, 0(a3) + c->daddiu(v1, v1, -1); // daddiu v1, v1, -1 + c->daddiu(a3, a3, 4); // daddiu a3, a3, 4 + bc = ((s64)c->sgpr64(v1)) > 0; // bgtz v1, L47 + // nop // sll r0, r0, 0 + if (bc) {goto block_2;} // branch non-likely + + c->mov64(v1, a2); // or v1, a2, r0 + c->lui(a0, 5376); // lui a0, 5376 + c->ori(a0, a0, 4); // ori a0, a0, 4 + c->sq(r0, 0, v1); // sq r0, 0(v1) + c->sw(a0, 12, v1); // sw a0, 12(v1) + c->daddiu(a2, v1, 16); // daddiu a2, v1, 16 + +block_4: + c->mov64(v0, a2); // or v0, a2, r0 + //jr ra // jr ra + c->daddu(sp, sp, r0); // daddu sp, sp, r0 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.shadow_data = intern_from_c(-1, 0, "*shadow-data*").c(); + gLinkedFunctionTable.reg("shadow-add-double-edges", execute, 128); +} + +} // namespace shadow_add_double_edges +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +// clang-format off +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/jak3/kscheme.h" +using ::jak3::intern_from_c; +namespace Mips2C::jak3 { +namespace shadow_execute { +struct Cache { + void* fake_scratchpad_data; // *fake-scratchpad-data* + void* gsf_buffer; // *gsf-buffer* + void* math_camera; // *math-camera* + void* shadow_debug; // *shadow-debug* + void* camera_pos; // camera-pos + void* debug_draw_settings; // debug-draw-settings + void* flush_cache; // flush-cache + void* shadow_add_double_edges; // shadow-add-double-edges + void* shadow_add_double_tris; // shadow-add-double-tris + void* shadow_add_facing_single_tris; // shadow-add-facing-single-tris + void* shadow_add_single_edges; // shadow-add-single-edges + void* shadow_add_single_tris; // shadow-add-single-tris + void* shadow_add_verts; // shadow-add-verts + void* shadow_calc_dual_verts; // shadow-calc-dual-verts + void* shadow_find_double_edges; // shadow-find-double-edges + void* shadow_find_facing_double_tris; // shadow-find-facing-double-tris + void* shadow_find_facing_single_tris; // shadow-find-facing-single-tris + void* shadow_find_single_edges; // shadow-find-single-edges + void* shadow_init_vars; // shadow-init-vars + void* shadow_scissor_edges; // shadow-scissor-edges + void* shadow_scissor_top; // shadow-scissor-top + void* shadow_xform_verts; // shadow-xform-verts +} cache; + +u64 execute(void* ctxt) { + u32 sadr, tadr; + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + bool cop1_bc = false; + c->daddiu(sp, sp, -112); // daddiu sp, sp, -112 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->sq(s1, 16, sp); // sq s1, 16(sp) + c->sq(s2, 32, sp); // sq s2, 32(sp) + c->sq(s3, 48, sp); // sq s3, 48(sp) + c->sq(s4, 64, sp); // sq s4, 64(sp) + c->sq(s5, 80, sp); // sq s5, 80(sp) + c->sq(gp, 96, sp); // sq gp, 96(sp) + c->mov64(gp, a1); // or gp, a1, r0 + c->mov64(s4, a0); // or s4, a0, r0 + c->addiu(v1, r0, 0); // addiu v1, r0, 0 + get_fake_spad_addr2(v1, cache.fake_scratchpad_data, 0, c);// lui v1, 28672 + c->daddiu(s5, v1, 40); // daddiu s5, v1, 40 + c->load_symbol2(t9, cache.flush_cache); // lw t9, flush-cache(s7) + c->addiu(a0, r0, 0); // addiu a0, r0, 0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + //beq r0, r0, L40 // beq r0, r0, L40 + // nop // sll r0, r0, 0 + goto block_37; // branch always + + +block_1: + c->lui(v1, 4096); // lui v1, 4096 + c->ori(v1, v1, 54272); // ori v1, v1, 54272 + c->addiu(a0, r0, 48); // addiu a0, r0, 48 + c->mov64(a1, v1); // or a1, v1, r0 + +/* +block_2: + c->lw(a2, 0, a1); // lw a2, 0(a1) + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->andi(a2, a2, 256); // andi a2, a2, 256 + // nop // sll r0, r0, 0 + bc = c->sgpr64(a2) == 0; // beq a2, r0, L24 + // nop // sll r0, r0, 0 + if (bc) {goto block_4;} // branch non-likely + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + //beq r0, r0, L23 // beq r0, r0, L23 + // nop // sll r0, r0, 0 + goto block_2; // branch always + + +block_4: + c->gprs[a1].du64[0] = 0; // or a1, r0, r0 + c->mov64(a1, v1); // or a1, v1, r0 + c->mov64(a2, s5); // or a2, s5, r0 + c->lw(a3, 0, a1); // lw a3, 0(a1) + c->andi(a3, a3, 256); // andi a3, a3, 256 + bc = c->sgpr64(a3) == 0; // beq a3, r0, L26 + DANGER jump to delay slot, this MUST be fixed manually! + c->lw(a3, 0, a2); // lw a3, 0(a2) + if (bc) {goto block_-1;} // branch non-likely + + +block_5: + c->lw(a3, 0, a2); // lw a3, 0(a2) + // nop // sll r0, r0, 0 + c->lw(t0, 0, a1); // lw t0, 0(a1) + // nop // sll r0, r0, 0 + c->andi(t0, t0, 256); // andi t0, t0, 256 + c->daddiu(a3, a3, 1); // daddiu a3, a3, 1 + bc = c->sgpr64(t0) != 0; // bne t0, r0, L25 + c->sw(a3, 0, a2); // sw a3, 0(a2) + if (bc) {goto block_5;} // branch non-likely +*/ + + c->gprs[a1].du64[0] = 0; // or a1, r0, r0 + sadr = c->sgpr64(a0); // c->sw(a0, 128, v1); // sw a0, 128(v1) + tadr = c->sgpr64(s4); // c->sw(s4, 48, v1); // sw s4, 48(v1) + // c->sw(r0, 32, v1); + // Unknown instr: sync.l + c->addiu(a0, r0, 324); // addiu a0, r0, 324 + // c->sw(a0, 0, v1); // sw a0, 0(v1) + spad_to_dma_blerc_chain(cache.fake_scratchpad_data, sadr, tadr); + // Unknown instr: sync.l + c->mov64(a0, s5); // or a0, s5, r0 +/* + c->lw(a1, 0, v1); // lw a1, 0(v1) + c->andi(a1, a1, 256); // andi a1, a1, 256 + bc = c->sgpr64(a1) == 0; // beq a1, r0, L28 + DANGER jump to delay slot, this MUST be fixed manually! + c->lw(a1, 0, a0); // lw a1, 0(a0) + if (bc) {goto block_-1;} // branch non-likely + + +block_8: + c->lw(a1, 0, a0); // lw a1, 0(a0) + // nop // sll r0, r0, 0 + c->lw(a2, 0, v1); // lw a2, 0(v1) + // nop // sll r0, r0, 0 + c->andi(a2, a2, 256); // andi a2, a2, 256 + c->daddiu(a1, a1, 1); // daddiu a1, a1, 1 + bc = c->sgpr64(a2) != 0; // bne a2, r0, L27 + c->sw(a1, 0, a0); // sw a1, 0(a0) + if (bc) {goto block_8;} // branch non-likely +*/ + + c->gprs[v1].du64[0] = 0; // or v1, r0, r0 + get_fake_spad_addr2(s4, cache.fake_scratchpad_data, 0, c);// lui s4, 28672 + c->addiu(v1, r0, 160); // addiu v1, r0, 160 + c->daddu(s2, v1, s4); // daddu s2, v1, s4 + c->lw(v1, 56, s4); // lw v1, 56(s4) + c->daddiu(s1, s4, 64); // daddiu s1, s4, 64 + c->load_symbol2(s3, cache.gsf_buffer); // lw s3, *gsf-buffer*(s7) + c->sw(v1, 68, s3); // sw v1, 68(s3) + c->lw(v1, 12, s1); // lw v1, 12(s1) + c->andi(v1, v1, 32); // andi v1, v1, 32 + bc = c->sgpr64(v1) != 0; // bne v1, r0, L39 + c->mov64(v1, s7); // or v1, s7, r0 + if (bc) {goto block_36;} // branch non-likely + + c->load_symbol2(v1, cache.shadow_debug); // lw v1, *shadow-debug*(s7) + bc = c->sgpr64(s7) == c->sgpr64(v1); // beq s7, v1, L29 + c->mov64(v1, s7); // or v1, s7, r0 + if (bc) {goto block_13;} // branch non-likely + + c->load_symbol2(t9, cache.debug_draw_settings); // lw t9, debug-draw-settings(s7) + c->mov64(a0, s1); // or a0, s1, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + +block_13: + c->daddiu(v1, s3, 80); // daddiu v1, s3, 80 + c->daddu(a0, r0, s1); // daddu a0, r0, s1 + c->daddiu(a1, s1, 16); // daddiu a1, s1, 16 + c->lwc1(f0, 28, s1); // lwc1 f0, 28(s1) + c->lqc2(vf2, 0, a1); // lqc2 vf2, 0(a1) + c->lqc2(vf1, 0, a0); // lqc2 vf1, 0(a0) + c->mfc1(a0, f0); // mfc1 a0, f0 + c->mov128_vf_gpr(vf3, a0); // qmtc2.i vf3, a0 + c->vadd_bc(DEST::w, BC::x, vf4, vf0, vf0); // vaddx.w vf4, vf0, vf0 + c->vmula_bc(DEST::xyzw, BC::x, vf2, vf3); // vmulax.xyzw acc, vf2, vf3 + c->vmadd_bc(DEST::xyz, BC::w, vf4, vf1, vf0); // vmaddw.xyz vf4, vf1, vf0 + c->sqc2(vf4, 0, v1); // sqc2 vf4, 0(v1) + c->lw(v1, 12, s1); // lw v1, 12(s1) + c->andi(v1, v1, 4); // andi v1, v1, 4 + bc = c->sgpr64(v1) == 0; // beq v1, r0, L30 + // nop // sll r0, r0, 0 + if (bc) {goto block_15;} // branch non-likely + + c->lq(v1, 32, s1); // lq v1, 32(s1) + c->sq(v1, 96, s3); // sq v1, 96(s3) + c->lq(v1, 48, s1); // lq v1, 48(s1) + c->sq(v1, 112, s3); // sq v1, 112(s3) + //beq r0, r0, L31 // beq r0, r0, L31 + // nop // sll r0, r0, 0 + goto block_16; // branch always + + +block_15: + c->daddiu(v1, s3, 96); // daddiu v1, s3, 96 + c->lwc1(f0, 32, s1); // lwc1 f0, 32(s1) + c->swc1(f0, 0, v1); // swc1 f0, 0(v1) + c->lwc1(f0, 36, s1); // lwc1 f0, 36(s1) + c->swc1(f0, 4, v1); // swc1 f0, 4(v1) + c->lwc1(f0, 40, s1); // lwc1 f0, 40(s1) + c->swc1(f0, 8, v1); // swc1 f0, 8(v1) + c->lwc1(f0, 44, s1); // lwc1 f0, 44(s1) + c->lwc1(f1, 4, s1); // lwc1 f1, 4(s1) + c->subs(f0, f0, f1); // sub.s f0, f0, f1 + c->swc1(f0, 12, v1); // swc1 f0, 12(v1) + c->daddiu(v1, s3, 112); // daddiu v1, s3, 112 + c->lwc1(f0, 48, s1); // lwc1 f0, 48(s1) + c->swc1(f0, 0, v1); // swc1 f0, 0(v1) + c->lwc1(f0, 52, s1); // lwc1 f0, 52(s1) + c->swc1(f0, 4, v1); // swc1 f0, 4(v1) + c->lwc1(f0, 56, s1); // lwc1 f0, 56(s1) + c->swc1(f0, 8, v1); // swc1 f0, 8(v1) + c->lwc1(f0, 60, s1); // lwc1 f0, 60(s1) + c->lwc1(f1, 4, s1); // lwc1 f1, 4(s1) + c->subs(f0, f0, f1); // sub.s f0, f0, f1 + c->swc1(f0, 12, v1); // swc1 f0, 12(v1) + +block_16: + c->lw(v1, 12, s1); // lw v1, 12(s1) + c->andi(v1, v1, 1); // andi v1, v1, 1 + if (((s64)c->sgpr64(v1)) == ((s64)0)) { // beql v1, r0, L32 + c->daddiu(v1, s7, 4); // daddiu v1, s7, 4 + goto block_20; + } + +// block_18: + c->load_symbol2(t9, cache.camera_pos); // lw t9, camera-pos(s7) + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(a0, v0); // or a0, v0, r0 + c->daddiu(v1, s3, 96); // daddiu v1, s3, 96 + c->lwc1(f0, 0, a0); // lwc1 f0, 0(a0) + c->lwc1(f1, 4, a0); // lwc1 f1, 4(a0) + c->lwc1(f2, 8, a0); // lwc1 f2, 8(a0) + c->lwc1(f3, 0, v1); // lwc1 f3, 0(v1) + c->lwc1(f4, 4, v1); // lwc1 f4, 4(v1) + c->lwc1(f5, 8, v1); // lwc1 f5, 8(v1) + // Unknown instr: mula.s f0, f3 + // Unknown instr: madda.s f1, f4 + // Unknown instr: madd.s f0, f2, f5 + c->fprs[f0] = (c->fprs[f2] * c->fprs[f5]) + (c->fprs[f1] * c->fprs[f4]) + (c->fprs[f0] * c->fprs[f3]); + + c->mfc1(v1, f0); // mfc1 v1, f0 + c->mtc1(f0, v1); // mtc1 f0, v1 + c->lwc1(f1, 108, s3); // lwc1 f1, 108(s3) + c->negs(f1, f1); // neg.s f1, f1 + cop1_bc = c->fprs[f0] < c->fprs[f1]; // c.lt.s f0, f1 + bc = !cop1_bc; // bc1f L32 + c->daddiu(v1, s7, 4); // daddiu v1, s7, 4 + if (bc) {goto block_20;} // branch non-likely + + c->mov64(v1, s7); // or v1, s7, r0 + +block_20: + bc = c->sgpr64(s7) == c->sgpr64(v1); // beq s7, v1, L39 + c->mov64(a0, s7); // or a0, s7, r0 + if (bc) {goto block_36;} // branch non-likely + + c->daddiu(a0, s3, 80); // daddiu a0, s3, 80 + c->daddiu(v1, s3, 96); // daddiu v1, s3, 96 + c->lwc1(f0, 0, a0); // lwc1 f0, 0(a0) + c->lwc1(f1, 4, a0); // lwc1 f1, 4(a0) + c->lwc1(f2, 8, a0); // lwc1 f2, 8(a0) + c->lwc1(f3, 0, v1); // lwc1 f3, 0(v1) + c->lwc1(f4, 4, v1); // lwc1 f4, 4(v1) + c->lwc1(f5, 8, v1); // lwc1 f5, 8(v1) + // Unknown instr: mula.s f0, f3 + // Unknown instr: madda.s f1, f4 + // Unknown instr: madd.s f0, f2, f5 + c->fprs[f0] = (c->fprs[f2] * c->fprs[f5]) + (c->fprs[f1] * c->fprs[f4]) + (c->fprs[f0] * c->fprs[f3]); + c->mfc1(v1, f0); // mfc1 v1, f0 + c->mtc1(f0, v1); // mtc1 f0, v1 + c->daddiu(a0, s3, 80); // daddiu a0, s3, 80 + c->daddiu(v1, s3, 112); // daddiu v1, s3, 112 + c->lwc1(f1, 0, a0); // lwc1 f1, 0(a0) + c->lwc1(f2, 4, a0); // lwc1 f2, 4(a0) + c->lwc1(f3, 8, a0); // lwc1 f3, 8(a0) + c->lwc1(f4, 0, v1); // lwc1 f4, 0(v1) + c->lwc1(f5, 4, v1); // lwc1 f5, 4(v1) + c->lwc1(f6, 8, v1); // lwc1 f6, 8(v1) + // Unknown instr: mula.s f1, f4 + // Unknown instr: madda.s f2, f5 + // Unknown instr: madd.s f1, f3, f6 + c->fprs[f1] = (c->fprs[f3] * c->fprs[f6]) + (c->fprs[f2] * c->fprs[f5]) + (c->fprs[f1] * c->fprs[f4]); + c->mfc1(v1, f1); // mfc1 v1, f1 + c->mtc1(f1, v1); // mtc1 f1, v1 + c->lwc1(f2, 108, s3); // lwc1 f2, 108(s3) + cop1_bc = c->fprs[f2] < c->fprs[f0]; // c.lt.s f2, f0 + bc = cop1_bc; // bc1t L33 + c->daddiu(v1, s7, 4); // daddiu v1, s7, 4 + if (bc) {goto block_23;} // branch non-likely + + c->mov64(v1, s7); // or v1, s7, r0 + +block_23: + if (((s64)c->sgpr64(s7)) == ((s64)c->sgpr64(v1))) {// beql s7, v1, L34 + c->mov64(v1, v1); // or v1, v1, r0 + goto block_27; + } + +// block_25: + c->lwc1(f2, 124, s3); // lwc1 f2, 124(s3) + cop1_bc = c->fprs[f1] < c->fprs[f2]; // c.lt.s f1, f2 + bc = cop1_bc; // bc1t L34 + c->daddiu(v1, s7, 4); // daddiu v1, s7, 4 + if (bc) {goto block_27;} // branch non-likely + + c->mov64(v1, s7); // or v1, s7, r0 + +block_27: + bc = c->sgpr64(s7) == c->sgpr64(v1); // beq s7, v1, L36 + c->mov64(v1, s7); // or v1, s7, r0 + if (bc) {goto block_31;} // branch non-likely + + c->mtc1(f2, r0); // mtc1 f2, r0 + c->lwc1(f3, 28, s1); // lwc1 f3, 28(s1) + cop1_bc = c->fprs[f2] < c->fprs[f3]; // c.lt.s f2, f3 + bc = !cop1_bc; // bc1f L35 + // nop // sll r0, r0, 0 + if (bc) {goto block_30;} // branch non-likely + + c->negs(f0, f0); // neg.s f0, f0 + c->swc1(f0, 108, s3); // swc1 f0, 108(s3) + c->mfc1(v1, f0); // mfc1 v1, f0 + //beq r0, r0, L36 // beq r0, r0, L36 + // nop // sll r0, r0, 0 + goto block_31; // branch always + + +block_30: + c->negs(f0, f1); // neg.s f0, f1 + c->swc1(f0, 124, s3); // swc1 f0, 124(s3) + c->mfc1(v1, f0); // mfc1 v1, f0 + +block_31: + c->lq(v1, 16, s1); // lq v1, 16(s1) + c->sq(v1, 144, s3); // sq v1, 144(s3) + c->daddiu(v1, s3, 128); // daddiu v1, s3, 128 + c->mtc1(f0, r0); // mtc1 f0, r0 + c->swc1(f0, 0, v1); // swc1 f0, 0(v1) + c->mtc1(f0, r0); // mtc1 f0, r0 + c->swc1(f0, 4, v1); // swc1 f0, 4(v1) + c->lui(a0, 16256); // lui a0, 16256 + c->mtc1(f0, a0); // mtc1 f0, a0 + c->swc1(f0, 8, v1); // swc1 f0, 8(v1) + c->lui(a0, -16384); // lui a0, -16384 + c->mtc1(f0, a0); // mtc1 f0, a0 + c->load_symbol2(a0, cache.math_camera); // lw a0, *math-camera*(s7) + c->lwc1(f1, 0, a0); // lwc1 f1, 0(a0) + c->muls(f0, f0, f1); // mul.s f0, f0, f1 + c->swc1(f0, 12, v1); // swc1 f0, 12(v1) + c->daddiu(v1, s3, 176); // daddiu v1, s3, 176 + c->sw(v1, 16, s3); // sw v1, 16(s3) + c->daddiu(v1, s3, 48); // daddiu v1, s3, 48 + c->lhu(a0, 18, v1); // lhu a0, 18(v1) + c->daddiu(a0, a0, 1); // daddiu a0, a0, 1 + c->sh(a0, 18, v1); // sh a0, 18(v1) + c->lw(v1, 12, s1); // lw v1, 12(s1) + c->andi(v1, v1, 64); // andi v1, v1, 64 + bc = c->sgpr64(v1) == 0; // beq v1, r0, L37 + // nop // sll r0, r0, 0 + if (bc) {goto block_33;} // branch non-likely + + c->load_symbol2(t9, cache.shadow_xform_verts); // lw t9, shadow-xform-verts(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_init_vars); // lw t9, shadow-init-vars(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_add_verts); // lw t9, shadow-add-verts(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + c->addiu(a3, r0, 1); // addiu a3, r0, 1 + c->mov64(a2, gp); // or a2, gp, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(a2, v0); // or a2, v0, r0 + c->load_symbol2(t9, cache.shadow_add_single_tris);// lw t9, shadow-add-single-tris(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(gp, v0); // or gp, v0, r0 + c->mov64(a0, gp); // or a0, gp, r0 + //beq r0, r0, L39 // beq r0, r0, L39 + // nop // sll r0, r0, 0 + goto block_36; // branch always + + +block_33: + c->load_symbol2(t9, cache.shadow_xform_verts); // lw t9, shadow-xform-verts(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_init_vars); // lw t9, shadow-init-vars(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_calc_dual_verts);// lw t9, shadow-calc-dual-verts(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->lw(v1, 12, s1); // lw v1, 12(s1) + c->andi(v1, v1, 8); // andi v1, v1, 8 + bc = c->sgpr64(v1) == 0; // beq v1, r0, L38 + c->mov64(v1, s7); // or v1, s7, r0 + if (bc) {goto block_35;} // branch non-likely + + c->load_symbol2(t9, cache.shadow_scissor_top); // lw t9, shadow-scissor-top(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + +block_35: + c->load_symbol2(t9, cache.shadow_scissor_edges); // lw t9, shadow-scissor-edges(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_find_facing_single_tris);// lw t9, shadow-find-facing-single-tris(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_find_single_edges);// lw t9, shadow-find-single-edges(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_find_facing_double_tris);// lw t9, shadow-find-facing-double-tris(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_find_double_edges);// lw t9, shadow-find-double-edges(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol2(t9, cache.shadow_add_verts); // lw t9, shadow-add-verts(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + c->mov64(a2, gp); // or a2, gp, r0 + c->addiu(a3, r0, 0); // addiu a3, r0, 0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(a2, v0); // or a2, v0, r0 + c->load_symbol2(t9, cache.shadow_add_facing_single_tris);// lw t9, shadow-add-facing-single-tris(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(a2, v0); // or a2, v0, r0 + c->load_symbol2(t9, cache.shadow_add_single_edges);// lw t9, shadow-add-single-edges(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(a2, v0); // or a2, v0, r0 + c->load_symbol2(t9, cache.shadow_add_double_tris);// lw t9, shadow-add-double-tris(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(a2, v0); // or a2, v0, r0 + c->load_symbol2(t9, cache.shadow_add_double_edges);// lw t9, shadow-add-double-edges(s7) + c->mov64(a0, s2); // or a0, s2, r0 + c->mov64(a1, s3); // or a1, s3, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(gp, v0); // or gp, v0, r0 + c->daddiu(v1, s3, 48); // daddiu v1, s3, 48 + c->lwu(a0, 0, v1); // lwu a0, 0(v1) + c->lwu(a1, 20, s3); // lwu a1, 20(s3) + c->daddu(a0, a0, a1); // daddu a0, a0, a1 + c->sw(a0, 0, v1); // sw a0, 0(v1) + c->lwu(a0, 4, v1); // lwu a0, 4(v1) + c->lhu(a1, 16, s2); // lhu a1, 16(s2) + c->daddu(a0, a0, a1); // daddu a0, a0, a1 + c->sw(a0, 4, v1); // sw a0, 4(v1) + c->lwu(a0, 8, v1); // lwu a0, 8(v1) + c->lwu(a1, 24, s3); // lwu a1, 24(s3) + c->daddu(a0, a0, a1); // daddu a0, a0, a1 + c->sw(a0, 8, v1); // sw a0, 8(v1) + c->lwu(a0, 12, v1); // lwu a0, 12(v1) + c->lwu(a1, 28, s3); // lwu a1, 28(s3) + c->daddu(a0, a0, a1); // daddu a0, a0, a1 + c->sw(a0, 12, v1); // sw a0, 12(v1) + +block_36: + c->lw(s4, 60, s4); // lw s4, 60(s4) + +block_37: + bc = c->sgpr64(s4) != 0; // bne s4, r0, L22 + // nop // sll r0, r0, 0 + if (bc) {goto block_1;} // branch non-likely + + c->mov64(v1, s7); // or v1, s7, r0 + c->mov64(v0, gp); // or v0, gp, r0 + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->lq(gp, 96, sp); // lq gp, 96(sp) + c->lq(s5, 80, sp); // lq s5, 80(sp) + c->lq(s4, 64, sp); // lq s4, 64(sp) + c->lq(s3, 48, sp); // lq s3, 48(sp) + c->lq(s2, 32, sp); // lq s2, 32(sp) + c->lq(s1, 16, sp); // lq s1, 16(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 112); // daddiu sp, sp, 112 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 +end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.fake_scratchpad_data = intern_from_c(-1, 0, "*fake-scratchpad-data*").c(); + cache.gsf_buffer = intern_from_c(-1, 0, "*gsf-buffer*").c(); + cache.math_camera = intern_from_c(-1, 0, "*math-camera*").c(); + cache.shadow_debug = intern_from_c(-1, 0, "*shadow-debug*").c(); + cache.camera_pos = intern_from_c(-1, 0, "camera-pos").c(); + cache.debug_draw_settings = intern_from_c(-1, 0, "debug-draw-settings").c(); + cache.flush_cache = intern_from_c(-1, 0, "flush-cache").c(); + cache.shadow_add_double_edges = intern_from_c(-1, 0, "shadow-add-double-edges").c(); + cache.shadow_add_double_tris = intern_from_c(-1, 0, "shadow-add-double-tris").c(); + cache.shadow_add_facing_single_tris = intern_from_c(-1, 0, "shadow-add-facing-single-tris").c(); + cache.shadow_add_single_edges = intern_from_c(-1, 0, "shadow-add-single-edges").c(); + cache.shadow_add_single_tris = intern_from_c(-1, 0, "shadow-add-single-tris").c(); + cache.shadow_add_verts = intern_from_c(-1, 0, "shadow-add-verts").c(); + cache.shadow_calc_dual_verts = intern_from_c(-1, 0, "shadow-calc-dual-verts").c(); + cache.shadow_find_double_edges = intern_from_c(-1, 0, "shadow-find-double-edges").c(); + cache.shadow_find_facing_double_tris = intern_from_c(-1, 0, "shadow-find-facing-double-tris").c(); + cache.shadow_find_facing_single_tris = intern_from_c(-1, 0, "shadow-find-facing-single-tris").c(); + cache.shadow_find_single_edges = intern_from_c(-1, 0, "shadow-find-single-edges").c(); + cache.shadow_init_vars = intern_from_c(-1, 0, "shadow-init-vars").c(); + cache.shadow_scissor_edges = intern_from_c(-1, 0, "shadow-scissor-edges").c(); + cache.shadow_scissor_top = intern_from_c(-1, 0, "shadow-scissor-top").c(); + cache.shadow_xform_verts = intern_from_c(-1, 0, "shadow-xform-verts").c(); + gLinkedFunctionTable.reg("shadow-execute", execute, 256); +} + +} // namespace shadow_execute +} // namespace Mips2C + diff --git a/game/mips2c/mips2c_table.cpp b/game/mips2c/mips2c_table.cpp index 9aa350c9e..74c461c71 100644 --- a/game/mips2c/mips2c_table.cpp +++ b/game/mips2c/mips2c_table.cpp @@ -377,6 +377,22 @@ namespace method_34_sky_work { extern void link(); } namespace method_35_sky_work { extern void link(); } namespace method_32_sky_work { extern void link(); } namespace set_sky_vf23_value { extern void link(); } +namespace shadow_xform_verts { extern void link(); } +namespace shadow_calc_dual_verts { extern void link(); } +namespace shadow_scissor_edges { extern void link(); } +namespace shadow_scissor_top { extern void link(); } +namespace shadow_init_vars { extern void link(); } +namespace shadow_find_facing_single_tris { extern void link(); } +namespace shadow_find_facing_double_tris { extern void link(); } +namespace shadow_find_single_edges { extern void link(); } +namespace shadow_find_double_edges { extern void link(); } +namespace shadow_add_verts { extern void link(); } +namespace shadow_add_facing_single_tris { extern void link(); } +namespace shadow_add_single_edges { extern void link(); } +namespace shadow_add_double_edges { extern void link(); } +namespace shadow_add_single_tris { extern void link(); } +namespace shadow_add_double_tris { extern void link(); } +namespace shadow_execute { extern void link(); } } // clang-format on @@ -629,7 +645,16 @@ PerGameVersion>> gMips2C jak3::method_29_sky_work::link, jak3::method_30_sky_work::link, jak3::method_31_sky_work::link, jak3::method_34_sky_work::link, jak3::method_35_sky_work::link, jak3::method_32_sky_work::link, - jak3::set_sky_vf23_value::link, jak3::draw_large_polygon::link}}}}; + jak3::set_sky_vf23_value::link, jak3::draw_large_polygon::link}}, + {"shadow-cpu", + {jak3::shadow_xform_verts::link, jak3::shadow_execute::link, + jak3::shadow_calc_dual_verts::link, jak3::shadow_scissor_edges::link, + jak3::shadow_scissor_top::link, jak3::shadow_init_vars::link, + jak3::shadow_find_facing_single_tris::link, jak3::shadow_find_facing_double_tris::link, + jak3::shadow_find_single_edges::link, jak3::shadow_find_double_edges::link, + jak3::shadow_add_verts::link, jak3::shadow_add_facing_single_tris::link, + jak3::shadow_add_single_edges::link, jak3::shadow_add_double_edges::link, + jak3::shadow_add_single_tris::link, jak3::shadow_add_double_tris::link}}}}; void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 stack_size) { const auto& it = m_executes.insert({name, {exec, Ptr()}}); diff --git a/goal_src/jak2/pc/pckernel-impl.gc b/goal_src/jak2/pc/pckernel-impl.gc index db5f7fa05..f6b6534a1 100644 --- a/goal_src/jak2/pc/pckernel-impl.gc +++ b/goal_src/jak2/pc/pckernel-impl.gc @@ -178,6 +178,7 @@ (set! (-> obj flava-unlocked i) #f)) (set! (-> obj stats) *statistics*) + (initialize (-> obj stats kill-stats)) 0) (defmethod reset-input ((obj pc-settings-jak2) (device symbol) (call-handlers symbol)) diff --git a/goal_src/jak3/engine/draw/drawable.gc b/goal_src/jak3/engine/draw/drawable.gc index bb77f8e2e..0a5a43edf 100644 --- a/goal_src/jak3/engine/draw/drawable.gc +++ b/goal_src/jak3/engine/draw/drawable.gc @@ -1455,7 +1455,7 @@ (bones-init gp-0) (bones-mtx-calc-execute) (generic-merc-execute-all gp-0) - ;; (shadow-execute-all gp-0) + (shadow-execute-all gp-0) ) (lightning-draw-all) ;(prim-engine-execute) diff --git a/goal_src/jak3/engine/gfx/foreground/shadow-cpu.gc b/goal_src/jak3/engine/gfx/foreground/shadow-cpu.gc index a833defbe..42104b626 100644 --- a/goal_src/jak3/engine/gfx/foreground/shadow-cpu.gc +++ b/goal_src/jak3/engine/gfx/foreground/shadow-cpu.gc @@ -5,10 +5,832 @@ ;; name in dgo: shadow-cpu ;; dgos: GAME +(define-extern shadow-vu1-patch-consts (function symbol int none)) +(define-extern shadow-vu1-init-buffer (function dma-buffer int none)) + ;; DECOMP BEGINS -;; stub -(format 0 "shadow-cpu: stubbed shadow-control::14~%") -(defmethod shadow-control-method-14 ((this shadow-control) (arg0 vector) (arg1 vector) (arg2 float) (arg3 float) (arg4 float)) +;; WARN: Return type mismatch uint vs int. +(defmethod asize-of ((this shadow-geo)) + (the-as int (* (-> this total-qwc) 16)) + ) + +(defmethod mem-usage ((this shadow-geo) (usage memory-usage-block) (flags int)) + (set! (-> usage length) (max 112 (-> usage length))) + (set! (-> usage data 111 name) "shadow-geo") + (+! (-> usage data 111 count) 1) + (let ((v1-6 (* (-> this total-qwc) 16))) + (+! (-> usage data 111 used) v1-6) + (+! (-> usage data 111 total) (logand -16 (+ v1-6 15))) + ) + this + ) + +(define *shadow-data* (new 'static 'shadow-data + :dma-unpack-template (new 'static 'dma-packet + :dma (new 'static 'dma-tag :id (dma-tag-id cnt)) + :vif0 (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1) + :vif1 (new 'static 'vif-tag :cmd (vif-cmd unpack-v4-32)) + ) + :dma-cnt (new 'static 'dma-tag :id (dma-tag-id cnt)) + :vif-unpack-v4-8 (new 'static 'vif-tag :cmd (vif-cmd unpack-v4-8)) + ) + ) + +(defun shadow-invert-z-buf ((arg0 dma-buffer)) + (let ((v1-0 (-> arg0 base))) + (let* ((a1-0 arg0) + (a2-0 (the-as object (-> a1-0 base))) + ) + (set! (-> (the-as dma-packet a2-0) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a2-0) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a2-0) vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a1-0 base) (&+ (the-as pointer a2-0) 16)) + ) + (let* ((a1-1 arg0) + (a2-2 (the-as object (-> a1-1 base))) + ) + (set! (-> (the-as gs-gif-tag a2-2) tag) (new 'static 'gif-tag64 :nloop #x7 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a2-2) regs) (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d))) + (set! (-> a1-1 base) (&+ (the-as pointer a2-2) 16)) + ) + (let ((t1-0 (-> arg0 base)) + (t0-0 512) + ) + 416 + (let ((a1-3 1792) + (a2-4 1840) + ) + 2304 + (let ((a3-5 2256) + (t0-1 (/ t0-0 32)) + ) + (set! (-> (the-as (pointer gs-reg) t1-0) 8) (gs-reg texflush)) + (set! (-> (the-as (pointer gs-reg64) t1-0) 0) (gs-reg64 prim)) + (set! (-> (the-as (pointer gs-reg) t1-0) 24) (gs-reg frame-1)) + (set! (-> (the-as (pointer gs-frame) t1-0) 2) (new 'static 'gs-frame :fbp #x130 :fbw #x8 :fbmsk #xff000000)) + (set! (-> (the-as (pointer gs-reg) t1-0) 40) (gs-reg zbuf-1)) + (set! (-> (the-as (pointer gs-zbuf) t1-0) 4) (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24) :zmsk #x1)) + (set! (-> (the-as (pointer gs-reg) t1-0) 56) (gs-reg test-1)) + (set! (-> (the-as (pointer gs-test) t1-0) 6) + (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest always)) + ) + (set! (-> (the-as (pointer gs-reg) t1-0) 72) (gs-reg alpha-1)) + (set! (-> (the-as (pointer gs-alpha) t1-0) 8) (new 'static 'gs-alpha :b #x1 :c #x2 :d #x2 :fix #x80)) + (set! (-> (the-as (pointer gs-reg) t1-0) 88) (gs-reg prim)) + (set! (-> (the-as (pointer gs-reg64) t1-0) 10) (gs-reg64 colclamp)) + (set! (-> (the-as (pointer gs-reg) t1-0) 104) (gs-reg rgbaq)) + (set! (-> (the-as (pointer gs-rgbaq) t1-0) 12) (new 'static 'gs-rgbaq :r #xff :g #xff :b #xff :q 1.0)) + (&+! (-> arg0 base) 112) + (let* ((t1-3 arg0) + (t2-12 (the-as object (-> t1-3 base))) + ) + (set! (-> (the-as gs-gif-tag t2-12) tag) + (new 'static 'gif-tag64 :eop #x1 :flg (gif-flag reg-list) :nreg #x2 :nloop t0-1) + ) + (set! (-> (the-as gs-gif-tag t2-12) regs) + (new 'static 'gif-tag-regs :regs0 (gif-reg-id xyz2) :regs1 (gif-reg-id xyz2)) + ) + (set! (-> t1-3 base) (&+ (the-as pointer t2-12) 16)) + ) + (let ((t1-4 0)) + (dotimes (t2-14 t0-1) + (let* ((t3-3 arg0) + (t4-2 (-> t3-3 base)) + ) + (set! (-> (the-as (pointer gs-xyzf) t4-2) 0) (new 'static 'gs-xyzf :y (* a2-4 16) :x (* (+ t1-4 a1-3) 16))) + (set! (-> (the-as (pointer gs-xyzf) t4-2) 1) (new 'static 'gs-xyzf :y (* a3-5 16) :x (* (+ t1-4 32 a1-3) 16))) + (set! (-> t3-3 base) (&+ t4-2 16)) + ) + (+! t1-4 32) + ) + ) + ) + ) + ) + (nop!) + (nop!) + 0 + (let ((a1-9 (/ (the-as int (+ (- -16 (the-as int v1-0)) (the-as int (-> arg0 base)))) 16))) + (cond + ((nonzero? a1-9) + (logior! (-> (the-as (pointer uint64) v1-0) 0) (shr (shl a1-9 48) 48)) + (logior! (-> (the-as (pointer uint64) v1-0) 1) (shl (shr (shl a1-9 48) 48) 32)) + ) + (else + (set! (-> arg0 base) v1-0) + ) + ) + ) + ) (none) - ) \ No newline at end of file + ) + +;; WARN: Return type mismatch pointer vs none. +(defun shadow-make-invert-buf () + (let ((gp-0 *shadow-dma-buf*)) + (let ((v1-0 gp-0)) + (set! (-> v1-0 base) (-> v1-0 data)) + (set! (-> v1-0 end) (the-as pointer (+ (+ (-> v1-0 allocated-length) 28) (the-as int v1-0)))) + ) + (shadow-invert-z-buf gp-0) + (let ((v1-1 (the-as object (-> gp-0 base)))) + (set! (-> (the-as dma-packet v1-1) dma) (new 'static 'dma-tag :id (dma-tag-id ret))) + (set! (-> (the-as dma-packet v1-1) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet v1-1) vif1) (new 'static 'vif-tag)) + (set! (-> gp-0 base) (&+ (the-as pointer v1-1) 16)) + ) + ) + (none) + ) + +(shadow-make-invert-buf) + +(define *shadow-dma-invert-call* (the-as pointer #f)) + +;; WARN: Return type mismatch dma-buffer vs none. +(defun shadow-dma-init ((arg0 dma-buffer)) + (-> *display* on-screen) + (let ((a1-0 408)) + (* a1-0 32) + (let ((t3-0 512) + (t2-0 416) + (a2-0 1792) + (a3-0 1840) + ) + 2304 + (let ((t0-0 2256) + (t1-0 (/ t3-0 32)) + (t5-0 (* a3-0 16)) + ) + (set! *shadow-dma-invert-call* (-> arg0 base)) + (let* ((v1-6 arg0) + (t4-0 (the-as object (-> v1-6 base))) + ) + (set! (-> (the-as dma-packet t4-0) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet t4-0) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet t4-0) vif1) (new 'static 'vif-tag)) + (set! (-> v1-6 base) (&+ (the-as pointer t4-0) 16)) + ) + (let ((v1-7 (-> arg0 base))) + (let* ((t4-2 arg0) + (t6-1 (the-as object (-> t4-2 base))) + ) + (set! (-> (the-as dma-packet t6-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet t6-1) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet t6-1) vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> t4-2 base) (&+ (the-as pointer t6-1) 16)) + ) + (let* ((t4-3 arg0) + (t6-3 (the-as object (-> t4-3 base))) + ) + (set! (-> (the-as gs-gif-tag t6-3) tag) (new 'static 'gif-tag64 :nloop #xa :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag t6-3) regs) (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d))) + (set! (-> t4-3 base) (&+ (the-as pointer t6-3) 16)) + ) + (let ((t4-4 (-> arg0 base))) + (set! (-> (the-as (pointer gs-reg64) t4-4) 1) (gs-reg64 texflush)) + (set! (-> (the-as (pointer gs-reg64) t4-4) 3) (gs-reg64 test-1)) + (set! (-> (the-as (pointer gs-test) t4-4) 2) + (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest always)) + ) + (set! (-> (the-as (pointer gs-reg64) t4-4) 5) (gs-reg64 alpha-1)) + (set! (-> (the-as (pointer gs-alpha) t4-4) 4) (new 'static 'gs-alpha :b #x1 :d #x1)) + (set! (-> (the-as (pointer gs-reg64) t4-4) 7) (gs-reg64 frame-1)) + (set! (-> (the-as (pointer gs-frame) t4-4) 6) (new 'static 'gs-frame :fbw #x8 :fbmsk #xffffff :fbp a1-0)) + (set! (-> (the-as (pointer gs-reg64) t4-4) 9) (gs-reg64 zbuf-1)) + (set! (-> (the-as (pointer gs-zbuf) t4-4) 8) (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24) :zmsk #x1)) + (set! (-> (the-as (pointer gs-reg64) t4-4) 11) (gs-reg64 xyoffset-1)) + (set! (-> (the-as (pointer gs-xy-offset) t4-4) 10) (new 'static 'gs-xy-offset :ofx (* a2-0 16) :ofy t5-0)) + (set! (-> (the-as (pointer gs-reg64) t4-4) 13) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer gs-tex0) t4-4) 12) + (new 'static 'gs-tex0 :tbw #x8 :tw #x9 :th #x9 :tcc #x1 :tbp0 (* a1-0 32)) + ) + (set! (-> (the-as (pointer gs-reg) t4-4) 120) (gs-reg tex1-1)) + (set! (-> (the-as (pointer gs-tex1) t4-4) 14) (new 'static 'gs-tex1)) + (set! (-> (the-as (pointer gs-reg) t4-4) 136) (gs-reg miptbp1-1)) + (set! (-> (the-as (pointer gs-miptbp) t4-4) 16) (new 'static 'gs-miptbp)) + (set! (-> (the-as (pointer gs-reg) t4-4) 152) (gs-reg clamp-1)) + (set! (-> (the-as (pointer gs-clamp) t4-4) 18) (new 'static 'gs-clamp + :wms (gs-tex-wrap-mode region-clamp) + :wmt (gs-tex-wrap-mode region-clamp) + :maxv (+ t2-0 -1) + :maxu (+ t3-0 -1) + ) + ) + ) + (&+! (-> arg0 base) 160) + (let* ((t2-7 arg0) + (t3-5 (the-as object (-> t2-7 base))) + ) + (set! (-> (the-as gs-gif-tag t3-5) tag) + (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :flg (gif-flag reg-list) :nreg #x2) + ) + (set! (-> (the-as gs-gif-tag t3-5) regs) (new 'static 'gif-tag-regs :regs1 (gif-reg-id rgbaq))) + (set! (-> t2-7 base) (&+ (the-as pointer t3-5) 16)) + ) + (let* ((t2-8 arg0) + (t3-7 (-> t2-8 base)) + ) + (set! (-> (the-as (pointer gs-prim) t3-7) 0) (new 'static 'gs-prim :prim (gs-prim-type sprite))) + (set! (-> (the-as (pointer gs-rgbaq) t3-7) 1) (new 'static 'gs-rgbaq :a #x60)) + (set! (-> t2-8 base) (&+ t3-7 16)) + ) + (let* ((t2-9 arg0) + (t3-9 (the-as object (-> t2-9 base))) + ) + (set! (-> (the-as gs-gif-tag t3-9) tag) + (new 'static 'gif-tag64 :eop #x1 :flg (gif-flag reg-list) :nreg #x2 :nloop t1-0) + ) + (set! (-> (the-as gs-gif-tag t3-9) regs) + (new 'static 'gif-tag-regs :regs0 (gif-reg-id xyz2) :regs1 (gif-reg-id xyz2)) + ) + (set! (-> t2-9 base) (&+ (the-as pointer t3-9) 16)) + ) + (let ((t2-10 0)) + (dotimes (t3-11 t1-0) + (let* ((t4-12 arg0) + (t5-12 (-> t4-12 base)) + ) + (set! (-> (the-as (pointer gs-xyzf) t5-12) 0) + (new 'static 'gs-xyzf :z #x1ffff :y (* a3-0 16) :x (* (+ a2-0 t2-10) 16)) + ) + (set! (-> (the-as (pointer gs-xyzf) t5-12) 1) + (new 'static 'gs-xyzf :z #x1ffff :y (* t0-0 16) :x (* (+ t2-10 32 a2-0) 16)) + ) + (set! (-> t4-12 base) (&+ t5-12 16)) + ) + (+! t2-10 32) + ) + ) + (let* ((a2-3 arg0) + (a3-1 (the-as object (-> a2-3 base))) + ) + (set! (-> (the-as gs-gif-tag a3-1) tag) (new 'static 'gif-tag64 :nloop #x4 :eop #x1 :nreg #x1)) + (set! (-> (the-as gs-gif-tag a3-1) regs) (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d))) + (set! (-> a2-3 base) (&+ (the-as pointer a3-1) 16)) + ) + (cond + (*shadow-debug* + (let* ((a2-5 arg0) + (a3-3 (-> a2-5 base)) + ) + (set! (-> (the-as (pointer gs-test) a3-3) 0) + (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest greater-equal)) + ) + (set! (-> (the-as (pointer gs-reg64) a3-3) 1) (gs-reg64 test-1)) + (set! (-> (the-as (pointer gs-zbuf) a3-3) 2) (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24))) + (set! (-> (the-as (pointer gs-reg64) a3-3) 3) (gs-reg64 zbuf-1)) + (set! (-> (the-as (pointer gs-frame) a3-3) 4) (new 'static 'gs-frame :fbw #x8 :fbp a1-0)) + (set! (-> (the-as (pointer gs-reg64) a3-3) 5) (gs-reg64 frame-1)) + (set! (-> (the-as (pointer uint64) a3-3) 6) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) a3-3) 7) (gs-reg64 texflush)) + (set! (-> a2-5 base) (&+ a3-3 64)) + ) + ) + (else + (let* ((a2-6 arg0) + (a3-4 (-> a2-6 base)) + ) + (set! (-> (the-as (pointer gs-test) a3-4) 0) + (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest greater-equal)) + ) + (set! (-> (the-as (pointer gs-reg64) a3-4) 1) (gs-reg64 test-1)) + (set! (-> (the-as (pointer gs-zbuf) a3-4) 2) (new 'static 'gs-zbuf :zbp #x130 :psm (gs-psm ct24) :zmsk #x1)) + (set! (-> (the-as (pointer gs-reg64) a3-4) 3) (gs-reg64 zbuf-1)) + (set! (-> (the-as (pointer gs-frame) a3-4) 4) (new 'static 'gs-frame :fbw #x8 :fbmsk #xffffff :fbp a1-0)) + (set! (-> (the-as (pointer gs-reg64) a3-4) 5) (gs-reg64 frame-1)) + (set! (-> (the-as (pointer uint64) a3-4) 6) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) a3-4) 7) (gs-reg64 texflush)) + (set! (-> a2-6 base) (&+ a3-4 64)) + ) + ) + ) + (let ((a2-10 (/ (the-as int (+ (- -16 (the-as int v1-7)) (the-as int (-> arg0 base)))) 16))) + (cond + ((nonzero? a2-10) + (logior! (-> (the-as (pointer uint64) v1-7) 0) (shr (shl a2-10 48) 48)) + (logior! (-> (the-as (pointer uint64) v1-7) 1) (shl (shr (shl a2-10 48) 48) 32)) + ) + (else + (set! (-> arg0 base) v1-7) + ) + ) + ) + ) + ) + ) + ) + (none) + ) + +;; WARN: Return type mismatch dma-buffer vs none. +(defun shadow-dma-end ((arg0 dma-buffer) (arg1 gs-rgbaq) (arg2 symbol) (arg3 int)) + (local-vars (sv-16 int)) + (set! sv-16 arg3) + (-> *display* on-screen) + (let ((s0-0 408)) + (* s0-0 32) + (let ((v1-4 512) + (s3-0 416) + (s5-0 1792) + (s4-0 1840) + ) + 2304 + 2256 + (let ((s2-0 (/ v1-4 32))) + (* s4-0 16) + (let ((v1-6 (the-as object *shadow-dma-invert-call*)) + (a0-3 *shadow-dma-buf*) + ) + (cond + (arg2 + (set! (-> (the-as (pointer uint64) v1-6)) (logior #x50000000 (shr (shl (the-as int (-> a0-3 data)) 33) 1))) + (set! (-> (the-as (pointer uint64) v1-6) 1) (the-as uint 0)) + (let* ((v1-7 arg0) + (a1-3 (the-as object (-> v1-7 base))) + ) + (set! (-> (the-as dma-packet a1-3) dma) + (new 'static 'dma-tag :id (dma-tag-id call) :addr (the-as int (-> a0-3 data))) + ) + (set! (-> (the-as dma-packet a1-3) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a1-3) vif1) (new 'static 'vif-tag :cmd (vif-cmd flusha) :msk #x1)) + (set! (-> v1-7 base) (&+ (the-as pointer a1-3) 16)) + ) + ) + (else + (set! (-> (the-as dma-packet v1-6) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as (pointer uint64) v1-6) 1) (the-as uint 0)) + 0 + ) + ) + ) + (shadow-vu1-patch-consts arg2 sv-16) + (cond + ((= sv-16 2) + (dma-buffer-add-gs-set-flusha arg0 + (texflush 0) + (test-1 + (new 'static 'gs-test :ate #x1 :atst (gs-atest not-equal) :aref #x60 :zte #x1 :ztst (gs-ztest always)) + ) + (tex0-1 (new 'static 'gs-tex0 :tbp0 #x3300 :tbw #x8 :tw #x9 :th #x9 :tcc #x1 :tfx #x3)) + (frame-1 (new 'static 'gs-frame :fbw #x8 :fbp s0-0)) + (alpha-1 (new 'static 'gs-alpha)) + (texflush 0) + ) + ) + (else + (let* ((v1-13 arg0) + (a0-19 (the-as object (-> v1-13 base))) + ) + (set! (-> (the-as dma-packet a0-19) dma) (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-19) vif0) (new 'static 'vif-tag :cmd (vif-cmd flusha) :msk #x1)) + (set! (-> (the-as dma-packet a0-19) vif1) (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-13 base) (&+ (the-as pointer a0-19) 16)) + ) + (let* ((v1-14 arg0) + (a0-21 (the-as object (-> v1-14 base))) + ) + (set! (-> (the-as gs-gif-tag a0-21) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x5)) + (set! (-> (the-as gs-gif-tag a0-21) regs) GIF_REGS_ALL_AD) + (set! (-> v1-14 base) (&+ (the-as pointer a0-21) 16)) + ) + (let* ((v1-15 arg0) + (a0-23 (-> v1-15 base)) + ) + (set! (-> (the-as (pointer uint64) a0-23) 0) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) a0-23) 1) (gs-reg64 texflush)) + (set! (-> (the-as (pointer gs-test) a0-23) 2) + (new 'static 'gs-test :ate #x1 :atst (gs-atest not-equal) :aref #x60 :zte #x1 :ztst (gs-ztest always)) + ) + (set! (-> (the-as (pointer gs-reg64) a0-23) 3) (gs-reg64 test-1)) + (set! (-> (the-as (pointer gs-frame) a0-23) 4) (new 'static 'gs-frame :fbw #x8 :fbp s0-0)) + (set! (-> (the-as (pointer gs-reg64) a0-23) 5) (gs-reg64 frame-1)) + (set! (-> (the-as (pointer uint64) a0-23) 6) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) a0-23) 7) (gs-reg64 alpha-1)) + (set! (-> (the-as (pointer uint64) a0-23) 8) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) a0-23) 9) (gs-reg64 texflush)) + (set! (-> v1-15 base) (&+ a0-23 80)) + ) + ) + ) + (let ((v1-16 (-> arg0 base))) + (let* ((a0-25 arg0) + (a1-35 (the-as object (-> a0-25 base))) + ) + (set! (-> (the-as dma-packet a1-35) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a1-35) vif0) (new 'static 'vif-tag :cmd (vif-cmd flusha) :msk #x1)) + (set! (-> (the-as dma-packet a1-35) vif1) (new 'static 'vif-tag :cmd (vif-cmd direct) :msk #x1)) + (set! (-> a0-25 base) (&+ (the-as pointer a1-35) 16)) + ) + (let* ((a0-26 arg0) + (a1-37 (the-as object (-> a0-26 base))) + ) + (set! (-> (the-as gs-gif-tag a1-37) tag) + (new 'static 'gif-tag64 :nloop #x1 :flg (gif-flag reg-list) :nreg #x2) + ) + (set! (-> (the-as gs-gif-tag a1-37) regs) (new 'static 'gif-tag-regs :regs1 (gif-reg-id rgbaq))) + (set! (-> (the-as (pointer gs-prim) a1-37) 2) + (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1 :abe #x1) + ) + (set! (-> (the-as (pointer gs-rgbaq) a1-37) 3) arg1) + (set! (-> (the-as (inline-array gs-gif-tag) a1-37) 2 tag) + (new 'static 'gif-tag64 :eop #x1 :flg (gif-flag reg-list) :nreg #x4 :nloop s2-0) + ) + (set! (-> (the-as (inline-array gs-gif-tag) a1-37) 2 regs) (new 'static 'gif-tag-regs + :regs0 (gif-reg-id st) + :regs1 (gif-reg-id xyz2) + :regs2 (gif-reg-id st) + :regs3 (gif-reg-id xyz2) + ) + ) + (set! (-> a0-26 base) (&+ (the-as pointer a1-37) 48)) + ) + (let ((a0-27 0) + (a1-39 0) + ) + (dotimes (a2-14 s2-0) + (let ((t1-0 a0-27)) + (+! a0-27 32) + (let* ((a3-7 arg0) + (t0-0 (-> a3-7 base)) + ) + (set! (-> (the-as (pointer uint64) t0-0) 0) + (the-as + uint + (logior (shl (the-as int (* 0.001953125 (+ 0.5 (the float a1-39)))) 32) + (shr (shl (the-as int (* 0.001953125 (+ 0.5 (the float t1-0)))) 32) 32) + ) + ) + ) + (set! (-> (the-as (pointer uint64) t0-0) 1) + (the-as + uint + (logior (logior (shl #x1ffff 32) (shr (shl (* (+ s5-0 t1-0) 16) 48) 48)) + (shr (shl (* (+ s4-0 a1-39) 16) 48) 32) + ) + ) + ) + (set! (-> (the-as (pointer uint64) t0-0) 2) + (the-as + uint + (logior (shl (the-as int (* 0.001953125 (+ 0.5 (the float s3-0)))) 32) + (shr (shl (the-as int (* 0.001953125 (+ 0.5 (the float a0-27)))) 32) 32) + ) + ) + ) + (set! (-> (the-as (pointer uint64) t0-0) 3) + (the-as uint (logior (logior (shl #x1ffff 32) (shr (shl (* (+ s5-0 a0-27) 16) 48) 48)) + (shr (shl (* (+ s4-0 s3-0) 16) 48) 32) + ) + ) + ) + (set! (-> a3-7 base) (&+ t0-0 32)) + ) + ) + ) + ) + (let ((a1-43 (/ (the-as int (+ (- -16 (the-as int v1-16)) (the-as int (-> arg0 base)))) 16))) + (cond + ((nonzero? a1-43) + (logior! (-> (the-as (pointer uint64) v1-16) 0) (shr (shl a1-43 48) 48)) + (logior! (-> (the-as (pointer uint64) v1-16) 1) (shl (shr (shl a1-43 48) 48) 32)) + ) + (else + (set! (-> arg0 base) v1-16) + ) + ) + ) + ) + ) + ) + ) + (reset-display-gs-state *display* arg0) + (none) + ) + +(deftype shadow-stats (structure) + ((num-single-tris uint32) + (num-double-tris uint32) + (num-single-edges uint32) + (num-double-edges uint32) + (num-fragments uint16) + (num-objects uint16) + ) + ) + + +(deftype shadow-dcache (structure) + ((vtx-table uint32) + (single-edge-table uint32) + (double-edge-table uint32) + (double-tri-table uint32) + (dcache-top uint32) + (num-facing-single-tris uint32) + (num-single-edges uint32) + (num-double-edges uint32) + (single-tri-list uint32) + (single-edge-list uint32) + (double-edge-list uint32) + (ptr-dual-verts uint32) + (stats shadow-stats :inline) + (frag-qwc uint32) + (center vector :inline) + (plane vector :inline) + (top-plane vector :inline) + (near-plane vector :inline) + (light-dir vector :inline) + (vtx-min vector :inline) + (data uint8 :dynamic) + ) + ) + + +(define shadow-vu0-block (new 'static 'vu-function :length 88 :qlength 44)) + +(def-mips2c shadow-xform-verts function) + +(def-mips2c shadow-calc-dual-verts function) + +(def-mips2c shadow-scissor-edges function) + +(def-mips2c shadow-scissor-top function) + +(def-mips2c shadow-init-vars function) + +(def-mips2c shadow-find-facing-single-tris function) + +(def-mips2c shadow-find-single-edges function) + +(def-mips2c shadow-find-facing-double-tris function) + +(def-mips2c shadow-find-double-edges function) + +(def-mips2c shadow-add-verts function) + +(def-mips2c shadow-add-facing-single-tris function) + +(def-mips2c shadow-add-single-edges function) + +(def-mips2c shadow-add-single-tris function) + +(def-mips2c shadow-add-double-tris function) + +(def-mips2c shadow-add-double-edges function) + +(defmethod shadow-control-method-14 ((this shadow-control) (arg0 vector) (arg1 vector) (arg2 float) (arg3 float) (arg4 float)) + (let ((gp-0 (-> this settings))) + (let ((s4-0 (-> gp-0 shadow-dir))) + (vector-normalize-copy! s4-0 arg1 1.0) + (set! (-> gp-0 shadow-dir w) (- arg2)) + (when *shadow-debug* + (add-debug-x #t (bucket-id debug-no-zbuf1) arg0 *color-red*) + (add-debug-vector #t (bucket-id debug-no-zbuf1) arg0 s4-0 (meters 3) *color-red*) + ) + (let ((s1-2 (vector+float*! (new 'stack-no-clear 'vector) arg0 s4-0 arg3)) + (s5-2 (vector+float*! (new 'stack-no-clear 'vector) arg0 s4-0 arg4)) + ) + (vector-negate! (-> gp-0 top-plane) s4-0) + (vector-negate! (-> gp-0 bot-plane) s4-0) + (set! (-> gp-0 top-plane w) (- (vector-dot s1-2 (the-as vector (-> gp-0 top-plane))))) + (set! (-> gp-0 bot-plane w) (- (vector-dot s5-2 (the-as vector (-> gp-0 bot-plane))))) + ) + ) + (logior! (-> gp-0 flags) (shadow-flags shdf02 shdf03 shdf04 shdf07)) + ) + 0 + (none) + ) + +(defun debug-draw-settings ((arg0 shadow-settings)) + (let ((s4-0 (-> arg0 shadow-dir)) + (s5-0 (-> arg0 center)) + (s3-0 (-> arg0 top-plane)) + (s2-0 (-> arg0 bot-plane)) + (s1-0 (new 'stack-no-clear 'vector)) + (s0-0 (new 'stack-no-clear 'vector)) + ) + (cond + ((logtest? (-> arg0 flags) (shadow-flags shdf02)) + (vector+float*! s1-0 s5-0 s4-0 (- (vector-dot (the-as vector s3-0) s5-0) (-> s3-0 w))) + (vector+float*! s0-0 s5-0 s4-0 (- (vector-dot (the-as vector s2-0) s5-0) (-> s2-0 w))) + ) + (else + (let ((v1-7 (vector+float*! (new 'stack-no-clear 'vector) s5-0 s4-0 (-> s4-0 w)))) + (vector+float*! s1-0 v1-7 s4-0 (- (vector-dot (the-as vector s3-0) v1-7) (-> s3-0 w))) + (vector+float*! s0-0 v1-7 s4-0 (- (vector-dot (the-as vector s2-0) v1-7) (-> s2-0 w))) + ) + ) + ) + (add-debug-sphere #t (bucket-id debug-no-zbuf1) s5-0 (meters 0.8) *color-magenta*) + (add-debug-vector #t (bucket-id debug-no-zbuf1) s5-0 s4-0 (meters 4) *color-magenta*) + (add-debug-x #t (bucket-id debug-no-zbuf1) s1-0 *color-blue*) + (add-debug-vector #t (bucket-id debug-no-zbuf1) s1-0 s3-0 (meters 2) *color-blue*) + (add-debug-line #t (bucket-id debug-no-zbuf1) (-> arg0 center) s1-0 *color-blue* #f (the-as rgba -1)) + (add-debug-x #t (bucket-id debug-no-zbuf1) s0-0 *color-green*) + (add-debug-vector #t (bucket-id debug-no-zbuf1) s0-0 s2-0 (meters 2) *color-green*) + (add-debug-line #t (bucket-id debug-no-zbuf1) s1-0 s0-0 *color-green* #f (the-as rgba -1)) + ) + ) + +(def-mips2c shadow-execute (function shadow-dma-packet pointer pointer)) + +;; ERROR: Failed store: (s.d! (+ (the-as dma-packet a0-5) 8) 0) at op 17 +(defun shadow-vu0-upload () + (#unless PC_PORT + (let ((gp-0 *vu0-dma-list*)) + (let ((v1-0 gp-0)) + (set! (-> v1-0 base) (-> v1-0 data)) + (set! (-> v1-0 end) (&-> v1-0 data-buffer (-> v1-0 allocated-length))) + ) + (dma-buffer-add-vu-function gp-0 shadow-vu0-block 0) + (let* ((v1-1 gp-0) + (a0-5 (the-as object (-> v1-1 base))) + ) + (set! (-> (the-as dma-packet a0-5) dma) (new 'static 'dma-tag :id (dma-tag-id end))) + (s.d! (+ (the-as dma-packet a0-5) 8) 0) + (set! (-> v1-1 base) (&+ (the-as pointer a0-5) 16)) + ) + (.sync.l) + (dma-buffer-send-chain (the-as dma-bank-source #x10008000) gp-0) + ) + ) + 0 + (none) + ) + +;; ERROR: Failed store: (s.h! (+ v1-25 18) 0) at op 61 +;; ERROR: Failed store: (s.h! (+ v1-25 16) 0) at op 62 +(defun shadow-execute-all ((arg0 dma-buffer)) + (when *debug-segment* + (let ((gp-0 (-> *display* frames (-> *display* on-screen) profile-array data 0)) + (v1-7 'other) + (s5-0 *profile-other-color*) + ) + (when (and *dproc* *debug-segment*) + (let ((s4-0 (-> gp-0 data (-> gp-0 count)))) + (let ((s3-0 (-> gp-0 base-time))) + (set! (-> s4-0 name) v1-7) + (set! (-> s4-0 start-time) (the-as int (- (timer-count (the-as timer-bank #x10000800)) (the-as uint s3-0)))) + ) + (set! (-> s4-0 depth) (the-as uint (-> gp-0 depth))) + (set! (-> s4-0 color) s5-0) + (set! (-> gp-0 segment (-> gp-0 depth)) s4-0) + ) + (set! (-> gp-0 count) (min 1023 (+ (-> gp-0 count) 1))) + (+! (-> gp-0 depth) 1) + (set! (-> gp-0 max-depth) (max (-> gp-0 max-depth) (-> gp-0 depth))) + ) + ) + 0 + ) + (when (logtest? (vu1-renderer-mask rn32) (-> *display* vu1-enable-user)) + (let ((gp-1 *shadow-globals*)) + (let ((v1-25 (the-as shadow-dcache (-> (the-as shadow-dcache *gsf-buffer*) stats)))) + (set! (-> v1-25 vtx-table) (the-as uint 0)) + (set! (-> v1-25 single-edge-table) (the-as uint 0)) + (set! (-> v1-25 double-edge-table) (the-as uint 0)) + (set! (-> v1-25 double-tri-table) (the-as uint 0)) + ;; (s.h! (+ v1-25 18) 0) + ;; (s.h! (+ v1-25 16) 0) + (set! (-> v1-25 dcache-top) (the-as uint 0)) + ) + 0 + (let ((v1-27 #f)) + (dotimes (a0-13 3) + (if (nonzero? (-> gp-1 bucket a0-13 first)) + (set! v1-27 #t) + ) + ) + (when v1-27 + (shadow-vu0-upload) + (dotimes (s5-1 3) + (let* ((s4-1 (-> gp-1 bucket s5-1)) + (s1-0 (-> s4-1 first)) + ) + (when (nonzero? s1-0) + (with-dma-buffer-add-bucket ((s2-0 (-> *display* frames (-> *display* on-screen) global-buf)) + (-> s4-1 bucket-id) + ) + (set! (-> (scratchpad-object shadow-dcache) ptr-dual-verts) (the-as uint 0)) + (shadow-vu1-init-buffer s2-0 s5-1) + (flush-cache 0) + (shadow-dma-init s2-0) + (set! (-> s2-0 base) (shadow-execute (the-as shadow-dma-packet s1-0) (-> s2-0 base))) + (let ((a2-1 (nonzero? (-> (scratchpad-object shadow-dcache) ptr-dual-verts))) + (a1-9 (logior (shl #x3f800000 32) (shr (shl (the-as int (the-as uint32 (-> s4-1 shadow-color))) 32) 32))) + ) + (let ((v1-43 (-> *time-of-day-context* current-shadow-color))) + (if (zero? s5-1) + (set! a1-9 + (logior (logand (logior (logand (logior (logand a1-9 -256) (shr (shl (the int (* 128.0 (-> v1-43 x))) 56) 56)) -65281) + (shr (shl (the int (* 128.0 (-> v1-43 y))) 56) 48) + ) + -16711681 + ) + (shr (shl (the int (* 128.0 (-> v1-43 z))) 56) 40) + ) + ) + ) + ) + ;; modified in pc port so we don't have to do the crazy z buffer flipping stuff. + (shadow-dma-end s2-0 (the-as gs-rgbaq a1-9) #f #|a2-1|# s5-1) + ) + ) + ) + ) + ) + ) + ) + ) + (let ((gp-2 *gsf-buffer*)) + (let ((v1-61 (-> *terrain-stats* shadow))) + (+! (-> v1-61 groups) (-> (the-as shadow-dcache gp-2) stats num-objects)) + (+! (-> v1-61 fragments) (-> (the-as shadow-dcache gp-2) stats num-objects)) + (+! (-> v1-61 tris) + (* (+ (-> (the-as shadow-dcache gp-2) stats num-single-tris) + (-> (the-as shadow-dcache gp-2) stats num-double-tris) + (-> (the-as shadow-dcache gp-2) stats num-single-edges) + (-> (the-as shadow-dcache gp-2) stats num-double-edges) + ) + 2 + ) + ) + (+! (-> v1-61 dverts) + (* (the-as uint 6) (-> (the-as shadow-dcache gp-2) stats num-single-tris)) + (* (the-as uint 6) (-> (the-as shadow-dcache gp-2) stats num-double-tris)) + (* (-> (the-as shadow-dcache gp-2) stats num-single-edges) 4) + (* (-> (the-as shadow-dcache gp-2) stats num-double-edges) 4) + ) + ) + (when #f + (format *stdcon* "~%~%~%~%#single tris : ~4d~%" (-> (the-as shadow-dcache gp-2) stats num-single-tris)) + (format *stdcon* "#double tris : ~4d~%" (-> (the-as shadow-dcache gp-2) stats num-double-tris)) + (format *stdcon* "#single edges: ~4d~%" (-> (the-as shadow-dcache gp-2) stats num-single-edges)) + (format *stdcon* "#double edges: ~4d~%" (-> (the-as shadow-dcache gp-2) stats num-double-edges)) + ) + ) + ) + (when *debug-segment* + (let ((gp-3 (-> *display* frames (-> *display* on-screen) profile-array data 0))) + (when (and *dproc* *debug-segment*) + (let* ((v1-75 (+ (-> gp-3 depth) -1)) + (s5-2 (-> gp-3 segment v1-75)) + (s4-2 (-> gp-3 base-time)) + ) + (when (>= v1-75 0) + (set! (-> s5-2 end-time) (the-as int (- (timer-count (the-as timer-bank #x10000800)) (the-as uint s4-2)))) + (+! (-> gp-3 depth) -1) + ) + ) + ) + ) + 0 + ) + 0 + (none) + ) + +(defmethod probe-line-for-shadow ((this shadow-control) (arg0 vector) (arg1 float) (arg2 float) (arg3 float)) + (with-pp + (let ((s4-0 (new 'stack-no-clear 'collide-query))) + (let ((v1-0 pp)) + (set! (-> s4-0 start-pos quad) (-> arg0 quad)) + (+! (-> s4-0 start-pos y) 4096.0) + (set-vector! (-> s4-0 move-dist) 0.0 (- arg3) 0.0 1.0) + (let ((a0-4 s4-0)) + (set! (-> a0-4 radius) 8192.0) + (set! (-> a0-4 collide-with) (collide-spec backgnd)) + (set! (-> a0-4 ignore-process0) v1-0) + (set! (-> a0-4 ignore-process1) #f) + (set! (-> a0-4 ignore-pat) + (new 'static 'pat-surface :noentity #x1 :nojak #x1 :probe #x1 :noendlessfall #x1 :board #x1) + ) + (set! (-> a0-4 action-mask) (collide-action solid)) + ) + ) + (cond + ((>= (fill-and-probe-using-line-sphere *collide-cache* s4-0) 0.0) + (let ((v1-5 this)) + (logclear! (-> v1-5 settings flags) (shadow-flags disable-draw)) + ) + 0 + (let ((v1-7 this)) + (set! (-> v1-7 settings bot-plane w) (- (+ (-> s4-0 best-other-tri intersect y) arg1))) + ) + 0 + (set! (-> this settings top-plane w) (- (+ (-> s4-0 best-other-tri intersect y) arg2))) + 0 + ) + (else + (let ((v1-10 this)) + (logior! (-> v1-10 settings flags) (shadow-flags disable-draw)) + ) + 0 + ) + ) + ) + 0 + (none) + ) + ) diff --git a/goal_src/jak3/engine/gfx/foreground/shadow-vu1.gc b/goal_src/jak3/engine/gfx/foreground/shadow-vu1.gc index fe8937954..d40f6fbef 100644 --- a/goal_src/jak3/engine/gfx/foreground/shadow-vu1.gc +++ b/goal_src/jak3/engine/gfx/foreground/shadow-vu1.gc @@ -7,3 +7,222 @@ ;; DECOMP BEGINS +(deftype shadow-vu1-constants (structure) + ((hmgescale vector :inline) + (invhscale vector :inline) + (texoffset vector :inline) + (texscale vector :inline) + (hvdfoff vector :inline) + (fog vector :inline) + (clrs vector 2 :inline) + (adgif gs-gif-tag :inline) + (texflush gs-adcmd :inline) + (flush gs-adcmd :inline) + (trigif gs-gif-tag :inline) + (quadgif gs-gif-tag :inline) + ) + ) + + +(deftype shadow-vu1-data (structure) + ((adgif gs-gif-tag :inline) + (ad gs-adcmd :inline) + (flush gs-adcmd :inline) + (trigif gs-gif-tag :inline) + (quadgif gs-gif-tag :inline) + (texoffset vector :inline) + (texscale vector :inline) + (clrs qword 2 :inline) + ) + ) + + +(define *shadow-vu1-data* (new 'static 'shadow-vu1-data + :adgif (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 :nloop #x1 :nreg #x1) + :regs (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + :ad (new 'static 'gs-adcmd :cmds (gs-reg64 texflush)) + :flush (new 'static 'gs-adcmd :cmds (gs-reg64 rgbaq) :y #x3f800000) + :trigif (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1) + :nreg #x7 + ) + :regs (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyzf2) + :regs5 (gif-reg-id st) + :regs6 (gif-reg-id xyzf2) + ) + ) + :quadgif (new 'static 'gs-gif-tag + :tag (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1) + :nreg #x9 + ) + :regs (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id st) + :regs2 (gif-reg-id xyzf2) + :regs3 (gif-reg-id st) + :regs4 (gif-reg-id xyzf2) + :regs5 (gif-reg-id st) + :regs6 (gif-reg-id xyzf2) + :regs7 (gif-reg-id st) + :regs8 (gif-reg-id xyzf2) + ) + ) + :texoffset (new 'static 'vector :x 256.5 :y 208.5) + :texscale (new 'static 'vector :x 0.001953125 :y 0.001953125) + :clrs (new 'static 'inline-array qword 2 + (new 'static 'qword :data (new 'static 'array uint32 4 #x80 #x0 #x0 #x82)) + (new 'static 'qword :data (new 'static 'array uint32 4 #x0 #x80 #x0 #x7f)) + ) + ) + ) + +(define shadow-vu1-block (new 'static 'vu-function #| :length #x2e9 :qlength #x175 |#)) + +;; WARN: Return type mismatch dma-buffer vs none. +(defun shadow-vu1-add-constants ((arg0 dma-buffer) (arg1 int)) + (let* ((a3-0 13) + (v1-0 arg0) + (a2-0 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a2-0) dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc a3-0)) + (set! (-> (the-as dma-packet a2-0) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a2-0) vif1) + (new 'static 'vif-tag :imm #x370 :cmd (vif-cmd unpack-v4-32) :num a3-0) + ) + (set! (-> v1-0 base) (the-as pointer (&+ (the-as dma-packet a2-0) 16))) + ) + (let ((v1-1 (the-as object (-> arg0 base)))) + (let ((a3-4 *math-camera*) + (a2-2 *shadow-vu1-data*) + ) + (set! (-> (the-as shadow-vu1-constants v1-1) hmgescale quad) (-> a3-4 hmge-scale quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) invhscale quad) (-> a3-4 inv-hmge-scale quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) hvdfoff quad) (-> a3-4 hvdf-off quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) hvdfoff x) 2048.0) + (set! (-> (the-as shadow-vu1-constants v1-1) hvdfoff y) 2048.0) + (set! (-> (the-as shadow-vu1-constants v1-1) fog x) (-> a3-4 pfog0)) + (set! (-> (the-as shadow-vu1-constants v1-1) clrs 0 quad) (-> a2-2 clrs 0 quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) clrs 1 quad) (-> a2-2 clrs 1 quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) texoffset quad) (-> a2-2 texoffset quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) texscale quad) (-> a2-2 texscale quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) adgif qword) (-> a2-2 adgif qword)) + (set! (-> (the-as shadow-vu1-constants v1-1) texflush quad) (-> a2-2 ad quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) flush quad) (-> a2-2 flush quad)) + (set! (-> (the-as shadow-vu1-constants v1-1) trigif qword) (-> a2-2 trigif qword)) + (set! (-> (the-as shadow-vu1-constants v1-1) quadgif qword) (-> a2-2 quadgif qword)) + ) + (set! (-> *shadow-globals* bucket arg1 constants) (the-as shadow-vu1-constants v1-1)) + ) + (&+! (-> arg0 base) 208) + (let* ((v1-4 arg0) + (a1-3 (the-as object (-> v1-4 base))) + ) + (set! (-> (the-as dma-packet a1-3) dma) (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a1-3) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a1-3) vif1) + (new 'static 'vif-tag :imm #x3ac :num #x4 :cmd (vif-cmd unpack-v4-32)) + ) + (set! (-> v1-4 base) (&+ (the-as pointer a1-3) 16)) + ) + (let* ((v1-5 arg0) + (a1-5 (the-as object (-> v1-5 base))) + ) + (set! (-> (the-as shadow-vu1-data a1-5) adgif tag) (new 'static 'gif-tag64 :nloop #x1 :nreg #x2)) + (set! (-> (the-as shadow-vu1-data a1-5) adgif regs) + (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d) :regs1 (gif-reg-id rgbaq)) + ) + (set! (-> (the-as shadow-vu1-data a1-5) ad data) (the-as uint 0)) + (set! (-> (the-as shadow-vu1-data a1-5) ad cmds) (gs-reg64 texflush)) + (set! (-> (the-as shadow-vu1-data a1-5) flush data) (the-as uint 0)) + (set! (-> (the-as shadow-vu1-data a1-5) flush cmds) (gs-reg64 prim)) + (set! (-> (the-as shadow-vu1-data a1-5) trigif tag) + (new 'static 'gif-tag64 + :nloop #x3 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-fan) :tme #x1) + :nreg #x2 + ) + ) + (set! (-> (the-as shadow-vu1-data a1-5) trigif regs) + (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id xyzf2)) + ) + (set! (-> v1-5 base) (&+ (the-as pointer a1-5) 64)) + ) + (none) + ) + +(defun shadow-vu1-patch-consts ((arg0 symbol) (arg1 int)) + (let ((v1-2 (-> *shadow-globals* bucket arg1 constants))) + (cond + (arg0 + (set! (-> v1-2 hvdfoff z) (- 1.0 (-> v1-2 hvdfoff z))) + (set! (-> v1-2 fog w) -1.0) + ) + (else + (set! (-> v1-2 fog w) 1.0) + ) + ) + ) + 0 + (none) + ) + +;; WARN: Return type mismatch dma-buffer vs none. +(defun shadow-vu1-add-matrix ((arg0 dma-buffer) (arg1 math-camera)) + (let ((v1-0 4)) + (let* ((a2-4 arg0) + (a3-0 (the-as object (-> a2-4 base))) + ) + (set! (-> (the-as dma-packet a3-0) dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc v1-0)) + (set! (-> (the-as dma-packet a3-0) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a3-0) vif1) (new 'static 'vif-tag :cmd (vif-cmd unpack-v4-32) :num v1-0)) + (set! (-> a2-4 base) (&+ (the-as pointer a3-0) 16)) + ) + ) + (let ((v1-5 (the-as object (-> arg0 base)))) + (let ((a2-5 (-> arg1 perspective rvec quad)) + (a3-1 (-> arg1 perspective uvec quad)) + (t0-4 (-> arg1 perspective fvec quad)) + (a1-1 (-> arg1 perspective trans quad)) + ) + (set! (-> (the-as matrix v1-5) rvec quad) a2-5) + (set! (-> (the-as matrix v1-5) uvec quad) a3-1) + (set! (-> (the-as matrix v1-5) fvec quad) t0-4) + (set! (-> (the-as matrix v1-5) trans quad) a1-1) + ) + (set! (-> arg0 base) (&+ (the-as pointer v1-5) 64)) + ) + (none) + ) + +;; WARN: Return type mismatch dma-buffer vs none. +(defun shadow-vu1-init-buffer ((arg0 dma-buffer) (arg1 int)) + (dma-buffer-add-vu-function arg0 shadow-vu1-block 1) + (shadow-vu1-add-constants arg0 arg1) + (shadow-vu1-add-matrix arg0 *math-camera*) + (let* ((v1-0 arg0) + (a0-4 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-4) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-4) vif0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1 :imm #xa)) + (set! (-> (the-as dma-packet a0-4) vif1) (new 'static 'vif-tag :cmd (vif-cmd flushe) :msk #x1)) + (set! (-> v1-0 base) (&+ (the-as pointer a0-4) 16)) + ) + (none) + )