diff --git a/examples/PoolBox/application/src/Overlay/GTETest/include/GTE_Sprite.hpp b/examples/PoolBox/application/src/Overlay/GTETest/include/GTE_Sprite.hpp index 8ff06c08..32f8ad7a 100644 --- a/examples/PoolBox/application/src/Overlay/GTETest/include/GTE_Sprite.hpp +++ b/examples/PoolBox/application/src/Overlay/GTETest/include/GTE_Sprite.hpp @@ -18,22 +18,19 @@ namespace GTETest { } void apply(const GTE::MATRIX& matrix) { - static const auto apply_to = [](const GTE::MATRIX& matrix, GTE::SVECTOR vector) -> GPU::Vertex { + static const auto apply_to = [](const GTE::MATRIX& matrix, GPU::Vertex vertex) -> GPU::Vertex { GTE::MATRIX move_back = GTE::MATRIX{ GTE::ROTMATRIX::identity(), GTE::TRANSFERVECTOR::translated(-matrix.transfer.x, -matrix.transfer.y, -matrix.transfer.z) }; - GTE::SVECTOR output; - int32_t flag; - GTE::comp_matrix(matrix, move_back, move_back); - return GTE::apply_matrix(move_back, vector, output).to(); + return GTE::apply_matrix(move_back, vertex, vertex); }; const auto& area = this->area; - this->display.vertex0 = apply_to(matrix, GTE::SVECTOR::from(area.get_top_left())); - this->display.vertex1 = apply_to(matrix, GTE::SVECTOR::from(area.get_top_right())); - this->display.vertex2 = apply_to(matrix, GTE::SVECTOR::from(area.get_bottom_left())); - this->display.vertex3 = apply_to(matrix, GTE::SVECTOR::from(area.get_bottom_right())); + this->display.vertex0 = apply_to(matrix, area.get_top_left()); + this->display.vertex1 = apply_to(matrix, area.get_top_right()); + this->display.vertex2 = apply_to(matrix, area.get_bottom_left()); + this->display.vertex3 = apply_to(matrix, area.get_bottom_right()); } void render() { diff --git a/include/PSX/GTE/gte.hpp b/include/PSX/GTE/gte.hpp index c5cd2370..7c271963 100644 --- a/include/PSX/GTE/gte.hpp +++ b/include/PSX/GTE/gte.hpp @@ -5,6 +5,20 @@ namespace JabyEngine { namespace GTE { static constexpr auto StackSize = 16; + /* + matrix: first input + + Sets the 3x3 constant rotation matrix and the parallel transfer vector from input + */ + void set_matrix(const MATRIX& matrix); + + /* + returns: current matrix + + Gets the current 3x3 constant rotation matrix and the parallel transfer vector + */ + MATRIX get_matrix(); + /* RotTrans @@ -99,8 +113,28 @@ namespace JabyEngine { returns: result Applies the matrix to the vector + The function destroys the constant rotation matrix and transfer vector */ - SVECTOR& apply_matrix(const MATRIX& m0, const SVECTOR& v0, SVECTOR& v1); + static SVECTOR& apply_matrix(const MATRIX& m0, const SVECTOR& v0, SVECTOR& v1) { + set_matrix(m0); + + JabyEngine::GTE::ldv0(v0); + JabyEngine::GTE::rt(); + JabyEngine::GTE::stsv(v1); + return v1; + } + + /* + Same as apply_matrix but works on Vertex + */ + static GPU::Vertex& apply_matrix(const MATRIX& m0, const GPU::Vertex& v0, GPU::Vertex& v1) { + set_matrix(m0); + + JabyEngine::GTE::ldgv0(v0); + JabyEngine::GTE::rt(); + JabyEngine::GTE::stgv(v1); + return v1; + } /* MulMatrix0 @@ -133,20 +167,6 @@ namespace JabyEngine { return result; } - /* - matrix: first input - - Sets the 3x3 constant rotation matrix and the parallel transfer vector from input - */ - void set_matrix(const MATRIX& matrix); - - /* - returns: current matrix - - Gets the current 3x3 constant rotation matrix and the parallel transfer vector - */ - MATRIX get_matrix(); - /* matrix: optional input diff --git a/include/PSX/GTE/gte_instruction.hpp b/include/PSX/GTE/gte_instruction.hpp index 09735981..167fcbc6 100644 --- a/include/PSX/GTE/gte_instruction.hpp +++ b/include/PSX/GTE/gte_instruction.hpp @@ -29,7 +29,12 @@ namespace JabyEngine { __asm__ volatile("or $12, $12, $13" :: "r"(&vector) : "$12", "$13"); __asm__ volatile("mtc2 $12, $0" :: "r"(&vector) : "$12", "$13"); __asm__ volatile("lwc2 $1, 8(%0)" :: "r"(&vector) : "$12", "$13"); - + } + + // Loads a GPU VERTEX type + static __always_inline void ldgv0(const GPU::Vertex& vertex) { + __asm__ volatile("lwc2 $0, 0(%0)" :: "r"(&vertex)); + __asm__ volatile("lwc2 $1, 0" :: "r"(&vertex)); } // Load column vector of MATRIX to universal register @@ -77,6 +82,14 @@ namespace JabyEngine { __asm__ volatile("sh $14, 4(%0)" :: "r"(&out_vector) : "$12", "$13", "$14", "memory"); } + // Stores result into a GPU Vertex type + static __always_inline void stgv(GPU::Vertex& out_vertex) { + __asm__ volatile("mfc2 $12, $9" :: "r"(&out_vertex) : "$12", "$13", "$14", "memory"); + __asm__ volatile("mfc2 $13, $10" :: "r"(&out_vertex) : "$12", "$13", "$14", "memory"); + __asm__ volatile("sh $12, 0(%0)" :: "r"(&out_vertex) : "$12", "$13", "$14", "memory"); + __asm__ volatile("sh $13, 2(%0)" :: "r"(&out_vertex) : "$12", "$13", "$14", "memory"); + } + /* Kernel of RotTrans (Transfer vector)+(Rotation Matrix)*(vertex register 0) diff --git a/include/PSX/GTE/gte_types.hpp b/include/PSX/GTE/gte_types.hpp index f75fccba..603ecd96 100644 --- a/include/PSX/GTE/gte_types.hpp +++ b/include/PSX/GTE/gte_types.hpp @@ -10,13 +10,14 @@ namespace JabyEngine { T x; T y; T z; + T pad; static constexpr VECTOR create() { return VECTOR::create(0, 0, 0); } static constexpr VECTOR create(T x, T y, T z) { - return VECTOR{.x = x, .y = y, .z = z}; + return VECTOR{.x = x, .y = y, .z = z, .pad = 0}; } template diff --git a/src/Library/src/BootLoader/start_boot.cpp b/src/Library/src/BootLoader/start_boot.cpp index a6e11586..749c20d3 100644 --- a/src/Library/src/BootLoader/start_boot.cpp +++ b/src/Library/src/BootLoader/start_boot.cpp @@ -2,10 +2,7 @@ #include "../../internal-include/GPU/gpu_internal.hpp" #include -#include #include -#include "../../reference/inline_n.h" -#include extern "C" uint32_t __heap_start; extern "C" uint32_t __bss_start; diff --git a/src/Library/src/GTE/gte.cpp b/src/Library/src/GTE/gte.cpp index 4a7c3127..77566591 100644 --- a/src/Library/src/GTE/gte.cpp +++ b/src/Library/src/GTE/gte.cpp @@ -43,16 +43,6 @@ namespace JabyEngine { static MATRIX Stack[StackSize]; static MATRIX* FreeStackEntry = Stack; - SVECTOR& apply_matrix(const MATRIX& m0, const SVECTOR& v0, SVECTOR& v1) { - // TODO: Do we want to push here? - set_matrix(m0); - - JabyEngine::GTE::ldv0(v0); - JabyEngine::GTE::rt(); - JabyEngine::GTE::stsv(v1); - return v1; - } - ROTMATRIX& multiply_matrix(const ROTMATRIX& m0, const ROTMATRIX& m1, ROTMATRIX& result) { set_rot_matrix(m0);