in IEmulator extensions add methods such as AsMemoryDomains(), AsStatable() that do the service calling magic. In the client code replace appplicable casts of IMemoryDomains with AsMemoryDomains(), more commits of this nature for the other IEmulatorServices soon to follow

This commit is contained in:
adelikat 2014-12-05 00:32:29 +00:00
parent cda9203ca5
commit 04f9081943
13 changed files with 39 additions and 16 deletions

View File

@ -24,7 +24,7 @@ namespace BizHawk.Client.Common
{
if (Global.Emulator.HasMemoryDomains())
{
return (Global.Emulator as IMemoryDomains).MemoryDomains.MainMemory;
return Global.Emulator.AsMemoryDomains().MemoryDomains.MainMemory;
}
else
{

View File

@ -17,7 +17,7 @@ namespace BizHawk.Client.Common
{
if (Global.Emulator.HasMemoryDomains())
{
var domains = (Global.Emulator as IMemoryDomains).MemoryDomains;
var domains = Global.Emulator.AsMemoryDomains().MemoryDomains;
_currentMemoryDomain = domains.IndexOf(domains.MainMemory);
}
}
@ -27,7 +27,7 @@ namespace BizHawk.Client.Common
{
if (Global.Emulator.HasMemoryDomains())
{
var domains = (Global.Emulator as IMemoryDomains).MemoryDomains;
var domains = Global.Emulator.AsMemoryDomains().MemoryDomains;
_currentMemoryDomain = domains.IndexOf(domains.MainMemory);
}
}
@ -40,7 +40,7 @@ namespace BizHawk.Client.Common
{
if (Global.Emulator.HasMemoryDomains())
{
return (Global.Emulator as IMemoryDomains).MemoryDomains[_currentMemoryDomain];
return Global.Emulator.AsMemoryDomains().MemoryDomains[_currentMemoryDomain];
}
else
{

View File

@ -4,6 +4,7 @@ using System.Linq;
using LuaInterface;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Emulation.Cores.Nintendo.NES;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
@ -34,7 +35,7 @@ namespace BizHawk.Client.Common
{
var decoder = new NESGameGenieDecoder(code);
var watch = Watch.GenerateWatch(
(Global.Emulator as IMemoryDomains).MemoryDomains["System Bus"],
Global.Emulator.AsMemoryDomains().MemoryDomains["System Bus"],
decoder.Address,
Watch.WatchSize.Byte,
Watch.DisplayType.Hex,

View File

@ -24,7 +24,7 @@ namespace BizHawk.Client.Common
{
if (Global.Emulator.HasMemoryDomains())
{
return (Global.Emulator as IMemoryDomains).MemoryDomains;
return Global.Emulator.AsMemoryDomains().MemoryDomains;
}
else
{

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common
{
@ -456,7 +457,7 @@ namespace BizHawk.Client.Common
compare = int.Parse(vals[2], NumberStyles.HexNumber);
}
var domain = (Global.Emulator as IMemoryDomains).MemoryDomains[vals[3]];
var domain = Global.Emulator.AsMemoryDomains().MemoryDomains[vals[3]];
var enabled = vals[4] == "1";
var name = vals[5];

View File

@ -5,6 +5,7 @@ using System.Linq;
using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
namespace BizHawk.Client.Common
{
@ -27,7 +28,7 @@ namespace BizHawk.Client.Common
public RamSearchEngine(Settings settings)
{
_settings = new Settings((IMemoryDomains)Global.Emulator);
_settings = new Settings(Global.Emulator.AsMemoryDomains());
_settings.Mode = settings.Mode;
_settings.Domain = settings.Domain;
_settings.Size = settings.Size;

View File

@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
@ -296,7 +297,7 @@ namespace BizHawk.Client.EmuHawk
}
var watch = Watch.GenerateWatch(
(Global.Emulator as IMemoryDomains).MemoryDomains["System Bus"],
Global.Emulator.AsMemoryDomains().MemoryDomains["System Bus"],
address,
Watch.WatchSize.Byte,
Watch.DisplayType.Hex,

View File

@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
#pragma warning disable 675 //TOOD: fix the potential problem this is masking
@ -357,7 +358,7 @@ namespace BizHawk.Client.EmuHawk
}
var watch = Watch.GenerateWatch(
(Global.Emulator as IMemoryDomains).MemoryDomains["MD CART"],
Global.Emulator.AsMemoryDomains().MemoryDomains["MD CART"],
address,
Watch.WatchSize.Word,
Watch.DisplayType.Hex,

View File

@ -4,6 +4,7 @@ using System.Globalization;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
@ -231,7 +232,7 @@ namespace BizHawk.Client.EmuHawk
if (!string.IsNullOrWhiteSpace(AddressBox.Text) && !string.IsNullOrWhiteSpace(ValueBox.Text))
{
var watch = Watch.GenerateWatch(
(Global.Emulator as IMemoryDomains).MemoryDomains["System Bus"],
Global.Emulator.AsMemoryDomains().MemoryDomains["System Bus"],
AddressBox.ToRawInt().Value,
Watch.WatchSize.Byte,
Watch.DisplayType.Hex,

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Emulation.Cores.Components.H6280;
using BizHawk.Emulation.Cores.PCEngine;
@ -304,7 +305,7 @@ namespace BizHawk.Client.EmuHawk
{
using (var fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write))
{
_cdl.Disassemble(fs, (Global.Emulator as IMemoryDomains).MemoryDomains);
_cdl.Disassemble(fs, Global.Emulator.AsMemoryDomains().MemoryDomains);
}
}
}

View File

@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
using System.Windows.Forms;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Emulation.Cores.Nintendo.SNES;
using BizHawk.Client.Common;
@ -275,7 +276,7 @@ namespace BizHawk.Client.EmuHawk
}
var watch = Watch.GenerateWatch(
(Global.Emulator as IMemoryDomains).MemoryDomains["BUS"],
Global.Emulator.AsMemoryDomains().MemoryDomains["BUS"],
address,
Watch.WatchSize.Byte,
Watch.DisplayType.Hex,

View File

@ -38,7 +38,7 @@ namespace BizHawk.Client.EmuHawk
if (Global.Emulator.CpuTraceAvailable())
{
Tracer = Global.Emulator.GetDebugger().Tracer;
Tracer = Global.Emulator.AsDebuggable().Tracer;
}
else
{

View File

@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return core != null && core.ServiceProvider.HasService<IMemoryDomains>();
}
public static IMemoryDomains GetMemoryDomains(this IEmulator core)
public static IMemoryDomains AsMemoryDomains(this IEmulator core)
{
return (IMemoryDomains)core.ServiceProvider.GetService<IMemoryDomains>();
}
@ -32,16 +32,31 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return core != null && core.ServiceProvider.HasService<ISaveRam>();
}
public static ISaveRam AsSaveRam(this IEmulator core)
{
return (ISaveRam)core.ServiceProvider.GetService<ISaveRam>();
}
public static bool HasSavestates(this IEmulator core)
{
return core != null && core.ServiceProvider.HasService<IStatable>();
}
public static IStatable AsStatable(this IEmulator core)
{
return (IStatable)core.ServiceProvider.GetService<IStatable>();
}
public static bool CanPollInput(this IEmulator core)
{
return core != null && core.ServiceProvider.HasService<IInputPollable>();
}
public static IInputPollable AsInputPollable(this IEmulator core)
{
return (IInputPollable)core.ServiceProvider.GetService<IInputPollable>();
}
public static bool CpuTraceAvailable(this IEmulator core)
{
// TODO: this is a pretty ugly way to handle this
@ -67,7 +82,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return core.ServiceProvider.HasService<IDebuggable>();
}
public static IDebuggable GetDebugger(this IEmulator core)
public static IDebuggable AsDebuggable(this IEmulator core)
{
return (IDebuggable)core.ServiceProvider.GetService<IDebuggable>();
}