Remove the ComplexBitMap
This commit is contained in:
parent
9a964a702e
commit
dfab120bfb
|
@ -1,17 +1,88 @@
|
||||||
#ifndef __JABYENGINE_BITS_HPP__
|
#ifndef __JABYENGINE_BITS_HPP__
|
||||||
#define __JABYENGINE_BITS_HPP__
|
#define __JABYENGINE_BITS_HPP__
|
||||||
#include "../jabyengine_defines.h"
|
#include "../jabyengine_defines.h"
|
||||||
|
#include "types.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace bit {
|
namespace bit {
|
||||||
|
namespace value {
|
||||||
|
template<typename T>
|
||||||
|
static constexpr T set_normalized(T raw_value, T value, size_t start_bit, size_t length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ClearBit {
|
||||||
|
uint16_t pos;
|
||||||
|
|
||||||
|
constexpr ClearBit(uint16_t bit_pos) : pos(bit_pos) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Bit {
|
||||||
|
uint16_t pos;
|
||||||
|
|
||||||
|
constexpr Bit(uint16_t bit_pos) : pos(bit_pos) {
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr ClearBit operator!() const {
|
||||||
|
return ClearBit(this->pos);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BitRange {
|
||||||
|
template<typename T>
|
||||||
|
using RangeValuePair = pair<BitRange, T>;
|
||||||
|
|
||||||
|
uint16_t pos;
|
||||||
|
uint16_t length;
|
||||||
|
|
||||||
|
constexpr BitRange(uint16_t pos, uint16_t length) : pos(pos), length(length) {
|
||||||
|
}
|
||||||
|
|
||||||
|
static constexpr BitRange from_to(uint16_t first_bit, uint16_t last_bit) {
|
||||||
|
return BitRange(first_bit, (last_bit - first_bit) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr RangeValuePair<T> with(T value) const {
|
||||||
|
return {*this, value};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr T as_value(T value) const {
|
||||||
|
return bit::value::set_normalized(static_cast<T>(0), value, this->pos, this->length);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
constexpr RangeValuePair<T> range_max() const {
|
||||||
|
return BitRange::with<T>((1 << this->length) - 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace bit {
|
||||||
|
template<typename T>
|
||||||
|
static constexpr T clear(T raw_value, size_t bit) {
|
||||||
|
return (raw_value & ~(1 << bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr T clear(T raw_value, Bit bit) {
|
||||||
|
return clear(raw_value, bit.pos);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr T set(T raw_value, size_t bit) {
|
static constexpr T set(T raw_value, size_t bit) {
|
||||||
return (raw_value | (1 << bit));
|
return (raw_value | (1 << bit));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr T clear(T raw_value, size_t bit) {
|
static constexpr T set(T raw_value, Bit bit) {
|
||||||
return (raw_value & ~(1 << bit));
|
return set(raw_value, bit.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr T set(T raw_value, ClearBit bit) {
|
||||||
|
return clear(raw_value, bit.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -19,30 +90,52 @@ namespace JabyEngine {
|
||||||
return static_cast<bool>(raw_value & (1 << bit));
|
return static_cast<bool>(raw_value & (1 << bit));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace value {
|
template<typename T>
|
||||||
template<typename T>
|
static constexpr bool is_set(T raw_value, Bit bit) {
|
||||||
static constexpr T crop_value(T raw_value, size_t length) {
|
return is_set(raw_value, bit.pos);
|
||||||
return (raw_value & ((1 << length) - 1));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
namespace value {
|
||||||
static constexpr T range_mask(size_t start_bit, size_t length) {
|
namespace helper {
|
||||||
return (((1 << length) - 1) << start_bit);
|
template<typename T>
|
||||||
|
static constexpr T crop_value(T raw_value, size_t length) {
|
||||||
|
return (raw_value & ((1 << length) - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr T range_mask(size_t start_bit, size_t length) {
|
||||||
|
return (((1 << length) - 1) << start_bit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr T clear_normalized(T raw_value, size_t start_bit, size_t length) {
|
static constexpr T clear_normalized(T raw_value, size_t start_bit, size_t length) {
|
||||||
return (raw_value & ~range_mask<T>(start_bit, length));
|
return (raw_value & ~helper::range_mask<T>(start_bit, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr T set_normalized(T raw_value, T value, size_t start_bit, size_t length) {
|
static constexpr T set_normalized(T raw_value, T value, size_t start_bit, size_t length) {
|
||||||
return (clear_normalized(raw_value, start_bit, length) | (crop_value(value, length) << start_bit));
|
return (clear_normalized(raw_value, start_bit, length) | (helper::crop_value(value, length) << start_bit));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr T set_normalized(T raw_value, BitRange bits, T value) {
|
||||||
|
return set_normalized(raw_value, value, bits.pos, bits.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename S>
|
||||||
|
static constexpr T set_normalized(T raw_value, const BitRange::RangeValuePair<S> &value_pair) {
|
||||||
|
return set_normalized(raw_value, value_pair.first, static_cast<T>(value_pair.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static constexpr T get_normalized(T raw_value, size_t start_bit, size_t length) {
|
static constexpr T get_normalized(T raw_value, size_t start_bit, size_t length) {
|
||||||
return crop_value((raw_value & range_mask<T>(start_bit, length)) >> start_bit, length);
|
return helper::crop_value((raw_value & helper::range_mask<T>(start_bit, length)) >> start_bit, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr T get_normalized(T raw_value, BitRange range) {
|
||||||
|
return get_normalized(raw_value, range.pos, range.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,208 +3,6 @@
|
||||||
#include "bits.hpp"
|
#include "bits.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
struct ClearBitValue {
|
|
||||||
size_t bit;
|
|
||||||
|
|
||||||
constexpr ClearBitValue(size_t bit) : bit(bit) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct Bit {
|
|
||||||
typedef T ValueType;
|
|
||||||
|
|
||||||
size_t value;
|
|
||||||
|
|
||||||
constexpr Bit(size_t value) : value(value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr operator size_t() const {
|
|
||||||
return this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ClearBitValue operator!() const {
|
|
||||||
return ClearBitValue(this->value);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct BitRangeValue {
|
|
||||||
T value;
|
|
||||||
size_t begin;
|
|
||||||
size_t length;
|
|
||||||
|
|
||||||
constexpr BitRangeValue() = default;
|
|
||||||
constexpr BitRangeValue(T value, size_t begin, size_t length) : value(value), begin(begin), length(length) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct BitRange {
|
|
||||||
typedef T ValueType;
|
|
||||||
|
|
||||||
size_t begin;
|
|
||||||
size_t length;
|
|
||||||
|
|
||||||
static constexpr BitRange<T> from_to(size_t start, size_t end) {
|
|
||||||
return {start, (end - start + 1)};
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr BitRangeValue<T> with(T value) const {
|
|
||||||
return BitRangeValue(value, this->begin, this->length);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr BitRangeValue<T> max() const {
|
|
||||||
return BitRange<T>::with((1 << this->length) - 1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
|
|
||||||
return BitRangeValue{value, range.begin, range.length};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class ComplexBitMap {
|
|
||||||
public:
|
|
||||||
typedef T UnderlyingType;
|
|
||||||
T raw;
|
|
||||||
|
|
||||||
private:
|
|
||||||
template<typename S>
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& set_va(const S& value) {
|
|
||||||
return this->set(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S, typename...ARGS>
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& set_va(const S& value, const ARGS&...args) {
|
|
||||||
return this->set_va(value).set_va(args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
template<typename...ARGS>
|
|
||||||
static constexpr __always_inline ComplexBitMap<T> with(ARGS...args) {
|
|
||||||
return ComplexBitMap().set_va(args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Accesssing bits
|
|
||||||
template<typename S>
|
|
||||||
constexpr ComplexBitMap<T>& set_bit(S bit) {
|
|
||||||
this->raw = bit::set(this->raw, static_cast<size_t>(bit));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr void set_bit(S bit) volatile {
|
|
||||||
this->raw = bit::set(this->raw, static_cast<size_t>(bit));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr ComplexBitMap<T>& clear_bit(S bit) {
|
|
||||||
this->raw = bit::clear(this->raw, static_cast<size_t>(bit));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr void clear_bit(S bit) volatile {
|
|
||||||
this->raw = bit::clear(this->raw, static_cast<size_t>(bit));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr bool is_bit_set(S bit) {
|
|
||||||
return bit::is_set(this->raw, static_cast<size_t>(bit));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr bool is_bit_set(S bit) const volatile {
|
|
||||||
return bit::is_set(this->raw, static_cast<size_t>(bit));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Accessing values
|
|
||||||
template<typename S>
|
|
||||||
constexpr ComplexBitMap<T>& set_value(S value, const BitRange<S>& range) {
|
|
||||||
this->raw = bit::value::set_normalized(this->raw, static_cast<T>(value), range.begin, range.length);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr void set_value(S value, const BitRange<S>& range) volatile {
|
|
||||||
this->raw = bit::value::set_normalized(this->raw, static_cast<T>(value), range.begin, range.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr ComplexBitMap<T>& clear_value(const BitRange<S>& range) {
|
|
||||||
this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr void clear_value(const BitRange<S>& range) volatile {
|
|
||||||
this->raw = bit::value::clear_normalized(this->raw, range.begin, range.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr S get_value(const BitRange<S>& range) const {
|
|
||||||
return static_cast<S>(bit::value::get_normalized(this->raw, range.begin, range.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr S get_value(const BitRange<S>& range) const volatile {
|
|
||||||
return static_cast<S>(bit::value::get_normalized(this->raw, range.begin, range.length));
|
|
||||||
}
|
|
||||||
|
|
||||||
//For easier checking
|
|
||||||
constexpr bool is(Bit<T> bit) const {
|
|
||||||
return ComplexBitMap::is_bit_set(bit);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr bool is(Bit<T> bit) const volatile {
|
|
||||||
return ComplexBitMap::is_bit_set(bit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// For easier constructing
|
|
||||||
template<typename S>
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& set(const BitRange<S>& range, T value) {
|
|
||||||
this->set_value(value, range);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& set(const BitRangeValue<S>& value) {
|
|
||||||
this->set_value(value.value, {value.begin, value.length});
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename S>
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& set(const Bit<S>& bit) {
|
|
||||||
this->set_bit(bit.value);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& set(const ClearBitValue& value) {
|
|
||||||
this->clear_bit(value.bit);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& operator|(const BitRangeValue<T>& value) {
|
|
||||||
this->set_value(value.value, value.range);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& operator|(const Bit<T>& bit) {
|
|
||||||
this->set_bit(bit.value);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr __always_inline ComplexBitMap<T>& operator|(const ClearBitValue& value) {
|
|
||||||
this->clear_bit(value.bit);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr __always_inline operator T() const {
|
|
||||||
return this->raw;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //!__JABYENGINE_COMPLEX_BITMAP_HPP__
|
#endif //!__JABYENGINE_COMPLEX_BITMAP_HPP__
|
|
@ -4,33 +4,35 @@
|
||||||
#include "../jabyengine_defines.h"
|
#include "../jabyengine_defines.h"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
struct __no_align SimpleTIM : private ComplexBitMap<uint32_t> {
|
struct __no_align SimpleTIM {
|
||||||
static constexpr auto TextureX = BitRange<uint32_t>(0, 8);
|
static constexpr auto TextureX = BitRange::from_to(0, 8);
|
||||||
static constexpr auto TextureY = BitRange<uint32_t>(9, 16);
|
static constexpr auto TextureY = BitRange::from_to(9, 16);
|
||||||
static constexpr auto ClutX = BitRange<uint32_t>(17, 22);
|
static constexpr auto ClutX = BitRange::from_to(17, 22);
|
||||||
static constexpr auto ClutY = BitRange<uint32_t>(23, 31);
|
static constexpr auto ClutY = BitRange::from_to(23, 31);
|
||||||
|
|
||||||
|
uint32_t raw;
|
||||||
|
|
||||||
constexpr SimpleTIM() {
|
constexpr SimpleTIM() {
|
||||||
this->raw = 0;
|
this->raw = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : ComplexBitMap(ComplexBitMap::with(TextureX.with(texX >> 1), TextureY.with(texY >> 1), ClutX.with(clutX >> 4), ClutY.with(clutY))) {
|
constexpr SimpleTIM(uint16_t texX, uint16_t texY, uint16_t clutX, uint16_t clutY) : raw(TextureX.as_value(texX >> 1) | TextureY.as_value(texY >> 1) | ClutX.as_value(clutX >> 4) | ClutY.as_value(clutY)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr uint16_t getTextureX() const {
|
constexpr uint16_t getTextureX() const {
|
||||||
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::TextureX) << 1);
|
return bit::value::get_normalized(this->raw, TextureX) << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr uint16_t getTextureY() const {
|
constexpr uint16_t getTextureY() const {
|
||||||
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::TextureY) << 1);
|
return bit::value::get_normalized(this->raw, TextureY) << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr uint16_t getClutX() const {
|
constexpr uint16_t getClutX() const {
|
||||||
return (ComplexBitMap<uint32_t>::get_value(SimpleTIM::ClutX) << 4);
|
return bit::value::get_normalized(this->raw, SimpleTIM::ClutX) << 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr uint16_t getClutY() const {
|
constexpr uint16_t getClutY() const {
|
||||||
return ComplexBitMap<uint32_t>::get_value(SimpleTIM::ClutY);
|
return bit::value::get_normalized(this->raw, ClutY);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,12 @@ namespace JabyEngine {
|
||||||
|
|
||||||
class Color {
|
class Color {
|
||||||
private:
|
private:
|
||||||
static constexpr auto RedRange = BitRange<uint16_t>::from_to(0, 4);
|
static constexpr auto RedRange = BitRange::from_to(0, 4);
|
||||||
static constexpr auto GreenRange = BitRange<uint16_t>::from_to(5, 9);
|
static constexpr auto GreenRange = BitRange::from_to(5, 9);
|
||||||
static constexpr auto BlueRange = BitRange<uint16_t>::from_to(10, 14);
|
static constexpr auto BlueRange = BitRange::from_to(10, 14);
|
||||||
static constexpr auto SemiTransperancyBit = Bit<uint16_t>(15);
|
static constexpr auto SemiTransperancyBit = Bit(15);
|
||||||
|
|
||||||
ComplexBitMap<uint16_t> value = {0};
|
uint16_t value = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr Color from_rgb(uint8_t r, uint8_t g, uint8_t b) {
|
static constexpr Color from_rgb(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
@ -58,17 +58,17 @@ namespace JabyEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Color& set_red(uint8_t red) {
|
constexpr Color& set_red(uint8_t red) {
|
||||||
this->value.set_value(static_cast<uint16_t>(red), RedRange);
|
this->value = bit::value::set_normalized(this->value, RedRange.with(red));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Color& set_green(uint8_t green) {
|
constexpr Color& set_green(uint8_t green) {
|
||||||
this->value.set_value(static_cast<uint16_t>(green), GreenRange);
|
this->value = bit::value::set_normalized(this->value, GreenRange.with(green));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Color& set_blue(uint8_t blue) {
|
constexpr Color& set_blue(uint8_t blue) {
|
||||||
this->value.set_value(static_cast<uint16_t>(blue), BlueRange);
|
this->value = bit::value::set_normalized(this->value, BlueRange.with(blue));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -32,41 +32,41 @@ namespace JabyEngine {
|
||||||
};
|
};
|
||||||
|
|
||||||
__declare_io_type(IndexStatus, uint8_t,
|
__declare_io_type(IndexStatus, uint8_t,
|
||||||
static constexpr auto PortIndex = IOValueSet::from_to(0, 1);
|
static constexpr auto PortIndex = BitRange::from_to(0, 1);
|
||||||
static constexpr auto HasXAFifoData = IOBitSet(2);
|
static constexpr auto HasXAFifoData = Bit(2);
|
||||||
static constexpr auto IsParameterFifoEmpty = IOBitSet(3);
|
static constexpr auto IsParameterFifoEmpty = Bit(3);
|
||||||
static constexpr auto HasParameterFifoSpace = IOBitSet(4);
|
static constexpr auto HasParameterFifoSpace = Bit(4);
|
||||||
static constexpr auto HasResponseFifoData = IOBitSet(5);
|
static constexpr auto HasResponseFifoData = Bit(5);
|
||||||
static constexpr auto HasDataFifoData = IOBitSet(6);
|
static constexpr auto HasDataFifoData = Bit(6);
|
||||||
static constexpr auto IsTransmissionBusy = IOBitSet(7);
|
static constexpr auto IsTransmissionBusy = Bit(7);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(InterruptEnable, uint8_t,
|
__declare_io_type(InterruptEnable, uint8_t,
|
||||||
static constexpr auto InterruptTypValue = IOValueSet::from_to(0, 2);
|
static constexpr auto InterruptTypValue = BitRange::from_to(0, 2);
|
||||||
static constexpr auto InterruptExtended = IOValueSet::from_to(0, 4);
|
static constexpr auto InterruptExtended = BitRange::from_to(0, 4);
|
||||||
static constexpr auto UnknownIRQ = IOBitSet(3);
|
static constexpr auto UnknownIRQ = Bit(3);
|
||||||
static constexpr auto CommandStartIRQ = IOBitSet(4);
|
static constexpr auto CommandStartIRQ = Bit(4);
|
||||||
);
|
);
|
||||||
typedef InterruptEnable_v InterruptFlag_v;
|
typedef InterruptEnable_v InterruptFlag_v;
|
||||||
|
|
||||||
__declare_io_type(Request, uint8_t,
|
__declare_io_type(Request, uint8_t,
|
||||||
static constexpr auto WantCommandStartIRQ = IOBitSet(5);
|
static constexpr auto WantCommandStartIRQ = Bit(5);
|
||||||
static constexpr auto WantData = IOBitSet(7);
|
static constexpr auto WantData = Bit(7);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(SoundMapCoding, uint8_t,
|
__declare_io_type(SoundMapCoding, uint8_t,
|
||||||
static constexpr auto Stereo = IOBitSet(0);
|
static constexpr auto Stereo = Bit(0);
|
||||||
static constexpr auto Mono = !Stereo;
|
static constexpr auto Mono = !Stereo;
|
||||||
static constexpr auto SampleRate_18900hz = IOBitSet(2);
|
static constexpr auto SampleRate_18900hz = Bit(2);
|
||||||
static constexpr auto SampleRate_37800hz = !SampleRate_18900hz;
|
static constexpr auto SampleRate_37800hz = !SampleRate_18900hz;
|
||||||
static constexpr auto BitsPerSample8 = IOBitSet(4);
|
static constexpr auto BitsPerSample8 = Bit(4);
|
||||||
static constexpr auto BitsPerSample4 = !BitsPerSample8;
|
static constexpr auto BitsPerSample4 = !BitsPerSample8;
|
||||||
static constexpr auto Emphasis = IOBitSet(6);
|
static constexpr auto Emphasis = Bit(6);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(AudioVolumeApply, uint8_t,
|
__declare_io_type(AudioVolumeApply, uint8_t,
|
||||||
static constexpr auto Mute = IOBitSet(0);
|
static constexpr auto Mute = Bit(0);
|
||||||
static constexpr auto ApplyChanges = IOBitSet(5);
|
static constexpr auto ApplyChanges = Bit(5);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(ResponseFifo, uint8_t,);
|
__declare_io_type(ResponseFifo, uint8_t,);
|
||||||
|
|
|
@ -5,18 +5,18 @@
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace DMA_IO {
|
namespace DMA_IO {
|
||||||
__declare_io_type(MADR, uint32_t,
|
__declare_io_type(MADR, uint32_t,
|
||||||
static constexpr auto MemoryAdr = IOValueSet::from_to(0, 23);
|
static constexpr auto MemoryAdr = BitRange::from_to(0, 23);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(BCR, uint32_t,
|
__declare_io_type(BCR, uint32_t,
|
||||||
struct __no_align SyncMode0 {
|
struct SyncMode0 {
|
||||||
static constexpr auto NumberOfWords = IOValueSet::from_to(0, 15);
|
static constexpr auto NumberOfWords = BitRange::from_to(0, 15);
|
||||||
static constexpr auto CD_OneBlock = IOBitSet(16);
|
static constexpr auto CD_OneBlock = Bit(16);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SyncMode1 : public ComplexBitMap<uint32_t> {
|
struct SyncMode1 {
|
||||||
static constexpr auto BlockSize = IOValueSet::from_to(0, 15);
|
static constexpr auto BlockSize = BitRange::from_to(0, 15);
|
||||||
static constexpr auto BlockAmount = IOValueSet::from_to(16, 31);
|
static constexpr auto BlockAmount = BitRange::from_to(16, 31);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SyncMode2 {
|
struct SyncMode2 {
|
||||||
|
@ -30,25 +30,25 @@ namespace JabyEngine {
|
||||||
Sync2 = 2, //Linked List
|
Sync2 = 2, //Linked List
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto ManualStart = IOBitSet(28);
|
static constexpr auto ManualStart = Bit(28);
|
||||||
|
|
||||||
static constexpr auto Start = IOBitSet(24);
|
static constexpr auto Start = Bit(24);
|
||||||
static constexpr auto Busy = Start;
|
static constexpr auto Busy = Start;
|
||||||
|
|
||||||
static constexpr auto ChoppingCPUWindowSize = IOValueSet::from_to(20, 22);
|
static constexpr auto ChoppingCPUWindowSize = BitRange::from_to(20, 22);
|
||||||
static constexpr auto ChoppingDMAWindowSize = IOValueSet::from_to(16, 18);
|
static constexpr auto ChoppingDMAWindowSize = BitRange::from_to(16, 18);
|
||||||
|
|
||||||
static constexpr auto SyncMode = IOValueSet::from_to(9, 10);
|
static constexpr auto SyncMode = BitRange::from_to(9, 10);
|
||||||
static constexpr auto UseSyncMode0 = SyncMode.with(Sync0);
|
static constexpr auto UseSyncMode0 = SyncMode.with(Sync0);
|
||||||
static constexpr auto UseSyncMode1 = SyncMode.with(Sync1);
|
static constexpr auto UseSyncMode1 = SyncMode.with(Sync1);
|
||||||
static constexpr auto UseSyncMode2 = SyncMode.with(Sync2);
|
static constexpr auto UseSyncMode2 = SyncMode.with(Sync2);
|
||||||
|
|
||||||
static constexpr auto UseChopping = IOBitSet(8);
|
static constexpr auto UseChopping = Bit(8);
|
||||||
|
|
||||||
static constexpr auto MemoryAdrDecreaseBy4 = IOBitSet(1);
|
static constexpr auto MemoryAdrDecreaseBy4 = Bit(1);
|
||||||
static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4;
|
static constexpr auto MemoryAdrIncreaseBy4 = !MemoryAdrDecreaseBy4;
|
||||||
|
|
||||||
static constexpr auto FromMainRAM = IOBitSet(0);
|
static constexpr auto FromMainRAM = Bit(0);
|
||||||
static constexpr auto ToMainRAM = !FromMainRAM;
|
static constexpr auto ToMainRAM = !FromMainRAM;
|
||||||
|
|
||||||
static constexpr Self StartMDECin() {
|
static constexpr Self StartMDECin() {
|
||||||
|
@ -105,34 +105,34 @@ namespace JabyEngine {
|
||||||
static constexpr Priority LowestPriority = 7;
|
static constexpr Priority LowestPriority = 7;
|
||||||
|
|
||||||
__declare_io_type(DPCR, uint32_t,
|
__declare_io_type(DPCR, uint32_t,
|
||||||
static constexpr auto OTCEnable = IOBitSet(27);
|
static constexpr auto OTCEnable = Bit(27);
|
||||||
static constexpr auto OTCPriority = IOValueSet::from_to(24, 26);
|
static constexpr auto OTCPriority = BitRange::from_to(24, 26);
|
||||||
|
|
||||||
static constexpr auto PIOEnable = IOBitSet(23);
|
static constexpr auto PIOEnable = Bit(23);
|
||||||
static constexpr auto PIOPriority = IOValueSet::from_to(20, 22);
|
static constexpr auto PIOPriority = BitRange::from_to(20, 22);
|
||||||
|
|
||||||
static constexpr auto SPUEnable = IOBitSet(19);
|
static constexpr auto SPUEnable = Bit(19);
|
||||||
static constexpr auto SPUPriority = IOValueSet::from_to(16, 18);
|
static constexpr auto SPUPriority = BitRange::from_to(16, 18);
|
||||||
|
|
||||||
static constexpr auto CDROMEnable = IOBitSet(15);
|
static constexpr auto CDROMEnable = Bit(15);
|
||||||
static constexpr auto CDROMPriority = IOValueSet::from_to(12, 14);
|
static constexpr auto CDROMPriority = BitRange::from_to(12, 14);
|
||||||
|
|
||||||
static constexpr auto GPUEnable = IOBitSet(11);
|
static constexpr auto GPUEnable = Bit(11);
|
||||||
static constexpr auto GPUPriority = IOValueSet::from_to(8, 10);
|
static constexpr auto GPUPriority = BitRange::from_to(8, 10);
|
||||||
|
|
||||||
static constexpr auto MDECoutEnable = IOBitSet(7);
|
static constexpr auto MDECoutEnable = Bit(7);
|
||||||
static constexpr auto MDECoutPriority = IOValueSet::from_to(4, 6);
|
static constexpr auto MDECoutPriority = BitRange::from_to(4, 6);
|
||||||
|
|
||||||
static constexpr auto MDECinEnable = IOBitSet(3);
|
static constexpr auto MDECinEnable = Bit(3);
|
||||||
static constexpr auto MDECinPriority = IOValueSet::from_to(0, 2);
|
static constexpr auto MDECinPriority = BitRange::from_to(0, 2);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(DICR, uint32_t,
|
__declare_io_type(DICR, uint32_t,
|
||||||
static constexpr auto MasterEnable = IOBitSet(31);
|
static constexpr auto MasterEnable = Bit(31);
|
||||||
static constexpr auto Flags = IOValueSet::from_to(24, 30);
|
static constexpr auto Flags = BitRange::from_to(24, 30);
|
||||||
static constexpr auto MasterEnableDPCR = IOBitSet(23);
|
static constexpr auto MasterEnableDPCR = Bit(23);
|
||||||
static constexpr auto EnableDPCR = IOValueSet::from_to(16, 22);
|
static constexpr auto EnableDPCR = BitRange::from_to(16, 22);
|
||||||
static constexpr auto ForceIRQ = IOBitSet(15);
|
static constexpr auto ForceIRQ = Bit(15);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_new_io_port(MDECin, 0x1F801080);
|
__declare_new_io_port(MDECin, 0x1F801080);
|
||||||
|
|
|
@ -53,12 +53,12 @@ namespace JabyEngine {
|
||||||
PAL = 1,
|
PAL = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto HorizontalResolution368 = IOBitSet(6);
|
static constexpr auto HorizontalResolution368 = Bit(6);
|
||||||
static constexpr auto VerticalInterlace = IOBitSet(5);
|
static constexpr auto VerticalInterlace = Bit(5);
|
||||||
static constexpr auto DisplayAreaColorDepth = IOValueSet::from_to(4, 4);
|
static constexpr auto DisplayAreaColorDepth = BitRange::from_to(4, 4);
|
||||||
static constexpr auto VideoMode = IOValueSet::from_to(3, 3);
|
static constexpr auto VideoMode = BitRange::from_to(3, 3);
|
||||||
static constexpr auto VerticalResolution = IOValueSet::from_to(2, 2);
|
static constexpr auto VerticalResolution = BitRange::from_to(2, 2);
|
||||||
static constexpr auto HorizontalResolution = IOValueSet::from_to(0, 1);
|
static constexpr auto HorizontalResolution = BitRange::from_to(0, 1);
|
||||||
|
|
||||||
static constexpr Self PAL() {
|
static constexpr Self PAL() {
|
||||||
return Self::from(
|
return Self::from(
|
||||||
|
@ -86,12 +86,12 @@ namespace JabyEngine {
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
struct Command {
|
struct Command {
|
||||||
struct Helper {
|
struct Helper {
|
||||||
static constexpr GP0_t DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) {
|
static constexpr GP0_t DrawAreaTemplate(uint8_t code, uint16_t x, uint16_t y) {
|
||||||
constexpr auto Command = IOValueSet::from_to(24, 31);
|
constexpr auto Command = BitRange::from_to(24, 31);
|
||||||
constexpr auto Y = IOValueSet::from_to(10, 18);
|
constexpr auto Y = BitRange::from_to(10, 18);
|
||||||
constexpr auto X = IOValueSet::from_to(0, 9);
|
constexpr auto X = BitRange::from_to(0, 9);
|
||||||
|
|
||||||
return GP0_t::from(Command.with(code), Y.with(y), X.with(x));
|
return GP0_t::from(Command.with(code), Y.with(y), X.with(x));
|
||||||
}
|
}
|
||||||
|
@ -142,24 +142,24 @@ namespace JabyEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr GP1_t DisplayArea(uint16_t x, uint16_t y) {
|
static constexpr GP1_t DisplayArea(uint16_t x, uint16_t y) {
|
||||||
constexpr auto X = BitRange<uint32_t>::from_to(0, 9);
|
constexpr auto X = BitRange::from_to(0, 9);
|
||||||
constexpr auto Y = BitRange<uint32_t>::from_to(10, 18);
|
constexpr auto Y = BitRange::from_to(10, 18);
|
||||||
|
|
||||||
return {Helper::construct_cmd(0x05, ComplexBitMap<uint32_t>::with(X.with(x), Y.with(y)).raw)};
|
return {Helper::construct_cmd(0x05, X.as_value(x) | Y.as_value(y))};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr GP1_t HorizontalDisplayRange(uint32_t x1, uint32_t x2) {
|
static constexpr GP1_t HorizontalDisplayRange(uint32_t x1, uint32_t x2) {
|
||||||
constexpr auto X1 = BitRange<uint32_t>::from_to(0, 11);
|
constexpr auto X1 = BitRange::from_to(0, 11);
|
||||||
constexpr auto X2 = BitRange<uint32_t>::from_to(12, 23);
|
constexpr auto X2 = BitRange::from_to(12, 23);
|
||||||
|
|
||||||
return {Helper::construct_cmd(0x06, ComplexBitMap<uint32_t>::with(X1.with(x1), X2.with(x2)).raw)};
|
return {Helper::construct_cmd(0x06, X1.as_value(x1) | X2.as_value(x2))};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr GP1_t VerticalDisplayRange(uint32_t y1, uint32_t y2) {
|
static constexpr GP1_t VerticalDisplayRange(uint32_t y1, uint32_t y2) {
|
||||||
constexpr auto Y1 = BitRange<uint32_t>::from_to(0, 9);
|
constexpr auto Y1 = BitRange::from_to(0, 9);
|
||||||
constexpr auto Y2 = BitRange<uint32_t>::from_to(10, 19);
|
constexpr auto Y2 = BitRange::from_to(10, 19);
|
||||||
|
|
||||||
return {Helper::construct_cmd(0x07, ComplexBitMap<uint32_t>::with(Y1.with(y1), Y2.with(y2)).raw)};
|
return {Helper::construct_cmd(0x07, Y1.as_value(y1) | Y2.as_value(y2))};
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr GP1_t DisplayMode(DisplayMode_t mode) {
|
static constexpr GP1_t DisplayMode(DisplayMode_t mode) {
|
||||||
|
@ -168,32 +168,32 @@ namespace JabyEngine {
|
||||||
};
|
};
|
||||||
|
|
||||||
__declare_io_type(GPUSTAT, uint32_t,
|
__declare_io_type(GPUSTAT, uint32_t,
|
||||||
static constexpr auto DrawingOddLinesInterlaced = IOBitSet(31);
|
static constexpr auto DrawingOddLinesInterlaced = Bit(31);
|
||||||
static constexpr auto DMADirectionValue = IOValueSet::from_to(29, 30);
|
static constexpr auto DMADirectionValue = BitRange::from_to(29, 30);
|
||||||
static constexpr auto DMAReady = IOBitSet(28);
|
static constexpr auto DMAReady = Bit(28);
|
||||||
static constexpr auto VRAMtoCPUtransferReay = IOBitSet(27);
|
static constexpr auto VRAMtoCPUtransferReay = Bit(27);
|
||||||
static constexpr auto GP0ReadyForCMD = IOBitSet(26);
|
static constexpr auto GP0ReadyForCMD = Bit(26);
|
||||||
static constexpr auto FifoNotFull = IOBitSet(25); // Only for Fifo
|
static constexpr auto FifoNotFull = Bit(25); // Only for Fifo
|
||||||
static constexpr auto InterruptRequest = IOBitSet(24);
|
static constexpr auto InterruptRequest = Bit(24);
|
||||||
static constexpr auto DisplayDisabled = IOBitSet(23);
|
static constexpr auto DisplayDisabled = Bit(23);
|
||||||
static constexpr auto VerticalInterlaceOn = IOBitSet(22);
|
static constexpr auto VerticalInterlaceOn = Bit(22);
|
||||||
static constexpr auto DisplayAreaColorDepth = IOValueSet::from_to(21, 21);
|
static constexpr auto DisplayAreaColorDepth = BitRange::from_to(21, 21);
|
||||||
static constexpr auto VideoModePal = IOBitSet(20);
|
static constexpr auto VideoModePal = Bit(20);
|
||||||
static constexpr auto VerticalResolutionValue = IOValueSet::from_to(19, 19);
|
static constexpr auto VerticalResolutionValue = BitRange::from_to(19, 19);
|
||||||
static constexpr auto HorizontalResolutionValue = IOValueSet::from_to(17, 18);
|
static constexpr auto HorizontalResolutionValue = BitRange::from_to(17, 18);
|
||||||
static constexpr auto HorizontalResolution368 = IOBitSet(16);
|
static constexpr auto HorizontalResolution368 = Bit(16);
|
||||||
static constexpr auto TexturesDisabled = IOBitSet(15);
|
static constexpr auto TexturesDisabled = Bit(15);
|
||||||
static constexpr auto NotDrawingMaskedPixels = IOBitSet(12);
|
static constexpr auto NotDrawingMaskedPixels = Bit(12);
|
||||||
static constexpr auto MaskBitSetDuringDrawEnabled = IOBitSet(11);
|
static constexpr auto MaskBitSetDuringDrawEnabled = Bit(11);
|
||||||
static constexpr auto DrawingToDisplayAreadAllowed = IOBitSet(10);
|
static constexpr auto DrawingToDisplayAreadAllowed = Bit(10);
|
||||||
static constexpr auto DitherEnabled = IOBitSet(9);
|
static constexpr auto DitherEnabled = Bit(9);
|
||||||
static constexpr auto TexturePageColorValue = IOValueSet::from_to(7, 8);
|
static constexpr auto TexturePageColorValue = BitRange::from_to(7, 8);
|
||||||
static constexpr auto SemiTransparencyValue = IOValueSet::from_to(5, 6);
|
static constexpr auto SemiTransparencyValue = BitRange::from_to(5, 6);
|
||||||
static constexpr auto TexturePageY = IOValueSet::from_to(4, 4); // N*256
|
static constexpr auto TexturePageY = BitRange::from_to(4, 4); // N*256
|
||||||
static constexpr auto TexturePageX = IOValueSet::from_to(0, 3); // N*64
|
static constexpr auto TexturePageX = BitRange::from_to(0, 3); // N*64
|
||||||
|
|
||||||
static constexpr auto VerticalResolution480 = IOBitSet(19);
|
static constexpr auto VerticalResolution480 = Bit(19);
|
||||||
static constexpr auto TexturePageY256 = IOBitSet(4);
|
static constexpr auto TexturePageY256 = Bit(4);
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef volatile uint32_t GPUREAD_v;
|
typedef volatile uint32_t GPUREAD_v;
|
||||||
|
|
|
@ -4,17 +4,17 @@
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
struct Interrupt {
|
struct Interrupt {
|
||||||
static constexpr auto VBlank = IOBitSet(0);
|
static constexpr auto VBlank = Bit(0);
|
||||||
static constexpr auto GPU = IOBitSet(1);
|
static constexpr auto GPU = Bit(1);
|
||||||
static constexpr auto CDROM = IOBitSet(2);
|
static constexpr auto CDROM = Bit(2);
|
||||||
static constexpr auto DMA = IOBitSet(3);
|
static constexpr auto DMA = Bit(3);
|
||||||
static constexpr auto Timer0 = IOBitSet(4);
|
static constexpr auto Timer0 = Bit(4);
|
||||||
static constexpr auto Timer1 = IOBitSet(5);
|
static constexpr auto Timer1 = Bit(5);
|
||||||
static constexpr auto Timer2 = IOBitSet(6);
|
static constexpr auto Timer2 = Bit(6);
|
||||||
static constexpr auto Periphery = IOBitSet(7);
|
static constexpr auto Periphery = Bit(7);
|
||||||
static constexpr auto SIO = IOBitSet(8);
|
static constexpr auto SIO = Bit(8);
|
||||||
static constexpr auto SPU = IOBitSet(9);
|
static constexpr auto SPU = Bit(9);
|
||||||
static constexpr auto Controller = IOBitSet(10);
|
static constexpr auto Controller = Bit(10);
|
||||||
static constexpr auto LightPen = Controller;
|
static constexpr auto LightPen = Controller;
|
||||||
|
|
||||||
__declare_io_type(Status, uint32_t,
|
__declare_io_type(Status, uint32_t,
|
||||||
|
@ -26,19 +26,19 @@ namespace JabyEngine {
|
||||||
__declare_new_io_port(Status, 0x1F801070);
|
__declare_new_io_port(Status, 0x1F801070);
|
||||||
__declare_new_io_port(Mask, 0x1F801074);
|
__declare_new_io_port(Mask, 0x1F801074);
|
||||||
|
|
||||||
static constexpr bool is_irq(IOBitSet irq) {
|
static constexpr bool is_irq(Bit irq) {
|
||||||
return Status.is_set(irq);
|
return Status.is_set(irq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr void ack_irq(IOBitSet irq) {
|
static constexpr void ack_irq(Bit irq) {
|
||||||
Status.clear(irq);
|
Status.clear(irq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr void disable_irq(IOBitSet irq) {
|
static constexpr void disable_irq(Bit irq) {
|
||||||
Mask.clear(irq);
|
Mask.clear(irq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enable_irq(IOBitSet irq) {
|
static void enable_irq(Bit irq) {
|
||||||
Mask.set(irq);
|
Mask.set(irq);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,49 +4,6 @@
|
||||||
#include "../../Auxiliary/types.hpp"
|
#include "../../Auxiliary/types.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
struct IOBitUnset {
|
|
||||||
uint16_t pos;
|
|
||||||
|
|
||||||
constexpr IOBitUnset(uint16_t bit_pos) : pos(bit_pos) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IOBitSet {
|
|
||||||
uint16_t pos;
|
|
||||||
|
|
||||||
constexpr IOBitSet(uint16_t bit_pos) : pos(bit_pos) {
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr IOBitUnset operator!() const {
|
|
||||||
return IOBitUnset(this->pos);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IOValueSet {
|
|
||||||
template<typename T>
|
|
||||||
using IOValueSetPair = pair<IOValueSet, T>;
|
|
||||||
|
|
||||||
uint16_t pos;
|
|
||||||
uint16_t length;
|
|
||||||
|
|
||||||
constexpr IOValueSet(uint16_t pos, uint16_t length) : pos(pos), length(length) {
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr IOValueSet from_to(uint16_t first_bit, uint16_t last_bit) {
|
|
||||||
return IOValueSet(first_bit, (last_bit - first_bit) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr IOValueSetPair<T> with(T value) const {
|
|
||||||
return {*this, value};
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
constexpr IOValueSetPair<T> range_max() const {
|
|
||||||
return IOValueSet::with<T>((1 << this->length) - 1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace IOPort {
|
namespace IOPort {
|
||||||
struct IOValueType {
|
struct IOValueType {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -91,24 +48,24 @@ namespace JabyEngine {
|
||||||
return Self().set_va(args...); \
|
return Self().set_va(args...); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
constexpr Self& set(IOBitSet bit) { \
|
constexpr Self& set(Bit bit) { \
|
||||||
this->raw_value = bit::set(this->raw_value, bit.pos); \
|
this->raw_value = bit::set(this->raw_value, bit); \
|
||||||
return *this; \
|
return *this; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
constexpr Self& set(IOBitUnset bit) { \
|
constexpr Self& set(ClearBit bit) { \
|
||||||
this->raw_value = bit::clear(this->raw_value, bit.pos); \
|
this->raw_value = bit::set(this->raw_value, bit); \
|
||||||
return *this; \
|
return *this; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
constexpr Self& set(IOValueSet bits, UnderlyingValue value) { \
|
constexpr Self& set(BitRange bits, UnderlyingValue value) { \
|
||||||
this->raw_value = bit::value::set_normalized(this->raw_value, value, bits.pos, bits.length); \
|
this->raw_value = bit::value::set_normalized(this->raw_value, bits, value); \
|
||||||
return *this; \
|
return *this; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
template<typename S> \
|
template<typename S> \
|
||||||
constexpr Self& set(const IOValueSet::IOValueSetPair<S>& value) { \
|
constexpr Self& set(const BitRange::RangeValuePair<S>& value) { \
|
||||||
this->set(value.first, static_cast<UnderlyingValue>(value.second)); \
|
this->raw_value = bit::value::set_normalized(this->raw_value, value); \
|
||||||
return *this; \
|
return *this; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
|
@ -122,17 +79,17 @@ namespace JabyEngine {
|
||||||
return this->set(head).set_va(tail...); \
|
return this->set(head).set_va(tail...); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
constexpr UnderlyingValue get(IOValueSet bits) const { \
|
constexpr UnderlyingValue get(BitRange bits) const { \
|
||||||
return bit::value::get_normalized(this->raw_value, bits.pos, bits.length); \
|
return bit::value::get_normalized(this->raw_value, bits.pos, bits.length); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
constexpr Self& clear(IOBitSet bit) { \
|
constexpr Self& clear(Bit bit) { \
|
||||||
this->raw_value = bit::clear(this->raw_value, bit.pos); \
|
this->raw_value = bit::clear(this->raw_value, bit); \
|
||||||
return *this; \
|
return *this; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
constexpr bool is_set(IOBitSet bit) const { \
|
constexpr bool is_set(Bit bit) const { \
|
||||||
return bit::is_set(this->raw_value, bit.pos); \
|
return bit::is_set(this->raw_value, bit); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
constexpr void operator=(UnderlyingValue value) { \
|
constexpr void operator=(UnderlyingValue value) { \
|
||||||
|
@ -160,38 +117,6 @@ namespace JabyEngine {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// For use with ComplexBitMaps or what else satisfies this API
|
|
||||||
template<typename T>
|
|
||||||
struct VolatileBitMapPOD {
|
|
||||||
typedef typename T::UnderlyingType Raw;
|
|
||||||
|
|
||||||
VolatilePOD<Raw> pod;
|
|
||||||
|
|
||||||
constexpr Raw read_raw() const {
|
|
||||||
return this->pod.read();
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr T read() const {
|
|
||||||
return T{this->pod.read()};
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr Raw read(const BitRange<Raw>& range) const {
|
|
||||||
return VolatileBitMapPOD<T>::read().get_value(range);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void write_raw(Raw value) {
|
|
||||||
this->pod.write(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void write(const T& value) {
|
|
||||||
this->pod.write(static_cast<Raw>(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void write(const BitRangeValue<Raw>& value) {
|
|
||||||
VolatileBitMapPOD<T>::write(T{T::with(value)});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct __no_align ubus32_t {
|
struct __no_align ubus32_t {
|
||||||
__declare_io_type(uint16_t, uint16_t,);
|
__declare_io_type(uint16_t, uint16_t,);
|
||||||
uint16_t_v low;
|
uint16_t_v low;
|
||||||
|
|
|
@ -42,33 +42,33 @@ namespace JabyEngine {
|
||||||
|
|
||||||
__declare_io_type(SweepVolume, int16_t,
|
__declare_io_type(SweepVolume, int16_t,
|
||||||
// For Volume Mode
|
// For Volume Mode
|
||||||
static constexpr auto SweepEnable = IOBitSet(15);
|
static constexpr auto SweepEnable = Bit(15);
|
||||||
static constexpr auto VolumeEnable = !SweepEnable;
|
static constexpr auto VolumeEnable = !SweepEnable;
|
||||||
static constexpr auto Volume = IOValueSet::from_to(0, 14);
|
static constexpr auto Volume = BitRange::from_to(0, 14);
|
||||||
|
|
||||||
// For Sweep Mode
|
// For Sweep Mode
|
||||||
static constexpr auto SweepMode = IOBitSet(14);
|
static constexpr auto SweepMode = Bit(14);
|
||||||
static constexpr auto SweepDirection = IOBitSet(13);
|
static constexpr auto SweepDirection = Bit(13);
|
||||||
static constexpr auto SweepPhase = IOBitSet(12);
|
static constexpr auto SweepPhase = Bit(12);
|
||||||
static constexpr auto SweepShift = IOValueSet::from_to(2, 6);
|
static constexpr auto SweepShift = BitRange::from_to(2, 6);
|
||||||
static constexpr auto SweepStep = IOValueSet::from_to(0, 1);
|
static constexpr auto SweepStep = BitRange::from_to(0, 1);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(SR, uint16_t,
|
__declare_io_type(SR, uint16_t,
|
||||||
static constexpr auto SustainMode = IOBitSet(31 - 16);
|
static constexpr auto SustainMode = Bit(31 - 16);
|
||||||
static constexpr auto SustainDirection = IOBitSet(30 - 16);
|
static constexpr auto SustainDirection = Bit(30 - 16);
|
||||||
static constexpr auto SustainShift = IOValueSet::from_to((24 - 16), (28 - 16));
|
static constexpr auto SustainShift = BitRange::from_to((24 - 16), (28 - 16));
|
||||||
static constexpr auto SustainStep = IOValueSet::from_to((22 - 16), (23 - 16));
|
static constexpr auto SustainStep = BitRange::from_to((22 - 16), (23 - 16));
|
||||||
static constexpr auto ReleaseMode = IOBitSet(21 - 16);
|
static constexpr auto ReleaseMode = Bit(21 - 16);
|
||||||
static constexpr auto ReleaseShift = IOValueSet::from_to((16 - 16), (20 - 16));
|
static constexpr auto ReleaseShift = BitRange::from_to((16 - 16), (20 - 16));
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(AD, uint16_t,
|
__declare_io_type(AD, uint16_t,
|
||||||
static constexpr auto AttackMode = IOBitSet(15);
|
static constexpr auto AttackMode = Bit(15);
|
||||||
static constexpr auto AttackShift = IOValueSet::from_to(10, 14);
|
static constexpr auto AttackShift = BitRange::from_to(10, 14);
|
||||||
static constexpr auto AttackStep = IOValueSet::from_to(8, 9);
|
static constexpr auto AttackStep = BitRange::from_to(8, 9);
|
||||||
static constexpr auto DecayShift = IOValueSet::from_to(4, 7);
|
static constexpr auto DecayShift = BitRange::from_to(4, 7);
|
||||||
static constexpr auto SustainLevel = IOValueSet::from_to(0, 3);
|
static constexpr auto SustainLevel = BitRange::from_to(0, 3);
|
||||||
);
|
);
|
||||||
|
|
||||||
struct __no_align Voice_v {
|
struct __no_align Voice_v {
|
||||||
|
@ -90,29 +90,29 @@ namespace JabyEngine {
|
||||||
DMARead = 3
|
DMARead = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto Enable = IOBitSet(15);
|
static constexpr auto Enable = Bit(15);
|
||||||
static constexpr auto Unmute = IOBitSet(14);
|
static constexpr auto Unmute = Bit(14);
|
||||||
static constexpr auto NoiseFrequcenyShift = IOValueSet::from_to(10, 13);
|
static constexpr auto NoiseFrequcenyShift = BitRange::from_to(10, 13);
|
||||||
static constexpr auto NoiseFrequcenyStep = IOValueSet::from_to(8, 9);
|
static constexpr auto NoiseFrequcenyStep = BitRange::from_to(8, 9);
|
||||||
static constexpr auto ReverbMasterEnable = IOBitSet(7);
|
static constexpr auto ReverbMasterEnable = Bit(7);
|
||||||
static constexpr auto IRQ9Enable = IOBitSet(6);
|
static constexpr auto IRQ9Enable = Bit(6);
|
||||||
static constexpr auto TransferMode = IOValueSet::from_to(4, 5);
|
static constexpr auto TransferMode = BitRange::from_to(4, 5);
|
||||||
static constexpr auto ExternalAudioReverb = IOBitSet(3);
|
static constexpr auto ExternalAudioReverb = Bit(3);
|
||||||
static constexpr auto CDAudioReverb = IOBitSet(2);
|
static constexpr auto CDAudioReverb = Bit(2);
|
||||||
static constexpr auto ExternalAudioEnable = IOBitSet(1);
|
static constexpr auto ExternalAudioEnable = Bit(1);
|
||||||
static constexpr auto CDAudioEnable = IOBitSet(0);
|
static constexpr auto CDAudioEnable = Bit(0);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(PMON, uint16_t,
|
__declare_io_type(PMON, uint16_t,
|
||||||
static constexpr auto EnableBits = IOValueSet::from_to(1, 23);
|
static constexpr auto EnableBits = BitRange::from_to(1, 23);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(NON, uint16_t,
|
__declare_io_type(NON, uint16_t,
|
||||||
static constexpr auto NoiseBits = IOValueSet::from_to(0, 23);
|
static constexpr auto NoiseBits = BitRange::from_to(0, 23);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(EON, uint16_t,
|
__declare_io_type(EON, uint16_t,
|
||||||
static constexpr auto EchoBits = IOValueSet::from_to(0, 23);
|
static constexpr auto EchoBits = BitRange::from_to(0, 23);
|
||||||
);
|
);
|
||||||
|
|
||||||
static constexpr size_t VoiceCount = 24;
|
static constexpr size_t VoiceCount = 24;
|
||||||
|
|
|
@ -5,28 +5,28 @@
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace Timer_IO {
|
namespace Timer_IO {
|
||||||
__declare_io_type(CounterMode, uint32_t,
|
__declare_io_type(CounterMode, uint32_t,
|
||||||
static constexpr auto SyncEnable = IOBitSet(0);
|
static constexpr auto SyncEnable = Bit(0);
|
||||||
static constexpr auto FreeRun = !SyncEnable;
|
static constexpr auto FreeRun = !SyncEnable;
|
||||||
static constexpr auto SyncMode = IOValueSet::from_to(1, 2);
|
static constexpr auto SyncMode = BitRange::from_to(1, 2);
|
||||||
static constexpr auto ResetAfterTarget = IOBitSet(3);
|
static constexpr auto ResetAfterTarget = Bit(3);
|
||||||
static constexpr auto IRQAtTarget = IOBitSet(4);
|
static constexpr auto IRQAtTarget = Bit(4);
|
||||||
static constexpr auto IRQAtMax = IOBitSet(5);
|
static constexpr auto IRQAtMax = Bit(5);
|
||||||
static constexpr auto IRQEveryTime = IOBitSet(6);
|
static constexpr auto IRQEveryTime = Bit(6);
|
||||||
static constexpr auto IRQOneShot = !IRQEveryTime;
|
static constexpr auto IRQOneShot = !IRQEveryTime;
|
||||||
static constexpr auto IRQToggle = IOBitSet(7);
|
static constexpr auto IRQToggle = Bit(7);
|
||||||
static constexpr auto IRQPulse = !IRQToggle;
|
static constexpr auto IRQPulse = !IRQToggle;
|
||||||
static constexpr auto ClockSource = IOValueSet::from_to(8, 9);
|
static constexpr auto ClockSource = BitRange::from_to(8, 9);
|
||||||
static constexpr auto HasIRQRequest = IOBitSet(10);
|
static constexpr auto HasIRQRequest = Bit(10);
|
||||||
static constexpr auto IsTargetReached = IOBitSet(11);
|
static constexpr auto IsTargetReached = Bit(11);
|
||||||
static constexpr auto IsMaxReached = IOBitSet(12);
|
static constexpr auto IsMaxReached = Bit(12);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(CounterTarget, uint32_t,
|
__declare_io_type(CounterTarget, uint32_t,
|
||||||
static constexpr auto CounterTargetValue = IOValueSet::from_to(0, 15);
|
static constexpr auto CounterTargetValue = BitRange::from_to(0, 15);
|
||||||
);
|
);
|
||||||
|
|
||||||
__declare_io_type(CounterValue, uint32_t,
|
__declare_io_type(CounterValue, uint32_t,
|
||||||
static constexpr auto Value = IOValueSet::from_to(0, 15);
|
static constexpr auto Value = BitRange::from_to(0, 15);
|
||||||
);
|
);
|
||||||
|
|
||||||
struct __no_align Counter {
|
struct __no_align Counter {
|
||||||
|
|
|
@ -7,19 +7,19 @@
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace CD {
|
namespace CD {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
struct Mode : public ComplexBitMap<uint8_t> {
|
__declare_io_type(Mode, uint8_t,
|
||||||
static constexpr auto DoubleSpeed = Bit<uint8_t>(7);
|
static constexpr auto DoubleSpeed = Bit(7);
|
||||||
static constexpr auto SingleSpeed = !DoubleSpeed;
|
static constexpr auto SingleSpeed = !DoubleSpeed;
|
||||||
static constexpr auto XADPCM = Bit<uint8_t>(6);
|
static constexpr auto XADPCM = Bit(6);
|
||||||
static constexpr auto WholeSector = Bit<uint8_t>(5);
|
static constexpr auto WholeSector = Bit(5);
|
||||||
static constexpr auto DataSector = !WholeSector;
|
static constexpr auto DataSector = !WholeSector;
|
||||||
static constexpr auto UseXAFilter = Bit<uint8_t>(3);
|
static constexpr auto UseXAFilter = Bit(3);
|
||||||
static constexpr auto AudioPlayIRQ = Bit<uint8_t>(2);
|
static constexpr auto AudioPlayIRQ = Bit(2);
|
||||||
static constexpr auto AutoPauseTrack = Bit<uint8_t>(1);
|
static constexpr auto AutoPauseTrack = Bit(1);
|
||||||
static constexpr auto CDDA = Bit<uint8_t>(0);
|
static constexpr auto CDDA = Bit(0);
|
||||||
};
|
);
|
||||||
|
|
||||||
static constexpr auto DataSectorMode = Mode::with(Mode::DoubleSpeed, Mode::DataSector);
|
static constexpr auto DataSectorMode = Mode_t::from(Mode_t::DoubleSpeed, Mode_t::DataSector);
|
||||||
|
|
||||||
static SectorBufferAllocator sector_allocator;
|
static SectorBufferAllocator sector_allocator;
|
||||||
static uint16_t sectors_left;
|
static uint16_t sectors_left;
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace JabyEngine {
|
||||||
void start() {
|
void start() {
|
||||||
NextRoutine next_routine = JabyEngine::NextRoutine::from(boot::Start::setup);
|
NextRoutine next_routine = JabyEngine::NextRoutine::from(boot::Start::setup);
|
||||||
|
|
||||||
printf("Starting Planschbecken 0x%p\n", next_routine.value);
|
printf("Starting Planschbecken Version 0 0x%p\n", next_routine.value);
|
||||||
while(true) {
|
while(true) {
|
||||||
if(next_routine.is_null()) {
|
if(next_routine.is_null()) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue