Lynx - break stuff up into separate files
This commit is contained in:
parent
76969200a3
commit
dfe7b23fe6
|
@ -258,6 +258,21 @@
|
|||
</Compile>
|
||||
<Compile Include="Consoles\Atari\lynx\LibLynx.cs" />
|
||||
<Compile Include="Consoles\Atari\lynx\Lynx.cs" />
|
||||
<Compile Include="Consoles\Atari\lynx\Lynx.IInputPollable.cs">
|
||||
<DependentUpon>Lynx.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Atari\lynx\Lynx.IMemoryDomains.cs">
|
||||
<DependentUpon>Lynx.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Atari\lynx\Lynx.ISaveRam.cs">
|
||||
<DependentUpon>Lynx.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Atari\lynx\Lynx.IStatable.cs">
|
||||
<DependentUpon>Lynx.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Atari\lynx\Lynx.IVideoProvider.cs">
|
||||
<DependentUpon>Lynx.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Coleco\ColecoVision.cs" />
|
||||
<Compile Include="Consoles\Coleco\ColecoVision.IDebuggable.cs">
|
||||
<DependentUpon>ColecoVision.cs</DependentUpon>
|
||||
|
@ -580,10 +595,10 @@
|
|||
<Compile Include="Consoles\WonderSwan\WonderSwan.IMemoryDomains.cs">
|
||||
<DependentUpon>WonderSwan.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\WonderSwan\WonderSwan.ISaveRam.cs">
|
||||
<Compile Include="Consoles\WonderSwan\WonderSwan.ISaveRam.cs">
|
||||
<DependentUpon>WonderSwan.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\WonderSwan\WonderSwan.ISettable.cs">
|
||||
<Compile Include="Consoles\WonderSwan\WonderSwan.ISettable.cs">
|
||||
<DependentUpon>WonderSwan.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\WonderSwan\WonderSwan.IStatable.cs">
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Lynx
|
||||
{
|
||||
public partial class Lynx : IInputPollable
|
||||
{
|
||||
public int LagCount { get; set; }
|
||||
|
||||
public bool IsLagFrame { get; private set; }
|
||||
|
||||
// TODO
|
||||
public IInputCallbackSystem InputCallbacks
|
||||
{
|
||||
[FeatureNotImplemented]
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Lynx
|
||||
{
|
||||
public partial class Lynx
|
||||
{
|
||||
private void SetupMemoryDomains()
|
||||
{
|
||||
var mms = new List<MemoryDomain>();
|
||||
mms.Add(MemoryDomain.FromIntPtr("RAM", 65536, MemoryDomain.Endian.Little, LibLynx.GetRamPointer(Core), true));
|
||||
|
||||
IntPtr p;
|
||||
int s;
|
||||
if (LibLynx.GetSaveRamPtr(Core, out s, out p))
|
||||
{
|
||||
mms.Add(MemoryDomain.FromIntPtr("Save RAM", s, MemoryDomain.Endian.Little, p, true));
|
||||
}
|
||||
|
||||
IntPtr p0, p1;
|
||||
int s0, s1;
|
||||
LibLynx.GetReadOnlyCartPtrs(Core, out s0, out p0, out s1, out p1);
|
||||
if (s0 > 0 && p0 != IntPtr.Zero)
|
||||
mms.Add(MemoryDomain.FromIntPtr("Cart A", s0, MemoryDomain.Endian.Little, p0, false));
|
||||
if (s1 > 0 && p1 != IntPtr.Zero)
|
||||
mms.Add(MemoryDomain.FromIntPtr("Cart B", s1, MemoryDomain.Endian.Little, p1, false));
|
||||
|
||||
_memoryDomains = new MemoryDomainList(mms, 0);
|
||||
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(_memoryDomains);
|
||||
}
|
||||
|
||||
private IMemoryDomains _memoryDomains;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Lynx
|
||||
{
|
||||
public partial class Lynx : ISaveRam
|
||||
{
|
||||
public byte[] CloneSaveRam()
|
||||
{
|
||||
int size;
|
||||
IntPtr data;
|
||||
if (!LibLynx.GetSaveRamPtr(Core, out size, out data))
|
||||
return null;
|
||||
byte[] ret = new byte[size];
|
||||
Marshal.Copy(data, ret, 0, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void StoreSaveRam(byte[] srcdata)
|
||||
{
|
||||
int size;
|
||||
IntPtr data;
|
||||
if (!LibLynx.GetSaveRamPtr(Core, out size, out data))
|
||||
throw new InvalidOperationException();
|
||||
if (size != srcdata.Length)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
Marshal.Copy(srcdata, 0, data, size);
|
||||
}
|
||||
|
||||
public bool SaveRamModified
|
||||
{
|
||||
get
|
||||
{
|
||||
int unused;
|
||||
IntPtr unused2;
|
||||
return LibLynx.GetSaveRamPtr(Core, out unused, out unused2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Lynx
|
||||
{
|
||||
public partial class Lynx : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
var s = new TextState<TextStateData>();
|
||||
s.Prepare();
|
||||
var ff = s.GetFunctionPointersSave();
|
||||
LibLynx.TxtStateSave(Core, ref ff);
|
||||
s.ExtraData.IsLagFrame = IsLagFrame;
|
||||
s.ExtraData.LagCount = LagCount;
|
||||
s.ExtraData.Frame = Frame;
|
||||
|
||||
ser.Serialize(writer, s);
|
||||
// write extra copy of stuff we don't use
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("Frame {0}", Frame);
|
||||
|
||||
//Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary()));
|
||||
}
|
||||
|
||||
public void LoadStateText(TextReader reader)
|
||||
{
|
||||
var s = (TextState<TextStateData>)ser.Deserialize(reader, typeof(TextState<TextStateData>));
|
||||
s.Prepare();
|
||||
var ff = s.GetFunctionPointersLoad();
|
||||
LibLynx.TxtStateLoad(Core, ref ff);
|
||||
IsLagFrame = s.ExtraData.IsLagFrame;
|
||||
LagCount = s.ExtraData.LagCount;
|
||||
Frame = s.ExtraData.Frame;
|
||||
}
|
||||
|
||||
public void SaveStateBinary(BinaryWriter writer)
|
||||
{
|
||||
if (!LibLynx.BinStateSave(Core, savebuff, savebuff.Length))
|
||||
{
|
||||
throw new InvalidOperationException("Core's BinStateSave() returned false!");
|
||||
}
|
||||
|
||||
writer.Write(savebuff.Length);
|
||||
writer.Write(savebuff);
|
||||
|
||||
// other variables
|
||||
writer.Write(IsLagFrame);
|
||||
writer.Write(LagCount);
|
||||
writer.Write(Frame);
|
||||
}
|
||||
|
||||
public void LoadStateBinary(BinaryReader reader)
|
||||
{
|
||||
int length = reader.ReadInt32();
|
||||
if (length != savebuff.Length)
|
||||
{
|
||||
throw new InvalidOperationException("Save buffer size mismatch!");
|
||||
}
|
||||
|
||||
reader.Read(savebuff, 0, length);
|
||||
if (!LibLynx.BinStateLoad(Core, savebuff, savebuff.Length))
|
||||
{
|
||||
throw new InvalidOperationException("Core's BinStateLoad() returned false!");
|
||||
}
|
||||
|
||||
// other variables
|
||||
IsLagFrame = reader.ReadBoolean();
|
||||
LagCount = reader.ReadInt32();
|
||||
Frame = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream(savebuff2, true);
|
||||
var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
if (ms.Position != savebuff2.Length)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
ms.Close();
|
||||
return savebuff2;
|
||||
}
|
||||
|
||||
private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
|
||||
private byte[] savebuff;
|
||||
private byte[] savebuff2;
|
||||
|
||||
private class TextStateData
|
||||
{
|
||||
public int Frame;
|
||||
public int LagCount;
|
||||
public bool IsLagFrame;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Atari.Lynx
|
||||
{
|
||||
public partial class Lynx : IVideoProvider
|
||||
{
|
||||
private const int WIDTH = 160;
|
||||
private const int HEIGHT = 102;
|
||||
|
||||
private int[] videobuff = new int[WIDTH * HEIGHT];
|
||||
|
||||
public int[] GetVideoBuffer()
|
||||
{
|
||||
return videobuff;
|
||||
}
|
||||
|
||||
public int VirtualWidth
|
||||
{
|
||||
get { return BufferWidth; }
|
||||
}
|
||||
|
||||
public int VirtualHeight
|
||||
{
|
||||
get { return BufferHeight; }
|
||||
}
|
||||
|
||||
public int BufferWidth { get; private set; }
|
||||
|
||||
public int BufferHeight { get; private set; }
|
||||
|
||||
public int BackgroundColor
|
||||
{
|
||||
get { return unchecked((int)0xff000000); }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
|
|||
{
|
||||
[CoreAttributes("Handy", "K. Wilkins", true, true, "mednafen 0-9-34-1", "http://mednafen.sourceforge.net/")]
|
||||
[ServiceNotApplicable(typeof(ISettable<,>), typeof(IDriveLight))]
|
||||
public class Lynx : IEmulator, IVideoProvider, ISyncSoundProvider, ISaveRam, IStatable, IInputPollable
|
||||
public partial class Lynx : IEmulator, IVideoProvider, ISyncSoundProvider, ISaveRam, IStatable, IInputPollable
|
||||
{
|
||||
IntPtr Core;
|
||||
|
||||
|
@ -139,15 +139,6 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
|
|||
}
|
||||
|
||||
public int Frame { get; private set; }
|
||||
public int LagCount { get; set; }
|
||||
public bool IsLagFrame { get; private set; }
|
||||
|
||||
// TODO
|
||||
public IInputCallbackSystem InputCallbacks
|
||||
{
|
||||
[FeatureNotImplemented]
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public string SystemId { get { return "Lynx"; } }
|
||||
|
||||
|
@ -202,147 +193,6 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
|
|||
|
||||
#endregion
|
||||
|
||||
#region savestates
|
||||
|
||||
JsonSerializer ser = new JsonSerializer() { Formatting = Formatting.Indented };
|
||||
byte[] savebuff;
|
||||
byte[] savebuff2;
|
||||
|
||||
class TextStateData
|
||||
{
|
||||
public int Frame;
|
||||
public int LagCount;
|
||||
public bool IsLagFrame;
|
||||
}
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
var s = new TextState<TextStateData>();
|
||||
s.Prepare();
|
||||
var ff = s.GetFunctionPointersSave();
|
||||
LibLynx.TxtStateSave(Core, ref ff);
|
||||
s.ExtraData.IsLagFrame = IsLagFrame;
|
||||
s.ExtraData.LagCount = LagCount;
|
||||
s.ExtraData.Frame = Frame;
|
||||
|
||||
ser.Serialize(writer, s);
|
||||
// write extra copy of stuff we don't use
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("Frame {0}", Frame);
|
||||
|
||||
//Console.WriteLine(BizHawk.Common.BufferExtensions.BufferExtensions.HashSHA1(SaveStateBinary()));
|
||||
}
|
||||
|
||||
public void LoadStateText(TextReader reader)
|
||||
{
|
||||
var s = (TextState<TextStateData>)ser.Deserialize(reader, typeof(TextState<TextStateData>));
|
||||
s.Prepare();
|
||||
var ff = s.GetFunctionPointersLoad();
|
||||
LibLynx.TxtStateLoad(Core, ref ff);
|
||||
IsLagFrame = s.ExtraData.IsLagFrame;
|
||||
LagCount = s.ExtraData.LagCount;
|
||||
Frame = s.ExtraData.Frame;
|
||||
}
|
||||
|
||||
public void SaveStateBinary(BinaryWriter writer)
|
||||
{
|
||||
if (!LibLynx.BinStateSave(Core, savebuff, savebuff.Length))
|
||||
throw new InvalidOperationException("Core's BinStateSave() returned false!");
|
||||
writer.Write(savebuff.Length);
|
||||
writer.Write(savebuff);
|
||||
|
||||
// other variables
|
||||
writer.Write(IsLagFrame);
|
||||
writer.Write(LagCount);
|
||||
writer.Write(Frame);
|
||||
}
|
||||
|
||||
public void LoadStateBinary(BinaryReader reader)
|
||||
{
|
||||
int length = reader.ReadInt32();
|
||||
if (length != savebuff.Length)
|
||||
throw new InvalidOperationException("Save buffer size mismatch!");
|
||||
reader.Read(savebuff, 0, length);
|
||||
if (!LibLynx.BinStateLoad(Core, savebuff, savebuff.Length))
|
||||
throw new InvalidOperationException("Core's BinStateLoad() returned false!");
|
||||
|
||||
// other variables
|
||||
IsLagFrame = reader.ReadBoolean();
|
||||
LagCount = reader.ReadInt32();
|
||||
Frame = reader.ReadInt32();
|
||||
}
|
||||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream(savebuff2, true);
|
||||
var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
if (ms.Position != savebuff2.Length)
|
||||
throw new InvalidOperationException();
|
||||
ms.Close();
|
||||
return savebuff2;
|
||||
}
|
||||
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region saveram
|
||||
|
||||
public byte[] CloneSaveRam()
|
||||
{
|
||||
int size;
|
||||
IntPtr data;
|
||||
if (!LibLynx.GetSaveRamPtr(Core, out size, out data))
|
||||
return null;
|
||||
byte[] ret = new byte[size];
|
||||
Marshal.Copy(data, ret, 0, size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void StoreSaveRam(byte[] srcdata)
|
||||
{
|
||||
int size;
|
||||
IntPtr data;
|
||||
if (!LibLynx.GetSaveRamPtr(Core, out size, out data))
|
||||
throw new InvalidOperationException();
|
||||
if (size != srcdata.Length)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
Marshal.Copy(srcdata, 0, data, size);
|
||||
}
|
||||
|
||||
public bool SaveRamModified
|
||||
{
|
||||
get
|
||||
{
|
||||
int unused;
|
||||
IntPtr unused2;
|
||||
return LibLynx.GetSaveRamPtr(Core, out unused, out unused2);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VideoProvider
|
||||
|
||||
const int WIDTH = 160;
|
||||
const int HEIGHT = 102;
|
||||
|
||||
int[] videobuff = new int[WIDTH * HEIGHT];
|
||||
|
||||
public int[] GetVideoBuffer() { return videobuff; }
|
||||
public int VirtualWidth { get { return BufferWidth; } }
|
||||
public int VirtualHeight { get { return BufferHeight; } }
|
||||
public int BufferWidth { get; private set; }
|
||||
public int BufferHeight { get; private set; }
|
||||
public int BackgroundColor { get { return unchecked((int)0xff000000); } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoundProvider
|
||||
|
||||
short[] soundbuff = new short[2048];
|
||||
|
@ -364,33 +214,5 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MemoryDomains
|
||||
|
||||
private void SetupMemoryDomains()
|
||||
{
|
||||
var mms = new List<MemoryDomain>();
|
||||
mms.Add(MemoryDomain.FromIntPtr("RAM", 65536, MemoryDomain.Endian.Little, LibLynx.GetRamPointer(Core), true));
|
||||
|
||||
IntPtr p;
|
||||
int s;
|
||||
if (LibLynx.GetSaveRamPtr(Core, out s, out p))
|
||||
mms.Add(MemoryDomain.FromIntPtr("Save RAM", s, MemoryDomain.Endian.Little, p, true));
|
||||
|
||||
IntPtr p0, p1;
|
||||
int s0, s1;
|
||||
LibLynx.GetReadOnlyCartPtrs(Core, out s0, out p0, out s1, out p1);
|
||||
if (s0 > 0 && p0 != IntPtr.Zero)
|
||||
mms.Add(MemoryDomain.FromIntPtr("Cart A", s0, MemoryDomain.Endian.Little, p0, false));
|
||||
if (s1 > 0 && p1 != IntPtr.Zero)
|
||||
mms.Add(MemoryDomain.FromIntPtr("Cart B", s1, MemoryDomain.Endian.Little, p1, false));
|
||||
|
||||
_memoryDomains = new MemoryDomainList(mms, 0);
|
||||
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(_memoryDomains);
|
||||
}
|
||||
|
||||
private IMemoryDomains _memoryDomains;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue