Inital Cody-Fix

This commit is contained in:
Jaby 2024-06-13 07:54:09 +02:00
parent 60a2eedd82
commit c67bc7d9f9
5 changed files with 54 additions and 78 deletions

View File

@ -20,30 +20,20 @@ namespace JabyEngine {
}; };
extern State current_state; extern State current_state;
extern volatile uint8_t cmd_interrupt_bit;
extern uint8_t last_cmd;
struct Command { struct NewCommand {
struct Internal { struct Internal {
static void wait_completed(CD_IO::Interrupt::Type irq) { static void wait_completed(CD_IO::Interrupt::Type irq) {
while(!bit::is_set(cmd_interrupt_bit, irq));
}
static void wait_completed_irq(CD_IO::Interrupt::Type irq) {
static const auto get_next_irq = []() -> CD_IO::Interrupt::Type { static const auto get_next_irq = []() -> CD_IO::Interrupt::Type {
CD_IO::Interrupt::Type cur_irq; CD_IO::Interrupt::Type cur_irq = CD_IO::Interrupt::None;
do { do {
cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
} while(cur_irq == CD_IO::Interrupt::None); } while(cur_irq == CD_IO::Interrupt::None);
cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
// ^ Stabilize interrupt
if(cur_irq == CD_IO::Interrupt::DataReady) {
printf("Wopsie!\n");
}
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
cmd_interrupt_bit = bit::set(cmd_interrupt_bit, cur_irq);
return cur_irq; return cur_irq;
}; };
CD_IO::PortIndex1::change_to(); CD_IO::PortIndex1::change_to();
@ -52,39 +42,36 @@ namespace JabyEngine {
} }
template<typename...ARGS> template<typename...ARGS>
static void send(IOPort<CD_IO::CommandFifo>& cmd_fifo, IOPort<CD_IO::ParameterFifo>& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) { static void send(CD_IO::Command::Desc cmd, bool sync, ARGS...args) {
while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy));
SysCall::EnterCriticalSection();
cmd_interrupt_bit = 0;
CD_IO::PortIndex0::change_to();
((parameter_fifo.write(CD_IO::ParameterFifo{args})),...);
cmd_fifo.write(CD_IO::CommandFifo{cmd.id});
SysCall::ExitCriticalSection();
}
template<typename...ARGS>
static void send_irq(IOPort<CD_IO::CommandFifo>& cmd_fifo, IOPort<CD_IO::ParameterFifo>& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) {
while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy)); while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy));
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
((parameter_fifo.write(CD_IO::ParameterFifo{args})),...); ((CD_IO::PortIndex0::ParameterFifo.write(CD_IO::ParameterFifo{args})),...);
cmd_fifo.write(CD_IO::CommandFifo{cmd.id}); CD_IO::PortIndex0::CommandFifo.write(CD_IO::CommandFifo{cmd.id});
if(sync)
while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy));
} }
}; };
// Requires Index 0 // Requires Index 0
template<typename...ARGS> template<typename...ARGS>
static void send_wait(CD_IO::Command::Desc cmd, ARGS...args) { static void send(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, cmd, args...); Internal::send(cmd, true, args...);
Internal::wait_completed(cmd.complete_irq); }
template<typename...ARGS>
static void sendX(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send(cmd, false, args...);
} }
// Requires Index 0 // Requires Index 0
template<typename...ARGS> template<typename...ARGS>
static void send_wait_irq(CD_IO::Command::Desc cmd, ARGS...args) { static void send_wait_response(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send_irq(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, cmd, args...); Interrupt::disable_irq(Interrupt::CDROM);
Internal::wait_completed_irq(cmd.complete_irq); Internal::send(cmd, true, args...);
Internal::wait_completed(cmd.complete_irq);
Interrupt::enable_irq(Interrupt::CDROM);
} }
}; };
@ -109,7 +96,7 @@ namespace JabyEngine {
static void pause() { static void pause() {
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
Command::send_wait(CD_IO::Command::Pause); NewCommand::send(CD_IO::Command::Pause);
} }
} }
} }

View File

@ -9,8 +9,7 @@ namespace JabyEngine {
static CD::BCDTimeStamp last_track; static CD::BCDTimeStamp last_track;
TrackList get_tracks() { TrackList get_tracks() {
CD_IO::PortIndex0::change_to(); CD::NewCommand::send_wait_response(CD_IO::Command::GetTN);
CD::Command::send_wait(CD_IO::Command::GetTN);
const auto stat = CD_IO::PortIndex0::ResponseFifo.read(); const auto stat = CD_IO::PortIndex0::ResponseFifo.read();
const auto first = CD_IO::PortIndex0::ResponseFifo.read().raw; const auto first = CD_IO::PortIndex0::ResponseFifo.read().raw;
@ -26,12 +25,12 @@ namespace JabyEngine {
void play(uint8_t track) { void play(uint8_t track) {
CD::enable_CDDA(); CD::enable_CDDA();
CD::Command::send_wait(CD_IO::Command::GetTD, track); CD::NewCommand::send_wait_response(CD_IO::Command::GetTD, track);
const auto stats = CD_IO::PortIndex0::ResponseFifo.read().raw; const auto stats = CD_IO::PortIndex0::ResponseFifo.read().raw;
playing_track.min = CD_IO::PortIndex0::ResponseFifo.read().raw; playing_track.min = CD_IO::PortIndex0::ResponseFifo.read().raw;
playing_track.sec = CD_IO::PortIndex0::ResponseFifo.read().raw; playing_track.sec = CD_IO::PortIndex0::ResponseFifo.read().raw;
CD::Command::send_wait(CD_IO::Command::Play, track); CD::NewCommand::send(CD_IO::Command::Play, track);
} }
void stop() { void stop() {
@ -45,8 +44,8 @@ namespace JabyEngine {
void pop_play() { void pop_play() {
CD::enable_CDDA(); CD::enable_CDDA();
CD::Command::send_wait(CD_IO::Command::SetLoc, last_track.min, last_track.sec, last_track.sector); CD::NewCommand::send(CD_IO::Command::SetLoc, last_track.min, last_track.sec, last_track.sector);
CD::Command::send_wait(CD_IO::Command::Play); CD::NewCommand::send(CD_IO::Command::Play);
} }
} }
} }

View File

@ -23,7 +23,7 @@ namespace JabyEngine {
CD::IRQ::read_sector_to0(reinterpret_cast<uint32_t*>(&xa_file), sizeof(CD::RawXADataSector)); CD::IRQ::read_sector_to0(reinterpret_cast<uint32_t*>(&xa_file), sizeof(CD::RawXADataSector));
if(setting.channel == xa_file.sub_header.channel_number) { if(setting.channel == xa_file.sub_header.channel_number) {
CD::IRQ::resume_at0(setting.start_loc); CD::IRQ::resume_at0(setting.start_loc);
CD::Command::send_wait_irq(CD_IO::Command::ReadS); CD::NewCommand::sendX(CD_IO::Command::ReadS);
} }
} break; } break;
@ -39,8 +39,8 @@ namespace JabyEngine {
CD::enable_CDXA(double_speed); //< Activates PortIndex0 CD::enable_CDXA(double_speed); //< Activates PortIndex0
set_channel(channel); set_channel(channel);
CD::Command::send_wait(CD_IO::Command::SetLoc, setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector); CD::NewCommand::send(CD_IO::Command::SetLoc, setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector);
CD::Command::send_wait(CD_IO::Command::ReadS); CD::NewCommand::send(CD_IO::Command::ReadS);
} }
void stop() { void stop() {
@ -50,8 +50,7 @@ namespace JabyEngine {
void set_channel(uint8_t channel) { void set_channel(uint8_t channel) {
static constexpr uint8_t File = 1; static constexpr uint8_t File = 1;
CD_IO::PortIndex0::change_to(); CD::NewCommand::send(CD_IO::Command::Filter, File, channel);
CD::Command::send_wait(CD_IO::Command::Filter, File, channel);
setting.channel = channel; setting.channel = channel;
} }
@ -65,8 +64,8 @@ namespace JabyEngine {
CD::enable_CDXA(setting.double_speed); //< Activates PortIndex0 CD::enable_CDXA(setting.double_speed); //< Activates PortIndex0
set_channel(setting.channel); set_channel(setting.channel);
CD::Command::send_wait(CD_IO::Command::SetLoc, setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector); CD::NewCommand::send(CD_IO::Command::SetLoc, setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector);
CD::Command::send_wait(CD_IO::Command::ReadS); CD::NewCommand::send(CD_IO::Command::ReadS);
} }
void planschi() { void planschi() {

View File

@ -13,7 +13,7 @@ namespace JabyEngine {
namespace boot { namespace boot {
namespace CD { namespace CD {
using JabyEngine::CD::internal::Command; using JabyEngine::CD::internal::NewCommand;
void setup() { void setup() {
static constexpr auto DebugX = 1; static constexpr auto DebugX = 1;
@ -41,13 +41,13 @@ namespace JabyEngine {
CD_IO::PortIndex0::change_to(); 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::Command::GetStat); NewCommand::send(CD_IO::Command::GetStat);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Blue(), DebugX, DebugY, DebugScale); __debug_boot_color_at(::JabyEngine::GPU::Color24::Blue(), DebugX, DebugY, DebugScale);
Command::send_wait(CD_IO::Command::GetStat); NewCommand::send(CD_IO::Command::GetStat);
__debug_boot_color_at(::JabyEngine::GPU::Color24::Yellow(), DebugX, DebugY, DebugScale); __debug_boot_color_at(::JabyEngine::GPU::Color24::Yellow(), DebugX, DebugY, DebugScale);
Command::send_wait(CD_IO::Command::Init); NewCommand::send(CD_IO::Command::Init);
Command::send_wait(CD_IO::Command::Demute); NewCommand::send(CD_IO::Command::Demute);
} }
} }
} }

View File

@ -38,15 +38,14 @@ namespace JabyEngine {
static SectorBufferAllocator sector_allocator; static SectorBufferAllocator sector_allocator;
static File cur_file; static File cur_file;
volatile uint8_t cmd_interrupt_bit = 0;
State current_state = State::Ready; State current_state = State::Ready;
auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler); auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler);
static BCDTimeStamp send_read_cmd0(uint32_t lba, CD_IO::Command::Desc cmd) { static BCDTimeStamp send_read_cmd0(uint32_t lba, CD_IO::Command::Desc cmd) {
const auto loc = BCDTimeStamp::from(lba); const auto loc = BCDTimeStamp::from(lba);
Command::send_wait(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector); NewCommand::send(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector);
Command::send_wait(cmd); NewCommand::send(cmd);
return loc; return loc;
} }
@ -86,7 +85,7 @@ namespace JabyEngine {
} }
void resume_at0(const BCDTimeStamp& cd_time) { void resume_at0(const BCDTimeStamp& cd_time) {
Command::send_wait_irq(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector); NewCommand::sendX(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector);
} }
//###################################################################################################################### //######################################################################################################################
@ -110,10 +109,6 @@ namespace JabyEngine {
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
//printf("Before: %i (IRQ: %i)\n", cmd_interrupt_bit, cur_irq);
cmd_interrupt_bit = bit::set(cmd_interrupt_bit, cur_irq);
//printf("After: %i (IRQ: %i)\n", cmd_interrupt_bit, cur_irq);
if(current_state != State::XAMode) { if(current_state != State::XAMode) {
switch(cur_irq) { switch(cur_irq) {
case CD_IO::Interrupt::DataReady: { case CD_IO::Interrupt::DataReady: {
@ -125,20 +120,20 @@ namespace JabyEngine {
if(cur_file.done_processing()) { if(cur_file.done_processing()) {
current_state = State::Done; current_state = State::Done;
Command::send_wait_irq(CD_IO::Command::Pause); NewCommand::send(CD_IO::Command::Pause);
} }
} }
else { else {
current_state = State::BufferFull; current_state = State::BufferFull;
Command::send_wait_irq(CD_IO::Command::Pause); NewCommand::send(CD_IO::Command::Pause);
} }
} break; } break;
case CD_IO::Interrupt::DataEnd: { case CD_IO::Interrupt::DataEnd: {
// TODO: Fix this!! This is a freaking static time // TODO: Fix this!! This is a freaking static time
resume_at0(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0}); resume_at0(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0});
Command::send_wait_irq(CD_IO::Command::Play); NewCommand::send(CD_IO::Command::Play);
} break; } break;
case CD_IO::Interrupt::DiskError: { case CD_IO::Interrupt::DiskError: {
@ -162,8 +157,7 @@ namespace JabyEngine {
cur_file.set_from(file_info); cur_file.set_from(file_info);
sector_allocator = buffer_allocator; sector_allocator = buffer_allocator;
CD_IO::PortIndex0::change_to(); NewCommand::send(CD_IO::Command::SetMode, DataSectorMode);
Command::send_wait(CD_IO::Command::SetMode, DataSectorMode);
send_read_n0(cur_file.cur_lba); send_read_n0(cur_file.cur_lba);
} }
@ -179,8 +173,7 @@ namespace JabyEngine {
} }
BCDTimeStamp get_loc() { BCDTimeStamp get_loc() {
CD_IO::PortIndex0::change_to(); NewCommand::send_wait_response(CD_IO::Command::GetLocP);
Command::send_wait(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 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 index = CD_IO::PortIndex0::ResponseFifo.read().raw; // index number (Usually 01h)
@ -191,17 +184,16 @@ namespace JabyEngine {
const auto min = CD_IO::PortIndex0::ResponseFifo.read().raw; // minute number on entire disk (00h and up) 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 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) const auto sectors = CD_IO::PortIndex0::ResponseFifo.read().raw; // sector number on entire disk (00h to 74h)
return BCDTimeStamp{min, sec, sectors}; return BCDTimeStamp{min, sec, sectors};
} }
void enable_CD() { void enable_CD() {
CD_IO::PortIndex0::change_to(); NewCommand::send(CD_IO::Command::SetMode, DataSectorMode);
Command::send_wait(CD_IO::Command::SetMode, DataSectorMode);
} }
void enable_CDDA() { void enable_CDDA() {
CD_IO::PortIndex0::change_to(); NewCommand::send(CD_IO::Command::SetMode, AudioSectorMode);
Command::send_wait(CD_IO::Command::SetMode, AudioSectorMode);
} }
void enable_CDXA(bool double_speed) { void enable_CDXA(bool double_speed) {
@ -210,8 +202,7 @@ namespace JabyEngine {
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit); const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit);
CD_IO::PortIndex0::change_to(); NewCommand::send(CD_IO::Command::SetMode, mode);
Command::send_wait(CD_IO::Command::SetMode, mode);
current_state = State::XAMode; current_state = State::XAMode;
} }
} }