diff --git a/include/PSX/GPU/GPU.hpp b/include/PSX/GPU/GPU.hpp index 7a6ce66e..d92fec84 100644 --- a/include/PSX/GPU/GPU.hpp +++ b/include/PSX/GPU/GPU.hpp @@ -12,6 +12,14 @@ namespace GPU { namespace Display { + #ifdef JABYENGINE_PAL + static constexpr size_t Width = 320; + static constexpr size_t Height = 256; + #else + static constexpr size_t Width = 320; + static constexpr size_t Height = 240; + #endif + static void enable() { GP1.write(Command::GP1::SetDisplayState(DisplayState::On)); } @@ -19,6 +27,8 @@ namespace GPU { static void disable() { GP1.write(Command::GP1::SetDisplayState(DisplayState::Off)); } + + void set_offset(uint16_t x, uint16_t y); } } diff --git a/include/PSX/System/IOPorts/GPU_IO.hpp b/include/PSX/System/IOPorts/GPU_IO.hpp index beb8cd55..9330a5cc 100644 --- a/include/PSX/System/IOPorts/GPU_IO.hpp +++ b/include/PSX/System/IOPorts/GPU_IO.hpp @@ -90,6 +90,20 @@ namespace GPU { return ComplexBitMap{construct_cmd(0x04, static_cast(dir))}; } + static constexpr GP1 HorizontalDisplayRange(uint32_t x1, uint32_t x2) { + constexpr auto X1 = BitRange::from_to(0, 11); + constexpr auto X2 = BitRange::from_to(12, 23); + + return ComplexBitMap{construct_cmd(0x06, ComplexBitMap::with(X1.with(x1), X2.with(x2)).raw)}; + } + + static constexpr GP1 VerticalDisplayRange(uint32_t y1, uint32_t y2) { + constexpr auto Y1 = BitRange::from_to(0, 9); + constexpr auto Y2 = BitRange::from_to(10, 19); + + return ComplexBitMap{construct_cmd(0x07, ComplexBitMap::with(Y1.with(y1), Y2.with(y2)).raw)}; + } + static constexpr GP1 DisplayMode(uint32_t mode) { return ComplexBitMap{construct_cmd(0x08, mode)}; } diff --git a/src/Library/include/GPU/GPU.hpp b/src/Library/include/GPU/GPU.hpp index 24f5d6a1..4d0c5216 100644 --- a/src/Library/include/GPU/GPU.hpp +++ b/src/Library/include/GPU/GPU.hpp @@ -1,32 +1,59 @@ #ifndef __JABYENGINE_INTERNAL_GPU_HPP__ #define __JABYENGINE_INTERNAL_GPU_HPP__ -#include +#include #include #include namespace GPU { - struct DisplayMode { - enum struct TVEncoding { - NTSC = 0, - PAL = 1, + namespace Display { + struct Mode { + 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( + Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320), + Mode::VerticalResolution.with(GPU::VerticalResolution::$240), + Mode::VideoMode.with(TVEncoding::PAL), + Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) + ).raw; + } + + static constexpr uint32_t NTSC() { + return ComplexBitMap::with( + Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320), + Mode::VerticalResolution.with(GPU::VerticalResolution::$240), + Mode::VideoMode.with(TVEncoding::NTSC), + Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) + ).raw; + } }; - 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 void configurate() { + static constexpr uint16_t FirstVisiblePixelH = 0x260; - 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; + #ifdef JABYENGINE_PAL + static constexpr uint16_t FirstVisiblePixelV = 0xA3; + + GP1.write(Command::GP1::DisplayMode(Mode::PAL())); + GPU::Display::set_offset(FirstVisiblePixelH, FirstVisiblePixelV); + #else + static constexpr uint16_t FirstVisiblePixelV = 0x88; + + GP1.write(Command::GP1::DisplayMode(Mode::NTSC())); + GPU::Display::set_offset(FirstVisiblePixelH, FirstVisiblePixelV); + #endif } - }; + } static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) { GP0.write(Command::GP0::QuickFill(color)); diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index 3e49d45d..a9579868 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -17,7 +17,7 @@ namespace GPU { void setup() { GP1.write(Command::GP1::Reset()); - GP1.write(Command::GP1::DisplayMode(DisplayMode::PAL())); + Display::configurate(); quick_fill_fast(Color24::Black(), PositionU16(0, 0), SizeU16(640, 480)); } diff --git a/src/Library/src/GPU/GPU.cpp b/src/Library/src/GPU/GPU.cpp index 0234dba4..8a995be3 100644 --- a/src/Library/src/GPU/GPU.cpp +++ b/src/Library/src/GPU/GPU.cpp @@ -1,5 +1,16 @@ #include namespace GPU { - + namespace Display { + #ifdef JABYENGINE_PAL + static constexpr uint16_t ScanlinesV = 288; + #else + static constexpr uint16_t ScanlinesV = 240; + #endif //JABYENGINE_PAL + + void set_offset(uint16_t x, uint16_t y) { + GP1.write(Command::GP1::HorizontalDisplayRange(x, (x + Display::Width*8))); + GP1.write(Command::GP1::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2))); + } + } } \ No newline at end of file