Port GPU IOs

This commit is contained in:
2023-03-20 19:06:28 +01:00
parent 69b886e677
commit 9243a3a17f
6 changed files with 173 additions and 164 deletions

View File

@@ -8,50 +8,18 @@ namespace JabyEngine {
namespace GPU {
namespace internal {
struct Screen {
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_IO::DisplayAreaColorDepth>::from_to(4, 4);
static constexpr auto VideoMode = BitRange<TVEncoding>::from_to(3, 3);
static constexpr auto VerticalResolution = BitRange<GPU_IO::VerticalResolution>::from_to(2, 2);
static constexpr auto HorizontalResolution = BitRange<GPU_IO::HorizontalResolution>::from_to(0, 1);
static constexpr uint32_t PAL() {
return ComplexBitMap<uint32_t>::with(
Mode::HorizontalResolution.with(GPU_IO::HorizontalResolution::$320),
Mode::VerticalResolution.with(GPU_IO::VerticalResolution::$240),
Mode::VideoMode.with(TVEncoding::PAL),
Mode::DisplayAreaColorDepth.with(GPU_IO::DisplayAreaColorDepth::$15bit)
).raw;
}
static constexpr uint32_t NTSC() {
return ComplexBitMap<uint32_t>::with(
Mode::HorizontalResolution.with(GPU_IO::HorizontalResolution::$320),
Mode::VerticalResolution.with(GPU_IO::VerticalResolution::$240),
Mode::VideoMode.with(TVEncoding::NTSC),
Mode::DisplayAreaColorDepth.with(GPU_IO::DisplayAreaColorDepth::$15bit)
).raw;
}
};
static void configurate() {
static constexpr uint16_t FirstVisiblePixelH = 0x260;
#ifdef JABYENGINE_PAL
static constexpr uint16_t FirstVisiblePixelV = 0xA3;
GPU_IO::GP1.write(GPU_IO::Command::GP1::DisplayMode(Mode::PAL()));
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.write(GPU_IO::Command::GP1::DisplayMode(Mode::NTSC()));
GPU_IO::GP1 = *GPU_IO::Command::DisplayMode(GPU_IO::DisplayMode_t::NTSC());
GPU::Screen::set_offset(0, 5); //< Random values
#endif
}
@@ -60,22 +28,22 @@ namespace JabyEngine {
};
static void set_draw_area(uint16_t x, uint16_t y) {
GPU_IO::GP0.write(GPU_IO::Command::GP0::DrawAreaTopLeft(x, y));
GPU_IO::GP0.write(GPU_IO::Command::GP0::DrawAreaBottomRight((x + Display::Width), (y + Display::Height)));
GPU_IO::GP0 = *GPU_IO::Command::DrawAreaTopLeft(x, y);
GPU_IO::GP0 = *GPU_IO::Command::DrawAreaBottomRight((x + Display::Width), (y + Display::Height));
}
static void quick_fill_fast(const Color24& color, const PositionU16& pos, const SizeU16& size) {
GPU_IO::GP0.write(GPU_IO::Command::GP0::QuickFill(color));
GPU_IO::GP0.write(GPU_IO::Command::GP0::TopLeftPosition(pos.x, pos.y));
GPU_IO::GP0.write(GPU_IO::Command::GP0::WidthHeight(size.width, size.height));
GPU_IO::GP0 = *GPU_IO::Command::QuickFill(color);
GPU_IO::GP0 = *GPU_IO::Command::TopLeftPosition(pos.x, pos.y);
GPU_IO::GP0 = *GPU_IO::Command::WidthHeight(size.width, size.height);
}
static void reset_cmd_buffer() {
GPU_IO::GP1.write(GPU_IO::Command::GP1::ResetCMDBufer());
GPU_IO::GP1 = *GPU_IO::Command::ResetCMDBufer();
}
static void wait_ready_for_CMD() {
while(!GPU_IO::GPUSTAT.read().is(GPU_IO::GPUStatusRegister::GP0ReadyForCMD));
while(!GPU_IO::GPUSTAT.is_set(GPU_IO::GPUSTAT_t::GP0ReadyForCMD));
}
namespace DMA {
@@ -88,9 +56,8 @@ namespace JabyEngine {
}
namespace Receive {
static void prepare()
{
GPU_IO::GP1.write(GPU_IO::Command::GP1::DMADirection(GPU_IO::DMADirection::CPU2GPU));
static void prepare() {
GPU_IO::GP1 = *GPU_IO::Command::DMADirection(GPU_IO::DMADirection::CPU2GPU);
reset_cmd_buffer();
}
@@ -100,9 +67,9 @@ namespace JabyEngine {
static void set_dst(const PositionU16& position, const SizeU16& size) {
wait_ready_for_CMD();
GPU_IO::GP0.write(GPU_IO::Command::GP0::CPU2VRAM_Blitting());
GPU_IO::GP0.write(GPU_IO::Command::GP0::TopLeftPosition(position.x, position.y));
GPU_IO::GP0.write(GPU_IO::Command::GP0::WidthHeight(size.width, size.height));
GPU_IO::GP0 = *GPU_IO::Command::CPU2VRAM_Blitting();
GPU_IO::GP0 = *GPU_IO::Command::TopLeftPosition(position.x, position.y);
GPU_IO::GP0 = *GPU_IO::Command::WidthHeight(size.width, size.height);
}
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {

View File

@@ -49,7 +49,7 @@ namespace JabyEngine {
}
void setup() {
GPU_IO::GP1.write(GPU_IO::Command::GP1::Reset());
GPU_IO::GP1 = *GPU_IO::Command::Reset();
internal::Screen::configurate();
internal::Screen::exchange_buffer_and_display();

View File

@@ -16,7 +16,7 @@ namespace JabyEngine {
void Screen :: exchange_buffer_and_display() {
GPU::internal::set_draw_area(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID));
PublicScreenClass::CurrentDisplayAreaID ^= 1;
GPU_IO::GP1.write(GPU_IO::Command::GP1::DisplayArea(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID)));
GPU_IO::GP1 = *GPU_IO::Command::DisplayArea(0, (Display::Height*PublicScreenClass::CurrentDisplayAreaID));
}
}
@@ -25,13 +25,13 @@ namespace JabyEngine {
x += 78;
y += 43;
GPU_IO::GP1.write(GPU_IO::Command::GP1::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3));
GPU_IO::GP1.write(GPU_IO::Command::GP1::VerticalDisplayRange(y, y + Display::Height));
GPU_IO::GP1 = *GPU_IO::Command::HorizontalDisplayRange((x << 3), (x + Display::Width) << 3);
GPU_IO::GP1 = *GPU_IO::Command::VerticalDisplayRange(y, y + Display::Height);
}
#else
void Screen :: 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)));
GPU_IO::GP1 = *GPU_IO::Command::HorizontalDisplayRange(x, (x + Display::Width*8));
GPU_IO::GP1 = *GPU_IO::Command::VerticalDisplayRange(y - (ScanlinesV/2), y + (ScanlinesV/2));
}
#endif //USE_NO$PSX
}