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 BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common
@ -16,8 +17,7 @@ namespace BizHawk.Client.Common
// 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
using var bs = new BinaryStateSaver(filename);
if (Global.Config.SaveStateType == SaveStateTypeE.Text
|| (Global.Config.SaveStateType == SaveStateTypeE.Default && !core.BinarySaveStatesPreferred))
if (Global.Config.SaveStateType == SaveStateTypeE.Text)
{
// text savestate format
using (new SimpleTime("Save Core"))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,5 @@
using System.IO;
using BizHawk.Common.BufferExtensions;
namespace BizHawk.Emulation.Common
{
@ -19,18 +20,54 @@ namespace BizHawk.Emulation.Common
/// </summary>
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>
/// save state binary to a byte buffer
/// </summary>
/// <returns>you may NOT modify this. if you call SaveStateBinary() again with the same core, the old data MAY be overwritten.</returns>
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
{
public partial class TI83 : IStatable
public partial class TI83 : ITextStatable
{
public bool BinarySaveStatesPreferred => true;
public void SaveStateText(TextWriter writer)
{
SyncState(new Serializer(writer));

View File

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

View File

@ -8,7 +8,7 @@ using Newtonsoft.Json.Serialization;
namespace BizHawk.Emulation.Cores.Computers.AppleII
{
public partial class AppleII : IStatable
public partial class AppleII : ITextStatable
{
private class CoreConverter : JsonConverter
{
@ -32,8 +32,6 @@ namespace BizHawk.Emulation.Cores.Computers.AppleII
}
}
public bool BinarySaveStatesPreferred => true;
private void SerializeEverything(JsonWriter w)
{
// 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
{
public sealed partial class C64 : IStatable
public sealed partial class C64 : ITextStatable
{
public bool BinarySaveStatesPreferred => true;
public void LoadStateBinary(BinaryReader br)
{
SyncState(new Serializer(br));

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(new Serializer(writer));

View File

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

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(Serializer.CreateTextWriter(writer));

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(new Serializer(writer));

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
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)
{
var s = new TextState<TextStateData>();
@ -21,8 +19,6 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
s.ExtraData.Frame = Frame;
_ser.Serialize(writer, s);
////Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary()));
}
public void LoadStateText(TextReader reader)

View File

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

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(new Serializer(writer));

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(new Serializer(writer));

View File

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

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(new Serializer(writer));

View File

@ -10,21 +10,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
private byte[] _savebuff = new byte[0];
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()
{
IntPtr p = IntPtr.Zero;

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
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)
{
var s = new TextState<TextStateData>();
@ -21,8 +19,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
s.ExtraData.Frame = Frame;
ser.Serialize(writer, s);
//Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary()));
}
public void LoadStateText(TextReader reader)

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(new Serializer(writer));

View File

@ -1,16 +1,12 @@
using System.IO;
using Newtonsoft.Json;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.GBHawk;
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)
{
L.SaveStateText(writer);
@ -50,8 +46,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink
return ms.ToArray();
}
//private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private void SyncState(Serializer ser)
{
ser.Sync("Lag", ref _lagcount);

View File

@ -1,16 +1,11 @@
using System.IO;
using Newtonsoft.Json;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.GBHawk;
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)
{
L.SaveStateText(writer);
@ -54,8 +49,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x
return ms.ToArray();
}
//private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private void SyncState(Serializer ser)
{
ser.Sync("Lag", ref _lagcount);

View File

@ -1,16 +1,12 @@
using System.IO;
using Newtonsoft.Json;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.GBHawk;
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)
{
A.SaveStateText(writer);

View File

@ -6,10 +6,8 @@ using BizHawk.Emulation.Common;
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)
{
var s = SaveState();

View File

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

View File

@ -1,7 +1,6 @@
using System;
using System.IO;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.N64.NativeApi;
@ -9,24 +8,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
{
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)
{
byte[] data = SaveStatePrivateBuff;

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(Serializer.CreateTextWriter(writer));

View File

@ -1,30 +1,11 @@
using System;
using System.IO;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
{
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)
{
CheckDisposed();

View File

@ -1,27 +1,10 @@
using System.IO;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.SNES
{
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)
{
Api.SaveStateBinary(writer);

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
subnes.SaveStateText(writer);
@ -44,8 +42,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SubNESHawk
return ms.ToArray();
}
//private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private void SyncState(Serializer ser)
{
ser.Sync("Lag", ref _lagCount);

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(Serializer.CreateBinaryWriter(bw));

View File

@ -1,15 +1,12 @@
using System.IO;
using Newtonsoft.Json;
using BizHawk.Common;
using BizHawk.Emulation.Common;
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)
{
L.SaveStateText(writer);
@ -49,8 +46,6 @@ namespace BizHawk.Emulation.Cores.Sega.GGHawkLink
return ms.ToArray();
}
//private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
private void SyncState(Serializer ser)
{
ser.Sync("Lag", ref _lagCount);

View File

@ -5,10 +5,8 @@ using BizHawk.Emulation.Common;
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)
{
SyncState(new Serializer(writer));

View File

@ -1,28 +1,10 @@
using System.IO;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{
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)
{
_elf.LoadStateBinary(reader);

View File

@ -1072,62 +1072,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
#region Savestates
//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[] savebuff2;
@ -1208,8 +1152,6 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
return savebuff2;
}
public bool BinarySaveStatesPreferred => true;
#endregion
#region Settings

View File

@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
namespace BizHawk.Emulation.Cores.WonderSwan
{
partial class WonderSwan: IStatable
partial class WonderSwan: ITextStatable
{
private void InitIStatable()
{
@ -97,7 +97,5 @@ namespace BizHawk.Emulation.Cores.WonderSwan
ms.Close();
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
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using BizHawk.Common;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Libretro
@ -364,20 +358,6 @@ namespace BizHawk.Emulation.Cores.Libretro
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)
{
api.CMD_UpdateSerializeSize();
@ -426,8 +406,6 @@ namespace BizHawk.Emulation.Cores.Libretro
return savebuff2;
}
public bool BinarySaveStatesPreferred { get { return true; } }
#endregion

View File

@ -1,14 +1,10 @@
using BizHawk.Common;
using BizHawk.BizInvoke;
using BizHawk.Common.BufferExtensions;
using BizHawk.Emulation.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace BizHawk.Emulation.Cores.Waterbox
{
@ -254,22 +250,6 @@ namespace BizHawk.Emulation.Cores.Waterbox
#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)
{
_exe.LoadStateBinary(reader);