Cody fixes

This commit is contained in:
jaby 2024-06-09 21:59:43 +02:00
parent 336e877aa6
commit c789deb800
9 changed files with 79 additions and 97 deletions

View File

@ -48,6 +48,7 @@ namespace Assets {
return; return;
} }
} }
file_processor.shutdown();
} }
template<size_t N> template<size_t N>

View File

@ -48,6 +48,7 @@ namespace JabyEngine {
CDFileProcessor() = default; CDFileProcessor() = default;
void setup(const volatile AutoLBAEntry* lba, JobArray jobs, const BufferConfiguration& buf_cfg); void setup(const volatile AutoLBAEntry* lba, JobArray jobs, const BufferConfiguration& buf_cfg);
void shutdown();
template<size_t N> template<size_t N>
void setup(const volatile AutoLBAEntry* lba, const CDFile (&file_array)[N], const BufferConfiguration& buf_cfg) { void setup(const volatile AutoLBAEntry* lba, const CDFile (&file_array)[N], const BufferConfiguration& buf_cfg) {

View File

@ -20,8 +20,6 @@ namespace JabyEngine {
extern State current_state; extern State current_state;
extern volatile uint8_t cmd_interrupt_bit; extern volatile uint8_t cmd_interrupt_bit;
extern uint8_t rel_last_send_cmd;
extern uint8_t last_send_cmd;
struct Command { struct Command {
struct Internal { struct Internal {
@ -35,16 +33,11 @@ namespace JabyEngine {
do { do {
cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
if(cur_irq == CD_IO::Interrupt::Acknowledge) {
printf("Rand ACK for 0x%X\n", last_send_cmd);
}
if(cur_irq == CD_IO::Interrupt::Complete) {
printf("Rand Comp for 0x%X\n", last_send_cmd);
}
} 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);
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); 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();
@ -61,9 +54,6 @@ namespace JabyEngine {
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
((parameter_fifo.write(CD_IO::ParameterFifo{args})),...); ((parameter_fifo.write(CD_IO::ParameterFifo{args})),...);
cmd_fifo.write(CD_IO::CommandFifo{cmd.id}); cmd_fifo.write(CD_IO::CommandFifo{cmd.id});
rel_last_send_cmd = cmd.id;
last_send_cmd = cmd.id;
SysCall::ExitCriticalSection(); SysCall::ExitCriticalSection();
} }
@ -74,9 +64,6 @@ namespace JabyEngine {
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
((parameter_fifo.write(CD_IO::ParameterFifo{args})),...); ((parameter_fifo.write(CD_IO::ParameterFifo{args})),...);
cmd_fifo.write(CD_IO::CommandFifo{cmd.id}); cmd_fifo.write(CD_IO::CommandFifo{cmd.id});
rel_last_send_cmd = cmd.id;
last_send_cmd = cmd.id;
} }
}; };
@ -105,6 +92,7 @@ namespace JabyEngine {
} }
void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator); void read_file(AutoLBAEntry file_info, const SectorBufferAllocator& buffer_allocator);
void end_read_file();
void continue_reading(); void continue_reading();
BCDTimeStamp get_loc(); BCDTimeStamp get_loc();

View File

@ -58,7 +58,10 @@ namespace JabyEngine {
} }
inline CD_IO::DataSector* allocate_sector() const { inline CD_IO::DataSector* allocate_sector() const {
return this->allocate(this->ctx); if(this->allocate) {
return this->allocate(this->ctx);
}
return nullptr;
} }
}; };

View File

@ -14,7 +14,7 @@ namespace JabyEngine {
} setting; } setting;
CD::State interrupt_handler(uint8_t irq) { CD::State interrupt_handler(uint8_t irq) {
/* switch(irq) { switch(irq) {
case CD_IO::Interrupt::DataReady: { case CD_IO::Interrupt::DataReady: {
// The IRQ stack is 0x1000 bytes large so this should fit // The IRQ stack is 0x1000 bytes large so this should fit
CD::RawXADataSector xa_file; CD::RawXADataSector xa_file;
@ -29,7 +29,7 @@ namespace JabyEngine {
case CD_IO::Interrupt::DiskError: case CD_IO::Interrupt::DiskError:
return CD::State::Error; return CD::State::Error;
};*/ };
return CD::State::XAMode; return CD::State::XAMode;
} }
@ -41,7 +41,6 @@ namespace JabyEngine {
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::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::Command::send_wait(CD_IO::Command::ReadS);
//CD::current_state = CD::State::XAMode;
} }
void stop() { void stop() {
@ -68,7 +67,6 @@ namespace JabyEngine {
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::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::Command::send_wait(CD_IO::Command::ReadS);
//CD::current_state = CD::State::XAMode;
} }
} }
} }

View File

