diff --git a/include/PSX/System/IOPorts/cd_io.hpp b/include/PSX/System/IOPorts/cd_io.hpp index 5f248bf0..4c219766 100644 --- a/include/PSX/System/IOPorts/cd_io.hpp +++ b/include/PSX/System/IOPorts/cd_io.hpp @@ -34,15 +34,15 @@ namespace JabyEngine { }; struct Interrupt { - static void enable_all(IOPort& port) { + static void enable_all(IOPortEx& port) { port.write({InterruptEnable::with(InterruptEnable::InterruptTypValue.max(), InterruptEnable::UnknownIRQ, InterruptEnable::CommandStartIRQ)}); } - static uint8_t get_type(const IOPort& port) { + static uint8_t get_type(const IOPortEx& port) { return port.read().get_value(InterruptFlag::InterruptTypValue); } - static void ack(IOPort& port) { + static void ack(IOPortEx& port) { port.write_range_value(InterruptFlag::InterruptTypValue.max()); } }; diff --git a/include/PSX/System/IOPorts/dma_io.hpp b/include/PSX/System/IOPorts/dma_io.hpp index cce389de..ea5f6468 100644 --- a/include/PSX/System/IOPorts/dma_io.hpp +++ b/include/PSX/System/IOPorts/dma_io.hpp @@ -77,9 +77,9 @@ namespace JabyEngine { }; struct __no_align Registers { - IOPort adr; - IOPort block_ctrl; - IOPort channel_ctrl; + IOPortEx adr; + IOPortEx block_ctrl; + IOPortEx channel_ctrl; }; //0: Highest, 7: Lowest diff --git a/include/PSX/System/IOPorts/ioport.hpp b/include/PSX/System/IOPorts/ioport.hpp index 33924261..c9fb78d5 100644 --- a/include/PSX/System/IOPorts/ioport.hpp +++ b/include/PSX/System/IOPorts/ioport.hpp @@ -3,7 +3,7 @@ #include "../../Auxiliary/complex_bitmap.hpp" namespace JabyEngine { - template + template class __no_align IOPort { private: volatile T value; @@ -17,10 +17,6 @@ namespace JabyEngine { return S{this->value}; } - constexpr T read_range_value(const BitRange& range) const { - return IOPort::read().get_value(range); - } - constexpr void write_raw(T value) { this->value = value; } @@ -28,9 +24,21 @@ namespace JabyEngine { constexpr void write(const S& value) { this->value = static_cast(value); } + }; - constexpr void write_range_value(const BitRangeValue& value) { - IOPort::write(S{S::with(value)}); + // For use with ComplexBitMaps or what else satisfies this API + template + class __no_align IOPortEx : public IOPort { + private: + typedef typename T::UnderlyingType Raw; + + public: + constexpr Raw read_range_value(const BitRange& range) const { + return IOPort::read().get_value(range); + } + + constexpr void write_range_value(const BitRangeValue& value) { + IOPort::write(T{T::with(value)}); } }; @@ -62,23 +70,21 @@ namespace JabyEngine { static constexpr uintptr_t IO_Base_Mask = 0xF0000000; static constexpr uintptr_t IO_Base_Adr = 0x10000000; - #define __declare_global_raw(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast(__io_port_adr(adr)) - #define __io_port_adr(adr) (IO_Base_Adr + (adr & ~IO_Base_Mask)) + #define __cast_io_adr_with_type(cv, type, name, adr) static __always_inline cv auto& name = *reinterpret_cast(__io_port_adr(adr)) - #define __declare_io_port_global_raw(cv, type, sub_type, name, adr) __declare_global_raw(cv, __collect(IOPort), name, adr) - #define __declare_io_port_global(type, name, adr) __declare_io_port_global_raw(, type::UnderlyingType, type, name, adr) - #define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type::UnderlyingType, type, name, adr) - #define __declare_io_port_global_simple(type, name, adr) __declare_io_port_global_raw(, type, type, name, adr) - #define __declare_io_port_global_const_simple(type, name, adr) __declare_io_port_global_raw(const, type, type, name, adr) + #define __declare_io_port_global(type, name, adr) __cast_io_adr_with_type(, IOPortEx, name, adr) + #define __declare_io_port_global_const(type, name, adr) __cast_io_adr_with_type(const, IOPortEx, name, adr) + #define __declare_io_port_global_simple(type, name, adr) __cast_io_adr_with_type(, IOPort, name, adr) + #define __declare_io_port_global_const_simple(type, name, adr) __cast_io_adr_with_type(const, IOPort, name, adr) - #define __declare_io_port_member(type, name, adr) __declare_io_port_global_raw(inline, type::UnderlyingType, type, name, adr) - #define __declare_io_port_member_const(type, name, adr) __declare_io_port_global_raw(const inline, type::UnderlyingType, type, name, adr) - #define __declare_io_port_member_simple(type, name, adr) __declare_io_port_global_raw(inline, type, type, name, adr) - #define __declare_io_port_member_const_simple(type, name, adr) __declare_io_port_global_raw(const inline, type, type, name, adr) + #define __declare_io_port_member(type, name, adr) __cast_io_adr_with_type(inline, IOPortEx, name, adr) + #define __declare_io_port_member_const(type, name, adr) __cast_io_adr_with_type(const inline, IOPortEx, name, adr) + #define __declare_io_port_member_simple(type, name, adr) __cast_io_adr_with_type(inline, IOPort, name, adr) + #define __declare_io_port_member_const_simple(type, name, adr) __cast_io_adr_with_type(const inline, IOPort, name, adr) - #define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast(*reinterpret_cast((IO_Base_Adr + (adr & ~IO_Base_Mask)))) + #define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast(*reinterpret_cast(__io_port_adr(adr))) #define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast(__io_port_adr(adr)) } #endif //!__JABYENGINE_IOPORT_HPP__ \ No newline at end of file diff --git a/include/PSX/System/IOPorts/spu_io.hpp b/include/PSX/System/IOPorts/spu_io.hpp index 287cb86d..5b542909 100644 --- a/include/PSX/System/IOPorts/spu_io.hpp +++ b/include/PSX/System/IOPorts/spu_io.hpp @@ -114,9 +114,9 @@ namespace JabyEngine { static constexpr size_t VoiceCount = 24; struct Key { - __declare_global_raw(inline, ubus32_t, On, 0x1F801D88); - __declare_global_raw(inline, ubus32_t, Off, 0x1F801D8C); - __declare_global_raw(inline, ubus32_t, Status, 0x1F801D9C); + __cast_io_adr_with_type(inline, ubus32_t, On, 0x1F801D88); + __cast_io_adr_with_type(inline, ubus32_t, Off, 0x1F801D8C); + __cast_io_adr_with_type(inline, ubus32_t, Status, 0x1F801D9C); }; struct MainVolume { diff --git a/include/PSX/System/IOPorts/timer_io.hpp b/include/PSX/System/IOPorts/timer_io.hpp index 49b4863b..48521ceb 100644 --- a/include/PSX/System/IOPorts/timer_io.hpp +++ b/include/PSX/System/IOPorts/timer_io.hpp @@ -30,9 +30,9 @@ namespace JabyEngine { }; struct __no_align Counter { - IOPort value; - IOPort mode; - IOPort target; + IOPortEx value; + IOPortEx mode; + IOPortEx target; private: uint32_t _unused; };