From 98d9f13600ae6a2f2a7e4150b10f6e8cba4e01bf Mon Sep 17 00:00:00 2001 From: goyuken Date: Wed, 3 Oct 2012 15:31:04 +0000 Subject: [PATCH] change IEmulator.DeterministicEmulation to get-only; the old interface implies that a core should be able to take a change to the property at any time, which isn't feasable. most existing cores changed to return true all the time. SNES now takes determinism parameter in Load() --- BizHawk.Emulation/Consoles/Calculator/TI83.cs | 2 +- .../Consoles/Coleco/ColecoVision.cs | 2 +- .../Consoles/Intellivision/Intellivision.cs | 2 +- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 2 +- .../Consoles/Nintendo/NES/NES.cs | 2 +- .../Consoles/Nintendo/SNES/LibsnesCore.cs | 19 +++++-------------- .../Consoles/PC Engine/PCEngine.cs | 2 +- .../Consoles/Sega/Genesis/Genesis.cs | 2 +- BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs | 2 +- .../Base Implementations/NullEmulator.cs | 2 +- BizHawk.Emulation/Interfaces/IEmulator.cs | 3 ++- BizHawk.MultiClient/MainForm.cs | 8 ++------ 12 files changed, 18 insertions(+), 30 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Calculator/TI83.cs b/BizHawk.Emulation/Consoles/Calculator/TI83.cs index c09230bcd7..4b75c8a1b1 100644 --- a/BizHawk.Emulation/Consoles/Calculator/TI83.cs +++ b/BizHawk.Emulation/Consoles/Calculator/TI83.cs @@ -475,7 +475,7 @@ namespace BizHawk.Emulation.Consoles.Calculator public int LagCount { get { return _lagcount; } set { _lagcount = value; } } public bool IsLagFrame { get { return islag; } } - public bool DeterministicEmulation { get { return true; } set { } } + public bool DeterministicEmulation { get { return true; } } public byte[] ReadSaveRam() { return null; } public void StoreSaveRam(byte[] data) { } diff --git a/BizHawk.Emulation/Consoles/Coleco/ColecoVision.cs b/BizHawk.Emulation/Consoles/Coleco/ColecoVision.cs index 4e52a816d4..f7adb0d0e3 100644 --- a/BizHawk.Emulation/Consoles/Coleco/ColecoVision.cs +++ b/BizHawk.Emulation/Consoles/Coleco/ColecoVision.cs @@ -75,7 +75,7 @@ namespace BizHawk.Emulation.Consoles.Coleco public void ClearSaveRam() { } public bool SaveRamModified { get; set; } - public bool DeterministicEmulation { get; set; } + public bool DeterministicEmulation { get { return true; } } public void SaveStateText(TextWriter writer) { SyncState(Serializer.CreateTextWriter(writer)); } public void LoadStateText(TextReader reader) { SyncState(Serializer.CreateTextReader(reader)); } public void SaveStateBinary(BinaryWriter bw) { SyncState(Serializer.CreateBinaryWriter(bw)); } diff --git a/BizHawk.Emulation/Consoles/Intellivision/Intellivision.cs b/BizHawk.Emulation/Consoles/Intellivision/Intellivision.cs index 398c9c0e22..287afe9aed 100644 --- a/BizHawk.Emulation/Consoles/Intellivision/Intellivision.cs +++ b/BizHawk.Emulation/Consoles/Intellivision/Intellivision.cs @@ -115,7 +115,7 @@ namespace BizHawk.Emulation.Consoles.Intellivision get { return "INTV"; } } - public bool DeterministicEmulation { get; set; } + public bool DeterministicEmulation { get { return true; } } public byte[] ReadSaveRam() { return null; } diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs index 8e65deb69f..1f4e610c11 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -219,7 +219,7 @@ namespace BizHawk.Emulation.Consoles.GB get { return "GB"; } } - public bool DeterministicEmulation { get; set; } + public bool DeterministicEmulation { get { return true; } } public byte[] ReadSaveRam() { diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs index 2b232501a2..815ae15555 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/NES.cs @@ -307,7 +307,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo public int LagCount { get { return _lagcount; } set { _lagcount = value; } } public bool IsLagFrame { get { return islag; } } - public bool DeterministicEmulation { get { return true; } set { } } + public bool DeterministicEmulation { get { return true; } } diff --git a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs index bd9c270ffe..3848f707bd 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -360,7 +360,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES { } - public void Load(GameInfo game, byte[] romData, byte[] sgbRomData) + public void Load(GameInfo game, byte[] romData, byte[] sgbRomData, bool DeterministicEmulation) { //attach this core as the current if (CurrLibsnesCore != null) @@ -434,9 +434,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES SetupMemoryDomains(romData); - // disallow any future modifications to the DeterministicEmulation parameter, and set initial deterministic savestate - _DeterministicEmulationProtected = true; - if (DeterministicEmulation) + this.DeterministicEmulation = DeterministicEmulation; + if (DeterministicEmulation) // save frame-0 savestate now CoreSaveStateInternal(true); } @@ -634,18 +633,10 @@ namespace BizHawk.Emulation.Consoles.Nintendo.SNES public bool IsLagFrame { get; private set; } public string SystemId { get; private set; } - - bool _DeterministicEmulation = false; - bool _DeterministicEmulationProtected = false; public bool DeterministicEmulation { - get { return _DeterministicEmulation; } - set - { - if (_DeterministicEmulationProtected && value != _DeterministicEmulation) - throw new Exception("snes: DeterministicEmulation must be set before load!"); - _DeterministicEmulation = value; - } + get; + private set; } diff --git a/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs b/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs index 75997a40a9..a862fc898d 100644 --- a/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs +++ b/BizHawk.Emulation/Consoles/PC Engine/PCEngine.cs @@ -277,7 +277,7 @@ namespace BizHawk.Emulation.Consoles.TurboGrafx public string SystemId { get { return systemid; } } public string Region { get; set; } - public bool DeterministicEmulation { get; set; } + public bool DeterministicEmulation { get { return true; } } public byte[] ReadSaveRam() { diff --git a/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs b/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs index 88e992ff81..9d6cb38f86 100644 --- a/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs +++ b/BizHawk.Emulation/Consoles/Sega/Genesis/Genesis.cs @@ -264,7 +264,7 @@ namespace BizHawk.Emulation.Consoles.Sega public int Frame { get; set; } public int LagCount { get { return _lagcount; } set { _lagcount = value; } } public bool IsLagFrame { get { return islag; } } - public bool DeterministicEmulation { get; set; } + public bool DeterministicEmulation { get { return true; } } public string SystemId { get { return "GEN"; } } diff --git a/BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs b/BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs index 1bc7cb40ce..457817a5fb 100644 --- a/BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs +++ b/BizHawk.Emulation/Consoles/Sega/SMS/SMS.cs @@ -77,7 +77,7 @@ namespace BizHawk.Emulation.Consoles.Sega byte Port3F = 0xFF; public DisplayType DisplayType { get; set; } - public bool DeterministicEmulation { get; set; } + public bool DeterministicEmulation { get { return true; } } public SMS(GameInfo game, byte[] rom) { diff --git a/BizHawk.Emulation/Interfaces/Base Implementations/NullEmulator.cs b/BizHawk.Emulation/Interfaces/Base Implementations/NullEmulator.cs index 48a6014373..d09126bfd2 100644 --- a/BizHawk.Emulation/Interfaces/Base Implementations/NullEmulator.cs +++ b/BizHawk.Emulation/Interfaces/Base Implementations/NullEmulator.cs @@ -44,7 +44,7 @@ namespace BizHawk public byte[] ReadSaveRam() { return null; } public void StoreSaveRam(byte[] data) { } public void ClearSaveRam() { } - public bool DeterministicEmulation { get; set; } + public bool DeterministicEmulation { get { return true; } } public bool SaveRamModified { get; set; } public void SaveStateText(TextWriter writer) { } public void LoadStateText(TextReader reader) { } diff --git a/BizHawk.Emulation/Interfaces/IEmulator.cs b/BizHawk.Emulation/Interfaces/IEmulator.cs index d2365fcc41..fcf036fb4b 100644 --- a/BizHawk.Emulation/Interfaces/IEmulator.cs +++ b/BizHawk.Emulation/Interfaces/IEmulator.cs @@ -20,7 +20,8 @@ namespace BizHawk int LagCount { get; set; } bool IsLagFrame { get; } string SystemId { get; } - bool DeterministicEmulation { get; set; } + /// if you want to set this, look in the emulator's constructor or Load() method + bool DeterministicEmulation { get; } /// /// return a copy of the saveram. editing it won't do you any good unless you later call StoreSaveRam() diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 9239f5f0e9..ccfe2ecb93 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -1401,10 +1401,9 @@ namespace BizHawk.MultiClient { game.System = "SNES"; var snes = new LibsnesCore(); - if (deterministicemulation) snes.DeterministicEmulation = true; nextEmulator = snes; nextEmulator.CoreInputComm = Global.CoreInputComm; - snes.Load(game, rom.FileData, null); + snes.Load(game, rom.FileData, null, deterministicemulation); } break; case "SMS": @@ -1492,9 +1491,8 @@ namespace BizHawk.MultiClient game.AddOption("SGB"); game.System = "SGB"; var snes = new LibsnesCore(); - if (deterministicemulation) snes.DeterministicEmulation = true; nextEmulator = snes; - snes.Load(game, rom.FileData, sgbrom); + snes.Load(game, rom.FileData, sgbrom, deterministicemulation); } break; case "COLV": @@ -1530,8 +1528,6 @@ namespace BizHawk.MultiClient if (nextEmulator == null) throw new Exception(); - if (deterministicemulation) nextEmulator.DeterministicEmulation = true; - CloseGame(); Global.Emulator.Dispose(); Global.Emulator = nextEmulator;