Set mode and improve on allocation callback

This commit is contained in:
Jaby 2023-02-18 10:56:46 +01:00
parent 26cd4bd4c4
commit d2fe06eef4
4 changed files with 50 additions and 30 deletions

View File

@ -109,6 +109,7 @@ namespace JabyEngine {
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 auto IORegister1Adr = 0x1F801801;

View File

@ -1,6 +1,7 @@
#ifndef __JABYENGINE_CD_INTERNAL_HPP__
#define __JABYENGINE_CD_INTERNAL_HPP__
#include <PSX/System/IOPorts/cd_io.hpp>
#include <PSX/AutoLBA/auto_lba.hpp>
namespace JabyEngine {
namespace CD {
@ -14,53 +15,46 @@ namespace JabyEngine {
Error,
};
extern VolatilePOD<CD_IO::Interrupt::Type> last_interrupt;
extern VolatilePOD<State> state;
struct DataSector {
static constexpr size_t SizeBytes = 2048;
static constexpr size_t SizeWords = (SizeBytes/sizeof(uint32_t));
struct Sector {
uint32_t data[512];
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;
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 {
private:
struct Dummy {
};
typedef Sector* (*SimpleAllocator)();
typedef Sector* (Dummy::*ComplexAllocator)();
typedef DataSector* (*AllocatorFunction)(void* ctx);
private:
Dummy* this_ctx = nullptr;
union {
SimpleAllocator allocate;
ComplexAllocator this_allocate;
};
void* ctx = nullptr;
AllocatorFunction allocate = nullptr;
SectorBufferAllocator(SimpleAllocator allocate) : this_ctx(nullptr), allocate(allocate) {
}
SectorBufferAllocator(Dummy* ctx, ComplexAllocator this_allocate) : this_ctx(ctx), this_allocate(this_allocate) {
constexpr SectorBufferAllocator(void* ctx, AllocatorFunction function) : ctx(ctx), allocate(function) {
}
public:
static SectorBufferAllocator create(SimpleAllocator allocate) {
return SectorBufferAllocator(allocate);
}
template<typename T>
static SectorBufferAllocator create(T &obj, Sector* (T::*obj_allocate)()) {
return SectorBufferAllocator(reinterpret_cast<Dummy*>(&obj), reinterpret_cast<ComplexAllocator>(obj_allocate));
static constexpr SectorBufferAllocator create(void* obj, AllocatorFunction function) {
return SectorBufferAllocator(obj, function);
}
};
extern VolatilePOD<CD_IO::Interrupt::Type> last_interrupt;
struct Command {
static void wait_until(CD_IO::Interrupt::Type 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);
}
}
}

View File

@ -7,7 +7,19 @@
namespace JabyEngine {
namespace CD {
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() {
if(Interrupt::is_irq(Interrupt::CDROM)) {
@ -32,14 +44,18 @@ namespace JabyEngine {
__syscall_ReturnFromException();
}
VolatilePOD<CD_IO::Interrupt::Type> last_interrupt{CD_IO::Interrupt::Type::None};
InterrupCallback callback = {
.next = nullptr,
.handler_function = reinterpret_cast<InterruptHandler>(interrupt_handler),
.verifier_function = interrupt_verifier
};
State start_reading(FileInfo file_info, const SectorBufferAllocator& buffer_allocator) {
printf("I'm not implemented! %s\n", __FUNCTION__);
State read_file(FileInfo file_info, const SectorBufferAllocator& buffer_allocator) {
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;
}
}

View File

@ -1,10 +1,19 @@
#include <PSX/File/Processor/cd_file_processor.hpp>
#include <CD/cd_internal.hpp>
#include <stdio.h>
namespace JabyEngine {
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];
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);
}