Use GlobalTime
This commit is contained in:
parent
3c1d965cc5
commit
149105a3fa
|
@ -36,6 +36,10 @@ namespace JabyEngine {
|
|||
Status.write(Status.read().clear_bit(irq));
|
||||
}
|
||||
|
||||
static void disable_irq(Bit<uint32_t> irq) {
|
||||
Mask.write(Mask.read().clear_bit(irq));
|
||||
}
|
||||
|
||||
static void enable_irq(Bit<uint32_t> irq) {
|
||||
Mask.write(Mask.read().set_bit(irq));
|
||||
}
|
||||
|
|
|
@ -32,10 +32,11 @@ namespace JabyEngine {
|
|||
};
|
||||
|
||||
struct __no_align Timer {
|
||||
IOPort<uint32_t> value;
|
||||
IOPort<CounterMode> mode;
|
||||
IOPort<CounterTarget> target;
|
||||
private:
|
||||
uint32_t _unused[2];
|
||||
uint32_t _unused[1];
|
||||
};
|
||||
|
||||
namespace Counter0 {
|
||||
|
@ -86,7 +87,7 @@ namespace JabyEngine {
|
|||
};
|
||||
}
|
||||
|
||||
__declare_io_port_global_array(Timer, Counter, 0x1F801104, 3);
|
||||
__declare_io_port_global_array(Timer, Counter, 0x1F801100, 3);
|
||||
static_assert(sizeof(Timer) == 0x10);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ namespace JabyEngine {
|
|||
|
||||
public:
|
||||
constexpr size_t milliseconds_to(const TimeStamp& ts) const {
|
||||
return (ts.value - this->value);
|
||||
return (ts.value - this->value)*10;
|
||||
}
|
||||
|
||||
friend class GlobalTime;
|
||||
};
|
||||
|
||||
private:
|
||||
static size_t global_counter;
|
||||
static volatile size_t global_counter;
|
||||
|
||||
public:
|
||||
GlobalTime() = delete;
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue