From edb16cd399bf20dfa4ab365ff6831fc68b8814e1 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 14 May 2017 20:25:25 -0700 Subject: [PATCH 1/7] DSP-LLE: dump code if m_DumpUCode instead of DEBUG This change makes the behavior consistent with that of DSP-HLE. --- Source/Core/Core/HW/DSPLLE/DSPHost.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HW/DSPLLE/DSPHost.cpp b/Source/Core/Core/HW/DSPLLE/DSPHost.cpp index 6805d8c70d..ec4202a538 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPHost.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPHost.cpp @@ -60,9 +60,10 @@ void CodeLoaded(const u8* ptr, int size) { g_dsp.iram_crc = HashEctor(ptr, size); -#if defined(_DEBUG) || defined(DEBUGFAST) - LLE::DumpDSPCode(ptr, size, g_dsp.iram_crc); -#endif + if (SConfig::GetInstance().m_DumpUCode) + { + LLE::DumpDSPCode(ptr, size, g_dsp.iram_crc); + } Symbols::Clear(); From e4c779de0b51794998aaed6a3d9e67cf778117ee Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 14 May 2017 20:19:34 -0700 Subject: [PATCH 2/7] DSP: move DumpDSPCode from DSPLLETools to DSPCodeUtil This code is useful outside of DSP-LLE, and I plan to modify DSP-HLE to use it in a future commit. --- Source/Core/Core/DSP/DSPCodeUtil.cpp | 40 ++++++++++++++++++++++ Source/Core/Core/DSP/DSPCodeUtil.h | 2 ++ Source/Core/Core/HW/DSPLLE/DSPHost.cpp | 4 +-- Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp | 39 --------------------- Source/Core/Core/HW/DSPLLE/DSPLLETools.h | 1 - 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Source/Core/Core/DSP/DSPCodeUtil.cpp b/Source/Core/Core/DSP/DSPCodeUtil.cpp index 3d9c2641ec..52261826c9 100644 --- a/Source/Core/Core/DSP/DSPCodeUtil.cpp +++ b/Source/Core/Core/DSP/DSPCodeUtil.cpp @@ -218,4 +218,44 @@ bool SaveBinary(const std::vector& code, const std::string& filename) return false; return true; } + +bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc) +{ + const std::string binFile = + StringFromFormat("%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), crc); + const std::string txtFile = + StringFromFormat("%sDSP_UC_%08X.txt", File::GetUserPath(D_DUMPDSP_IDX).c_str(), crc); + + File::IOFile pFile(binFile, "wb"); + if (pFile) + { + pFile.WriteBytes(code_be, size_in_bytes); + pFile.Close(); + } + else + { + PanicAlert("Can't open file (%s) to dump UCode!!", binFile.c_str()); + return false; + } + + // Load the binary back in. + std::vector code; + LoadBinary(binFile, code); + + AssemblerSettings settings; + settings.show_hex = true; + settings.show_pc = true; + settings.ext_separator = '\''; + settings.decode_names = true; + settings.decode_registers = true; + + std::string text; + DSPDisassembler disasm(settings); + + if (!disasm.Disassemble(0, code, 0x0000, text)) + return false; + + return File::WriteStringToFile(text, txtFile); +} + } // namespace DSP diff --git a/Source/Core/Core/DSP/DSPCodeUtil.h b/Source/Core/Core/DSP/DSPCodeUtil.h index e3d0ee8c93..5fe8d64f30 100644 --- a/Source/Core/Core/DSP/DSPCodeUtil.h +++ b/Source/Core/Core/DSP/DSPCodeUtil.h @@ -27,4 +27,6 @@ void BinaryStringBEToCode(const std::string& str, std::vector& code); // Load code (big endian binary). bool LoadBinary(const std::string& filename, std::vector& code); bool SaveBinary(const std::vector& code, const std::string& filename); + +bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc); } // namespace DSP diff --git a/Source/Core/Core/HW/DSPLLE/DSPHost.cpp b/Source/Core/Core/HW/DSPLLE/DSPHost.cpp index ec4202a538..b723705044 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPHost.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPHost.cpp @@ -8,10 +8,10 @@ #include "Common/Logging/Log.h" #include "Core/ConfigManager.h" #include "Core/DSP/DSPAnalyzer.h" +#include "Core/DSP/DSPCodeUtil.h" #include "Core/DSP/DSPCore.h" #include "Core/DSP/Jit/DSPEmitter.h" #include "Core/HW/DSP.h" -#include "Core/HW/DSPLLE/DSPLLETools.h" #include "Core/HW/DSPLLE/DSPSymbols.h" #include "Core/Host.h" #include "VideoCommon/OnScreenDisplay.h" @@ -62,7 +62,7 @@ void CodeLoaded(const u8* ptr, int size) if (SConfig::GetInstance().m_DumpUCode) { - LLE::DumpDSPCode(ptr, size, g_dsp.iram_crc); + DSP::DumpDSPCode(ptr, size, g_dsp.iram_crc); } Symbols::Clear(); diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp b/Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp index 3e05628ab4..2675863c23 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp @@ -23,45 +23,6 @@ namespace DSP { namespace LLE { -bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc) -{ - const std::string binFile = - StringFromFormat("%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), crc); - const std::string txtFile = - StringFromFormat("%sDSP_UC_%08X.txt", File::GetUserPath(D_DUMPDSP_IDX).c_str(), crc); - - File::IOFile pFile(binFile, "wb"); - if (pFile) - { - pFile.WriteBytes(code_be, size_in_bytes); - pFile.Close(); - } - else - { - PanicAlert("Can't open file (%s) to dump UCode!!", binFile.c_str()); - return false; - } - - // Load the binary back in. - std::vector code; - LoadBinary(binFile, code); - - AssemblerSettings settings; - settings.show_hex = true; - settings.show_pc = true; - settings.ext_separator = '\''; - settings.decode_names = true; - settings.decode_registers = true; - - std::string text; - DSPDisassembler disasm(settings); - - if (!disasm.Disassemble(0, code, 0x0000, text)) - return false; - - return File::WriteStringToFile(text, txtFile); -} - // TODO make this useful :p bool DumpCWCode(u32 _Address, u32 _Length) { diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLETools.h b/Source/Core/Core/HW/DSPLLE/DSPLLETools.h index 4890f47dd9..03c2a5776e 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPLLETools.h +++ b/Source/Core/Core/HW/DSPLLE/DSPLLETools.h @@ -10,7 +10,6 @@ namespace DSP { namespace LLE { -bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc); bool DumpCWCode(u32 _Address, u32 _Length); } // namespace DSP } // namespace LLE From f985e0faac3eebd8e65f5c3ab13ce2d631914d06 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 14 May 2017 20:20:40 -0700 Subject: [PATCH 3/7] DSP: remove unused DSPLLETools With the relocation of DumpDSPCode to DSPCodeUtils, the only remaining function in DSPLLETools is DumpCWCode. This function 1) is not used anywhere (not even in DSPTool), 2) doesn't seem to really do anything, and 3) has a single comment saying "TODO make this useful :p" --- Source/Core/Core/CMakeLists.txt | 1 - Source/Core/Core/Core.vcxproj | 2 - Source/Core/Core/Core.vcxproj.filters | 6 --- Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp | 45 ---------------------- Source/Core/Core/HW/DSPLLE/DSPLLETools.h | 15 -------- 5 files changed, 69 deletions(-) delete mode 100644 Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp delete mode 100644 Source/Core/Core/HW/DSPLLE/DSPLLETools.h diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 28e10f52ae..b610b06d8f 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -89,7 +89,6 @@ set(SRCS HW/DSPLLE/DSPSymbols.cpp HW/DSPLLE/DSPLLEGlobals.cpp HW/DSPLLE/DSPLLE.cpp - HW/DSPLLE/DSPLLETools.cpp HW/DVD/DVDInterface.cpp HW/DVD/DVDMath.cpp HW/DVD/DVDThread.cpp diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index b046d1140e..d8304543e9 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -117,7 +117,6 @@ - @@ -374,7 +373,6 @@ - diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 1afefc23e1..25d211e06e 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -400,9 +400,6 @@ HW %28Flipper/Hollywood%29\DSP Interface + HLE\LLE - - HW %28Flipper/Hollywood%29\DSP Interface + HLE\LLE - HW %28Flipper/Hollywood%29\DSP Interface + HLE\LLE @@ -1079,9 +1076,6 @@ HW %28Flipper/Hollywood%29\DSP Interface + HLE\LLE - - HW %28Flipper/Hollywood%29\DSP Interface + HLE\LLE - HW %28Flipper/Hollywood%29\DSP Interface + HLE\LLE diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp b/Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp deleted file mode 100644 index 2675863c23..0000000000 --- a/Source/Core/Core/HW/DSPLLE/DSPLLETools.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2008 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#ifdef _WIN32 -#include -#endif - -#include -#include -#include -#include - -#include "Common/CommonTypes.h" -#include "Common/FileUtil.h" -#include "Common/StringUtil.h" -#include "Core/DSP/DSPCodeUtil.h" -#include "Core/DSP/DSPCore.h" -#include "Core/DSP/DSPDisassembler.h" -#include "Core/HW/DSPLLE/DSPLLETools.h" - -namespace DSP -{ -namespace LLE -{ -// TODO make this useful :p -bool DumpCWCode(u32 _Address, u32 _Length) -{ - std::string filename = File::GetUserPath(D_DUMPDSP_IDX) + "DSP_UCode.bin"; - File::IOFile pFile(filename, "wb"); - - if (pFile) - { - for (size_t i = _Address; i != _Address + _Length; ++i) - { - u16 val = g_dsp.iram[i]; - fprintf(pFile.GetHandle(), " cw 0x%04x \n", val); - } - return true; - } - - return false; -} -} // namespace LLE -} // namespace DSP diff --git a/Source/Core/Core/HW/DSPLLE/DSPLLETools.h b/Source/Core/Core/HW/DSPLLE/DSPLLETools.h deleted file mode 100644 index 03c2a5776e..0000000000 --- a/Source/Core/Core/HW/DSPLLE/DSPLLETools.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2008 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include "Common/CommonTypes.h" - -namespace DSP -{ -namespace LLE -{ -bool DumpCWCode(u32 _Address, u32 _Length); -} // namespace DSP -} // namespace LLE From c67bae549143feb7c6ff9a80fc7885d15127b4e1 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 14 May 2017 20:33:42 -0700 Subject: [PATCH 4/7] DSP-HLE: use DumpDSPCode to de-duplicate logic (and gain disassembly) This change centralizes all of the path handling and file writing logic in DumpDSPCode. DSP-HLE also gains the feature of DSP-LLE to automatically disassemble dumped code and write it to an accompanying text file. --- Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp | 12 +++--------- Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp | 11 +++-------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp index 8b3c3b68a8..ae3e3d4dab 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/ROM.cpp @@ -17,6 +17,7 @@ #include "Common/Logging/Log.h" #include "Common/StringUtil.h" #include "Core/ConfigManager.h" +#include "Core/DSP/DSPCodeUtil.h" #include "Core/HW/DSPHLE/DSPHLE.h" #include "Core/HW/DSPHLE/MailHandler.h" #include "Core/HW/DSPHLE/UCodes/UCodes.h" @@ -107,15 +108,8 @@ void ROMUCode::BootUCode() if (SConfig::GetInstance().m_DumpUCode) { - std::string ucode_dump_path = - StringFromFormat("%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), ector_crc); - - File::IOFile fp(ucode_dump_path, "wb"); - if (fp) - { - fp.WriteArray((u8*)HLEMemory_Get_Pointer(m_current_ucode.m_ram_address), - m_current_ucode.m_length); - } + DSP::DumpDSPCode(static_cast(HLEMemory_Get_Pointer(m_current_ucode.m_ram_address)), + m_current_ucode.m_length, ector_crc); } INFO_LOG(DSPHLE, "CurrentUCode SOURCE Addr: 0x%08x", m_current_ucode.m_ram_address); diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp b/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp index cef0f00583..625e5969ed 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp +++ b/Source/Core/Core/HW/DSPHLE/UCodes/UCodes.cpp @@ -19,6 +19,7 @@ #include "Common/StringUtil.h" #include "Common/Swap.h" #include "Core/ConfigManager.h" +#include "Core/DSP/DSPCodeUtil.h" #include "Core/HW/DSPHLE/DSPHLE.h" #include "Core/HW/DSPHLE/UCodes/AX.h" #include "Core/HW/DSPHLE/UCodes/AXWii.h" @@ -187,14 +188,8 @@ void UCodeInterface::PrepareBootUCode(u32 mail) if (SConfig::GetInstance().m_DumpUCode) { - std::string ucode_dump_path = StringFromFormat( - "%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), ector_crc); - - File::IOFile fp(ucode_dump_path, "wb"); - if (fp) - { - fp.WriteArray((u8*)Memory::GetPointer(m_next_ucode.iram_mram_addr), m_next_ucode.iram_size); - } + DSP::DumpDSPCode(static_cast(Memory::GetPointer(m_next_ucode.iram_mram_addr)), + m_next_ucode.iram_size, ector_crc); } DEBUG_LOG(DSPHLE, "PrepareBootUCode 0x%08x", ector_crc); From 59c863329d22d41ec1ed6be00d5d3c2fdfaa261d Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Sun, 14 May 2017 21:00:08 -0700 Subject: [PATCH 5/7] DSP-LLE: calculate code CRC _before_ swapping endianness - Makes DSP-LLE code checksums the same as those from DSP-HLE. I'm assuming DSP-HLE was doing it correctly, since there are numerous references to these pre-endian-swapped checksums (including in DSPHost.cpp itself). - Fixes disassembly when dumping code from DSP-LLE, which was using the wrong endianness and giving totally bogus output. - Reveals error messages of the format, "Bah! ReadAnnotatedAssembly couldn't find the file ../../docs/DSP/DSP_UC_AX_07F88145.txt," which seems to be intended behavior that was previously hidden. --- Source/Core/Core/DSP/DSPHWInterface.cpp | 10 ++++++---- Source/Core/Core/HW/DSPLLE/DSPHost.cpp | 2 -- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Core/Core/DSP/DSPHWInterface.cpp b/Source/Core/Core/DSP/DSPHWInterface.cpp index 9c73e69388..c5fb7a3397 100644 --- a/Source/Core/Core/DSP/DSPHWInterface.cpp +++ b/Source/Core/Core/DSP/DSPHWInterface.cpp @@ -7,6 +7,7 @@ #include "Common/CPUDetect.h" #include "Common/CommonTypes.h" +#include "Common/Hash.h" #include "Common/Intrinsics.h" #include "Common/Logging/Log.h" #include "Common/MemoryUtil.h" @@ -227,18 +228,19 @@ u16 gdsp_ifx_read(u16 addr) static const u8* gdsp_idma_in(u16 dsp_addr, u32 addr, u32 size) { + const u8* code = &g_dsp.cpu_ram[addr & 0x0fffffff]; + g_dsp.iram_crc = HashEctor(code, size); + Common::UnWriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); u8* dst = ((u8*)g_dsp.iram); for (u32 i = 0; i < size; i += 2) { - *(u16*)&dst[dsp_addr + i] = - Common::swap16(*(const u16*)&g_dsp.cpu_ram[(addr + i) & 0x0fffffff]); + *(u16*)&dst[dsp_addr + i] = Common::swap16(*(const u16*)&code[i]); } Common::WriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); - Host::CodeLoaded((const u8*)g_dsp.iram + dsp_addr, size); - + Host::CodeLoaded(code, size); NOTICE_LOG(DSPLLE, "*** Copy new UCode from 0x%08x to 0x%04x (crc: %8x)", addr, dsp_addr, g_dsp.iram_crc); diff --git a/Source/Core/Core/HW/DSPLLE/DSPHost.cpp b/Source/Core/Core/HW/DSPLLE/DSPHost.cpp index b723705044..892d0d245e 100644 --- a/Source/Core/Core/HW/DSPLLE/DSPHost.cpp +++ b/Source/Core/Core/HW/DSPLLE/DSPHost.cpp @@ -58,8 +58,6 @@ void InterruptRequest() void CodeLoaded(const u8* ptr, int size) { - g_dsp.iram_crc = HashEctor(ptr, size); - if (SConfig::GetInstance().m_DumpUCode) { DSP::DumpDSPCode(ptr, size, g_dsp.iram_crc); From 5f68a0dcdd6368e3f69b828980a787b1d5065a12 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Mon, 15 May 2017 15:07:30 -0700 Subject: [PATCH 6/7] DSP: cleanup DumpDSPCode and remove temp file write --- Source/Core/Core/DSP/DSPCodeUtil.cpp | 39 ++++++++++------------------ 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/Source/Core/Core/DSP/DSPCodeUtil.cpp b/Source/Core/Core/DSP/DSPCodeUtil.cpp index 52261826c9..4db6f47c53 100644 --- a/Source/Core/Core/DSP/DSPCodeUtil.cpp +++ b/Source/Core/Core/DSP/DSPCodeUtil.cpp @@ -10,6 +10,7 @@ #include "Common/CommonTypes.h" #include "Common/FileUtil.h" #include "Common/StringUtil.h" +#include "Common/Swap.h" #include "Core/DSP/DSPAssembler.h" #include "Core/DSP/DSPCodeUtil.h" @@ -221,41 +222,27 @@ bool SaveBinary(const std::vector& code, const std::string& filename) bool DumpDSPCode(const u8* code_be, int size_in_bytes, u32 crc) { - const std::string binFile = - StringFromFormat("%sDSP_UC_%08X.bin", File::GetUserPath(D_DUMPDSP_IDX).c_str(), crc); - const std::string txtFile = - StringFromFormat("%sDSP_UC_%08X.txt", File::GetUserPath(D_DUMPDSP_IDX).c_str(), crc); + const std::string root_name = + File::GetUserPath(D_DUMPDSP_IDX) + StringFromFormat("DSP_UC_%08X", crc); + const std::string binary_file = root_name + ".bin"; + const std::string text_file = root_name + ".txt"; - File::IOFile pFile(binFile, "wb"); - if (pFile) + if (!File::IOFile(binary_file, "wb").WriteBytes(code_be, size_in_bytes)) { - pFile.WriteBytes(code_be, size_in_bytes); - pFile.Close(); - } - else - { - PanicAlert("Can't open file (%s) to dump UCode!!", binFile.c_str()); + PanicAlert("Can't dump UCode to file '%s'!!", binary_file.c_str()); return false; } - // Load the binary back in. - std::vector code; - LoadBinary(binFile, code); - - AssemblerSettings settings; - settings.show_hex = true; - settings.show_pc = true; - settings.ext_separator = '\''; - settings.decode_names = true; - settings.decode_registers = true; + // The disassembler works in native endian + std::vector code(size_in_bytes / 2); + for (size_t i = 0; i < code.size(); i++) + code[i] = Common::swap16(&code_be[i * 2]); std::string text; - DSPDisassembler disasm(settings); - - if (!disasm.Disassemble(0, code, 0x0000, text)) + if (!Disassemble(code, true, text)) return false; - return File::WriteStringToFile(text, txtFile); + return File::WriteStringToFile(text, text_file); } } // namespace DSP From 930c165c4e65a9c7502adc7f4c7041d201d47983 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Mon, 15 May 2017 15:08:50 -0700 Subject: [PATCH 7/7] DSPHWInterface: cleanup gdsp_idma_in --- Source/Core/Core/DSP/DSPHWInterface.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/DSP/DSPHWInterface.cpp b/Source/Core/Core/DSP/DSPHWInterface.cpp index c5fb7a3397..09b66f42e2 100644 --- a/Source/Core/Core/DSP/DSPHWInterface.cpp +++ b/Source/Core/Core/DSP/DSPHWInterface.cpp @@ -5,6 +5,9 @@ #include "Core/DSP/DSPHWInterface.h" +#include +#include + #include "Common/CPUDetect.h" #include "Common/CommonTypes.h" #include "Common/Hash.h" @@ -228,23 +231,22 @@ u16 gdsp_ifx_read(u16 addr) static const u8* gdsp_idma_in(u16 dsp_addr, u32 addr, u32 size) { + u16* dst = g_dsp.iram + (dsp_addr / 2); + const u8* code = &g_dsp.cpu_ram[addr & 0x0fffffff]; g_dsp.iram_crc = HashEctor(code, size); Common::UnWriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); - - u8* dst = ((u8*)g_dsp.iram); - for (u32 i = 0; i < size; i += 2) - { - *(u16*)&dst[dsp_addr + i] = Common::swap16(*(const u16*)&code[i]); - } + memcpy(dst, code, size); + for (size_t i = 0; i < size / 2; i++) + dst[i] = Common::swap16(dst[i]); Common::WriteProtectMemory(g_dsp.iram, DSP_IRAM_BYTE_SIZE, false); Host::CodeLoaded(code, size); NOTICE_LOG(DSPLLE, "*** Copy new UCode from 0x%08x to 0x%04x (crc: %8x)", addr, dsp_addr, g_dsp.iram_crc); - return dst + dsp_addr; + return reinterpret_cast(dst); } static const u8* gdsp_idma_out(u16 dsp_addr, u32 addr, u32 size)