diff --git a/src/core/hle/service/dsp_dsp.cpp b/src/core/hle/service/dsp_dsp.cpp index 17e54945f..4e8ef7663 100644 --- a/src/core/hle/service/dsp_dsp.cpp +++ b/src/core/hle/service/dsp_dsp.cpp @@ -195,13 +195,11 @@ static VAddr GetCurrentBase() { static std::array syncs; static ChannelContext GetChannelContext(VAddr base, int channel_id) { - ChannelContext ctx; - - if (!Memory::ExtractFromMemory(DspAddrToVAddr(base, DSPADDR1) + channel_id * sizeof(ChannelContext), ctx)) { + auto ret = Memory::ExtractFromMemory(DspAddrToVAddr(base, DSPADDR1) + channel_id * sizeof(ChannelContext)); + if (!ret) { LOG_CRITICAL(Service_DSP, "ExtractFromMemory for DSPADDR1 failed"); } - - return ctx; + return *ret; } 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)) { // Update ADPCM coefficients - AdpcmCoefficients coeff; - if (!Memory::ExtractFromMemory(DspAddrToVAddr(current_base, DSPADDR3) + channel_id * sizeof(coeff), coeff)) { + auto coeff = Memory::ExtractFromMemory(DspAddrToVAddr(current_base, DSPADDR3) + channel_id * sizeof(AdpcmCoefficients)); + if (!coeff) { LOG_CRITICAL(Service_DSP, "ExtractFromMemory for DSPADDR3 failed"); return; } - Audio::UpdateAdpcm(channel_id, coeff.coeff); + Audio::UpdateAdpcm(channel_id, coeff->coeff); } if (TestAndUnsetBit<17>(ctx.dirty)) { diff --git a/src/core/memory.h b/src/core/memory.h index b42ad6268..2baf66257 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -4,6 +4,7 @@ #pragma once +#include #include #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. */ template -bool ExtractFromMemory(VAddr address, T& object) { +boost::optional ExtractFromMemory(VAddr address) { static_assert(std::is_standard_layout::value, "Type must have standard layout"); const u8* memory = GetPointer(address); if (!memory) { - return false; + return {}; } + T object; std::memcpy(&object, memory, sizeof(T)); - return true; + return boost::make_optional(object); } /**