From d9919e3317f7f21eeec017e806101ad63bdc0498 Mon Sep 17 00:00:00 2001 From: Jaby Date: Mon, 5 Sep 2022 22:35:38 +0200 Subject: [PATCH] Support 'with' --- include/PSX/System/IOPorts/IOPort.hpp | 38 +++++++++++++++++++------ src/Library/src/BootLoader/boot_spu.cpp | 4 +-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/include/PSX/System/IOPorts/IOPort.hpp b/include/PSX/System/IOPorts/IOPort.hpp index efa21bcc..56c9760d 100644 --- a/include/PSX/System/IOPorts/IOPort.hpp +++ b/include/PSX/System/IOPorts/IOPort.hpp @@ -27,6 +27,13 @@ struct Bit { } }; +template +struct BitRangeValue { + T value; + size_t begin; + size_t length; +}; + template struct BitRange { typedef T ValueType; @@ -37,20 +44,15 @@ struct BitRange { static constexpr BitRange from_to(size_t start, size_t end) { return {start, (end - start + 1)}; } -}; -template -struct BitRangeValue { - T value; - BitRange range; - - constexpr BitRangeValue(BitRange range, T value) : value(value), range(range) { + constexpr BitRangeValue with(T value) const { + return {value, this->begin, this->length}; } }; template static constexpr __always_inline BitRangeValue operator<<(const BitRange& range, T value) { - return BitRangeValue(range, value); + return BitRangeValue{value, range.begin, range.length}; } template @@ -58,11 +60,26 @@ class __no_align ComplexBitMap { private: T value = 0; + template + constexpr ComplexBitMap& set_va(const S& value) { + return this->set(value); + } + + template + constexpr ComplexBitMap& set_va(const S& value, const ARGS&...args) { + return this->set_va(value).set_va(args...); + } + public: constexpr ComplexBitMap() = default; constexpr ComplexBitMap(T value) : value(value) { } + template + static constexpr ComplexBitMap with(ARGS...args) { + return ComplexBitMap().set_va(args...); + } + //Accesssing bits template constexpr ComplexBitMap& set_bit(S bit) { @@ -136,7 +153,7 @@ public: } constexpr ComplexBitMap& set(const BitRangeValue& value) { - this->set_value(value.value, value.range); + this->set_value(value.value, {value.begin, value.length}); return *this; } @@ -241,6 +258,9 @@ static constexpr uintptr_t IO_Base_Adr = 0x10000000; using ComplexBitMap::operator=; \ constexpr name() = default; \ constexpr name(ComplexBitMap value) : ComplexBitMap(value) { \ + }\ + template \ + constexpr name(ARGS...args) : ComplexBitMap(args...) {\ } #endif //!__JABYENGINE_IOPORT_HPP__ \ No newline at end of file diff --git a/src/Library/src/BootLoader/boot_spu.cpp b/src/Library/src/BootLoader/boot_spu.cpp index 9a45204a..4d2eac7e 100644 --- a/src/Library/src/BootLoader/boot_spu.cpp +++ b/src/Library/src/BootLoader/boot_spu.cpp @@ -10,7 +10,7 @@ namespace SPU { } static void clear_main_volume() { - static constexpr auto StartVol = SweepVolume().set(!SweepVolume::SweepEnable).set(SweepVolume::Volume, I16_MAX >> 2); + static constexpr auto StartVol = SweepVolume::with(!SweepVolume::SweepEnable, SweepVolume::Volume.with(I16_MAX >> 2)); MainVolume::left.write(StartVol); MainVolume::right.write(StartVol); @@ -58,7 +58,7 @@ namespace SPU { } static void setup_control_register() { - static constexpr auto SetupValue = ControlRegister().set(ControlRegister::Enable).set(ControlRegister::Unmute).set(ControlRegister::CDAudioEnable); + static constexpr auto SetupValue = ControlRegister::with(ControlRegister::Enable, ControlRegister::Unmute, ControlRegister::CDAudioEnable); Control.write(SetupValue); }