Skip to content

Commit d853da3

Browse files
Merge pull request dolphin-emu#11354 from Pokechu22/desert-bus-asnd-ucode
DSPHLE: Add Desert Bus libasnd ucode variants
2 parents 5348c8b + 66b3686 commit d853da3

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

Source/Core/Core/HW/DSPHLE/UCodes/ASnd.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,15 @@ constexpr u32 FLAGS_SAMPLE_FORMAT_BYTES_SHIFT = 16;
5454

5555
constexpr u32 SAMPLE_RATE = 48000;
5656

57+
bool ASndUCode::SwapLeftRight() const
58+
{
59+
return m_crc == HASH_DESERT_BUS_2011 || m_crc == HASH_DESERT_BUS_2012;
60+
}
61+
5762
bool ASndUCode::UseNewFlagMasks() const
5863
{
59-
return m_crc == HASH_2011 || m_crc == HASH_2020 || m_crc == HASH_2020_PAD;
64+
return m_crc == HASH_2011 || m_crc == HASH_2020 || m_crc == HASH_2020_PAD ||
65+
m_crc == HASH_DESERT_BUS_2011 || m_crc == HASH_DESERT_BUS_2012;
6066
}
6167

6268
ASndUCode::ASndUCode(DSPHLE* dsphle, u32 crc) : UCodeInterface(dsphle, crc)
@@ -383,7 +389,13 @@ void ASndUCode::DoMixing(u32 return_mail)
383389
}
384390
// Both paths jmpr $AR3, which is an index into sample_selector
385391

386-
const auto [new_r, new_l] = (this->*sample_function)();
392+
auto [new_r, new_l] = (this->*sample_function)();
393+
if (SwapLeftRight())
394+
{
395+
// The Desert Bus versions swapped the left and right input channels so that left
396+
// comes first, and then right. Before, right came before left.
397+
std::swap(new_r, new_l);
398+
}
387399
// out_samp: "multiply sample x volume" - left is put in $ax0.h, right is put in $ax1.h
388400

389401
// All functions jumped to from sample_selector jump or fall through here (zero_samples also

Source/Core/Core/HW/DSPHLE/UCodes/ASnd.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ class ASndUCode final : public UCodeInterface
5151
// https://github.com/extremscorner/libogc2/commit/0b64f879808953d80ba06501a1c079b0fbf017d2
5252
// https://github.com/extremscorner/libogc-rice/commit/ce22c3269699fdbd474f2f28ca2ffca211954659
5353
static constexpr u32 HASH_2020_PAD = 0xbad876ef;
54+
// Variant used in Desert Bus v1.04 - this is based off of the code in libogc (as it existed in
55+
// 2011, even though that code only became used in 2020), but the left and right channels are
56+
// swapped. Padded to 0x0620 bytes.
57+
static constexpr u32 HASH_DESERT_BUS_2011 = 0xfa9c576f;
58+
// Variant used in Desert Bus v1.05 - this is the same as the previous version, except 4 junk
59+
// instructions were added to the start, which do not change behavior in any way. Padded to 0x0620
60+
// bytes.
61+
static constexpr u32 HASH_DESERT_BUS_2012 = 0x614dd145;
5462

5563
private:
5664
void DMAInVoiceData();
@@ -60,6 +68,7 @@ class ASndUCode final : public UCodeInterface
6068
void ChangeBuffer();
6169
void DoMixing(u32 return_mail);
6270

71+
bool SwapLeftRight() const;
6372
bool UseNewFlagMasks() const;
6473

6574
std::pair<s16, s16> ReadSampleMono8Bits() const;

Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ std::unique_ptr<UCodeInterface> UCodeFactory(u32 crc, DSPHLE* dsphle, bool wii)
313313
case ASndUCode::HASH_2011:
314314
case ASndUCode::HASH_2020:
315315
case ASndUCode::HASH_2020_PAD:
316+
case ASndUCode::HASH_DESERT_BUS_2011:
317+
case ASndUCode::HASH_DESERT_BUS_2012:
316318
INFO_LOG_FMT(DSPHLE, "CRC {:08x}: ASnd chosen (Homebrew)", crc);
317319
return std::make_unique<ASndUCode>(dsphle, crc);
318320

0 commit comments

Comments
 (0)