Code ready to obtain data; Doesn't work in No and causes strange errors in DS

This commit is contained in:
Jaby 2023-03-26 16:42:45 +02:00
parent 932824a68f
commit 2582d6ea21
6 changed files with 51 additions and 12 deletions

View File

@ -52,6 +52,14 @@ namespace JabyEngine {
__declare_io_type(Request, uint8_t, __declare_io_type(Request, uint8_t,
static constexpr auto WantCommandStartIRQ = Bit(5); static constexpr auto WantCommandStartIRQ = Bit(5);
static constexpr auto WantData = Bit(7); static constexpr auto WantData = Bit(7);
void want_data() {
this->raw_value = Self::set(Self::WantData);
}
void reset() {
this->raw_value = 0;
}
); );
__declare_io_type(SoundMapCoding, uint8_t, __declare_io_type(SoundMapCoding, uint8_t,

View File

@ -12,6 +12,11 @@ namespace JabyEngine {
struct SyncMode0 { struct SyncMode0 {
static constexpr auto NumberOfWords = BitRange::from_to(0, 15); static constexpr auto NumberOfWords = BitRange::from_to(0, 15);
static constexpr auto CD_OneBlock = Bit(16); static constexpr auto CD_OneBlock = Bit(16);
static constexpr Self for_cd() {
// v Should be replaced with a named constant
return Self::from(SyncMode0::CD_OneBlock, SyncMode0::NumberOfWords.with(512));
}
}; };
struct SyncMode1 { struct SyncMode1 {

View File

@ -25,11 +25,10 @@ namespace JabyEngine {
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
CD_IO::Interrupt::enable(CD_IO::PortIndex1::InterruptEnable); CD_IO::Interrupt::enable(CD_IO::PortIndex1::InterruptEnable);
Interrupt::ack_irq(Interrupt::CDROM);
Interrupt::enable_irq(Interrupt::CDROM); Interrupt::enable_irq(Interrupt::CDROM);
Interrupt::ack_irq(Interrupt::CDROM);
__syscall_ExitCriticalSection(); __syscall_ExitCriticalSection();
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::GetStat); Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::GetStat);

View File

@ -7,10 +7,10 @@
namespace JabyEngine { namespace JabyEngine {
namespace boot { namespace boot {
namespace Start { namespace Start {
//This should become part of the bootloader later
static void enable_DMA() { static void enable_DMA() {
const auto dpcr = DMA_IO::DPCR_t(DMA_IO::DPCR).set(DMA_IO::DPCR_t::SPUEnable).set(DMA_IO::DPCR_t::GPUEnable); DMA_IO::DPCR = DMA_IO::DPCR_t(DMA_IO::DPCR).set(DMA_IO::DPCR_t::SPUEnable).set(DMA_IO::DPCR_t::GPUEnable).set(DMA_IO::DPCR_t::CDROMEnable);
DMA_IO::DPCR = dpcr;
} }
JabyEngine::NextRoutine setup() { JabyEngine::NextRoutine setup() {

View File

@ -1,4 +1,5 @@
#include "../../internal-include/CD/cd_internal.hpp" #include "../../internal-include/CD/cd_internal.hpp"
#include <PSX/System/IOPorts/dma_io.hpp>
#include <PSX/System/IOPorts/interrupt_io.hpp> #include <PSX/System/IOPorts/interrupt_io.hpp>
#include <PSX/System/syscalls.h> #include <PSX/System/syscalls.h>
@ -24,6 +25,36 @@ namespace JabyEngine {
static SectorBufferAllocator sector_allocator; static SectorBufferAllocator sector_allocator;
static uint16_t sectors_left; static uint16_t sectors_left;
static void read_sector_dma(CD_IO::DataSector& sector) {
static const auto WaitSectorReady = []() {
while(!CD_IO::IndexStatus.is_set(CD_IO::IndexStatus_t::HasDataFifoData));
};
static const auto ReadSector = [](uint32_t* dst) {
DMA_IO::CDROM.set_adr(reinterpret_cast<uintptr_t>(dst));
DMA_IO::CDROM.block_ctrl = DMA_IO::BCR_t::SyncMode0::for_cd();
DMA_IO::CDROM.channel_ctrl = DMA_IO::CHCHR_t::StartCDROM();
DMA_IO::CDROM.wait();
CD_IO::PortIndex0::Request.reset();
};
WaitSectorReady();
ReadSector(sector.data);
}
static void read_sector_to(CD_IO::DataSector& sector) {
CD_IO::PortIndex0::change_to();
CD_IO::PortIndex0::Request.want_data();
// We only support DMA rn
read_sector_dma(sector);
// Do we ever want to support reading via IO Port?
// Doesn't seem to important when we can use DMA
}
static InterruptVerifierResult interrupt_verifier() { static InterruptVerifierResult interrupt_verifier() {
static const auto pause = []() { static const auto pause = []() {
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
@ -43,12 +74,7 @@ namespace JabyEngine {
auto* sector = sector_allocator.allocate_sector(); auto* sector = sector_allocator.allocate_sector();
if(sector) { if(sector) {
//Now obtain sector //Now obtain sector
static const char SimpleStr[] = "CD-Drive: This is a test string"; //read_sector_to(*sector);
char* test_str = reinterpret_cast<char*>(sector->data);
for(size_t n = 0; n < sizeof(SimpleStr); n++) {
test_str[n] = SimpleStr[n];
}
sectors_left--; sectors_left--;
if(sectors_left == 0) { if(sectors_left == 0) {
@ -102,7 +128,7 @@ namespace JabyEngine {
current_state = State::Reading; current_state = State::Reading;
printf("Now reading: %i\n", file_info.lba); printf("Now reading: %i(%i:%i:%i)\n", file_info.lba, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd());
} }
} }
} }

View File

@ -54,6 +54,7 @@ namespace JabyEngine {
case CD::internal::State::Error: case CD::internal::State::Error:
// Error for real! // Error for real!
test_print();
return Progress::Error; return Progress::Error;
} }