Memory: ExtractFromMemory returns a boost::optional<T>
This commit is contained in:
parent
5973712410
commit
3e75de6006
2 changed files with 11 additions and 11 deletions
|
@ -195,13 +195,11 @@ static VAddr GetCurrentBase() {
|
||||||
static std::array<u16, NUM_CHANNELS> syncs;
|
static std::array<u16, NUM_CHANNELS> syncs;
|
||||||
|
|
||||||
static ChannelContext GetChannelContext(VAddr base, int channel_id) {
|
static ChannelContext GetChannelContext(VAddr base, int channel_id) {
|
||||||
ChannelContext ctx;
|
auto ret = Memory::ExtractFromMemory<ChannelContext>(DspAddrToVAddr(base, DSPADDR1) + channel_id * sizeof(ChannelContext));
|
||||||
|
if (!ret) {
|
||||||
if (!Memory::ExtractFromMemory(DspAddrToVAddr(base, DSPADDR1) + channel_id * sizeof(ChannelContext), ctx)) {
|
|
||||||
LOG_CRITICAL(Service_DSP, "ExtractFromMemory for DSPADDR1 failed");
|
LOG_CRITICAL(Service_DSP, "ExtractFromMemory for DSPADDR1 failed");
|
||||||
}
|
}
|
||||||
|
return *ret;
|
||||||
return ctx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetChannelContext(VAddr base, int channel_id, const ChannelContext& ctx) {
|
static void SetChannelContext(VAddr base, int channel_id, const ChannelContext& ctx) {
|
||||||
|
@ -224,12 +222,12 @@ static void ReadChannelContext(VAddr current_base, int channel_id) {
|
||||||
|
|
||||||
if (TestAndUnsetBit<2>(ctx.dirty)) {
|
if (TestAndUnsetBit<2>(ctx.dirty)) {
|
||||||
// Update ADPCM coefficients
|
// Update ADPCM coefficients
|
||||||
AdpcmCoefficients coeff;
|
auto coeff = Memory::ExtractFromMemory<AdpcmCoefficients>(DspAddrToVAddr(current_base, DSPADDR3) + channel_id * sizeof(AdpcmCoefficients));
|
||||||
if (!Memory::ExtractFromMemory(DspAddrToVAddr(current_base, DSPADDR3) + channel_id * sizeof(coeff), coeff)) {
|
if (!coeff) {
|
||||||
LOG_CRITICAL(Service_DSP, "ExtractFromMemory for DSPADDR3 failed");
|
LOG_CRITICAL(Service_DSP, "ExtractFromMemory for DSPADDR3 failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Audio::UpdateAdpcm(channel_id, coeff.coeff);
|
Audio::UpdateAdpcm(channel_id, coeff->coeff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TestAndUnsetBit<17>(ctx.dirty)) {
|
if (TestAndUnsetBit<17>(ctx.dirty)) {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/optional.hpp>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
@ -134,16 +135,17 @@ u8* GetPointer(VAddr virtual_address);
|
||||||
* Extracts a POD type from memory. Returns false if address is invalid.
|
* Extracts a POD type from memory. Returns false if address is invalid.
|
||||||
*/
|
*/
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool ExtractFromMemory(VAddr address, T& object) {
|
boost::optional<T> ExtractFromMemory(VAddr address) {
|
||||||
static_assert(std::is_standard_layout<T>::value, "Type must have standard layout");
|
static_assert(std::is_standard_layout<T>::value, "Type must have standard layout");
|
||||||
|
|
||||||
const u8* memory = GetPointer(address);
|
const u8* memory = GetPointer(address);
|
||||||
if (!memory) {
|
if (!memory) {
|
||||||
return false;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T object;
|
||||||
std::memcpy(&object, memory, sizeof(T));
|
std::memcpy(&object, memory, sizeof(T));
|
||||||
return true;
|
return boost::make_optional(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue