Load image w/o CircularBuffer

This commit is contained in:
Jaby 2023-04-01 14:57:03 +02:00
parent 5770d4f77e
commit a633b74db1
7 changed files with 43 additions and 31 deletions

View File

@ -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<typename T>
static __always_inline Configuration from(GenericProcessRoutine<T> process_routine, const uint32_t* data_adr) {
static __always_inline Configuration from(GenericProcessRoutine<T> process_routine, const uint8_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;
constexpr void processed(size_t bytes) {
this->data_adr += bytes;
this->data_bytes -= bytes;
}
};
@ -39,14 +39,14 @@ namespace JabyEngine {
Reserved reserved;
template<typename T>
static __always_inline State from(const T& reserved, const uint32_t* data_adr, GenericProcessRoutine<T> process_routine) {
static __always_inline State from(const T& reserved, const uint8_t* data_adr, GenericProcessRoutine<T> process_routine) {
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&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);
}
};

View File

@ -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();
}

View File

@ -30,6 +30,12 @@ namespace JabyEngine {
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
}
// Requires Index0
static void start_reading_cd() {
Command::send<CD_IO::PortIndex0>(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::PortIndex0>(CD_IO::Command::SetLoc, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd());
Command::send<CD_IO::PortIndex0>(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;
}
}
}

View File

@ -3,7 +3,7 @@
#include <stdio.h>
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;
}
}

View File

@ -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<const uint8_t*>(data_adr), parse_nothing);
}
}
}

View File

@ -10,12 +10,10 @@ namespace JabyEngine {
namespace Helper {
template<typename T>
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<const T*>(config.data_adr);
config.processed(UINT32_SIZE);
static_assert((UINT32_SIZE*sizeof(uint32_t)) == sizeof(T));
config.processed(T_SIZE);
}
template<typename T>

View File

@ -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<const uint32_t*>(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<const uint32_t*>(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<const uint8_t*>(data_adr), parse_header);
}
}
}