From 672ad04c83afd61846eda5e14a0f78bed4e6ec93 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sat, 18 Feb 2023 09:35:15 +0100 Subject: [PATCH] Get rough shape of CD file processing code --- .../PSX/File/Processor/cd_file_processor.hpp | 43 +++++++------- include/PSX/File/cd_file_types.hpp | 13 ++++- include/PSX/File/file_types.hpp | 4 ++ src/Library/include/CD/cd_internal.hpp | 56 +++++++++++++++++++ .../src/BootLoader/boot_file/main_boot.cpp | 2 + src/Library/src/CD/cd.cpp | 7 +++ .../src/File/Processor/cd_file_processor.cpp | 20 +++++++ 7 files changed, 121 insertions(+), 24 deletions(-) diff --git a/include/PSX/File/Processor/cd_file_processor.hpp b/include/PSX/File/Processor/cd_file_processor.hpp index e7853ebd..a1b4be58 100644 --- a/include/PSX/File/Processor/cd_file_processor.hpp +++ b/include/PSX/File/Processor/cd_file_processor.hpp @@ -1,34 +1,35 @@ #ifndef __JABYENGINE_CD_FILE_PROCESSOR_HPP__ #define __JABYENGINE_CD_FILE_PROCESSOR_HPP__ +#include "../../AutoLBA/auto_lba.hpp" +#include "../../Auxiliary/lz4_decompressor.hpp" #include "../cd_file_types.hpp" #include "file_processor.hpp" +extern "C" uint32_t __heap_base; + namespace JabyEngine { - namespace CDFileProcessor { - class State { - private: - FileProcessor::State file_processor_state; - const uint32_t* data_adr; - - public: - State() = default; - - void setup(uint16_t lba, uint16_t size, const CDFile::Payload& payload); - bool process(); + class CDFileProcessor { + public: + struct JobArray { + const CDFile* files = nullptr; + size_t size = 0; }; - template - static void load_from_cd(const OverlayLBA* overlay_lbas, const CDFile (&cd_files)[Size]) { - State state; + private: + FileProcessor::State file_pro_state; + LZ4Decompressor lz4_decomp; + JobArray jobs; + uint8_t* work_area = nullptr; + const AutoLBAEntry* lba = nullptr; - for(const auto& file : cd_files) { - const auto& lba_info = overlay_lbas[file.rel_lba_idx]; + void start_cur_job(); - state.setup(lba_info.lba, lba_info.size, file.payload); - //while(state.process());??? - } - } - } + public: + CDFileProcessor() = default; + + void setup(const volatile AutoLBAEntry* lba, JobArray jobs, uint8_t* work_area = reinterpret_cast(&__heap_base)); + Progress process(); + }; } // This will be used as the file processor but will work on cd types diff --git a/include/PSX/File/cd_file_types.hpp b/include/PSX/File/cd_file_types.hpp index de663eff..4e8d0eb6 100644 --- a/include/PSX/File/cd_file_types.hpp +++ b/include/PSX/File/cd_file_types.hpp @@ -6,24 +6,31 @@ namespace JabyEngine { enum struct CDFileType : uint8_t { SimpleTIM = 0, - Custom + CopyTo, }; struct __no_align CDFile { union __no_align Payload { uint32_t empty; SimpleTIM simple_tim; + CopyTo copy_to; }; uint8_t rel_lba_idx; CDFileType type; Payload payload; + + static_assert(sizeof(Payload) == sizeof(uint32_t)); }; - namespace CDFileBuilder { + struct CDFileBuilder { static constexpr CDFile simple_tim(uint8_t rel_lba_idx, SimpleTIM simple_tim) { return CDFile{.rel_lba_idx = rel_lba_idx, .type = CDFileType::SimpleTIM, .payload = {.simple_tim = simple_tim}}; } - } + + static constexpr CDFile copy_to(uint8_t rel_lba_idx, uint32_t* dst) { + return CDFile{.rel_lba_idx = rel_lba_idx, .type = CDFileType::CopyTo, .payload = {.copy_to = CopyTo{dst}}}; + } + }; } #endif //!__JABYENGINE_CD_FILE_TYPES_HPP__ \ No newline at end of file diff --git a/include/PSX/File/file_types.hpp b/include/PSX/File/file_types.hpp index bd64755f..6f353d7c 100644 --- a/include/PSX/File/file_types.hpp +++ b/include/PSX/File/file_types.hpp @@ -33,5 +33,9 @@ namespace JabyEngine { return ComplexBitMap::get_value(SimpleTIM::ClutY); } }; + + struct __no_align CopyTo { + uint32_t* dst; + }; } #endif // !__JABYENGINE_FILE_TYPES_HPP__ \ No newline at end of file diff --git a/src/Library/include/CD/cd_internal.hpp b/src/Library/include/CD/cd_internal.hpp index 08b9900a..3b47036c 100644 --- a/src/Library/include/CD/cd_internal.hpp +++ b/src/Library/include/CD/cd_internal.hpp @@ -5,7 +5,61 @@ namespace JabyEngine { namespace CD { namespace internal { + enum struct State { + Free = 0, + Done = 0, + + Reading, + BufferFull, + Error, + }; + extern VolatilePOD last_interrupt; + extern VolatilePOD state; + + struct Sector { + uint32_t data[512]; + }; + + struct FileInfo { + uint16_t lba; + uint16_t sectors; + + constexpr FileInfo(uint16_t lba, uint16_t sectors) : lba(lba), sectors(sectors) { + } + }; + + class SectorBufferAllocator { + private: + struct Dummy { + }; + + typedef Sector* (*SimpleAllocator)(); + typedef Sector* (Dummy::*ComplexAllocator)(); + + private: + Dummy* this_ctx = nullptr; + union { + SimpleAllocator allocate; + ComplexAllocator this_allocate; + }; + + SectorBufferAllocator(SimpleAllocator allocate) : this_ctx(nullptr), allocate(allocate) { + } + + SectorBufferAllocator(Dummy* ctx, ComplexAllocator this_allocate) : this_ctx(ctx), this_allocate(this_allocate) { + } + + public: + static SectorBufferAllocator create(SimpleAllocator allocate) { + return SectorBufferAllocator(allocate); + } + + template + static SectorBufferAllocator create(T &obj, Sector* (T::*obj_allocate)()) { + return SectorBufferAllocator(reinterpret_cast(&obj), reinterpret_cast(obj_allocate)); + } + }; struct Command { static void wait_until(CD_IO::Interrupt::Type irq) { @@ -26,6 +80,8 @@ namespace JabyEngine { wait_until(cmd.complete_irq); } }; + + State start_reading(FileInfo file_info, const SectorBufferAllocator& buffer_allocator); } } } diff --git a/src/Library/src/BootLoader/boot_file/main_boot.cpp b/src/Library/src/BootLoader/boot_file/main_boot.cpp index 119b0aec..afd053a1 100644 --- a/src/Library/src/BootLoader/boot_file/main_boot.cpp +++ b/src/Library/src/BootLoader/boot_file/main_boot.cpp @@ -1,6 +1,8 @@ #include "../../../include/BootLoader/boot_loader.hpp" #include +#include + extern JabyEngine::NextRoutine main(); namespace JabyEngine { diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index c334f9e1..39c8d26c 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -2,6 +2,8 @@ #include #include +#include + namespace JabyEngine { namespace CD { namespace internal { @@ -35,6 +37,11 @@ namespace JabyEngine { .handler_function = reinterpret_cast(interrupt_handler), .verifier_function = interrupt_verifier }; + + State start_reading(FileInfo file_info, const SectorBufferAllocator& buffer_allocator) { + printf("I'm not implemented! %s\n", __FUNCTION__); + return State::Error; + } } } } \ No newline at end of file diff --git a/src/Library/src/File/Processor/cd_file_processor.cpp b/src/Library/src/File/Processor/cd_file_processor.cpp index 10c19829..13275049 100644 --- a/src/Library/src/File/Processor/cd_file_processor.cpp +++ b/src/Library/src/File/Processor/cd_file_processor.cpp @@ -1,2 +1,22 @@ #include +#include +namespace JabyEngine { + void CDFileProcessor :: start_cur_job() { + const auto& cur_lba = this->lba[this->jobs.files->rel_lba_idx]; + + printf(">>> CD needs to load LBA: %i -> %i\n", cur_lba.lba, cur_lba.size_words); + } + + void CDFileProcessor :: setup(const volatile AutoLBAEntry* lba, JobArray jobs, uint8_t* work_area) { + this->lba = const_cast(lba); + this->work_area = work_area; + this->jobs = jobs; + + CDFileProcessor::start_cur_job(); + } + + Progress CDFileProcessor :: process() { + return Progress::Error; + } +} \ No newline at end of file