Support custom file parsing
This commit is contained in:
@@ -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<Reserved> 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<typename T>
|
||||
static __always_inline Configuration from(GenericProcessRoutine<T> process_routine, const uint8_t* data_adr) {
|
||||
@@ -33,13 +33,12 @@ namespace JabyEngine {
|
||||
}
|
||||
};
|
||||
|
||||
__friends:
|
||||
Configuration config;
|
||||
Reserved reserved;
|
||||
|
||||
template<typename T>
|
||||
static __always_inline State from(const T& reserved, const uint8_t* data_adr, GenericProcessRoutine<T> process_routine) {
|
||||
return {Configuration::from(process_routine, data_adr), *reinterpret_cast<const Reserved*>(&reserved)};
|
||||
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*>(&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);
|
||||
}
|
||||
}
|
@@ -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<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));
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
23
include/PSX/File/file_processor_helper.hpp
Normal file
23
include/PSX/File/file_processor_helper.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "Processor/file_processor.hpp"
|
||||
#include "cd_file_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace FileProcessor {
|
||||
namespace Helper {
|
||||
template<typename T>
|
||||
static void simple_read(T& dst, State::Configuration& config) {
|
||||
static constexpr size_t T_SIZE = sizeof(T);
|
||||
|
||||
dst = *reinterpret_cast<const T*>(config.data_adr);
|
||||
config.processed(T_SIZE);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static Progress exchange_and_execute_process_function(State::GenericProcessRoutine<T> process_routine, State::Configuration& config, T& state) {
|
||||
config.process_routine = reinterpret_cast<State::ProcessRoutine>(process_routine);
|
||||
return process_routine(config, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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
|
||||
#endif //!__friends
|
Reference in New Issue
Block a user