From c255c9259f196aaae026abe8f2146c6b9d73bb28 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 2 Oct 2022 13:14:30 +0200 Subject: [PATCH] Upload Direct16 pic --- include/PSX/File/File_Types.hpp | 8 ++-- include/PSX/File/Processor/File_Processor.hpp | 10 ++-- src/Library/src/BootLoader/gpu_boot.cpp | 8 ++-- .../src/File/Processor/SimpleHelper.hpp | 4 +- .../src/File/Processor/TIM_Processor.cpp | 46 +++++++++++++++---- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/include/PSX/File/File_Types.hpp b/include/PSX/File/File_Types.hpp index 358e6ac9..beaf1c5e 100644 --- a/include/PSX/File/File_Types.hpp +++ b/include/PSX/File/File_Types.hpp @@ -13,19 +13,19 @@ struct __no_align SimpleTIM : private ComplexBitMap { this->raw = 0; } - constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : ComplexBitMap(ComplexBitMap::with(TextureX.with(texX), TextureY.with(texY), ClutX.with(clutX), ClutY.with(clutY))) { + constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : ComplexBitMap(ComplexBitMap::with(TextureX.with(texX >> 1), TextureY.with(texY >> 1), ClutX.with(clutX >> 4), ClutY.with(clutY))) { } constexpr uint16_t getTextureX() const { - return ComplexBitMap::get_value(SimpleTIM::TextureX); + return (ComplexBitMap::get_value(SimpleTIM::TextureX) << 1); } constexpr uint16_t getTextureY() const { - return ComplexBitMap::get_value(SimpleTIM::TextureY); + return (ComplexBitMap::get_value(SimpleTIM::TextureY) << 1); } constexpr uint16_t getClutX() const { - return ComplexBitMap::get_value(SimpleTIM::ClutX); + return (ComplexBitMap::get_value(SimpleTIM::ClutX) << 4); } constexpr uint16_t getClutY() const { diff --git a/include/PSX/File/Processor/File_Processor.hpp b/include/PSX/File/Processor/File_Processor.hpp index 2bab9f28..d2986437 100644 --- a/include/PSX/File/Processor/File_Processor.hpp +++ b/include/PSX/File/Processor/File_Processor.hpp @@ -10,7 +10,7 @@ namespace FileProcessor { }; struct Configuration; - typedef bool (*ProcessRoutine)(Configuration&, Reserved&); + typedef bool (*ProcessRoutine)(Configuration&, Reserved&, bool); struct Configuration { ProcessRoutine process_routine = nullptr; @@ -18,7 +18,7 @@ namespace FileProcessor { size_t data_size = 0ull; template - static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&), const uint32_t* data_adr) { + static __always_inline Configuration from(bool (*process_routine)(Configuration&, T&, bool), const uint32_t* data_adr) { return {reinterpret_cast(process_routine), data_adr}; } }; @@ -28,15 +28,15 @@ namespace FileProcessor { Reserved reserved; template - static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&)) { + static __always_inline State from(const T& reserved, const uint32_t* data_adr, bool (*process_routine)(Configuration&, T&, bool)) { return {Configuration::from(process_routine, data_adr), *reinterpret_cast(&reserved)}; static_assert(sizeof(T) <= sizeof(Reserved)); } public: - bool process(size_t size) { + bool process(size_t size, bool is_last) { this->config.data_size += size; - return (*this->config.process_routine)(this->config, this->reserved); + return (*this->config.process_routine)(this->config, this->reserved, is_last); } }; diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index 272065fe..a00a63fe 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -35,11 +35,11 @@ namespace GPU { DMA::end(); //DMA End - Display::enable(); - //For now - auto state = FileProcessor::create(reinterpret_cast(SplashScreen), SimpleTIM(0, 0, 0, 0)); - while(state.process((sizeof(SplashScreen)/sizeof(uint32_t)))); + auto state = FileProcessor::create(reinterpret_cast(SplashScreen), SimpleTIM(93, 0, 0, 0)); + while(state.process((sizeof(SplashScreen)/sizeof(uint32_t)), true)); + + Display::enable(); } void setup() { diff --git a/src/Library/src/File/Processor/SimpleHelper.hpp b/src/Library/src/File/Processor/SimpleHelper.hpp index 081af333..d0e7de9f 100644 --- a/src/Library/src/File/Processor/SimpleHelper.hpp +++ b/src/Library/src/File/Processor/SimpleHelper.hpp @@ -17,9 +17,9 @@ namespace FileProcessor { } template - static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&), State::Configuration& config, T& state) { + static bool exchange_and_execute_process_function(bool (*process_routine)(State::Configuration&, T&, bool), State::Configuration& config, T& state, bool is_last) { config.process_routine = reinterpret_cast(process_routine); - return process_routine(config, state); + return process_routine(config, state, is_last); } } } diff --git a/src/Library/src/File/Processor/TIM_Processor.cpp b/src/Library/src/File/Processor/TIM_Processor.cpp index 1c9b1cee..9b02bf53 100644 --- a/src/Library/src/File/Processor/TIM_Processor.cpp +++ b/src/Library/src/File/Processor/TIM_Processor.cpp @@ -1,5 +1,6 @@ #include "../../../include/GPU/GPU.h" #include "SimpleHelper.hpp" +#include #include namespace FileProcessor { @@ -29,7 +30,8 @@ namespace FileProcessor { struct SimpleTIMState { SimpleTIM dst_info; - SimpleTIMSize size_info; + SimpleTIMSize size_info; + size_t words_left; //32bit values constexpr SimpleTIMState(const SimpleTIM& dst_info) : dst_info(dst_info) { } @@ -41,15 +43,43 @@ namespace FileProcessor { GPU::DMA::Receive::set_src(reinterpret_cast(src)); } - static void set_gpu_receive_data(const uint32_t* src, const SimpleTIMState& state) { - set_gpu_receive(src, state.dst_info.getTextureX(), state.dst_info.getTextureY(), state.size_info.getTextureWidth(), state.size_info.getTextureWidth()); + 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(); + + 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) { - return false; + static bool parse_data(State::Configuration& config, SimpleTIMState& state, bool is_last) { + auto block_count = (state.words_left >> 4); + + state.words_left &= 0b1111; + while(block_count > 0) { + const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count; + + // Send data! + GPU::DMA::wait(); + GPU::DMA::Receive::start(block_send); + block_count -= block_send; + } + + if(is_last) { + // Send words + if(state.words_left > 0) { + GPU::DMA::wait(); + GPU::DMA::Receive::start(1, state.words_left); + } + + GPU::DMA::wait(); + GPU::DMA::end(); + return false; + } + + return true; } - static bool parse_header(State::Configuration& config, SimpleTIMState& state) { + static bool parse_header(State::Configuration& config, SimpleTIMState& state, bool is_last) { if(config.data_size >= sizeof(SimpleTIMSize)) { Helper::simple_read(state.size_info, config); @@ -63,11 +93,11 @@ 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); + return Helper::exchange_and_execute_process_function(parse_data, config, state, is_last); } } - return true; + return !is_last; } State create(const uint32_t* data_adr, const SimpleTIM& file) {