From 66b3686d849d1c11a84340c08796ee017b78d92f Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Mon, 19 Dec 2022 22:37:35 -0800 Subject: [PATCH] DSPHLE: Add Desert Bus libasnd ucode variants --- Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp | 16 ++++++++++++++-- Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h | 9 +++++++++ Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp index 3d8c6749e9..294270856d 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp @@ -54,9 +54,15 @@ constexpr u32 FLAGS_SAMPLE_FORMAT_BYTES_SHIFT = 16; constexpr u32 SAMPLE_RATE = 48000; +bool ASndUCode::SwapLeftRight() const +{ + return m_crc == HASH_DESERT_BUS_2011 || m_crc == HASH_DESERT_BUS_2012; +} + bool ASndUCode::UseNewFlagMasks() const { - return m_crc == HASH_2011 || m_crc == HASH_2020 || m_crc == HASH_2020_PAD; + return m_crc == HASH_2011 || m_crc == HASH_2020 || m_crc == HASH_2020_PAD || + m_crc == HASH_DESERT_BUS_2011 || m_crc == HASH_DESERT_BUS_2012; } ASndUCode::ASndUCode(DSPHLE* dsphle, u32 crc) : UCodeInterface(dsphle, crc) @@ -383,7 +389,13 @@ void ASndUCode::DoMixing(u32 return_mail) } // Both paths jmpr $AR3, which is an index into sample_selector - const auto [new_r, new_l] = (this->*sample_function)(); + auto [new_r, new_l] = (this->*sample_function)(); + if (SwapLeftRight()) + { + // The Desert Bus versions swapped the left and right input channels so that left + // comes first, and then right. Before, right came before left. + std::swap(new_r, new_l); + } // out_samp: "multiply sample x volume" - left is put in $ax0.h, right is put in $ax1.h // All functions jumped to from sample_selector jump or fall through here (zero_samples also diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h b/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h index 2849c80f8b..51524ad7ef 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h +++ b/Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h @@ -51,6 +51,14 @@ public: // https://github.com/extremscorner/libogc2/commit/0b64f879808953d80ba06501a1c079b0fbf017d2 // https://github.com/extremscorner/libogc-rice/commit/ce22c3269699fdbd474f2f28ca2ffca211954659 static constexpr u32 HASH_2020_PAD = 0xbad876ef; + // Variant used in Desert Bus v1.04 - this is based off of the code in libogc (as it existed in + // 2011, even though that code only became used in 2020), but the left and right channels are + // swapped. Padded to 0x0620 bytes. + static constexpr u32 HASH_DESERT_BUS_2011 = 0xfa9c576f; + // Variant used in Desert Bus v1.05 - this is the same as the previous version, except 4 junk + // instructions were added to the start, which do not change behavior in any way. Padded to 0x0620 + // bytes. + static constexpr u32 HASH_DESERT_BUS_2012 = 0x614dd145; private: void DMAInVoiceData(); @@ -60,6 +68,7 @@ private: void ChangeBuffer(); void DoMixing(u32 return_mail); + bool SwapLeftRight() const; bool UseNewFlagMasks() const; std::pair ReadSampleMono8Bits() const; diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp index 9e4a2c9f99..0a5c6907bf 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp @@ -313,6 +313,8 @@ std::unique_ptr UCodeFactory(u32 crc, DSPHLE* dsphle, bool wii) case ASndUCode::HASH_2011: case ASndUCode::HASH_2020: case ASndUCode::HASH_2020_PAD: + case ASndUCode::HASH_DESERT_BUS_2011: + case ASndUCode::HASH_DESERT_BUS_2012: INFO_LOG_FMT(DSPHLE, "CRC {:08x}: ASnd chosen (Homebrew)", crc); return std::make_unique(dsphle, crc);