Prepare CD Callback handler
This commit is contained in:
parent
d628375a18
commit
d8aee97397
|
@ -3,9 +3,9 @@
|
|||
|
||||
namespace JabyEngine {
|
||||
namespace Callback {
|
||||
using Function = void (*)();
|
||||
|
||||
struct VSyncCallback {
|
||||
struct [[deprecated("Currently not supported")]] VSyncCallback {
|
||||
using Function = void (*)();
|
||||
|
||||
static Function callback;
|
||||
|
||||
static void install(Function function) {
|
||||
|
@ -16,17 +16,5 @@ namespace JabyEngine {
|
|||
VSyncCallback::install(nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
struct DataReadyCallback {
|
||||
static Function callback;
|
||||
|
||||
static void install(Function function) {
|
||||
DataReadyCallback::callback = function;
|
||||
}
|
||||
|
||||
static void uninstall() {
|
||||
DataReadyCallback::install(nullptr);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -44,6 +44,7 @@ namespace JabyEngine {
|
|||
}
|
||||
|
||||
static void restore() {
|
||||
SysCall::EnterCriticalSection();
|
||||
MainThread::prepare_restore();
|
||||
Thread::execute_next();
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace JabyEngine {
|
|||
Internal::send(cmd, true, args...);
|
||||
}
|
||||
|
||||
template<typename...ARGS>
|
||||
template<typename...ARGS>
|
||||
static void sendX(CD_IO::Command::Desc cmd, ARGS...args) {
|
||||
Internal::send(cmd, false, args...);
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ template<typename...ARGS>
|
|||
};
|
||||
|
||||
namespace IRQ {
|
||||
void data_ready_handler(uint32_t data);
|
||||
void read_sector_to0(uint32_t* dst, size_t bytes);
|
||||
void resume_at0(const BCDTimeStamp& cd_time);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
namespace JabyEngine {
|
||||
namespace Callback {
|
||||
namespace internal {
|
||||
static void execute_thread(SysCall::ThreadHandle thread_handle) {
|
||||
MainThread::prepare_if_main(thread_handle);
|
||||
Thread::execute_next();
|
||||
}
|
||||
|
||||
namespace VSync {
|
||||
static constexpr size_t StackSize = 64;
|
||||
|
||||
|
@ -11,22 +16,19 @@ namespace JabyEngine {
|
|||
extern uint32_t stack[StackSize];
|
||||
void routine();
|
||||
|
||||
static void execute() {
|
||||
MainThread::prepare_if_main(VSync::thread_handle);
|
||||
Thread::execute_next();
|
||||
static void [[deprecated("Currently not in use")]] execute() {
|
||||
execute_thread(VSync::thread_handle);
|
||||
}
|
||||
}
|
||||
|
||||
namespace DataReady {
|
||||
namespace CD {
|
||||
static constexpr size_t StackSize = 256;
|
||||
|
||||
extern SysCall::ThreadHandle thread_handle;
|
||||
extern uint32_t stack[StackSize];
|
||||
void routine();
|
||||
|
||||
static void execute() {
|
||||
MainThread::prepare_if_main(DataReady::thread_handle);
|
||||
Thread::execute_next();
|
||||
execute_thread(CD::thread_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "../../internal-include/BootLoader/boot_loader.hpp"
|
||||
#include "../../internal-include/CD/cd_internal.hpp"
|
||||
#include "../../internal-include/System/callbacks_internal.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
|
@ -8,19 +9,19 @@ namespace JabyEngine {
|
|||
|
||||
void setup() {
|
||||
SysCall::EnterCriticalSection();
|
||||
InternalCallback::VSync::thread_handle = SysCall::OpenThread(
|
||||
/*InternalCallback::VSync::thread_handle = SysCall::OpenThread(
|
||||
InternalCallback::VSync::routine,
|
||||
&InternalCallback::VSync::stack[InternalCallback::VSync::StackSize - 1],
|
||||
SysCall::get_gp()
|
||||
);
|
||||
InternalCallback::DataReady::thread_handle = SysCall::OpenThread(
|
||||
InternalCallback::DataReady::routine,
|
||||
&InternalCallback::DataReady::stack[InternalCallback::DataReady::StackSize - 1],
|
||||
SysCall::get_gp()
|
||||
);
|
||||
Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);*/
|
||||
|
||||
Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);
|
||||
Thread::set_user_mode_for(InternalCallback::DataReady::thread_handle);
|
||||
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()
|
||||
);
|
||||
Thread::set_user_mode_for(InternalCallback::CD::thread_handle);
|
||||
SysCall::ExitCriticalSection();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,8 +103,8 @@ namespace JabyEngine {
|
|||
}
|
||||
|
||||
static void handler(uint32_t) {
|
||||
const auto old_status = CD_IO::IndexStatus.read();
|
||||
bool run_callback = false;
|
||||
const auto old_status = CD_IO::IndexStatus.read();
|
||||
void (*exit_routine)() = Callback::internal::CD::execute;
|
||||
|
||||
CD_IO::PortIndex1::change_to();
|
||||
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
|
||||
|
@ -114,7 +114,6 @@ namespace JabyEngine {
|
|||
if(current_state != State::XAMode) {
|
||||
switch(cur_irq) {
|
||||
case CD_IO::Interrupt::DataReady: {
|
||||
run_callback = true;
|
||||
// Obtain sector content here
|
||||
auto* sector = sector_allocator.allocate_sector();
|
||||
if(sector) {
|
||||
|
@ -152,11 +151,12 @@ namespace JabyEngine {
|
|||
|
||||
// No masking required because we can only write bit 0 - 2
|
||||
CD_IO::IndexStatus.write(old_status);
|
||||
exit_routine();
|
||||
}
|
||||
|
||||
if(run_callback) {
|
||||
Callback::internal::DataReady::execute();
|
||||
}
|
||||
SysCall::ReturnFromException();
|
||||
void data_ready_handler(uint32_t data) {
|
||||
printf("Data: %i\n", data);
|
||||
MainThread::restore();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ namespace JabyEngine {
|
|||
const uint8_t mode = XAAudioSectorMode.raw | (double_speed ? DoubleSpeedBit : SingleSpeedBit);
|
||||
|
||||
NewCommand::send(CD_IO::Command::SetMode, mode);
|
||||
//current_state = State::XAMode;
|
||||
current_state = State::XAMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@
|
|||
|
||||
namespace JabyEngine {
|
||||
namespace Callback {
|
||||
Function VSyncCallback :: callback = nullptr;
|
||||
Function DataReadyCallback :: callback = nullptr;
|
||||
// Marked deprecated currently
|
||||
/*using Function = VSyncCallback::Function;
|
||||
Function VSyncCallback :: callback = nullptr;*/
|
||||
|
||||
namespace internal {
|
||||
namespace VSync {
|
||||
|
@ -14,32 +15,18 @@ namespace JabyEngine {
|
|||
|
||||
void routine() {
|
||||
while(true) {
|
||||
if(VSyncCallback::callback) {
|
||||
// Marked deprecated currently
|
||||
/*if(VSyncCallback::callback) {
|
||||
VSyncCallback::callback();
|
||||
}
|
||||
SysCall::EnterCriticalSection();
|
||||
}*/
|
||||
MainThread::restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace DataReady {
|
||||
namespace CD {
|
||||
SysCall::ThreadHandle thread_handle = 0;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue