diff --git a/include/PSX/GTE/gte.hpp b/include/PSX/GTE/gte.hpp index 88739f32..ff15c048 100644 --- a/include/PSX/GTE/gte.hpp +++ b/include/PSX/GTE/gte.hpp @@ -1,3 +1,27 @@ #pragma once +#include "gte_instruction.hpp" -namespace JabyEngine {} \ No newline at end of file +namespace JabyEngine { + namespace GTE { + /* + gte_SetGeomOffset(ofx,ofy) + + Load GTE-offset. + */ + static void set_geom_offset(int32_t off_x, int32_t off_y) { + __asm__ volatile("sll $12, %0, 16" :: "r"(off_x), "r"(off_y) : "$12", "$13"); + __asm__ volatile("sll $13, %1, 16" :: "r"(off_x), "r"(off_y) : "$12", "$13"); + __asm__ volatile("ctc2 $12, $24" :: "r"(off_x), "r"(off_y) : "$12", "$13"); + __asm__ volatile("ctc2 $13, $25" :: "r"(off_x), "r"(off_y) : "$12", "$13"); + } + + /* + gte_SetGeomScreen(h) + + Load distance from viewpoint to screen. + */ + static void set_geom_screen(int32_t h) { + __asm__ volatile("ctc2 %0, $26" :: "r"(h)); + } + } +} \ No newline at end of file diff --git a/include/PSX/GTE/gte_instruction.hpp b/include/PSX/GTE/gte_instruction.hpp new file mode 100644 index 00000000..0598e40a --- /dev/null +++ b/include/PSX/GTE/gte_instruction.hpp @@ -0,0 +1,21 @@ +#pragma once +#include "gte_types.hpp" + +namespace JabyEngine { + namespace GTE { + static __always_inline void ldv0(const SVECTOR& vector) { + __asm__ volatile("lwc2 $0, 0(%0)":: "r"(&vector)); + __asm__ volatile("lwc2 $1, 4(%0)":: "r"(&vector)); + } + + static __always_inline void ldv1(const SVECTOR& vector) { + __asm__ volatile("lwc2 $2, 0(%0)":: "r"(&vector)); + __asm__ volatile("lwc2 $3, 4(%0)":: "r"(&vector)); + } + + static __always_inline void ldv2(const SVECTOR& vector) { + __asm__ volatile("lwc2 $4, 0(%0)":: "r"(&vector)); + __asm__ volatile("lwc2 $5, 4(%0)":: "r"(&vector)); + } + } +} \ No newline at end of file diff --git a/include/PSX/GTE/gte_types.hpp b/include/PSX/GTE/gte_types.hpp new file mode 100644 index 00000000..437c5dde --- /dev/null +++ b/include/PSX/GTE/gte_types.hpp @@ -0,0 +1,43 @@ +#pragma once +#include "../jabyengine_defines.h" + +namespace JabyEngine { + namespace GTE { + namespace internal { + template + struct VECTOR { + 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, .pad = 0}; + } + }; + } + + struct MATRIX { + int16_t rot[3][3]; // Rotation matrix + int32_t trans[3]; // Translation vector + + static constexpr MATRIX identity() { + return MATRIX{ + .rot = { + {1, 0, 0}, + {0, 1, 0}, + {0, 0, 1} + }, + .trans = {0, 0, 0} + }; + } + }; + + using VECTOR = internal::VECTOR; + using SVECTOR = internal::VECTOR; + } +} \ No newline at end of file diff --git a/src/Library/Library.code-workspace b/src/Library/Library.code-workspace index 24cb6ef6..8ca4cc99 100644 --- a/src/Library/Library.code-workspace +++ b/src/Library/Library.code-workspace @@ -66,7 +66,9 @@ "**/*.dep": true }, "files.associations": { - "stdio.h": "c" + "stdio.h": "c", + "TUTO0.C": "cpp", + "MAIN.C": "cpp" } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/start_boot.cpp b/src/Library/src/BootLoader/start_boot.cpp index 1dcc2641..8bab75db 100644 --- a/src/Library/src/BootLoader/start_boot.cpp +++ b/src/Library/src/BootLoader/start_boot.cpp @@ -3,7 +3,9 @@ #include #include +#include #include +#include "../../reference/inline_n.h" extern "C" uint32_t __heap_start; extern "C" uint32_t __bss_start; @@ -65,6 +67,18 @@ namespace JabyEngine { } } + static void test_gte() { + const auto data = GTE::SVECTOR::create(); + + asm("# MY PLANSCHI START"); + GTE::ldv0(data); + asm("# MY PLANSCHI END"); + + asm("# THEIR PLANSCHI START"); + gte_ldv0(&data); + asm("# THEIR PLANSCHI END"); + } + void start() { static constexpr auto DebugX = 0; static constexpr auto DebugY = 0; @@ -74,6 +88,7 @@ namespace JabyEngine { printf("Heap starts @0x%p\n", &__heap_start); printf("BSS from 0x%p to 0x%p (%u)\n", &__bss_start, &__bss_end, __bss_len); test_bios_font(); + test_gte(); __debug_boot_print_at(GPU::Color24::Green(), DebugX, DebugY, DebugScale, "PLANSCHI from 0x%p to 0x%p\n", &__planschi_start, &__planschi_end); boot::Start::setup();