From c789deb8009d31b89cc632b0d32bce38020504d8 Mon Sep 17 00:00:00 2001 From: jaby Date: Sun, 9 Jun 2024 21:59:43 +0200 Subject: [PATCH] Cody fixes --- .../PoolBox/application/src/asset_mgr.cpp | 1 + .../PSX/File/Processor/cd_file_processor.hpp | 1 + .../internal-include/CD/cd_internal.hpp | 18 +-- src/Library/internal-include/CD/cd_types.hpp | 5 +- src/Library/src/Audio/CDXA.cpp | 6 +- src/Library/src/CD/cd.cpp | 127 ++++++++---------- .../src/File/Processor/cd_file_processor.cpp | 4 + src/Library/src/GPU/gpu.cpp | 10 +- src/Library/src/Timer/high_res_timer.cpp | 4 +- 9 files changed, 79 insertions(+), 97 deletions(-) diff --git a/examples/PoolBox/application/src/asset_mgr.cpp b/examples/PoolBox/application/src/asset_mgr.cpp index e9e62d30..d7f3b712 100644 --- a/examples/PoolBox/application/src/asset_mgr.cpp +++ b/examples/PoolBox/application/src/asset_mgr.cpp @@ -48,6 +48,7 @@ namespace Assets { return; } } + file_processor.shutdown(); } template diff --git a/include/PSX/File/Processor/cd_file_processor.hpp b/include/PSX/File/Processor/cd_file_processor.hpp index 16c9823f..fa628c22 100644 --- a/include/PSX/File/Processor/cd_file_processor.hpp +++ b/include/PSX/File/Processor/cd_file_processor.hpp @@ -48,6 +48,7 @@ namespace JabyEngine { CDFileProcessor() = default; void setup(const volatile AutoLBAEntry* lba, JobArray jobs, const BufferConfiguration& buf_cfg); + void shutdown(); template void setup(const volatile AutoLBAEntry* lba, const CDFile (&file_array)[N], const BufferConfiguration& buf_cfg) { diff --git a/src/Library/internal-include/CD/cd_internal.hpp b/src/Library/internal-include/CD/cd_internal.hpp index 13196472..ee092b6e 100644 --- a/src/Library/internal-include/CD/cd_internal.hpp +++ b/src/Library/internal-include/CD/cd_internal.hpp @@ -20,8 +20,6 @@ namespace JabyEngine { extern State current_state; extern volatile uint8_t cmd_interrupt_bit; - extern uint8_t rel_last_send_cmd; - extern uint8_t last_send_cmd; struct Command { struct Internal { @@ -35,16 +33,11 @@ namespace JabyEngine { do { 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); + cur_irq = CD_IO::Interrupt::get_type(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; }; CD_IO::PortIndex1::change_to(); @@ -61,9 +54,6 @@ namespace JabyEngine { CD_IO::PortIndex0::change_to(); ((parameter_fifo.write(CD_IO::ParameterFifo{args})),...); cmd_fifo.write(CD_IO::CommandFifo{cmd.id}); - - rel_last_send_cmd = cmd.id; - last_send_cmd = cmd.id; SysCall::ExitCriticalSection(); } @@ -74,9 +64,6 @@ namespace JabyEngine { CD_IO::PortIndex0::change_to(); ((parameter_fifo.write(CD_IO::ParameterFifo{args})),...); 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 end_read_file(); void continue_reading(); BCDTimeStamp get_loc(); diff --git a/src/Library/internal-include/CD/cd_types.hpp b/src/Library/internal-include/CD/cd_types.hpp index d5411d37..18401420 100644 --- a/src/Library/internal-include/CD/cd_types.hpp +++ b/src/Library/internal-include/CD/cd_types.hpp @@ -58,7 +58,10 @@ namespace JabyEngine { } inline CD_IO::DataSector* allocate_sector() const { - return this->allocate(this->ctx); + if(this->allocate) { + return this->allocate(this->ctx); + } + return nullptr; } }; diff --git a/src/Library/src/Audio/CDXA.cpp b/src/Library/src/Audio/CDXA.cpp index 32555860..6af080e7 100644 --- a/src/Library/src/Audio/CDXA.cpp +++ b/src/Library/src/Audio/CDXA.cpp @@ -14,7 +14,7 @@ namespace JabyEngine { } setting; CD::State interrupt_handler(uint8_t irq) { -/* switch(irq) { + switch(irq) { case CD_IO::Interrupt::DataReady: { // The IRQ stack is 0x1000 bytes large so this should fit CD::RawXADataSector xa_file; @@ -29,7 +29,7 @@ namespace JabyEngine { case CD_IO::Interrupt::DiskError: return CD::State::Error; - };*/ + }; return CD::State::XAMode; } @@ -41,7 +41,6 @@ namespace JabyEngine { 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::current_state = CD::State::XAMode; } void stop() { @@ -68,7 +67,6 @@ namespace JabyEngine { 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::current_state = CD::State::XAMode; } } } \ No newline at end of file diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index b8824b26..b295258e 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -39,8 +39,6 @@ namespace JabyEngine { static File cur_file; 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; auto irq_callback = SysCall::InterruptCallback::from(IRQ::verifier, IRQ::handler); @@ -95,73 +93,7 @@ namespace JabyEngine { static SysCall::InterruptVerifierResult verifier() { if(Interrupt::is_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()) { - 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); - + Interrupt::ack_irq(Interrupt::CDROM); return SysCall::InterruptVerifierResult::ExecuteHandler; } @@ -171,7 +103,57 @@ namespace JabyEngine { } 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(); } } @@ -185,6 +167,10 @@ namespace JabyEngine { send_read_n0(cur_file.cur_lba); } + void end_read_file() { + sector_allocator = SectorBufferAllocator::invalid(); + } + void continue_reading() { if(current_state == State::BufferFull) { CD_IO::PortIndex0::change_to(); @@ -219,6 +205,7 @@ namespace JabyEngine { const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit); + current_state = State::XAMode; CD_IO::PortIndex0::change_to(); Command::send_wait(CD_IO::Command::SetMode, mode); } diff --git a/src/Library/src/File/Processor/cd_file_processor.cpp b/src/Library/src/File/Processor/cd_file_processor.cpp index 80a6c5fc..2046df53 100644 --- a/src/Library/src/File/Processor/cd_file_processor.cpp +++ b/src/Library/src/File/Processor/cd_file_processor.cpp @@ -87,6 +87,10 @@ namespace JabyEngine { CDFileProcessor::start_cur_job(const_cast(lba), buf_cfg); } + void CDFileProcessor :: shutdown() { + CD::internal::end_read_file(); + } + Progress CDFileProcessor :: process() { const auto cur_state = CD::internal::read_current_state(); CDFileProcessor::process_data(); diff --git a/src/Library/src/GPU/gpu.cpp b/src/Library/src/GPU/gpu.cpp index 83679bf0..fbf3342e 100644 --- a/src/Library/src/GPU/gpu.cpp +++ b/src/Library/src/GPU/gpu.cpp @@ -22,10 +22,7 @@ namespace JabyEngine { static SysCall::InterruptVerifierResult interrupt_verifier() { if(Interrupt::is_irq(Interrupt::VBlank)) { - vsync_counter++; - MasterTime::value++; - - //Callback::internal::VSync::execute(); + Interrupt::ack_irq(Interrupt::VBlank); return SysCall::InterruptVerifierResult::ExecuteHandler; } @@ -35,7 +32,10 @@ namespace JabyEngine { } static void interrupt_handler(uint32_t) { - Interrupt::ack_irq(Interrupt::VBlank); + vsync_counter++; + MasterTime::value++; + + //Callback::internal::VSync::execute(); SysCall::ReturnFromException(); } diff --git a/src/Library/src/Timer/high_res_timer.cpp b/src/Library/src/Timer/high_res_timer.cpp index 9bfd0f35..2d9436cd 100644 --- a/src/Library/src/Timer/high_res_timer.cpp +++ b/src/Library/src/Timer/high_res_timer.cpp @@ -8,7 +8,7 @@ namespace JabyEngine { namespace Timer { static SysCall::InterruptVerifierResult interrupt_verifier() { if(Interrupt::is_irq(Interrupt::Timer2)) { - HighResTime::global_counter_10ms = HighResTime::global_counter_10ms + 1; + Interrupt::ack_irq(Interrupt::Timer2); return SysCall::InterruptVerifierResult::ExecuteHandler; } @@ -18,7 +18,7 @@ namespace JabyEngine { } static void interrupt_handler(uint32_t) { - Interrupt::ack_irq(Interrupt::Timer2); + HighResTime::global_counter_10ms = HighResTime::global_counter_10ms + 1; SysCall::ReturnFromException(); }