diff --git a/include/PSX/System/IOPorts/IOPort.hpp b/include/PSX/System/IOPorts/IOPort.hpp index 462091e6..4b88b87d 100644 --- a/include/PSX/System/IOPorts/IOPort.hpp +++ b/include/PSX/System/IOPorts/IOPort.hpp @@ -2,6 +2,13 @@ #define __JABYENGINE_IOPORT_HPP__ #include "../../Auxiliary/bits.hpp" +struct ClearBitValue { + size_t bit; + + constexpr ClearBitValue(size_t bit) : bit(bit) { + } +}; + template struct Bit { typedef T ValueType; @@ -14,6 +21,10 @@ struct Bit { constexpr operator size_t() const { return this->value; } + + constexpr ClearBitValue operator!() const { + return ClearBitValue(this->value); + } }; template @@ -28,6 +39,20 @@ struct BitRange { } }; +template +struct BitRangeValue { + T value; + BitRange range; + + constexpr BitRangeValue(BitRange range, T value) : value(value), range(range) { + } +}; + +template +static constexpr __always_inline BitRangeValue operator<<(const BitRange& range, T value) { + return BitRangeValue(range, value); +} + template class __no_align IOPort { private: @@ -130,6 +155,22 @@ public: constexpr void operator=(T value) volatile { this->value = value; } + + // For easier constructing + constexpr IOPort& operator|(const BitRangeValue& value) { + this->set_value(value.value, value.range); + return *this; + } + + constexpr IOPort& operator|(const Bit& bit) { + this->set_bit(bit.value); + return *this; + } + + constexpr IOPort& operator|(const ClearBitValue& value) { + this->clear_bit(value.bit); + return *this; + } }; struct __no_align ubus32_t { diff --git a/include/PSX/System/IOPorts/SPU_IO.hpp b/include/PSX/System/IOPorts/SPU_IO.hpp index b9b26d21..68d23310 100644 --- a/include/PSX/System/IOPorts/SPU_IO.hpp +++ b/include/PSX/System/IOPorts/SPU_IO.hpp @@ -91,7 +91,7 @@ namespace SPU { }; static constexpr Bit Enable = 15; - static constexpr Bit Mute = 14; + static constexpr Bit Unmute = 14; static constexpr BitRange NoiseFrequcenyShift = BitRange::from_to(10, 13); static constexpr BitRange NoiseFrequcenyStep = BitRange::from_to(8, 9); static constexpr Bit ReverbMasterEnable = 7; diff --git a/src/Library/src/BootLoader/boot_spu.cpp b/src/Library/src/BootLoader/boot_spu.cpp index ff4aead8..f51ee1c5 100644 --- a/src/Library/src/BootLoader/boot_spu.cpp +++ b/src/Library/src/BootLoader/boot_spu.cpp @@ -9,7 +9,7 @@ namespace SPU { } static void clear_main_volume() { - static constexpr auto StartVol = SweepVolume().clear_bit(SweepVolume::SweepEnable).set_value(static_cast(I16_MAX >> 2), SweepVolume::Volume); + static constexpr auto StartVol = SweepVolume() | !SweepVolume::SweepEnable | (SweepVolume::Volume << static_cast(I16_MAX >> 2)); MainVolume::left.write(StartVol); MainVolume::right.write(StartVol); @@ -19,9 +19,17 @@ namespace SPU { Control.write(ControlRegister()); } + static void setup_control_register() { + static constexpr auto SetupValue = ControlRegister() | ControlRegister::Enable | ControlRegister::Unmute | ControlRegister::CDAudioEnable; + + Control.write(SetupValue); + } + void setup() { clear_key(); clear_main_volume(); clear_control_register(); + + setup_control_register(); } } \ No newline at end of file