Integrate CircularBuffer as essential part of loading files from CD and dedicate file processing to the FileProcessor
This commit is contained in:
@@ -24,11 +24,11 @@ namespace JabyEngine {
|
||||
|
||||
void LZ4Decompressor :: setup(uint8_t* dst_adr) {
|
||||
this->dst_adr = dst_adr;
|
||||
LZ4Decompressor::reset();
|
||||
this->state.enable();
|
||||
}
|
||||
|
||||
void LZ4Decompressor :: reset() {
|
||||
this->state = State();
|
||||
void LZ4Decompressor :: disable() {
|
||||
this->state.disable();
|
||||
}
|
||||
|
||||
LZ4Decompressor::Result LZ4Decompressor :: process(ArrayRange<const uint8_t> data, bool is_last) {
|
||||
@@ -36,6 +36,9 @@ namespace JabyEngine {
|
||||
|
||||
while(data) {
|
||||
switch(this->state.step) {
|
||||
case State::Step::Disabled:
|
||||
return Result::new_done(data.size);
|
||||
|
||||
case State::Step::ReadToken: {
|
||||
const auto token = data.pop();
|
||||
|
||||
|
@@ -3,6 +3,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JabyEngine {
|
||||
static constexpr auto NormalCircularBufferSize = 5;
|
||||
|
||||
void CDFileProcessor :: start_cur_job() {
|
||||
using CD::internal::FileInfo;
|
||||
using CD::internal::SectorBufferAllocator;
|
||||
@@ -11,13 +13,6 @@ namespace JabyEngine {
|
||||
CDFileProcessor &self = *reinterpret_cast<CDFileProcessor*>(ctx);
|
||||
return self.circular_buffer.allocate();
|
||||
};
|
||||
static const auto direct_copy_callback = [](void* ctx) -> CD_IO::DataSector* {
|
||||
auto** data_sector = reinterpret_cast<CD_IO::DataSector**>(ctx);
|
||||
auto* cur_sector = *data_sector;
|
||||
|
||||
data_sector += sizeof(CD_IO::DataSector);
|
||||
return cur_sector;
|
||||
};
|
||||
|
||||
switch(file.type) {
|
||||
case CDFileType::SimpleTIM:
|
||||
@@ -25,8 +20,11 @@ namespace JabyEngine {
|
||||
return SectorBufferAllocator::invalid();
|
||||
|
||||
case CDFileType::CopyTo:
|
||||
this->dst_area = file.payload.copy_to.dst;
|
||||
return SectorBufferAllocator::create(&this->dst_area, direct_copy_callback);
|
||||
this->circular_buffer.setup(reinterpret_cast<CD_IO::DataSector*>(file.payload.copy_to.dst), 512);
|
||||
this->lz4_decomp.disable();
|
||||
|
||||
this->file_state = FileProcessor::create(this->tmp_area, Nothing());
|
||||
return SectorBufferAllocator::create(this, circular_buffer_callback);
|
||||
|
||||
default:
|
||||
return SectorBufferAllocator::invalid();
|
||||
@@ -42,28 +40,26 @@ namespace JabyEngine {
|
||||
printf(">>> CD needs to load LBA: %i -> %i\n", cur_lba.lba, cur_lba.size_words);
|
||||
}
|
||||
|
||||
void CDFileProcessor :: reading_state(const CDFile& file) {
|
||||
switch(file.type) {
|
||||
case CDFileType::SimpleTIM:
|
||||
printf("CDFileProcessor: SimpleTIM not supported yet\n");
|
||||
break;
|
||||
bool CDFileProcessor :: process_data() {
|
||||
while(this->circular_buffer.has_data()) {
|
||||
ArrayRange<const uint8_t> cur_sector(reinterpret_cast<uint8_t*>(this->circular_buffer.get_next()->data), CD_IO::DataSector::SizeBytes);
|
||||
|
||||
// v We can not know if there will be more data or not - but it also doesn't matter much for us
|
||||
const auto result = this->lz4_decomp.process(cur_sector, false);
|
||||
this->circular_buffer.pop();
|
||||
|
||||
case CDFileType::CopyTo:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void CDFileProcessor :: done_state(const CDFile& file) {
|
||||
switch(file.type) {
|
||||
case CDFileType::SimpleTIM:
|
||||
printf("CDFileProcessor: SimpleTIM not supported yet\n");
|
||||
break;
|
||||
|
||||
case CDFileType::CopyTo:
|
||||
default:
|
||||
break;
|
||||
if(result) {
|
||||
// Process the data in the tmp_area
|
||||
if(this->file_state.process(result.bytes_ready/sizeof(uint32_t)) == Progress::Error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDFileProcessor :: setup(const volatile AutoLBAEntry* lba, JobArray jobs, uint32_t* tmp_area) {
|
||||
@@ -71,33 +67,30 @@ namespace JabyEngine {
|
||||
this->jobs = jobs;
|
||||
|
||||
// Setsup the circular buffer and determines where to place the temp area in
|
||||
const_cast<uint32_t*&>(this->tmp_area) = reinterpret_cast<uint32_t*>(this->circular_buffer.setup(reinterpret_cast<CD_IO::DataSector*>(tmp_area), 5));
|
||||
const_cast<uint32_t*&>(this->tmp_area) = reinterpret_cast<uint32_t*>(this->circular_buffer.setup(reinterpret_cast<CD_IO::DataSector*>(tmp_area), NormalCircularBufferSize));
|
||||
CDFileProcessor::start_cur_job();
|
||||
}
|
||||
|
||||
Progress CDFileProcessor :: process() {
|
||||
const auto& cur_job = *this->jobs.files;
|
||||
|
||||
CDFileProcessor::process_data();
|
||||
switch(CD::internal::read_current_state()) {
|
||||
case CD::internal::State::Done:
|
||||
// We are done now!
|
||||
// The user decides if he wants the next value
|
||||
CDFileProcessor::done_state(cur_job);
|
||||
/*
|
||||
We are done now!
|
||||
The user decides if he wants the next value
|
||||
*/
|
||||
return Progress::Done;
|
||||
|
||||
case CD::internal::State::BufferFull:
|
||||
// We have to process data and unpause the CD drive
|
||||
CDFileProcessor::reading_state(cur_job);
|
||||
return CD::internal::continue_reading() ? CDFileProcessor::process() : Progress::Error;
|
||||
/* We processd data and unpause the CD drive */
|
||||
return CD::internal::continue_reading() ? Progress::InProgress : Progress::Error;
|
||||
|
||||
case CD::internal::State::Reading:
|
||||
// Do we have data? Use it!
|
||||
CDFileProcessor::reading_state(cur_job);
|
||||
return Progress::InProgress;
|
||||
|
||||
case CD::internal::State::Error:
|
||||
default:
|
||||
// Error for real!
|
||||
/* Error for real */
|
||||
return Progress::Error;
|
||||
}
|
||||
}
|
||||
|
16
src/Library/src/File/Processor/nothing_processor.cpp
Normal file
16
src/Library/src/File/Processor/nothing_processor.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "simplehelper.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace FileProcessor {
|
||||
struct NothingState {
|
||||
};
|
||||
|
||||
static Progress parse_nothing(State::Configuration& config, NothingState& state) {
|
||||
return Progress::Done;
|
||||
}
|
||||
|
||||
State create(const uint32_t* data_adr, const Nothing& nothing) {
|
||||
return State::from(NothingState(), data_adr, parse_nothing);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user