From a633b74db140edb50a8997c8444d07af43b958e5 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sat, 1 Apr 2023 14:57:03 +0200 Subject: [PATCH] Load image w/o CircularBuffer --- include/PSX/File/Processor/file_processor.hpp | 18 ++++++++-------- src/Library/src/BootLoader/gpu_boot.cpp | 2 +- src/Library/src/CD/cd.cpp | 21 +++++++++++++++---- .../src/File/Processor/cd_file_processor.cpp | 6 +++--- .../src/File/Processor/nothing_processor.cpp | 2 +- .../src/File/Processor/simplehelper.hpp | 6 ++---- .../src/File/Processor/tim_processor.cpp | 19 +++++++++-------- 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/include/PSX/File/Processor/file_processor.hpp b/include/PSX/File/Processor/file_processor.hpp index fe3e3e9d..5930071a 100644 --- a/include/PSX/File/Processor/file_processor.hpp +++ b/include/PSX/File/Processor/file_processor.hpp @@ -20,17 +20,17 @@ namespace JabyEngine { struct Configuration { ProcessRoutine process_routine = nullptr; - const uint32_t* data_adr = nullptr; - size_t data_word_size = 0ull; + const uint8_t* data_adr = nullptr; + size_t data_bytes = 0ull; template - static __always_inline Configuration from(GenericProcessRoutine process_routine, const uint32_t* data_adr) { + static __always_inline Configuration from(GenericProcessRoutine process_routine, const uint8_t* data_adr) { return {reinterpret_cast(process_routine), data_adr}; } - constexpr void processed(size_t words) { - this->data_adr += words; - this->data_word_size -= words; + constexpr void processed(size_t bytes) { + this->data_adr += bytes; + this->data_bytes -= bytes; } }; @@ -39,14 +39,14 @@ namespace JabyEngine { Reserved reserved; template - static __always_inline State from(const T& reserved, const uint32_t* data_adr, GenericProcessRoutine process_routine) { + static __always_inline State from(const T& reserved, const uint8_t* data_adr, GenericProcessRoutine process_routine) { return {Configuration::from(process_routine, data_adr), *reinterpret_cast(&reserved)}; static_assert(sizeof(T) <= sizeof(Reserved)); } public: - Progress process(size_t word_size) { - this->config.data_word_size += word_size; + Progress process(size_t bytes_ready) { + this->config.data_bytes += bytes_ready; return (*this->config.process_routine)(this->config, this->reserved); } }; diff --git a/src/Library/src/BootLoader/gpu_boot.cpp b/src/Library/src/BootLoader/gpu_boot.cpp index fa0d97bd..d311e54d 100644 --- a/src/Library/src/BootLoader/gpu_boot.cpp +++ b/src/Library/src/BootLoader/gpu_boot.cpp @@ -43,7 +43,7 @@ namespace JabyEngine { // Upload SplashScreen picture auto state = FileProcessor::create(&__boot_loader_end, SimpleTIM(32, 0, 0, 0)); - while(state.process((bytes_ready/sizeof(uint32_t))) == Progress::InProgress); + while(state.process(bytes_ready) == Progress::InProgress); Display::enable(); } diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index a812c3f4..c407727e 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -30,6 +30,12 @@ namespace JabyEngine { Command::send(CD_IO::Command::Pause); } + // Requires Index0 + static void start_reading_cd() { + Command::send(CD_IO::Command::ReadN); + current_state = State::Reading; + } + static void read_sector_dma(CD_IO::DataSector& sector) { static const auto WaitSectorReady = []() { while(!CD_IO::IndexStatus.is_set(CD_IO::IndexStatus_t::HasDataFifoData)); @@ -130,9 +136,7 @@ namespace JabyEngine { const auto loc = CDTimeStamp::from(file_info); Command::send_wait(CD_IO::Command::SetLoc, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd()); - Command::send(CD_IO::Command::ReadN); - - current_state = State::Reading; + start_reading_cd(); printf("Now reading: %i(%i:%i:%i)\n", file_info.lba, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd()); } @@ -142,8 +146,17 @@ namespace JabyEngine { return true; } + printf(">>> Trying to read buffer from continue_reading\n"); CD_IO::PortIndex1::change_to(); - return try_read_sector(); + if(!try_read_sector()) { + return false; + } + + if(current_state != State::Done) { + CD_IO::PortIndex0::change_to(); + start_reading_cd(); + } + return true; } } } diff --git a/src/Library/src/File/Processor/cd_file_processor.cpp b/src/Library/src/File/Processor/cd_file_processor.cpp index 3fe5550a..684c8858 100644 --- a/src/Library/src/File/Processor/cd_file_processor.cpp +++ b/src/Library/src/File/Processor/cd_file_processor.cpp @@ -3,7 +3,7 @@ #include namespace JabyEngine { - static constexpr auto NormalCircularBufferSize = 5; + static constexpr auto NormalCircularBufferSize = 64; void CDFileProcessor :: start_cur_job() { using CD::internal::FileInfo; @@ -57,7 +57,7 @@ namespace JabyEngine { if(result) { // Process the data in the tmp_area - if(this->file_state.process(result.bytes_ready/sizeof(uint32_t)) == Progress::Error) { + if(this->file_state.process(result.bytes_ready) == Progress::Error) { return false; } } @@ -84,7 +84,7 @@ namespace JabyEngine { /* We are done now! The user decides if he wants the next value - */ + */ return Progress::Done; case CD::internal::State::BufferFull: diff --git a/src/Library/src/File/Processor/nothing_processor.cpp b/src/Library/src/File/Processor/nothing_processor.cpp index b76e5e2c..3bedba7b 100644 --- a/src/Library/src/File/Processor/nothing_processor.cpp +++ b/src/Library/src/File/Processor/nothing_processor.cpp @@ -10,7 +10,7 @@ namespace JabyEngine { } State create(const uint32_t* data_adr, const Nothing& nothing) { - return State::from(NothingState(), data_adr, parse_nothing); + return State::from(NothingState(), reinterpret_cast(data_adr), parse_nothing); } } } \ No newline at end of file diff --git a/src/Library/src/File/Processor/simplehelper.hpp b/src/Library/src/File/Processor/simplehelper.hpp index 0c179381..bdcfcae5 100644 --- a/src/Library/src/File/Processor/simplehelper.hpp +++ b/src/Library/src/File/Processor/simplehelper.hpp @@ -10,12 +10,10 @@ namespace JabyEngine { namespace Helper { template static void simple_read(T& dst, State::Configuration& config) { - static constexpr size_t UINT32_SIZE = (sizeof(T)/sizeof(uint32_t)); + static constexpr size_t T_SIZE = sizeof(T); dst = *reinterpret_cast(config.data_adr); - config.processed(UINT32_SIZE); - - static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T)); + config.processed(T_SIZE); } template diff --git a/src/Library/src/File/Processor/tim_processor.cpp b/src/Library/src/File/Processor/tim_processor.cpp index c9a3eca8..f0528270 100644 --- a/src/Library/src/File/Processor/tim_processor.cpp +++ b/src/Library/src/File/Processor/tim_processor.cpp @@ -50,9 +50,10 @@ namespace JabyEngine { } static Progress 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); + 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); while(block_count > 0) { const auto block_send = (block_count > UI16_MAX) ? UI16_MAX : block_count; @@ -75,7 +76,7 @@ namespace JabyEngine { GPU::internal::DMA::end(); state.words_left = 0; - config.processed(words_to_use); + config.processed(words_to_use*sizeof(uint32_t)); return Progress::Done; } @@ -84,13 +85,13 @@ namespace JabyEngine { const auto words_used = (words_to_use & ~0b1111); state.words_left -= words_used; - config.processed(words_used); + config.processed(words_used*sizeof(uint32_t)); return Progress::InProgress; } } static Progress switch_state_parse_data(State::Configuration& config, SimpleTIMState& state) { - set_gpu_receive_data(config.data_adr, state, state.size_info.getTextureWidth(), state.size_info.getTextureHeight()); + set_gpu_receive_data(reinterpret_cast(config.data_adr), state, state.size_info.getTextureWidth(), state.size_info.getTextureHeight()); return Helper::exchange_and_execute_process_function(parse_data, config, state); } @@ -105,13 +106,13 @@ namespace JabyEngine { } static Progress parse_header(State::Configuration& config, SimpleTIMState& state) { - if(config.data_word_size >= (sizeof(SimpleTIMSize)/sizeof(uint32_t))) { + if(config.data_bytes >= sizeof(SimpleTIMSize)) { Helper::simple_read(state.size_info, config); //Check if we have a clut to care about if(state.size_info.getClutWidth() > 0) { //CLUTs are 16bit full color anyway - set_gpu_receive_data(config.data_adr, state, state.size_info.getClutWidth(), state.size_info.getClutHeight()); + set_gpu_receive_data(reinterpret_cast(config.data_adr), state, state.size_info.getClutWidth(), state.size_info.getClutHeight()); return Helper::exchange_and_execute_process_function(parse_clut, config, state); } @@ -125,7 +126,7 @@ namespace JabyEngine { } State create(const uint32_t* data_adr, const SimpleTIM& file) { - return State::from(SimpleTIMState(file), data_adr, parse_header); + return State::from(SimpleTIMState(file), reinterpret_cast(data_adr), parse_header); } } }