Share commo DMA related code for use with SPU
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "Processor/file_processor.hpp"
|
||||
#include "cd_file_types.hpp"
|
||||
#include <limits.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace FileProcessor {
|
||||
@@ -18,6 +19,54 @@ namespace JabyEngine {
|
||||
config.process_routine = reinterpret_cast<State::ProcessRoutine>(process_routine);
|
||||
return process_routine(config, state);
|
||||
}
|
||||
|
||||
namespace DMA {
|
||||
using words_t = size_t;
|
||||
|
||||
struct WordsReady {
|
||||
uint32_t words_to_use;
|
||||
bool is_last;
|
||||
|
||||
static constexpr WordsReady calculate(const State::Configuration& config, words_t words_left) {
|
||||
const auto config_data_words = (config.data_bytes/sizeof(uint32_t));
|
||||
const auto words_to_use = (config_data_words > words_left) ? words_left : config_data_words;
|
||||
|
||||
return {
|
||||
.words_to_use = words_to_use,
|
||||
.is_last = words_to_use == words_left
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static words_t send_words(words_t words_to_send, bool send_all) {
|
||||
auto blocks_to_send = words_to_send/16;
|
||||
while(blocks_to_send > 0) {
|
||||
const auto block_send = (blocks_to_send > UI16_MAX) ? UI16_MAX : blocks_to_send;
|
||||
|
||||
// Send data!
|
||||
T::wait();
|
||||
T::Receive::start(blocks_to_send);
|
||||
blocks_to_send -= block_send;
|
||||
}
|
||||
|
||||
if(send_all) {
|
||||
const auto last_words_to_send = (words_to_send & 0b1111);
|
||||
if(last_words_to_send > 0) {
|
||||
T::wait();
|
||||
T::Receive::start(1, last_words_to_send);
|
||||
}
|
||||
|
||||
T::wait();
|
||||
T::end();
|
||||
return words_to_send;
|
||||
}
|
||||
|
||||
else {
|
||||
return (words_to_send & ~0b1111);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user