Introduce new timer based on vsync

This commit is contained in:
2023-08-27 21:29:43 +02:00
parent db2e5543df
commit c40a8f44a5
6 changed files with 129 additions and 22 deletions

View File

@@ -1,4 +1,8 @@
#include "../../internal-include/GPU/gpu_internal.hpp"
// We need to access the master time
#define private public
#include <PSX/Timer/frame_timer.hpp>
#undef private
#include <PSX/System/IOPorts/interrupt_io.hpp>
#include <PSX/System/syscalls.h>
@@ -7,12 +11,12 @@ namespace JabyEngine {
uint8_t Display :: current_id = 1; //< Setup will call exchange and set it to 0
namespace internal {
static uint8_t vsync_count = 0;
static InterruptVerifierResult interrupt_verifier();
static void interrupt_handler(uint32_t);
InterrupCallback callback = {
static uint8_t vsync_counter = 0;
InterrupCallback callback = {
.next = nullptr,
.handler_function = reinterpret_cast<InterruptHandler>(interrupt_handler),
.verifier_function = interrupt_verifier
@@ -29,9 +33,8 @@ namespace JabyEngine {
}
static void interrupt_handler(uint32_t) {
if(vsync_count != 0xFF) {
vsync_count++;
}
vsync_counter++;
MasterTime::value++;
Interrupt::ack_irq(Interrupt::VBlank);
__syscall_ReturnFromException();
@@ -47,14 +50,10 @@ namespace JabyEngine {
}
void wait_vsync(uint8_t syncs) {
volatile uint8_t& vsync_count = reinterpret_cast<volatile uint8_t&>(internal::vsync_count);
volatile auto& vsync_count = reinterpret_cast<volatile uint8_t&>(vsync_counter);
const uint8_t dst_value = vsync_count + syncs;
if(internal::vsync_count >= syncs) {
syncs = internal::vsync_count + 1;
}
while(vsync_count < syncs);
vsync_count = 0;
while(vsync_count != dst_value);
}
void render(const uint32_t* data, size_t words) {

View File

@@ -0,0 +1,5 @@
#include <PSX/Timer/frame_timer.hpp>
namespace JabyEngine {
uint32_t MasterTime :: value = 0;
}