79 lines
2.5 KiB
C++
79 lines
2.5 KiB
C++
#pragma once
|
|
#include "cd_types.hpp"
|
|
#include <PSX/System/syscalls.hpp>
|
|
|
|
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
|
#include <stdio.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 irq_bit_pending;
|
|
|
|
struct Command {
|
|
static void wait_completed() {
|
|
while(const_cast<volatile uint8_t&>(irq_bit_pending));
|
|
}
|
|
|
|
template<typename...ARGS>
|
|
static void send_no_wait(CD_IO::Command::Desc cmd, ARGS...args) {
|
|
while(CD_IO::IndexStatus.read().is_set(CD_IO_Values::IndexStatus::IsTransmissionBusy));
|
|
|
|
irq_bit_pending = bit::set(irq_bit_pending, cmd.complete_irq);
|
|
CD_IO::PortIndex0::change_to();
|
|
((CD_IO::PortIndex0::ParameterFifo.write(CD_IO_Values::ParameterFifo{args})),...);
|
|
CD_IO::PortIndex0::CommandFifo.write(CD_IO_Values::CommandFifo{cmd.id});
|
|
}
|
|
|
|
template<typename...ARGS>
|
|
static void send(CD_IO::Command::Desc cmd, ARGS...args) {
|
|
Command::wait_completed();
|
|
Command::send_no_wait(cmd, args...);
|
|
}
|
|
|
|
template<typename...ARGS>
|
|
static void send_wait_response(CD_IO::Command::Desc cmd, ARGS...args) {
|
|
Command::send(cmd, args...);
|
|
Command::wait_completed();
|
|
}
|
|
};
|
|
|
|
namespace IRQ {
|
|
void process(uint32_t 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 end_read_file();
|
|
void continue_reading();
|
|
|
|
BCDTimeStamp get_loc();
|
|
BCDTimeStamp get_locL();
|
|
|
|
void enable_CD();
|
|
void enable_CDDA();
|
|
void enable_CDXA(bool double_speed);
|
|
|
|
static void pause() {
|
|
Command::send(CD_IO::Command::Pause);
|
|
}
|
|
}
|
|
}
|
|
} |