snes9x: savestates

This commit is contained in:
nattthebear 2017-05-28 06:39:11 -04:00
parent ef8264a8b0
commit 0cc1abd51b
4 changed files with 66 additions and 12 deletions

View File

@ -37,6 +37,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
[BizImport(CC)]
public abstract void biz_soft_reset();
[BizImport(CC)]
public abstract void biz_hard_reset();
[BizImport(CC)]
public abstract void biz_set_port_devices(uint left, uint right);
[BizImport(CC)]
public abstract bool biz_load_rom(byte[] data, int size);
@ -48,5 +50,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
public abstract bool biz_is_ntsc();
[BizImport(CC)]
public abstract void biz_get_memory_area(int which, [In, Out] memory_area mem);
[BizImport(CC)]
public abstract void biz_post_load_state();
}
}

View File

@ -3,12 +3,14 @@ using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Waterbox;
using BizHawk.Common.BizInvoke;
using System.Runtime.InteropServices;
using System.IO;
using BizHawk.Common.BufferExtensions;
namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
{
[CoreAttributes("Snes9x", "FIXME", true, false, "5e0319ab3ef9611250efb18255186d0dc0d7e125", "https://github.com/snes9xgit/snes9x", false)]
[ServiceNotApplicable(typeof(IDriveLight))]
public class Snes9x : IEmulator, IVideoProvider, ISoundProvider
public class Snes9x : IEmulator, IVideoProvider, ISoundProvider, IStatable
{
private LibSnes9x _core;
private PeRunner _exe;
@ -40,6 +42,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
{
throw new InvalidOperationException("LoadRom() failed");
}
_exe.Seal();
if (_core.biz_is_ntsc())
{
@ -54,7 +57,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
VsyncDenominator = 425568;
}
_exe.Seal();
}
catch
{
@ -203,6 +205,62 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES9X
throw new InvalidOperationException("Async mode is not supported.");
}
// TODO
public int LagCount { get; set; }
public bool IsLagFrame { get; set; }
public bool BinarySaveStatesPreferred
{
get { return true; }
}
public void SaveStateText(TextWriter writer)
{
var temp = SaveStateBinary();
temp.SaveAsHexFast(writer);
// write extra copy of stuff we don't use
writer.WriteLine("Frame {0}", Frame);
}
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);
// other variables
Frame = reader.ReadInt32();
LagCount = reader.ReadInt32();
IsLagFrame = reader.ReadBoolean();
// any managed pointers that we sent to the core need to be resent now!
_core.biz_post_load_state();
}
public void SaveStateBinary(BinaryWriter writer)
{
_exe.SaveStateBinary(writer);
// other variables
writer.Write(Frame);
writer.Write(LagCount);
writer.Write(IsLagFrame);
}
public byte[] SaveStateBinary()
{
var ms = new MemoryStream();
var bw = new BinaryWriter(ms);
SaveStateBinary(bw);
bw.Flush();
ms.Close();
return ms.ToArray();
}
#endregion
}
}

View File

@ -53,12 +53,6 @@ namespace BizHawk.Emulation.Cores.Waterbox
/// </summary>
private class Psx
{
private static IntPtr BEXLAND;
static Psx()
{
BEXLAND = Marshal.AllocHGlobal(16);
}
private readonly PeRunner _parent;
private readonly List<Delegate> _traps = new List<Delegate>();
@ -95,12 +89,10 @@ namespace BizHawk.Emulation.Cores.Waterbox
Action del = () =>
{
Console.WriteLine(s);
System.Diagnostics.Debugger.Break(); // do not remove this until all unwindings are fixed
throw new InvalidOperationException(s);
};
_traps.Add(del);
ptr = Marshal.GetFunctionPointerForDelegate(del);
//ptr = BEXLAND;
}
return ptr;
}).ToArray();
@ -353,7 +345,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
//if (_firstTime)
//{
//_firstTime = false;
throw new InvalidOperationException("This shouldn' be called");
throw new InvalidOperationException("This shouldn't be called");
//}
//else
//{

@ -1 +1 @@
Subproject commit ba009bc83960ee39f9eb24ae1724a67d9b87f51e
Subproject commit f5273208bb592c29a9f41f4b251957966f640cac