Improve readability of code slightly
This commit is contained in:
@@ -22,11 +22,11 @@ namespace JabyEngine {
|
||||
#endif
|
||||
|
||||
static void enable() {
|
||||
GPU_IO::GP1 = *GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::On);
|
||||
GPU_IO::GP1 = GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::On);
|
||||
}
|
||||
|
||||
static void disable() {
|
||||
GPU_IO::GP1 = *GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::Off);
|
||||
GPU_IO::GP1 = GPU_IO::Command::SetDisplayState(GPU_IO::DisplayState::Off);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -95,7 +95,7 @@ namespace JabyEngine {
|
||||
}
|
||||
|
||||
static void enable_extended(InterruptEnable_v& port) {
|
||||
port = *InterruptEnable_t::from(InterruptEnable_t::InterruptTypValue.range_max<uint8_t>(), InterruptEnable_t::UnknownIRQ, InterruptEnable_t::CommandStartIRQ);
|
||||
port = InterruptEnable_t::from(InterruptEnable_t::InterruptTypValue.range_max<uint8_t>(), InterruptEnable_t::UnknownIRQ, InterruptEnable_t::CommandStartIRQ);
|
||||
}
|
||||
|
||||
static Type get_type(const InterruptFlag_v& port) {
|
||||
@@ -107,7 +107,7 @@ namespace JabyEngine {
|
||||
}
|
||||
|
||||
static void ack_extended(InterruptFlag_v& port) {
|
||||
port = *InterruptFlag_v::from(InterruptFlag_v::InterruptTypValue.range_max<uint8_t>(), InterruptEnable_v::UnknownIRQ, InterruptEnable_v::CommandStartIRQ);
|
||||
port = InterruptFlag_v::from(InterruptFlag_v::InterruptTypValue.range_max<uint8_t>(), InterruptEnable_v::UnknownIRQ, InterruptEnable_v::CommandStartIRQ);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -163,7 +163,7 @@ namespace JabyEngine {
|
||||
}
|
||||
|
||||
static constexpr GP1_t DisplayMode(DisplayMode_t mode) {
|
||||
return {Helper::construct_cmd(0x08, *mode)};
|
||||
return {Helper::construct_cmd(0x08, mode)};
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -47,15 +47,21 @@ namespace JabyEngine {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct NormalValue {
|
||||
typedef T Value;
|
||||
};
|
||||
namespace IOPort {
|
||||
struct IOValueType {
|
||||
template<typename T>
|
||||
struct Normal {
|
||||
typedef T Value;
|
||||
typedef T UnderlyingValue;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct VolatileValue {
|
||||
typedef volatile T Value;
|
||||
};
|
||||
template<typename T>
|
||||
struct Volatile {
|
||||
typedef volatile T Value;
|
||||
typedef T UnderlyingValue;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#define __declare_new_named_io_port(type, name, adr) \
|
||||
static inline auto& name = *reinterpret_cast<type##_v*>(adr)
|
||||
@@ -69,73 +75,77 @@ namespace JabyEngine {
|
||||
#define __declare_new_io_port_array(name, adr, size) \
|
||||
static inline auto& name = reinterpret_cast<name##_v(&)[size]>(*reinterpret_cast<name##_v*>(adr))
|
||||
|
||||
#define __declare_io_type(name, type, ...) \
|
||||
template<template<typename> typename T> \
|
||||
struct name##_io_base { \
|
||||
T<type>::Value raw_value = 0; \
|
||||
typedef name##_io_base Self; \
|
||||
\
|
||||
__VA_ARGS__ \
|
||||
template<typename...ARGS> \
|
||||
static constexpr name##_io_base from(const ARGS&...args) { \
|
||||
return name##_io_base().set_va(args...); \
|
||||
} \
|
||||
constexpr name##_io_base& set(IOBitSet bit) { \
|
||||
this->raw_value = bit::set(this->raw_value, bit.pos); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
constexpr name##_io_base& set(IOBitUnset bit) { \
|
||||
this->raw_value = bit::clear(this->raw_value, bit.pos); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
constexpr name##_io_base& set(IOValueSet bits, type value) { \
|
||||
this->raw_value = bit::value::set_normalized(this->raw_value, value, bits.pos, bits.length); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
template<typename S> \
|
||||
constexpr name##_io_base& set(const IOValueSet::IOValueSetPair<S>& value) { \
|
||||
this->set(value.first, static_cast<type>(value.second)); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
template<typename S> \
|
||||
constexpr name##_io_base& set_va(const S& head) { \
|
||||
return this->set(head); \
|
||||
} \
|
||||
template<typename S, typename...ARGS> \
|
||||
constexpr name##_io_base& set_va(const S& head, const ARGS&...tail) { \
|
||||
return this->set(head).set_va(tail...); \
|
||||
} \
|
||||
constexpr type get(IOValueSet bits) const { \
|
||||
return bit::value::get_normalized(this->raw_value, bits.pos, bits.length); \
|
||||
} \
|
||||
\
|
||||
\
|
||||
constexpr name##_io_base& clear(IOBitSet bit) { \
|
||||
this->raw_value = bit::clear(this->raw_value, bit.pos); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
\
|
||||
constexpr bool is_set(IOBitSet bit) const { \
|
||||
return bit::is_set(this->raw_value, bit.pos); \
|
||||
} \
|
||||
\
|
||||
\
|
||||
constexpr void operator=(type value) { \
|
||||
this->raw_value = value; \
|
||||
} \
|
||||
\
|
||||
constexpr type operator*() const { \
|
||||
return this->raw_value; \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
typedef name##_io_base<VolatileValue> name##_v; \
|
||||
typedef name##_io_base<NormalValue> name##_t \
|
||||
#define __declare_io_type(name, type, ...) \
|
||||
/*We need this type to be a POD sadly*/ \
|
||||
template<template<typename> typename T> \
|
||||
struct name##_io_base { \
|
||||
typedef T<type>::UnderlyingValue UnderlyingValue; \
|
||||
typedef name##_io_base Self; \
|
||||
\
|
||||
T<type>::Value raw_value = 0; \
|
||||
\
|
||||
__VA_ARGS__ \
|
||||
\
|
||||
template<typename...ARGS> \
|
||||
static constexpr Self from(const ARGS&...args) { \
|
||||
return Self().set_va(args...); \
|
||||
} \
|
||||
\
|
||||
constexpr Self& set(IOBitSet bit) { \
|
||||
this->raw_value = bit::set(this->raw_value, bit.pos); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
constexpr Self& set(IOBitUnset bit) { \
|
||||
this->raw_value = bit::clear(this->raw_value, bit.pos); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
constexpr Self& set(IOValueSet bits, UnderlyingValue value) { \
|
||||
this->raw_value = bit::value::set_normalized(this->raw_value, value, bits.pos, bits.length); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
template<typename S> \
|
||||
constexpr Self& set(const IOValueSet::IOValueSetPair<S>& value) { \
|
||||
this->set(value.first, static_cast<UnderlyingValue>(value.second)); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
template<typename S> \
|
||||
constexpr Self& set_va(const S& head) { \
|
||||
return this->set(head); \
|
||||
} \
|
||||
\
|
||||
template<typename S, typename...ARGS> \
|
||||
constexpr Self& set_va(const S& head, const ARGS&...tail) { \
|
||||
return this->set(head).set_va(tail...); \
|
||||
} \
|
||||
\
|
||||
constexpr UnderlyingValue get(IOValueSet bits) const { \
|
||||
return bit::value::get_normalized(this->raw_value, bits.pos, bits.length); \
|
||||
} \
|
||||
\
|
||||
constexpr Self& clear(IOBitSet bit) { \
|
||||
this->raw_value = bit::clear(this->raw_value, bit.pos); \
|
||||
return *this; \
|
||||
} \
|
||||
\
|
||||
constexpr bool is_set(IOBitSet bit) const { \
|
||||
return bit::is_set(this->raw_value, bit.pos); \
|
||||
} \
|
||||
\
|
||||
constexpr void operator=(UnderlyingValue value) { \
|
||||
this->raw_value = value; \
|
||||
} \
|
||||
\
|
||||
constexpr operator UnderlyingValue() const { \
|
||||
return this->raw_value; \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
typedef name##_io_base<IOPort::IOValueType::Volatile> name##_v; \
|
||||
typedef name##_io_base<IOPort::IOValueType::Normal> name##_t
|
||||
|
||||
template<typename T>
|
||||
struct VolatilePOD {
|
||||
@@ -196,8 +206,8 @@ namespace JabyEngine {
|
||||
}
|
||||
|
||||
constexpr operator uint32_t() const {
|
||||
const uint32_t high = *this->high;
|
||||
const uint32_t low = *this->low;
|
||||
const uint32_t high = this->high;
|
||||
const uint32_t low = this->low;
|
||||
|
||||
return ((high << 16) | low);
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ namespace JabyEngine {
|
||||
}
|
||||
|
||||
constexpr void set_mode(CounterMode_t mode) {
|
||||
this->mode = *mode;
|
||||
this->mode = mode;
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user