Use GlobalTime

This commit is contained in:
2023-01-08 16:20:30 +01:00
parent d403aedf16
commit 7b1cefac0a
8 changed files with 55 additions and 12 deletions

View File

@@ -4,6 +4,8 @@
#include <PSX/System/IOPorts/dma_io.hpp>
#include <PSX/System/IOPorts/gpu_io.hpp>
#include <stdio.h>
namespace JabyEngine {
namespace GPU {
namespace Screen {
@@ -94,6 +96,7 @@ namespace JabyEngine {
}
static void set_src(uintptr_t adr) {
printf("Source: 0x%p\n", adr);
::JabyEngine::DMA::GPU.adr.write(::JabyEngine::DMA::MADR::MemoryAdr.with(static_cast<uint32_t>(adr)));
}

View File

@@ -1,5 +1,7 @@
#include "BootLoader/boot_loader.hpp"
#include <PSX/System/IOPorts/dMa_io.hpp>
#include <PSX/Timer/timer.hpp>
#include <stdio.h>
namespace JabyEngine {
@@ -14,8 +16,13 @@ namespace JabyEngine {
SPU::stop_voices();
Timer::setup();
const auto start = GlobalTime::get_time_stamp();
printf("Start...\n");
GPU::setup();
GPU::display_logo();
const auto end = GlobalTime::get_time_stamp();
printf("GPU setup took %ims\n", start.milliseconds_to(end));
//Pause??
SPU::setup();

View File

@@ -2,19 +2,46 @@
#include <PSX/System/IOPorts/timer_io.hpp>
#include <PSX/System/syscalls.h>
#include <GPU/gpu.hpp>
#include <stdio.h>
namespace JabyEngine {
namespace Timer {
extern InterrupCallback IRQCallback;
void setup() {
static constexpr auto Mode = CounterMode::with(CounterMode::FreeRun, Counter2::SyncMode::Freerun, CounterMode::ResetAfterTarget, CounterMode::IRQAtTarget, CounterMode::IRQEveryTime, Counter2::Source::System_Clock_Div_8);
static constexpr uint16_t Target = 0x1234;
static constexpr double CPU_Frequency_Hz = 33868800.0;
static constexpr double CPU_Frequncey_Hz_Div8 = (CPU_Frequency_Hz/8.0);
//Counter[2].target.ref().set(CounterTarget::CounterTargetValue.with(Target));
template<typename T>
static constexpr T NS_Per_Tick(double CPU_Frequency_Hz) {
return static_cast<T>((1.0/CPU_Frequency_Hz)*1000.0*1000.0*1000.0);
}
template<typename T>
static constexpr T US_Per_Tick(double CPU_Frequency_Hz) {
return static_cast<T>((1000.0/NS_Per_Tick<double>(CPU_Frequency_Hz)));
}
template<typename T>
static constexpr T MS_Per_Tick(double CPU_Frequency_Hz) {
return static_cast<T>(((1000.0*1000.0)/NS_Per_Tick<double>(CPU_Frequency_Hz)));
}
void setup() {
static constexpr auto Mode = CounterMode::with(CounterMode::FreeRun, Counter2::SyncMode::Freerun, CounterMode::ResetAfterTarget, CounterMode::IRQAtTarget, CounterMode::IRQEveryTime, CounterMode::IRQPulse, Counter2::Source::System_Clock_Div_8);
static constexpr uint16_t Target = MS_Per_Tick<uint16_t>(CPU_Frequncey_Hz_Div8)*10;
printf("Timer2 Target: %i\n", Target);
Interrupt::disable_irq(Interrupt::Timer2);
__syscall_EnterCriticalSection();
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
__syscall_SysEnqIntRP(Timer2Irq, &IRQCallback);
__syscall_ExitCriticalSection();
Counter[2].target.write(CounterTarget::CounterTargetValue.with(Target));
Counter[2].mode.write(Mode);
Interrupt::enable_irq(Interrupt::Timer2);
}
}

View File

@@ -1,16 +1,15 @@
#define private public
#include <PSX/System/IOPorts/interrupt_io.hpp>
#include <PSX/System/IOPorts/timer_io.hpp>
#include <PSX/System/syscalls.h>
#include <PSX/Timer/timer.hpp>
#undef private
namespace JabyEngine {
size_t GlobalTime :: global_counter = 0;
volatile size_t GlobalTime :: global_counter = 0;
namespace Timer {
InterruptVerifierResult interrupt_verifier() {
const auto irq_status = Interrupt::Status.read();
if(Interrupt::is_irq(Interrupt::Timer2)) {
return InterruptVerifierResult::ExecuteHandler;
}

View File

@@ -1,6 +1,8 @@
#include "../include/BootLoader/boot_loader.hpp"
#include <stdio.h>
#include <PSX/Timer/timer.hpp>
namespace JabyEngine {
static NextRoutine execute(NextRoutine routine) {
// Support currently only direct call