From d49cf587b1d34e83caa0d6b4cd6dab30b3267800 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 20 Dec 2023 16:24:56 -0500 Subject: [PATCH] Upload BIOS Clut (wrong plaette yet) --- .../src/FontWriter/font_writer.cpp | 2 +- include/PSX/GPU/gpu_auto_load_font.hpp | 2 +- include/PSX/GPU/gpu_types.hpp | 81 ++++++++++--------- src/Library/src/BootLoader/gpu_boot.cpp | 21 +++++ 4 files changed, 66 insertions(+), 40 deletions(-) diff --git a/examples/PoolBox/application/src/FontWriter/font_writer.cpp b/examples/PoolBox/application/src/FontWriter/font_writer.cpp index 7e66adea..f7e5cf34 100644 --- a/examples/PoolBox/application/src/FontWriter/font_writer.cpp +++ b/examples/PoolBox/application/src/FontWriter/font_writer.cpp @@ -48,7 +48,7 @@ namespace FontWriter { return {text, color}; } - return {text + 7, GPU::Color24(char_to_color(text[1]), char_to_color(text[3]), char_to_color(text[5]))}; + return {text + 7, GPU::Color24::from_rgb(char_to_color(text[1]), char_to_color(text[3]), char_to_color(text[5]))}; }; const auto* cur_text_end = &Pool::buffer[GPU::Display::current_id].text_buffer[Pool::Buffer::BufferSize]; const auto org_x = pos.x; diff --git a/include/PSX/GPU/gpu_auto_load_font.hpp b/include/PSX/GPU/gpu_auto_load_font.hpp index 32ff3a73..fd1d4ef2 100644 --- a/include/PSX/GPU/gpu_auto_load_font.hpp +++ b/include/PSX/GPU/gpu_auto_load_font.hpp @@ -9,7 +9,7 @@ namespace JabyEngine { // The following two values can be easily changed static constexpr auto TextureLoadPos = PositionU16::create(0, 0); - static constexpr auto CLUTLoadPos = PositionU16::create(0, 0); + static constexpr auto CLUTLoadPos = PositionU16::create(0, 96); static constexpr TexPage get_tex_page() { return TexPage::create(BIOS_Font::TextureLoadPos, GPU::TexturePageColor::$4bit); diff --git a/include/PSX/GPU/gpu_types.hpp b/include/PSX/GPU/gpu_types.hpp index 02c6381d..7c899f03 100644 --- a/include/PSX/GPU/gpu_types.hpp +++ b/include/PSX/GPU/gpu_types.hpp @@ -53,6 +53,37 @@ namespace JabyEngine { return T::create(static_cast(this)->x, static_cast(this)->y).move(dx, dy); } }; + + template + struct PredefinedColors { + static constexpr T Black() { + return T::from_rgb(0, 0, 0); + } + + static constexpr T Grey() { + return T::from_rgb(0x80, 0x80, 0x80); + } + + static constexpr T White() { + return T::from_rgb(0xFF, 0xFF, 0xFF); + } + + static constexpr T Red(uint8_t base = 0xFF) { + return T::from_rgb(base, 0x0, 0x0); + } + + static constexpr T Green(uint8_t base = 0xFF) { + return T::from_rgb(0x0, base, 0x0); + } + + static constexpr T Blue(uint8_t base = 0xFF) { + return T::from_rgb(0x0, 0x0, base); + } + + static constexpr T Yellow(uint8_t base = 0xFF) { + return T::from_rgb(base, base, 0x0); + } + }; } enum struct SemiTransparency { @@ -68,62 +99,32 @@ namespace JabyEngine { $15bit = 2, }; - struct Color24 { + struct Color24 : public internal::PredefinedColors { uint8_t red; uint8_t green; uint8_t blue; static constexpr Color24 from_rgb(uint8_t r, uint8_t g, uint8_t b) { - return Color24{r, g, b}; + return Color24{.red = r, .green = g, .blue = b}; } constexpr uint32_t raw() const { return ((this->blue << 16) | (this->green << 8) | this->red); } - static constexpr Color24 Black() { - return Color24(0, 0, 0); - } - - static constexpr Color24 Grey() { - return Color24(0x80, 0x80, 0x80); - } - - static constexpr Color24 White() { - return Color24(0xFF, 0xFF, 0xFF); - } - - static constexpr Color24 Red(uint8_t base = 0xFF) { - return Color24(base, 0x0, 0x0); - } - - static constexpr Color24 Green(uint8_t base = 0xFF) { - return Color24(0x0, base, 0x0); - } - - static constexpr Color24 Blue(uint8_t base = 0xFF) { - return Color24(0x0, 0x0, base); - } - - static constexpr Color24 Yellow(uint8_t base = 0xFF) { - return Color24(base, base, 0x0); - } - constexpr Color24 invert() const { - return Color24(0xFF - this->red, 0xFF - this->green, 0xFF - this->blue); + return Color24::from_rgb(this->red^0xFF, this->green^0xFF, this->blue^0xFF); } }; - class Color { - private: + struct Color : public internal::PredefinedColors { static constexpr auto RedRange = BitRange::from_to(0, 4); static constexpr auto GreenRange = BitRange::from_to(5, 9); static constexpr auto BlueRange = BitRange::from_to(10, 14); static constexpr auto SemiTransperancyBit = Bit(15); - uint16_t value; + uint16_t raw; - public: static constexpr Color from_rgb(uint8_t r, uint8_t g, uint8_t b) { return Color().set_red(r).set_green(g).set_blue(b); } @@ -132,18 +133,22 @@ namespace JabyEngine { return Color::from_rgb(color.red, color.green, color.blue); } + constexpr Color invert() const { + return Color{.raw = static_cast(this->raw^0xFFFF)}; + } + constexpr Color& set_red(uint8_t red) { - this->value = bit::value::set_normalized(this->value, RedRange.with(red)); + this->raw = bit::value::set_normalized(this->raw, RedRange.with(red)); return *this; } constexpr Color& set_green(uint8_t green) { - this->value = bit::value::set_normalized(this->value, GreenRange.with(green)); + this->raw = bit::value::set_normalized(this->raw, GreenRange.with(green)); return *this; } constexpr Color& set_blue(uint8_t blue) { - this->value = bit::value::set_normalized(this->value, BlueRange.with(blue)); + this->raw = bit::value::set_normalized(this->raw, BlueRange.with(blue)); return *this; } }; diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index a704fd4b..7df4500f 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -22,6 +22,26 @@ namespace JabyEngine { namespace internal { extern SysCall::InterrupCallback callback; } + + namespace SJIS { + void load_clut(const PositionU16& dst_cord) { + struct CLUT { + CPU2VRAM cmd; + Color data[16]; + }; + const CLUT clut { + .cmd = CPU2VRAM::create(AreaU16::create(dst_cord, GPU::SizeU16::create(16, 1))), + .data = { + Color::Blue(), Color::White(), + Color::Blue(), Color::White(), Color::Blue(), Color::White(), Color::Blue(), Color::White(), + Color::Blue(), Color::White(), + Color::Blue(), Color::White(), Color::Blue(), Color::White(), Color::Blue(), Color::White(), + } + }; + + GPU::internal::render(reinterpret_cast(&clut), sizeof(CLUT)/sizeof(uint32_t)); + } + } } namespace boot { @@ -64,6 +84,7 @@ namespace JabyEngine { // Now load the BIOS font to the specified location SJIS::load(BIOS_Font::TextureLoadPos); + SJIS::load_clut(BIOS_Font::CLUTLoadPos); // Duplicate DisplayBuffer content ::JabyEngine::GPU::internal::copy_vram_to_vram({PositionU16::create(0, Display::Height), SizeU16::create(Display::Width, Display::Height)}, PositionU16::create(0, 0));