Convert Timer IO

This commit is contained in:
Jaby
2023-03-18 16:04:05 +01:00
committed by Jaby
parent a349746263
commit 01e72e300d
4 changed files with 97 additions and 68 deletions

View File

@@ -53,19 +53,23 @@ namespace JabyEngine {
};
#define __declare_new_io_port(name, adr) \
typedef name##_io_base<VolatileValue> name##_v; \
typedef name##_io_base<NormalValue> name##_t; \
static auto& name = *reinterpret_cast<name##_v*>(adr)
/*constexpr name##_io_base() = default; \
\
constexpr name##_io_base(type value) : raw_value(value) {} \
\*/
#define __declare_io_type(name, type, ...) \
template<template<typename> typename T> \
struct name##_io_base { \
T<type>::Value raw_value = 0; \
\
constexpr name##_io_base() = default; \
\
constexpr name##_io_base(type value) : raw_value(value) {} \
__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); \
@@ -87,7 +91,15 @@ namespace JabyEngine {
return *this; \
} \
\
type get(IOValueSet bits) const { \
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); \
} \
\
@@ -98,22 +110,25 @@ namespace JabyEngine {
} \
\
\
bool is_set(IOBitSet bit) const { \
constexpr bool is_set(IOBitSet bit) const { \
return bit::is_set(this->raw_value, bit.pos); \
} \
\
\
void operator=(type value) { \
constexpr void operator=(type value) { \
this->raw_value = value; \
} \
\
type operator*() const { \
constexpr type operator*() const { \
return this->raw_value; \
} \
}
}; \
\
typedef name##_io_base<VolatileValue> name##_v; \
typedef name##_io_base<NormalValue> name##_t \
template<typename T>
struct __attribute__((deprecated)) VolatilePOD {
struct VolatilePOD {
volatile T raw;
constexpr T read() const {
@@ -127,7 +142,7 @@ namespace JabyEngine {
// For use with ComplexBitMaps or what else satisfies this API
template<typename T>
struct __attribute__((deprecated)) VolatileBitMapPOD {
struct VolatileBitMapPOD {
typedef typename T::UnderlyingType Raw;
VolatilePOD<Raw> pod;