diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 64e880e7ec..75013a44b6 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -184,8 +184,8 @@ bool CBoot::Load_BS2(const std::string& _rBootROMFilename) // Run the descrambler over the encrypted section containing BS1/BS2 CEXIIPL::Descrambler((u8*)data.data()+0x100, 0x1AFE00); - Memory::WriteBigEData((const u8*)data.data() + 0x100, 0x81200000, 0x700); - Memory::WriteBigEData((const u8*)data.data() + 0x820, 0x81300000, 0x1AFE00); + Memory::CopyToEmu(0x81200000, data.data() + 0x100, 0x700); + Memory::CopyToEmu(0x81300000, data.data() + 0x820, 0x1AFE00); PC = 0x81200000; return true; } @@ -428,8 +428,7 @@ bool CBoot::BootUp() if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bEnableCheats) { HLE::Patch(0x80001800, "HBReload"); - const u8 stubstr[] = { 'S', 'T', 'U', 'B', 'H', 'A', 'X', 'X' }; - Memory::WriteBigEData(stubstr, 0x80001804, 8); + Memory::CopyToEmu(0x80001804, "STUBHAXX", 8); } // Not part of the binary itself, but either we or Gecko OS might insert diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index ac0bdd11c9..71311abc1b 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -226,7 +226,7 @@ bool CBoot::SetupWiiMemory(IVolume::ECountry country) return false; } // Write the 256 byte setting.txt to memory. - Memory::WriteBigEData(gen.GetData(), 0x3800, SettingsHandler::SETTINGS_SIZE); + Memory::CopyToEmu(0x3800, gen.GetData(), SettingsHandler::SETTINGS_SIZE); } INFO_LOG(BOOT, "Setup Wii Memory..."); diff --git a/Source/Core/Core/GeckoCode.cpp b/Source/Core/Core/GeckoCode.cpp index cfa35c48a6..47d5b7f171 100644 --- a/Source/Core/Core/GeckoCode.cpp +++ b/Source/Core/Core/GeckoCode.cpp @@ -90,7 +90,7 @@ static bool InstallCodeHandler() } // Install code handler - Memory::WriteBigEData((const u8*)data.data(), INSTALLER_BASE_ADDRESS, data.length()); + Memory::CopyToEmu(INSTALLER_BASE_ADDRESS, data.data(), data.length()); // Patch the code handler to the system starting up for (unsigned int h = 0; h < data.length(); h += 4) diff --git a/Source/Core/Core/HW/Memmap.cpp b/Source/Core/Core/HW/Memmap.cpp index 5d7b96d60d..58c878d0bb 100644 --- a/Source/Core/Core/HW/Memmap.cpp +++ b/Source/Core/Core/HW/Memmap.cpp @@ -215,9 +215,14 @@ u32 Read_Instruction(const u32 em_address) return inst.hex; } -void WriteBigEData(const u8 *_pData, const u32 _Address, const size_t _iSize) +void CopyFromEmu(void* data, u32 address, size_t size) { - memcpy(GetPointer(_Address), _pData, _iSize); + memcpy(data, GetPointer(address), size); +} + +void CopyToEmu(u32 address, const void* data, size_t size) +{ + memcpy(GetPointer(address), data, size); } void Memset(const u32 _Address, const u8 _iValue, const u32 _iLength) @@ -286,12 +291,6 @@ void DMA_MemoryToLC(const u32 _CacheAddr, const u32 _MemAddr, const u32 _iNumBlo } } -void ReadBigEData(u8 *data, const u32 em_address, const u32 size) -{ - u8 *src = GetPointer(em_address); - memcpy(data, src, size); -} - std::string GetString(u32 em_address) { std::string str; diff --git a/Source/Core/Core/HW/Memmap.h b/Source/Core/Core/HW/Memmap.h index 0973166ca9..bf28c16ff2 100644 --- a/Source/Core/Core/HW/Memmap.h +++ b/Source/Core/Core/HW/Memmap.h @@ -120,11 +120,11 @@ void Write_F64(const double _Data, const u32 _Address); std::string GetString(u32 em_address); -void WriteBigEData(const u8 *_pData, const u32 _Address, const size_t size); -void ReadBigEData(u8 *_pDest, const u32 _Address, const u32 size); u8* GetPointer(const u32 _Address); void DMA_LCToMemory(const u32 _iMemAddr, const u32 _iCacheAddr, const u32 _iNumBlocks); void DMA_MemoryToLC(const u32 _iCacheAddr, const u32 _iMemAddr, const u32 _iNumBlocks); +void CopyFromEmu(void* data, u32 address, size_t size); +void CopyToEmu(u32 address, const void* data, size_t size); void Memset(const u32 _Address, const u8 _Data, const u32 _iLength); void ClearCacheLine(const u32 _Address); // Zeroes 32 bytes; address should be 32-byte-aligned diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp index f138be80f5..18e924c839 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_es.cpp @@ -639,8 +639,8 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) for (unsigned int View = 0; View != maxViews && View < viewCnt; ++View) { Memory::Write_U32(View, Buffer.PayloadBuffer[0].m_Address + View * 0xD8); - Memory::WriteBigEData(Ticket + 0x1D0 + (View * DiscIO::INANDContentLoader::TICKET_SIZE), - Buffer.PayloadBuffer[0].m_Address + 4 + View * 0xD8, 212); + Memory::CopyToEmu(Buffer.PayloadBuffer[0].m_Address + 4 + View * 0xD8, + Ticket + 0x1D0 + (View * DiscIO::INANDContentLoader::TICKET_SIZE), 212); } } else @@ -655,7 +655,7 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) for (unsigned int View = 0; View != maxViews && pFile.ReadBytes(FileTicket, DiscIO::INANDContentLoader::TICKET_SIZE); ++View) { Memory::Write_U32(View, Buffer.PayloadBuffer[0].m_Address + View * 0xD8); - Memory::WriteBigEData(FileTicket+0x1D0, Buffer.PayloadBuffer[0].m_Address + 4 + View * 0xD8, 212); + Memory::CopyToEmu(Buffer.PayloadBuffer[0].m_Address + 4 + View * 0xD8, FileTicket+0x1D0, 212); } } } @@ -727,7 +727,7 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) { u32 Address = Buffer.PayloadBuffer[0].m_Address; - Memory::WriteBigEData(Loader.GetTMDView(), Address, DiscIO::INANDContentLoader::TMD_VIEW_SIZE); + Memory::CopyToEmu(Address, Loader.GetTMDView(), DiscIO::INANDContentLoader::TMD_VIEW_SIZE); Address += DiscIO::INANDContentLoader::TMD_VIEW_SIZE; Memory::Write_U16(Loader.GetTitleVersion(), Address); Address += 2; @@ -835,13 +835,13 @@ bool CWII_IPC_HLE_Device_es::IOCtlV(u32 _CommandAddress) { u32 Address = Buffer.PayloadBuffer[0].m_Address; - Memory::WriteBigEData(Loader.GetTMDHeader(), Address, DiscIO::INANDContentLoader::TMD_HEADER_SIZE); + Memory::CopyToEmu(Address, Loader.GetTMDHeader(), DiscIO::INANDContentLoader::TMD_HEADER_SIZE); Address += DiscIO::INANDContentLoader::TMD_HEADER_SIZE; const std::vector& rContent = Loader.GetContent(); for (size_t i=0; ibNumInterfaces; ic++) @@ -418,7 +418,7 @@ void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize) WiiHIDInterfaceDescriptor wii_interface; ConvertInterfaceToWii(&wii_interface, interface); - Memory::WriteBigEData((const u8*)&wii_interface, OffsetBuffer, Align(wii_interface.bLength, 4)); + Memory::CopyToEmu(OffsetBuffer, &wii_interface, Align(wii_interface.bLength, 4)); OffsetBuffer += Align(wii_interface.bLength, 4); for (e = 0; e < interface->bNumEndpoints; e++) @@ -427,7 +427,7 @@ void CWII_IPC_HLE_Device_hid::FillOutDevices(u32 BufferOut, u32 BufferOutSize) WiiHIDEndpointDescriptor wii_endpoint; ConvertEndpointToWii(&wii_endpoint, endpoint); - Memory::WriteBigEData((const u8*)&wii_endpoint, OffsetBuffer, Align(wii_endpoint.bLength, 4)); + Memory::CopyToEmu(OffsetBuffer, &wii_endpoint, Align(wii_endpoint.bLength, 4)); OffsetBuffer += Align(wii_endpoint.bLength, 4); } //endpoints diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index 8b2211910d..1a1cb0b2ef 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -409,7 +409,7 @@ bool CWII_IPC_HLE_Device_net_ncd_manage::IOCtlV(u32 _CommandAddress) u8 address[MAC_ADDRESS_SIZE]; GetMacAddress(address); - Memory::WriteBigEData(address, CommandBuffer.PayloadBuffer.at(1).m_Address, sizeof(address)); + Memory::CopyToEmu(CommandBuffer.PayloadBuffer.at(1).m_Address, address, sizeof(address)); break; default: @@ -756,7 +756,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) Memory::Write_U32(optlen, BufferOut + 0xC); - Memory::WriteBigEData((u8*) optval, BufferOut + 0x10, optlen); + Memory::CopyToEmu(BufferOut + 0x10, optval, optlen); if (optname == SO_ERROR) { @@ -775,7 +775,8 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) u32 optname = Memory::Read_U32(BufferIn + 8); u32 optlen = Memory::Read_U32(BufferIn + 0xc); u8 optval[20]; - Memory::ReadBigEData(optval, BufferIn + 0x10, optlen); + optlen = std::min(optlen, (u32)sizeof(optval)); + Memory::CopyFromEmu(optval, BufferIn + 0x10, optlen); INFO_LOG(WII_IPC_NET, "IOCTL_SO_SETSOCKOPT(%08x, %08x, %08x, %08x) " "BufferIn: (%08x, %i), BufferOut: (%08x, %i)" @@ -830,7 +831,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) Memory::Write_U8(BufferOutSize, BufferOut); Memory::Write_U8(sa.sa_family & 0xFF, BufferOut + 1); - Memory::WriteBigEData((u8*)&sa.sa_data, BufferOut + 2, BufferOutSize - 2); + Memory::CopyToEmu(BufferOut + 2, &sa.sa_data, BufferOutSize - 2); ReturnValue = ret; break; } @@ -846,7 +847,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) Memory::Write_U8(BufferOutSize, BufferOut); Memory::Write_U8(AF_INET, BufferOut + 1); - Memory::WriteBigEData((u8*)&sa.sa_data, BufferOut + 2, BufferOutSize - 2); + Memory::CopyToEmu(BufferOut + 2, &sa.sa_data, BufferOutSize - 2); INFO_LOG(WII_IPC_NET, "IOCTL_SO_GETPEERNAME(%x)", fd); @@ -1056,7 +1057,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) u32 wii_addr = BufferOut + 4 * 3 + 2 * 2; u32 name_length = (u32)strlen(remoteHost->h_name) + 1; - Memory::WriteBigEData((const u8*)remoteHost->h_name, wii_addr, name_length); + Memory::CopyToEmu(wii_addr, remoteHost->h_name, name_length); Memory::Write_U32(wii_addr, BufferOut); wii_addr += (name_length + 4) & ~3; @@ -1274,7 +1275,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtlV(u32 CommandAddress) case 0x1004: // mac address u8 address[MAC_ADDRESS_SIZE]; GetMacAddress(address); - Memory::WriteBigEData(address, _BufferOut, sizeof(address)); + Memory::CopyToEmu(_BufferOut, address, sizeof(address)); break; case 0x1005: // link state @@ -1358,7 +1359,7 @@ bool CWII_IPC_HLE_Device_net_ip_top::IOCtlV(u32 CommandAddress) { Memory::Write_U32(sockoffset, addr + 0x18); Memory::Write_U16(((result->ai_addr->sa_family & 0xFF) << 8) | (result->ai_addrlen & 0xFF), sockoffset); - Memory::WriteBigEData((u8*)result->ai_addr->sa_data, sockoffset + 0x2, sizeof(result->ai_addr->sa_data)); + Memory::CopyToEmu(sockoffset + 0x2, result->ai_addr->sa_data, sizeof(result->ai_addr->sa_data)); sockoffset += 0x1C; } else diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.h b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.h index 6b45cfa707..854631c8f1 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.h +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.h @@ -357,12 +357,12 @@ public: void WriteToMem(const u32 address) { - Memory::WriteBigEData((const u8*)&config, address, sizeof(config)); + Memory::CopyToEmu(address, &config, sizeof(config)); } void ReadFromMem(const u32 address) { - Memory::ReadBigEData((u8*)&config, address, sizeof(config)); + Memory::CopyFromEmu(&config, address, sizeof(config)); } void ReadConfig()