@ -39,8 +39,6 @@ namespace JabyEngine {
static File cur_file; static File cur_file;
volatile uint8_t cmd_interrupt_bit = 0; volatile uint8_t cmd_interrupt_bit = 0;
uint8_t rel_last_send_cmd = 0;
uint8_t last_send_cmd = 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);
@ -95,73 +93,7 @@ namespace JabyEngine {
static SysCall::InterruptVerifierResult verifier() { static SysCall::InterruptVerifierResult verifier() {
if(Interrupt::is_irq(Interrupt::CDROM)) { if(Interrupt::is_irq(Interrupt::CDROM)) {
const auto old_status = CD_IO::IndexStatus.read(); Interrupt::ack_irq(Interrupt::CDROM);
CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
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: {
// Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to0(sector->data, CD_IO::DataSector::SizeBytes);
if(cur_file.done_processing()) {
printf("Pause1\n");
current_state = State::Done;
Command::send_wait_irq(CD_IO::Command::Pause);
printf("Pause done!\n");
}
}
else {
current_state = State::BufferFull;
printf("Pause2\n");
Command::send_wait_irq(CD_IO::Command::Pause);
printf("Pause done!\n");
}
} break;
case CD_IO::Interrupt::Complete: {
printf("Complete for 0x%X\n", rel_last_send_cmd);
} break;
case CD_IO::Interrupt::Acknowledge: {
if(last_send_cmd != 0x0) {
printf("ACK 0x%X\n", last_send_cmd);
last_send_cmd = 0x0;
}
} 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);
} break;
case CD_IO::Interrupt::DiskError: {
printf("CD ERROR\n");
current_state = State::Error;
} break;
}
}
else {
current_state = CDXA::interrupt_handler(cur_irq);
}
// No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus.write(old_status);
return SysCall::InterruptVerifierResult::ExecuteHandler; return SysCall::InterruptVerifierResult::ExecuteHandler;
} }
@ -171,7 +103,57 @@ namespace JabyEngine {
} }
static void handler(uint32_t) { static void handler(uint32_t) {
Interrupt::ack_irq(Interrupt::CDROM); const auto old_status = CD_IO::IndexStatus.read();
CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
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: {
// Obtain sector content here
auto* sector = sector_allocator.allocate_sector();
if(sector) {
//Now obtain sector
read_sector_to0(sector->data, CD_IO::DataSector::SizeBytes);
if(cur_file.done_processing()) {
current_state = State::Done;
Command::send_wait_irq(CD_IO::Command::Pause);
}
}
else {
current_state = State::BufferFull;
Command::send_wait_irq(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);
} break;
case CD_IO::Interrupt::DiskError: {
printf("CD ERROR\n");
current_state = State::Error;
} break;
}
}
else {
current_state = CDXA::interrupt_handler(cur_irq);
}
// No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus.write(old_status);
SysCall::ReturnFromException(); SysCall::ReturnFromException();
} }
} }
@ -185,6 +167,10 @@ namespace JabyEngine {
send_read_n0(cur_file.cur_lba); send_read_n0(cur_file.cur_lba);
} }
void end_read_file() {
sector_allocator = SectorBufferAllocator::invalid();
}
void continue_reading() { void continue_reading() {
if(current_state == State::BufferFull) { if(current_state == State::BufferFull) {
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
@ -219,6 +205,7 @@ namespace JabyEngine {
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit); const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit);
current_state = State::XAMode;
CD_IO::PortIndex0::change_to(); CD_IO::PortIndex0::change_to();
Command::send_wait(CD_IO::Command::SetMode, mode); Command::send_wait(CD_IO::Command::SetMode, mode);
} }

View File

@ -87,6 +87,10 @@ namespace JabyEngine {
CDFileProcessor::start_cur_job(const_cast<const AutoLBAEntry*>(lba), buf_cfg); CDFileProcessor::start_cur_job(const_cast<const AutoLBAEntry*>(lba), buf_cfg);
} }
void CDFileProcessor :: shutdown() {
CD::internal::end_read_file();
}
Progress CDFileProcessor :: process() { Progress CDFileProcessor :: process() {
const auto cur_state = CD::internal::read_current_state(); const auto cur_state = CD::internal::read_current_state();
CDFileProcessor::process_data(); CDFileProcessor::process_data();

View File

@ -22,10 +22,7 @@ namespace JabyEngine {
static SysCall::InterruptVerifierResult interrupt_verifier() { static SysCall::InterruptVerifierResult interrupt_verifier() {
if(Interrupt::is_irq(Interrupt::VBlank)) { if(Interrupt::is_irq(Interrupt::VBlank)) {
vsync_counter++; Interrupt::ack_irq(Interrupt::VBlank);
MasterTime::value++;
//Callback::internal::VSync::execute();
return SysCall::InterruptVerifierResult::ExecuteHandler; return SysCall::InterruptVerifierResult::ExecuteHandler;
} }
@ -35,7 +32,10 @@ namespace JabyEngine {
} }
static void interrupt_handler(uint32_t) { static void interrupt_handler(uint32_t) {
Interrupt::ack_irq(Interrupt::VBlank); vsync_counter++;
MasterTime::value++;
//Callback::internal::VSync::execute();
SysCall::ReturnFromException(); SysCall::ReturnFromException();
} }

View File

@ -8,7 +8,7 @@ namespace JabyEngine {
namespace Timer { namespace Timer {
static SysCall::InterruptVerifierResult interrupt_verifier() { static SysCall::InterruptVerifierResult interrupt_verifier() {
if(Interrupt::is_irq(Interrupt::Timer2)) { if(Interrupt::is_irq(Interrupt::Timer2)) {
HighResTime::global_counter_10ms = HighResTime::global_counter_10ms + 1; Interrupt::ack_irq(Interrupt::Timer2);
return SysCall::InterruptVerifierResult::ExecuteHandler; return SysCall::InterruptVerifierResult::ExecuteHandler;
} }
@ -18,7 +18,7 @@ namespace JabyEngine {
} }
static void interrupt_handler(uint32_t) { static void interrupt_handler(uint32_t) {
Interrupt::ack_irq(Interrupt::Timer2); HighResTime::global_counter_10ms = HighResTime::global_counter_10ms + 1;
SysCall::ReturnFromException(); SysCall::ReturnFromException();
} }