75 lines
2.6 KiB
C++
75 lines
2.6 KiB
C++
#pragma once
|
|
#include "cd_types.hpp"
|
|
|
|
namespace JabyEngine {
|
|
namespace CD {
|
|
namespace internal {
|
|
enum struct State {
|
|
Ready = 0,
|
|
Done = 0,
|
|
|
|
XAMode,
|
|
|
|
Reading,
|
|
BufferFull,
|
|
Error,
|
|
};
|
|
|
|
extern State current_state;
|
|
extern uint8_t cmd_interrupt_bit;
|
|
|
|
struct Command {
|
|
static void wait_completed() {
|
|
while(const_cast<volatile uint8_t&>(cmd_interrupt_bit) > 0);
|
|
}
|
|
|
|
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));
|
|
|
|
((parameter_fifo.write(CD_IO::ParameterFifo{args})),...);
|
|
cmd_fifo.write(CD_IO::CommandFifo {cmd.id});
|
|
cmd_interrupt_bit = bit::set(0, cmd.complete_irq);
|
|
}
|
|
|
|
template<typename T, typename...ARGS>
|
|
static void send(CD_IO::Command::Desc cmd, ARGS...args) {
|
|
send(T::CommandFifo, T::ParameterFifo, cmd, args...);
|
|
}
|
|
|
|
template<typename...ARGS>
|
|
static void send_wait(IOPort<CD_IO::CommandFifo>& cmd_fifo, IOPort<CD_IO::ParameterFifo>& parameter_fifo, CD_IO::Command::Desc cmd, ARGS...args) {
|
|
send(cmd_fifo, parameter_fifo, cmd, args...);
|
|
wait_completed();
|
|
}
|
|
|
|
template<typename T, typename...ARGS>
|
|
static void send_wait(CD_IO::Command::Desc cmd, ARGS...args) {
|
|
send_wait(T::CommandFifo, T::ParameterFifo, cmd, args...);
|
|
}
|
|
};
|
|
|
|
namespace IRQ {
|
|
void read_sector_to0(uint32_t* dst, size_t bytes);
|
|
void resume_at0(const BCDTimeStamp& cd_time);
|
|
}
|
|
|
|
static State read_current_state() {
|
|
return const_cast<volatile State&>(current_state);
|
|
}
|
|
|
|
void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator);
|
|
void continue_reading();
|
|
|
|
BCDTimeStamp get_loc();
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |