Add some GTE code

This commit is contained in:
Jaby 2024-01-24 12:04:03 -05:00
parent b41b5f25bf
commit 3a38f3192f
5 changed files with 107 additions and 2 deletions

View File

@ -1,3 +1,27 @@
#pragma once
#include "gte_instruction.hpp"
namespace JabyEngine {}
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));
}
}
}

View File

@ -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));
}
}
}

View File

@ -0,0 +1,43 @@
#pragma once
#include "../jabyengine_defines.h"
namespace JabyEngine {
namespace GTE {
namespace internal {
template<typename T>
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<int32_t>;
using SVECTOR = internal::VECTOR<int16_t>;
}
}

View File

@ -66,7 +66,9 @@
"**/*.dep": true
},
"files.associations": {
"stdio.h": "c"
"stdio.h": "c",
"TUTO0.C": "cpp",
"MAIN.C": "cpp"
}
}
}

View File

@ -3,7 +3,9 @@
#include <PSX/System/IOPorts/dma_io.hpp>
#include <stdio.h>
#include <PSX/GTE/gte.hpp>
#include <PSX/System/syscalls.hpp>
#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();