citra-emu
/
citra
Archived
1
0
Fork 0

AudioCore: CurrentRegion() -> ReadRegion(), WriteRegion()

This commit is contained in:
MerryMage 2016-04-25 10:01:37 +01:00
parent 1ecee38468
commit 22995bd9bf
3 changed files with 31 additions and 26 deletions

View File

@ -38,10 +38,10 @@ void Init() {
/// Add DSP address spaces to Process's address space. /// Add DSP address spaces to Process's address space.
void AddAddressSpace(Kernel::VMManager& 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); 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); address_space.Reprotect(r1_vma, Kernel::VMAPermission::ReadWrite);
} }

View File

@ -8,8 +8,32 @@
namespace DSP { namespace DSP {
namespace HLE { namespace HLE {
SharedMemory g_region0; std::array<SharedMemory, 2> g_regions;
SharedMemory g_region1;
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() { void Init() {
DSP::HLE::ResetPipes(); DSP::HLE::ResetPipes();
@ -22,21 +46,5 @@ bool Tick() {
return true; 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 HLE
} // namespace DSP } // namespace DSP

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <array>
#include <cstddef> #include <cstddef>
#include <type_traits> #include <type_traits>
@ -30,10 +31,9 @@ namespace HLE {
struct SharedMemory; struct SharedMemory;
constexpr VAddr region0_base = 0x1FF50000; constexpr VAddr region0_base = 0x1FF50000;
extern SharedMemory g_region0;
constexpr VAddr region1_base = 0x1FF70000; 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 * 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(); bool Tick();
/// Returns a mutable reference to the current region. Current region is selected based on the frame counter.
SharedMemory& CurrentRegion();
} // namespace HLE } // namespace HLE
} // namespace DSP } // namespace DSP