Sketch Timer and implement Interrupt support

This commit is contained in:
jaby 2023-01-06 15:18:35 +01:00
parent d0f52aa494
commit b9b3656180
6 changed files with 102 additions and 11 deletions

View File

@ -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__

View File

@ -31,15 +31,12 @@ namespace JabyEngine {
};
struct __no_align Timer {
IOPort<CounterMode> counter_mode;
IOPort<CounterTarget> counter_target;
IOPort<CounterMode> mode;
IOPort<CounterTarget> target;
private:
uint32_t _unused[2];
};
__declare_io_port_global_array(Timer, timer, 0x1F801104, 3);
static_assert(sizeof(Timer) == 0x10);
namespace Counter0 {
struct SyncMode {
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);
};
}
__declare_io_port_global_array(Timer, Counter, 0x1F801104, 3);
static_assert(sizeof(Timer) == 0x10);
}
}

View File

@ -40,10 +40,13 @@ enum __syscall_PriorityChain {
static __constexpr const uint32_t SkipHandler = 0;
static __constexpr const uint32_t ExecuteHandler = 1;
typedef uint32_t (*InterruptVerifier)();
typedef uint32_t (*InterruptHandler)(uint32_t);
struct __no_align __syscall_InterruptElement {
struct __syscall_InterruptElement *next;
void (*handler)(uint32_t);
uint32_t (*verifier)();
struct __syscall_InterruptElement* next;
InterruptHandler handler_function;
InterruptVerifier verifier_function;
uint32_t notUsed;
};

View File

@ -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__

View File

@ -6,9 +6,9 @@ namespace JabyEngine {
// Just testing around
static constexpr auto wuff = CounterMode::with(CounterMode::IRQAtMax, Counter0::SyncMode::Zero_At_Hblank);
timer[0].counter_mode = wuff;
timer[0].counter_mode = wuff;
timer[0].counter_mode = wuff;
Counter[0].mode = wuff;
Counter[0].mode = wuff;
Counter[0].mode = wuff;
}
}
}

View File

@ -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;
}
}
}