Support Push/Pop in DS

This commit is contained in:
2024-06-01 16:37:00 +02:00
parent 658eed7b46
commit 7dbc829fe8
6 changed files with 98 additions and 41 deletions

View File

@@ -50,8 +50,8 @@ namespace JabyEngine {
};
namespace IRQ {
void read_sector_to(uint32_t* dst, size_t bytes);
void resume_at(const BCDTimeStamp& cd_time);
void read_sector_to0(uint32_t* dst, size_t bytes);
void resume_at0(const BCDTimeStamp& cd_time);
}
static State read_current_state() {
@@ -67,6 +67,7 @@ namespace JabyEngine {
void enable_CDXA(bool double_speed);
static void pause() {
CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Pause);
}
}

View File

@@ -18,9 +18,11 @@ namespace JabyEngine {
case CD_IO::Interrupt::DataReady: {
// The IRQ stack is 0x1000 bytes large so this should fit
CD::RawXADataSector xa_file;
CD::IRQ::read_sector_to(reinterpret_cast<uint32_t*>(&xa_file), sizeof(CD::RawXADataSector));
CD_IO::PortIndex0::change_to();
CD::IRQ::read_sector_to0(reinterpret_cast<uint32_t*>(&xa_file), sizeof(CD::RawXADataSector));
if(setting.channel == xa_file.sub_header.channel_number) {
CD::IRQ::resume_at(setting.start_loc);
CD::IRQ::resume_at0(setting.start_loc);
CD::Command::send<CD_IO::PortIndex0>(CD_IO::Command::ReadS);
}
} break;
@@ -35,7 +37,8 @@ namespace JabyEngine {
setting.start_loc = CD::BCDTimeStamp::from(lba[rel_lba_idx].get_lba());
setting.double_speed = double_speed;
CD::enable_CDXA(double_speed);
CD::current_state = CD::State::XAMode;
CD::enable_CDXA(double_speed); //< Activates PortIndex0
set_channel(channel);
CD::Command::wait_completed();
CD::Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector);
@@ -43,13 +46,13 @@ namespace JabyEngine {
}
void stop() {
// TODO: Alias this?
CD::pause();
}
void set_channel(uint8_t channel) {
static constexpr uint8_t File = 1;
CD_IO::PortIndex0::change_to();
CD::Command::send<CD_IO::PortIndex0>(CD_IO::Command::Filter, File, channel);
setting.channel = channel;
}
@@ -61,7 +64,8 @@ namespace JabyEngine {
void pop_play() {
CD::Command::wait_completed();
CD::enable_CDXA(setting.double_speed);
CD::current_state = CD::State::XAMode;
CD::enable_CDXA(setting.double_speed); //< Activates PortIndex0
set_channel(setting.channel);
CD::Command::wait_completed();

View File

@@ -40,12 +40,12 @@ namespace JabyEngine {
__debug_boot_color_at(::JabyEngine::GPU::Color24::Red(), DebugX, DebugY, DebugScale);
CD_IO::PortIndex0::change_to();
__debug_boot_color_at(::JabyEngine::GPU::Color24::Green(), DebugX, DebugY, DebugScale);
/* __debug_boot_color_at(::JabyEngine::GPU::Color24::Green(), DebugX, DebugY, DebugScale);
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::GetStat);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Blue(), DebugX, DebugY, DebugScale);
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::GetStat);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Yellow(), DebugX, DebugY, DebugScale);
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::Init);
Command::send_wait(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, CD_IO::Command::Init);*/
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Demute);
}

View File

@@ -46,21 +46,21 @@ namespace JabyEngine {
.verifier_function = IRQ::verifier
};
static BCDTimeStamp send_read_cmd(uint32_t lba, CD_IO::Command::Desc desc) {
const auto loc = BCDTimeStamp::from(lba);
static BCDTimeStamp send_read_cmd0(uint32_t lba, CD_IO::Command::Desc desc) {
const auto loc = BCDTimeStamp::from(lba);
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector);
Command::send<CD_IO::PortIndex0>(desc);
return loc;
}
static void send_read_n(uint32_t lba) {
send_read_cmd(lba, CD_IO::Command::ReadN);
static void send_read_n0(uint32_t lba) {
send_read_cmd0(lba, CD_IO::Command::ReadN);
current_state = State::Reading;
}
namespace IRQ {
static void read_sector_dma(uint32_t* dst, size_t bytes) {
static void read_sector_dma0(uint32_t* dst, size_t bytes) {
static const auto WaitSectorReady = []() {
while(!CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::HasDataFifoData));
};
@@ -79,23 +79,22 @@ namespace JabyEngine {
ReadSector(dst, bytes);
}
void read_sector_to(uint32_t* dst, size_t bytes) {
void read_sector_to0(uint32_t* dst, size_t bytes) {
CD_IO::PortIndex0::Request.write(CD_IO::Request::want_data());
// We only support DMA rn
read_sector_dma(dst, bytes);
read_sector_dma0(dst, bytes);
// Do we ever want to support reading via IO Port?
// Doesn't seem to important when we can use DMA
}
void resume_at(const BCDTimeStamp& cd_time) {
void resume_at0(const BCDTimeStamp& cd_time) {
Command::send<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector);
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();
}
@@ -128,7 +127,7 @@ namespace JabyEngine {
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to(sector->data, CD_IO::DataSector::SizeBytes);
read_sector_to0(sector->data, CD_IO::DataSector::SizeBytes);
if(cur_file.done_processing()) {
current_state = State::Done;
@@ -144,7 +143,7 @@ namespace JabyEngine {
case CD_IO::Interrupt::DataEnd: {
// TODO: Fix this!! This is a freaking static time
resume_at(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0});
resume_at0(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0});
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play);
} break;
@@ -172,38 +171,40 @@ namespace JabyEngine {
sector_allocator = buffer_allocator;
Command::wait_completed();
CD_IO::PortIndex0::change_to();
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, DataSectorMode);
send_read_n(cur_file.cur_lba);
send_read_n0(cur_file.cur_lba);
}
void continue_reading() {
if(current_state == State::BufferFull) {
Command::wait_completed();
send_read_n(cur_file.cur_lba);
CD_IO::PortIndex0::change_to();
send_read_n0(cur_file.cur_lba);
}
}
BCDTimeStamp get_loc() {
Command::wait_completed();
CD_IO::PortIndex0::change_to();
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::GetLocP);
const auto track = CD_IO::PortIndex0::ResponseFifo.read().raw; // track number (AAh=Lead-out area) (FFh=unknown, toc, none?)
const auto index = CD_IO::PortIndex0::ResponseFifo.read().raw; // index number (Usually 01h)
const auto mm = CD_IO::PortIndex0::ResponseFifo.read().raw; // minute number within track (00h and up)
const auto ss = CD_IO::PortIndex0::ResponseFifo.read().raw; // second number within track (00h to 59h)
const auto sect = CD_IO::PortIndex0::ResponseFifo.read().raw; // sector number within track (00h to 74h)
const auto track = CD_IO::PortIndex0::ResponseFifo.read().raw; // track number (AAh=Lead-out area) (FFh=unknown, toc, none?)
const auto index = CD_IO::PortIndex0::ResponseFifo.read().raw; // index number (Usually 01h)
const auto mm = CD_IO::PortIndex0::ResponseFifo.read().raw; // minute number within track (00h and up)
const auto ss = CD_IO::PortIndex0::ResponseFifo.read().raw; // second number within track (00h to 59h)
const auto sect = CD_IO::PortIndex0::ResponseFifo.read().raw; // sector number within track (00h to 74h)
return BCDTimeStamp::from_time(
CD_IO::PortIndex0::ResponseFifo.read().raw, // minute number on entire disk (00h and up)
CD_IO::PortIndex0::ResponseFifo.read().raw, // second number on entire disk (00h to 59h)
CD_IO::PortIndex0::ResponseFifo.read().raw // sector number on entire disk (00h to 74h)
);
const auto min = CD_IO::PortIndex0::ResponseFifo.read().raw; // minute number on entire disk (00h and up)
const auto sec = CD_IO::PortIndex0::ResponseFifo.read().raw; // second number on entire disk (00h to 59h)
const auto sectors = CD_IO::PortIndex0::ResponseFifo.read().raw; // sector number on entire disk (00h to 74h)
return BCDTimeStamp{min, sec, sectors};
}
void enable_CDDA() {
Command::wait_completed();
CD_IO::PortIndex0::change_to();
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, AudioSectorMode);
}
@@ -214,8 +215,8 @@ namespace JabyEngine {
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);
current_state = State::XAMode;
}
}
}