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