Skip to content

Commit d5400f7

Browse files
committed
Fix snapshot bugs.
1 parent 97dd443 commit d5400f7

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

memmap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ bool8 CMemory::Init (void)
930930

931931
ROMStorage.resize(MAX_ROM_SIZE + 0x200 + 0x8000);
932932
std::fill(ROMStorage.begin(), ROMStorage.end(), 0);
933-
SRAMStorage.resize(0x80000);
933+
SRAMStorage.resize(SRAM_SIZE);
934934
std::fill(SRAMStorage.begin(), SRAMStorage.end(), 0);
935935
SRAM = &SRAMStorage[0];
936936
memset(RAM, 0, sizeof(RAM));

memmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct CMemory
6161
uint8 *ROM;
6262
std::vector<uint8_t> SRAMStorage;
6363
uint8 *SRAM;
64+
const size_t SRAM_SIZE = 0x80000;
6465
uint8 VRAM[0x10000];
6566
uint8 *FillRAM;
6667
uint8 *BWRAM;

snapshot.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ void S9xFreezeToStream (STREAM stream)
11931193

11941194
FreezeBlock (stream, "RAM", Memory.RAM, sizeof(Memory.RAM));
11951195

1196-
FreezeBlock (stream, "SRA", Memory.SRAM, sizeof(Memory.SRAM));
1196+
FreezeBlock (stream, "SRA", Memory.SRAM, Memory.SRAM_SIZE);
11971197

11981198
FreezeBlock (stream, "FIL", Memory.FillRAM, 0x8000);
11991199

@@ -1399,9 +1399,9 @@ int S9xUnfreezeFromStream (STREAM stream)
13991399
break;
14001400

14011401
if (fast)
1402-
result = UnfreezeBlock(stream, "SRA", Memory.SRAM, sizeof(Memory.SRAM));
1402+
result = UnfreezeBlock(stream, "SRA", Memory.SRAM, Memory.SRAM_SIZE);
14031403
else
1404-
result = UnfreezeBlockCopy (stream, "SRA", &local_sram, sizeof(Memory.SRAM));
1404+
result = UnfreezeBlockCopy (stream, "SRA", &local_sram, Memory.SRAM_SIZE);
14051405
if (result != SUCCESS)
14061406
break;
14071407

@@ -1571,7 +1571,7 @@ int S9xUnfreezeFromStream (STREAM stream)
15711571
memcpy(Memory.RAM, local_ram, 0x20000);
15721572

15731573
if (local_sram)
1574-
memcpy(Memory.SRAM, local_sram, 0x80000);
1574+
memcpy(Memory.SRAM, local_sram, Memory.SRAM_SIZE);
15751575

15761576
if (local_fillram)
15771577
memcpy(Memory.FillRAM, local_fillram, 0x8000);
@@ -1585,15 +1585,19 @@ int S9xUnfreezeFromStream (STREAM stream)
15851585
{
15861586
printf("Adjusting old APU snapshot (snapshot version %d, current is %d)\n", version, SNAPSHOT_VERSION);
15871587
const size_t spc_block_size = 65700;
1588-
const size_t old_dsp_block_size = 513;
1588+
const size_t old_dsp_block_size = 514;
15891589
const size_t added_bytes_v12 = 128;
15901590
const size_t bytes_afterward = 16;
15911591
// Shift end to make room for extra 128 bytes
15921592
memmove(local_apu_sound + spc_block_size + old_dsp_block_size + added_bytes_v12,
15931593
local_apu_sound + spc_block_size + old_dsp_block_size,
15941594
bytes_afterward);
15951595
// Copy saved internal registers to external registers
1596-
memmove(local_apu_sound + spc_block_size + old_dsp_block_size, local_apu_sound + spc_block_size, added_bytes_v12);
1596+
const size_t new_dsp_registers_position = spc_block_size + 513;
1597+
1598+
memmove(local_apu_sound + spc_block_size + new_dsp_registers_position,
1599+
local_apu_sound + spc_block_size,
1600+
added_bytes_v12);
15971601
S9xAPULoadState(local_apu_sound);
15981602
}
15991603
else if (version >= 12)

0 commit comments

Comments
 (0)