Support custom file parsing

This commit is contained in:
Jaby 2024-08-04 13:15:58 -05:00
parent f67ac19513
commit 5ebee334fd
12 changed files with 91 additions and 37 deletions

View File

@ -0,0 +1,13 @@
#pragma once
#include <PSX/File/cd_file_types.hpp>
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);
}
};

View File

@ -0,0 +1,26 @@
#include "custom_files.hpp"
#include <PSX/File/file_processor_helper.hpp>
#include <stdio.hpp>
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<FileType>(file_type)) {
case FileType::Jingle:
return State::from(JingleState{.sfx_id = payload.raw}, reinterpret_cast<const uint8_t*>(data_adr), parse_jingle);
default:
return FileProcessor::create(data_adr, Nothing());
}
}
}
}

View File

@ -1,4 +1,5 @@
#include "../include/asset_mgr.hpp" #include "../include/asset_mgr.hpp"
#include "Custom/custom_files.hpp"
#include "Overlay/Overlays.hpp" #include "Overlay/Overlays.hpp"
#include <PSX/Audio/CDXA.hpp> #include <PSX/Audio/CDXA.hpp>
#include <PSX/AutoLBA/auto_lba.hpp> #include <PSX/AutoLBA/auto_lba.hpp>
@ -58,8 +59,9 @@ namespace Assets {
namespace Main { namespace Main {
static const CDFile Files[] = { static const CDFile Files[] = {
CDFileBuilder::simple_tim(LBA::PACO, PacoTIM), CDFileBuilder::simple_tim(LBA::PACO, PacoTIM),
CDFileBuilder::simple_tim(LBA::DFISH, DoenerFishInfo.tim) CDFileBuilder::simple_tim(LBA::DFISH, DoenerFishInfo.tim),
CustomCDFileBuilder::jingle(32),
}; };
void load() { void load() {

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "../../Auxiliary/types.hpp" #include "../../Auxiliary/types.hpp"
#include "../file_types.hpp" #include "../cd_file_types.hpp"
namespace JabyEngine { namespace JabyEngine {
namespace FileProcessor { namespace FileProcessor {
class State { class State {
__friends: public:
struct Reserved { struct Reserved {
uint32_t reserved[4]; uint32_t reserved[4];
}; };
@ -18,9 +18,9 @@ namespace JabyEngine {
typedef GenericProcessRoutine<Reserved> ProcessRoutine; typedef GenericProcessRoutine<Reserved> ProcessRoutine;
struct Configuration { struct Configuration {
ProcessRoutine process_routine = nullptr; ProcessRoutine process_routine = nullptr;
const uint8_t* data_adr = nullptr; const uint8_t* data_adr = nullptr;
size_t data_bytes = 0ull; size_t data_bytes = 0ull;
template<typename T> template<typename T>
static __always_inline Configuration from(GenericProcessRoutine<T> process_routine, const uint8_t* data_adr) { static __always_inline Configuration from(GenericProcessRoutine<T> process_routine, const uint8_t* data_adr) {
@ -33,13 +33,12 @@ namespace JabyEngine {
} }
}; };
__friends:
Configuration config; Configuration config;
Reserved reserved; Reserved reserved;
template<typename T> template<typename T>
static __always_inline State from(const T& reserved, const uint8_t* data_adr, GenericProcessRoutine<T> process_routine) { static __always_inline State from(const T& state, const uint8_t* data_adr, GenericProcessRoutine<T> process_routine) {
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)}; return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&state)};
static_assert(sizeof(T) <= sizeof(Reserved)); static_assert(sizeof(T) <= sizeof(Reserved));
} }
@ -53,5 +52,7 @@ namespace JabyEngine {
// The nothing state // The nothing state
State create(const uint32_t* data_adr, const Nothing& nothing); State create(const uint32_t* data_adr, const Nothing& nothing);
State create(const uint32_t* data_adr, const SimpleTIM& file); 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);
} }
} }

View File

@ -3,24 +3,36 @@
#include "file_types.hpp" #include "file_types.hpp"
namespace JabyEngine { namespace JabyEngine {
enum struct CDFileType : uint8_t { using CDFileType_t = uint8_t;
using RawPayload_t = uint32_t;
enum struct CDFileType : CDFileType_t {
SimpleTIM = 0, SimpleTIM = 0,
CopyTo, CopyTo,
Custom,
}; };
#pragma pack(push, 1) #pragma pack(push, 1)
struct CDFile { struct CDFile {
union Payload { union Payload {
uint32_t raw; RawPayload_t raw;
SimpleTIM simple_tim; SimpleTIM simple_tim;
CopyTo copy_to; CopyTo copy_to;
Overlay overlay; Overlay overlay;
}; };
uint8_t rel_lba_idx; uint8_t rel_lba_idx;
CDFileType type; CDFileType type;
Payload payload; Payload payload;
template<typename S>
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<CDFileType>(static_cast<CDFileType_t>(CDFileType::Custom) + static_cast<CDFileType_t>(cd_file_type)),
.payload = {.raw = raw}
};
}
static_assert(sizeof(Payload) == sizeof(uint32_t)); static_assert(sizeof(Payload) == sizeof(uint32_t));
}; };
#pragma pack(pop) #pragma pack(pop)

View File

@ -1,7 +1,6 @@
#ifndef __JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__ #pragma once
#define __JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__ #include "Processor/file_processor.hpp"
#include "cd_file_types.hpp"
#include <PSX/File/Processor/file_processor.hpp>
namespace JabyEngine { namespace JabyEngine {
namespace FileProcessor { namespace FileProcessor {
@ -21,5 +20,4 @@ namespace JabyEngine {
} }
} }
} }
} }
#endif // !__JABYENGINE_INTERNAL_SIMPLE_HELPER_HPP__

View File

@ -7,19 +7,10 @@
#define __no_inline __attribute__((noinline)) #define __no_inline __attribute__((noinline))
#define __no_return __attribute__((noreturn)) #define __no_return __attribute__((noreturn))
#define __always_inline __attribute__((always_inline)) #define __always_inline __attribute__((always_inline))
#define __weak __attribute__((weak))
#define __section(name) __attribute__((section(name))) #define __section(name) __attribute__((section(name)))
#define __collect(...) __VA_ARGS__ #define __collect(...) __VA_ARGS__
#ifndef __friends #ifndef __friends
#define __friends private #define __friends private
#endif //!__friends #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

View File

@ -7,6 +7,7 @@
// TODO: Outsource the interrupt handler to new source file? // 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: 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 JabyEngine {
namespace CDDA { namespace CDDA {
extern CD::internal::BCDTimeStamp playing_track; extern CD::internal::BCDTimeStamp playing_track;

View File

@ -39,10 +39,11 @@ namespace JabyEngine {
switch(file.type) { switch(file.type) {
case CDFileType::SimpleTIM: case CDFileType::SimpleTIM:
return FileProcessor::create(data_adr, file.payload.simple_tim); return FileProcessor::create(data_adr, file.payload.simple_tim);
case CDFileType::CopyTo: case CDFileType::CopyTo:
return FileProcessor::create(data_adr, Nothing());
default: default:
return FileProcessor::create(data_adr, Nothing()); return FileProcessor::create_custom(data_adr, static_cast<CDFileType_t>(file.type) - static_cast<CDFileType_t>(CDFileType::Custom), file.payload);
} }
}; };
@ -56,7 +57,6 @@ namespace JabyEngine {
return self.circular_buffer.allocate(); 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"); //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");
} }

View File

@ -0,0 +1,10 @@
#include <PSX/File/file_processor_helper.hpp>
#include <stdio.hpp>
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());
}
}
}

View File

@ -1,4 +1,4 @@
#include "simplehelper.hpp" #include <PSX/File/file_processor_helper.hpp>
namespace JabyEngine { namespace JabyEngine {
namespace FileProcessor { namespace FileProcessor {

View File

@ -1,5 +1,5 @@
#include "../../../internal-include/GPU/gpu_internal.hpp" #include "../../../internal-include/GPU/gpu_internal.hpp"
#include "simplehelper.hpp" #include <PSX/File/file_processor_helper.hpp>
#include <PSX/GPU/gpu_types.hpp> #include <PSX/GPU/gpu_types.hpp>
#include <limits.hpp> #include <limits.hpp>
#include <stdio.hpp> #include <stdio.hpp>