Misc VBANext cleanups
This commit is contained in:
parent
ba28ca53a8
commit
e72aceccdc
|
@ -1,8 +1,4 @@
|
|||
using BizHawk.Emulation.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
|
|
|
@ -6,11 +6,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
public interface IGBAGPUViewable : IEmulatorService
|
||||
{
|
||||
GBAGPUMemoryAreas GetMemoryAreas();
|
||||
|
||||
/// <summary>
|
||||
/// calls correspond to entering hblank (maybe) and in a regular frame, the sequence of calls will be 160, 161, ..., 227, 0, ..., 159
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <param name="scanline"></param>
|
||||
void SetScanlineCallback(Action callback, int scanline);
|
||||
}
|
||||
|
||||
|
@ -18,7 +17,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
// the pointers are assumed to stay valid as long as the IEmulator is valid, maybe
|
||||
// this will need some change for a managed core (lifecycle management, etc)
|
||||
|
||||
public IntPtr vram;
|
||||
public IntPtr oam;
|
||||
public IntPtr mmio;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
|
@ -25,12 +24,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
}
|
||||
|
||||
private readonly MemoryCallbackSystem _memorycallbacks = new MemoryCallbackSystem();
|
||||
public IMemoryCallbackSystem MemoryCallbacks { get { return _memorycallbacks; } }
|
||||
public IMemoryCallbackSystem MemoryCallbacks => _memorycallbacks;
|
||||
|
||||
[FeatureNotImplemented]
|
||||
public void Step(StepType type) { throw new NotImplementedException(); }
|
||||
public void Step(StepType type)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[FeatureNotImplemented]
|
||||
public int TotalExecutedCycles { get { throw new NotImplementedException(); } }
|
||||
public int TotalExecutedCycles
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
||||
{
|
||||
|
@ -27,6 +23,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(scanline), "Scanline must be in [0, 227]!");
|
||||
}
|
||||
|
||||
if (callback == null)
|
||||
{
|
||||
scanlinecb = null;
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
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 bool SaveRamModified => LibVBANext.SaveRamSize(Core) != 0;
|
||||
|
||||
public byte[] CloneSaveRam()
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
|
|
@ -5,23 +5,20 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
public partial class VBANext : ISoundProvider
|
||||
{
|
||||
private short[] soundbuff = new short[2048];
|
||||
private int numsamp;
|
||||
private readonly short[] _soundbuff = new short[2048];
|
||||
private int _numsamp;
|
||||
|
||||
public void GetSamplesSync(out short[] samples, out int nsamp)
|
||||
{
|
||||
samples = soundbuff;
|
||||
nsamp = numsamp;
|
||||
samples = _soundbuff;
|
||||
nsamp = _numsamp;
|
||||
}
|
||||
|
||||
public void DiscardSamples()
|
||||
{
|
||||
}
|
||||
|
||||
public bool CanProvideAsync
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
public bool CanProvideAsync => false;
|
||||
|
||||
public void SetSyncMode(SyncSoundMode mode)
|
||||
{
|
||||
|
@ -31,10 +28,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
}
|
||||
}
|
||||
|
||||
public SyncSoundMode SyncMode
|
||||
{
|
||||
get { return SyncSoundMode.Sync; }
|
||||
}
|
||||
public SyncSoundMode SyncMode => SyncSoundMode.Sync;
|
||||
|
||||
public void GetSamplesAsync(short[] samples)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
|
@ -10,10 +8,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
public partial class VBANext : IStatable
|
||||
{
|
||||
public bool BinarySaveStatesPreferred
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
public bool BinarySaveStatesPreferred => true;
|
||||
|
||||
public void SaveStateText(TextWriter writer)
|
||||
{
|
||||
|
@ -26,6 +21,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
s.ExtraData.Frame = Frame;
|
||||
|
||||
ser.Serialize(writer, s);
|
||||
|
||||
// write extra copy of stuff we don't use
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("Frame {0}", Frame);
|
||||
|
@ -46,10 +42,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
|
||||
public void SaveStateBinary(BinaryWriter writer)
|
||||
{
|
||||
if (!LibVBANext.BinStateSave(Core, savebuff, savebuff.Length))
|
||||
if (!LibVBANext.BinStateSave(Core, _savebuff, _savebuff.Length))
|
||||
throw new InvalidOperationException("Core's BinStateSave() returned false!");
|
||||
writer.Write(savebuff.Length);
|
||||
writer.Write(savebuff);
|
||||
writer.Write(_savebuff.Length);
|
||||
writer.Write(_savebuff);
|
||||
|
||||
// other variables
|
||||
writer.Write(IsLagFrame);
|
||||
|
@ -60,10 +56,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
public void LoadStateBinary(BinaryReader reader)
|
||||
{
|
||||
int length = reader.ReadInt32();
|
||||
if (length != savebuff.Length)
|
||||
if (length != _savebuff.Length)
|
||||
throw new InvalidOperationException("Save buffer size mismatch!");
|
||||
reader.Read(savebuff, 0, length);
|
||||
if (!LibVBANext.BinStateLoad(Core, savebuff, savebuff.Length))
|
||||
reader.Read(_savebuff, 0, length);
|
||||
if (!LibVBANext.BinStateLoad(Core, _savebuff, _savebuff.Length))
|
||||
throw new InvalidOperationException("Core's BinStateLoad() returned false!");
|
||||
|
||||
// other variables
|
||||
|
@ -74,19 +70,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
|
||||
public byte[] SaveStateBinary()
|
||||
{
|
||||
var ms = new MemoryStream(savebuff2, true);
|
||||
var ms = new MemoryStream(_savebuff2, true);
|
||||
var bw = new BinaryWriter(ms);
|
||||
SaveStateBinary(bw);
|
||||
bw.Flush();
|
||||
if (ms.Position != savebuff2.Length)
|
||||
if (ms.Position != _savebuff2.Length)
|
||||
throw new InvalidOperationException();
|
||||
ms.Close();
|
||||
return savebuff2;
|
||||
return _savebuff2;
|
||||
}
|
||||
|
||||
private JsonSerializer ser = new JsonSerializer() { Formatting = Formatting.Indented };
|
||||
private byte[] savebuff;
|
||||
private byte[] savebuff2;
|
||||
private JsonSerializer ser = new JsonSerializer { Formatting = Formatting.Indented };
|
||||
private readonly byte[] _savebuff;
|
||||
private readonly byte[] _savebuff2;
|
||||
|
||||
private class TextStateData
|
||||
{
|
||||
|
|
|
@ -1,42 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
|
||||
|
||||
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 VirtualWidth => 240;
|
||||
public int VirtualHeight => 160;
|
||||
public int BufferWidth => 240;
|
||||
public int BufferHeight => 160;
|
||||
|
||||
public int BackgroundColor
|
||||
{
|
||||
get { return unchecked((int)0xff000000); }
|
||||
}
|
||||
public int BackgroundColor => unchecked((int)0xff000000);
|
||||
|
||||
public int[] GetVideoBuffer()
|
||||
{
|
||||
return videobuff;
|
||||
return _videobuff;
|
||||
}
|
||||
|
||||
private int[] videobuff = new int[240 * 160];
|
||||
private int[] videopalette = new int[65536];
|
||||
private readonly int[] _videobuff = new int[240 * 160];
|
||||
private readonly int[] _videopalette = new int[65536];
|
||||
|
||||
private void SetupColors()
|
||||
{
|
||||
int[] tmp = BizHawk.Emulation.Cores.Nintendo.Gameboy.GBColors.GetLut(Gameboy.GBColors.ColorType.vivid);
|
||||
int[] tmp = GBColors.GetLut(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];
|
||||
_videopalette[i] = tmp[j];
|
||||
}
|
||||
|
||||
// duplicate
|
||||
Array.Copy(videopalette, 0, videopalette, 32768, 32768);
|
||||
Array.Copy(_videopalette, 0, _videopalette, 32768, 32768);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
public unsafe class VBARegisterHelper
|
||||
{
|
||||
IntPtr _origin;
|
||||
Dictionary<string, IntPtr> _locs = new Dictionary<string, IntPtr>();
|
||||
private readonly IntPtr _origin;
|
||||
private readonly Dictionary<string, IntPtr> _locs = new Dictionary<string, IntPtr>();
|
||||
|
||||
public VBARegisterHelper(IntPtr Core)
|
||||
{
|
||||
|
@ -27,11 +27,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
int* p = (int*)_locs[name];
|
||||
return *p;
|
||||
}
|
||||
|
||||
public void SetRegister(string name, int val)
|
||||
{
|
||||
int* p = (int*)_locs[name];
|
||||
*p = val;
|
||||
}
|
||||
|
||||
public Dictionary<string, RegisterValue> GetAllRegisters()
|
||||
{
|
||||
var ret = new Dictionary<string, RegisterValue>();
|
||||
|
@ -39,6 +41,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
{
|
||||
ret[kvp.Key] = GetRegister(kvp.Key);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -48,10 +51,13 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
|
|||
int* p = (int*)_origin;
|
||||
for (int i = 0; i < 17; i++)
|
||||
{
|
||||
sb.Append(string.Format("r{0}:{1:X8}", i, p[i]));
|
||||
sb.Append($"r{i}:{p[i]:X8}");
|
||||
if (i != 16)
|
||||
{
|
||||
sb.Append(' ');
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue