Set mode and improve on allocation callback
This commit is contained in:
parent
672ad04c83
commit
6febdae88e
|
@ -109,6 +109,7 @@ namespace JabyEngine {
|
||||||
|
|
||||||
static constexpr Info GetStat{0x1, Interrupt::Type::Acknowledge};
|
static constexpr Info GetStat{0x1, Interrupt::Type::Acknowledge};
|
||||||
static constexpr Info Init{0xA, Interrupt::Type::Complete};
|
static constexpr Info Init{0xA, Interrupt::Type::Complete};
|
||||||
|
static constexpr Info SetMode{0xE, Interrupt::Type::Acknowledge};
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto IORegister1Adr = 0x1F801801;
|
static constexpr auto IORegister1Adr = 0x1F801801;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef __JABYENGINE_CD_INTERNAL_HPP__
|
#ifndef __JABYENGINE_CD_INTERNAL_HPP__
|
||||||
#define __JABYENGINE_CD_INTERNAL_HPP__
|
#define __JABYENGINE_CD_INTERNAL_HPP__
|
||||||
#include <PSX/System/IOPorts/cd_io.hpp>
|
#include <PSX/System/IOPorts/cd_io.hpp>
|
||||||
|
#include <PSX/AutoLBA/auto_lba.hpp>
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace CD {
|
namespace CD {
|
||||||
|
@ -14,53 +15,46 @@ namespace JabyEngine {
|
||||||
Error,
|
Error,
|
||||||
};
|
};
|
||||||
|
|
||||||
extern VolatilePOD<CD_IO::Interrupt::Type> last_interrupt;
|
struct DataSector {
|
||||||
extern VolatilePOD<State> state;
|
static constexpr size_t SizeBytes = 2048;
|
||||||
|
static constexpr size_t SizeWords = (SizeBytes/sizeof(uint32_t));
|
||||||
|
|
||||||
struct Sector {
|
uint32_t data[SizeWords];
|
||||||
uint32_t data[512];
|
|
||||||
|
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 {
|
struct FileInfo {
|
||||||
uint16_t lba;
|
uint16_t lba;
|
||||||
uint16_t sectors;
|
uint16_t sectors;
|
||||||
|
|
||||||
constexpr FileInfo(uint16_t lba, uint16_t sectors) : lba(lba), sectors(sectors) {
|
static constexpr FileInfo from_auto_lba(const AutoLBAEntry& entry) {
|
||||||
|
return FileInfo{entry.lba, DataSector::words_to_sectors(entry.size_words)};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SectorBufferAllocator {
|
class SectorBufferAllocator {
|
||||||
private:
|
private:
|
||||||
struct Dummy {
|
typedef DataSector* (*AllocatorFunction)(void* ctx);
|
||||||
};
|
|
||||||
|
|
||||||
typedef Sector* (*SimpleAllocator)();
|
|
||||||
typedef Sector* (Dummy::*ComplexAllocator)();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Dummy* this_ctx = nullptr;
|
void* ctx = nullptr;
|
||||||
union {
|
AllocatorFunction allocate = nullptr;
|
||||||
SimpleAllocator allocate;
|
|
||||||
ComplexAllocator this_allocate;
|
|
||||||
};
|
|
||||||
|
|
||||||
SectorBufferAllocator(SimpleAllocator allocate) : this_ctx(nullptr), allocate(allocate) {
|
constexpr SectorBufferAllocator(void* ctx, AllocatorFunction function) : ctx(ctx), allocate(function) {
|
||||||
}
|
|
||||||
|
|
||||||
SectorBufferAllocator(Dummy* ctx, ComplexAllocator this_allocate) : this_ctx(ctx), this_allocate(this_allocate) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static SectorBufferAllocator create(SimpleAllocator allocate) {
|
static constexpr SectorBufferAllocator create(void* obj, AllocatorFunction function) {
|
||||||
return SectorBufferAllocator(allocate);
|
return SectorBufferAllocator(obj, function);
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static SectorBufferAllocator create(T &obj, Sector* (T::*obj_allocate)()) {
|
|
||||||
return SectorBufferAllocator(reinterpret_cast<Dummy*>(&obj), reinterpret_cast<ComplexAllocator>(obj_allocate));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern VolatilePOD<CD_IO::Interrupt::Type> last_interrupt;
|
||||||
|
|
||||||
struct Command {
|
struct Command {
|
||||||
static void wait_until(CD_IO::Interrupt::Type irq) {
|
static void wait_until(CD_IO::Interrupt::Type irq) {
|
||||||
while(last_interrupt.read() != irq);
|
while(last_interrupt.read() != irq);
|
||||||
|
@ -81,7 +75,7 @@ namespace JabyEngine {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
State start_reading(FileInfo file_info, const SectorBufferAllocator& buffer_allocator);
|
State read_file(FileInfo file_info, const SectorBufferAllocator& buffer_allocator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,19 @@
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace CD {
|
namespace CD {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
VolatilePOD<CD_IO::Interrupt::Type> last_interrupt{CD_IO::Interrupt::Type::None};
|
struct Mode : public ComplexBitMap<uint8_t> {
|
||||||
|
static constexpr auto DoubleSpeed = Bit<uint8_t>(7);
|
||||||
|
static constexpr auto SingleSpeed = !DoubleSpeed;
|
||||||
|
static constexpr auto XADPCM = Bit<uint8_t>(6);
|
||||||
|
static constexpr auto WholeSector = Bit<uint8_t>(5);
|
||||||
|
static constexpr auto DataSector = !WholeSector;
|
||||||
|
static constexpr auto UseXAFilter = Bit<uint8_t>(3);
|
||||||
|
static constexpr auto AudioPlayIRQ = Bit<uint8_t>(2);
|
||||||
|
static constexpr auto AutoPauseTrack = Bit<uint8_t>(1);
|
||||||
|
static constexpr auto CDDA = Bit<uint8_t>(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
static constexpr auto DataSectorMode = Mode::with(Mode::DoubleSpeed, Mode::DataSector);
|
||||||
|
|
||||||
static InterruptVerifierResult interrupt_verifier() {
|
static InterruptVerifierResult interrupt_verifier() {
|
||||||
if(Interrupt::is_irq(Interrupt::CDROM)) {
|
if(Interrupt::is_irq(Interrupt::CDROM)) {
|
||||||
|
@ -32,14 +44,18 @@ namespace JabyEngine {
|
||||||
__syscall_ReturnFromException();
|
__syscall_ReturnFromException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VolatilePOD<CD_IO::Interrupt::Type> last_interrupt{CD_IO::Interrupt::Type::None};
|
||||||
InterrupCallback callback = {
|
InterrupCallback callback = {
|
||||||
.next = nullptr,
|
.next = nullptr,
|
||||||
.handler_function = reinterpret_cast<InterruptHandler>(interrupt_handler),
|
.handler_function = reinterpret_cast<InterruptHandler>(interrupt_handler),
|
||||||
.verifier_function = interrupt_verifier
|
.verifier_function = interrupt_verifier
|
||||||
};
|
};
|
||||||
|
|
||||||
State start_reading(FileInfo file_info, const SectorBufferAllocator& buffer_allocator) {
|
State read_file(FileInfo file_info, const SectorBufferAllocator& buffer_allocator) {
|
||||||
printf("I'm not implemented! %s\n", __FUNCTION__);
|
CD_IO::PortIndex0::change_to();
|
||||||
|
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::SetMode, DataSectorMode);
|
||||||
|
|
||||||
|
printf("I'm not fully implemented! %s\n", __FUNCTION__);
|
||||||
return State::Error;
|
return State::Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,19 @@
|
||||||
#include <PSX/File/Processor/cd_file_processor.hpp>
|
#include <PSX/File/Processor/cd_file_processor.hpp>
|
||||||
|
#include <CD/cd_internal.hpp>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
void CDFileProcessor :: start_cur_job() {
|
void CDFileProcessor :: start_cur_job() {
|
||||||
|
using CD::internal::FileInfo;
|
||||||
|
using CD::internal::SectorBufferAllocator;
|
||||||
|
|
||||||
const auto& cur_lba = this->lba[this->jobs.files->rel_lba_idx];
|
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* {
|
||||||
|
printf("Blubb?!\n");
|
||||||
|
return nullptr;
|
||||||
|
}));
|
||||||
|
|
||||||
printf(">>> CD needs to load LBA: %i -> %i\n", cur_lba.lba, cur_lba.size_words);
|
printf(">>> CD needs to load LBA: %i -> %i\n", cur_lba.lba, cur_lba.size_words);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue