From 7925b6f939b0c3a2e09d071b5f2c32cbc01237bc Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 13 Dec 2014 23:26:18 +0000 Subject: [PATCH] convert some gb tools to EmulatorServices --- BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs | 71 ++++++++----------- .../tools/GB/GBGameGenie.cs | 13 ++-- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs b/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs index 0a0808b039..5fabd2d153 100644 --- a/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs +++ b/BizHawk.Client.EmuHawk/tools/GB/GBGPUView.cs @@ -11,9 +11,11 @@ using System.Collections.Generic; namespace BizHawk.Client.EmuHawk { + [RequiredServices(typeof(Gameboy))] public partial class GBGPUView : Form, IToolForm { public IDictionary EmulatorServices { private get; set; } + private Gameboy Gb { get { return (Gameboy)EmulatorServices[typeof(Gameboy)]; } } // TODO: freeze semantics are a bit weird: details for a mouseover or freeze are taken from the current // state, not the state at the last callback (and so can be quite different when update is set to manual). @@ -30,8 +32,6 @@ namespace BizHawk.Client.EmuHawk // g' = 8.25g // b' = 8.25b - private Gameboy _gb; - // gambatte doesn't modify these memory locations unless you reconstruct, so we can store private IntPtr _vram; private IntPtr _bgpal; @@ -90,40 +90,31 @@ namespace BizHawk.Client.EmuHawk public void Restart() { - if (Global.Emulator is Gameboy) - { - _gb = Global.Emulator as Gameboy; - _cgb = _gb.IsCGBMode(); - _lcdc = 0; - if (!_gb.GetGPUMemoryAreas(out _vram, out _bgpal, out _sppal, out _oam)) - { - _gb = null; - if (Visible) - Close(); - } - tilespal = _bgpal; + _cgb = Gb.IsCGBMode(); + _lcdc = 0; - if (_cgb) - label4.Enabled = true; - else - label4.Enabled = false; - bmpViewBG.Clear(); - bmpViewWin.Clear(); - bmpViewTiles1.Clear(); - bmpViewTiles2.Clear(); - bmpViewBGPal.Clear(); - bmpViewSPPal.Clear(); - bmpViewOAM.Clear(); - bmpViewDetails.Clear(); - bmpViewMemory.Clear(); - cbscanline_emu = -4; // force refresh - } - else + // TODO: can this be a required Emulator Service, and let the tool manage the logic of closing? + if (!Gb.GetGPUMemoryAreas(out _vram, out _bgpal, out _sppal, out _oam)) { - _gb = null; if (Visible) Close(); } + tilespal = _bgpal; + + if (_cgb) + label4.Enabled = true; + else + label4.Enabled = false; + bmpViewBG.Clear(); + bmpViewWin.Clear(); + bmpViewTiles1.Clear(); + bmpViewTiles2.Clear(); + bmpViewBGPal.Clear(); + bmpViewSPPal.Clear(); + bmpViewOAM.Clear(); + bmpViewDetails.Clear(); + bmpViewMemory.Clear(); + cbscanline_emu = -4; // force refresh } @@ -484,11 +475,11 @@ namespace BizHawk.Client.EmuHawk private void GBGPUView_FormClosed(object sender, FormClosedEventArgs e) { - if (_gb != null) + if (Gb != null) { - _gb.SetScanlineCallback(null, 0); - _gb = null; + Gb.SetScanlineCallback(null, 0); } + Global.Config.GBGPUSpriteBack = spriteback; } @@ -536,8 +527,8 @@ namespace BizHawk.Client.EmuHawk private void buttonRefresh_Click(object sender, EventArgs e) { - if (cbscanline == -2 && _gb != null) - _gb.SetScanlineCallback(ScanlineCallback, -2); + if (cbscanline == -2 && Gb != null) + Gb.SetScanlineCallback(ScanlineCallback, -2); } private void hScrollBarScanline_ValueChanged(object sender, EventArgs e) @@ -564,14 +555,14 @@ namespace BizHawk.Client.EmuHawk { return; } - else if (_gb != null) + else if (Gb != null) { if (!Visible) { if (cbscanline_emu != -2) { cbscanline_emu = -2; - _gb.SetScanlineCallback(null, 0); + Gb.SetScanlineCallback(null, 0); } } else @@ -580,9 +571,9 @@ namespace BizHawk.Client.EmuHawk { cbscanline_emu = cbscanline; if (cbscanline == -2) - _gb.SetScanlineCallback(null, 0); + Gb.SetScanlineCallback(null, 0); else - _gb.SetScanlineCallback(ScanlineCallback, cbscanline); + Gb.SetScanlineCallback(ScanlineCallback, cbscanline); } } } diff --git a/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs b/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs index 4550532d1b..2c1bf7ea54 100644 --- a/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs +++ b/BizHawk.Client.EmuHawk/tools/GB/GBGameGenie.cs @@ -10,12 +10,15 @@ using BizHawk.Client.Common; namespace BizHawk.Client.EmuHawk { + [RequiredServices(typeof(IEmulator), typeof(IMemoryDomains))] public partial class GBGameGenie : Form, IToolForm { private readonly Dictionary _gameGenieTable = new Dictionary(); private bool _processing; public IDictionary EmulatorServices { private get; set; } + private IMemoryDomains Emulator { get { return (IMemoryDomains)EmulatorServices[typeof(IMemoryDomains)]; } } + private MemoryDomainList MemoryDomains { get { return (EmulatorServices[typeof(IMemoryDomains)] as IMemoryDomains).MemoryDomains; } } #region Public @@ -25,7 +28,7 @@ namespace BizHawk.Client.EmuHawk public void Restart() { - if ((Global.Emulator.SystemId != "GB") && (Global.Game.System != "GG")) + if ((Emulator.SystemId != "GB") && (Global.Game.System != "GG")) { Close(); } @@ -33,7 +36,7 @@ namespace BizHawk.Client.EmuHawk public void UpdateValues() { - if ((Global.Emulator.SystemId != "GB") && (Global.Game.System != "GG")) + if ((Emulator.SystemId != "GB") && (Global.Game.System != "GG")) { Close(); } @@ -190,7 +193,7 @@ namespace BizHawk.Client.EmuHawk } //"Game Boy/Game Gear Game Genie Encoder / Decoder" - if (Global.Emulator.SystemId == "GB") + if (Emulator.SystemId == "GB") { Text = "Game Boy Game Genie Encoder/Decoder"; } @@ -256,7 +259,7 @@ namespace BizHawk.Client.EmuHawk private void AddCheatClick(object sender, EventArgs e) { - if ((Global.Emulator.SystemId == "GB") || (Global.Game.System == "GG")) + if ((Emulator.SystemId == "GB") || (Global.Game.System == "GG")) { string name; var address = 0; @@ -299,7 +302,7 @@ namespace BizHawk.Client.EmuHawk } var watch = Watch.GenerateWatch( - Global.Emulator.AsMemoryDomains().MemoryDomains["System Bus"], + MemoryDomains["System Bus"], address, Watch.WatchSize.Byte, Watch.DisplayType.Hex,