From 63df4e8ad8cc6f7768a93077a14301510cb2fb1b Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 2 Oct 2022 17:32:23 +0200 Subject: [PATCH] Start configurating GPU --- include/PSX/Auxiliary/complex_bitmap.hpp | 9 ++++-- include/PSX/System/IOPorts/GPU_IO.hpp | 29 ++++++++++++------- src/Library/include/GPU/{GPU.h => GPU.hpp} | 23 +++++++++++++++ src/Library/src/BootLoader/gpu_boot.cpp | 4 +-- src/Library/src/BootLoader/start_boot.cpp | 4 +-- .../src/File/Processor/TIM_Processor.cpp | 2 +- src/Library/src/GPU/GPU.cpp | 5 ++++ 7 files changed, 58 insertions(+), 18 deletions(-) rename src/Library/include/GPU/{GPU.h => GPU.hpp} (63%) create mode 100644 src/Library/src/GPU/GPU.cpp diff --git a/include/PSX/Auxiliary/complex_bitmap.hpp b/include/PSX/Auxiliary/complex_bitmap.hpp index 5a734067..96a7c045 100644 --- a/include/PSX/Auxiliary/complex_bitmap.hpp +++ b/include/PSX/Auxiliary/complex_bitmap.hpp @@ -153,17 +153,20 @@ public: } // For easier constructing - constexpr __always_inline ComplexBitMap& set(const BitRange& range, T value) { + template + constexpr __always_inline ComplexBitMap& set(const BitRange& range, T value) { this->set_value(value, range); return *this; } - constexpr __always_inline ComplexBitMap& set(const BitRangeValue& value) { + template + constexpr __always_inline ComplexBitMap& set(const BitRangeValue& value) { this->set_value(value.value, {value.begin, value.length}); return *this; } - constexpr __always_inline ComplexBitMap& set(const Bit& bit) { + template + constexpr __always_inline ComplexBitMap& set(const Bit& bit) { this->set_bit(bit.value); return *this; } diff --git a/include/PSX/System/IOPorts/GPU_IO.hpp b/include/PSX/System/IOPorts/GPU_IO.hpp index 9675fc37..beb8cd55 100644 --- a/include/PSX/System/IOPorts/GPU_IO.hpp +++ b/include/PSX/System/IOPorts/GPU_IO.hpp @@ -11,22 +11,27 @@ namespace GPU { B_add_F_Quarter = 3, }; + enum struct DisplayAreaColorDepth { + $15bit = 0, + $24bit = 1, + }; + enum struct TexturePageColor { - _4bit = 0, - _8bit = 1, - _15bit = 2, + $4bit = 0, + $8bit = 1, + $15bit = 2, }; enum struct HorizontalResolution { - _256 = 0, - _320 = 1, - _512 = 2, - _640 = 3, + $256 = 0, + $320 = 1, + $512 = 2, + $640 = 3, }; enum struct VerticalResolution { - _240 = 0, - _480 = 1 + $240 = 0, + $480 = 1 }; enum struct DMADirection { @@ -84,6 +89,10 @@ namespace GPU { static constexpr GP1 DMADirection(DMADirection dir) { return ComplexBitMap{construct_cmd(0x04, static_cast(dir))}; } + + static constexpr GP1 DisplayMode(uint32_t mode) { + return ComplexBitMap{construct_cmd(0x08, mode)}; + } }; } @@ -97,7 +106,7 @@ namespace GPU { static constexpr auto InterruptRequest = Bit(24); static constexpr auto DisplayDisabled = Bit(23); static constexpr auto VerticalInterlaceOn = Bit(22); - static constexpr auto DisplayAreaColorDepth24bit = Bit(21); + static constexpr auto DisplayAreaColorDepth = BitRange::from_to(21, 21); static constexpr auto VideoModePal = Bit(20); static constexpr auto VerticalResolutionValue = BitRange::from_to(19, 19); static constexpr auto HorizontalResolutionValue = BitRange::from_to(17, 18); diff --git a/src/Library/include/GPU/GPU.h b/src/Library/include/GPU/GPU.hpp similarity index 63% rename from src/Library/include/GPU/GPU.h rename to src/Library/include/GPU/GPU.hpp index b896640e..24f5d6a1 100644 --- a/src/Library/include/GPU/GPU.h +++ b/src/Library/include/GPU/GPU.hpp @@ -5,6 +5,29 @@ #include namespace GPU { + struct DisplayMode { + enum struct TVEncoding { + NTSC = 0, + PAL = 1, + }; + + static constexpr auto HorizontalResolution368 = Bit(6); + static constexpr auto VerticalInterlace = Bit(5); + static constexpr auto DisplayAreaColorDepth = BitRange::from_to(4, 4); + static constexpr auto VideoMode = BitRange::from_to(3, 3); + static constexpr auto VerticalResolution = BitRange::from_to(2, 2); + static constexpr auto HorizontalResolution = BitRange::from_to(0, 1); + + static constexpr uint32_t PAL() { + return ComplexBitMap::with( + DisplayMode::HorizontalResolution.with(GPU::HorizontalResolution::$320), + DisplayMode::VerticalResolution.with(GPU::VerticalResolution::$240), + DisplayMode::VideoMode.with(TVEncoding::PAL), + DisplayMode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) + ).raw; + } + }; + static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) { GP0.write(Command::GP0::QuickFill(color)); GP0.write(Command::GP0::TopLeftPosition(pos.x, pos.y)); diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index 6d8b4d0d..3e49d45d 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -1,4 +1,4 @@ -#include "../../include/GPU/GPU.h" +#include "../../include/GPU/GPU.hpp" #include #include @@ -7,7 +7,6 @@ namespace GPU { void display_logo() { Display::disable(); - quick_fill_fast(Color24(0x0, 0x80, 0x80), PositionU16(0, 0), SizeU16(640, 480)); // Upload SplashScreen picture auto state = FileProcessor::create(reinterpret_cast(SplashScreen), SimpleTIM(93, 0, 0, 0)); @@ -18,6 +17,7 @@ namespace GPU { void setup() { GP1.write(Command::GP1::Reset()); + GP1.write(Command::GP1::DisplayMode(DisplayMode::PAL())); quick_fill_fast(Color24::Black(), PositionU16(0, 0), SizeU16(640, 480)); } diff --git a/src/Library/src/BootLoader/start_boot.cpp b/src/Library/src/BootLoader/start_boot.cpp index 7c60c2c4..7ebb595d 100644 --- a/src/Library/src/BootLoader/start_boot.cpp +++ b/src/Library/src/BootLoader/start_boot.cpp @@ -12,11 +12,11 @@ namespace JabyEngine { enable_DMA(); SPU::stop_voices(); + + GPU::setup(); GPU::display_logo(); //Pause?? - //Do not setup GPU for now - //GPU::setup(); SPU::setup(); printf("Setup done!\n"); } diff --git a/src/Library/src/File/Processor/TIM_Processor.cpp b/src/Library/src/File/Processor/TIM_Processor.cpp index 0e03d3f4..c2fc81e5 100644 --- a/src/Library/src/File/Processor/TIM_Processor.cpp +++ b/src/Library/src/File/Processor/TIM_Processor.cpp @@ -1,4 +1,4 @@ -#include "../../../include/GPU/GPU.h" +#include "../../../include/GPU/GPU.hpp" #include "SimpleHelper.hpp" #include #include diff --git a/src/Library/src/GPU/GPU.cpp b/src/Library/src/GPU/GPU.cpp new file mode 100644 index 00000000..0234dba4 --- /dev/null +++ b/src/Library/src/GPU/GPU.cpp @@ -0,0 +1,5 @@ +#include + +namespace GPU { + +} \ No newline at end of file