mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 23:02:47 +01:00
AudioCore: CurrentRegion() -> ReadRegion(), WriteRegion()
This commit is contained in:
parent
1ecee38468
commit
22995bd9bf
3 changed files with 31 additions and 26 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue