Read files with temp fix
This commit is contained in:
parent
fa8c3ae822
commit
db5366f35b
|
@ -0,0 +1,18 @@
|
|||
#ifndef __JABYENGINE_MATH_HELPER_HPP__
|
||||
#define __JABYENGINE_MATH_HELPER_HPP__
|
||||
#include "types.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
template<typename T>
|
||||
static constexpr pair<T, T> div_and_mod(T value, T div) {
|
||||
const auto result = value/div;
|
||||
return {static_cast<T>(result), static_cast<T>(value - (result*div))};
|
||||
}
|
||||
|
||||
static constexpr uint8_t to_bcd(uint8_t value) {
|
||||
const auto [tenth, rest] = div_and_mod(value, static_cast<uint8_t>(10));
|
||||
return (tenth << 4 | rest);
|
||||
}
|
||||
}
|
||||
|
||||
#endif //!__JABYENGINE_MATH_HELPER_HPP__
|
|
@ -107,9 +107,11 @@ namespace JabyEngine {
|
|||
Interrupt::Type complete_irq;
|
||||
};
|
||||
|
||||
static constexpr Info GetStat{0x1, Interrupt::Type::Acknowledge};
|
||||
static constexpr Info Init{0xA, Interrupt::Type::Complete};
|
||||
static constexpr Info SetMode{0xE, Interrupt::Type::Acknowledge};
|
||||
static constexpr Info GetStat{0x01, Interrupt::Type::Acknowledge};
|
||||
static constexpr Info SetLoc{0x02, Interrupt::Type::Acknowledge};
|
||||
static constexpr Info ReadN{0x06, Interrupt::Type::DataReady};
|
||||
static constexpr Info Init{0x0A, Interrupt::Type::Complete};
|
||||
static constexpr Info SetMode{0x0E, Interrupt::Type::Acknowledge};
|
||||
};
|
||||
|
||||
static constexpr auto IORegister1Adr = 0x1F801801;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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__
|
|
@ -20,14 +20,22 @@ namespace JabyEngine {
|
|||
};
|
||||
|
||||
static constexpr auto DataSectorMode = Mode::with(Mode::DoubleSpeed, Mode::DataSector);
|
||||
|
||||
static SectorBufferAllocator sector_allocator;
|
||||
static uint16_t sectors_left;
|
||||
|
||||
static InterruptVerifierResult interrupt_verifier() {
|
||||
if(Interrupt::is_irq(Interrupt::CDROM)) {
|
||||
const uint8_t old_idx = (CD_IO::IndexStatus.read() & 0x3);
|
||||
|
||||
CD_IO::PortIndex1::change_to();
|
||||
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlagRegister);
|
||||
|
||||
last_interrupt.write(CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlagRegister));
|
||||
if(cur_irq == CD_IO::Interrupt::DataReady) {
|
||||
printf("CDDrive: Got data!\n");
|
||||
}
|
||||
|
||||
last_interrupt.write(cur_irq);
|
||||
CD_IO::Interrupt::ack(CD_IO::PortIndex1::InterruptFlagRegister);
|
||||
|
||||
CD_IO::IndexStatus.write({old_idx});
|
||||
|
@ -52,9 +60,17 @@ namespace JabyEngine {
|
|||
};
|
||||
|
||||
State read_file(FileInfo file_info, const SectorBufferAllocator& buffer_allocator) {
|
||||
sector_allocator = buffer_allocator;
|
||||
sectors_left = file_info.sectors;
|
||||
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::SetMode, DataSectorMode);
|
||||
|
||||
const auto loc = CDTimeStamp::from(file_info);
|
||||
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::SetLoc, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd());
|
||||
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::ReadN);
|
||||
|
||||
printf("Now reading: %i\n", file_info.lba);
|
||||
printf("I'm not fully implemented! %s\n", __FUNCTION__);
|
||||
return State::Error;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace JabyEngine {
|
|||
|
||||
const auto& cur_lba = this->lba[this->jobs.files->rel_lba_idx];
|
||||
|
||||
CD::internal::read_file(FileInfo::from_auto_lba(cur_lba), SectorBufferAllocator::create(this, [](void* ctx) -> CD::internal::DataSector* {
|
||||
CD::internal::read_file(FileInfo::from(cur_lba), SectorBufferAllocator::create(this, [](void* ctx) -> CD::internal::DataSector* {
|
||||
printf("Blubb?!\n");
|
||||
return nullptr;
|
||||
}));
|
||||
|
|
|
@ -24,5 +24,6 @@ namespace JabyEngine {
|
|||
next_routine = execute(next_routine);
|
||||
}
|
||||
printf("Stop!\n");
|
||||
while(true);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue