Inital Cody-Fix

This commit is contained in:
jaby 2024-06-13 07:54:09 +02:00
parent a8fd01579b
commit 33177eb97b
5 changed files with 54 additions and 78 deletions

View File

@ -19,31 +19,21 @@ namespace JabyEngine {
Error,
};
extern State current_state;
extern volatile uint8_t cmd_interrupt_bit;
extern uint8_t last_cmd;
extern State current_state;
struct Command {
struct NewCommand {
struct Internal {
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 {
CD_IO::Interrupt::Type cur_irq;
CD_IO::Interrupt::Type cur_irq = CD_IO::Interrupt::None;
do {
cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
} while(cur_irq == CD_IO::Interrupt::None);
cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
if(cur_irq == CD_IO::Interrupt::DataReady) {
printf("Wopsie!\n");
}
// ^ Stabilize interrupt
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
cmd_interrupt_bit = bit::set(cmd_interrupt_bit, cur_irq);
return cur_irq;
};
CD_IO::PortIndex1::change_to();
@ -52,39 +42,36 @@ namespace JabyEngine {
}
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) {
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) {
static void send(CD_IO::Command::Desc cmd, bool sync, ARGS...args) {
while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy));
CD_IO::PortIndex0::change_to();
((parameter_fifo.write(CD_IO::ParameterFifo{args})),...);
cmd_fifo.write(CD_IO::CommandFifo{cmd.id});
((CD_IO::PortIndex0::ParameterFifo.write(CD_IO::ParameterFifo{args})),...);
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
template<typename...ARGS>
static void send_wait(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, cmd, args...);
Internal::wait_completed(cmd.complete_irq);
static void send(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send(cmd, true, args...);
}
template<typename...ARGS>
static void sendX(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send(cmd, false, args...);
}
// Requires Index 0
template<typename...ARGS>
static void send_wait_irq(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send_irq(CD_IO::PortIndex0::CommandFifo, CD_IO::PortIndex0::ParameterFifo, cmd, args...);
Internal::wait_completed_irq(cmd.complete_irq);
static void send_wait_response(CD_IO::Command::Desc cmd, ARGS...args) {
Interrupt::disable_irq(Interrupt::CDROM);
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() {
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;
TrackList get_tracks() {
CD_IO::PortIndex0::change_to();
CD::Command::send_wait(CD_IO::Command::GetTN);
CD::NewCommand::send_wait_response(CD_IO::Command::GetTN);
const auto stat = CD_IO::PortIndex0::ResponseFifo.read();
const auto first = CD_IO::PortIndex0::ResponseFifo.read().raw;
@ -26,12 +25,12 @@ namespace JabyEngine {
void play(uint8_t track) {
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;
playing_track.min = 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() {
@ -45,8 +44,8 @@ namespace JabyEngine {
void pop_play() {
CD::enable_CDDA();
CD::Command::send_wait(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::SetLoc, last_track.min, last_track.sec, last_track.sector);
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));
if(setting.channel == xa_file.sub_header.channel_number) {
CD::IRQ::resume_at0(setting.start_loc);
CD::Command::send_wait_irq(CD_IO::Command::ReadS);
CD::NewCommand::sendX(CD_IO::Command::ReadS);
}
} break;
@ -39,8 +39,8 @@ namespace JabyEngine {
CD::enable_CDXA(double_speed); //< Activates PortIndex0
set_channel(channel);
CD::Command::send_wait(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::SetLoc, setting.start_loc.min, setting.start_loc.sec, setting.start_loc.sector);
CD::NewCommand::send(CD_IO::Command::ReadS);
}
void stop() {
@ -50,14 +50,13 @@ namespace JabyEngine {
void set_channel(uint8_t channel) {
static constexpr uint8_t File = 1;
CD_IO::PortIndex0::change_to();
CD::Command::send_wait(CD_IO::Command::Filter, File, channel);
CD::NewCommand::send(CD_IO::Command::Filter, File, channel);
setting.channel = channel;
}
void push_play() {
stop();
setting.last_loc = CD::get_loc();
setting.last_loc = CD::get_loc();
CD::current_state = CD::State::Ready;
}
@ -65,8 +64,8 @@ namespace JabyEngine {
CD::enable_CDXA(setting.double_speed); //< Activates PortIndex0
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::Command::send_wait(CD_IO::Command::ReadS);
CD::NewCommand::send(CD_IO::Command::SetLoc, setting.last_loc.min, setting.last_loc.sec, setting.last_loc.sector);
CD::NewCommand::send(CD_IO::Command::ReadS);
}
void planschi() {

View File

@ -13,7 +13,7 @@ namespace JabyEngine {
namespace boot {
namespace CD {
using JabyEngine::CD::internal::Command;
using JabyEngine::CD::internal::NewCommand;
void setup() {
static constexpr auto DebugX = 1;
@ -41,13 +41,13 @@ namespace JabyEngine {
CD_IO::PortIndex0::change_to();
__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);
Command::send_wait(CD_IO::Command::GetStat);
NewCommand::send(CD_IO::Command::GetStat);
__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 File cur_file;
volatile uint8_t cmd_interrupt_bit = 0;
State current_state = State::Ready;
auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler);
State current_state = State::Ready;
auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler);
static BCDTimeStamp send_read_cmd0(uint32_t lba, CD_IO::Command::Desc cmd) {
const auto loc = BCDTimeStamp::from(lba);
Command::send_wait(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector);
Command::send_wait(cmd);
NewCommand::send(CD_IO::Command::SetLoc, loc.min, loc.sec, loc.sector);
NewCommand::send(cmd);
return loc;
}
@ -86,7 +85,7 @@ namespace JabyEngine {
}
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::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) {
switch(cur_irq) {
case CD_IO::Interrupt::DataReady: {
@ -125,20 +120,20 @@ namespace JabyEngine {
if(cur_file.done_processing()) {
current_state = State::Done;
Command::send_wait_irq(CD_IO::Command::Pause);
NewCommand::send(CD_IO::Command::Pause);
}
}
else {
current_state = State::BufferFull;
Command::send_wait_irq(CD_IO::Command::Pause);
NewCommand::send(CD_IO::Command::Pause);
}
} break;
case CD_IO::Interrupt::DataEnd: {
// TODO: Fix this!! This is a freaking static time
resume_at0(BCDTimeStamp{.min = 0x0, .sec = 0x09, .sector = 0x0});
Command::send_wait_irq(CD_IO::Command::Play);
NewCommand::send(CD_IO::Command::Play);
} break;
case CD_IO::Interrupt::DiskError: {
@ -162,8 +157,7 @@ namespace JabyEngine {
cur_file.set_from(file_info);
sector_allocator = buffer_allocator;
CD_IO::PortIndex0::change_to();
Command::send_wait(CD_IO::Command::SetMode, DataSectorMode);
NewCommand::send(CD_IO::Command::SetMode, DataSectorMode);
send_read_n0(cur_file.cur_lba);
}
@ -179,8 +173,7 @@ namespace JabyEngine {
}
BCDTimeStamp get_loc() {
CD_IO::PortIndex0::change_to();
Command::send_wait(CD_IO::Command::GetLocP);
NewCommand::send_wait_response(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)
@ -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 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_CD() {
CD_IO::PortIndex0::change_to();
Command::send_wait(CD_IO::Command::SetMode, DataSectorMode);
NewCommand::send(CD_IO::Command::SetMode, DataSectorMode);
}
void enable_CDDA() {
CD_IO::PortIndex0::change_to();
Command::send_wait(CD_IO::Command::SetMode, AudioSectorMode);
NewCommand::send(CD_IO::Command::SetMode, AudioSectorMode);
}
void enable_CDXA(bool double_speed) {
@ -210,8 +202,7 @@ namespace JabyEngine {
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit);
CD_IO::PortIndex0::change_to();
Command::send_wait(CD_IO::Command::SetMode, mode);
NewCommand::send(CD_IO::Command::SetMode, mode);
current_state = State::XAMode;
}
}