Share commo DMA related code for use with SPU

This commit is contained in:
2024-09-10 22:50:05 +02:00
parent 0fb71beff2
commit 2f0d972a2a
6 changed files with 70 additions and 54 deletions

View File

@@ -65,10 +65,10 @@ namespace JabyEngine {
GPU_IO::GP1.write(GPU_IO::Command::ResetCMDBufer());
}
namespace DMA {
struct DMA {
#ifdef __SUPPORT_PS3__
// The PS3 doesn't autoincrement the GPU MADR register so we have to do it
extern uintptr_t MADR;
static uintptr_t MADR;
#endif // __SUPPORT_PS3__
static void wait() {
@@ -79,7 +79,7 @@ namespace JabyEngine {
reset_cmd_buffer();
}
namespace Receive {
struct Receive {
static void prepare() {
GPU_IO::GP1.write(GPU_IO::Command::DMADirection(GPU_IO::DMADirection::CPU2GPU));
reset_cmd_buffer();
@@ -87,7 +87,7 @@ namespace JabyEngine {
static void set_src(uintptr_t adr) {
#ifdef __SUPPORT_PS3__
MADR = adr;
DMA::MADR = adr;
#else
DMA_IO::GPU.set_adr(adr);
#endif // __SUPPORT_PS3__
@@ -105,13 +105,13 @@ namespace JabyEngine {
#ifdef __SUPPORT_PS3__
DMA_IO::GPU.set_adr(MADR);
MADR += (blockCount * wordsPerBlock) << 2;
DMA::MADR += (blockCount * wordsPerBlock) << 2;
#endif // __SUPPORT_PS3__
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());
}
}
}
};
};
}
}
}

View File

@@ -5,7 +5,7 @@
namespace JabyEngine {
namespace SPU {
namespace internal {
namespace DMA {
struct DMA {
static void wait() {
DMA_IO::SPU.wait();
}
@@ -14,7 +14,7 @@ namespace JabyEngine {
SPU_IO::ControlRegister.set_transfer_mode(SPU_IO::ControlRegister::Stop);
}
namespace Receive {
struct Receive {
static void prepare() {
SPU_IO::DataTransferControl.write(SPU_IO::DataTransferControl::NormalTransferMode());
SPU_IO::ControlRegister.set_transfer_mode(SPU_IO::ControlRegister::Stop);
@@ -36,8 +36,8 @@ namespace JabyEngine {
DMA_IO::SPU.block_ctrl.write(DMA_IO::BCR::from(SyncMode1::BlockSize.with(wordsPerBlock), SyncMode1::BlockAmount.with(blockCount)));
DMA_IO::SPU.channel_ctrl.write(DMA_IO::CHCHR::StartSPUReceive());
}
}
}
};
};
}
}
}

View File

@@ -1,7 +1,6 @@
#include "../../../internal-include/GPU/gpu_internal.hpp"
#include <PSX/File/file_processor_helper.hpp>
#include <PSX/GPU/gpu_types.hpp>
#include <limits.hpp>
#include <stdio.hpp>
namespace JabyEngine {
@@ -63,44 +62,12 @@ namespace JabyEngine {
}
static Progress parse_data(State::Configuration& config, SimpleTIMState& state) {
const auto config_data_words = (config.data_bytes/sizeof(uint32_t));
const auto words_to_use = (config_data_words > state.words_left) ? state.words_left : config_data_words;
bool is_last = (words_to_use == state.words_left);
auto block_count = (words_to_use >> 4);
const auto [words_to_use, is_last] = Helper::DMA::WordsReady::calculate(config, state.words_left);
const auto words_used = Helper::DMA::send_words<GPU::internal::DMA>(words_to_use, is_last);
while(block_count > 0) {
const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count;
// Send data!
GPU::internal::DMA::wait();
GPU::internal::DMA::Receive::start(block_send);
block_count -= block_send;
}
if(is_last) {
// Send words
const auto last_words = (words_to_use & 0b1111);
if(last_words > 0) {
GPU::internal::DMA::wait();
GPU::internal::DMA::Receive::start(1, last_words);
}
GPU::internal::DMA::wait();
GPU::internal::DMA::end();
state.words_left = 0;
config.processed(words_to_use*sizeof(uint32_t));
return Progress::Done;
}
else {
const auto words_used = (words_to_use & ~0b1111);
state.words_left -= words_used;
config.processed(words_used*sizeof(uint32_t));
return Progress::InProgress;
}
state.words_left -= words_used;
config.processed(words_used*sizeof(uint32_t));
return is_last ? Progress::Done : Progress::InProgress;
}
static Progress switch_state_parse_data(State::Configuration& config, SimpleTIMState& state) {

View File

@@ -41,6 +41,8 @@ namespace JabyEngine {
static Progress parse_sample(State::Configuration& config, VAGState& state) {
// Load balancer?
return Progress::Error;
}

View File

@@ -8,11 +8,9 @@ namespace JabyEngine {
uint8_t Display :: current_id = 1; //< Setup will call exchange and set it to 0
namespace internal {
namespace DMA {
#ifdef __SUPPORT_PS3__
uintptr_t MADR = 0;
#endif // __SUPPORT_PS3__
}
#ifdef __SUPPORT_PS3__
uintptr_t DMA :: MADR = 0;
#endif // __SUPPORT_PS3__
static SysCall::InterruptVerifierResult interrupt_verifier();
static void interrupt_handler(uint32_t);