Read files with temp fix

This commit is contained in:
Jaby
2023-02-19 18:00:19 +01:00
committed by Jaby
parent 6febdae88e
commit 4c0d591c81
7 changed files with 138 additions and 53 deletions

View File

@@ -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 {