From 9d46658e0f89a4f3dfb543bb7d80eb92f4e86734 Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 26 Apr 2023 20:42:44 +0200 Subject: [PATCH] Cleanup GPU code more --- include/PSX/GPU/gpu.hpp | 6 ++--- .../internal-include/GPU/gpu_internal.hpp | 27 +++++++++---------- src/Library/src/BootLoader/gpu_boot.cpp | 10 +++++-- src/Library/src/GPU/gpu.cpp | 21 +++++---------- 4 files changed, 28 insertions(+), 36 deletions(-) diff --git a/include/PSX/GPU/gpu.hpp b/include/PSX/GPU/gpu.hpp index 6f026a8f..af26db57 100644 --- a/include/PSX/GPU/gpu.hpp +++ b/include/PSX/GPU/gpu.hpp @@ -21,6 +21,8 @@ namespace JabyEngine { static constexpr size_t Height = 240; #endif + static uint8_t current_id; + static void enable() { GPU_IO::GP1 = GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::On); } @@ -28,10 +30,6 @@ namespace JabyEngine { static void disable() { GPU_IO::GP1 = GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::Off); } - }; - - struct Screen { - static uint8_t CurrentDisplayAreaID; static void set_offset(uint16_t x, uint16_t y); }; diff --git a/src/Library/internal-include/GPU/gpu_internal.hpp b/src/Library/internal-include/GPU/gpu_internal.hpp index 9903400b..1b04be47 100644 --- a/src/Library/internal-include/GPU/gpu_internal.hpp +++ b/src/Library/internal-include/GPU/gpu_internal.hpp @@ -7,22 +7,19 @@ namespace JabyEngine { namespace GPU { namespace internal { - struct Screen { - static void configurate() { - static constexpr uint16_t FirstVisiblePixelH = 0x260; + struct Display { + typedef ::JabyEngine::GPU::Display PublicDisplay; - #ifdef JABYENGINE_PAL - static constexpr uint16_t FirstVisiblePixelV = 0xA3; - - GPU_IO::GP1 = GPU_IO::Command::DisplayMode(GPU_IO::DisplayMode_t::PAL()); - GPU::Screen::set_offset(0, 0); - #else - static constexpr uint16_t FirstVisiblePixelV = 0x88; - - GPU_IO::GP1 = GPU_IO::Command::DisplayMode(GPU_IO::DisplayMode_t::NTSC()); - GPU::Screen::set_offset(0, 5); //< Random values - #endif - } + static constexpr auto Width = PublicDisplay::Width; + static constexpr auto Height = PublicDisplay::Height; + + #ifdef JABYENGINE_PAL + static constexpr auto DisplayMode = GPU_IO::DisplayMode_t::PAL(); + static constexpr uint16_t ScanlinesV = 288; + #else + static constexpr auto DisplayMode = GPU_IO::DisplayMode_t::NTSC(); + static constexpr uint16_t ScanlinesV = 240; + #endif //JABYENGINE_PAL static void exchange_buffer_and_display(); }; diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index 5f38475e..4720d0f9 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -16,6 +16,12 @@ namespace JabyEngine { namespace boot { namespace GPU { using namespace JabyEngine::GPU; + + static void configurate_display() { + // Ideal I hope that an offset of 0,0 will produce a well enough centered picture for every TV + GPU_IO::GP1 = GPU_IO::Command::DisplayMode(internal::Display::DisplayMode); + GPU::Display::set_offset(0, 0); + } static size_t decompress_logo() { LZ4Decompressor lz4_decomp(reinterpret_cast(&__boot_loader_end)); @@ -50,8 +56,8 @@ namespace JabyEngine { void setup() { GPU_IO::GP1 = GPU_IO::Command::Reset(); - internal::Screen::configurate(); - internal::Screen::exchange_buffer_and_display(); + configurate_display(); + internal::Display::exchange_buffer_and_display(); GPU::internal::wait_ready_for_CMD(); GPU::internal::quick_fill_fast(Color24::Black(), PositionU16(32, 0), SizeU16(Display::Width, Display::Height)); diff --git a/src/Library/src/GPU/gpu.cpp b/src/Library/src/GPU/gpu.cpp index b4004e80..8597cfeb 100644 --- a/src/Library/src/GPU/gpu.cpp +++ b/src/Library/src/GPU/gpu.cpp @@ -2,26 +2,18 @@ namespace JabyEngine { namespace GPU { - uint8_t Screen :: CurrentDisplayAreaID = 1; //< Setup will call exchange and set it to 0 + uint8_t Display :: current_id = 1; //< Setup will call exchange and set it to 0 namespace internal { - typedef ::JabyEngine::GPU::Screen PublicScreenClass; - - #ifdef JABYENGINE_PAL - static constexpr uint16_t ScanlinesV = 288; - #else - static constexpr uint16_t ScanlinesV = 240; - #endif //JABYENGINE_PAL - - void Screen :: exchange_buffer_and_display() { - GPU::internal::set_draw_area(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID)); - PublicScreenClass::CurrentDisplayAreaID ^= 1; - GPU_IO::GP1 = GPU_IO::Command::DisplayArea(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID)); + void Display :: exchange_buffer_and_display() { + GPU::internal::set_draw_area(0, (PublicDisplay::Height*PublicDisplay::current_id)); + PublicDisplay::current_id ^= 1; + GPU_IO::GP1 = GPU_IO::Command::DisplayArea(0, (PublicDisplay::Height*PublicDisplay::current_id)); } } #ifndef USE_NO$PSX - void Screen :: set_offset(uint16_t x, uint16_t y) { + void Display :: set_offset(uint16_t x, uint16_t y) { x += 78; y += 43; @@ -35,5 +27,4 @@ namespace JabyEngine { } #endif //USE_NO$PSX } - } \ No newline at end of file