Prepare CD Callback handler

This commit is contained in:
jaby 2024-06-13 22:28:37 +02:00
parent d628375a18
commit d8aee97397
7 changed files with 39 additions and 59 deletions

View File

@ -3,9 +3,9 @@
namespace JabyEngine { namespace JabyEngine {
namespace Callback { namespace Callback {
using Function = void (*)(); struct [[deprecated("Currently not supported")]] VSyncCallback {
using Function = void (*)();
struct VSyncCallback {
static Function callback; static Function callback;
static void install(Function function) { static void install(Function function) {
@ -16,17 +16,5 @@ namespace JabyEngine {
VSyncCallback::install(nullptr); VSyncCallback::install(nullptr);
} }
}; };
struct DataReadyCallback {
static Function callback;
static void install(Function function) {
DataReadyCallback::callback = function;
}
static void uninstall() {
DataReadyCallback::install(nullptr);
}
};
} }
} }

View File

@ -44,6 +44,7 @@ namespace JabyEngine {
} }
static void restore() { static void restore() {
SysCall::EnterCriticalSection();
MainThread::prepare_restore(); MainThread::prepare_restore();
Thread::execute_next(); Thread::execute_next();
} }

View File

@ -60,7 +60,7 @@ namespace JabyEngine {
Internal::send(cmd, true, args...); Internal::send(cmd, true, args...);
} }
template<typename...ARGS> template<typename...ARGS>
static void sendX(CD_IO::Command::Desc cmd, ARGS...args) { static void sendX(CD_IO::Command::Desc cmd, ARGS...args) {
Internal::send(cmd, false, args...); Internal::send(cmd, false, args...);
} }
@ -76,6 +76,7 @@ template<typename...ARGS>
}; };
namespace IRQ { namespace IRQ {
void data_ready_handler(uint32_t data);
void read_sector_to0(uint32_t* dst, size_t bytes); void read_sector_to0(uint32_t* dst, size_t bytes);
void resume_at0(const BCDTimeStamp& cd_time); void resume_at0(const BCDTimeStamp& cd_time);
} }

View File

