jabyengine/include/PSX/System/IOPorts/timer_io.hpp

116 lines
5.4 KiB
C++

#ifndef __JABYENGINE_TIMER_IO_HPP__
#define __JABYENGINE_TIMER_IO_HPP__
#include "ioport.hpp"
namespace JabyEngine {
namespace Timer_IO {
__new_declare_io_value(CounterMode, uint32_t) {
static constexpr auto SyncEnable = Bit(0);
static constexpr auto FreeRun = !SyncEnable;
static constexpr auto SyncMode = BitRange::from_to(1, 2);
static constexpr auto ResetAfterTarget = Bit(3);
static constexpr auto IRQAtTarget = Bit(4);
static constexpr auto IRQAtMax = Bit(5);
static constexpr auto IRQEveryTime = Bit(6);
static constexpr auto IRQOneShot = !IRQEveryTime;
static constexpr auto IRQToggle = Bit(7);
static constexpr auto IRQPulse = !IRQToggle;
static constexpr auto ClockSource = BitRange::from_to(8, 9);
static constexpr auto HasIRQRequest = Bit(10);
static constexpr auto IsTargetReached = Bit(11);
static constexpr auto IsMaxReached = Bit(12);
};
__new_declare_io_value(CounterTarget, uint32_t) {
static constexpr auto CounterTargetValue = BitRange::from_to(0, 15);
};
__new_declare_io_value(CounterValue, uint32_t) {
static constexpr auto Value = BitRange::from_to(0, 15);
};
#pragma pack(push, 1)
struct Counter {
New::IOPort<CounterValue> value;
New::IOPort<CounterMode> mode;
New::IOPort<CounterTarget> target;
private:
uint32_t _unused;
public:
inline uint16_t get_current_value() const {
return this->value.read().get2(CounterValue::Value);
}
inline void set_target_value(uint16_t value) {
this->target.write(CounterTarget{0}.set_range(CounterTarget::CounterTargetValue, value));
}
inline void set_mode(CounterMode mode) {
this->mode.write(mode);
}
};
#pragma pack(pop)
static constexpr uintptr_t counter_base_adr(size_t ID) {
return (0x1F801100 + (ID*0x10));
}
#pragma pack(push, 1)
struct Counter0 : public Counter {
struct SyncMode {
static constexpr auto Zero_At_Hblank = CounterMode::SyncMode.with(1u);
static constexpr auto Pause_During_Hblank = CounterMode::SyncMode.with(0u);
static constexpr auto Zero_At_Hblank_Pause_Outside_Hblank = CounterMode::SyncMode.with(2u);
static constexpr auto Pause_Until_Hblank_Then_Freerun = CounterMode::SyncMode.with(3u);
};
struct Source {
static constexpr auto System_Clock = CounterMode::ClockSource.with(0u);
static constexpr auto Dot_Clock = CounterMode::ClockSource.with(1u);
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(2u);
static constexpr auto Dot_Clock_Too = CounterMode::ClockSource.with(3u);
};
};
struct Counter1 : public Counter {
struct SyncMode {
static constexpr auto Pause_During_Vblank = CounterMode::SyncMode.with(0u);
static constexpr auto Zero_At_Vblank = CounterMode::SyncMode.with(1u);
static constexpr auto Zero_At_Vblank_Pause_Outside_Vblank = CounterMode::SyncMode.with(2u);
static constexpr auto Pause_Until_Vblank_Then_FreeRun = CounterMode::SyncMode.with(3u);
};
struct Source {
static constexpr auto System_Clock = CounterMode::ClockSource.with(0u);
static constexpr auto Hblank = CounterMode::ClockSource.with(1u);
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(2u);
static constexpr auto Hblank_Too = CounterMode::ClockSource.with(3u);
};
};
struct Counter2 : public Counter {
struct SyncMode {
static constexpr auto Stop_Counter = CounterMode::SyncMode.with(0u);
static constexpr auto FreeRun = CounterMode::SyncMode.with(1u);
static constexpr auto FreeRun_Too = CounterMode::SyncMode.with(2u);
static constexpr auto Stop_Counter_Too = CounterMode::SyncMode.with(3u);
};
struct Source {
static constexpr auto System_Clock = CounterMode::ClockSource.with(0u);
static constexpr auto System_Clock_Too = CounterMode::ClockSource.with(1u);
static constexpr auto System_Clock_Div_8 = CounterMode::ClockSource.with(2u);
static constexpr auto System_Clock_Div_8_Too = CounterMode::ClockSource.with(3u);
};
};
#pragma pack(pop)
__new_declare_value_at(, struct Counter0, Counter0, counter_base_adr(0));
__new_declare_value_at(, struct Counter1, Counter1, counter_base_adr(1));
__new_declare_value_at(, struct Counter2, Counter2, counter_base_adr(2));
}
}
#endif //!__JABYENGINE_TIMER_IO_HPP__