Code ready to obtain data; Doesn't work in No and causes strange errors in DS
This commit is contained in:
parent
932824a68f
commit
2582d6ea21
|
@ -52,6 +52,14 @@ namespace JabyEngine {
|
|||
__declare_io_type(Request, uint8_t,
|
||||
static constexpr auto WantCommandStartIRQ = Bit(5);
|
||||
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,
|
||||
|
|
|
@ -12,6 +12,11 @@ namespace JabyEngine {
|
|||
struct SyncMode0 {
|
||||
static constexpr auto NumberOfWords = BitRange::from_to(0, 15);
|
||||
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 {
|
||||
|
|
|
@ -25,11 +25,10 @@ namespace JabyEngine {
|
|||
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
|
||||
CD_IO::Interrupt::enable(CD_IO::PortIndex1::InterruptEnable);
|
||||
|
||||
Interrupt::ack_irq(Interrupt::CDROM);
|
||||
Interrupt::enable_irq(Interrupt::CDROM);
|
||||
Interrupt::ack_irq(Interrupt::CDROM);
|
||||
__syscall_ExitCriticalSection();
|
||||
|
||||
|
||||
CD_IO::PortIndex0::change_to();
|
||||
|
||||
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::GetStat);
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
|
||||
namespace JabyEngine {
|
||||
namespace boot {
|
||||
namespace Start {
|
||||
namespace Start {
|
||||
//This should become part of the bootloader later
|
||||
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 = dpcr;
|
||||
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);
|
||||
}
|
||||
|
||||
JabyEngine::NextRoutine setup() {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "../../internal-include/CD/cd_internal.hpp"
|
||||
#include <PSX/System/IOPorts/dma_io.hpp>
|
||||
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
||||
#include <PSX/System/syscalls.h>
|
||||
|
||||
|
@ -24,6 +25,36 @@ namespace JabyEngine {
|
|||
static SectorBufferAllocator sector_allocator;
|
||||
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 const auto pause = []() {
|
||||
CD_IO::PortIndex0::change_to();
|
||||
|
@ -43,12 +74,7 @@ namespace JabyEngine {
|
|||
auto* sector = sector_allocator.allocate_sector();
|
||||
if(sector) {
|
||||
//Now obtain sector
|
||||
static const char SimpleStr[] = "CD-Drive: This is a test string";
|
||||
|
||||
char* test_str = reinterpret_cast<char*>(sector->data);
|
||||
for(size_t n = 0; n < sizeof(SimpleStr); n++) {
|
||||
test_str[n] = SimpleStr[n];
|
||||
}
|
||||
//read_sector_to(*sector);
|
||||
|
||||
sectors_left--;
|
||||
if(sectors_left == 0) {
|
||||
|
@ -102,7 +128,7 @@ namespace JabyEngine {
|
|||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ namespace JabyEngine {
|
|||
|
||||
case CD::internal::State::Error:
|
||||
// Error for real!
|
||||
test_print();
|
||||
return Progress::Error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue