Memory Mapped IO

using reg_dispcnt = gba::iomemmap<short, 0x4000000>;

reg_dispcnt::emplace( 1 << 8 ); // BG0 on
short value = reg_dispcnt::read();
if ( value & ( 1 << 8 ) ) {
    // BG0 is on
}

reg_dispcnt::generate( []() {
    return 1 << 10; // BG2 on
} );

reg_dispcnt::transform( []( short& dispcnt ) {
    if ( dispcnt & ( 1 << 10 ) ) {
        dispcnt |= 3; // Enable mode 3
    }
} );
namespace gba
template<typename Type, unsigned Address>
class imemmap : public gba::memmap<Type, Address>
#include <memmap.hpp>

Input (read-only) memory mapped register type

tparam Type

value type stored in the memory mapping

tparam Address

location within the memory mapping

Subclassed by gba::iomemmap< Type, Address >

Public Types

using type = typename memmap<Type, Address>::type

Value type stored in the memory mapping.

Public Static Functions

static inline type read() noexcept

Read value stored in this memory map

Returns

value stored in this memory mapping

Public Static Attributes

static constexpr auto address = memmap<Type, Address>::address

Address location within the memory mapping.

template<typename Type, unsigned Address>
class iomemmap : public gba::imemmap<Type, Address>, public gba::omemmap<Type, Address>
#include <memmap.hpp>

Input/output (read/write) memory mapped register type

tparam Type

value type stored in the memory mapping

tparam Address

location within the memory mapping

Public Types

using type = typename memmap<Type, Address>::type

Value type stored in the memory mapping.

Public Static Functions

template<class TransformOp>
static inline void transform(TransformOp t) noexcept

Reads the stored value, transforms it, then writes the modified value back

Template Parameters

TransformOp – function object type

Parameters

t – function object that will be called

Public Static Attributes

static constexpr auto address = memmap<Type, Address>::address

Address location within the memory mapping.

template<typename Type, unsigned Address>
class memmap
#include <memmap.hpp>

Base memory mapped register type

tparam Type

value type stored in the memory mapping

tparam Address

location within the memory mapping

Subclassed by gba::imemmap< Type, Address >, gba::omemmap< Type, Address >

Public Types

using type = Type

Public Static Attributes

static constexpr auto address = Address
template<typename Type, unsigned Address>
class omemmap : public gba::memmap<Type, Address>
#include <memmap.hpp>

Output (write-only) memory mapped register type

tparam Type

value type stored in the memory mapping

tparam Address

location within the memory mapping

Subclassed by gba::iomemmap< Type, Address >

Public Types

using type = typename memmap<Type, Address>::type

Value type stored in the memory mapping.

Public Static Functions

static inline void write(type &&value) noexcept

Move value into this memory map

Parameters

value – value to move into this memory map

static inline void write(const type &value) noexcept

Copy value into this memory map

Parameters

value – value to copy into this memory map

template<typename ...Args>
static inline void emplace(Args&&... args) noexcept

Construct value into this memory map with the provided arguments

Template Parameters

Args – variadic argument types

Parameters

args – variadic list of arguments

template<class Generator>
static inline void generate(Generator g) noexcept

Calls generator to provide value to write into this memory map

Template Parameters

Generator – function object type

Parameters

g – function object that will be called

Public Static Attributes

static constexpr auto address = memmap<Type, Address>::address

Address location within the memory mapping.