Support VSync callback

This commit is contained in:
Jaby
2024-05-15 21:43:12 +02:00
parent 9ec82eba02
commit 4dab38239f
11 changed files with 156 additions and 49 deletions

View File

@@ -8,6 +8,10 @@ namespace JabyEngine {
void identify();
}
namespace Callbacks {
void setup();
}
namespace CD {
void setup();
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include <PSX/System/threads.hpp>
namespace JabyEngine {
namespace Callback {
namespace internal {
namespace VSync {
static constexpr size_t StackSize = 64;
extern SysCall::ThreadHandle thread_handle;
extern uint32_t stack[StackSize];
void routine();
static void execute() {
MainThread::prepare_if_main(VSync::thread_handle);
Thread::execute_next();
}
}
}
}
}

View File

@@ -0,0 +1,21 @@
#include "../../internal-include/BootLoader/boot_loader.hpp"
#include "../../internal-include/System/callbacks_internal.hpp"
namespace JabyEngine {
namespace boot {
namespace Callbacks {
namespace InternalCallback = JabyEngine::Callback::internal;
void setup() {
SysCall::EnterCriticalSection();
InternalCallback::VSync::thread_handle = SysCall::OpenThread(
InternalCallback::VSync::routine,
&InternalCallback::VSync::stack[InternalCallback::VSync::StackSize - 1],
SysCall::get_gp()
);
Thread::set_user_mode_for(InternalCallback::VSync::thread_handle);
SysCall::ExitCriticalSection();
}
}
}
}

View File

@@ -47,6 +47,7 @@ namespace JabyEngine {
static constexpr auto DebugScale = 1.0;
BIOS::identify();
Callbacks::setup();
__debug_boot_color_at(::JabyEngine::GPU::Color24::Grey(), DebugX, DebugY, DebugScale);
DMA::setup();
@@ -69,7 +70,6 @@ namespace JabyEngine {
test_bios_font();
test_gte_scale();
//Pause??
SPU::setup();
}
}

View File

@@ -13,9 +13,6 @@ namespace JabyEngine {
static SysCall::InterruptVerifierResult interrupt_verifier();
static uint32_t interrupt_handler(uint32_t);
static uint32_t stack[1024];
static uint32_t thread = 0;
static SectorBufferAllocator sector_allocator;
static uint32_t cur_lba;
static uint32_t dst_lba;
@@ -112,12 +109,15 @@ namespace JabyEngine {
} break;
case CD_IO::Interrupt::DataEnd: {
if(thread != 0 && table_of_tables.processes->current_tcb == &table_of_tables.threads[0]) {
//changeThread(thread);
printf("About to change...\n");
table_of_tables.processes->current_tcb = &table_of_tables.threads[thread&0xFFFF];
printf("Changed!\n");
}
CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, static_cast<uint8_t>(0x0), static_cast<uint8_t>(0x09), static_cast<uint8_t>(0x0));
CD_IO::PortIndex1::change_to();
while(CD_IO::Interrupt::get_type(CD_IO::PortIndex1::InterruptFlag) != CD_IO::Interrupt::Acknowledge);
CD_IO::Interrupt::ack_extended(CD_IO::PortIndex1::InterruptFlag);
CD_IO::PortIndex0::change_to();
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play);
} break;
case CD_IO::Interrupt::DiskError: {
@@ -152,26 +152,6 @@ namespace JabyEngine {
}
void enable_CDDA() {
if(thread == 0) {
SysCall::EnterCriticalSection();
thread = SysCall::OpenTh([]() {
printf("Hallo!\n");
CD_IO::PortIndex0::change_to();
printf("Wait...\n");
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetLoc, static_cast<uint8_t>(0x0), static_cast<uint8_t>(0x09), static_cast<uint8_t>(0x0));
printf("Done!\n");
Command::send<CD_IO::PortIndex0>(CD_IO::Command::Play);
table_of_tables.processes->current_tcb = &table_of_tables.threads[0];
SysCall::ReturnFromException();
}, &stack[1023], SysCall::get_gp());
SysCall::ExitCriticalSection();
table_of_tables.threads[thread&0xFFFF].sr = table_of_tables.threads[0].sr;
printf(">>> 0x%X\n", table_of_tables.threads[0].sr);
}
Command::wait_completed();
CD_IO::PortIndex0::change_to();
Command::send_wait<CD_IO::PortIndex0>(CD_IO::Command::SetMode, AudioSectorMode);

View File

@@ -1,4 +1,5 @@
#include "../../internal-include/GPU/gpu_internal.hpp"
#include "../../internal-include/System/callbacks_internal.hpp"
#include <PSX/Timer/frame_timer.hpp>
#include <PSX/System/IOPorts/interrupt_io.hpp>
#include <PSX/System/syscalls.hpp>
@@ -40,8 +41,7 @@ namespace JabyEngine {
MasterTime::value++;
Interrupt::ack_irq(Interrupt::VBlank);
SysCall::ReturnFromException();
__builtin_unreachable();
Callback::internal::VSync::execute();
}
uint32_t Display :: exchange_buffer_and_display() {

View File

@@ -0,0 +1,26 @@
#include "../../internal-include/System/callbacks_internal.hpp"
#include <PSX/System/callbacks.hpp>
#include <stdio.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();
}
MainThread::restore();
}
}
}
}
}
}