From ea472466588ee94d863a7bef51a68fb4f1af1798 Mon Sep 17 00:00:00 2001 From: goyuken Date: Mon, 15 Dec 2014 22:25:06 +0000 Subject: [PATCH] remove the IEmulator inheritance from some services, and fix code as needed --- .../lua/EmuLuaLibrary.Emu.cs | 2 +- BizHawk.Client.Common/tools/WatchList.cs | 6 ++++-- BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs | 19 +++++++++++-------- .../tools/Debugger/BreakpointControl.cs | 5 +++-- .../Debugger/GenericDebugger.IToolForm.cs | 3 +++ .../tools/Debugger/GenericDebugger.cs | 8 ++++---- .../tools/Watch/RamSearch.cs | 8 +++++--- .../tools/Watch/RamWatch.cs | 8 +++++--- BizHawk.Emulation.Common/Extensions.cs | 3 ++- .../Interfaces/IDebuggable.cs | 2 +- .../Interfaces/IMemoryDomains.cs | 2 +- 11 files changed, 40 insertions(+), 26 deletions(-) diff --git a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs index 6af9429891..9b22d49e45 100644 --- a/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs +++ b/BizHawk.Client.Common/lua/EmuLuaLibrary.Emu.cs @@ -71,7 +71,7 @@ namespace BizHawk.Client.Common throw new NotImplementedException(); } - var registers = debuggable.AsDebuggable().GetCpuFlagsAndRegisters(); + var registers = debuggable.GetCpuFlagsAndRegisters(); return registers.ContainsKey(name) ? registers[name] : 0; diff --git a/BizHawk.Client.Common/tools/WatchList.cs b/BizHawk.Client.Common/tools/WatchList.cs index d75043e5f2..325440d41f 100644 --- a/BizHawk.Client.Common/tools/WatchList.cs +++ b/BizHawk.Client.Common/tools/WatchList.cs @@ -16,6 +16,7 @@ namespace BizHawk.Client.Common private List _watchList = new List(); private MemoryDomain _domain; private string _currentFilename = string.Empty; + private string _systemid; public const string ADDRESS = "AddressColumn"; public const string VALUE = "ValueColumn"; @@ -25,10 +26,11 @@ namespace BizHawk.Client.Common public const string DOMAIN = "DomainColumn"; public const string NOTES = "NotesColumn"; - public WatchList(IMemoryDomains core, MemoryDomain domain) + public WatchList(IMemoryDomains core, MemoryDomain domain, string systemid) { _core = core; _domain = domain; + _systemid = systemid; } public void RefreshDomans(IMemoryDomains core, MemoryDomain domain) @@ -387,7 +389,7 @@ namespace BizHawk.Client.Common var sb = new StringBuilder(); sb .Append("Domain ").AppendLine(_domain.Name) - .Append("SystemID ").AppendLine(_core.SystemId); + .Append("SystemID ").AppendLine(_systemid); foreach (var watch in _watchList) { diff --git a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 782d2f56fd..f0a464e23c 100644 --- a/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -22,6 +22,9 @@ namespace BizHawk.Client.EmuHawk [RequiredService] private IMemoryDomains Core { get; set; } + [RequiredService] // TODO: use of this property should be factored out + private IEmulator Emu { get; set; } + public const string NAME = "NamesColumn"; public const string ADDRESS = "AddressColumn"; public const string VALUE = "ValueColumn"; @@ -195,11 +198,11 @@ namespace BizHawk.Client.EmuHawk { GameGenieToolbarSeparator.Visible = LoadGameGenieToolbarItem.Visible = - (Core.SystemId == "NES") - || (Core.SystemId == "GEN" && VersionInfo.DeveloperBuild) - || (Core.SystemId == "GB") + (Emu.SystemId == "NES") + || (Emu.SystemId == "GEN" && VersionInfo.DeveloperBuild) + || (Emu.SystemId == "GB") || (Global.Game.System == "GG") - || (Core is LibsnesCore); + || (Emu is LibsnesCore); } private void AddCheat() @@ -536,11 +539,11 @@ namespace BizHawk.Client.EmuHawk GameGenieSeparator.Visible = OpenGameGenieEncoderDecoderMenuItem.Visible = - (Core.SystemId == "NES") - || (Core is Genesis) - || (Core.SystemId == "GB") + (Emu.SystemId == "NES") + || (Emu is Genesis) + || (Emu.SystemId == "GB") || (Global.Game.System == "GG") - || (Core is LibsnesCore); + || (Emu is LibsnesCore); } private void RemoveCheatMenuItem_Click(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs b/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs index 229ae68769..429b22be22 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs @@ -16,6 +16,7 @@ namespace BizHawk.Client.EmuHawk.tools.Debugger public partial class BreakpointControl : UserControl { public IDebuggable Core { get; set; } + public IMemoryCallbackSystem MCS { get; set; } public GenericDebugger ParentDebugger { get; set; } private readonly BreakpointList Breakpoints = new BreakpointList(); @@ -73,9 +74,9 @@ namespace BizHawk.Client.EmuHawk.tools.Debugger public void GenerateUI() { - if (Core.MemoryCallbacksAvailable()) + if (MCS != null) { - foreach (var callback in Core.MemoryCallbacks) + foreach (var callback in MCS) { Breakpoints.Add(new Breakpoint(Core, callback)); } diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs index c9a316ac26..abc42e3e12 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IToolForm.cs @@ -15,6 +15,9 @@ namespace BizHawk.Client.EmuHawk private IDisassemblable Disassembler { get; set; } [OptionalService] private IMemoryDomains MemoryDomainSource { get; set; } + [OptionalService] + private IMemoryCallbackSystem MCS { get; set; } + private MemoryDomainList MemoryDomains { get { return MemoryDomainSource.MemoryDomains; } } private int PC diff --git a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs index 23ef14eea5..de3381bd7e 100644 --- a/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs +++ b/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.cs @@ -100,8 +100,8 @@ namespace BizHawk.Client.EmuHawk DropDownStyle = ComboBoxStyle.DropDownList }; - c.Items.AddRange(Core.AsDissassembler().AvailableCpus.ToArray()); - c.SelectedItem = Core.AsDissassembler().Cpu; + c.Items.AddRange(Disassembler.AvailableCpus.ToArray()); + c.SelectedItem = Disassembler.Cpu; c.SelectedIndexChanged += OnCpuDropDownIndexChanged; DisassemblerBox.Controls.Add(c); @@ -140,6 +140,7 @@ namespace BizHawk.Client.EmuHawk // TODO: handle if unavailable BreakPointControl1.Core = Core; + BreakPointControl1.MCS = MCS; BreakPointControl1.ParentDebugger = this; BreakPointControl1.GenerateUI(); } @@ -147,8 +148,7 @@ namespace BizHawk.Client.EmuHawk private void DisengageDebugger() { SaveConfigSettings(); - - if (Core.CpuTraceAvailable()) + if (Core.Tracer != null) { Core.Tracer.Enabled = false; } diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 7bc8c12242..0efa5019c8 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -55,6 +55,8 @@ namespace BizHawk.Client.EmuHawk [RequiredService] public IMemoryDomains Core { get; private set; } + [RequiredService] + public IEmulator Emu { get; private set; } public bool AskSaveChanges() { @@ -839,7 +841,7 @@ namespace BizHawk.Client.EmuHawk _currentFileName = file.FullName; } - var watches = new WatchList(Core, _settings.Domain); + var watches = new WatchList(Core, _settings.Domain, Emu.SystemId); watches.Load(file.FullName, append); var watchList = watches.Where(x => !x.IsSeparator); @@ -995,7 +997,7 @@ namespace BizHawk.Client.EmuHawk { if (!string.IsNullOrWhiteSpace(_currentFileName)) { - var watches = new WatchList(Core, _settings.Domain) { CurrentFileName = _currentFileName }; + var watches = new WatchList(Core, _settings.Domain, Emu.SystemId) { CurrentFileName = _currentFileName }; for (var i = 0; i < _searches.Count; i++) { watches.Add(_searches[i]); @@ -1023,7 +1025,7 @@ namespace BizHawk.Client.EmuHawk private void SaveAsMenuItem_Click(object sender, EventArgs e) { - var watches = new WatchList(Core, _settings.Domain) { CurrentFileName = _currentFileName }; + var watches = new WatchList(Core, _settings.Domain, Emu.SystemId) { CurrentFileName = _currentFileName }; for (var i = 0; i < _searches.Count; i++) { watches.Add(_searches[i]); diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index e61f131368..c11c375328 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -39,6 +39,8 @@ namespace BizHawk.Client.EmuHawk [RequiredService] private IMemoryDomains _core { get; set; } + [RequiredService] + private IEmulator _emu { get; set; } public RamWatch() { @@ -203,7 +205,7 @@ namespace BizHawk.Client.EmuHawk } else { - _watches = new WatchList(_core, _core.MemoryDomains.MainMemory); + _watches = new WatchList(_core, _core.MemoryDomains.MainMemory, _emu.SystemId); NewWatchList(true); } } @@ -572,7 +574,7 @@ namespace BizHawk.Client.EmuHawk private void SetPlatformAndMemoryDomainLabel() { - MemDomainLabel.Text = _core.SystemId + " " + _watches.Domain.Name; + MemDomainLabel.Text = _emu.SystemId + " " + _watches.Domain.Name; } private void UpdateStatusBar(bool saved = false) @@ -1076,7 +1078,7 @@ namespace BizHawk.Client.EmuHawk private void NewRamWatch_Load(object sender, EventArgs e) { - _watches = new WatchList(_core, _core.MemoryDomains.MainMemory); + _watches = new WatchList(_core, _core.MemoryDomains.MainMemory, _emu.SystemId); LoadConfigSettings(); UpdateStatusBar(); } diff --git a/BizHawk.Emulation.Common/Extensions.cs b/BizHawk.Emulation.Common/Extensions.cs index eaa3765c2e..d3a6cd0908 100644 --- a/BizHawk.Emulation.Common/Extensions.cs +++ b/BizHawk.Emulation.Common/Extensions.cs @@ -12,6 +12,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions return (CoreAttributes)Attribute.GetCustomAttribute(core.GetType(), typeof(CoreAttributes)); } + // todo: most of the special cases involving the NullEmulator should probably go away public static bool IsNull(this IEmulator core) { return core == null || core is NullEmulator; @@ -169,7 +170,7 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions public static IDisassemblable AsDissassembler(this IEmulator core) { - return (IDisassemblable)core.ServiceProvider.GetService(); + return (IDisassemblable)core.ServiceProvider.GetService(); } // TODO: a better place for these diff --git a/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs b/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs index a8226b8c11..81cb2d354e 100644 --- a/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs +++ b/BizHawk.Emulation.Common/Interfaces/IDebuggable.cs @@ -2,7 +2,7 @@ namespace BizHawk.Emulation.Common { - public interface IDebuggable : IEmulator, IEmulatorService + public interface IDebuggable : IEmulatorService { /// /// Returns a list of Cpu registers and their current state diff --git a/BizHawk.Emulation.Common/Interfaces/IMemoryDomains.cs b/BizHawk.Emulation.Common/Interfaces/IMemoryDomains.cs index bac0635523..6958b2455c 100644 --- a/BizHawk.Emulation.Common/Interfaces/IMemoryDomains.cs +++ b/BizHawk.Emulation.Common/Interfaces/IMemoryDomains.cs @@ -1,6 +1,6 @@ namespace BizHawk.Emulation.Common { - public interface IMemoryDomains : IEmulator, IEmulatorService + public interface IMemoryDomains : IEmulatorService { ///The list of all avaialble memory domains /// A memory domain is a byte array that respresents a distinct part of the emulated system.