Improve code
This commit is contained in:
parent
d95c421b53
commit
17f7ba545e
|
@ -10,17 +10,22 @@ namespace FileProcessor {
|
|||
};
|
||||
|
||||
struct Configuration;
|
||||
typedef bool (*ProcessRoutine)(Configuration&, Reserved&, bool);
|
||||
typedef bool (*ProcessRoutine)(Configuration&, Reserved&);
|
||||
|
||||
struct Configuration {
|
||||
ProcessRoutine process_routine = nullptr;
|
||||
const uint32_t* data_adr = nullptr;
|
||||
size_t data_size = 0ull;
|
||||
size_t data_word_size = 0ull;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&, bool), const uint32_t* data_adr) {
|
||||
static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) {
|
||||
return {reinterpret_cast<ProcessRoutine>(process_routine), data_adr};
|
||||
}
|
||||
}
|
||||
|
||||
constexpr void processed(size_t words) {
|
||||
this->data_adr += words;
|
||||
this->data_word_size -= words;
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
|
@ -28,15 +33,15 @@ namespace FileProcessor {
|
|||
Reserved reserved;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&, bool)) {
|
||||
static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) {
|
||||
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)};
|
||||
static_assert(sizeof(T) <= sizeof(Reserved));
|
||||
}
|
||||
|
||||
public:
|
||||
bool process(size_t size, bool is_last) {
|
||||
this->config.data_size += size;
|
||||
return (*this->config.process_routine)(this->config, this->reserved, is_last);
|
||||
bool process(size_t word_size) {
|
||||
this->config.data_word_size += word_size;
|
||||
return (*this->config.process_routine)(this->config, this->reserved);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace GPU {
|
|||
|
||||
// Upload SplashScreen picture
|
||||
auto state = FileProcessor::create(reinterpret_cast<const uint32_t*>(SplashScreen), SimpleTIM(93, 0, 0, 0));
|
||||
while(state.process((sizeof(SplashScreen)/sizeof(uint32_t)), true));
|
||||
while(state.process((2048/sizeof(uint32_t))));
|
||||
|
||||
Display::enable();
|
||||
}
|
||||
|
|
|
@ -9,17 +9,16 @@ namespace FileProcessor {
|
|||
static void simple_read(T& dst, State::Configuration& config) {
|
||||
static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t));
|
||||
|
||||
dst = *reinterpret_cast<const T*>(config.data_adr);
|
||||
config.data_adr += UINT32_SIZE;
|
||||
config.data_size -= UINT32_SIZE;
|
||||
dst = *reinterpret_cast<const T*>(config.data_adr);
|
||||
config.processed(UINT32_SIZE);
|
||||
|
||||
static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&, bool), State::Configuration& config, T& state, bool is_last) {
|
||||
static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&), State::Configuration& config, T& state) {
|
||||
config.process_routine = reinterpret_cast<State::ProcessRoutine>(process_routine);
|
||||
return process_routine(config, state, is_last);
|
||||
return process_routine(config, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,18 +43,16 @@ namespace FileProcessor {
|
|||
GPU::DMA::Receive::set_src(reinterpret_cast<const uintptr_t>(src));
|
||||
}
|
||||
|
||||
static void set_gpu_receive_data(const uint32_t* src, SimpleTIMState& state) {
|
||||
const auto width = state.size_info.getTextureWidth();
|
||||
const auto height = state.size_info.getTextureHeight();
|
||||
|
||||
static void set_gpu_receive_data(const uint32_t* src, SimpleTIMState& state, uint16_t width, uint16_t height) {
|
||||
state.words_left = (width*height)/2;
|
||||
set_gpu_receive(src, state.dst_info.getTextureX(), state.dst_info.getTextureY(), width, height);
|
||||
}
|
||||
|
||||
static bool parse_data(State::Configuration& config, SimpleTIMState& state, bool is_last) {
|
||||
auto block_count = (state.words_left >> 4);
|
||||
|
||||
state.words_left &= 0b1111;
|
||||
static bool parse_data(State::Configuration& config, SimpleTIMState& state) {
|
||||
const auto words_to_use = (config.data_word_size > state.words_left) ? state.words_left : config.data_word_size;
|
||||
bool is_last = (words_to_use == state.words_left);
|
||||
auto block_count = (words_to_use >> 4);
|
||||
|
||||
while(block_count > 0) {
|
||||
const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count;
|
||||
|
||||
|
@ -66,21 +64,32 @@ namespace FileProcessor {
|
|||
|
||||
if(is_last) {
|
||||
// Send words
|
||||
if(state.words_left > 0) {
|
||||
const auto last_words = (words_to_use & 0b1111);
|
||||
if(last_words > 0) {
|
||||
GPU::DMA::wait();
|
||||
GPU::DMA::Receive::start(1, state.words_left);
|
||||
GPU::DMA::Receive::start(1, last_words);
|
||||
}
|
||||
|
||||
GPU::DMA::wait();
|
||||
GPU::DMA::end();
|
||||
|
||||
state.words_left = 0;
|
||||
config.processed(words_to_use);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
else {
|
||||
const auto words_used = (words_to_use & ~0b1111);
|
||||
|
||||
state.words_left -= words_used;
|
||||
config.processed(words_used);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool parse_header(State::Configuration& config, SimpleTIMState& state, bool is_last) {
|
||||
if(config.data_size >= sizeof(SimpleTIMSize)) {
|
||||
static bool parse_header(State::Configuration& config, SimpleTIMState& state) {
|
||||
if(config.data_word_size >= (sizeof(SimpleTIMSize)/sizeof(uint32_t))) {
|
||||
Helper::simple_read(state.size_info, config);
|
||||
|
||||
//Check if we have a clut to care about
|
||||
|
@ -92,12 +101,12 @@ namespace FileProcessor {
|
|||
|
||||
//We have direct data
|
||||
else {
|
||||
set_gpu_receive_data(config.data_adr, state);
|
||||
return Helper::exchange_and_execute_process_function(parse_data, config, state, is_last);
|
||||
set_gpu_receive_data(config.data_adr, state, state.size_info.getTextureWidth(), state.size_info.getTextureHeight());
|
||||
return Helper::exchange_and_execute_process_function(parse_data, config, state);
|
||||
}
|
||||
}
|
||||
|
||||
return !is_last;
|
||||
return true;
|
||||
}
|
||||
|
||||
State create(const uint32_t* data_adr, const SimpleTIM& file) {
|
||||
|
|
Loading…
Reference in New Issue