Reactive Callbacks and integrate them
This commit is contained in:
parent
c67bc7d9f9
commit
97727d5dbb
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
#include "syscalls.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Callback {
|
||||
using Function = void (*)();
|
||||
|
||||
struct VSyncCallback {
|
||||
static Function callback;
|
||||
|
||||
static void install(Function function) {
|
||||
VSyncCallback::callback = function;
|
||||
}
|
||||
|
||||
static void uninstall() {
|
||||
VSyncCallback::install(nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
struct DataReadyCallback {
|
||||
static Function callback;
|
||||
|
||||
static void install(Function function) {
|
||||
DataReadyCallback::callback = function;
|
||||
}
|
||||
|
||||
static void uninstall() {
|
||||
DataReadyCallback::install(nullptr);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
#pragma once
|
||||
#include "syscalls.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace [[deprecated("Callbacks are deprecated for now")]] Callback {
|
||||
struct VSyncCallback {
|
||||
using Function = void (*)();
|
||||
|
||||
static Function callback;
|
||||
|
||||
static void install(Function function) {
|
||||
VSyncCallback::callback = function;
|
||||
}
|
||||
|
||||
static void uninstall() {
|
||||
VSyncCallback::install(nullptr);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ namespace JabyEngine {
|
|||
void identify();
|
||||
}
|
||||
|
||||
namespace [[deprecated("Callbacks are deprecated for now")]] Callbacks {
|
||||
namespace Callbacks {
|
||||
void setup();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <PSX/System/threads.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace [[deprecated("Callbacks are deprecated for now")]] Callback {
|
||||
namespace Callback {
|
||||
namespace internal {
|
||||
namespace VSync {
|
||||
static constexpr size_t StackSize = 64;
|
||||
|
@ -16,6 +16,19 @@ namespace JabyEngine {
|
|||
Thread::execute_next();
|
||||
}
|
||||
}
|
||||
|
||||
namespace DataReady {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,14 @@ namespace JabyEngine {
|
|||
&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::DataReady::thread_handle);
|
||||
SysCall::ExitCriticalSection();
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@ namespace JabyEngine {
|
|||
static constexpr auto DebugScale = 1.0;
|
||||
|
||||
BIOS::identify();
|
||||
//Callbacks::setup();
|
||||
Callbacks::setup();
|
||||
|
||||
__debug_boot_color_at(::JabyEngine::GPU::Color24::Grey(), DebugX, DebugY, DebugScale);
|
||||
DMA::setup();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "../../internal-include/CD/cd_internal.hpp"
|
||||
#include "../../internal-include/System/callbacks_internal.hpp"
|
||||
#include <PSX/System/IOPorts/dma_io.hpp>
|
||||
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
||||
#include <PSX/System/syscalls.hpp>
|
||||
|
@ -102,7 +103,8 @@ namespace JabyEngine {
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
CD_IO::PortIndex1::change_to();
|
||||
const auto cur_irq = CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag);
|
||||
|
@ -112,6 +114,7 @@ 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) {
|
||||
|
@ -149,6 +152,10 @@ namespace JabyEngine {
|
|||
|
||||
// No masking required because we can only write bit 0 - 2
|
||||
CD_IO::IndexStatus.write(old_status);
|
||||
|
||||
if(run_callback) {
|
||||
Callback::internal::DataReady::execute();
|
||||
}
|
||||
SysCall::ReturnFromException();
|
||||
}
|
||||
}
|
||||
|
@ -203,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#include "../../internal-include/System/callbacks_internal.hpp"
|
||||
#include "../../internal-include/CD/cd_internal.hpp"
|
||||
#include <PSX/System/callbacks.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Callback {
|
||||
Function VSyncCallback :: callback = nullptr;
|
||||
Function DataReadyCallback :: callback = nullptr;
|
||||
|
||||
namespace internal {
|
||||
namespace VSync {
|
||||
SysCall::ThreadHandle thread_handle = 0;
|
||||
uint32_t stack[StackSize] = {0};
|
||||
|
||||
void routine() {
|
||||
while(true) {
|
||||
if(VSyncCallback::callback) {
|
||||
VSyncCallback::callback();
|
||||
}
|
||||
SysCall::EnterCriticalSection();
|
||||
MainThread::restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace DataReady {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
#include "../../internal-include/System/callbacks_internal.hpp"
|
||||
#include <PSX/System/callbacks.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Callback {
|
||||
VSyncCallback::Function VSyncCallback :: callback = nullptr;
|
||||
|
||||
namespace internal {
|
||||
namespace VSync {
|
||||
SysCall::ThreadHandle thread_handle = 0;
|
||||
uint32_t stack[StackSize] = {0};
|
||||
|
||||
void routine() {
|
||||
while(true) {
|
||||
if(VSyncCallback::callback) {
|
||||
VSyncCallback::callback();
|
||||
}
|
||||
SysCall::EnterCriticalSection();
|
||||
MainThread::restore();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue