diff options
Diffstat (limited to '')
| -rw-r--r-- | src/audio_core/audio_core.cpp | 4 | ||||
| -rw-r--r-- | src/audio_core/hle/dsp.cpp | 44 | ||||
| -rw-r--r-- | src/audio_core/hle/dsp.h | 9 |
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() { | |||
| 38 | 38 | ||
| 39 | /// Add DSP address spaces to Process's address space. | 39 | /// Add DSP address spaces to Process's address space. |
| 40 | void AddAddressSpace(Kernel::VMManager& address_space) { | 40 | void AddAddressSpace(Kernel::VMManager& address_space) { |
| 41 | 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(); | 41 | 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(); |
| 42 | address_space.Reprotect(r0_vma, Kernel::VMAPermission::ReadWrite); | 42 | address_space.Reprotect(r0_vma, Kernel::VMAPermission::ReadWrite); |
| 43 | 43 | ||
| 44 | 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(); | 44 | 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(); |
| 45 | address_space.Reprotect(r1_vma, Kernel::VMAPermission::ReadWrite); | 45 | address_space.Reprotect(r1_vma, Kernel::VMAPermission::ReadWrite); |
| 46 | } | 46 | } |
| 47 | 47 | ||
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 @@ | |||
| 8 | namespace DSP { | 8 | namespace DSP { |
| 9 | namespace HLE { | 9 | namespace HLE { |
| 10 | 10 | ||
| 11 | SharedMemory g_region0; | 11 | std::array<SharedMemory, 2> g_regions; |
| 12 | SharedMemory g_region1; | 12 | |
| 13 | static size_t CurrentRegionIndex() { | ||
| 14 | // The region with the higher frame counter is chosen unless there is wraparound. | ||
| 15 | // This function only returns a 0 or 1. | ||
| 16 | |||
| 17 | if (g_regions[0].frame_counter == 0xFFFFu && g_regions[1].frame_counter != 0xFFFEu) { | ||
| 18 | // Wraparound has occured. | ||
| 19 | return 1; | ||
| 20 | } | ||
| 21 | |||
| 22 | if (g_regions[1].frame_counter == 0xFFFFu && g_regions[0].frame_counter != 0xFFFEu) { | ||
| 23 | // Wraparound has occured. | ||
| 24 | return 0; | ||
| 25 | } | ||
| 26 | |||
| 27 | return (g_regions[0].frame_counter > g_regions[1].frame_counter) ? 0 : 1; | ||
| 28 | } | ||
| 29 | |||
| 30 | static SharedMemory& ReadRegion() { | ||
| 31 | return g_regions[CurrentRegionIndex()]; | ||
| 32 | } | ||
| 33 | |||
| 34 | static SharedMemory& WriteRegion() { | ||
| 35 | return g_regions[1 - CurrentRegionIndex()]; | ||
| 36 | } | ||
| 13 | 37 | ||
| 14 | void Init() { | 38 | void Init() { |
| 15 | DSP::HLE::ResetPipes(); | 39 | DSP::HLE::ResetPipes(); |
| @@ -22,21 +46,5 @@ bool Tick() { | |||
| 22 | return true; | 46 | return true; |
| 23 | } | 47 | } |
| 24 | 48 | ||
| 25 | SharedMemory& CurrentRegion() { | ||
| 26 | // The region with the higher frame counter is chosen unless there is wraparound. | ||
| 27 | |||
| 28 | if (g_region0.frame_counter == 0xFFFFu && g_region1.frame_counter != 0xFFFEu) { | ||
| 29 | // Wraparound has occured. | ||
| 30 | return g_region1; | ||
| 31 | } | ||
| 32 | |||
| 33 | if (g_region1.frame_counter == 0xFFFFu && g_region0.frame_counter != 0xFFFEu) { | ||
| 34 | // Wraparound has occured. | ||
| 35 | return g_region0; | ||
| 36 | } | ||
| 37 | |||
| 38 | return (g_region0.frame_counter > g_region1.frame_counter) ? g_region0 : g_region1; | ||
| 39 | } | ||
| 40 | |||
| 41 | } // namespace HLE | 49 | } // namespace HLE |
| 42 | } // namespace DSP | 50 | } // 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 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 7 | #include <cstddef> | 8 | #include <cstddef> |
| 8 | #include <type_traits> | 9 | #include <type_traits> |
| 9 | 10 | ||
| @@ -30,10 +31,9 @@ namespace HLE { | |||
| 30 | struct SharedMemory; | 31 | struct SharedMemory; |
| 31 | 32 | ||
| 32 | constexpr VAddr region0_base = 0x1FF50000; | 33 | constexpr VAddr region0_base = 0x1FF50000; |
| 33 | extern SharedMemory g_region0; | ||
| 34 | |||
| 35 | constexpr VAddr region1_base = 0x1FF70000; | 34 | constexpr VAddr region1_base = 0x1FF70000; |
| 36 | extern SharedMemory g_region1; | 35 | |
| 36 | extern std::array<SharedMemory, 2> g_regions; | ||
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | * The DSP is native 16-bit. The DSP also appears to be big-endian. When reading 32-bit numbers from | 39 | * 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(); | |||
| 535 | */ | 535 | */ |
| 536 | bool Tick(); | 536 | bool Tick(); |
| 537 | 537 | ||
| 538 | /// Returns a mutable reference to the current region. Current region is selected based on the frame counter. | ||
| 539 | SharedMemory& CurrentRegion(); | ||
| 540 | |||
| 541 | } // namespace HLE | 538 | } // namespace HLE |
| 542 | } // namespace DSP | 539 | } // namespace DSP |