From 5651181d39103eda72fa2598f065f245e3402faf Mon Sep 17 00:00:00 2001 From: zeromus Date: Fri, 22 Nov 2013 19:34:24 +0000 Subject: [PATCH] fix n64 savestates --- BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs | 4 +++- .../Consoles/Nintendo/N64/mupen64plusApi.cs | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs index bfae8f383b..723d0599bb 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/N64.cs @@ -252,6 +252,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 byte[] saveram = api.SaveSaveram(); writer.Write(saveram); + if (saveram.Length != mupen64plusApi.kSaveramSize) + throw new InvalidOperationException("Unexpected N64 SaveRam size"); // other variables writer.Write(IsLagFrame); @@ -267,7 +269,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 api.LoadState(data); - reader.Read(SaveStatePrivateBuff,0,0x800 + 0x8000 * 4); + reader.Read(SaveStatePrivateBuff, 0, mupen64plusApi.kSaveramSize); api.LoadSaveram(SaveStatePrivateBuff); // other variables diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs index 748578ca34..cd641d41a7 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/N64/mupen64plusApi.cs @@ -792,6 +792,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 m64pinit_saveram(); } + public const int kSaveramSize = 0x800 + 4 * 0x8000 + 0x20000 + 0x8000; + public byte[] SaveSaveram() { if (disposed) @@ -803,12 +805,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64 else { // This shouldn't happen!! - return new byte[0x800 + 4 * 0x8000 + 0x20000 + 0x8000]; + return new byte[kSaveramSize]; } } else { - byte[] dest = new byte[0x800 + 4 * 0x8000 + 0x20000 + 0x8000]; + byte[] dest = new byte[kSaveramSize]; m64psave_saveram(dest); return dest; }