Read files with temp fix
This commit is contained in:
@@ -1,58 +1,11 @@
|
||||
#ifndef __JABYENGINE_CD_INTERNAL_HPP__
|
||||
#define __JABYENGINE_CD_INTERNAL_HPP__
|
||||
#include "cd_types.hpp"
|
||||
#include <PSX/System/IOPorts/cd_io.hpp>
|
||||
#include <PSX/AutoLBA/auto_lba.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace CD {
|
||||
namespace internal {
|
||||
enum struct State {
|
||||
Free = 0,
|
||||
Done = 0,
|
||||
|
||||
Reading,
|
||||
BufferFull,
|
||||
Error,
|
||||
};
|
||||
|
||||
struct DataSector {
|
||||
static constexpr size_t SizeBytes = 2048;
|
||||
static constexpr size_t SizeWords = (SizeBytes/sizeof(uint32_t));
|
||||
|
||||
uint32_t data[SizeWords];
|
||||
|
||||
template<typename T>
|
||||
static constexpr T words_to_sectors(T size) {
|
||||
return (size + static_cast<T>(DataSector::SizeWords - 1))/static_cast<T>(DataSector::SizeWords);
|
||||
}
|
||||
};
|
||||
|
||||
struct FileInfo {
|
||||
uint16_t lba;
|
||||
uint16_t sectors;
|
||||
|
||||
static constexpr FileInfo from_auto_lba(const AutoLBAEntry& entry) {
|
||||
return FileInfo{entry.lba, DataSector::words_to_sectors(entry.size_words)};
|
||||
}
|
||||
};
|
||||
|
||||
class SectorBufferAllocator {
|
||||
private:
|
||||
typedef DataSector* (*AllocatorFunction)(void* ctx);
|
||||
|
||||
private:
|
||||
void* ctx = nullptr;
|
||||
AllocatorFunction allocate = nullptr;
|
||||
|
||||
constexpr SectorBufferAllocator(void* ctx, AllocatorFunction function) : ctx(ctx), allocate(function) {
|
||||
}
|
||||
|
||||
public:
|
||||
static constexpr SectorBufferAllocator create(void* obj, AllocatorFunction function) {
|
||||
return SectorBufferAllocator(obj, function);
|
||||
}
|
||||
};
|
||||
|
||||
extern VolatilePOD<CD_IO::Interrupt::Type> last_interrupt;
|
||||
|
||||
struct Command {
|
||||
|
||||
95
src/Library/include/CD/cd_types.hpp
Normal file
95
src/Library/include/CD/cd_types.hpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#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 <stddef.h>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace CD {
|
||||
namespace internal {
|
||||
enum struct State {
|
||||
Free = 0,
|
||||
Done = 0,
|
||||
|
||||
Reading,
|
||||
BufferFull,
|
||||
Error,
|
||||
};
|
||||
|
||||
struct DataSector {
|
||||
static constexpr size_t SizeBytes = 2048;
|
||||
static constexpr size_t SizeWords = (SizeBytes/sizeof(uint32_t));
|
||||
|
||||
uint32_t data[SizeWords];
|
||||
|
||||
template<typename T>
|
||||
static constexpr T words_to_sectors(T size) {
|
||||
return (size + static_cast<T>(DataSector::SizeWords - 1))/static_cast<T>(DataSector::SizeWords);
|
||||
}
|
||||
};
|
||||
|
||||
struct FileInfo {
|
||||
uint16_t lba;
|
||||
uint16_t sectors;
|
||||
|
||||
static constexpr FileInfo from(const AutoLBAEntry& entry) {
|
||||
return FileInfo{entry.lba, DataSector::words_to_sectors(entry.size_words)};
|
||||
}
|
||||
};
|
||||
|
||||
class SectorBufferAllocator {
|
||||
private:
|
||||
typedef 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);
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
// Only for now
|
||||
const auto lba = file_info.lba + 2*MaxSector;
|
||||
return CDTimeStamp::from(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