Rename include folder to internal-include for easier destinguishing with the JabyEngine include folder
This commit is contained in:
53
src/Library/internal-include/CD/cd_internal.hpp
Normal file
53
src/Library/internal-include/CD/cd_internal.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef __JABYENGINE_CD_INTERNAL_HPP__
|
||||
#define __JABYENGINE_CD_INTERNAL_HPP__
|
||||
#include "cd_types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace CD {
|
||||
namespace internal {
|
||||
extern CD_IO::Interrupt::Type last_interrupt;
|
||||
extern State current_state;
|
||||
|
||||
static CD_IO::Interrupt::Type read_last_interrupt() {
|
||||
return const_cast<volatile CD_IO::Interrupt::Type&>(last_interrupt);
|
||||
}
|
||||
|
||||
static State read_current_state() {
|
||||
return const_cast<volatile State&>(current_state);
|
||||
}
|
||||
|
||||
struct Command {
|
||||
static void wait_until(CD_IO::Interrupt::Type irq) {
|
||||
while(read_last_interrupt() != irq);
|
||||
}
|
||||
|
||||
template<typename...ARGS>
|
||||
static void send(CD_IO::CommandFifo_v& cmd_fifo, CD_IO::ParameterFifo_v& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) {
|
||||
while(CD_IO::IndexStatus.is_set(CD_IO::IndexStatus_t::IsTransmissionBusy));
|
||||
|
||||
((parameter_fifo = args),...);
|
||||
cmd_fifo = cmd.id;
|
||||
}
|
||||
|
||||
template<typename T, typename...ARGS>
|
||||
static void send(CD_IO::Command::Desc cmd, ARGS...args) {
|
||||
send(T::CommandFifo, T::ParameterFifo, cmd, args...);
|
||||
}
|
||||
|
||||
template<typename...ARGS>
|
||||
static void send_wait(CD_IO::CommandFifo_v& cmd_fifo, CD_IO::ParameterFifo_v& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) {
|
||||
send(cmd_fifo, parameter_fifo, cmd, args...);
|
||||
wait_until(cmd.complete_irq);
|
||||
}
|
||||
|
||||
template<typename T, typename...ARGS>
|
||||
static void send_wait(CD_IO::Command::Desc cmd, ARGS...args) {
|
||||
send_wait(T::CommandFifo, T::ParameterFifo, cmd, args...);
|
||||
}
|
||||
};
|
||||
|
||||
void read_file(FileInfo file_info, const SectorBufferAllocator& buffer_allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //!__JABYENGINE_CD_INTERNAL_HPP__
|
86
src/Library/internal-include/CD/cd_types.hpp
Normal file
86
src/Library/internal-include/CD/cd_types.hpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#ifndef __JABYENGINE_INTERNAL_CD_TYPES_HPP__
|
||||
#define __JABYENGINE_INTERNAL_CD_TYPES_HPP__
|
||||
#include <PSX/AutoLBA/auto_lba.hpp>
|
||||
#include <PSX/Auxiliary/math_helper.hpp>
|
||||
#include <PSX/System/IOPorts/cd_io.hpp>
|
||||
#include <stddef.h>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace CD {
|
||||
namespace internal {
|
||||
enum struct State {
|
||||
Free = 0,
|
||||
Done = 0,
|
||||
|
||||
Reading,
|
||||
BufferFull,
|
||||
Error,
|
||||
};
|
||||
|
||||
struct FileInfo {
|
||||
uint16_t lba;
|
||||
uint16_t sectors;
|
||||
|
||||
static constexpr FileInfo from(const AutoLBAEntry& entry) {
|
||||
return FileInfo{entry.lba, CD_IO::DataSector::words_to_sectors(entry.size_words)};
|
||||
}
|
||||
};
|
||||
|
||||
class SectorBufferAllocator {
|
||||
private:
|
||||
typedef CD_IO::DataSector* (*AllocatorFunction)(void* ctx);
|
||||
|
||||
private:
|
||||
void* ctx = nullptr;
|
||||
AllocatorFunction allocate = nullptr;
|
||||
|
||||
constexpr SectorBufferAllocator(void* ctx, AllocatorFunction function) : ctx(ctx), allocate(function) {
|
||||
}
|
||||
|
||||
public:
|
||||
constexpr SectorBufferAllocator() = default;
|
||||
|
||||
static constexpr SectorBufferAllocator create(void* obj, AllocatorFunction function) {
|
||||
return SectorBufferAllocator(obj, function);
|
||||
}
|
||||
|
||||
inline CD_IO::DataSector* allocate_sector() const {
|
||||
return this->allocate(this->ctx);
|
||||
}
|
||||
};
|
||||
|
||||
struct CDTimeStamp {
|
||||
static constexpr size_t MaxSector = 75;
|
||||
static constexpr size_t MaxSeconds = 60;
|
||||
|
||||
uint8_t min;
|
||||
uint8_t sec;
|
||||
uint8_t sector;
|
||||
|
||||
static constexpr CDTimeStamp from(uint16_t lba) {
|
||||
const auto [min, new_lba] = div_and_mod(lba, static_cast<uint16_t>(MaxSector*MaxSeconds));
|
||||
const auto [sec, sectors] = div_and_mod(new_lba, static_cast<uint16_t>(MaxSector));
|
||||
|
||||
return CDTimeStamp{static_cast<uint8_t>(min), static_cast<uint8_t>(sec), static_cast<uint8_t>(sectors)};
|
||||
}
|
||||
|
||||
static constexpr CDTimeStamp from(const FileInfo& file_info) {
|
||||
return CDTimeStamp::from(file_info.lba);
|
||||
}
|
||||
|
||||
constexpr uint8_t get_min_cd() const {
|
||||
return to_bcd(this->min);
|
||||
}
|
||||
|
||||
constexpr uint8_t get_sec_cd() const {
|
||||
return to_bcd(this->sec);
|
||||
}
|
||||
|
||||
constexpr uint8_t get_sector_cd() const {
|
||||
return to_bcd(this->sector);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //!__JABYENGINE_INTERNAL_CD_TYPES_HPP__
|
Reference in New Issue
Block a user