NES - make DatachBarcode an emulator service, convert BarcodeEntry to EmulatorService

This commit is contained in:
adelikat 2014-12-14 02:01:38 +00:00
parent 5179a3379f
commit 1a1116c651
4 changed files with 11 additions and 24 deletions

View File

@ -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)

View File

@ -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<Type, object> 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);
}

View File

@ -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]
{

View File

@ -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<DatachBarcode>((board as BANDAI_FCG_1).reader);
}
}
public IEmulatorServiceProvider ServiceProvider { get; private set; }