From 00fc6fcf15a6e9dbf50403a941f3bde510d8d63f Mon Sep 17 00:00:00 2001 From: Jaby Date: Wed, 22 Mar 2023 21:23:52 +0100 Subject: [PATCH] More cleanup --- include/PSX/System/IOPorts/interrupt_io.hpp | 6 +-- include/PSX/System/IOPorts/ioport.hpp | 45 +++++---------------- include/PSX/System/IOPorts/spu_io.hpp | 8 ++-- 3 files changed, 19 insertions(+), 40 deletions(-) diff --git a/include/PSX/System/IOPorts/interrupt_io.hpp b/include/PSX/System/IOPorts/interrupt_io.hpp index 83683d39..cb2aeb3f 100644 --- a/include/PSX/System/IOPorts/interrupt_io.hpp +++ b/include/PSX/System/IOPorts/interrupt_io.hpp @@ -26,15 +26,15 @@ namespace JabyEngine { __declare_new_io_port(Status, 0x1F801070); __declare_new_io_port(Mask, 0x1F801074); - static constexpr bool is_irq(Bit irq) { + static bool is_irq(Bit irq) { return Status.is_set(irq); } - static constexpr void ack_irq(Bit irq) { + static void ack_irq(Bit irq) { Status.clear(irq); } - static constexpr void disable_irq(Bit irq) { + static void disable_irq(Bit irq) { Mask.clear(irq); } diff --git a/include/PSX/System/IOPorts/ioport.hpp b/include/PSX/System/IOPorts/ioport.hpp index 3e7935c4..7120225f 100644 --- a/include/PSX/System/IOPorts/ioport.hpp +++ b/include/PSX/System/IOPorts/ioport.hpp @@ -20,8 +20,17 @@ namespace JabyEngine { }; } + namespace IOAdress { + constexpr uintptr_t patch_adr(uintptr_t adr) { + constexpr uintptr_t Mask = 0xF0000000; + constexpr uintptr_t Base = 0x10000000; // We might want to change this later to 0xB0000000 for caching and stuff (More research needed) + + return (Base + (adr & ~Mask)); + } + } + #define __declare_new_named_io_port(type, name, adr) \ - static inline auto& name = *reinterpret_cast(adr) + static inline auto& name = *reinterpret_cast(IOAdress::patch_adr(adr)) #define __declare_new_io_port(name, adr) \ __declare_new_named_io_port(name, name, adr) @@ -32,8 +41,8 @@ namespace JabyEngine { #define __declare_new_io_port_array(name, adr, size) \ static inline auto& name = reinterpret_cast(*reinterpret_cast(adr)) + // We need this construct to ensure the types end up being a POD - Inheritance doesn't qualify for a POD #define __declare_io_type(name, type, ...) \ - /*We need this type to be a POD sadly*/ \ template typename T> \ struct name##_io_base { \ typedef T::UnderlyingValue UnderlyingValue; \ @@ -104,19 +113,6 @@ namespace JabyEngine { typedef name##_io_base name##_v; \ typedef name##_io_base name##_t - template - struct VolatilePOD { - volatile T raw; - - constexpr T read() const { - return this->raw; - } - - constexpr void write(T value) { - this->raw = value; - } - }; - struct __no_align ubus32_t { __declare_io_type(uint16_t, uint16_t,); uint16_t_v low; @@ -144,24 +140,5 @@ namespace JabyEngine { return *this; } }; - static constexpr uintptr_t IO_Base_Mask = 0xF0000000; - static constexpr uintptr_t IO_Base_Adr = 0x10000000; - - #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(type, name, adr) __cast_io_adr_with_type(, VolatileBitMapPOD, name, adr) - #define __declare_io_port_global_const(type, name, adr) __cast_io_adr_with_type(const, VolatileBitMapPOD, name, adr) - #define __declare_io_port_global_simple(type, name, adr) __cast_io_adr_with_type(, VolatilePOD, name, adr) - #define __declare_io_port_global_const_simple(type, name, adr) __cast_io_adr_with_type(const, VolatilePOD, name, adr) - - #define __declare_io_port_member(type, name, adr) __cast_io_adr_with_type(inline, VolatileBitMapPOD, name, adr) - #define __declare_io_port_member_const(type, name, adr) __cast_io_adr_with_type(const inline, VolatileBitMapPOD, name, adr) - #define __declare_io_port_member_simple(type, name, adr) __cast_io_adr_with_type(inline, VolatilePOD, name, adr) - #define __declare_io_port_member_const_simple(type, name, adr) __cast_io_adr_with_type(const inline, VolatilePOD, name, adr) - - #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 e5450ccb..a5edfea0 100644 --- a/include/PSX/System/IOPorts/spu_io.hpp +++ b/include/PSX/System/IOPorts/spu_io.hpp @@ -118,9 +118,11 @@ namespace JabyEngine { static constexpr size_t VoiceCount = 24; struct Key { - __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); + typedef ubus32_t ubus32_v; + + __declare_new_named_io_port(ubus32, On, 0x1F801D88); + __declare_new_named_io_port(ubus32, Off, 0x1F801D8C); + __declare_new_named_io_port(ubus32, Status, 0x1F801D9C); }; struct MainVolume {