Use new fancy way to set values at build time
This commit is contained in:
parent
c7608b7934
commit
595b6e0ec5
|
@ -2,6 +2,13 @@
|
||||||
#define __JABYENGINE_IOPORT_HPP__
|
#define __JABYENGINE_IOPORT_HPP__
|
||||||
#include "../../Auxiliary/bits.hpp"
|
#include "../../Auxiliary/bits.hpp"
|
||||||
|
|
||||||
|
struct ClearBitValue {
|
||||||
|
size_t bit;
|
||||||
|
|
||||||
|
constexpr ClearBitValue(size_t bit) : bit(bit) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct Bit {
|
struct Bit {
|
||||||
typedef T ValueType;
|
typedef T ValueType;
|
||||||
|
@ -14,6 +21,10 @@ struct Bit {
|
||||||
constexpr operator size_t() const {
|
constexpr operator size_t() const {
|
||||||
return this->value;
|
return this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr ClearBitValue operator!() const {
|
||||||
|
return ClearBitValue(this->value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -28,6 +39,20 @@ struct BitRange {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct BitRangeValue {
|
||||||
|
T value;
|
||||||
|
BitRange<T> range;
|
||||||
|
|
||||||
|
constexpr BitRangeValue(BitRange<T> range, T value) : value(value), range(range) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
|
||||||
|
return BitRangeValue(range, value);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class __no_align IOPort {
|
class __no_align IOPort {
|
||||||
private:
|
private:
|
||||||
|
@ -130,6 +155,22 @@ public:
|
||||||
constexpr void operator=(T value) volatile {
|
constexpr void operator=(T value) volatile {
|
||||||
this->value = value;
|
this->value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For easier constructing
|
||||||
|
constexpr IOPort<T>& operator|(const BitRangeValue<T>& value) {
|
||||||
|
this->set_value(value.value, value.range);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr IOPort<T>& operator|(const Bit<T>& bit) {
|
||||||
|
this->set_bit(bit.value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr IOPort<T>& operator|(const ClearBitValue& value) {
|
||||||
|
this->clear_bit(value.bit);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __no_align ubus32_t {
|
struct __no_align ubus32_t {
|
||||||
|
|
|
@ -91,7 +91,7 @@ namespace SPU {
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr Bit<uint16_t> Enable = 15;
|
static constexpr Bit<uint16_t> Enable = 15;
|
||||||
static constexpr Bit<uint16_t> Mute = 14;
|
static constexpr Bit<uint16_t> Unmute = 14;
|
||||||
static constexpr BitRange<Shift> NoiseFrequcenyShift = BitRange<Shift>::from_to(10, 13);
|
static constexpr BitRange<Shift> NoiseFrequcenyShift = BitRange<Shift>::from_to(10, 13);
|
||||||
static constexpr BitRange<Step> NoiseFrequcenyStep = BitRange<Step>::from_to(8, 9);
|
static constexpr BitRange<Step> NoiseFrequcenyStep = BitRange<Step>::from_to(8, 9);
|
||||||
static constexpr Bit<uint16_t> ReverbMasterEnable = 7;
|
static constexpr Bit<uint16_t> ReverbMasterEnable = 7;
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace SPU {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void clear_main_volume() {
|
static void clear_main_volume() {
|
||||||
static constexpr auto StartVol = SweepVolume().clear_bit(SweepVolume::SweepEnable).set_value(static_cast<int16_t>(I16_MAX >> 2), SweepVolume::Volume);
|
static constexpr auto StartVol = SweepVolume() | !SweepVolume::SweepEnable | (SweepVolume::Volume << static_cast<int16_t>(I16_MAX >> 2));
|
||||||
|
|
||||||
MainVolume::left.write(StartVol);
|
MainVolume::left.write(StartVol);
|
||||||
MainVolume::right.write(StartVol);
|
MainVolume::right.write(StartVol);
|
||||||
|
@ -19,9 +19,17 @@ namespace SPU {
|
||||||
Control.write(ControlRegister());
|
Control.write(ControlRegister());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setup_control_register() {
|
||||||
|
static constexpr auto SetupValue = ControlRegister() | ControlRegister::Enable | ControlRegister::Unmute | ControlRegister::CDAudioEnable;
|
||||||
|
|
||||||
|
Control.write(SetupValue);
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
clear_key();
|
clear_key();
|
||||||
clear_main_volume();
|
clear_main_volume();
|
||||||
clear_control_register();
|
clear_control_register();
|
||||||
|
|
||||||
|
setup_control_register();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue