[NES] rewind for the masses
This commit is contained in:
parent
aded25da64
commit
2fe2aae243
|
@ -152,6 +152,22 @@ namespace BizHawk.Emulation.CPUs.M6502
|
|||
}
|
||||
}
|
||||
|
||||
void SyncStateBinary(BinarySerializer ser)
|
||||
{
|
||||
ser.Sync(ref A);
|
||||
ser.Sync(ref X);
|
||||
ser.Sync(ref Y);
|
||||
ser.Sync(ref P);
|
||||
ser.Sync(ref PC);
|
||||
ser.Sync(ref S);
|
||||
ser.Sync(ref NMI);
|
||||
ser.Sync(ref IRQ);
|
||||
ser.Sync(ref TotalExecutedCycles);
|
||||
ser.Sync(ref PendingCycles);
|
||||
}
|
||||
public void SaveStateBinary(BinaryWriter writer) { SyncStateBinary(BinarySerializer.CreateWriter(writer)); }
|
||||
public void LoadStateBinary(BinaryReader reader) { SyncStateBinary(BinarySerializer.CreateReader(reader)); }
|
||||
|
||||
// ==== End State ====
|
||||
|
||||
/// <summary>Carry Flag</summary>
|
||||
|
|
|
@ -513,12 +513,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
public void SaveStateBinary(BinaryWriter bw)
|
||||
{
|
||||
using (var sw = new StringWriter())
|
||||
{
|
||||
cpu.SaveStateText(sw);
|
||||
sw.Flush();
|
||||
Util.WriteByteBuffer(bw, System.Text.Encoding.ASCII.GetBytes(sw.ToString()));
|
||||
}
|
||||
cpu.SaveStateBinary(bw);
|
||||
Util.WriteByteBuffer(bw, ram);
|
||||
Util.WriteByteBuffer(bw, CIRAM);
|
||||
bw.Write(cpu_accumulate);
|
||||
|
@ -529,8 +524,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
|
||||
public void LoadStateBinary(BinaryReader br)
|
||||
{
|
||||
using (var sr = new StringReader(System.Text.Encoding.ASCII.GetString(Util.ReadByteBuffer(br, false))))
|
||||
cpu.LoadStateText(sr);
|
||||
cpu.LoadStateBinary(br);
|
||||
ram = Util.ReadByteBuffer(br, false);
|
||||
CIRAM = Util.ReadByteBuffer(br, false);
|
||||
cpu_accumulate = br.ReadInt32();
|
||||
|
|
|
@ -515,6 +515,74 @@ namespace BizHawk
|
|||
|
||||
}
|
||||
|
||||
public class BinarySerializer
|
||||
{
|
||||
BinaryReader br;
|
||||
BinaryWriter bw;
|
||||
public BinarySerializer() { }
|
||||
public BinarySerializer(BinaryWriter _bw) { StartWrite(_bw); }
|
||||
public BinarySerializer(BinaryReader _br) { StartRead(_br); }
|
||||
public void StartWrite(BinaryWriter _bw) { this.bw = _bw; }
|
||||
public void StartRead(BinaryReader _br) { this.br = _br; }
|
||||
public static BinarySerializer CreateWriter(BinaryWriter _bw) { return new BinarySerializer(_bw); }
|
||||
public static BinarySerializer CreateReader(BinaryReader _br) { return new BinarySerializer(_br); }
|
||||
|
||||
bool IsReader { get { return br != null; } }
|
||||
|
||||
public void Sync(ref byte val)
|
||||
{
|
||||
if (IsReader) Read(ref val);
|
||||
else Write(ref val);
|
||||
}
|
||||
public void Sync(ref ushort val)
|
||||
{
|
||||
if (IsReader) Read(ref val);
|
||||
else Write(ref val);
|
||||
}
|
||||
public void Sync(ref uint val)
|
||||
{
|
||||
if (IsReader) Read(ref val);
|
||||
else Write(ref val);
|
||||
}
|
||||
public void Sync(ref sbyte val)
|
||||
{
|
||||
if (IsReader) Read(ref val);
|
||||
else Write(ref val);
|
||||
}
|
||||
public void Sync(ref short val)
|
||||
{
|
||||
if (IsReader) Read(ref val);
|
||||
else Write(ref val);
|
||||
}
|
||||
public void Sync(ref int val)
|
||||
{
|
||||
if (IsReader) Read(ref val);
|
||||
else Write(ref val);
|
||||
}
|
||||
public void Sync(ref bool val)
|
||||
{
|
||||
if (IsReader) Read(ref val);
|
||||
else Write(ref val);
|
||||
}
|
||||
|
||||
|
||||
void Read(ref byte val) { val = br.ReadByte(); }
|
||||
void Write(ref byte val) { bw.Write(val); }
|
||||
void Read(ref ushort val) { val = br.ReadUInt16(); }
|
||||
void Write(ref ushort val) { bw.Write(val); }
|
||||
void Read(ref uint val) { val = br.ReadUInt32(); }
|
||||
void Write(ref uint val) { bw.Write(val); }
|
||||
void Read(ref sbyte val) { val = br.ReadSByte(); }
|
||||
void Write(ref sbyte val) { bw.Write(val); }
|
||||
void Read(ref short val) { val = br.ReadInt16(); }
|
||||
void Write(ref short val) { bw.Write(val); }
|
||||
void Read(ref int val) { val = br.ReadInt32(); }
|
||||
void Write(ref int val) { bw.Write(val); }
|
||||
|
||||
void Read(ref bool val) { val = br.ReadBoolean(); }
|
||||
void Write(ref bool val) { bw.Write(val); }
|
||||
}
|
||||
|
||||
|
||||
public static class BITREV
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue