102 lines
4.1 KiB
C++
102 lines
4.1 KiB
C++
#pragma once
|
|
#include <PSX/GPU/gpu.hpp>
|
|
#include <PSX/System/IOPorts/dma_io.hpp>
|
|
#include <PSX/System/IOPorts/gpu_io.hpp>
|
|
|
|
namespace JabyEngine {
|
|
namespace GPU {
|
|
namespace internal {
|
|
struct Display {
|
|
typedef ::JabyEngine::GPU::Display PublicDisplay;
|
|
|
|
static constexpr auto Width = PublicDisplay::Width;
|
|
static constexpr auto Height = PublicDisplay::Height;
|
|
|
|
#ifdef JABYENGINE_PAL
|
|
static constexpr auto DisplayMode = GPU_IO::DisplayMode::PAL();
|
|
static constexpr uint16_t ScanlinesV = 288;
|
|
#else
|
|
static constexpr auto DisplayMode = GPU_IO::DisplayMode::NTSC();
|
|
static constexpr uint16_t ScanlinesV = 240;
|
|
#endif //JABYENGINE_PAL
|
|
|
|
static uint32_t exchange_buffer_and_display();
|
|
};
|
|
|
|
void wait_vsync(uint8_t syncs);
|
|
|
|
static void wait_ready_for_CMD() {
|
|
while(!GPU_IO::GPUSTAT.read().is_set(GPU_IO::GPUSTAT::GP0ReadyForCMD));
|
|
}
|
|
|
|
static void set_draw_area(const PositionU16& pos) {
|
|
const auto top_left = GPU_IO::Command::DrawAreaTopLeft(pos);
|
|
const auto bottom_right = GPU_IO::Command::DrawAreaBottomRight(pos.move((Display::Width - 1), (Display::Height - 1)));
|
|
|
|
wait_ready_for_CMD();
|
|
GPU_IO::GP0.write(top_left);
|
|
wait_ready_for_CMD();
|
|
GPU_IO::GP0.write(bottom_right);
|
|
}
|
|
|
|
static void copy_vram_to_vram(const AreaU16& dst, const PositionU16& src) {
|
|
wait_ready_for_CMD();
|
|
GPU_IO::GP0.write(GPU_IO::Command::VRAM2VRAM_Blitting());
|
|
GPU_IO::GP0.write(GPU_IO::Command::TopLeftPosition(src));
|
|
GPU_IO::GP0.write(GPU_IO::Command::TopLeftPosition(dst.position));
|
|
GPU_IO::GP0.write(GPU_IO::Command::WidthHeight(dst.size));
|
|
}
|
|
|
|
static void quick_fill_fast(const Color24& color, const AreaU16& area) {
|
|
wait_ready_for_CMD();
|
|
GPU_IO::GP0.write(GPU_IO::Command::QuickFill(color));
|
|
GPU_IO::GP0.write(GPU_IO::Command::TopLeftPosition(area.position));
|
|
GPU_IO::GP0.write(GPU_IO::Command::WidthHeight(area.size));
|
|
}
|
|
|
|
static void set_draw_offset(const PositionI16& offset) {
|
|
wait_ready_for_CMD();
|
|
GPU_IO::GP0.write(GPU_IO::Command::SetDrawOffset(offset));
|
|
}
|
|
|
|
static void reset_cmd_buffer() {
|
|
GPU_IO::GP1.write(GPU_IO::Command::ResetCMDBufer());
|
|
}
|
|
|
|
namespace DMA {
|
|
static void wait() {
|
|
::JabyEngine::DMA_IO::GPU.wait();
|
|
}
|
|
|
|
static void end() {
|
|
reset_cmd_buffer();
|
|
}
|
|
|
|
namespace Receive {
|
|
static void prepare() {
|
|
GPU_IO::GP1.write(GPU_IO::Command::DMADirection(GPU_IO::DMADirection::CPU2GPU));
|
|
reset_cmd_buffer();
|
|
}
|
|
|
|
static void set_src(uintptr_t adr) {
|
|
DMA_IO::GPU.set_adr(adr);
|
|
}
|
|
|
|
static void set_dst(const PositionU16& position, const SizeU16& size) {
|
|
wait_ready_for_CMD();
|
|
GPU_IO::GP0.write(GPU_IO::Command::CPU2VRAM_Blitting());
|
|
GPU_IO::GP0.write(GPU_IO::Command::TopLeftPosition(position));
|
|
GPU_IO::GP0.write(GPU_IO::Command::WidthHeight(size));
|
|
}
|
|
|
|
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {
|
|
typedef DMA_IO::BCR::SyncMode1 SyncMode1;
|
|
|
|
DMA_IO::GPU.block_ctrl.write(DMA_IO::BCR::from(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount)));
|
|
DMA_IO::GPU.channel_ctrl.write(DMA_IO::CHCHR::StartGPUReceive());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |