aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNebuleon Fumika2013-02-01 00:33:30 -0500
committerNebuleon Fumika2013-02-01 00:33:30 -0500
commitf385752705de73b04cbbda735a71f14c19e241a6 (patch)
tree59aca906a8c3fcbaae402d503e7c6b34643e0199
parentf0fab191e48f165c551980d724bba2f26a764795 (diff)
downloadsnes9x2005-f385752705de73b04cbbda735a71f14c19e241a6.tar.gz
snes9x2005-f385752705de73b04cbbda735a71f14c19e241a6.tar.bz2
snes9x2005-f385752705de73b04cbbda735a71f14c19e241a6.zip
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.
-rw-r--r--source/apu.cpp16
-rw-r--r--source/c4emu.cpp1
-rw-r--r--source/cheats.cpp3
-rw-r--r--source/cheats2.cpp1
-rw-r--r--source/clip.cpp12
-rw-r--r--source/gfx.cpp17
-rw-r--r--source/loadzip.cpp8
-rw-r--r--source/memmap.cpp81
-rw-r--r--source/sa1.cpp4
-rw-r--r--source/snaporig.cpp6
-rw-r--r--source/snapshot.cpp14
-rw-r--r--source/srtc.cpp12
12 files changed, 125 insertions, 50 deletions
diff --git a/source/apu.cpp b/source/apu.cpp
index 3c1a5d3..d60cc75 100644
--- a/source/apu.cpp
+++ b/source/apu.cpp
@@ -177,8 +177,12 @@ void S9xResetAPU ()
ZeroMemory (IAPU.CachedSamples, 0x40000);
ZeroMemory (APU.OutPorts, 4);
IAPU.DirectPage = IAPU.RAM;
- memmove (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM));
- memmove (APU.ExtraRAM, APUROM, sizeof (APUROM));
+ // memmove converted: Different mallocs [Neb]
+ // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb]
+ memcpy (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM));
+ // memmove converted: Different mallocs [Neb]
+ // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb]
+ memcpy (APU.ExtraRAM, APUROM, sizeof (APUROM));
IAPU.PC = IAPU.RAM + IAPU.RAM [0xfffe] + (IAPU.RAM [0xffff] << 8);
APU.Cycles = 0;
IAPU.Registers.YA.W = 0;
@@ -874,7 +878,9 @@ void S9xSetAPUControl (uint8 byte)
{
if (!APU.ShowROM)
{
- memmove (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM));
+ // memmove converted: Different mallocs [Neb]
+ // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb]
+ memcpy (&IAPU.RAM [0xffc0], APUROM, sizeof (APUROM));
APU.ShowROM = TRUE;
}
}
@@ -883,7 +889,9 @@ void S9xSetAPUControl (uint8 byte)
if (APU.ShowROM)
{
APU.ShowROM = FALSE;
- memmove (&IAPU.RAM [0xffc0], APU.ExtraRAM, sizeof (APUROM));
+ // memmove converted: Different mallocs [Neb]
+ // DS2 DMA notes: The APU ROM is not 32-byte aligned [Neb]
+ memcpy (&IAPU.RAM [0xffc0], APU.ExtraRAM, sizeof (APUROM));
}
}
IAPU.RAM [0xf1] = byte;
diff --git a/source/c4emu.cpp b/source/c4emu.cpp
index a8fcce9..be08f07 100644
--- a/source/c4emu.cpp
+++ b/source/c4emu.cpp
@@ -878,6 +878,7 @@ void S9xSetC4 (uint8 byte, uint16 Address)
if(byte != 0) printf("C4 load: non-0 written to $7f47! Wrote %02x\n", byte);
if(READ_WORD(Memory.C4RAM+0x1f45) < 0x6000 || (READ_WORD(Memory.C4RAM+0x1f45) + READ_WORD(Memory.C4RAM+0x1f43)) > 0x6c00) printf("C4 load: Dest unusual! It's %04x\n", READ_WORD(Memory.C4RAM+0x1f45));
#endif
+ // memmove required: Can overlap arbitrarily [Neb]
memmove(Memory.C4RAM+(READ_WORD(Memory.C4RAM+0x1f45)&0x1fff),
S9xGetMemPointer(READ_3WORD(Memory.C4RAM+0x1f40)),
READ_WORD(Memory.C4RAM+0x1f43));
diff --git a/source/cheats.cpp b/source/cheats.cpp
index dc388d2..9c4a8f2 100644
--- a/source/cheats.cpp
+++ b/source/cheats.cpp
@@ -190,8 +190,11 @@ const char *S9xGameGenieToRaw (const char *code, uint32 *address, uint8 *byte)
void S9xStartCheatSearch (SCheatData *d)
{
+ // memmove may be required: Source is usually a different malloc, but could be pointed to d->CWRAM [Neb]
memmove (d->CWRAM, d->RAM, 0x20000);
+ // memmove may be required: Source is usually a different malloc, but could be pointed to d->CSRAM [Neb]
memmove (d->CSRAM, d->SRAM, 0x10000);
+ // memmove may be required: Source is usually a different malloc, but could be pointed to d->CIRAM [Neb]
memmove (d->CIRAM, &d->FillRAM [0x3000], 0x2000);
memset ((char *) d->WRAM_BITS, 0xff, 0x20000 >> 3);
memset ((char *) d->SRAM_BITS, 0xff, 0x10000 >> 3);
diff --git a/source/cheats2.cpp b/source/cheats2.cpp
index e5a7b0f..59855b9 100644
--- a/source/cheats2.cpp
+++ b/source/cheats2.cpp
@@ -128,6 +128,7 @@ void S9xDeleteCheat (uint32 which1)
if (Cheat.c [which1].enabled)
S9xRemoveCheat (which1);
+ // memmove required: Overlapping addresses [Neb]
memmove (&Cheat.c [which1], &Cheat.c [which1 + 1],
sizeof (Cheat.c [0]) * (Cheat.num_cheats - which1 - 1));
Cheat.num_cheats--; //MK: This used to set it to 0??
diff --git a/source/clip.cpp b/source/clip.cpp
index 57204ac..7147abf 100644
--- a/source/clip.cpp
+++ b/source/clip.cpp
@@ -291,7 +291,8 @@ void ComputeClipWindows ()
if (BAND_EMPTY(Win1[0]))
{
B = Window2Enabled;
- memmove (Bands, Win2,
+ // memmove converted: Different stack allocations [Neb]
+ memcpy (Bands, Win2,
sizeof(Win2[0]) * Window2Enabled);
}
else
@@ -355,7 +356,8 @@ void ComputeClipWindows ()
// use window 1 as the clipping (which
// could also be empty).
B = Window1Enabled;
- memmove (Bands, Win1,
+ // memmove converted: Different stack allocations [Neb]
+ memcpy (Bands, Win1,
sizeof(Win1[0]) * Window1Enabled);
}
else
@@ -468,14 +470,16 @@ void ComputeClipWindows ()
if (Window1Enabled == 1 && BAND_EMPTY(Win1[0]))
{
B = Window2Enabled;
- memmove (Bands, Win2,
+ // memmove converted: Different stack allocations [Neb]
+ memcpy (Bands, Win2,
sizeof(Win2[0]) * Window2Enabled);
}
else
if (Window2Enabled == 1 && BAND_EMPTY(Win2[0]))
{
B = Window1Enabled;
- memmove (Bands, Win1,
+ // memmove converted: Different stack allocations [Neb]
+ memcpy (Bands, Win1,
sizeof(Win1[0]) * Window1Enabled);
}
else
diff --git a/source/gfx.cpp b/source/gfx.cpp
index d2b8b6e..1b429c6 100644
--- a/source/gfx.cpp
+++ b/source/gfx.cpp
@@ -154,10 +154,12 @@ extern uint8 Mode7Depths [2];
if (IPPU.DoubleHeightPixels && ((PPU.BGMode != 5 && PPU.BGMode != 6) || !IPPU.Interlace)) \
for (uint32 y = GFX.StartY; y <= GFX.EndY; y++) \
{ \
- memmove (SCREEN + (y * 2 + 1) * GFX.Pitch2, \
- SCREEN + y * 2 * GFX.Pitch2, \
- GFX.Pitch2); \
+ /* memmove converted: Same malloc, non-overlapping addresses [Neb] */ \
+ memcpy (SCREEN + (y * 2 + 1) * GFX.Pitch2, \
+ SCREEN + y * 2 * GFX.Pitch2, \
+ GFX.Pitch2); \
if(DO_DEPTH){ \
+ /* memmove required: Same malloc, potentially overlapping addresses [Neb] */ \
memmove (DEPTH + (y * 2 + 1) * (GFX.PPLx2>>1), \
DEPTH + y * GFX.PPL, \
GFX.PPLx2>>1); \
@@ -1207,6 +1209,7 @@ static void DrawOBJS (bool8 OnMain = FALSE, uint8 D = 0)
if(j<i && Windows[j].Pos==GFX.pCurrentClip->Left[clip][4]){
Windows[j].Value = TRUE;
} else {
+ // memmove required: Overlapping addresses [Neb]
if(j<i) memmove(&Windows[j+1], &Windows[j], sizeof(Windows[0])*(i-j));
Windows[j].Pos = GFX.pCurrentClip->Left[clip][4];
Windows[j].Value = TRUE;
@@ -1214,6 +1217,7 @@ static void DrawOBJS (bool8 OnMain = FALSE, uint8 D = 0)
}
for(j=0; j<i && Windows[j].Pos<GFX.pCurrentClip->Right[clip][4]; j++);
if(j>=i || Windows[j].Pos!=GFX.pCurrentClip->Right[clip][4]){
+ // memmove required: Overlapping addresses [Neb]
if(j<i) memmove(&Windows[j+1], &Windows[j], sizeof(Windows[0])*(i-j));
Windows[j].Pos = GFX.pCurrentClip->Right[clip][4];
Windows[j].Value = FALSE;
@@ -3723,10 +3727,13 @@ void S9xUpdateScreen ()
// part way down the screen. Scale everything.
for (register int32 y = (int32) GFX.StartY - 1; y >= 0; y--)
{
- memmove (GFX.Screen + y * 2 * GFX.Pitch2,
+ // memmove converted: Same malloc, different addresses, and identical addresses at line 0 [Neb]
+ // DS2 DMA notes: This code path is unused [Neb]
+ memcpy (GFX.Screen + y * 2 * GFX.Pitch2,
GFX.Screen + y * GFX.Pitch2,
GFX.Pitch2);
- memmove (GFX.Screen + (y * 2 + 1) * GFX.Pitch2,
+ // memmove converted: Same malloc, different addresses [Neb]
+ memcpy (GFX.Screen + (y * 2 + 1) * GFX.Pitch2,
GFX.Screen + y * GFX.Pitch2,
GFX.Pitch2);
}
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;
diff --git a/source/memmap.cpp b/source/memmap.cpp
index 04bc621..c1546b1 100644
--- a/source/memmap.cpp
+++ b/source/memmap.cpp
@@ -214,6 +214,7 @@ void S9xDeinterleaveType1(int TotalFileSize, uint8 * base)
blocks [i * 2] = i + nblocks;
blocks [i * 2 + 1] = i;
}
+ // DS2 DMA notes: base may or may not be 32-byte aligned
uint8 *tmp = (uint8 *) malloc (0x8000);
if (tmp)
{
@@ -223,10 +224,14 @@ void S9xDeinterleaveType1(int TotalFileSize, uint8 * base)
{
if (blocks [j] == i)
{
- memmove (tmp, &base [blocks [j] * 0x8000], 0x8000);
- memmove (&base [blocks [j] * 0x8000],
+ // memmove converted: Different mallocs [Neb]
+ memcpy (tmp, &base [blocks [j] * 0x8000], 0x8000);
+ // memmove converted: Different addresses, or identical for blocks[i] == blocks[j] [Neb]
+ // DS2 DMA notes: Don't do DMA at all if blocks[i] == blocks[j]
+ memcpy (&base [blocks [j] * 0x8000],
&base [blocks [i] * 0x8000], 0x8000);
- memmove (&base [blocks [i] * 0x8000], tmp, 0x8000);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (&base [blocks [i] * 0x8000], tmp, 0x8000);
uint8 b = blocks [j];
blocks [j] = blocks [i];
blocks [i] = b;
@@ -250,13 +255,18 @@ void S9xDeinterleaveGD24(int TotalFileSize, uint8 * base)
SET_UI_COLOR(0,255,255);
}
+ // DS2 DMA notes: base may or may not be 32-byte aligned
uint8 *tmp = (uint8 *) malloc (0x80000);
if (tmp)
{
- memmove(tmp, &base[0x180000], 0x80000);
- memmove(&base[0x180000], &base[0x200000], 0x80000);
- memmove(&base[0x200000], &base[0x280000], 0x80000);
- memmove(&base[0x280000], tmp, 0x80000);
+ // memmove converted: Different mallocs [Neb]
+ memcpy(tmp, &base[0x180000], 0x80000);
+ // memmove converted: Different addresses [Neb]
+ memcpy(&base[0x180000], &base[0x200000], 0x80000);
+ // memmove converted: Different addresses [Neb]
+ memcpy(&base[0x200000], &base[0x280000], 0x80000);
+ // memmove converted: Different mallocs [Neb]
+ memcpy(&base[0x280000], tmp, 0x80000);
free ((char *) tmp);
S9xDeinterleaveType1(TotalFileSize, base);
@@ -399,10 +409,13 @@ char *CMemory::Safe (const char *s)
/**********************************************************************************************/
bool8 CMemory::Init ()
{
+ // DS2 DMA notes: These would do well to be allocated with 32 extra bytes
+ // so they can be 32-byte aligned. [Neb]
RAM = (uint8 *) malloc (0x20000);
SRAM = (uint8 *) malloc (0x20000);
VRAM = (uint8 *) malloc (0x10000);
ROM = (uint8 *) malloc (MAX_ROM_SIZE + 0x200 + 0x8000);
+ // DS2 DMA notes: Can this be sped up with DMA from a block of zeroes? [Neb]
memset (RAM, 0, 0x20000);
memset (SRAM, 0, 0x20000);
memset (VRAM, 0, 0x10000);
@@ -453,7 +466,8 @@ bool8 CMemory::Init ()
SuperFX.nRomBanks = (2 * 1024 * 1024) / (32 * 1024);
SuperFX.pvRom = (uint8 *) ROM;
#endif
-
+
+ // DS2 DMA notes: Can this be sped up with DMA from a block of zeroes? [Neb]
ZeroMemory (IPPU.TileCache [TILE_2BIT], MAX_2BIT_TILES * 128);
ZeroMemory (IPPU.TileCache [TILE_4BIT], MAX_4BIT_TILES * 128);
ZeroMemory (IPPU.TileCache [TILE_8BIT], MAX_8BIT_TILES * 128);
@@ -627,6 +641,8 @@ again:
((hi_score > lo_score && ScoreHiROM (TRUE) > hi_score) ||
(hi_score <= lo_score && ScoreLoROM (TRUE) > lo_score)))
{
+ // memmove required: Overlapping addresses [Neb]
+ // DS2 DMA notes: Can be split into 512-byte DMA blocks [Neb]
memmove (Memory.ROM, Memory.ROM + 512, TotalFileSize - 512);
TotalFileSize -= 512;
S9xMessage (S9X_INFO, S9X_HEADER_WARNING,
@@ -871,6 +887,7 @@ uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize)
_makepath (fname, drive, dir, name, ext);
#ifdef __WIN32__
+ // memmove required: Overlapping addresses [Neb]
memmove (&ext [0], &ext[1], 4);
#endif
@@ -936,11 +953,13 @@ uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize)
FileSize = fread (ptr, 1, maxsize + 0x200 - (ptr - ROM), ROMFile);
fclose (ROMFile);
- int calc_size = (FileSize / 0x2000) * 0x2000;
+ int calc_size = FileSize & ~0x1FFF; // round to the lower 0x2000
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);
HeaderCount++;
FileSize -= 512;
@@ -958,6 +977,7 @@ uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize)
more = TRUE;
ext [0]++;
#ifdef __WIN32__
+ // memmove required: Overlapping addresses [Neb]
memmove (&ext [1], &ext [0], 4);
ext [0] = '.';
#endif
@@ -972,6 +992,7 @@ uint32 CMemory::FileLoader (uint8* buffer, const char* filename, int32 maxsize)
more = TRUE;
name [len - 1]++;
#ifdef __WIN32__
+ // memmove required: Overlapping addresses [Neb]
memmove (&ext [1], &ext [0], 4);
ext [0] = '.';
#endif
@@ -1180,7 +1201,8 @@ void S9xDeinterleaveType2 (bool8 reset)
blocks [i] = (i & ~0xF) | ((i & 3) << 2) |
((i & 12) >> 2);
}
-
+
+ // DS2 DMA notes: ROM needs to be 32-byte aligned [Neb]
uint8 *tmp = (uint8 *) malloc (0x10000);
if (tmp)
@@ -1191,10 +1213,14 @@ void S9xDeinterleaveType2 (bool8 reset)
{
if (blocks [j] == i)
{
- memmove (tmp, &Memory.ROM [blocks [j] * 0x10000], 0x10000);
- memmove (&Memory.ROM [blocks [j] * 0x10000],
+ // memmove converted: Different mallocs [Neb]
+ memcpy (tmp, &Memory.ROM [blocks [j] * 0x10000], 0x10000);
+ // memmove converted: Different addresses, or identical if blocks[i] == blocks[j] [Neb]
+ // DS2 DMA notes: Don't do DMA at all if blocks[i] == blocks[j] [Neb]
+ memcpy (&Memory.ROM [blocks [j] * 0x10000],
&Memory.ROM [blocks [i] * 0x10000], 0x10000);
- memmove (&Memory.ROM [blocks [i] * 0x10000], tmp, 0x10000);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (&Memory.ROM [blocks [i] * 0x10000], tmp, 0x10000);
uint8 b = blocks [j];
blocks [j] = blocks [i];
blocks [i] = b;
@@ -1605,6 +1631,8 @@ bool8 CMemory::LoadSRAM (const char *filename)
if (len - size == 512)
{
// S-RAM file has a header - remove it
+ // memmove required: Overlapping addresses [Neb]
+ // DS2 DMA notes: Can be split into 512-byte DMA blocks [Neb]
memmove (::SRAM, ::SRAM + 512, size);
}
if (len == size + SRTC_SRAM_PAD)
@@ -1705,7 +1733,8 @@ void CMemory::ResetSpeedMap()
void CMemory::WriteProtectROM ()
{
- memmove ((void *) WriteMap, (void *) Map, sizeof (Map));
+ // memmove converted: Different mallocs [Neb]
+ memcpy ((void *) WriteMap, (void *) Map, sizeof (Map));
for (int c = 0; c < 0x1000; c++)
{
if (BlockIsROM [c])
@@ -2545,8 +2574,10 @@ void CMemory::SuperFXROMMap ()
// block is repeated twice in each 64K block.
for (c = 0; c < 64; c++)
{
- memmove (&ROM [0x200000 + c * 0x10000], &ROM [c * 0x8000], 0x8000);
- memmove (&ROM [0x208000 + c * 0x10000], &ROM [c * 0x8000], 0x8000);
+ // memmove converted: Different addresses [Neb]
+ memcpy (&ROM [0x200000 + c * 0x10000], &ROM [c * 0x8000], 0x8000);
+ // memmove converted: Different addresses [Neb]
+ memcpy (&ROM [0x208000 + c * 0x10000], &ROM [c * 0x8000], 0x8000);
}
WriteProtectROM ();
@@ -2612,8 +2643,10 @@ void CMemory::SA1ROMMap ()
WriteProtectROM ();
// Now copy the map and correct it for the SA1 CPU.
- memmove ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap));
- memmove ((void *) SA1.Map, (void *) Map, sizeof (Map));
+ // memmove converted: Different mallocs [Neb]
+ memcpy ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap));
+ // memmove converted: Different mallocs [Neb]
+ memcpy ((void *) SA1.Map, (void *) Map, sizeof (Map));
// Banks 00->3f and 80->bf
for (c = 0; c < 0x400; c += 16)
@@ -3025,8 +3058,10 @@ void CMemory::GNextROMMap ()
WriteProtectROM ();
// Now copy the map and correct it for the SA1 CPU.
- memmove ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap));
- memmove ((void *) SA1.Map, (void *) Map, sizeof (Map));
+ // memmove converted: Different mallocs [Neb]
+ memcpy ((void *) SA1.WriteMap, (void *) WriteMap, sizeof (WriteMap));
+ // memmove converted: Different mallocs [Neb]
+ memcpy ((void *) SA1.Map, (void *) Map, sizeof (Map));
// Banks 00->3f and 80->bf
for (c = 0; c < 0x400; c += 16)
@@ -4385,9 +4420,11 @@ void CMemory::ParseSNESHeader(uint8* RomHeader)
ROMChecksum = RomHeader [0x2e] + (RomHeader [0x2f] << 8);
ROMComplementChecksum = RomHeader [0x2c] + (RomHeader [0x2d] << 8);
ROMRegion= RomHeader[0x29];
- memmove (ROMId, &RomHeader [0x2], 4);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (ROMId, &RomHeader [0x2], 4);
if(RomHeader[0x2A]==0x33)
- memmove (CompanyId, &RomHeader [0], 2);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (CompanyId, &RomHeader [0], 2);
else sprintf(CompanyId, "%02X", RomHeader[0x2A]);
}
diff --git a/source/sa1.cpp b/source/sa1.cpp
index 4dbf9b0..addeed7 100644
--- a/source/sa1.cpp
+++ b/source/sa1.cpp
@@ -742,7 +742,8 @@ void S9xSetSA1 (uint8 byte, uint32 address)
if ((Memory.FillRAM [0x2230] & 0xb0) == 0xa0)
{
// Char conversion 2 DMA enabled
- memmove (&Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + SA1.in_char_dma * 16,
+ // memmove converted: Same malloc but constant non-overlapping addresses [Neb]
+ memcpy (&Memory.ROM [CMemory::MAX_ROM_SIZE - 0x10000] + SA1.in_char_dma * 16,
&Memory.FillRAM [0x2240], 16);
SA1.in_char_dma = (SA1.in_char_dma + 1) & 7;
if ((SA1.in_char_dma & 3) == 0)
@@ -895,6 +896,7 @@ static void S9xSA1DMA ()
len &= 0x3ff;
d = &Memory.FillRAM [0x3000] + dst;
}
+ // memmove required: Can overlap arbitrarily [Neb]
memmove (d, s, len);
Memory.FillRAM [0x2301] |= 0x20;
diff --git a/source/snaporig.cpp b/source/snaporig.cpp
index ac2045c..62674f2 100644
--- a/source/snaporig.cpp
+++ b/source/snaporig.cpp
@@ -313,12 +313,14 @@ static int ReadOrigSnapshot (STREAM snap)
PPU.OBJSizeSelect = OrigPPU.OBJSizeSelect;
PPU.OBJNameBase = OrigPPU.OBJNameBase;
PPU.OAMReadFlip = OrigPPU.OAMReadFlip;
- memmove (PPU.OAMData, OrigPPU.OAMData, sizeof (PPU.OAMData));
+ // memmove converted: Different data segments [Neb]
+ memcpy (PPU.OAMData, OrigPPU.OAMData, sizeof (PPU.OAMData));
PPU.VTimerEnabled = OrigPPU.VTimerEnabled;
PPU.HTimerEnabled = OrigPPU.HTimerEnabled;
PPU.HTimerPosition = OrigPPU.HTimerPosition;
PPU.Mosaic = OrigPPU.Mosaic;
- memmove (PPU.BGMosaic, OrigPPU.BGMosaic, sizeof (PPU.BGMosaic));
+ // memmove converted: Different data segments [Neb]
+ memcpy (PPU.BGMosaic, OrigPPU.BGMosaic, sizeof (PPU.BGMosaic));
PPU.Mode7HFlip = OrigPPU.Mode7HFlip;
PPU.Mode7VFlip = OrigPPU.Mode7VFlip;
PPU.Mode7Repeat = OrigPPU.Mode7Repeat;
diff --git a/source/snapshot.cpp b/source/snapshot.cpp
index ad9b131..c414dc2 100644
--- a/source/snapshot.cpp
+++ b/source/snapshot.cpp
@@ -1036,7 +1036,8 @@ void FreezeStruct (STREAM stream, char *name, void *base, FreezeData *fields,
}
break;
case uint8_ARRAY_V:
- memmove (ptr, (uint8 *) base + fields [i].offset, fields [i].size);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (ptr, (uint8 *) base + fields [i].offset, fields [i].size);
ptr += fields [i].size;
break;
case uint16_ARRAY_V:
@@ -1139,7 +1140,8 @@ int UnfreezeStruct (STREAM stream, char *name, void *base, FreezeData *fields,
}
break;
case uint8_ARRAY_V:
- memmove ((uint8 *) base + fields [i].offset, ptr, fields [i].size);
+ // memmove converted: Different mallocs [Neb]
+ memcpy ((uint8 *) base + fields [i].offset, ptr, fields [i].size);
ptr += fields [i].size;
break;
case uint16_ARRAY_V:
@@ -1264,6 +1266,7 @@ void UnfreezeStructFromCopy (void *base, FreezeData *fields, int num_fields, uin
}
break;
case uint8_ARRAY_V:
+ // memmove required: Source could point within dest [Neb]
memmove ((uint8 *) base + fields [i].offset, ptr, fields [i].size);
ptr += fields [i].size;
break;
@@ -1581,7 +1584,8 @@ bool8 S9xUnfreezeZSNES (const char *filename)
APU.Timer [1] = t [45];
APU.Timer [2] = t [46];
- memmove (APU.ExtraRAM, &t [48], 64);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (APU.ExtraRAM, &t [48], 64);
// Internal ZSNES sound DSP state
fread (t, 1, 1068, fs);
@@ -1657,7 +1661,9 @@ bool8 S9xUnfreezeZSNES (const char *filename)
SA1.Registers.PC = READ_DWORD (&t [636]);
SA1.Registers.P.W = t [620] | (t [624] << 8);
- memmove (&Memory.FillRAM [0x3000], t + 692, 2 * 1024);
+ // memmove converted: Different mallocs [Neb]
+ // DS2 DMA notes: This code path is not used [Neb]
+ memcpy (&Memory.FillRAM [0x3000], t + 692, 2 * 1024);
fread (::SRAM, 1, 64 * 1024, fs);
fseek (fs, 64 * 1024, SEEK_CUR);
diff --git a/source/srtc.cpp b/source/srtc.cpp
index 48add97..0e6f30e 100644
--- a/source/srtc.cpp
+++ b/source/srtc.cpp
@@ -525,12 +525,14 @@ void S9xSRTCPreSaveState ()
SRAM [s + 0] = rtc.needs_init;
SRAM [s + 1] = rtc.count_enable;
- memmove (&SRAM [s + 2], rtc.data, MAX_RTC_INDEX + 1);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (&SRAM [s + 2], rtc.data, MAX_RTC_INDEX + 1);
SRAM [s + 3 + MAX_RTC_INDEX] = rtc.index;
SRAM [s + 4 + MAX_RTC_INDEX] = rtc.mode;
#ifdef LSB_FIRST
- memmove (&SRAM [s + 5 + MAX_RTC_INDEX], &rtc.system_timestamp, 8);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (&SRAM [s + 5 + MAX_RTC_INDEX], &rtc.system_timestamp, 8);
#else
SRAM [s + 5 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 0);
SRAM [s + 6 + MAX_RTC_INDEX] = (uint8) (rtc.system_timestamp >> 8);
@@ -555,12 +557,14 @@ void S9xSRTCPostLoadState ()
rtc.needs_init = SRAM [s + 0];
rtc.count_enable = SRAM [s + 1];
- memmove (rtc.data, &SRAM [s + 2], MAX_RTC_INDEX + 1);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (rtc.data, &SRAM [s + 2], MAX_RTC_INDEX + 1);
rtc.index = SRAM [s + 3 + MAX_RTC_INDEX];
rtc.mode = SRAM [s + 4 + MAX_RTC_INDEX];
#ifdef LSB_FIRST
- memmove (&rtc.system_timestamp, &SRAM [s + 5 + MAX_RTC_INDEX], 8);
+ // memmove converted: Different mallocs [Neb]
+ memcpy (&rtc.system_timestamp, &SRAM [s + 5 + MAX_RTC_INDEX], 8);
#else
rtc.system_timestamp |= (SRAM [s + 5 + MAX_RTC_INDEX] << 0);
rtc.system_timestamp |= (SRAM [s + 6 + MAX_RTC_INDEX] << 8);