diff --git a/include/PSX/System/IOPorts/interrupt_io.hpp b/include/PSX/System/IOPorts/interrupt_io.hpp new file mode 100644 index 00000000..7f4616a1 --- /dev/null +++ b/include/PSX/System/IOPorts/interrupt_io.hpp @@ -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(0); + static constexpr auto GPU = Bit(1); + static constexpr auto CDROM = Bit(2); + static constexpr auto DMA = Bit(3); + static constexpr auto Timer0 = Bit(4); + static constexpr auto Timer1 = Bit(5); + static constexpr auto Timer2 = Bit(6); + static constexpr auto Periphery = Bit(7); + static constexpr auto SIO = Bit(8); + static constexpr auto SPU = Bit(9); + static constexpr auto Controller = Bit(10); + static constexpr auto LightPen = Controller; + + __declare_io_port_global(ComplexBitMap, Status, 0x1F801070); + __declare_io_port_global(ComplexBitMap, Mask, 0x1F801074); + } +} + +#endif //!__JABYENGINE_INTERRUPT_IO_HPP__ \ No newline at end of file diff --git a/include/PSX/System/IOPorts/timer_io.hpp b/include/PSX/System/IOPorts/timer_io.hpp index 7fea31d1..14845672 100644 --- a/include/PSX/System/IOPorts/timer_io.hpp +++ b/include/PSX/System/IOPorts/timer_io.hpp @@ -31,15 +31,12 @@ namespace JabyEngine { }; struct __no_align Timer { - IOPort counter_mode; - IOPort counter_target; + IOPort mode; + IOPort 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); } } diff --git a/include/PSX/System/syscalls.h b/include/PSX/System/syscalls.h index 362c387a..072510b1 100644 --- a/include/PSX/System/syscalls.h +++ b/include/PSX/System/syscalls.h @@ -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; }; diff --git a/include/PSX/Timer/timer.hpp b/include/PSX/Timer/timer.hpp new file mode 100644 index 00000000..f60271cb --- /dev/null +++ b/include/PSX/Timer/timer.hpp @@ -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__ \ No newline at end of file diff --git a/src/Library/src/BootLoader/timer_boot.cpp b/src/Library/src/BootLoader/timer_boot.cpp index 4446ed69..544e4ae0 100644 --- a/src/Library/src/BootLoader/timer_boot.cpp +++ b/src/Library/src/BootLoader/timer_boot.cpp @@ -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; } } } \ No newline at end of file diff --git a/src/Library/src/Timer/timer.cpp b/src/Library/src/Timer/timer.cpp new file mode 100644 index 00000000..1b40e9e8 --- /dev/null +++ b/src/Library/src/Timer/timer.cpp @@ -0,0 +1,28 @@ +#define private public +#include +#include +#include +#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; + } + } +} \ No newline at end of file