diff --git a/source/Memory.cpp b/source/Memory.cpp index 26cb5d90..e07c6548 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -1537,7 +1537,7 @@ static LPBYTE AllocMemImage(void) // Allocate memory for 'memimage' (and the alias 'mem') // . Setup so we have 2 consecutive virtual 64K pages pointing to the same physical 64K page. - // . This is a fix (and optimisation) for 6502 opcodes that do a 16-bit at 6502 address $FFFF. (GH#1285) + // . This is a fix (and optimisation) for 6502 opcodes that do a 16-bit read at 6502 address $FFFF. (GH#1285) SYSTEM_INFO info; GetSystemInfo(&info); bool res = info.dwAllocationGranularity <= _6502_MEM_LEN; @@ -1559,23 +1559,22 @@ static LPBYTE AllocMemImage(void) { VirtualFree(baseAddr, 0, MEM_RELEASE); - res = true; - for (UINT i = 0; i < num64KPages; i++) + UINT count = 0; + while (count < num64KPages) { // MSDN: "To specify a suggested base address for the view, use the MapViewOfFileEx function. However, this practice is not recommended." // This is why we retry 10 times. - if (!MapViewOfFileEx(g_hMemImage, FILE_MAP_ALL_ACCESS, 0, 0, _6502_MEM_LEN, baseAddr + i * _6502_MEM_LEN)) - { - res = false; + if (!MapViewOfFileEx(g_hMemImage, FILE_MAP_ALL_ACCESS, 0, 0, _6502_MEM_LEN, baseAddr + count * _6502_MEM_LEN)) break; - } + count++; } + res = (count == num64KPages); if (res) break; // Failed this time, so clean-up and retry... - for (UINT i = 0; i < num64KPages; i++) + for (UINT i = 0; i < count; i++) UnmapViewOfFile(baseAddr + i * _6502_MEM_LEN); } }