diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index d77b265d06..ae9e0680a4 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -1222,7 +1222,7 @@ namespace BizHawk.Client.EmuHawk NesControllerSettingsMenuItem.Enabled = (Global.Emulator is NES || Global.Emulator is QuickNES) && !Global.MovieSession.Movie.IsActive; MovieSettingsMenuItem.Enabled = Global.Emulator is NES && !Global.MovieSession.Movie.IsActive; - barcodeReaderToolStripMenuItem.Enabled = BarcodeEntry.HasReader(); + barcodeReaderToolStripMenuItem.Enabled = GlobalWin.Tools.IsAvailable(typeof(BarcodeEntry)); } private void FdsControlsMenuItem_DropDownOpened(object sender, EventArgs e) diff --git a/BizHawk.Client.EmuHawk/tools/NES/BarcodeEntry.cs b/BizHawk.Client.EmuHawk/tools/NES/BarcodeEntry.cs index 68eefedace..f8e0d99cfc 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/BarcodeEntry.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/BarcodeEntry.cs @@ -12,11 +12,11 @@ using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { + [RequiredServices(typeof(DatachBarcode))] public partial class BarcodeEntry : Form, IToolForm { - private DatachBarcode reader; - public IDictionary EmulatorServices { private get; set; } + private DatachBarcode reader { get { return (DatachBarcode)EmulatorServices[typeof(DatachBarcode)]; } } public BarcodeEntry() { @@ -35,28 +35,8 @@ namespace BizHawk.Client.EmuHawk { } - public static bool HasReader() - { - return GetReader() != null; - } - - private static DatachBarcode GetReader() - { - var nes = Global.Emulator as NES; - if (nes == null) - return null; - var board = nes.GetBoard() as BANDAI_FCG_1; - if (board == null) - return null; - var reader = board.reader; // will be null for non-datach FCG-1 games - return reader; - } - public void Restart() { - reader = GetReader(); - if (reader == null) - Close(); textBox1_TextChanged(null, null); } diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/DatachBarcode.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/DatachBarcode.cs index c94ecb8a50..fbbc7026b5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/DatachBarcode.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/DatachBarcode.cs @@ -2,15 +2,17 @@ using System.Collections.Generic; using System.Linq; using System.Text; + using BizHawk.Common.NumberExtensions; using BizHawk.Common; +using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.NES { // mostly jacked from nestopia's NstBoardBandaiDatach.cpp // very dirty, needs cleanup and such - public class DatachBarcode + public class DatachBarcode : IEmulatorService { static readonly byte[,] prefixParityType = new byte[10, 6] { diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 95de8f2e0d..c5c4a50439 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -50,6 +50,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES (board as FDS).SetDriveLightCallback((val) => DriveLightOn = val); } PutSettings((NESSettings)Settings ?? new NESSettings()); + + if (board is BANDAI_FCG_1) + { + (ServiceProvider as BasicServiceProvider).Register((board as BANDAI_FCG_1).reader); + } } public IEmulatorServiceProvider ServiceProvider { get; private set; }