jabyengine/src/Library/internal-include/GPU/gpu_internal.hpp

87 lines
3.4 KiB
C++

#ifndef __JABYENGINE_GPU_INTERNAL_HPP__
#define __JABYENGINE_GPU_INTERNAL_HPP__
#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 Screen {
static void configurate() {
static constexpr uint16_t FirstVisiblePixelH = 0x260;
#ifdef JABYENGINE_PAL
static constexpr uint16_t FirstVisiblePixelV = 0xA3;
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 = GPU_IO::Command::DisplayMode(GPU_IO::DisplayMode_t::NTSC());
GPU::Screen::set_offset(0, 5); //< Random values
#endif
}
static void exchange_buffer_and_display();
};
static void set_draw_area(uint16_t x, uint16_t y) {
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 = 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 = GPU_IO::Command::ResetCMDBufer();
}
static void wait_ready_for_CMD() {
while(!GPU_IO::GPUSTAT.is_set(GPU_IO::GPUSTAT_t::GP0ReadyForCMD));
}
namespace DMA {
static void wait() {
::JabyEngine::DMA_IO::GPU.wait();
}
static void end() {
reset_cmd_buffer();
}
namespace Receive {
static void prepare() {
GPU_IO::GP1 = 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 = 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) {
typedef DMA_IO::BCR_t::SyncMode1 SyncMode1;
DMA_IO::GPU.block_ctrl = DMA_IO::BCR_t::from(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount));
DMA_IO::GPU.channel_ctrl = DMA_IO::CHCHR_t::StartGPUReceive();
}
}
}
}
}
}
#endif //!__JABYENGINE_GPU_INTERNAL_HPP__