Integrate all the progress into master #6

Merged
jaby merged 595 commits from ToolBox into main 2025-01-01 13:17:44 +00:00
12 changed files with 190 additions and 32 deletions
Showing only changes of commit 09b16dae16 - Show all commits

View File

@ -1,6 +1,7 @@
#include <PSX/File/Processor/cd_file_processor.hpp>
#include <PSX/AutoLBA/auto_lba_declaration.hpp>
#include <PSX/GPU/gpu.hpp>
#include <PSX/GPU/gpu_primitives.hpp>
#include <stdio.h>
enum LBA {
@ -38,10 +39,17 @@ static void load_assets() {
}
void main() {
const JabyEngine::GPU::POLY_F3 triangle(
JabyEngine::GPU::Color24(0x0, 0xFF, 0xFF),
{
{0, 0}, {320*2, 127}, {0, 255}
}
);
printf("Hello PoolBox!\n");
load_assets();
while(true) {
JabyEngine::GPU::render(triangle);
JabyEngine::GPU::swap_buffers_vsync(2);
}
}

View File

@ -0,0 +1,14 @@
#ifndef __JABYENGINE_TYPE_TRAITS_HPP__
#define __JABYENGINE_TYPE_TRAITS_HPP__
namespace JabyEngine {
template<bool B, class T = void>
struct enable_if {};
template<class T>
struct enable_if<true, T> {
typedef T type;
};
}
#endif //! __JABYENGINE_TYPE_TRAITS_HPP__

View File

@ -16,9 +16,7 @@ namespace JabyEngine {
uint32_t raw;
constexpr SimpleTIM() {
this->raw = 0;
}
constexpr SimpleTIM() : raw(0) {}
constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : raw(TextureX.as_value(texX >> 1) | TextureY.as_value(texY >> 1) | ClutX.as_value(clutX >> 4) | ClutY.as_value(static_cast<uint32_t>(clutY))) {
}

View File

@ -1,6 +1,8 @@
#ifndef __JABYENGINE_GPU_HPP__
#define __JABYENGINE_GPU_HPP__
#include "../Auxiliary/type_traits.hpp"
#include "../System/IOPorts/gpu_io.hpp"
#include "gpu_primitives.hpp"
#if !defined(JABYENGINE_NTSC) && !defined(JABYENGINE_PAL)
#error "JABYENGINE_NTSC or JABYENGINE_PAL must be defined"
@ -34,7 +36,16 @@ namespace JabyEngine {
static void set_offset(uint16_t x, uint16_t y);
};
uint8_t swap_buffers_vsync(uint8_t syncs);
namespace internal {
void render(const uint32_t* data, size_t words);
}
template<typename T>
static enable_if<T::is_primitive>::type render(const T& primitive) {
internal::render(reinterpret_cast<const uint32_t*>(&primitive), sizeof(T)/sizeof(uint32_t));
}
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen = true);
}
}
#endif //!__JABYENGINE_GPU_HPP__

View File

