Make Binary states default and Textstates opt-in for cores (#1848)

* Rewind & State config - remove the default option

* remove the savestate type of default, not that this is a breaking config change for anyone that had specifically set savestates to text

* remove BinaryStatesPreferred from IStatable and use config setting when starting movies from "Now" in record movie dialog

* remove BinaryStatesPreferred from cores

* make text savestates an extension method off of IStatable and an inteface ITextStatable it uses if the core implements it. This will allow cores to opt in to text states if desired

* make cores with actual text savestate impleemntations get ITextStatable, remove text state logic from cores that just have a binary as as text implementation
This commit is contained in:
adelikat 2020-02-15 10:22:26 -06:00 committed by GitHub
parent 2d637b6d1d
commit 4b7a7dd293
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 78 additions and 319 deletions

View File

@ -3,6 +3,7 @@ using System.IO;
using System.Linq; using System.Linq;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -16,8 +17,7 @@ namespace BizHawk.Client.Common
// the old method of text savestate save is now gone. // the old method of text savestate save is now gone.
// a text savestate is just like a binary savestate, but with a different core lump // a text savestate is just like a binary savestate, but with a different core lump
using var bs = new BinaryStateSaver(filename); using var bs = new BinaryStateSaver(filename);
if (Global.Config.SaveStateType == SaveStateTypeE.Text if (Global.Config.SaveStateType == SaveStateTypeE.Text)
|| (Global.Config.SaveStateType == SaveStateTypeE.Default && !core.BinarySaveStatesPreferred))
{ {
// text savestate format // text savestate format
using (new SimpleTime("Save Core")) using (new SimpleTime("Save Core"))

View File

@ -136,7 +136,7 @@ namespace BizHawk.Client.Common
public RewindConfig Rewind { get; set; } = new RewindConfig(); public RewindConfig Rewind { get; set; } = new RewindConfig();
// Savestate settings // Savestate settings
public SaveStateTypeE SaveStateType { get; set; } = SaveStateTypeE.Default; public SaveStateTypeE SaveStateType { get; set; } = SaveStateTypeE.Binary;
public const int DefaultSaveStateCompressionLevelNormal = 1; public const int DefaultSaveStateCompressionLevelNormal = 1;
public int SaveStateCompressionLevelNormal { get; set; } = DefaultSaveStateCompressionLevelNormal; public int SaveStateCompressionLevelNormal { get; set; } = DefaultSaveStateCompressionLevelNormal;
public const int DefaultSaveStateCompressionLevelRewind = 0; // this isn't actually used yet public const int DefaultSaveStateCompressionLevelRewind = 0; // this isn't actually used yet

View File

@ -29,7 +29,7 @@
public enum SaveStateTypeE public enum SaveStateTypeE
{ {
Default, Binary, Text Binary, Text
} }
public enum ClientProfile public enum ClientProfile

View File

@ -84,7 +84,6 @@
this.groupBox6 = new System.Windows.Forms.GroupBox(); this.groupBox6 = new System.Windows.Forms.GroupBox();
this.rbStatesText = new System.Windows.Forms.RadioButton(); this.rbStatesText = new System.Windows.Forms.RadioButton();
this.rbStatesBinary = new System.Windows.Forms.RadioButton(); this.rbStatesBinary = new System.Windows.Forms.RadioButton();
this.rbStatesDefault = new System.Windows.Forms.RadioButton();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.btnResetCompression = new System.Windows.Forms.Button(); this.btnResetCompression = new System.Windows.Forms.Button();
this.trackBarCompression = new System.Windows.Forms.TrackBar(); this.trackBarCompression = new System.Windows.Forms.TrackBar();
@ -762,7 +761,6 @@
// //
this.groupBox6.Controls.Add(this.rbStatesText); this.groupBox6.Controls.Add(this.rbStatesText);
this.groupBox6.Controls.Add(this.rbStatesBinary); this.groupBox6.Controls.Add(this.rbStatesBinary);
this.groupBox6.Controls.Add(this.rbStatesDefault);
this.groupBox6.Location = new System.Drawing.Point(22, 78); this.groupBox6.Location = new System.Drawing.Point(22, 78);
this.groupBox6.Name = "groupBox6"; this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(215, 48); this.groupBox6.Size = new System.Drawing.Size(215, 48);
@ -773,7 +771,7 @@
// rbStatesText // rbStatesText
// //
this.rbStatesText.AutoSize = true; this.rbStatesText.AutoSize = true;
this.rbStatesText.Location = new System.Drawing.Point(163, 18); this.rbStatesText.Location = new System.Drawing.Point(88, 18);
this.rbStatesText.Name = "rbStatesText"; this.rbStatesText.Name = "rbStatesText";
this.rbStatesText.Size = new System.Drawing.Size(46, 17); this.rbStatesText.Size = new System.Drawing.Size(46, 17);
this.rbStatesText.TabIndex = 1; this.rbStatesText.TabIndex = 1;
@ -784,7 +782,7 @@
// rbStatesBinary // rbStatesBinary
// //
this.rbStatesBinary.AutoSize = true; this.rbStatesBinary.AutoSize = true;
this.rbStatesBinary.Location = new System.Drawing.Point(88, 18); this.rbStatesBinary.Location = new System.Drawing.Point(6, 18);
this.rbStatesBinary.Name = "rbStatesBinary"; this.rbStatesBinary.Name = "rbStatesBinary";
this.rbStatesBinary.Size = new System.Drawing.Size(54, 17); this.rbStatesBinary.Size = new System.Drawing.Size(54, 17);
this.rbStatesBinary.TabIndex = 1; this.rbStatesBinary.TabIndex = 1;
@ -792,17 +790,6 @@
this.rbStatesBinary.Text = "Binary"; this.rbStatesBinary.Text = "Binary";
this.rbStatesBinary.UseVisualStyleBackColor = true; this.rbStatesBinary.UseVisualStyleBackColor = true;
// //
// rbStatesDefault
//
this.rbStatesDefault.AutoSize = true;
this.rbStatesDefault.Location = new System.Drawing.Point(6, 18);
this.rbStatesDefault.Name = "rbStatesDefault";
this.rbStatesDefault.Size = new System.Drawing.Size(59, 17);
this.rbStatesDefault.TabIndex = 0;
this.rbStatesDefault.TabStop = true;
this.rbStatesDefault.Text = "Default";
this.rbStatesDefault.UseVisualStyleBackColor = true;
//
// btnResetCompression // btnResetCompression
// //
this.btnResetCompression.AutoSize = true; this.btnResetCompression.AutoSize = true;
@ -1088,7 +1075,6 @@
private System.Windows.Forms.GroupBox groupBox6; private System.Windows.Forms.GroupBox groupBox6;
private System.Windows.Forms.RadioButton rbStatesText; private System.Windows.Forms.RadioButton rbStatesText;
private System.Windows.Forms.RadioButton rbStatesBinary; private System.Windows.Forms.RadioButton rbStatesBinary;
private System.Windows.Forms.RadioButton rbStatesDefault;
private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.TrackBar trackBarCompression; private System.Windows.Forms.TrackBar trackBarCompression;
private System.Windows.Forms.NumericUpDown nudCompression; private System.Windows.Forms.NumericUpDown nudCompression;

View File

@ -74,7 +74,6 @@ namespace BizHawk.Client.EmuHawk
nudCompression.Value = _config.SaveStateCompressionLevelNormal; nudCompression.Value = _config.SaveStateCompressionLevelNormal;
rbStatesDefault.Checked = _config.SaveStateType == SaveStateTypeE.Default;
rbStatesBinary.Checked = _config.SaveStateType == SaveStateTypeE.Binary; rbStatesBinary.Checked = _config.SaveStateType == SaveStateTypeE.Binary;
rbStatesText.Checked = _config.SaveStateType == SaveStateTypeE.Text; rbStatesText.Checked = _config.SaveStateType == SaveStateTypeE.Text;
@ -182,7 +181,6 @@ namespace BizHawk.Client.EmuHawk
// These settings are not used by DoRewindSettings // These settings are not used by DoRewindSettings
_config.Rewind.SpeedMultiplier = (int)RewindSpeedNumeric.Value; _config.Rewind.SpeedMultiplier = (int)RewindSpeedNumeric.Value;
_config.SaveStateCompressionLevelNormal = (int)nudCompression.Value; _config.SaveStateCompressionLevelNormal = (int)nudCompression.Value;
if (rbStatesDefault.Checked) _config.SaveStateType = SaveStateTypeE.Default;
if (rbStatesBinary.Checked) _config.SaveStateType = SaveStateTypeE.Binary; if (rbStatesBinary.Checked) _config.SaveStateType = SaveStateTypeE.Binary;
if (rbStatesText.Checked) _config.SaveStateType = SaveStateTypeE.Text; if (rbStatesText.Checked) _config.SaveStateType = SaveStateTypeE.Text;
_config.BackupSavestates = BackupSavestatesCheckbox.Checked; _config.BackupSavestates = BackupSavestatesCheckbox.Checked;

View File

@ -108,7 +108,7 @@ namespace BizHawk.Client.EmuHawk
movieToRecord.StartsFromSavestate = true; movieToRecord.StartsFromSavestate = true;
movieToRecord.StartsFromSaveRam = false; movieToRecord.StartsFromSaveRam = false;
if (core.BinarySaveStatesPreferred) if (_config.SaveStateType == SaveStateTypeE.Binary)
{ {
movieToRecord.BinarySavestate = (byte[])core.SaveStateBinary().Clone(); movieToRecord.BinarySavestate = (byte[])core.SaveStateBinary().Clone();
} }

View File

@ -1,4 +1,5 @@
using System.IO; using System.IO;
using BizHawk.Common.BufferExtensions;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
@ -19,18 +20,54 @@ namespace BizHawk.Emulation.Common
/// </summary> /// </summary>
public interface IStatable : IBinaryStateable, IEmulatorService public interface IStatable : IBinaryStateable, IEmulatorService
{ {
/// <summary>
/// Gets a value indicating whether the core would rather give a binary savestate than a text one. Both must function regardless
/// </summary>
bool BinarySaveStatesPreferred { get; }
void SaveStateText(TextWriter writer);
void LoadStateText(TextReader reader);
/// <summary> /// <summary>
/// save state binary to a byte buffer /// save state binary to a byte buffer
/// </summary> /// </summary>
/// <returns>you may NOT modify this. if you call SaveStateBinary() again with the same core, the old data MAY be overwritten.</returns> /// <returns>you may NOT modify this. if you call SaveStateBinary() again with the same core, the old data MAY be overwritten.</returns>
byte[] SaveStateBinary(); byte[] SaveStateBinary();
} }
/// <summary>
/// Allows a core to opt into text savestates.
/// If a core does not implement this interface, a default implementation
/// will be used that doesn't yield anything useful in the states, just binary as text
/// </summary>
public interface ITextStatable : IStatable
{
void SaveStateText(TextWriter writer);
void LoadStateText(TextReader reader);
}
public static class StatableExtensions
{
public static void SaveStateText(this IStatable core, TextWriter writer)
{
if (core is ITextStatable textCore)
{
textCore.SaveStateText(writer);
}
var temp = core.SaveStateBinary();
temp.SaveAsHexFast(writer);
}
public static void LoadStateText(this IStatable core, TextReader reader)
{
if (core is ITextStatable textCore)
{
textCore.LoadStateText(reader);
}
string hex = reader.ReadLine();
if (hex != null)
{
var state = new byte[hex.Length / 2];
state.ReadFromHexFast(hex);
using var ms = new MemoryStream(state);
using var br = new BinaryReader(ms);
core.LoadStateBinary(br);
}
}
}
} }

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Calculators namespace BizHawk.Emulation.Cores.Calculators
{ {
public partial class TI83 : IStatable public partial class TI83 : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -8,10 +8,8 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
/// CPCHawk: Core Class /// CPCHawk: Core Class
/// * IStatable * /// * IStatable *
/// </summary> /// </summary>
public partial class AmstradCPC : IStatable public partial class AmstradCPC : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -8,7 +8,7 @@ using Newtonsoft.Json.Serialization;
namespace BizHawk.Emulation.Cores.Computers.AppleII namespace BizHawk.Emulation.Cores.Computers.AppleII
{ {
public partial class AppleII : IStatable public partial class AppleII : ITextStatable
{ {
private class CoreConverter : JsonConverter private class CoreConverter : JsonConverter
{ {
@ -32,8 +32,6 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
} }
} }
public bool BinarySaveStatesPreferred => true;
private void SerializeEverything(JsonWriter w) private void SerializeEverything(JsonWriter w)
{ {
// this is much faster than other possibilities for serialization // this is much faster than other possibilities for serialization

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64 namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public sealed partial class C64 : IStatable public sealed partial class C64 : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void LoadStateBinary(BinaryReader br) public void LoadStateBinary(BinaryReader br)
{ {
SyncState(new Serializer(br)); SyncState(new Serializer(br));

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.MSX namespace BizHawk.Emulation.Cores.Computers.MSX
{ {
public partial class MSX : IStatable public partial class MSX : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -8,10 +8,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
/// ZXHawk: Core Class /// ZXHawk: Core Class
/// * IStatable * /// * IStatable *
/// </summary> /// </summary>
public partial class ZXSpectrum : IStatable public partial class ZXSpectrum : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Atari.Atari2600 namespace BizHawk.Emulation.Cores.Atari.Atari2600
{ {
public partial class Atari2600 : IStatable public partial class Atari2600 : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(Serializer.CreateTextWriter(writer)); SyncState(Serializer.CreateTextWriter(writer));

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Atari.A7800Hawk namespace BizHawk.Emulation.Cores.Atari.A7800Hawk
{ {
public partial class A7800Hawk : IStatable public partial class A7800Hawk : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Atari.Lynx namespace BizHawk.Emulation.Cores.Atari.Lynx
{ {
public partial class Lynx : IStatable public partial class Lynx : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
var s = new TextState<TextStateData>(); var s = new TextState<TextStateData>();
@ -21,8 +19,6 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
s.ExtraData.Frame = Frame; s.ExtraData.Frame = Frame;
_ser.Serialize(writer, s); _ser.Serialize(writer, s);
////Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary()));
} }
public void LoadStateText(TextReader reader) public void LoadStateText(TextReader reader)

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.ColecoVision namespace BizHawk.Emulation.Cores.ColecoVision
{ {
public partial class ColecoVision : IStatable public partial class ColecoVision : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.ChannelF namespace BizHawk.Emulation.Cores.Consoles.ChannelF
{ {
public partial class ChannelF : IStatable public partial class ChannelF : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.Vectrex namespace BizHawk.Emulation.Cores.Consoles.Vectrex
{ {
public partial class VectrexHawk : IStatable public partial class VectrexHawk : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Intellivision namespace BizHawk.Emulation.Cores.Intellivision
{ {
public partial class Intellivision : IStatable public partial class Intellivision : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(Serializer.CreateTextWriter(writer)); SyncState(Serializer.CreateTextWriter(writer));

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.O2Hawk namespace BizHawk.Emulation.Cores.Consoles.O2Hawk
{ {
public partial class O2Hawk : IStatable public partial class O2Hawk : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -10,21 +10,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
private byte[] _savebuff = new byte[0]; private byte[] _savebuff = new byte[0];
private byte[] _savebuff2 = new byte[13]; private byte[] _savebuff2 = new byte[13];
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer)
{
var tmp = SaveStateBinary();
BizHawk.Common.BufferExtensions.BufferExtensions.SaveAsHexFast(tmp, writer);
}
public void LoadStateText(TextReader reader)
{
string hex = reader.ReadLine();
byte[] state = new byte[hex.Length / 2];
BizHawk.Common.BufferExtensions.BufferExtensions.ReadFromHexFast(state, hex);
LoadStateBinary(new BinaryReader(new MemoryStream(state)));
}
private void StartSaveStateBinaryInternal() private void StartSaveStateBinaryInternal()
{ {
IntPtr p = IntPtr.Zero; IntPtr p = IntPtr.Zero;

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.GBA namespace BizHawk.Emulation.Cores.Nintendo.GBA
{ {
public partial class VBANext : IStatable public partial class VBANext : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
var s = new TextState<TextStateData>(); var s = new TextState<TextStateData>();
@ -21,8 +19,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
s.ExtraData.Frame = Frame; s.ExtraData.Frame = Frame;
ser.Serialize(writer, s); ser.Serialize(writer, s);
//Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary()));
} }
public void LoadStateText(TextReader reader) public void LoadStateText(TextReader reader)

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.GBHawk namespace BizHawk.Emulation.Cores.Nintendo.GBHawk
{ {
public partial class GBHawk : IStatable public partial class GBHawk : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -1,16 +1,12 @@
using System.IO; using System.IO;
using Newtonsoft.Json;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.GBHawk;
namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
{ {
public partial class GBHawkLink : IStatable public partial class GBHawkLink : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
L.SaveStateText(writer); L.SaveStateText(writer);
@ -50,8 +46,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
return ms.ToArray(); return ms.ToArray();
} }
//private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private void SyncState(Serializer ser) private void SyncState(Serializer ser)
{ {
ser.Sync("Lag", ref _lagcount); ser.Sync("Lag", ref _lagcount);

View File

@ -1,16 +1,11 @@
using System.IO; using System.IO;
using Newtonsoft.Json;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.GBHawk;
namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
{ {
public partial class GBHawkLink3x : IStatable public partial class GBHawkLink3x : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
L.SaveStateText(writer); L.SaveStateText(writer);
@ -54,8 +49,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
return ms.ToArray(); return ms.ToArray();
} }
//private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private void SyncState(Serializer ser) private void SyncState(Serializer ser)
{ {
ser.Sync("Lag", ref _lagcount); ser.Sync("Lag", ref _lagcount);

View File

@ -1,16 +1,12 @@
using System.IO; using System.IO;
using Newtonsoft.Json;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.GBHawk;
namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x
{ {
public partial class GBHawkLink4x : IStatable public partial class GBHawkLink4x : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
A.SaveStateText(writer); A.SaveStateText(writer);

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.Gameboy namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{ {
public partial class Gameboy : IStatable public partial class Gameboy : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
var s = SaveState(); var s = SaveState();

View File

@ -8,8 +8,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
{ {
public partial class GambatteLink : IStatable public partial class GambatteLink : IStatable
{ {
public bool BinarySaveStatesPreferred { get { return true; } }
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
var s = new DGBSerialized var s = new DGBSerialized

View File

@ -1,7 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi; using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi;
@ -9,24 +8,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
{ {
public partial class N64 : IStatable public partial class N64 : IStatable
{ {
public bool BinarySaveStatesPreferred => true;
// these functions are all exact copy paste from gambatte.
// if something's wrong here, it's probably wrong there too
public void SaveStateText(TextWriter writer)
{
var temp = SaveStateBinary();
temp.SaveAsHexFast(writer);
}
public void LoadStateText(TextReader reader)
{
var hex = reader.ReadLine();
var state = new byte[hex.Length / 2];
state.ReadFromHexFast(hex);
LoadStateBinary(new BinaryReader(new MemoryStream(state)));
}
public void SaveStateBinary(BinaryWriter writer) public void SaveStateBinary(BinaryWriter writer)
{ {
byte[] data = SaveStatePrivateBuff; byte[] data = SaveStatePrivateBuff;

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.NES namespace BizHawk.Emulation.Cores.Nintendo.NES
{ {
public partial class NES : IStatable public partial class NES : ITextStatable
{ {
public bool BinarySaveStatesPreferred => false;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(Serializer.CreateTextWriter(writer)); SyncState(Serializer.CreateTextWriter(writer));

View File

@ -1,30 +1,11 @@
using System; using System;
using System.IO; using System.IO;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
{ {
public partial class QuickNES : IStatable public partial class QuickNES : IStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer)
{
CheckDisposed();
var temp = SaveStateBinary();
temp.SaveAsHexFast(writer);
}
public void LoadStateText(TextReader reader)
{
CheckDisposed();
string hex = reader.ReadLine();
byte[] state = new byte[hex.Length / 2];
state.ReadFromHexFast(hex);
LoadStateBinary(new BinaryReader(new MemoryStream(state)));
}
public void SaveStateBinary(BinaryWriter writer) public void SaveStateBinary(BinaryWriter writer)
{ {
CheckDisposed(); CheckDisposed();

View File

@ -1,27 +1,10 @@
using System.IO; using System.IO;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.SNES namespace BizHawk.Emulation.Cores.Nintendo.SNES
{ {
public unsafe partial class LibsnesCore : IStatable public unsafe partial class LibsnesCore : IStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer)
{
var temp = SaveStateBinary();
temp.SaveAsHexFast(writer);
}
public void LoadStateText(TextReader reader)
{
string hex = reader.ReadLine();
byte[] state = new byte[hex.Length / 2];
state.ReadFromHexFast(hex);
LoadStateBinary(new BinaryReader(new MemoryStream(state)));
}
public void SaveStateBinary(BinaryWriter writer) public void SaveStateBinary(BinaryWriter writer)
{ {
Api.SaveStateBinary(writer); Api.SaveStateBinary(writer);

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk
{ {
public partial class SubNESHawk : IStatable public partial class SubNESHawk : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
subnes.SaveStateText(writer); subnes.SaveStateText(writer);
@ -44,8 +42,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk
return ms.ToArray(); return ms.ToArray();
} }
//private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private void SyncState(Serializer ser) private void SyncState(Serializer ser)
{ {
ser.Sync("Lag", ref _lagCount); ser.Sync("Lag", ref _lagCount);

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.PCEngine namespace BizHawk.Emulation.Cores.PCEngine
{ {
public sealed partial class PCEngine : IStatable public sealed partial class PCEngine : ITextStatable
{ {
public bool BinarySaveStatesPreferred => false;
public void SaveStateBinary(BinaryWriter bw) public void SaveStateBinary(BinaryWriter bw)
{ {
SyncState(Serializer.CreateBinaryWriter(bw)); SyncState(Serializer.CreateBinaryWriter(bw));

View File

@ -1,15 +1,12 @@
using System.IO; using System.IO;
using Newtonsoft.Json;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Sega.GGHawkLink namespace BizHawk.Emulation.Cores.Sega.GGHawkLink
{ {
public partial class GGHawkLink : IStatable public partial class GGHawkLink : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
L.SaveStateText(writer); L.SaveStateText(writer);
@ -49,8 +46,6 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink
return ms.ToArray(); return ms.ToArray();
} }
//private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private void SyncState(Serializer ser) private void SyncState(Serializer ser)
{ {
ser.Sync("Lag", ref _lagCount); ser.Sync("Lag", ref _lagCount);

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Sega.MasterSystem namespace BizHawk.Emulation.Cores.Sega.MasterSystem
{ {
public partial class SMS : IStatable public partial class SMS : ITextStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer) public void SaveStateText(TextWriter writer)
{ {
SyncState(new Serializer(writer)); SyncState(new Serializer(writer));

View File

@ -1,28 +1,10 @@
using System.IO; using System.IO;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{ {
public partial class GPGX : IStatable public partial class GPGX : IStatable
{ {
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer)
{
var temp = SaveStateBinary();
temp.SaveAsHexFast(writer);
}
public void LoadStateText(TextReader reader)
{
string hex = reader.ReadLine();
byte[] state = new byte[hex.Length / 2];
state.ReadFromHexFast(hex);
LoadStateBinary(new BinaryReader(new MemoryStream(state)));
}
public void LoadStateBinary(BinaryReader reader) public void LoadStateBinary(BinaryReader reader)
{ {
_elf.LoadStateBinary(reader); _elf.LoadStateBinary(reader);

View File

@ -1072,62 +1072,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
#region Savestates #region Savestates
//THIS IS STILL AWFUL //THIS IS STILL AWFUL
JsonSerializer ser = new JsonSerializer() { Formatting = Formatting.Indented };
class TextStateData
{
public int Frame;
public int LagCount;
public bool IsLagFrame;
public bool CurrentDiscEjected;
public int CurrentDiscIndexMounted;
}
public void SaveStateText(TextWriter writer)
{
var s = new TextState<TextStateData>();
s.Prepare();
var transaction = new OctoshockDll.ShockStateTransaction()
{
transaction = OctoshockDll.eShockStateTransaction.TextSave,
ff = s.GetFunctionPointersSave()
};
int result = OctoshockDll.shock_StateTransaction(psx, ref transaction);
if (result != OctoshockDll.SHOCK_OK)
throw new InvalidOperationException($"{nameof(OctoshockDll.eShockStateTransaction)}.{nameof(OctoshockDll.eShockStateTransaction.TextSave)} returned error!");
s.ExtraData.IsLagFrame = IsLagFrame;
s.ExtraData.LagCount = LagCount;
s.ExtraData.Frame = Frame;
s.ExtraData.CurrentDiscEjected = CurrentTrayOpen;
s.ExtraData.CurrentDiscIndexMounted = CurrentDiscIndexMounted;
ser.Serialize(writer, s);
}
public void LoadStateText(TextReader reader)
{
var s = (TextState<TextStateData>)ser.Deserialize(reader, typeof(TextState<TextStateData>));
s.Prepare();
var transaction = new OctoshockDll.ShockStateTransaction()
{
transaction = OctoshockDll.eShockStateTransaction.TextLoad,
ff = s.GetFunctionPointersLoad()
};
int result = OctoshockDll.shock_StateTransaction(psx, ref transaction);
if (result != OctoshockDll.SHOCK_OK)
throw new InvalidOperationException($"{nameof(OctoshockDll.eShockStateTransaction)}.{nameof(OctoshockDll.eShockStateTransaction.TextLoad)} returned error!");
IsLagFrame = s.ExtraData.IsLagFrame;
LagCount = s.ExtraData.LagCount;
Frame = s.ExtraData.Frame;
CurrentTrayOpen = s.ExtraData.CurrentDiscEjected;
CurrentDiscIndexMounted = s.ExtraData.CurrentDiscIndexMounted;
PokeDisc();
}
byte[] savebuff; byte[] savebuff;
byte[] savebuff2; byte[] savebuff2;
@ -1208,8 +1152,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
return savebuff2; return savebuff2;
} }
public bool BinarySaveStatesPreferred => true;
#endregion #endregion
#region Settings #region Settings

View File

@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
namespace BizHawk.Emulation.Cores.WonderSwan namespace BizHawk.Emulation.Cores.WonderSwan
{ {
partial class WonderSwan: IStatable partial class WonderSwan: ITextStatable
{ {
private void InitIStatable() private void InitIStatable()
{ {
@ -97,7 +97,5 @@ namespace BizHawk.Emulation.Cores.WonderSwan
ms.Close(); ms.Close();
return savebuff2; return savebuff2;
} }
public bool BinarySaveStatesPreferred => true;
} }
} }

View File

@ -4,15 +4,9 @@
//Since it's an IEmulator.. but... I dont know. Yeah, that's probably best //Since it's an IEmulator.. but... I dont know. Yeah, that's probably best
using System; using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using BizHawk.Common;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Libretro namespace BizHawk.Emulation.Cores.Libretro
@ -364,20 +358,6 @@ namespace BizHawk.Emulation.Cores.Libretro
private byte[] savebuff, savebuff2; private byte[] savebuff, savebuff2;
public void SaveStateText(System.IO.TextWriter writer)
{
var temp = SaveStateBinary();
temp.SaveAsHexFast(writer);
}
public void LoadStateText(System.IO.TextReader reader)
{
string hex = reader.ReadLine();
byte[] state = new byte[hex.Length / 2];
state.ReadFromHex(hex);
LoadStateBinary(new BinaryReader(new MemoryStream(state)));
}
public void SaveStateBinary(System.IO.BinaryWriter writer) public void SaveStateBinary(System.IO.BinaryWriter writer)
{ {
api.CMD_UpdateSerializeSize(); api.CMD_UpdateSerializeSize();
@ -426,8 +406,6 @@ namespace BizHawk.Emulation.Cores.Libretro
return savebuff2; return savebuff2;
} }
public bool BinarySaveStatesPreferred { get { return true; } }
#endregion #endregion

View File

@ -1,14 +1,10 @@
using BizHawk.Common; using BizHawk.Common;
using BizHawk.BizInvoke; using BizHawk.BizInvoke;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Waterbox namespace BizHawk.Emulation.Cores.Waterbox
{ {
@ -254,22 +250,6 @@ namespace BizHawk.Emulation.Cores.Waterbox
#region IStatable #region IStatable
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer)
{
var temp = SaveStateBinary();
temp.SaveAsHexFast(writer);
}
public void LoadStateText(TextReader reader)
{
string hex = reader.ReadLine();
byte[] state = new byte[hex.Length / 2];
state.ReadFromHexFast(hex);
LoadStateBinary(new BinaryReader(new MemoryStream(state)));
}
public void LoadStateBinary(BinaryReader reader) public void LoadStateBinary(BinaryReader reader)
{ {
_exe.LoadStateBinary(reader); _exe.LoadStateBinary(reader);