Lua NES library - properly use an OptionalService instead of Global.Emulator

This commit is contained in:
adelikat 2016-12-04 11:50:07 -06:00
parent 17ea38f904
commit 63202570cc
1 changed files with 9 additions and 3 deletions

View File

@ -3,8 +3,8 @@ using System.ComponentModel;
using System.Linq; using System.Linq;
using LuaInterface; using LuaInterface;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Common.IEmulatorExtensions;
using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Cores.Nintendo.NES;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
@ -22,11 +22,17 @@ namespace BizHawk.Client.Common
[OptionalService] [OptionalService]
private NES _neshawk { get; set; } private NES _neshawk { get; set; }
[OptionalService] [OptionalService]
private QuickNES _quicknes { get; set; } private QuickNES _quicknes { get; set; }
[OptionalService]
private IMemoryDomains _memoryDomains { get; set; }
private bool NESAvailable { get { return _neshawk != null || _quicknes != null; } } private bool NESAvailable { get { return _neshawk != null || _quicknes != null; } }
private bool HasMemoryDOmains { get { return _memoryDomains != null; } }
public NesLuaLibrary(Lua lua, Action<string> logOutputCallback) public NesLuaLibrary(Lua lua, Action<string> logOutputCallback)
: base(lua, logOutputCallback) { } : base(lua, logOutputCallback) { }
@ -38,11 +44,11 @@ namespace BizHawk.Client.Common
)] )]
public void AddGameGenie(string code) public void AddGameGenie(string code)
{ {
if (NESAvailable) if (NESAvailable && HasMemoryDOmains)
{ {
var decoder = new NESGameGenieDecoder(code); var decoder = new NESGameGenieDecoder(code);
var watch = Watch.GenerateWatch( var watch = Watch.GenerateWatch(
Global.Emulator.AsMemoryDomains()["System Bus"], _memoryDomains["System Bus"],
decoder.Address, decoder.Address,
WatchSize.Byte, WatchSize.Byte,
DisplayType.Hex, DisplayType.Hex,