From f385752705de73b04cbbda735a71f14c19e241a6 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Fri, 1 Feb 2013 00:33:30 -0500 Subject: memcpy vs memmove: memmove correctly handles overlapping source and destination memory buffers, but is slower than memcpy in many implementations. When memory buffers don't overlap, memcpy may be more efficient. The DS2 SDK is such an implementation, so change many memmoves into memcpys. --- source/loadzip.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/loadzip.cpp') diff --git a/source/loadzip.cpp b/source/loadzip.cpp index 4ee3bcb..d3e24a1 100644 --- a/source/loadzip.cpp +++ b/source/loadzip.cpp @@ -132,8 +132,7 @@ bool8 LoadZip(const char* zipname, char name[132]; unzGetCurrentFileInfo(file, &info, name,128, NULL,0, NULL,0); - int calc_size = info.uncompressed_size / 0x2000; - calc_size *= 0x2000; + int calc_size = info.uncompressed_size & ~0x1FFF; // round to lower 0x2000 if(!(info.uncompressed_size - calc_size == 512 || info.uncompressed_size == calc_size)) { port = unzGoToNextFile(file); @@ -190,8 +189,7 @@ bool8 LoadZip(const char* zipname, // assert(info.uncompressed_size <= CMemory::MAX_ROM_SIZE + 512); int FileSize = info.uncompressed_size; - int calc_size = FileSize / 0x2000; - calc_size *= 0x2000; + int calc_size = FileSize & ~0x1FFF; // round to lower 0x2000 int l = unzReadCurrentFile(file,ptr,FileSize); if(unzCloseCurrentFile(file) == UNZ_CRCERROR) @@ -224,6 +222,8 @@ bool8 LoadZip(const char* zipname, if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) || Settings.ForceHeader) { + // memmove required: Overlapping addresses [Neb] + // DS2 DMA notes: Can be split into 512-byte DMA blocks [Neb] memmove (ptr, ptr + 512, calc_size); (*headers)++; FileSize -= 512; -- cgit v1.2.3