@ -0,0 +1,90 @@
#ifndef __JABYENGINE_GPU_PRIMITIVES_HPP__
#define __JABYENGINE_GPU_PRIMITIVES_HPP__
#include "gpu_types.hpp"
namespace JabyEngine {
namespace GPU {
namespace internal {
struct Code {
static constexpr uint8_t CmdValue = 0b001;
static constexpr auto BitCorrection = 24;
static constexpr auto CmdID = BitRange::from_to(29 - BitCorrection, 31 - BitCorrection);
static constexpr auto GouraudShading = Bit(28 - BitCorrection);
static constexpr auto FlatShading = !GouraudShading;
static constexpr auto QuardVertics = Bit(27 - BitCorrection);
static constexpr auto TriVertics = !QuardVertics;
static constexpr auto Textured = Bit(26 - BitCorrection);
static constexpr auto Untextured = !Textured;
static constexpr auto SemiTransparent = Bit(25 - BitCorrection);
static constexpr auto NonTransparent = !SemiTransparent;
static constexpr auto BlendTexture = Bit(24 - BitCorrection);
static constexpr auto NoBlendTexture = !BlendTexture;
uint8_t value = bit::value::set_normalized(0u, CmdID.with(CmdValue));
constexpr Code() = default;
constexpr Code& set(Bit bit) {
this->value = bit::set(this->value, bit);
return *this;
}
constexpr Code& set(ClearBit bit) {
this->value = bit::set(this->value, bit);
return *this;
}
};
struct IsPrimitive {
static constexpr bool is_primitive = true;
};
template<typename T>
struct CodeInterface {
constexpr T& set_semi_transparent() {
static_cast<T*>(this)->code.set(Code::SemiTransparent);
return *static_cast<T*>(this);
}
constexpr T& set_non_transparent() {
static_cast<T*>(this)->code.set(Code::NonTransparent);
return *static_cast<T*>(this);
}
constexpr T& set_texture_blending() {
static_cast<T*>(this)->code.set(Code::BlendTexture);
return *static_cast<T*>(this);
}
constexpr T& set_non_texture_blening() {
static_cast<T*>(this)->code.set(Code::NoBlendTexture);
return *static_cast<T*>(this);
}
};
// Concept for now
template<typename T>
struct Hooked {
uint32_t hook;
T primitive;
};
}
struct POLY_F3 : public internal::IsPrimitive, public internal::CodeInterface<POLY_F3> {
static constexpr auto IdentityCode = internal::Code().set(internal::Code::FlatShading).set(internal::Code::TriVertics).set(internal::Code::Untextured).set(internal::Code::NonTransparent).set(internal::Code::NoBlendTexture);
Color24 color;
internal::Code code = IdentityCode;
PositionI16 vertex[3];
constexpr POLY_F3() = default;
constexpr POLY_F3(Color24 color, const PositionI16 (&verticies)[3]) : color(color), code(IdentityCode), vertex{verticies[0], verticies[1], verticies[2]} {
}
};
static_assert(sizeof(POLY_F3) == 16);
}
}
#endif // !__JABYENGINE_GPU_PRIMITIVES_HPP__

View File

