Sketch Timer and implement Interrupt support
This commit is contained in:
parent
6608d92934
commit
ec6b93942c
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef __JABYENGINE_INTERRUPT_IO_HPP__
|
||||||
|
#define __JABYENGINE_INTERRUPT_IO_HPP__
|
||||||
|
#include "ioport.hpp"
|
||||||
|
|
||||||
|
namespace JabyEngine {
|
||||||
|
namespace Interrupt {
|
||||||
|
static constexpr auto VBlank = Bit<uint32_t>(0);
|
||||||
|
static constexpr auto GPU = Bit<uint32_t>(1);
|
||||||
|
static constexpr auto CDROM = Bit<uint32_t>(2);
|
||||||
|
static constexpr auto DMA = Bit<uint32_t>(3);
|
||||||
|
static constexpr auto Timer0 = Bit<uint32_t>(4);
|
||||||
|
static constexpr auto Timer1 = Bit<uint32_t>(5);
|
||||||
|
static constexpr auto Timer2 = Bit<uint32_t>(6);
|
||||||
|
static constexpr auto Periphery = Bit<uint32_t>(7);
|
||||||
|
static constexpr auto SIO = Bit<uint32_t>(8);
|
||||||
|
static constexpr auto SPU = Bit<uint32_t>(9);
|
||||||
|
static constexpr auto Controller = Bit<uint32_t>(10);
|
||||||
|
static constexpr auto LightPen = Controller;
|
||||||
|
|
||||||
|
__declare_io_port_global(ComplexBitMap<uint32_t>, Status, 0x1F801070);
|
||||||
|
__declare_io_port_global(ComplexBitMap<uint32_t>, Mask, 0x1F801074);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //!__JABYENGINE_INTERRUPT_IO_HPP__
|
|
@ -31,15 +31,12 @@ namespace JabyEngine {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __no_align Timer {
|
struct __no_align Timer {
|
||||||
IOPort<CounterMode> counter_mode;
|
IOPort<CounterMode> mode;
|
||||||
IOPort<CounterTarget> counter_target;
|
IOPort<CounterTarget> target;
|
||||||
private:
|
private:
|
||||||
uint32_t _unused[2];
|
uint32_t _unused[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
__declare_io_port_global_array(Timer, timer, 0x1F801104, 3);
|
|
||||||
static_assert(sizeof(Timer) == 0x10);
|
|
||||||
|
|
||||||
namespace Counter0 {
|
namespace Counter0 {
|
||||||
struct SyncMode {
|
struct SyncMode {
|
||||||
static constexpr auto Pause_During_Hblank = CounterMode::SyncMode.with(0);
|
static constexpr auto Pause_During_Hblank = CounterMode::SyncMode.with(0);
|
||||||
|
@ -87,6 +84,9 @@ namespace JabyEngine {
|
||||||
static constexpr auto System_Clock_Div_8_Too = CounterMode::ClockSource.with(3);
|
static constexpr auto System_Clock_Div_8_Too = CounterMode::ClockSource.with(3);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__declare_io_port_global_array(Timer, Counter, 0x1F801104, 3);
|
||||||
|
static_assert(sizeof(Timer) == 0x10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,13 @@ enum __syscall_PriorityChain {
|
||||||
static __constexpr const uint32_t SkipHandler = 0;
|
static __constexpr const uint32_t SkipHandler = 0;
|
||||||
static __constexpr const uint32_t ExecuteHandler = 1;
|
static __constexpr const uint32_t ExecuteHandler = 1;
|
||||||
|
|
||||||
|
typedef uint32_t (*InterruptVerifier)();
|
||||||
|
typedef uint32_t (*InterruptHandler)(uint32_t);
|
||||||
|
|
||||||
struct __no_align __syscall_InterruptElement {
|
struct __no_align __syscall_InterruptElement {
|
||||||
struct __syscall_InterruptElement* next;
|
struct __syscall_InterruptElement* next;
|
||||||
void (*handler)(uint32_t);
|
InterruptHandler handler_function;
|
||||||
uint32_t (*verifier)();
|
InterruptVerifier verifier_function;
|
||||||
uint32_t notUsed;
|
uint32_t notUsed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
#ifndef __JABYENGINE_TIMER_HPP__
|
||||||
|
#define __JABYENGINE_TIMER_HPP__
|
||||||
|
#include "../jabyengine_defines.h"
|
||||||
|
|
||||||
|
namespace JabyEngine {
|
||||||
|
class GlobalTime {
|
||||||
|
public:
|
||||||
|
class TimeStamp {
|
||||||
|
private:
|
||||||
|
size_t value;
|
||||||
|
|
||||||
|
constexpr TimeStamp(size_t value) : value(value) {}
|
||||||
|
|
||||||
|
public:
|
||||||
|
constexpr size_t milliseconds_to(const TimeStamp& ts) const {
|
||||||
|
return (ts.value - this->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend class GlobalTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
static size_t global_counter;
|
||||||
|
|
||||||
|
public:
|
||||||
|
GlobalTime() = delete;
|
||||||
|
~GlobalTime() = delete;
|
||||||
|
|
||||||
|
static TimeStamp get_time_stamp() {
|
||||||
|
return TimeStamp(GlobalTime::global_counter);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //!__JABYENGINE_TIMER_HPP__
|
|
@ -6,9 +6,9 @@ namespace JabyEngine {
|
||||||
// Just testing around
|
// Just testing around
|
||||||
static constexpr auto wuff = CounterMode::with(CounterMode::IRQAtMax, Counter0::SyncMode::Zero_At_Hblank);
|
static constexpr auto wuff = CounterMode::with(CounterMode::IRQAtMax, Counter0::SyncMode::Zero_At_Hblank);
|
||||||
|
|
||||||
timer[0].counter_mode = wuff;
|
Counter[0].mode = wuff;
|
||||||
timer[0].counter_mode = wuff;
|
Counter[0].mode = wuff;
|
||||||
timer[0].counter_mode = wuff;
|
Counter[0].mode = wuff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
#define private public
|
||||||
|
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
||||||
|
#include <PSX/System/syscalls.h>
|
||||||
|
#include <PSX/Timer/timer.hpp>
|
||||||
|
#undef private
|
||||||
|
|
||||||
|
namespace JabyEngine {
|
||||||
|
size_t GlobalTime :: global_counter = 0;
|
||||||
|
|
||||||
|
namespace Timer {
|
||||||
|
uint32_t interrupt_verifier() {
|
||||||
|
const auto irq_status = Interrupt::Status.read();
|
||||||
|
|
||||||
|
if(irq_status.is_bit_set(Interrupt::Timer0)) {
|
||||||
|
return ExecuteHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
return SkipHandler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t interrupt_handler(uint32_t) {
|
||||||
|
GlobalTime::global_counter++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue