Simulated load of a file
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
#ifndef __JABYENGINE_CD_INTERNAL_HPP__
|
||||
#define __JABYENGINE_CD_INTERNAL_HPP__
|
||||
#include "cd_types.hpp"
|
||||
#include <PSX/System/IOPorts/cd_io.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace CD {
|
||||
namespace internal {
|
||||
extern VolatilePOD<CD_IO::Interrupt::Type> last_interrupt;
|
||||
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(last_interrupt.read() != irq);
|
||||
while(read_last_interrupt() != irq);
|
||||
}
|
||||
|
||||
template<typename...ARGS>
|
||||
@@ -38,7 +46,7 @@ namespace JabyEngine {
|
||||
}
|
||||
};
|
||||
|
||||
State read_file(FileInfo file_info, const SectorBufferAllocator& buffer_allocator);
|
||||
void read_file(FileInfo file_info, const SectorBufferAllocator& buffer_allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#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 {
|
||||
@@ -16,30 +17,18 @@ namespace JabyEngine {
|
||||
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)};
|
||||
return FileInfo{entry.lba, CD_IO::DataSector::words_to_sectors(entry.size_words)};
|
||||
}
|
||||
};
|
||||
|
||||
class SectorBufferAllocator {
|
||||
private:
|
||||
typedef DataSector* (*AllocatorFunction)(void* ctx);
|
||||
typedef CD_IO::DataSector* (*AllocatorFunction)(void* ctx);
|
||||
|
||||
private:
|
||||
void* ctx = nullptr;
|
||||
@@ -54,6 +43,10 @@ namespace JabyEngine {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user