CDXA not working
This commit is contained in:
@@ -45,7 +45,16 @@ namespace JabyEngine {
|
||||
void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator);
|
||||
void continue_reading();
|
||||
|
||||
void read_n(uint32_t lba);
|
||||
void read_s(uint32_t lba);
|
||||
|
||||
void enable_CDDA();
|
||||
void enable_CDXA(bool double_speed);
|
||||
|
||||
static void pause() {
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,8 +8,8 @@ namespace JabyEngine {
|
||||
namespace CD {
|
||||
namespace internal {
|
||||
enum struct State {
|
||||
Free = 0,
|
||||
Done = 0,
|
||||
Ready = 0,
|
||||
Done = 0,
|
||||
|
||||
Reading,
|
||||
BufferFull,
|
||||
|
@@ -38,8 +38,7 @@ namespace JabyEngine {
|
||||
}
|
||||
|
||||
void stop() {
|
||||
CD::Command::wait_completed();
|
||||
CD::Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
|
||||
CD::pause();
|
||||
}
|
||||
|
||||
void push_play() {
|
||||
|
20
src/Library/src/Audio/CDXA.cpp
Normal file
20
src/Library/src/Audio/CDXA.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "../../internal-include/CD/cd_internal.hpp"
|
||||
#include <PSX/Audio/CDXA.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace CDXA {
|
||||
namespace CD = JabyEngine::CD::internal;
|
||||
|
||||
void play(const volatile AutoLBAEntry* lba, const CDFile& file, uint8_t channel) {
|
||||
static constexpr uint8_t File = 0;
|
||||
|
||||
CD::enable_CDXA(false);
|
||||
CD::Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::Filter, File, channel);
|
||||
CD::read_s(lba[file.rel_lba_idx].get_lba());
|
||||
}
|
||||
|
||||
void stop() {
|
||||
CD::pause();
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,8 +7,9 @@
|
||||
namespace JabyEngine {
|
||||
namespace CD {
|
||||
namespace internal {
|
||||
static constexpr auto AudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::AutoPauseTrack, CD_IO::Mode::CDDA);
|
||||
static constexpr auto DataSectorMode = CD_IO::Mode::from(CD_IO::Mode::DoubleSpeed, CD_IO::Mode::DataSector);
|
||||
static constexpr auto AudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::AutoPauseTrack, CD_IO::Mode::CDDA);
|
||||
static constexpr auto DataSectorMode = CD_IO::Mode::from(CD_IO::Mode::DoubleSpeed, CD_IO::Mode::DataSector);
|
||||
static constexpr auto XAAudioSectorMode = CD_IO::Mode::from(CD_IO::Mode::SingleSpeed, CD_IO::Mode::XADPCM, CD_IO::Mode::WholeSector, CD_IO::Mode::UseXAFilter);
|
||||
|
||||
static SysCall::InterruptVerifierResult interrupt_verifier();
|
||||
static uint32_t interrupt_handler(uint32_t);
|
||||
@@ -18,25 +19,21 @@ namespace JabyEngine {
|
||||
static uint32_t dst_lba;
|
||||
|
||||
uint8_t cmd_interrupt_bit = 0;
|
||||
State current_state = State::Free;
|
||||
State current_state = State::Ready;
|
||||
SysCall::InterrupCallback callback = {
|
||||
.next = nullptr,
|
||||
.handler_function = interrupt_handler,
|
||||
.verifier_function = interrupt_verifier
|
||||
};
|
||||
|
||||
static void pause_cd() {
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
|
||||
}
|
||||
|
||||
// Requires Index0
|
||||
static void read_cd(uint32_t lba) {
|
||||
static void read_cd(uint32_t lba, CD_IO::Command::Desc desc) {
|
||||
const auto loc = CDTimeStamp::from(lba);
|
||||
|
||||
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, loc.get_min_cd(), loc.get_sec_cd(), loc.get_sector_cd());
|
||||
Command::send<CD_IO::PortIndex0>(CD_IO::Command::ReadN);
|
||||
Command::send<CD_IO::PortIndex0>(desc);
|
||||
current_state = State::Reading;
|
||||
printf("Done??\n");
|
||||
}
|
||||
|
||||
static void read_sector_dma(CD_IO::DataSector& sector) {
|
||||
@@ -87,42 +84,49 @@ namespace JabyEngine {
|
||||
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
|
||||
|
||||
cmd_interrupt_bit = bit::clear(cmd_interrupt_bit, cur_irq);
|
||||
switch(cur_irq) {
|
||||
case CD_IO::Interrupt::DataReady: {
|
||||
// Obtain sector content here
|
||||
auto* sector = sector_allocator.allocate_sector();
|
||||
if(sector) {
|
||||
//Now obtain sector
|
||||
read_sector_to(*sector);
|
||||
|
||||
cur_lba++;
|
||||
if(cur_lba == dst_lba) {
|
||||
current_state = State::Done;
|
||||
pause_cd();
|
||||
if(!CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::HasXAFifoData)) {
|
||||
switch(cur_irq) {
|
||||
case CD_IO::Interrupt::DataReady: {
|
||||
// Obtain sector content here
|
||||
auto* sector = sector_allocator.allocate_sector();
|
||||
if(sector) {
|
||||
//Now obtain sector
|
||||
read_sector_to(*sector);
|
||||
|
||||
cur_lba++;
|
||||
if(cur_lba == dst_lba) {
|
||||
current_state = State::Done;
|
||||
pause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
current_state = State::BufferFull;
|
||||
pause_cd();
|
||||
}
|
||||
} break;
|
||||
else {
|
||||
current_state = State::BufferFull;
|
||||
pause();
|
||||
}
|
||||
} break;
|
||||
|
||||
case CD_IO::Interrupt::DataEnd: {
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, static_cast<uint8_t>(0x0), static_cast<uint8_t>(0x09), static_cast<uint8_t>(0x0));
|
||||
case CD_IO::Interrupt::DataEnd: {
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, static_cast<uint8_t>(0x0), static_cast<uint8_t>(0x09), static_cast<uint8_t>(0x0));
|
||||
|
||||
CD_IO::PortIndex1::change_to();
|
||||
while(CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag) != CD_IO::Interrupt::Acknowledge);
|
||||
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
|
||||
CD_IO::PortIndex1::change_to();
|
||||
while(CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag) != CD_IO::Interrupt::Acknowledge);
|
||||
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
|
||||
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play);
|
||||
} break;
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play);
|
||||
} break;
|
||||
|
||||
case CD_IO::Interrupt::DiskError: {
|
||||
current_state = State::Error;
|
||||
} break;
|
||||
case CD_IO::Interrupt::DiskError: {
|
||||
current_state = State::Error;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
printf("Playing CDXA\n");
|
||||
}
|
||||
|
||||
// No masking required because we can only write bit 0 - 2
|
||||
@@ -141,21 +145,41 @@ namespace JabyEngine {
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, DataSectorMode);
|
||||
|
||||
read_cd(cur_lba);
|
||||
read_n(cur_lba);
|
||||
}
|
||||
|
||||
void continue_reading() {
|
||||
if(current_state == State::BufferFull) {
|
||||
Command::wait_completed();
|
||||
read_cd(cur_lba);
|
||||
read_n(cur_lba);
|
||||
}
|
||||
}
|
||||
|
||||
void read_n(uint32_t lba) {
|
||||
read_cd(lba, CD_IO::Command::ReadN);
|
||||
}
|
||||
|
||||
void read_s(uint32_t lba) {
|
||||
printf("Now ReadS %i\n", lba);
|
||||
read_cd(lba, CD_IO::Command::ReadS);
|
||||
}
|
||||
|
||||
void enable_CDDA() {
|
||||
Command::wait_completed();
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, AudioSectorMode);
|
||||
}
|
||||
|
||||
void enable_CDXA(bool double_speed) {
|
||||
static constexpr uint8_t SingleSpeedBit = 0x0;
|
||||
static constexpr uint8_t DoubleSpeedBit = static_cast<uint8_t>(CD_IO::Mode::DoubleSpeed);
|
||||
|
||||
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit);
|
||||
|
||||
Command::wait_completed();
|
||||
CD_IO::PortIndex0::change_to();
|
||||
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user