Use DMA for GPU

This commit is contained in:
Jaby
2022-09-11 15:44:45 +02:00
parent 2a97f7fa68
commit 303ffbccc9
8 changed files with 143 additions and 20 deletions

View File

@@ -1,6 +1,7 @@
#ifndef __JABYENGINE_INTERNAL_GPU_HPP__
#define __JABYENGINE_INTERNAL_GPU_HPP__
#include <PSX/GPU/GPU_Types.hpp>
#include <PSX/System/IOPorts/DMA_IO.hpp>
#include <PSX/System/IOPorts/GPU_IO.hpp>
namespace GPU {
@@ -9,6 +10,51 @@ namespace GPU {
Port::GP0.write(Port::Command::GP0::TopLeftPosition(pos.x, pos.y));
Port::GP0.write(Port::Command::GP0::WidthHeight(size.width, size.height));
}
static void reset_cmd_buffer() {
Port::GP1.write(Port::Command::GP1::ResetCMDBufer());
}
static void wait_ready_for_CMD() {
while(!Port::GPUSTAT.ref().is(Port::GPUStatusRegister::GP0ReadyForCMD));
}
namespace DMA {
static void wait() {
while(::DMA::Port::GPU.channel_ctrl.ref().is(::DMA::Port::CHCHR::Busy));
}
static void end() {
reset_cmd_buffer();
}
namespace Receive {
static void prepare()
{
Port::GP1.write(Port::Command::GP1::DMADirection(Port::DMADirection::CPU2GPU));
reset_cmd_buffer();
}
static void set_src(uintptr_t adr) {
::DMA::Port::GPU.adr.ref().set_value(static_cast<uint32_t>(adr), ::DMA::Port::MADR::MemoryAdr);
}
static void set_dst(const PositionU16& position, const SizeU16& size) {
wait_ready_for_CMD();
Port::GP0.write(Port::Command::GP0::CPU2VRAM_Blitting());
Port::GP0.write(Port::Command::GP0::TopLeftPosition(position.x, position.y));
Port::GP0.write(Port::Command::GP0::WidthHeight(size.width, size.height));
}
static void start(uint16_t blockCount, uint16_t wordsPerBlock = 0x10) {
typedef ::DMA::Port::BCR::SyncMode1 SyncMode1;
::DMA::Port::GPU.block_ctrl.write(SyncMode1::with(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount)));
::DMA::Port::GPU.channel_ctrl.write(::DMA::Port::CHCHR::StartGPUReceive());
}
}
}
}
#endif //!__JABYENGINE_INTERNAL_GPU_HPP__

View File

@@ -20,6 +20,18 @@ namespace GPU {
void display_logo() {
Display::disable();
quick_fill_fast(Color24(0x0, 0x80, 0x80), PositionU16(0, 0), SizeU16(640, 480));
//DMA Start
DMA::Receive::prepare();
DMA::Receive::set_dst(PositionU16(0, 0), SizeU16(12, 12));
DMA::Receive::set_src(reinterpret_cast<uintptr_t>(&TestSequence));
DMA::Receive::start(12, (12*sizeof(Color))/sizeof(uint32_t));
DMA::wait();
DMA::end();
//DMA End
Display::enable();
}

View File

@@ -95,8 +95,5 @@ namespace SPU {
setup_data_transfer_control();
setup_control_register();
// Enable SPU DMA
DPCR.write(DPCR.read() | DMAControlRegister::SPUEnable);
}
}

View File

@@ -1,12 +1,19 @@
#include "BootLoader/boot_loader.hpp"
#include <PSX/System/IOPorts/DMA_IO.hpp>
#include <stdio.h>
using namespace DMA::Port;
namespace JabyEngine {
static void enable_DMA() {
DPCR.write(DPCR.read() | DMAControlRegister::SPUEnable | DMAControlRegister::GPUEnable);
}
void start() {
printf("Hello Planschbecken\n");
enable_DMA();
SPU::stop_voices();
GPU::display_logo();
//Load picture here
//Pause??