@ -1,5 +1,6 @@
#ifndef __JABYENGINE_GPU_TYPES_HPP__
#define __JABYENGINE_GPU_TYPES_HPP__
#include "../Auxiliary/bits.hpp"
#include "../jabyengine_defines.h"
namespace JabyEngine {

View File

@ -89,16 +89,16 @@ namespace JabyEngine {
struct Command {
struct Helper {
static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) {
return ((cmd << 24) | value);
}
static constexpr GP0_t DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) {
constexpr auto Command = BitRange::from_to(24, 31);
constexpr auto Y = BitRange::from_to(10, 18);
constexpr auto X = BitRange::from_to(0, 9);
return GP0_t::from(Command.with(code), Y.with(y), X.with(x));
}
static constexpr uint32_t construct_cmd(uint8_t cmd, uint32_t value) {
return ((cmd << 24) | value);
return {construct_cmd(code, Y.as_value(static_cast<uint32_t>(y)) | X.as_value(static_cast<uint32_t>(x)))};
}
};
@ -122,12 +122,19 @@ namespace JabyEngine {
return Helper::DrawAreaTemplate(0xE4, x, y);
}
static GP0_t SetDrawOffset(int16_t x, int16_t y) {
constexpr auto X = BitRange::from_to(0, 10);
constexpr auto Y = BitRange::from_to(11, 21);
return {Helper::construct_cmd(0xE5, X.as_value(static_cast<int32_t>(x)) | Y.as_value(static_cast<int32_t>(y)))};
}
static constexpr GP0_t TopLeftPosition(uint16_t x, uint16_t y) {
return {static_cast<uint32_t>((y << 16u) | x)};
return {(static_cast<uint32_t>(y) << 16u) | x};
}
static constexpr GP0_t WidthHeight(uint16_t w, uint16_t h) {
return {static_cast<uint32_t>((h << 16u) | w)};
return {(static_cast<uint32_t>(h) << 16u) | w};
}
static constexpr GP1_t Reset() {
@ -146,25 +153,25 @@ namespace JabyEngine {
return {Helper::construct_cmd(0x04, static_cast<uint32_t>(dir))};
}
static constexpr GP1_t DisplayArea(uint32_t x, uint32_t y) {
static constexpr GP1_t DisplayArea(uint16_t x, uint16_t y) {
constexpr auto X = BitRange::from_to(0, 9);
constexpr auto Y = BitRange::from_to(10, 18);
return {Helper::construct_cmd(0x05, X.as_value(x) | Y.as_value(y))};
return {Helper::construct_cmd(0x05, X.as_value(static_cast<uint32_t>(x)) | Y.as_value(static_cast<uint32_t>(y)))};
}
static constexpr GP1_t HorizontalDisplayRange(uint32_t x1, uint32_t x2) {
static constexpr GP1_t HorizontalDisplayRange(uint16_t x1, uint16_t x2) {
constexpr auto X1 = BitRange::from_to(0, 11);
constexpr auto X2 = BitRange::from_to(12, 23);
return {Helper::construct_cmd(0x06, X1.as_value(x1) | X2.as_value(x2))};
return {Helper::construct_cmd(0x06, X1.as_value(static_cast<uint32_t>(x1)) | X2.as_value(static_cast<uint32_t>(x2)))};
}
static constexpr GP1_t VerticalDisplayRange(uint32_t y1, uint32_t y2) {
static constexpr GP1_t VerticalDisplayRange(uint16_t y1, uint16_t y2) {
constexpr auto Y1 = BitRange::from_to(0, 9);
constexpr auto Y2 = BitRange::from_to(10, 19);
return {Helper::construct_cmd(0x07, Y1.as_value(y1) | Y2.as_value(y2))};
return {Helper::construct_cmd(0x07, Y1.as_value(static_cast<uint32_t>(y1)) | Y2.as_value(static_cast<uint32_t>(y2)))};
}
static constexpr GP1_t DisplayMode(DisplayMode_t mode) {

View File

@ -37,7 +37,7 @@ LD = $(CXX)
AR = ar
#architecture flags
ARCHFLAGS = -march=mips1 -mabi=32 -EL -fno-pic -mno-shared -nostdinc -nostdinc++ -mno-abicalls -mfp32
ARCHFLAGS = -march=r2000 -mtune=r2000 -mabi=32 -EL -fno-pic -mno-shared -nostdinc -nostdinc++ -mno-abicalls -mfp32 -mno-llsc
ARCHFLAGS += -fno-stack-protector -nostdlib -ffreestanding
#Compiler flags for build profiles
@ -46,7 +46,7 @@ CCFLAGS_debug += -O0
CXXFLAGS += -fno-exceptions -fno-rtti
CCFLAGS += -mno-gpopt -fomit-frame-pointer -ffunction-sections
CCFLAGS += -mno-gpopt -fomit-frame-pointer -ffunction-sections -fdata-sections
CCFLAGS += -fno-builtin -fno-strict-aliasing -Wno-attributes
CCFLAGS += -std=c++20
CCFLAGS += $(ARCHFLAGS)

View File

@ -21,17 +21,27 @@ namespace JabyEngine {
static constexpr uint16_t ScanlinesV = 240;
#endif //JABYENGINE_PAL
static void exchange_buffer_and_display();
static uint32_t exchange_buffer_and_display();
};
void wait_vsync(uint8_t syncs);
static void wait_ready_for_CMD() {
while(!GPU_IO::GPUSTAT.is_set(GPU_IO::GPUSTAT_t::GP0ReadyForCMD));
}
static void set_draw_area(uint16_t x, uint16_t y) {
GPU_IO::GP0 = GPU_IO::Command::DrawAreaTopLeft(x, y);
GPU_IO::GP0 = GPU_IO::Command::DrawAreaBottomRight((x + Display::Width), (y + Display::Height));
const auto top_left = GPU_IO::Command::DrawAreaTopLeft(x, y);
const auto bottom_right = GPU_IO::Command::DrawAreaBottomRight((x + Display::Width - 1), (y + Display::Height - 1));
wait_ready_for_CMD();
GPU_IO::GP0 = top_left;
wait_ready_for_CMD();
GPU_IO::GP0 = bottom_right;
}
static void copy_vram_to_vram(const AreaU16& dst, const PositionU16& src) {
wait_ready_for_CMD();
GPU_IO::GP0 = GPU_IO::Command::VRAM2VRAM_Blitting();
GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(src.x, src.y);
GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(dst.position.x, dst.position.y);
@ -39,17 +49,19 @@ namespace JabyEngine {
}
static void quick_fill_fast(const Color24& color, const AreaU16& area) {
wait_ready_for_CMD();
GPU_IO::GP0 = GPU_IO::Command::QuickFill(color);
GPU_IO::GP0 = GPU_IO::Command::TopLeftPosition(area.position.x, area.position.y);
GPU_IO::GP0 = GPU_IO::Command::WidthHeight(area.size.width, area.size.height);
}
static void reset_cmd_buffer() {
GPU_IO::GP1 = GPU_IO::Command::ResetCMDBufer();
static void set_draw_offset(int16_t x, int16_t y) {
wait_ready_for_CMD();
GPU_IO::GP0 = GPU_IO::Command::SetDrawOffset(x, y);
}
static void wait_ready_for_CMD() {
while(!GPU_IO::GPUSTAT.is_set(GPU_IO::GPUSTAT_t::GP0ReadyForCMD));
static void reset_cmd_buffer() {
GPU_IO::GP1 = GPU_IO::Command::ResetCMDBufer();
}
namespace DMA {

View File

@ -44,7 +44,7 @@ namespace JabyEngine {
SimpleTIMSize size_info;
size_t words_left; //32bit values
constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info) {
constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info), words_left(0) {
}
};

View File

@ -37,10 +37,13 @@ namespace JabyEngine {
__syscall_ReturnFromException();
}
void Display :: exchange_buffer_and_display() {
GPU::internal::set_draw_area(0, (PublicDisplay::Height*PublicDisplay::current_id));
uint32_t Display :: exchange_buffer_and_display() {
const auto draw_area_y = (PublicDisplay::Height*PublicDisplay::current_id);
GPU::internal::set_draw_area(0, draw_area_y);
PublicDisplay::current_id ^= 1;
GPU_IO::GP1 = GPU_IO::Command::DisplayArea(0, (PublicDisplay::Height*PublicDisplay::current_id));
return draw_area_y;
}
void wait_vsync(uint8_t syncs) {
@ -53,6 +56,13 @@ namespace JabyEngine {
while(vsync_count < syncs);
vsync_count = 0;
}
void render(const uint32_t* data, size_t words) {
wait_ready_for_CMD();
for(size_t n = 0; n < words; n++) {
GPU_IO::GP0 = data[n];
}
}
}
#ifndef USE_NO$PSX
@ -70,10 +80,16 @@ namespace JabyEngine {
}
#endif //USE_NO$PSX
uint8_t swap_buffers_vsync(uint8_t syncs) {
// Wait finish draw
uint8_t swap_buffers_vsync(uint8_t syncs, bool clear_screen) {
// Waits for finish FIFO
internal::wait_ready_for_CMD();
internal::wait_vsync(syncs);
internal::Display::exchange_buffer_and_display();
const auto draw_offset_y = internal::Display::exchange_buffer_and_display();
internal::set_draw_offset(0, draw_offset_y);
if(clear_screen) {
internal::quick_fill_fast(Color24::Black(), AreaU16{0, static_cast<uint16_t>(draw_offset_y), Display::Width, Display::Height});
}
return Display::current_id;
}
}

View File

@ -1,3 +1,4 @@
#include <PSX/GPU/gpu_primitives.hpp>
#include <stdio.h>
extern void main();