From 5ebee334fddf5c013e0c9ecf8e5b9fe17a609dc2 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 4 Aug 2024 13:15:58 -0500 Subject: [PATCH] Support custom file parsing --- .../application/src/Custom/custom_files.hpp | 13 ++++++++++ .../application/src/Custom/file_parser.cpp | 26 +++++++++++++++++++ .../PoolBox/application/src/asset_mgr.cpp | 6 +++-- include/PSX/File/Processor/file_processor.hpp | 17 ++++++------ include/PSX/File/cd_file_types.hpp | 22 ++++++++++++---- .../PSX/File/file_processor_helper.hpp | 10 +++---- include/PSX/jabyengine_defines.hpp | 13 ++-------- src/Library/src/CD/cd.cpp | 1 + .../src/File/Processor/cd_file_processor.cpp | 6 ++--- .../src/File/Processor/custom_processor.cpp | 10 +++++++ .../src/File/Processor/nothing_processor.cpp | 2 +- .../src/File/Processor/tim_processor.cpp | 2 +- 12 files changed, 91 insertions(+), 37 deletions(-) create mode 100644 examples/PoolBox/application/src/Custom/custom_files.hpp create mode 100644 examples/PoolBox/application/src/Custom/file_parser.cpp rename src/Library/src/File/Processor/simplehelper.hpp => include/PSX/File/file_processor_helper.hpp (76%) create mode 100644 src/Library/src/File/Processor/custom_processor.cpp diff --git a/examples/PoolBox/application/src/Custom/custom_files.hpp b/examples/PoolBox/application/src/Custom/custom_files.hpp new file mode 100644 index 00000000..c99999ea --- /dev/null +++ b/examples/PoolBox/application/src/Custom/custom_files.hpp @@ -0,0 +1,13 @@ +#pragma once +#include + +enum struct FileType : JabyEngine::CDFileType_t { + Jingle, +}; + +struct CustomCDFileBuilder { + static constexpr JabyEngine::CDFile jingle(uint32_t sfx_id) { + // TODO: This currently re-loads Paco; We should make this treat it's own file! + return JabyEngine::CDFile::custom(0, FileType::Jingle, sfx_id); + } +}; \ No newline at end of file diff --git a/examples/PoolBox/application/src/Custom/file_parser.cpp b/examples/PoolBox/application/src/Custom/file_parser.cpp new file mode 100644 index 00000000..9f96fb97 --- /dev/null +++ b/examples/PoolBox/application/src/Custom/file_parser.cpp @@ -0,0 +1,26 @@ +#include "custom_files.hpp" +#include +#include + +namespace JabyEngine { + namespace FileProcessor { + struct JingleState { + uint32_t sfx_id; + }; + + static Progress parse_jingle(State::Configuration& config, JingleState& jingle) { + printf("Playing jingle: %i\n", jingle.sfx_id); + return Progress::Done; + } + + State create_custom(const uint32_t* data_adr, const CDFileType_t& file_type, const CDFile::Payload& payload) { + switch(static_cast(file_type)) { + case FileType::Jingle: + return State::from(JingleState{.sfx_id = payload.raw}, reinterpret_cast(data_adr), parse_jingle); + + default: + return FileProcessor::create(data_adr, Nothing()); + } + } + } +} \ No newline at end of file diff --git a/examples/PoolBox/application/src/asset_mgr.cpp b/examples/PoolBox/application/src/asset_mgr.cpp index 009d0f74..0fcc3493 100644 --- a/examples/PoolBox/application/src/asset_mgr.cpp +++ b/examples/PoolBox/application/src/asset_mgr.cpp @@ -1,4 +1,5 @@ #include "../include/asset_mgr.hpp" +#include "Custom/custom_files.hpp" #include "Overlay/Overlays.hpp" #include #include @@ -58,8 +59,9 @@ namespace Assets { namespace Main { static const CDFile Files[] = { - CDFileBuilder::simple_tim(LBA::PACO, PacoTIM), - CDFileBuilder::simple_tim(LBA::DFISH, DoenerFishInfo.tim) + CDFileBuilder::simple_tim(LBA::PACO, PacoTIM), + CDFileBuilder::simple_tim(LBA::DFISH, DoenerFishInfo.tim), + CustomCDFileBuilder::jingle(32), }; void load() { diff --git a/include/PSX/File/Processor/file_processor.hpp b/include/PSX/File/Processor/file_processor.hpp index 5cf1091f..ecccbe3e 100644 --- a/include/PSX/File/Processor/file_processor.hpp +++ b/include/PSX/File/Processor/file_processor.hpp @@ -1,11 +1,11 @@ #pragma once #include "../../Auxiliary/types.hpp" -#include "../file_types.hpp" +#include "../cd_file_types.hpp" namespace JabyEngine { namespace FileProcessor { class State { - __friends: + public: struct Reserved { uint32_t reserved[4]; }; @@ -18,9 +18,9 @@ namespace JabyEngine { typedef GenericProcessRoutine ProcessRoutine; struct Configuration { - ProcessRoutine process_routine = nullptr; - const uint8_t* data_adr = nullptr; - size_t data_bytes = 0ull; + ProcessRoutine process_routine = nullptr; + const uint8_t* data_adr = nullptr; + size_t data_bytes = 0ull; template static __always_inline Configuration from(GenericProcessRoutine process_routine, const uint8_t* data_adr) { @@ -33,13 +33,12 @@ namespace JabyEngine { } }; - __friends: Configuration config; Reserved reserved; template - 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 __always_inline State from(const T& state, const uint8_t* data_adr, GenericProcessRoutine process_routine) { + return {Configuration::from(process_routine, data_adr), *reinterpret_cast(&state)}; static_assert(sizeof(T) <= sizeof(Reserved)); } @@ -53,5 +52,7 @@ namespace JabyEngine { // The nothing state State create(const uint32_t* data_adr, const Nothing& nothing); State create(const uint32_t* data_adr, const SimpleTIM& file); + + State create_custom(const uint32_t* data_adr, const CDFileType_t& file_type, const CDFile::Payload& payload); } } \ No newline at end of file diff --git a/include/PSX/File/cd_file_types.hpp b/include/PSX/File/cd_file_types.hpp index 3934cdf2..908d3e92 100644 --- a/include/PSX/File/cd_file_types.hpp +++ b/include/PSX/File/cd_file_types.hpp @@ -3,24 +3,36 @@ #include "file_types.hpp" namespace JabyEngine { - enum struct CDFileType : uint8_t { + using CDFileType_t = uint8_t; + using RawPayload_t = uint32_t; + + enum struct CDFileType : CDFileType_t { SimpleTIM = 0, CopyTo, + Custom, }; #pragma pack(push, 1) struct CDFile { union Payload { - uint32_t raw; - SimpleTIM simple_tim; - CopyTo copy_to; - Overlay overlay; + RawPayload_t raw; + SimpleTIM simple_tim; + CopyTo copy_to; + Overlay overlay; }; uint8_t rel_lba_idx; CDFileType type; Payload payload; + template + static constexpr CDFile custom(uint8_t lba_idx, S cd_file_type, RawPayload_t raw) { + return CDFile{ + .rel_lba_idx = lba_idx, + .type = static_cast(static_cast(CDFileType::Custom) + static_cast(cd_file_type)), + .payload = {.raw = raw} + }; + } static_assert(sizeof(Payload) == sizeof(uint32_t)); }; #pragma pack(pop) diff --git a/src/Library/src/File/Processor/simplehelper.hpp b/include/PSX/File/file_processor_helper.hpp similarity index 76% rename from src/Library/src/File/Processor/simplehelper.hpp rename to include/PSX/File/file_processor_helper.hpp index 983233d8..26e8fb57 100644 --- a/src/Library/src/File/Processor/simplehelper.hpp +++ b/include/PSX/File/file_processor_helper.hpp @@ -1,7 +1,6 @@ -#ifndef __JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__ -#define __JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__ - -#include +#pragma once +#include "Processor/file_processor.hpp" +#include "cd_file_types.hpp" namespace JabyEngine { namespace FileProcessor { @@ -21,5 +20,4 @@ namespace JabyEngine { } } } -} -#endif // !__JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__ \ No newline at end of file +} \ No newline at end of file diff --git a/include/PSX/jabyengine_defines.hpp b/include/PSX/jabyengine_defines.hpp index bd0bb37d..b9b19fb9 100644 --- a/include/PSX/jabyengine_defines.hpp +++ b/include/PSX/jabyengine_defines.hpp @@ -7,19 +7,10 @@ #define __no_inline __attribute__((noinline)) #define __no_return __attribute__((noreturn)) #define __always_inline __attribute__((always_inline)) +#define __weak __attribute__((weak)) #define __section(name) __attribute__((section(name))) #define __collect(...) __VA_ARGS__ #ifndef __friends #define __friends private -#endif //!__friends - -#ifdef __cplusplus - #define __constexpr constexpr - #define START_C_FUNCTIONS extern "C" { - #define END_C_FUNCTIONS } -#else - #define __constexpr - #define START_C_FUNCTIONS - #define END_C_FUNCTIONS -#endif \ No newline at end of file +#endif //!__friends \ No newline at end of file diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index 84f6b1d5..a04f1bd8 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -7,6 +7,7 @@ // TODO: Outsource the interrupt handler to new source file? // TODO: Do not spawn a new thread for handling the CD interrupt but use that thread for loading files or something? +// TODO: Can you use the GPU IO Port while also using DMA? namespace JabyEngine { namespace CDDA { extern CD::internal::BCDTimeStamp playing_track; diff --git a/src/Library/src/File/Processor/cd_file_processor.cpp b/src/Library/src/File/Processor/cd_file_processor.cpp index a99df151..dcc21e67 100644 --- a/src/Library/src/File/Processor/cd_file_processor.cpp +++ b/src/Library/src/File/Processor/cd_file_processor.cpp @@ -39,10 +39,11 @@ namespace JabyEngine { switch(file.type) { case CDFileType::SimpleTIM: return FileProcessor::create(data_adr, file.payload.simple_tim); - case CDFileType::CopyTo: + return FileProcessor::create(data_adr, Nothing()); + default: - return FileProcessor::create(data_adr, Nothing()); + return FileProcessor::create_custom(data_adr, static_cast(file.type) - static_cast(CDFileType::Custom), file.payload); } }; @@ -56,7 +57,6 @@ namespace JabyEngine { return self.circular_buffer.allocate(); })); - //printf(">>> 0x%p\n", this->jobs.files); //printf(">>> %i.) CD needs to load LBA: %i -> %i (is LZ4: [%s])\n", cur_job.rel_lba_idx, cur_lba.get_lba(), cur_lba.get_size_in_sectors(), cur_lba.is_lz4() ? "Yes" : "No"); } diff --git a/src/Library/src/File/Processor/custom_processor.cpp b/src/Library/src/File/Processor/custom_processor.cpp new file mode 100644 index 00000000..4f1cb308 --- /dev/null +++ b/src/Library/src/File/Processor/custom_processor.cpp @@ -0,0 +1,10 @@ +#include +#include + +namespace JabyEngine { + namespace FileProcessor { + State __weak create_custom(const uint32_t* data_adr, const CDFileType_t& file_type, const CDFile::Payload& payload) { + return FileProcessor::create(data_adr, Nothing()); + } + } +} \ No newline at end of file diff --git a/src/Library/src/File/Processor/nothing_processor.cpp b/src/Library/src/File/Processor/nothing_processor.cpp index 3bedba7b..613078e8 100644 --- a/src/Library/src/File/Processor/nothing_processor.cpp +++ b/src/Library/src/File/Processor/nothing_processor.cpp @@ -1,4 +1,4 @@ -#include "simplehelper.hpp" +#include namespace JabyEngine { namespace FileProcessor { diff --git a/src/Library/src/File/Processor/tim_processor.cpp b/src/Library/src/File/Processor/tim_processor.cpp index 74016215..7de8d882 100644 --- a/src/Library/src/File/Processor/tim_processor.cpp +++ b/src/Library/src/File/Processor/tim_processor.cpp @@ -1,5 +1,5 @@ #include "../../../internal-include/GPU/gpu_internal.hpp" -#include "simplehelper.hpp" +#include #include #include #include