@ -4,6 +4,11 @@
namespace JabyEngine { namespace JabyEngine {
namespace Callback { namespace Callback {
namespace internal { namespace internal {
static void execute_thread(SysCall::ThreadHandle thread_handle) {
MainThread::prepare_if_main(thread_handle);
Thread::execute_next();
}
namespace VSync { namespace VSync {
static constexpr size_t StackSize = 64; static constexpr size_t StackSize = 64;
@ -11,22 +16,19 @@ namespace JabyEngine {
extern uint32_t stack[StackSize]; extern uint32_t stack[StackSize];
void routine(); void routine();
static void execute() { static void [[deprecated("Currently not in use")]] execute() {
MainThread::prepare_if_main(VSync::thread_handle); execute_thread(VSync::thread_handle);
Thread::execute_next();
} }
} }
namespace DataReady { namespace CD {
static constexpr size_t StackSize = 256; static constexpr size_t StackSize = 256;
extern SysCall::ThreadHandle thread_handle; extern SysCall::ThreadHandle thread_handle;
extern uint32_t stack[StackSize]; extern uint32_t stack[StackSize];
void routine();
static void execute() { static void execute() {
MainThread::prepare_if_main(DataReady::thread_handle); execute_thread(CD::thread_handle);
Thread::execute_next();
} }
} }
} }

View File

@ -1,4 +1,5 @@
#include "../../internal-include/BootLoader/boot_loader.hpp" #include "../../internal-include/BootLoader/boot_loader.hpp"
#include "../../internal-include/CD/cd_internal.hpp"
#include "../../internal-include/System/callbacks_internal.hpp" #include "../../internal-include/System/callbacks_internal.hpp"
namespace JabyEngine { namespace JabyEngine {
@ -8,19 +9,19 @@ namespace JabyEngine {
void setup() { void setup() {
SysCall::EnterCriticalSection(); SysCall::EnterCriticalSection();
InternalCallback::VSync::thread_handle = SysCall::OpenThread( /*InternalCallback::VSync::thread_handle = SysCall::OpenThread(
InternalCallback::VSync::routine, InternalCallback::VSync::routine,
&InternalCallback::VSync::stack[InternalCallback::VSync::StackSize - 1], &InternalCallback::VSync::stack[InternalCallback::VSync::StackSize - 1],
SysCall::get_gp() SysCall::get_gp()
); );
InternalCallback::DataReady::thread_handle = SysCall::OpenThread( Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);*/
InternalCallback::DataReady::routine,
&InternalCallback::DataReady::stack[InternalCallback::DataReady::StackSize - 1], InternalCallback::CD::thread_handle = SysCall::OpenThread(
reinterpret_cast<void(*)()>(JabyEngine::CD::internal::IRQ::data_ready_handler),
&InternalCallback::CD::stack[InternalCallback::CD::StackSize - 1],
SysCall::get_gp() SysCall::get_gp()
); );
Thread::set_user_mode_for(InternalCallback::CD::thread_handle);
Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);
Thread::set_user_mode_for(InternalCallback::DataReady::thread_handle);
SysCall::ExitCriticalSection(); SysCall::ExitCriticalSection();
} }
} }

View File

@ -103,8 +103,8 @@ namespace JabyEngine {
} }
static void handler(uint32_t) { static void handler(uint32_t) {
const auto old_status = CD_IO::IndexStatus.read(); const auto old_status = CD_IO::IndexStatus.read();
bool run_callback = false; void (*exit_routine)() = Callback::internal::CD::execute;
CD_IO::PortIndex1::change_to(); CD_IO::PortIndex1::change_to();
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag); const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
@ -114,7 +114,6 @@ namespace JabyEngine {
if(current_state != State::XAMode) { if(current_state != State::XAMode) {
switch(cur_irq) { switch(cur_irq) {
case CD_IO::Interrupt::DataReady: { case CD_IO::Interrupt::DataReady: {
run_callback = true;
// Obtain sector content here // Obtain sector content here
auto* sector = sector_allocator.allocate_sector(); auto* sector = sector_allocator.allocate_sector();
if(sector) { if(sector) {
@ -152,11 +151,12 @@ namespace JabyEngine {
// No masking required because we can only write bit 0 - 2 // No masking required because we can only write bit 0 - 2
CD_IO::IndexStatus.write(old_status); CD_IO::IndexStatus.write(old_status);
exit_routine();
}
if(run_callback) { void data_ready_handler(uint32_t data) {
Callback::internal::DataReady::execute(); printf("Data: %i\n", data);
} MainThread::restore();
SysCall::ReturnFromException();
} }
} }
@ -210,7 +210,7 @@ namespace JabyEngine {
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit); const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit);
NewCommand::send(CD_IO::Command::SetMode, mode); NewCommand::send(CD_IO::Command::SetMode, mode);
//current_state = State::XAMode; current_state = State::XAMode;
} }
} }
} }

View File

@ -4,8 +4,9 @@
namespace JabyEngine { namespace JabyEngine {
namespace Callback { namespace Callback {
Function VSyncCallback :: callback = nullptr; // Marked deprecated currently
Function DataReadyCallback :: callback = nullptr; /*using Function = VSyncCallback::Function;
Function VSyncCallback :: callback = nullptr;*/
namespace internal { namespace internal {
namespace VSync { namespace VSync {
@ -14,32 +15,18 @@ namespace JabyEngine {
void routine() { void routine() {
while(true) { while(true) {
if(VSyncCallback::callback) { // Marked deprecated currently
/*if(VSyncCallback::callback) {
VSyncCallback::callback(); VSyncCallback::callback();
} }*/
SysCall::EnterCriticalSection();
MainThread::restore(); MainThread::restore();
} }
} }
} }
namespace DataReady { namespace CD {
SysCall::ThreadHandle thread_handle = 0; SysCall::ThreadHandle thread_handle = 0;
uint32_t stack[StackSize]; uint32_t stack[StackSize];
void routine() {
while(true) {
if(DataReadyCallback::callback) {
DataReadyCallback::callback();
}
CD::internal::IRQ::resume_at0(CD::internal::BCDTimeStamp::from(222));
CD::internal::NewCommand::send(CD_IO::Command::ReadS);
SysCall::EnterCriticalSection();
MainThread::restore();
}
}
} }
} }
} }