diff --git a/examples/PoolBox/application/src/application.cpp b/examples/PoolBox/application/src/application.cpp index a3ef5960..8db4687a 100644 --- a/examples/PoolBox/application/src/application.cpp +++ b/examples/PoolBox/application/src/application.cpp @@ -221,9 +221,6 @@ namespace LoadingScene { } void main() { - printf("Hello Plaschi\n"); - CDXA::planschi(); - printf("Bye Bye Planschi\n"); setup(); while(true) { diff --git a/include/PSX/Audio/CDXA.hpp b/include/PSX/Audio/CDXA.hpp index 23bdab77..d4506b5d 100644 --- a/include/PSX/Audio/CDXA.hpp +++ b/include/PSX/Audio/CDXA.hpp @@ -10,7 +10,5 @@ namespace JabyEngine { void push_play(); void pop_play(); - - void planschi(); } } \ No newline at end of file diff --git a/src/Library/internal-include/CD/cd_internal.hpp b/src/Library/internal-include/CD/cd_internal.hpp index 8acdf1d0..f60ea8c1 100644 --- a/src/Library/internal-include/CD/cd_internal.hpp +++ b/src/Library/internal-include/CD/cd_internal.hpp @@ -42,41 +42,35 @@ namespace JabyEngine { } template - static void send(CD_IO::Command::Desc cmd, bool sync, ARGS...args) { + static void send(CD_IO::Command::Desc cmd, ARGS...args) { while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy)); CD_IO::PortIndex0::change_to(); ((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)); + while(CD_IO::IndexStatus.read().is_set(CD_IO::IndexStatus::IsTransmissionBusy)); } }; // Requires Index 0 template static void send(CD_IO::Command::Desc cmd, ARGS...args) { - Internal::send(cmd, true, args...); - } - - template - static void sendX(CD_IO::Command::Desc cmd, ARGS...args) { - Internal::send(cmd, false, args...); + Internal::send(cmd, args...); } // Requires Index 0 template static void send_wait_response(CD_IO::Command::Desc cmd, ARGS...args) { Interrupt::disable_irq(Interrupt::CDROM); - Internal::send(cmd, true, args...); + Internal::send(cmd, args...); Internal::wait_completed(cmd.complete_irq); Interrupt::enable_irq(Interrupt::CDROM); } }; namespace IRQ { - void data_ready_handler(uint32_t data); + void process(uint32_t irq); void read_sector_to0(uint32_t* dst, size_t bytes); void resume_at0(const BCDTimeStamp& cd_time); } diff --git a/src/Library/internal-include/System/callbacks_internal.hpp b/src/Library/internal-include/System/callbacks_internal.hpp index a921682f..783bd126 100644 --- a/src/Library/internal-include/System/callbacks_internal.hpp +++ b/src/Library/internal-include/System/callbacks_internal.hpp @@ -35,9 +35,10 @@ namespace JabyEngine { extern Thread::Handle thread_handle; extern uint32_t stack[StackSize]; + void routine(uint32_t irq); - static void execute(uint32_t parm) { - execute_callback(CD::thread_handle, parm); + static void execute(uint32_t irq) { + execute_callback(CD::thread_handle, irq); } static uint32_t resume() { diff --git a/src/Library/src/Audio/CDXA.cpp b/src/Library/src/Audio/CDXA.cpp index 3c44244a..393ea802 100644 --- a/src/Library/src/Audio/CDXA.cpp +++ b/src/Library/src/Audio/CDXA.cpp @@ -23,7 +23,7 @@ namespace JabyEngine { CD::IRQ::read_sector_to0(reinterpret_cast(&xa_file), sizeof(CD::RawXADataSector)); if(setting.channel == xa_file.sub_header.channel_number) { CD::IRQ::resume_at0(setting.start_loc); - CD::NewCommand::sendX(CD_IO::Command::ReadS); + CD::NewCommand::send(CD_IO::Command::ReadS); } } break; @@ -67,13 +67,5 @@ namespace JabyEngine { 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() { - for(size_t n = 0; n < 100; n++) { - CD::enable_CD(); - CD::enable_CDXA(false); - printf("%i\n", n); - } - } } } \ No newline at end of file diff --git a/src/Library/src/BootLoader/callbacks_boot.cpp b/src/Library/src/BootLoader/callbacks_boot.cpp index 4fa7e058..c14b4bb1 100644 --- a/src/Library/src/BootLoader/callbacks_boot.cpp +++ b/src/Library/src/BootLoader/callbacks_boot.cpp @@ -1,5 +1,4 @@ #include "../../internal-include/BootLoader/boot_loader.hpp" -#include "../../internal-include/CD/cd_internal.hpp" #include "../../internal-include/System/callbacks_internal.hpp" namespace JabyEngine { @@ -16,7 +15,7 @@ namespace JabyEngine { ); Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);*/ - InternalCallback::CD::thread_handle = Thread::create(JabyEngine::CD::internal::IRQ::data_ready_handler, InternalCallback::CD::stack); + InternalCallback::CD::thread_handle = Thread::create(InternalCallback::CD::routine, InternalCallback::CD::stack); Thread::set_user_mode_for(InternalCallback::CD::thread_handle); SysCall::ExitCriticalSection(); } diff --git a/src/Library/src/CD/cd.cpp b/src/Library/src/CD/cd.cpp index a7e85301..ac8fbc00 100644 --- a/src/Library/src/CD/cd.cpp +++ b/src/Library/src/CD/cd.cpp @@ -76,8 +76,6 @@ namespace JabyEngine { } void read_sector_to0(uint32_t* dst, size_t bytes) { - CD_IO::PortIndex0::Request.write(CD_IO::Request::want_data()); - // We only support DMA rn read_sector_dma0(dst, bytes); @@ -86,7 +84,7 @@ namespace JabyEngine { } void resume_at0(const BCDTimeStamp& cd_time) { - NewCommand::sendX(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector); + NewCommand::send(CD_IO::Command::SetLoc, cd_time.min, cd_time.sec, cd_time.sector); } //###################################################################################################################### @@ -107,11 +105,23 @@ namespace JabyEngine { CD_IO::PortIndex1::change_to(); const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); + if(cur_irq == CD_IO::Interrupt::DataReady) { + CD_IO::PortIndex0::change_to(); + CD_IO::PortIndex0::Request.write(CD_IO::Request::want_data()); + } + + CD_IO::PortIndex1::change_to(); CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag); CD_IO::PortIndex0::change_to(); + // No masking required because we can only write bit 0 - 2 + CD_IO::IndexStatus.write(old_status); + Callback::internal::CD::execute(cur_irq); + } + + void process(uint32_t irq) { if(current_state != State::XAMode) { - switch(cur_irq) { + switch(irq) { case CD_IO::Interrupt::DataReady: { // Obtain sector content here auto* sector = sector_allocator.allocate_sector(); @@ -138,31 +148,13 @@ namespace JabyEngine { } 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); - Callback::internal::CD::execute(cur_irq); - } - - void data_ready_handler(uint32_t data) { - while(true) { - if(current_state == State::XAMode) { - if(data == CD_IO::Interrupt::DataReady) { - printf("Scree...\n"); - IRQ::resume_at0(BCDTimeStamp::from(221)); - NewCommand::send(CD_IO::Command::ReadS); - } - } - data = Callback::internal::CD::resume(); + current_state = CDXA::interrupt_handler(irq); } } } diff --git a/src/Library/src/System/callbacks.cpp b/src/Library/src/System/callbacks.cpp index 69f027a6..3b5ac341 100644 --- a/src/Library/src/System/callbacks.cpp +++ b/src/Library/src/System/callbacks.cpp @@ -25,8 +25,17 @@ namespace JabyEngine { } namespace CD { + namespace CD_IRQ = JabyEngine::CD::internal::IRQ; + SysCall::ThreadHandle thread_handle = 0; uint32_t stack[StackSize]; + + void routine(uint32_t irq) { + while(true) { + CD_IRQ::process(irq); + irq = Callback::internal::CD::resume(); + } + } } } }