summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2016-04-29 18:18:26 +0200
committerbunnei <bunneidev@gmail.com>2016-04-29 18:18:26 +0200
commit73624b4721a091022e6c715b96d69daddc933fdd (patch)
tree5ea541705fb66a829e2cf6060af39b7cf0054109 /src
parentMerge pull request #1723 from MerryMage/audio-interp (diff)
parentAudioCore: CurrentRegion() -> ReadRegion(), WriteRegion() (diff)
downloadyuzu-73624b4721a091022e6c715b96d69daddc933fdd.tar
yuzu-73624b4721a091022e6c715b96d69daddc933fdd.tar.gz
yuzu-73624b4721a091022e6c715b96d69daddc933fdd.tar.bz2
yuzu-73624b4721a091022e6c715b96d69daddc933fdd.tar.lz
yuzu-73624b4721a091022e6c715b96d69daddc933fdd.tar.xz
yuzu-73624b4721a091022e6c715b96d69daddc933fdd.tar.zst
yuzu-73624b4721a091022e6c715b96d69daddc933fdd.zip
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/audio_core.cpp4
-rw-r--r--src/audio_core/hle/dsp.cpp44
-rw-r--r--src/audio_core/hle/dsp.h9
3 files changed, 31 insertions, 26 deletions
diff --git a/src/audio_core/audio_core.cpp b/src/audio_core/audio_core.cpp
index b512b0f9b..cbe869a04 100644
--- a/src/audio_core/audio_core.cpp
+++ b/src/audio_core/audio_core.cpp
@@ -38,10 +38,10 @@ void Init() {
/// Add DSP address spaces to Process's address space.
void AddAddressSpace(Kernel::VMManager& address_space) {
- auto r0_vma = address_space.MapBackingMemory(DSP::HLE::region0_base, reinterpret_cast<u8*>(&DSP::HLE::g_region0), sizeof(DSP::HLE::SharedMemory), Kernel::MemoryState::IO).MoveFrom();
+ auto r0_vma = address_space.MapBackingMemory(DSP::HLE::region0_base, reinterpret_cast<u8*>(&DSP::HLE::g_regions[0]), sizeof(DSP::HLE::SharedMemory), Kernel::MemoryState::IO).MoveFrom();
address_space.Reprotect(r0_vma, Kernel::VMAPermission::ReadWrite);
- auto r1_vma = address_space.MapBackingMemory(DSP::HLE::region1_base, reinterpret_cast<u8*>(&DSP::HLE::g_region1), sizeof(DSP::HLE::SharedMemory), Kernel::MemoryState::IO).MoveFrom();
+ auto r1_vma = address_space.MapBackingMemory(DSP::HLE::region1_base, reinterpret_cast<u8*>(&DSP::HLE::g_regions[1]), sizeof(DSP::HLE::SharedMemory), Kernel::MemoryState::IO).MoveFrom();
address_space.Reprotect(r1_vma, Kernel::VMAPermission::ReadWrite);
}
diff --git a/src/audio_core/hle/dsp.cpp b/src/audio_core/hle/dsp.cpp
index c89356edc..5759a5b9e 100644
--- a/src/audio_core/hle/dsp.cpp
+++ b/src/audio_core/hle/dsp.cpp
@@ -8,8 +8,32 @@
namespace DSP {
namespace HLE {
-SharedMemory g_region0;
-SharedMemory g_region1;
+std::array<SharedMemory, 2> g_regions;
+
+static size_t CurrentRegionIndex() {
+ // The region with the higher frame counter is chosen unless there is wraparound.
+ // This function only returns a 0 or 1.
+
+ if (g_regions[0].frame_counter == 0xFFFFu && g_regions[1].frame_counter != 0xFFFEu) {
+ // Wraparound has occured.
+ return 1;
+ }
+
+ if (g_regions[1].frame_counter == 0xFFFFu && g_regions[0].frame_counter != 0xFFFEu) {
+ // Wraparound has occured.
+ return 0;
+ }
+
+ return (g_regions[0].frame_counter > g_regions[1].frame_counter) ? 0 : 1;
+}
+
+static SharedMemory& ReadRegion() {
+ return g_regions[CurrentRegionIndex()];
+}
+
+static SharedMemory& WriteRegion() {
+ return g_regions[1 - CurrentRegionIndex()];
+}
void Init() {
DSP::HLE::ResetPipes();
@@ -22,21 +46,5 @@ bool Tick() {
return true;
}
-SharedMemory& CurrentRegion() {
- // The region with the higher frame counter is chosen unless there is wraparound.
-
- if (g_region0.frame_counter == 0xFFFFu && g_region1.frame_counter != 0xFFFEu) {
- // Wraparound has occured.
- return g_region1;
- }
-
- if (g_region1.frame_counter == 0xFFFFu && g_region0.frame_counter != 0xFFFEu) {
- // Wraparound has occured.
- return g_region0;
- }
-
- return (g_region0.frame_counter > g_region1.frame_counter) ? g_region0 : g_region1;
-}
-
} // namespace HLE
} // namespace DSP
diff --git a/src/audio_core/hle/dsp.h b/src/audio_core/hle/dsp.h
index c76350bdd..f0f125284 100644
--- a/src/audio_core/hle/dsp.h
+++ b/src/audio_core/hle/dsp.h
@@ -4,6 +4,7 @@
#pragma once
+#include <array>
#include <cstddef>
#include <type_traits>
@@ -30,10 +31,9 @@ namespace HLE {
struct SharedMemory;
constexpr VAddr region0_base = 0x1FF50000;
-extern SharedMemory g_region0;
-
constexpr VAddr region1_base = 0x1FF70000;
-extern SharedMemory g_region1;
+
+extern std::array<SharedMemory, 2> g_regions;
/**
* The DSP is native 16-bit. The DSP also appears to be big-endian. When reading 32-bit numbers from
@@ -535,8 +535,5 @@ void Shutdown();
*/
bool Tick();
-/// Returns a mutable reference to the current region. Current region is selected based on the frame counter.
-SharedMemory& CurrentRegion();
-
} // namespace HLE
} // namespace DSP