ref: d634b1f7523a10f2de4e59147afe2720e3716fe4
parent: 1de9649cf755481b692e278ad2af69d6369fd0b5
author: Snesrev <[email protected]>
date: Tue Sep 20 10:24:50 EDT 2022
Fix snapshot bug introduced in the hdma reloc
--- a/zelda_cpu_infra.c
+++ b/zelda_cpu_infra.c
@@ -375,6 +375,8 @@
}
void CopyStateAfterSnapshotRestore(bool is_reset) {
+ memcpy(g_snes->ram + 0x1DBA0, g_snes->ram + 0x1b00, 224 * 2); // hdma table was moved
+
memcpy(g_zenv.ram, g_snes->ram, 0x20000);
memcpy(g_zenv.sram, g_snes->cart->ram, g_snes->cart->ramSize);
memcpy(g_zenv.ppu->vram, &g_snes->ppu->vram, offsetof(Ppu, ppu2openBus) + 1 - offsetof(Ppu, vram));
@@ -387,6 +389,8 @@
memcpy(g_zenv.dma->channel, g_snes->dma->channel, sizeof(Dma) - offsetof(Dma, channel));
+
+
g_zenv.player->timer_cycles = 0;
ZeldaOpenMsuFile();
@@ -395,6 +399,8 @@
void SaveSnesState(ByteArray *ctx) {
MakeSnapshot(&g_snapshot_before);
+ memcpy(g_zenv.ram + 0x1b00, g_zenv.ram + 0x1DBA0, 224 * 2); // hdma table was moved
+
// Copy from my state into the emulator
memcpy(&g_snes->ppu->vram, g_zenv.ppu->vram, offsetof(Ppu, ppu2openBus) + 1 - offsetof(Ppu, vram));
memcpy(g_snes->ram, g_zenv.ram, 0x20000);
@@ -746,14 +752,16 @@
MakeMySnapshot(&g_snapshot_mine);
MakeSnapshot(&g_snapshot_theirs);
- // Compare both snapshots
+ // Compare both snapshots before we run the frame, to see they match
VerifySnapshotsEq(&g_snapshot_mine, &g_snapshot_theirs, &g_snapshot_before);
if (g_fail) {
printf("early fail\n");
+ assert(0);
return turbo;
}
// Run orig version then snapshot
+again_theirs:
snes->input1->currentState = input_state;
RunEmulatedSnesFrame(snes, run_what);
MakeSnapshot(&g_snapshot_theirs);
@@ -770,9 +778,11 @@
if (g_fail) {
g_fail = false;
RestoreMySnapshot(&g_snapshot_before);
- // RestoreSnapshot(&g_snapshot_before);
//SaveLoadSlot(kSaveLoad_Save, 0);
- goto again_mine;
+ if (0)
+ goto again_mine;
+ RestoreSnapshot(&g_snapshot_before);
+ goto again_theirs;
}
return turbo;