From ecd58fc96efb09398169f05b2710081ce8b90399 Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 16 Jul 2012 22:06:55 +0000 Subject: [PATCH] nes-protect from syncstates which dont call base.SyncState --- BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs | 4 ++++ .../Consoles/Nintendo/NES/Boards/Namcot1xx/Mapper112.cs | 2 +- BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs index 2a677d44fd..a463a69afe 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/BoardSystem.cs @@ -70,12 +70,16 @@ namespace BizHawk.Emulation.Consoles.Nintendo public CartInfo Cart { get { return NES.cart; } } public NES NES { get; set; } + //this is set to true when SyncState is called, so that we know the base class SyncState was used + public bool SyncStateFlag = false; + public virtual void SyncState(Serializer ser) { ser.Sync("vram", ref vram, true); ser.Sync("wram", ref wram, true); for (int i = 0; i < 4; i++) ser.Sync("mirroring" + i, ref mirroring[i]); ser.Sync("irq_signal", ref irq_signal); + SyncStateFlag = true; } public virtual void SyncIRQ(bool flag) diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Namcot1xx/Mapper112.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Namcot1xx/Mapper112.cs index 2c659ba864..402a00691f 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Namcot1xx/Mapper112.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/Namcot1xx/Mapper112.cs @@ -55,7 +55,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo public override void SyncState(Serializer ser) { - base.SyncState(ser); //any syncstate which doesnt call base is a BUG!!!!!!!!! im going to protect against this in the near future. + base.SyncState(ser); ser.Sync("reg_addr", ref reg_addr); ser.Sync("regs", ref regs); Sync(); diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index 155244b2a8..99e495d5fc 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -595,6 +595,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo ser.Sync("cpu_stepcounter", ref cpu_stepcounter); ser.Sync("cpu_deadcounter", ref cpu_deadcounter); board.SyncState(ser); + if (board is NESBoardBase && !((NESBoardBase)board).SyncStateFlag) + throw new InvalidOperationException("the current NES mapper didnt call base.SyncState"); ppu.SyncState(ser); apu.SyncState(ser); ser.EndSection();