Configurate Screen

This commit is contained in:
Jaby 2022-10-03 15:38:54 +02:00 committed by Jaby
parent b1c06a4123
commit 260e3d1b21
5 changed files with 83 additions and 21 deletions

View File

@ -12,6 +12,14 @@
namespace GPU { namespace GPU {
namespace Display { 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() { static void enable() {
GP1.write(Command::GP1::SetDisplayState(DisplayState::On)); GP1.write(Command::GP1::SetDisplayState(DisplayState::On));
} }
@ -19,6 +27,8 @@ namespace GPU {
static void disable() { static void disable() {
GP1.write(Command::GP1::SetDisplayState(DisplayState::Off)); GP1.write(Command::GP1::SetDisplayState(DisplayState::Off));
} }
void set_offset(uint16_t x, uint16_t y);
} }
} }

View File

@ -90,6 +90,20 @@ namespace GPU {
return ComplexBitMap{construct_cmd(0x04, static_cast<uint32_t>(dir))}; return ComplexBitMap{construct_cmd(0x04, static_cast<uint32_t>(dir))};
} }
static constexpr GP1 HorizontalDisplayRange(uint32_t x1, uint32_t x2) {
constexpr auto X1 = BitRange<uint32_t>::from_to(0, 11);
constexpr auto X2 = BitRange<uint32_t>::from_to(12, 23);
return ComplexBitMap{construct_cmd(0x06, ComplexBitMap<uint32_t>::with(X1.with(x1), X2.with(x2)).raw)};
}
static constexpr GP1 VerticalDisplayRange(uint32_t y1, uint32_t y2) {
constexpr auto Y1 = BitRange<uint32_t>::from_to(0, 9);
constexpr auto Y2 = BitRange<uint32_t>::from_to(10, 19);
return ComplexBitMap{construct_cmd(0x07, ComplexBitMap<uint32_t>::with(Y1.with(y1), Y2.with(y2)).raw)};
}
static constexpr GP1 DisplayMode(uint32_t mode) { static constexpr GP1 DisplayMode(uint32_t mode) {
return ComplexBitMap{construct_cmd(0x08, mode)}; return ComplexBitMap{construct_cmd(0x08, mode)};
} }

View File

@ -1,11 +1,12 @@
#ifndef __JABYENGINE_INTERNAL_GPU_HPP__ #ifndef __JABYENGINE_INTERNAL_GPU_HPP__
#define __JABYENGINE_INTERNAL_GPU_HPP__ #define __JABYENGINE_INTERNAL_GPU_HPP__
#include <PSX/GPU/GPU_Types.hpp> #include <PSX/GPU/GPU.hpp>
#include <PSX/System/IOPorts/DMA_IO.hpp> #include <PSX/System/IOPorts/DMA_IO.hpp>
#include <PSX/System/IOPorts/GPU_IO.hpp> #include <PSX/System/IOPorts/GPU_IO.hpp>
namespace GPU { namespace GPU {
struct DisplayMode { namespace Display {
struct Mode {
enum struct TVEncoding { enum struct TVEncoding {
NTSC = 0, NTSC = 0,
PAL = 1, PAL = 1,
@ -20,14 +21,40 @@ namespace GPU {
static constexpr uint32_t PAL() { static constexpr uint32_t PAL() {
return ComplexBitMap<uint32_t>::with( return ComplexBitMap<uint32_t>::with(
DisplayMode::HorizontalResolution.with(GPU::HorizontalResolution::$320), Mode::HorizontalResolution.with(GPU::HorizontalResolution::$320),
DisplayMode::VerticalResolution.with(GPU::VerticalResolution::$240), Mode::VerticalResolution.with(GPU::VerticalResolution::$240),
DisplayMode::VideoMode.with(TVEncoding::PAL), Mode::VideoMode.with(TVEncoding::PAL),
DisplayMode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit) Mode::DisplayAreaColorDepth.with(GPU::DisplayAreaColorDepth::$15bit)
).raw;
}
static constexpr uint32_t NTSC() {
return ComplexBitMap<uint32_t>::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; ).raw;
} }
}; };
static void configurate() {
static constexpr uint16_t FirstVisiblePixelH = 0x260;
#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) { static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) {
GP0.write(Command::GP0::QuickFill(color)); GP0.write(Command::GP0::QuickFill(color));
GP0.write(Command::GP0::TopLeftPosition(pos.x, pos.y)); GP0.write(Command::GP0::TopLeftPosition(pos.x, pos.y));

View File

@ -17,7 +17,7 @@ namespace GPU {
void setup() { void setup() {
GP1.write(Command::GP1::Reset()); 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)); quick_fill_fast(Color24::Black(), PositionU16(0, 0), SizeU16(640, 480));
} }

View File

@ -1,5 +1,16 @@
#include <PSX/GPU/GPU.hpp> #include <PSX/GPU/GPU.hpp>
namespace GPU { 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)));
}
}
} }