Introduce new timer based on vsync
This commit is contained in:
@@ -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) {
|
||||
|
5
src/Library/src/Timer/frame_timer.cpp
Normal file
5
src/Library/src/Timer/frame_timer.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <PSX/Timer/frame_timer.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
uint32_t MasterTime :: value = 0;
|
||||
}
|
Reference in New Issue
Block a user