More cleanup

This commit is contained in:
Jaby 2023-01-15 17:14:34 +01:00
parent a58d352790
commit 35d5662d3b
5 changed files with 37 additions and 31 deletions

View File

@ -34,15 +34,15 @@ namespace JabyEngine {
};
struct Interrupt {
static void enable_all(IOPort<InterruptEnable::UnderlyingType, InterruptEnable>& port) {
static void enable_all(IOPortEx<InterruptEnable>& port) {
port.write({InterruptEnable::with(InterruptEnable::InterruptTypValue.max(), InterruptEnable::UnknownIRQ, InterruptEnable::CommandStartIRQ)});
}
static uint8_t get_type(const IOPort<InterruptFlag::UnderlyingType, InterruptFlag>& port) {
static uint8_t get_type(const IOPortEx<InterruptFlag>& port) {
return port.read().get_value(InterruptFlag::InterruptTypValue);
}
static void ack(IOPort<InterruptFlag::UnderlyingType, InterruptFlag>& port) {
static void ack(IOPortEx<InterruptFlag>& port) {
port.write_range_value(InterruptFlag::InterruptTypValue.max());
}
};

View File

@ -77,9 +77,9 @@ namespace JabyEngine {
};
struct __no_align Registers {
IOPort<MADR::UnderlyingType, MADR> adr;
IOPort<BCR::UnderlyingType, BCR> block_ctrl;
IOPort<CHCHR::UnderlyingType, CHCHR> channel_ctrl;
IOPortEx<MADR> adr;
IOPortEx<BCR> block_ctrl;
IOPortEx<CHCHR> channel_ctrl;
};
//0: Highest, 7: Lowest

View File

@ -3,7 +3,7 @@
#include "../../Auxiliary/complex_bitmap.hpp"
namespace JabyEngine {
template<typename T, typename S/* = T*/>
template<typename T, typename S = T>
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<T>& 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<T>(value);
}
};
constexpr void write_range_value(const BitRangeValue<T>& value) {
IOPort<T, S>::write(S{S::with(value)});
// For use with ComplexBitMaps or what else satisfies this API
template<typename T>
class __no_align IOPortEx : public IOPort<typename T::UnderlyingType, T> {
private:
typedef typename T::UnderlyingType Raw;
public:
constexpr Raw read_range_value(const BitRange<Raw>& range) const {
return IOPort<Raw, T>::read().get_value(range);
}
constexpr void write_range_value(const BitRangeValue<Raw>& value) {
IOPort<Raw, T>::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<type*>(__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<type*>(__io_port_adr(adr))
#define __declare_io_port_global_raw(cv, type, sub_type, name, adr) __declare_global_raw(cv, __collect(IOPort<type, sub_type>), 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<type>, name, adr)
#define __declare_io_port_global_const(type, name, adr) __cast_io_adr_with_type(const, IOPortEx<type>, name, adr)
#define __declare_io_port_global_simple(type, name, adr) __cast_io_adr_with_type(, IOPort<type>, name, adr)
#define __declare_io_port_global_const_simple(type, name, adr) __cast_io_adr_with_type(const, IOPort<type>, 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<type>, name, adr)
#define __declare_io_port_member_const(type, name, adr) __cast_io_adr_with_type(const inline, IOPortEx<type>, name, adr)
#define __declare_io_port_member_simple(type, name, adr) __cast_io_adr_with_type(inline, IOPort<type>, name, adr)
#define __declare_io_port_member_const_simple(type, name, adr) __cast_io_adr_with_type(const inline, IOPort<type>, name, adr)
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>((IO_Base_Adr + (adr & ~IO_Base_Mask))))
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>(__io_port_adr(adr)))
#define __declare_io_port_global_struct(type, name, adr) static __always_inline auto& name = *reinterpret_cast<type*>(__io_port_adr(adr))
}
#endif //!__JABYENGINE_IOPORT_HPP__

View File

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

View File

@ -30,9 +30,9 @@ namespace JabyEngine {
};
struct __no_align Counter {
IOPort<CounterValue::UnderlyingType, CounterValue> value;
IOPort<CounterMode::UnderlyingType, CounterMode> mode;
IOPort<CounterTarget::UnderlyingType, CounterTarget> target;
IOPortEx<CounterValue> value;
IOPortEx<CounterMode> mode;
IOPortEx<CounterTarget> target;
private:
uint32_t _unused;
};