VBANext - separate into separate files
This commit is contained in:
parent
c23e60ac62
commit
ede452700c
|
@ -352,21 +352,42 @@
|
|||
<Compile Include="Consoles\Nintendo\GBA\LibVBANext.cs" />
|
||||
<Compile Include="Consoles\Nintendo\GBA\Meteor.cs" />
|
||||
<Compile Include="Consoles\Nintendo\GBA\Meteor.IGBAGPUViewable.cs">
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\Meteor.IMemoryDomains.cs">
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\Meteor.ISaveRam.cs">
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\Meteor.IStatable.cs">
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\Meteor.IVideoProvider.cs">
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
<DependentUpon>Meteor.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBANext.cs" />
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBANext.IDebuggable.cs">
|
||||
<DependentUpon>VBANext.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBANext.IGBAGPUViewable.cs">
|
||||
<DependentUpon>VBANext.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBANext.IMemoryDomains.cs">
|
||||
<DependentUpon>VBANext.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBANext.ISaveRam.cs">
|
||||
<DependentUpon>VBANext.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBANext.ISettings.cs">
|
||||
<DependentUpon>VBANext.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBANext.IStatable.cs">
|
||||
<DependentUpon>VBANext.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBANext.IVideoProvider.cs">
|
||||
<DependentUpon>VBANext.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Consoles\Nintendo\GBA\VBARegisterHelper.cs" />
|
||||
<Compile Include="Consoles\Nintendo\N64\N64.IDebuggable.cs">
|
||||
<DependentUpon>N64.cs</DependentUpon>
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
public partial class VBANext : IDebuggable
|
||||
{
|
||||
public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
|
||||
{
|
||||
return regs.GetAllRegisters();
|
||||
}
|
||||
|
||||
public void SetCpuRegister(string register, int value)
|
||||
{
|
||||
regs.SetRegister(register, value);
|
||||
}
|
||||
|
||||
|
||||
public bool CanStep(StepType type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private readonly MemoryCallbackSystem _memorycallbacks = new MemoryCallbackSystem();
|
||||
public IMemoryCallbackSystem MemoryCallbacks { get { return _memorycallbacks; } }
|
||||
|
||||
[FeatureNotImplemented]
|
||||
public void Step(StepType type) { throw new NotImplementedException(); }
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
public partial class VBANext : IGBAGPUViewable
|
||||
{
|
||||
public GBAGPUMemoryAreas GetMemoryAreas()
|
||||
{
|
||||
var s = new LibVBANext.MemoryAreas();
|
||||
LibVBANext.GetMemoryAreas(Core, s);
|
||||
return new GBAGPUMemoryAreas
|
||||
{
|
||||
mmio = s.mmio,
|
||||
oam = s.oam,
|
||||
palram = s.palram,
|
||||
vram = s.vram
|
||||
};
|
||||
}
|
||||
|
||||
public void SetScanlineCallback(Action callback, int scanline)
|
||||
{
|
||||
if (scanline < 0 || scanline > 227)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Scanline must be in [0, 227]!");
|
||||
}
|
||||
if (callback == null)
|
||||
{
|
||||
scanlinecb = null;
|
||||
LibVBANext.SetScanlineCallback(Core, scanlinecb, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
scanlinecb = new LibVBANext.StandardCallback(callback);
|
||||
LibVBANext.SetScanlineCallback(Core, scanlinecb, scanline);
|
||||
}
|
||||
}
|
||||
|
||||
private LibVBANext.StandardCallback scanlinecb;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
public partial class VBANext
|
||||
{
|
||||
private IMemoryDomains _memoryDomains;
|
||||
|
||||
private void InitMemoryDomains()
|
||||
{
|
||||
var mm = new List<MemoryDomain>();
|
||||
var s = new LibVBANext.MemoryAreas();
|
||||
var l = MemoryDomain.Endian.Little;
|
||||
LibVBANext.GetMemoryAreas(Core, s);
|
||||
mm.Add(MemoryDomain.FromIntPtr("IWRAM", 32 * 1024, l, s.iwram));
|
||||
mm.Add(MemoryDomain.FromIntPtr("EWRAM", 256 * 1024, l, s.ewram));
|
||||
mm.Add(MemoryDomain.FromIntPtr("BIOS", 16 * 1024, l, s.bios, false));
|
||||
mm.Add(MemoryDomain.FromIntPtr("PALRAM", 1024, l, s.palram, false));
|
||||
mm.Add(MemoryDomain.FromIntPtr("VRAM", 96 * 1024, l, s.vram));
|
||||
mm.Add(MemoryDomain.FromIntPtr("OAM", 1024, l, s.oam));
|
||||
mm.Add(MemoryDomain.FromIntPtr("ROM", 32 * 1024 * 1024, l, s.rom));
|
||||
|
||||
mm.Add(new MemoryDomain("System Bus", 0x10000000, l,
|
||||
delegate(int addr)
|
||||
{
|
||||
if (addr < 0 || addr >= 0x10000000)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
return LibVBANext.SystemBusRead(Core, addr);
|
||||
},
|
||||
delegate(int addr, byte val)
|
||||
{
|
||||
if (addr < 0 || addr >= 0x10000000)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
LibVBANext.SystemBusWrite(Core, addr, val);
|
||||
}));
|
||||
// special combined ram memory domain
|
||||
{
|
||||
var ew = mm[1];
|
||||
var iw = mm[0];
|
||||
MemoryDomain cr = new MemoryDomain("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little,
|
||||
delegate(int addr)
|
||||
{
|
||||
if (addr < 0 || addr >= (256 + 32) * 1024)
|
||||
throw new IndexOutOfRangeException();
|
||||
if (addr >= 256 * 1024)
|
||||
return iw.PeekByte(addr & 32767);
|
||||
else
|
||||
return ew.PeekByte(addr);
|
||||
},
|
||||
delegate(int addr, byte val)
|
||||
{
|
||||
if (addr < 0 || addr >= (256 + 32) * 1024)
|
||||
throw new IndexOutOfRangeException();
|
||||
if (addr >= 256 * 1024)
|
||||
iw.PokeByte(addr & 32767, val);
|
||||
else
|
||||
ew.PokeByte(addr, val);
|
||||
});
|
||||
mm.Add(cr);
|
||||
}
|
||||
|
||||
_memoryDomains = new MemoryDomainList(mm, 0);
|
||||
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(_memoryDomains);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
public partial class VBANext : ISaveRam
|
||||
{
|
||||
public bool SaveRamModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return LibVBANext.SaveRamSize(Core) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] CloneSaveRam()
|
||||
{
|
||||
var data = new byte[LibVBANext.SaveRamSize(Core)];
|
||||
if (!LibVBANext.SaveRamSave(Core, data, data.Length))
|
||||
{
|
||||
throw new InvalidOperationException("SaveRamSave() failed!");
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public void StoreSaveRam(byte[] data)
|
||||
{
|
||||
// internally, we try to salvage bad-sized saverams
|
||||
if (!LibVBANext.SaveRamLoad(Core, data, data.Length))
|
||||
{
|
||||
throw new InvalidOperationException("SaveRamLoad() failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
public partial class VBANext : ISettable<object, VBANext.SyncSettings>
|
||||
{
|
||||
public object GetSettings()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public SyncSettings GetSyncSettings()
|
||||
{
|
||||
return _syncSettings.Clone();
|
||||
}
|
||||
|
||||
public bool PutSettings(object o)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool PutSyncSettings(SyncSettings o)
|
||||
{
|
||||
bool ret = SyncSettings.NeedsReboot(o, _syncSettings);
|
||||
_syncSettings = o;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private SyncSettings _syncSettings;
|
||||
|
||||
public class SyncSettings
|
||||
{
|
||||
[DisplayName("Skip BIOS")]
|
||||
[Description("Skips the BIOS intro. A BIOS file is still required.")]
|
||||
[DefaultValue(true)]
|
||||
public bool SkipBios { get; set; }
|
||||
|
||||
[DisplayName("RTC Use Real Time")]
|
||||
[Description("Causes the internal clock to reflect your system clock. Only relevant when a game has an RTC chip. Forced to false for movie recording.")]
|
||||
[DefaultValue(true)]
|
||||
public bool RTCUseRealTime { get; set; }
|
||||
|
||||
[DisplayName("RTC Initial Time")]
|
||||
[Description("The initial time of emulation. Only relevant when a game has an RTC chip and \"RTC Use Real Time\" is false.")]
|
||||
[DefaultValue(typeof(DateTime), "2010-01-01")]
|
||||
public DateTime RTCInitialTime { get; set; }
|
||||
|
||||
public enum DayOfWeek
|
||||
{
|
||||
Sunday = 0,
|
||||
Monday,
|
||||
Tuesday,
|
||||
Wednesday,
|
||||
Thursday,
|
||||
Friday,
|
||||
Saturday
|
||||
}
|
||||
|
||||
[DisplayName("RTC Initial Day")]
|
||||
[Description("The day of the week to go with \"RTC Initial Time\". Due to peculiarities in the RTC chip, this can be set indepedently of the year, month, and day of month.")]
|
||||
[DefaultValue(DayOfWeek.Friday)]
|
||||
public DayOfWeek RTCInitialDay { get; set; }
|
||||
|
||||
public SyncSettings()
|
||||
{
|
||||
SettingsUtil.SetDefaultValues(this);
|
||||
}
|
||||
|
||||
public static bool NeedsReboot(SyncSettings x, SyncSettings y)
|
||||
{
|
||||
return !DeepEquality.DeepEquals(x, y);
|
||||
}
|
||||
|
||||
public SyncSettings Clone()
|
||||
{
|
||||
return (SyncSettings)MemberwiseClone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
public partial class VBANext : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
var s = new TextState<TextStateData>();
|
||||
s.Prepare();
|
||||
var ff = s.GetFunctionPointersSave();
|
||||
LibVBANext.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();
|
||||
LibVBANext.TxtStateLoad(Core, ref ff);
|
||||
IsLagFrame = s.ExtraData.IsLagFrame;
|
||||
LagCount = s.ExtraData.LagCount;
|
||||
Frame = s.ExtraData.Frame;
|
||||
}
|
||||
|
||||
public void SaveStateBinary(BinaryWriter writer)
|
||||
{
|
||||
if (!LibVBANext.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 (!LibVBANext.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,42 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
public partial class VBANext : IVideoProvider
|
||||
{
|
||||
public int VirtualWidth { get { return 240; } }
|
||||
public int VirtualHeight { get { return 160; } }
|
||||
public int BufferWidth { get { return 240; } }
|
||||
public int BufferHeight { get { return 160; } }
|
||||
|
||||
public int BackgroundColor
|
||||
{
|
||||
get { return unchecked((int)0xff000000); }
|
||||
}
|
||||
|
||||
public int[] GetVideoBuffer()
|
||||
{
|
||||
return videobuff;
|
||||
}
|
||||
|
||||
private int[] videobuff = new int[240 * 160];
|
||||
private int[] videopalette = new int[65536];
|
||||
|
||||
private void SetupColors()
|
||||
{
|
||||
int[] tmp = BizHawk.Emulation.Cores.Nintendo.Gameboy.GBColors.GetLut(Gameboy.GBColors.ColorType.vivid);
|
||||
// reorder
|
||||
for (int i = 0; i < 32768; i++)
|
||||
{
|
||||
int j = i & 0x3e0 | (i & 0x1f) << 10 | i >> 10 & 0x1f;
|
||||
videopalette[i] = tmp[j];
|
||||
}
|
||||
// duplicate
|
||||
Array.Copy(videopalette, 0, videopalette, 32768, 32768);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
[CoreAttributes("VBA-Next", "many authors", true, true, "cd508312a29ed8c29dacac1b11c2dce56c338a54", "https://github.com/libretro/vba-next")]
|
||||
[ServiceNotApplicable(typeof(IDriveLight))]
|
||||
public class VBANext : IEmulator, IVideoProvider, ISyncSoundProvider, IInputPollable,
|
||||
public partial class VBANext : IEmulator, IVideoProvider, ISyncSoundProvider, IInputPollable,
|
||||
IGBAGPUViewable, ISaveRam, IStatable, IDebuggable, ISettable<object, VBANext.SyncSettings>
|
||||
{
|
||||
IntPtr Core;
|
||||
|
@ -44,18 +44,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
Console.WriteLine("GameDB loaded settings: saveType={0}, flashSize={1}, rtcEnabled={2}, mirroringEnabled={3}",
|
||||
FES.saveType, FES.flashSize, FES.enableRtc, FES.mirroringEnable);
|
||||
|
||||
_SyncSettings = (SyncSettings)syncsettings ?? new SyncSettings();
|
||||
_syncSettings = (SyncSettings)syncsettings ?? new SyncSettings();
|
||||
DeterministicEmulation = deterministic;
|
||||
|
||||
FES.skipBios = _SyncSettings.SkipBios;
|
||||
FES.RTCUseRealTime = _SyncSettings.RTCUseRealTime;
|
||||
FES.RTCwday = (int)_SyncSettings.RTCInitialDay;
|
||||
FES.RTCyear = _SyncSettings.RTCInitialTime.Year % 100;
|
||||
FES.RTCmonth = _SyncSettings.RTCInitialTime.Month - 1;
|
||||
FES.RTCmday = _SyncSettings.RTCInitialTime.Day;
|
||||
FES.RTChour = _SyncSettings.RTCInitialTime.Hour;
|
||||
FES.RTCmin = _SyncSettings.RTCInitialTime.Minute;
|
||||
FES.RTCsec = _SyncSettings.RTCInitialTime.Second;
|
||||
FES.skipBios = _syncSettings.SkipBios;
|
||||
FES.RTCUseRealTime = _syncSettings.RTCUseRealTime;
|
||||
FES.RTCwday = (int)_syncSettings.RTCInitialDay;
|
||||
FES.RTCyear = _syncSettings.RTCInitialTime.Year % 100;
|
||||
FES.RTCmonth = _syncSettings.RTCInitialTime.Month - 1;
|
||||
FES.RTCmday = _syncSettings.RTCInitialTime.Day;
|
||||
FES.RTChour = _syncSettings.RTCInitialTime.Hour;
|
||||
FES.RTCmin = _syncSettings.RTCInitialTime.Minute;
|
||||
FES.RTCsec = _syncSettings.RTCInitialTime.Second;
|
||||
if (DeterministicEmulation)
|
||||
{
|
||||
// FES.skipBios = false; // this is OK; it is deterministic and probably accurate
|
||||
|
@ -148,122 +148,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
}
|
||||
}
|
||||
|
||||
#region SaveRam
|
||||
|
||||
public byte[] CloneSaveRam()
|
||||
{
|
||||
byte[] data = new byte[LibVBANext.SaveRamSize(Core)];
|
||||
if (!LibVBANext.SaveRamSave(Core, data, data.Length))
|
||||
throw new InvalidOperationException("SaveRamSave() failed!");
|
||||
return data;
|
||||
}
|
||||
|
||||
public void StoreSaveRam(byte[] data)
|
||||
{
|
||||
// internally, we try to salvage bad-sized saverams
|
||||
if (!LibVBANext.SaveRamLoad(Core, data, data.Length))
|
||||
throw new InvalidOperationException("SaveRamLoad() failed!");
|
||||
}
|
||||
|
||||
public bool SaveRamModified
|
||||
{
|
||||
get
|
||||
{
|
||||
return LibVBANext.SaveRamSize(Core) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
#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();
|
||||
LibVBANext.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();
|
||||
LibVBANext.TxtStateLoad(Core, ref ff);
|
||||
IsLagFrame = s.ExtraData.IsLagFrame;
|
||||
LagCount = s.ExtraData.LagCount;
|
||||
Frame = s.ExtraData.Frame;
|
||||
}
|
||||
|
||||
public void SaveStateBinary(BinaryWriter writer)
|
||||
{
|
||||
if (!LibVBANext.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 (!LibVBANext.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 Debugging
|
||||
|
||||
LibVBANext.StandardCallback padcb;
|
||||
|
@ -275,9 +159,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
private readonly InputCallbackSystem _inputCallbacks = new InputCallbackSystem();
|
||||
public IInputCallbackSystem InputCallbacks { get { return _inputCallbacks; } }
|
||||
|
||||
private readonly MemoryCallbackSystem _memorycallbacks = new MemoryCallbackSystem();
|
||||
public IMemoryCallbackSystem MemoryCallbacks { get { return _memorycallbacks; } }
|
||||
|
||||
string Trace(uint addr, uint opcode)
|
||||
{
|
||||
return
|
||||
|
@ -315,98 +196,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
LibVBANext.SetTraceCallback(Core, Tracer.Enabled ? tracecb : null);
|
||||
}
|
||||
|
||||
LibVBANext.StandardCallback scanlinecb;
|
||||
|
||||
GBAGPUMemoryAreas IGBAGPUViewable.GetMemoryAreas()
|
||||
{
|
||||
var s = new LibVBANext.MemoryAreas();
|
||||
LibVBANext.GetMemoryAreas(Core, s);
|
||||
return new GBAGPUMemoryAreas
|
||||
{
|
||||
mmio = s.mmio,
|
||||
oam = s.oam,
|
||||
palram = s.palram,
|
||||
vram = s.vram
|
||||
};
|
||||
}
|
||||
|
||||
void IGBAGPUViewable.SetScanlineCallback(Action callback, int scanline)
|
||||
{
|
||||
if (scanline < 0 || scanline > 227)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Scanline must be in [0, 227]!");
|
||||
}
|
||||
if (callback == null)
|
||||
{
|
||||
scanlinecb = null;
|
||||
LibVBANext.SetScanlineCallback(Core, scanlinecb, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
scanlinecb = new LibVBANext.StandardCallback(callback);
|
||||
LibVBANext.SetScanlineCallback(Core, scanlinecb, scanline);
|
||||
}
|
||||
}
|
||||
|
||||
void InitMemoryDomains()
|
||||
{
|
||||
var mm = new List<MemoryDomain>();
|
||||
var s = new LibVBANext.MemoryAreas();
|
||||
var l = MemoryDomain.Endian.Little;
|
||||
LibVBANext.GetMemoryAreas(Core, s);
|
||||
mm.Add(MemoryDomain.FromIntPtr("IWRAM", 32 * 1024, l, s.iwram));
|
||||
mm.Add(MemoryDomain.FromIntPtr("EWRAM", 256 * 1024, l, s.ewram));
|
||||
mm.Add(MemoryDomain.FromIntPtr("BIOS", 16 * 1024, l, s.bios, false));
|
||||
mm.Add(MemoryDomain.FromIntPtr("PALRAM", 1024, l, s.palram, false));
|
||||
mm.Add(MemoryDomain.FromIntPtr("VRAM", 96 * 1024, l, s.vram));
|
||||
mm.Add(MemoryDomain.FromIntPtr("OAM", 1024, l, s.oam));
|
||||
mm.Add(MemoryDomain.FromIntPtr("ROM", 32 * 1024 * 1024, l, s.rom));
|
||||
|
||||
mm.Add(new MemoryDomain("System Bus", 0x10000000, l,
|
||||
delegate(int addr)
|
||||
{
|
||||
if (addr < 0 || addr >= 0x10000000)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
return LibVBANext.SystemBusRead(Core, addr);
|
||||
},
|
||||
delegate(int addr, byte val)
|
||||
{
|
||||
if (addr < 0 || addr >= 0x10000000)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
LibVBANext.SystemBusWrite(Core, addr, val);
|
||||
}));
|
||||
// special combined ram memory domain
|
||||
{
|
||||
var ew = mm[1];
|
||||
var iw = mm[0];
|
||||
MemoryDomain cr = new MemoryDomain("Combined WRAM", (256 + 32) * 1024, MemoryDomain.Endian.Little,
|
||||
delegate(int addr)
|
||||
{
|
||||
if (addr < 0 || addr >= (256 + 32) * 1024)
|
||||
throw new IndexOutOfRangeException();
|
||||
if (addr >= 256 * 1024)
|
||||
return iw.PeekByte(addr & 32767);
|
||||
else
|
||||
return ew.PeekByte(addr);
|
||||
},
|
||||
delegate(int addr, byte val)
|
||||
{
|
||||
if (addr < 0 || addr >= (256 + 32) * 1024)
|
||||
throw new IndexOutOfRangeException();
|
||||
if (addr >= 256 * 1024)
|
||||
iw.PokeByte(addr & 32767, val);
|
||||
else
|
||||
ew.PokeByte(addr, val);
|
||||
});
|
||||
mm.Add(cr);
|
||||
}
|
||||
|
||||
_memoryDomains = new MemoryDomainList(mm, 0);
|
||||
(ServiceProvider as BasicServiceProvider).Register<IMemoryDomains>(_memoryDomains);
|
||||
}
|
||||
|
||||
private IMemoryDomains _memoryDomains;
|
||||
|
||||
VBARegisterHelper regs;
|
||||
|
||||
void InitRegisters()
|
||||
|
@ -414,98 +203,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
regs = new VBARegisterHelper(Core);
|
||||
}
|
||||
|
||||
public IDictionary<string, RegisterValue> GetCpuFlagsAndRegisters()
|
||||
{
|
||||
return regs.GetAllRegisters();
|
||||
}
|
||||
|
||||
public void SetCpuRegister(string register, int value)
|
||||
{
|
||||
regs.SetRegister(register, value);
|
||||
}
|
||||
|
||||
public bool CanStep(StepType type) { return false; }
|
||||
|
||||
[FeatureNotImplemented]
|
||||
public void Step(StepType type) { throw new NotImplementedException(); }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Settings
|
||||
|
||||
public object GetSettings()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public SyncSettings GetSyncSettings()
|
||||
{
|
||||
return _SyncSettings.Clone();
|
||||
}
|
||||
|
||||
SyncSettings _SyncSettings;
|
||||
|
||||
|
||||
public bool PutSettings(object o)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool PutSyncSettings(SyncSettings o)
|
||||
{
|
||||
bool ret = SyncSettings.NeedsReboot(o, _SyncSettings);
|
||||
_SyncSettings = o;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public class SyncSettings
|
||||
{
|
||||
[DisplayName("Skip BIOS")]
|
||||
[Description("Skips the BIOS intro. A BIOS file is still required.")]
|
||||
[DefaultValue(true)]
|
||||
public bool SkipBios { get; set; }
|
||||
[DisplayName("RTC Use Real Time")]
|
||||
[Description("Causes the internal clock to reflect your system clock. Only relevant when a game has an RTC chip. Forced to false for movie recording.")]
|
||||
[DefaultValue(true)]
|
||||
public bool RTCUseRealTime { get; set; }
|
||||
|
||||
[DisplayName("RTC Initial Time")]
|
||||
[Description("The initial time of emulation. Only relevant when a game has an RTC chip and \"RTC Use Real Time\" is false.")]
|
||||
[DefaultValue(typeof(DateTime), "2010-01-01")]
|
||||
public DateTime RTCInitialTime { get; set; }
|
||||
|
||||
public enum DayOfWeek
|
||||
{
|
||||
Sunday = 0,
|
||||
Monday,
|
||||
Tuesday,
|
||||
Wednesday,
|
||||
Thursday,
|
||||
Friday,
|
||||
Saturday
|
||||
}
|
||||
|
||||
[DisplayName("RTC Initial Day")]
|
||||
[Description("The day of the week to go with \"RTC Initial Time\". Due to peculiarities in the RTC chip, this can be set indepedently of the year, month, and day of month.")]
|
||||
[DefaultValue(DayOfWeek.Friday)]
|
||||
public DayOfWeek RTCInitialDay { get; set; }
|
||||
|
||||
public SyncSettings()
|
||||
{
|
||||
SettingsUtil.SetDefaultValues(this);
|
||||
}
|
||||
|
||||
public static bool NeedsReboot(SyncSettings x, SyncSettings y)
|
||||
{
|
||||
return !DeepEquality.DeepEquals(x, y);
|
||||
}
|
||||
|
||||
public SyncSettings Clone()
|
||||
{
|
||||
return (SyncSettings)MemberwiseClone();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Controller
|
||||
|
@ -526,33 +223,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
|
||||
#endregion
|
||||
|
||||
#region VideoProvider
|
||||
|
||||
int[] videobuff = new int[240 * 160];
|
||||
int[] videopalette = new int[65536];
|
||||
|
||||
public int[] GetVideoBuffer() { return videobuff; }
|
||||
public int VirtualWidth { get { return 240; } }
|
||||
public int VirtualHeight { get { return 160; } }
|
||||
public int BufferWidth { get { return 240; } }
|
||||
public int BufferHeight { get { return 160; } }
|
||||
public int BackgroundColor { get { return unchecked((int)0xff000000); } }
|
||||
|
||||
void SetupColors()
|
||||
{
|
||||
int[] tmp = BizHawk.Emulation.Cores.Nintendo.Gameboy.GBColors.GetLut(Gameboy.GBColors.ColorType.vivid);
|
||||
// reorder
|
||||
for (int i = 0; i < 32768; i++)
|
||||
{
|
||||
int j = i & 0x3e0 | (i & 0x1f) << 10 | i >> 10 & 0x1f;
|
||||
videopalette[i] = tmp[j];
|
||||
}
|
||||
// duplicate
|
||||
Array.Copy(videopalette, 0, videopalette, 32768, 32768);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoundProvider
|
||||
|
||||
short[] soundbuff = new short[2048];
|
||||
|
|
Loading…
Reference in New Issue