Configurate Screen

This commit is contained in:
Jaby 2022-10-03 15:38:54 +02:00
parent 9e69aec9bd
commit 83c00992aa
5 changed files with 83 additions and 21 deletions

View File

@ -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);
}
}

View File

@ -90,6 +90,20 @@ namespace GPU {
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) {
return ComplexBitMap{construct_cmd(0x08, mode)};
}

View File

@ -1,32 +1,59 @@
#ifndef __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/GPU_IO.hpp>
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<uint32_t>(6);
static constexpr auto VerticalInterlace = Bit<uint32_t>(5);
static constexpr auto DisplayAreaColorDepth = BitRange<GPU::DisplayAreaColorDepth>::from_to(4, 4);
static constexpr auto VideoMode = BitRange<TVEncoding>::from_to(3, 3);
static constexpr auto VerticalResolution = BitRange<GPU::VerticalResolution>::from_to(2, 2);
static constexpr auto HorizontalResolution = BitRange<GPU::HorizontalResolution>::from_to(0, 1);
static constexpr uint32_t PAL() {
return ComplexBitMap<uint32_t>::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<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;
}
};
static constexpr auto HorizontalResolution368 = Bit<uint32_t>(6);
static constexpr auto VerticalInterlace = Bit<uint32_t>(5);
static constexpr auto DisplayAreaColorDepth = BitRange<GPU::DisplayAreaColorDepth>::from_to(4, 4);
static constexpr auto VideoMode = BitRange<TVEncoding>::from_to(3, 3);
static constexpr auto VerticalResolution = BitRange<GPU::VerticalResolution>::from_to(2, 2);
static constexpr auto HorizontalResolution = BitRange<GPU::HorizontalResolution>::from_to(0, 1);
static void configurate() {
static constexpr uint16_t FirstVisiblePixelH = 0x260;
static constexpr uint32_t PAL() {
return ComplexBitMap<uint32_t>::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));

View File

@ -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));
}

View File

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