Make LZ4 Decompressor return a state value

This commit is contained in:
Jaby 2022-12-29 13:25:48 +01:00
parent c7b9e4e301
commit 87d7bf8efa
3 changed files with 25 additions and 12 deletions

View File

@ -6,10 +6,21 @@
namespace JabyEngine {
class LZ4Decompressor {
public:
enum struct Result {
InProgress = 0,
Done,
Error
struct Result {
Progress progress;
size_t bytes_ready;
static constexpr Result new_error() {
return {Progress::Error, 0};
}
static constexpr Result new_done(size_t bytes_ready) {
return {Progress::Done, bytes_ready};
}
static constexpr Result new_in_progress(size_t bytes_ready) {
return {Progress::InProgress, bytes_ready};
}
};
private:
@ -28,7 +39,7 @@ namespace JabyEngine {
void setup(uint8_t* dst_adr);
void reset();
Progress process(const uint8_t* data, size_t size);
Result process(const uint8_t* data, size_t size);
};
}

View File

@ -10,10 +10,10 @@ namespace JabyEngine {
}
Progress LZ4Decompressor :: process(const uint8_t* data, size_t size) {
LZ4Decompressor::Result LZ4Decompressor :: process(const uint8_t* data, size_t size) {
for(size_t n = 0; n < size; n++) {
this->dst_adr[n] = data[n];
}
return Progress::Error;
return Result::new_error();
}
}

View File

@ -14,10 +14,11 @@ extern "C" uint32_t __boot_loader_end;
namespace JabyEngine {
namespace GPU {
static void decompress_logo() {
static size_t decompress_logo() {
LZ4Decompressor lz4_decomp(reinterpret_cast<uint8_t*>(&__boot_loader_end));
switch(lz4_decomp.process(SplashScreen, sizeof(SplashScreen))) {
const auto [progress, bytes_ready] = lz4_decomp.process(SplashScreen, sizeof(SplashScreen));
switch(progress) {
case Progress::InProgress:
printf("Decompressing still in progress...\n");
break;
@ -30,15 +31,16 @@ namespace JabyEngine {
printf("Done decompressing\n");
break;
}
return bytes_ready;
}
void display_logo() {
decompress_logo();
const auto bytes_ready = decompress_logo();
// Upload SplashScreen picture
auto state = FileProcessor::create(&__boot_loader_end, SimpleTIM(32, 0, 0, 0));
// v this will not be correct for now...
while(state.process((sizeof(SplashScreen)/sizeof(uint32_t))) == Progress::InProgress);
while(state.process((bytes_ready/sizeof(uint32_t))) == Progress::InProgress);
Display::enable();
}