Make a shim property in Mainform as a step towards reducing the use of Globals

This commit is contained in:
adelikat 2016-12-04 11:19:34 -06:00
parent 4ab2fadc93
commit 9135aea773
1 changed files with 120 additions and 114 deletions

View File

@ -288,7 +288,7 @@ namespace BizHawk.Client.EmuHawk
var comm = CreateCoreComm(); var comm = CreateCoreComm();
CoreFileProvider.SyncCoreCommInputSignals(comm); CoreFileProvider.SyncCoreCommInputSignals(comm);
Global.Emulator = new NullEmulator(comm, Global.Config.GetCoreSettings<NullEmulator>()); Emulator = new NullEmulator(comm, Global.Config.GetCoreSettings<NullEmulator>());
Global.ActiveController = new Controller(NullEmulator.NullController); Global.ActiveController = new Controller(NullEmulator.NullController);
Global.AutoFireController = Global.AutofireNullControls; Global.AutoFireController = Global.AutofireNullControls;
Global.AutofireStickyXORAdapter.SetOnOffPatternFromConfig(); Global.AutofireStickyXORAdapter.SetOnOffPatternFromConfig();
@ -497,7 +497,7 @@ namespace BizHawk.Client.EmuHawk
Global.ActiveController.LatchFromPhysical(Global.ControllerInputCoalescer); Global.ActiveController.LatchFromPhysical(Global.ControllerInputCoalescer);
Global.ActiveController.ApplyAxisConstraints( Global.ActiveController.ApplyAxisConstraints(
(Global.Emulator is N64 && Global.Config.N64UseCircularAnalogConstraint) ? "Natural Circle" : null); (Emulator is N64 && Global.Config.N64UseCircularAnalogConstraint) ? "Natural Circle" : null);
Global.ActiveController.OR_FromLogical(Global.ClickyVirtualPadController); Global.ActiveController.OR_FromLogical(Global.ClickyVirtualPadController);
Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer); Global.AutoFireController.LatchFromPhysical(Global.ControllerInputCoalescer);
@ -717,7 +717,13 @@ namespace BizHawk.Client.EmuHawk
return false; return false;
} }
// TODO: make this an actual property, set it when loading a Rom, and pass it dialogs, etc
// This is a quick hack to reduce the dependency on Global.Emulator
public IEmulator Emulator
{
get { return Global.Emulator; }
set { Global.Emulator = value; }
}
protected override void OnActivated(EventArgs e) protected override void OnActivated(EventArgs e)
{ {
@ -834,7 +840,7 @@ namespace BizHawk.Client.EmuHawk
// also handle floats // also handle floats
conInput.AcceptNewFloats(Input.Instance.GetFloats().Select(o => conInput.AcceptNewFloats(Input.Instance.GetFloats().Select(o =>
{ {
var video = Global.Emulator.VideoProvider(); var video = Emulator.VideoProvider();
// hackish // hackish
if (o.Item1 == "WMouse X") if (o.Item1 == "WMouse X")
{ {
@ -912,7 +918,7 @@ namespace BizHawk.Client.EmuHawk
public void TakeScreenshotClientToClipboard() public void TakeScreenshotClientToClipboard()
{ {
using (var bb = GlobalWin.DisplayManager.RenderOffscreen(Global.Emulator.AsVideoProvider(), Global.Config.Screenshot_CaptureOSD)) using (var bb = GlobalWin.DisplayManager.RenderOffscreen(Emulator.AsVideoProvider(), Global.Config.Screenshot_CaptureOSD))
{ {
using (var img = bb.ToSysdrawingBitmap()) using (var img = bb.ToSysdrawingBitmap())
Clipboard.SetImage(img); Clipboard.SetImage(img);
@ -962,7 +968,7 @@ namespace BizHawk.Client.EmuHawk
} }
/* /*
using (var fs = new FileStream(path + "_test.bmp", FileMode.OpenOrCreate, FileAccess.Write)) using (var fs = new FileStream(path + "_test.bmp", FileMode.OpenOrCreate, FileAccess.Write))
QuickBmpFile.Save(Global.Emulator.VideoProvider(), fs, r.Next(50, 500), r.Next(50, 500)); QuickBmpFile.Save(Emulator.VideoProvider(), fs, r.Next(50, 500), r.Next(50, 500));
*/ */
GlobalWin.OSD.AddMessage(fi.Name + " saved."); GlobalWin.OSD.AddMessage(fi.Name + " saved.");
} }
@ -973,8 +979,8 @@ namespace BizHawk.Client.EmuHawk
// run this entire thing exactly twice, since the first resize may adjust the menu stacking // run this entire thing exactly twice, since the first resize may adjust the menu stacking
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
var video = Global.Emulator.VideoProvider(); var video = Emulator.VideoProvider();
int zoom = Global.Config.TargetZoomFactors[Global.Emulator.SystemId]; int zoom = Global.Config.TargetZoomFactors[Emulator.SystemId];
var area = Screen.FromControl(this).WorkingArea; var area = Screen.FromControl(this).WorkingArea;
int borderWidth = Size.Width - PresentationPanel.Control.Size.Width; int borderWidth = Size.Width - PresentationPanel.Control.Size.Width;
@ -1179,13 +1185,13 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private static LibsnesCore AsSNES { get { return Global.Emulator as LibsnesCore; } } private LibsnesCore AsSNES { get { return Emulator as LibsnesCore; } }
// TODO: Clean Me! // TODO: Clean Me!
public void SNES_ToggleBG1(bool? setto = null) public void SNES_ToggleBG1(bool? setto = null)
{ {
if (!(Global.Emulator is LibsnesCore)) return; if (!(Emulator is LibsnesCore)) return;
var s = AsSNES.GetSettings(); var s = AsSNES.GetSettings();
if (setto.HasValue) if (setto.HasValue)
{ {
@ -1202,7 +1208,7 @@ namespace BizHawk.Client.EmuHawk
public void SNES_ToggleBG2(bool? setto = null) public void SNES_ToggleBG2(bool? setto = null)
{ {
if (!(Global.Emulator is LibsnesCore)) return; if (!(Emulator is LibsnesCore)) return;
var s = AsSNES.GetSettings(); var s = AsSNES.GetSettings();
if (setto.HasValue) if (setto.HasValue)
{ {
@ -1219,7 +1225,7 @@ namespace BizHawk.Client.EmuHawk
public void SNES_ToggleBG3(bool? setto = null) public void SNES_ToggleBG3(bool? setto = null)
{ {
if (!(Global.Emulator is LibsnesCore)) return; if (!(Emulator is LibsnesCore)) return;
var s = AsSNES.GetSettings(); var s = AsSNES.GetSettings();
if (setto.HasValue) if (setto.HasValue)
{ {
@ -1236,7 +1242,7 @@ namespace BizHawk.Client.EmuHawk
public void SNES_ToggleBG4(bool? setto = null) public void SNES_ToggleBG4(bool? setto = null)
{ {
if (!(Global.Emulator is LibsnesCore)) return; if (!(Emulator is LibsnesCore)) return;
var s = AsSNES.GetSettings(); var s = AsSNES.GetSettings();
if (setto.HasValue) if (setto.HasValue)
{ {
@ -1253,7 +1259,7 @@ namespace BizHawk.Client.EmuHawk
public void SNES_ToggleObj1(bool? setto = null) public void SNES_ToggleObj1(bool? setto = null)
{ {
if (!(Global.Emulator is LibsnesCore)) return; if (!(Emulator is LibsnesCore)) return;
var s = AsSNES.GetSettings(); var s = AsSNES.GetSettings();
if (setto.HasValue) if (setto.HasValue)
{ {
@ -1270,7 +1276,7 @@ namespace BizHawk.Client.EmuHawk
public void SNES_ToggleObj2(bool? setto = null) public void SNES_ToggleObj2(bool? setto = null)
{ {
if (!(Global.Emulator is LibsnesCore)) return; if (!(Emulator is LibsnesCore)) return;
var s = AsSNES.GetSettings(); var s = AsSNES.GetSettings();
if (setto.HasValue) if (setto.HasValue)
{ {
@ -1286,7 +1292,7 @@ namespace BizHawk.Client.EmuHawk
public void SNES_ToggleOBJ3(bool? setto = null) public void SNES_ToggleOBJ3(bool? setto = null)
{ {
if (!(Global.Emulator is LibsnesCore)) return; if (!(Emulator is LibsnesCore)) return;
var s = AsSNES.GetSettings(); var s = AsSNES.GetSettings();
if (setto.HasValue) if (setto.HasValue)
{ {
@ -1303,7 +1309,7 @@ namespace BizHawk.Client.EmuHawk
public void SNES_ToggleOBJ4(bool? setto = null) public void SNES_ToggleOBJ4(bool? setto = null)
{ {
if (!(Global.Emulator is LibsnesCore)) return; if (!(Emulator is LibsnesCore)) return;
var s = AsSNES.GetSettings(); var s = AsSNES.GetSettings();
if (setto.HasValue) if (setto.HasValue)
{ {
@ -1405,7 +1411,7 @@ namespace BizHawk.Client.EmuHawk
if (!string.IsNullOrEmpty(VersionInfo.CustomBuildString)) if (!string.IsNullOrEmpty(VersionInfo.CustomBuildString))
str += VersionInfo.CustomBuildString + " "; str += VersionInfo.CustomBuildString + " ";
if (Global.Emulator.IsNull()) if (Emulator.IsNull())
{ {
str = str + "BizHawk" + (VersionInfo.DeveloperBuild ? " (interim) " : string.Empty); str = str + "BizHawk" + (VersionInfo.DeveloperBuild ? " (interim) " : string.Empty);
} }
@ -1459,7 +1465,7 @@ namespace BizHawk.Client.EmuHawk
DumpStatusButton.Image = Properties.Resources.Blank; DumpStatusButton.Image = Properties.Resources.Blank;
DumpStatusButton.ToolTipText = string.Empty; DumpStatusButton.ToolTipText = string.Empty;
if (Global.Emulator.IsNull()) if (Emulator.IsNull())
{ {
return; return;
} }
@ -1511,17 +1517,17 @@ namespace BizHawk.Client.EmuHawk
annotation = "Verified good dump"; annotation = "Verified good dump";
} }
if (!string.IsNullOrEmpty(Global.Emulator.CoreComm.RomStatusAnnotation)) if (!string.IsNullOrEmpty(Emulator.CoreComm.RomStatusAnnotation))
{ {
annotation = Global.Emulator.CoreComm.RomStatusAnnotation; annotation = Emulator.CoreComm.RomStatusAnnotation;
} }
DumpStatusButton.ToolTipText = annotation; DumpStatusButton.ToolTipText = annotation;
} }
private static void LoadSaveRam() private void LoadSaveRam()
{ {
if (Global.Emulator.HasSaveRam()) if (Emulator.HasSaveRam())
{ {
try // zero says: this is sort of sketchy... but this is no time for rearchitecting try // zero says: this is sort of sketchy... but this is no time for rearchitecting
{ {
@ -1529,13 +1535,13 @@ namespace BizHawk.Client.EmuHawk
// GBA meteor core might not know how big the saveram ought to be, so just send it the whole file // GBA meteor core might not know how big the saveram ought to be, so just send it the whole file
// GBA vba-next core will try to eat anything, regardless of size // GBA vba-next core will try to eat anything, regardless of size
if (Global.Emulator is GBA || Global.Emulator is VBANext || Global.Emulator is MGBAHawk) if (Emulator is GBA || Emulator is VBANext || Emulator is MGBAHawk)
{ {
sram = File.ReadAllBytes(PathManager.SaveRamPath(Global.Game)); sram = File.ReadAllBytes(PathManager.SaveRamPath(Global.Game));
} }
else else
{ {
var oldram = Global.Emulator.AsSaveRam().CloneSaveRam(); var oldram = Emulator.AsSaveRam().CloneSaveRam();
if (oldram == null) if (oldram == null)
{ {
// we're eating this one now. the possible negative consequence is that a user could lose // we're eating this one now. the possible negative consequence is that a user could lose
@ -1552,7 +1558,7 @@ namespace BizHawk.Client.EmuHawk
} }
} }
Global.Emulator.AsSaveRam().StoreSaveRam(sram); Emulator.AsSaveRam().StoreSaveRam(sram);
} }
catch (IOException) catch (IOException)
{ {
@ -1561,9 +1567,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private static void SaveRam() private void SaveRam()
{ {
if (Global.Emulator.HasSaveRam()) if (Emulator.HasSaveRam())
{ {
var path = PathManager.SaveRamPath(Global.Game); var path = PathManager.SaveRamPath(Global.Game);
var f = new FileInfo(path); var f = new FileInfo(path);
@ -1586,7 +1592,7 @@ namespace BizHawk.Client.EmuHawk
} }
var writer = new BinaryWriter(new FileStream(path, FileMode.Create, FileAccess.Write)); var writer = new BinaryWriter(new FileStream(path, FileMode.Create, FileAccess.Write));
var saveram = Global.Emulator.AsSaveRam().CloneSaveRam(); var saveram = Emulator.AsSaveRam().CloneSaveRam();
writer.Write(saveram, 0, saveram.Length); writer.Write(saveram, 0, saveram.Length);
writer.Close(); writer.Close();
@ -1603,8 +1609,8 @@ namespace BizHawk.Client.EmuHawk
} }
else else
{ {
Global.Emulator.EndAsyncSound(); Emulator.EndAsyncSound();
GlobalWin.Sound.SetSyncInputPin(Global.Emulator.SyncSoundProvider); GlobalWin.Sound.SetSyncInputPin(Emulator.SyncSoundProvider);
} }
} }
@ -1615,7 +1621,7 @@ namespace BizHawk.Client.EmuHawk
{ {
//New Code //New Code
//We use SystemID as that has the system we are playing on. //We use SystemID as that has the system we are playing on.
system = Global.Emulator.SystemId; system = Emulator.SystemId;
//Old Code below. //Old Code below.
//system = Global.Game.System; //system = Global.Game.System;
@ -1684,9 +1690,9 @@ namespace BizHawk.Client.EmuHawk
case "SNES": case "SNES":
case "SGB": case "SGB":
// TODO: fix SNES9x here // TODO: fix SNES9x here
if (Global.Emulator is LibsnesCore) if (Emulator is LibsnesCore)
{ {
if ((Global.Emulator as LibsnesCore).IsSGB) if ((Emulator as LibsnesCore).IsSGB)
{ {
SNESSubMenu.Text = "&SGB"; SNESSubMenu.Text = "&SGB";
} }
@ -1728,7 +1734,7 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private static void InitControls() private void InitControls()
{ {
var controls = new Controller( var controls = new Controller(
new ControllerDefinition new ControllerDefinition
@ -1743,7 +1749,7 @@ namespace BizHawk.Client.EmuHawk
} }
Global.ClientControls = controls; Global.ClientControls = controls;
Global.AutofireNullControls = new AutofireController(NullEmulator.NullController, Global.Emulator); Global.AutofireNullControls = new AutofireController(NullEmulator.NullController, Emulator);
} }
@ -1832,7 +1838,7 @@ namespace BizHawk.Client.EmuHawk
Global.DisableSecondaryThrottling = _unthrottled || turbo || fastForward || rewind; Global.DisableSecondaryThrottling = _unthrottled || turbo || fastForward || rewind;
// realtime throttle is never going to be so exact that using a double here is wrong // realtime throttle is never going to be so exact that using a double here is wrong
_throttle.SetCoreFps(Global.Emulator.CoreComm.VsyncRate); _throttle.SetCoreFps(Emulator.CoreComm.VsyncRate);
_throttle.signal_paused = EmulatorPaused; _throttle.signal_paused = EmulatorPaused;
_throttle.signal_unthrottle = _unthrottled || turbo; _throttle.signal_unthrottle = _unthrottled || turbo;
//zero 26-mar-2016 - vsync and vsync throttle here both is odd, but see comments elsewhere about triple buffering //zero 26-mar-2016 - vsync and vsync throttle here both is odd, but see comments elsewhere about triple buffering
@ -1893,9 +1899,9 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private static BitmapBuffer MakeScreenshotImage() private BitmapBuffer MakeScreenshotImage()
{ {
return GlobalWin.DisplayManager.RenderVideoProvider(Global.Emulator.AsVideoProvider()); return GlobalWin.DisplayManager.RenderVideoProvider(Emulator.AsVideoProvider());
} }
private void SaveSlotSelectedMessage() private void SaveSlotSelectedMessage()
@ -1913,7 +1919,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
//private Size _lastVideoSize = new Size(-1, -1), _lastVirtualSize = new Size(-1, -1); //private Size _lastVideoSize = new Size(-1, -1), _lastVirtualSize = new Size(-1, -1);
var video = Global.Emulator.VideoProvider(); var video = Emulator.VideoProvider();
//bool change = false; //bool change = false;
Size currVideoSize = new Size(video.BufferWidth, video.BufferHeight); Size currVideoSize = new Size(video.BufferWidth, video.BufferHeight);
Size currVirtualSize = new Size(video.VirtualWidth, video.VirtualHeight); Size currVirtualSize = new Size(video.VirtualWidth, video.VirtualHeight);
@ -2029,7 +2035,7 @@ namespace BizHawk.Client.EmuHawk
{ {
var ofd = new OpenFileDialog var ofd = new OpenFileDialog
{ {
InitialDirectory = PathManager.GetRomsPath(Global.Emulator.SystemId), InitialDirectory = PathManager.GetRomsPath(Emulator.SystemId),
Filter = RomFilter, Filter = RomFilter,
RestoreDirectory = false, RestoreDirectory = false,
FilterIndex = _lastOpenRomFilter FilterIndex = _lastOpenRomFilter
@ -2090,7 +2096,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
public void PutCoreSettings(object o) public void PutCoreSettings(object o)
{ {
var settable = new SettingsAdapter(Global.Emulator); var settable = new SettingsAdapter(Emulator);
if (settable.HasSettings && settable.PutSettings(o)) if (settable.HasSettings && settable.PutSettings(o))
{ {
FlagNeedsReboot(); FlagNeedsReboot();
@ -2102,7 +2108,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
public void PutCoreSyncSettings(object o) public void PutCoreSyncSettings(object o)
{ {
var settable = new SettingsAdapter(Global.Emulator); var settable = new SettingsAdapter(Emulator);
if (Global.MovieSession.Movie.IsActive) if (Global.MovieSession.Movie.IsActive)
{ {
GlobalWin.OSD.AddMessage("Attempt to change sync-relevant settings while recording BLOCKED."); GlobalWin.OSD.AddMessage("Attempt to change sync-relevant settings while recording BLOCKED.");
@ -2195,10 +2201,10 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.OSD.AddMessage("Volume " + Global.Config.SoundVolume); GlobalWin.OSD.AddMessage("Volume " + Global.Config.SoundVolume);
} }
private static void SoftReset() private void SoftReset()
{ {
// is it enough to run this for one frame? maybe.. // is it enough to run this for one frame? maybe..
if (Global.Emulator.ControllerDefinition.BoolButtons.Contains("Reset")) if (Emulator.ControllerDefinition.BoolButtons.Contains("Reset"))
{ {
if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished) if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished)
{ {
@ -2208,10 +2214,10 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private static void HardReset() private void HardReset()
{ {
// is it enough to run this for one frame? maybe.. // is it enough to run this for one frame? maybe..
if (Global.Emulator.ControllerDefinition.BoolButtons.Contains("Power")) if (Emulator.ControllerDefinition.BoolButtons.Contains("Power"))
{ {
if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished) if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished)
{ {
@ -2258,67 +2264,67 @@ namespace BizHawk.Client.EmuHawk
Slot7StatusButton.Visible = Slot7StatusButton.Visible =
Slot8StatusButton.Visible = Slot8StatusButton.Visible =
Slot9StatusButton.Visible = Slot9StatusButton.Visible =
Global.Emulator.HasSavestates(); Emulator.HasSavestates();
} }
public BitmapBuffer CaptureOSD() public BitmapBuffer CaptureOSD()
{ {
var bb = GlobalWin.DisplayManager.RenderOffscreen(Global.Emulator.AsVideoProvider(), true); var bb = GlobalWin.DisplayManager.RenderOffscreen(Emulator.AsVideoProvider(), true);
bb.DiscardAlpha(); bb.DiscardAlpha();
return bb; return bb;
} }
private void IncreaseWindowSize() private void IncreaseWindowSize()
{ {
switch (Global.Config.TargetZoomFactors[Global.Emulator.SystemId]) switch (Global.Config.TargetZoomFactors[Emulator.SystemId])
{ {
case 1: case 1:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 2; Global.Config.TargetZoomFactors[Emulator.SystemId] = 2;
break; break;
case 2: case 2:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 3; Global.Config.TargetZoomFactors[Emulator.SystemId] = 3;
break; break;
case 3: case 3:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 4; Global.Config.TargetZoomFactors[Emulator.SystemId] = 4;
break; break;
case 4: case 4:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 5; Global.Config.TargetZoomFactors[Emulator.SystemId] = 5;
break; break;
case 5: case 5:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 10; Global.Config.TargetZoomFactors[Emulator.SystemId] = 10;
break; break;
case 10: case 10:
return; return;
} }
GlobalWin.OSD.AddMessage("Screensize set to " + Global.Config.TargetZoomFactors[Global.Emulator.SystemId] + "x"); GlobalWin.OSD.AddMessage("Screensize set to " + Global.Config.TargetZoomFactors[Emulator.SystemId] + "x");
FrameBufferResized(); FrameBufferResized();
} }
private void DecreaseWindowSize() private void DecreaseWindowSize()
{ {
switch (Global.Config.TargetZoomFactors[Global.Emulator.SystemId]) switch (Global.Config.TargetZoomFactors[Emulator.SystemId])
{ {
case 1: case 1:
return; return;
case 2: case 2:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 1; Global.Config.TargetZoomFactors[Emulator.SystemId] = 1;
break; break;
case 3: case 3:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 2; Global.Config.TargetZoomFactors[Emulator.SystemId] = 2;
break; break;
case 4: case 4:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 3; Global.Config.TargetZoomFactors[Emulator.SystemId] = 3;
break; break;
case 5: case 5:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 4; Global.Config.TargetZoomFactors[Emulator.SystemId] = 4;
break; break;
case 10: case 10:
Global.Config.TargetZoomFactors[Global.Emulator.SystemId] = 5; Global.Config.TargetZoomFactors[Emulator.SystemId] = 5;
return; return;
} }
GlobalWin.OSD.AddMessage("Screensize set to " + Global.Config.TargetZoomFactors[Global.Emulator.SystemId] + "x"); GlobalWin.OSD.AddMessage("Screensize set to " + Global.Config.TargetZoomFactors[Emulator.SystemId] + "x");
FrameBufferResized(); FrameBufferResized();
} }
@ -2485,7 +2491,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (MainStatusBar.Visible) if (MainStatusBar.Visible)
{ {
var hasDriveLight = Global.Emulator.HasDriveLight() && Global.Emulator.AsDriveLight().DriveLightEnabled; var hasDriveLight = Emulator.HasDriveLight() && Emulator.AsDriveLight().DriveLightEnabled;
if (hasDriveLight) if (hasDriveLight)
{ {
@ -2494,7 +2500,7 @@ namespace BizHawk.Client.EmuHawk
LedLightStatusLabel.Visible = true; LedLightStatusLabel.Visible = true;
} }
LedLightStatusLabel.Image = Global.Emulator.AsDriveLight().DriveLightOn LedLightStatusLabel.Image = Emulator.AsDriveLight().DriveLightOn
? StatusBarDiskLightOnImage ? StatusBarDiskLightOnImage
: StatusBarDiskLightOffImage; : StatusBarDiskLightOffImage;
} }
@ -2506,14 +2512,14 @@ namespace BizHawk.Client.EmuHawk
} }
} }
if (Global.Emulator.UsesLinkCable()) if (Emulator.UsesLinkCable())
{ {
if (!LinkConnectStatusBarButton.Visible) if (!LinkConnectStatusBarButton.Visible)
{ {
LinkConnectStatusBarButton.Visible = true; LinkConnectStatusBarButton.Visible = true;
} }
LinkConnectStatusBarButton.Image = Global.Emulator.AsLinkable().LinkConnected LinkConnectStatusBarButton.Image = Emulator.AsLinkable().LinkConnected
? LinkCableOn ? LinkCableOn
: LinkCableOff; : LinkCableOff;
} }
@ -2589,7 +2595,7 @@ namespace BizHawk.Client.EmuHawk
{ {
FDSControlsMenuItem.DropDownItems.Add(name, null, delegate FDSControlsMenuItem.DropDownItems.Add(name, null, delegate
{ {
if (Global.Emulator.ControllerDefinition.BoolButtons.Contains(button)) if (Emulator.ControllerDefinition.BoolButtons.Contains(button))
{ {
if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished) if (!Global.MovieSession.Movie.IsPlaying || Global.MovieSession.Movie.IsFinished)
{ {
@ -2633,17 +2639,17 @@ namespace BizHawk.Client.EmuHawk
private void UpdateCoreStatusBarButton() private void UpdateCoreStatusBarButton()
{ {
if (Global.Emulator.IsNull()) if (Emulator.IsNull())
{ {
CoreNameStatusBarButton.Visible = false; CoreNameStatusBarButton.Visible = false;
return; return;
} }
CoreNameStatusBarButton.Visible = true; CoreNameStatusBarButton.Visible = true;
var attributes = Global.Emulator.Attributes(); var attributes = Emulator.Attributes();
CoreNameStatusBarButton.Text = Global.Emulator.DisplayName(); CoreNameStatusBarButton.Text = Emulator.DisplayName();
CoreNameStatusBarButton.Image = Global.Emulator.Icon(); CoreNameStatusBarButton.Image = Emulator.Icon();
CoreNameStatusBarButton.ToolTipText = attributes.Ported ? "(ported) " : string.Empty; CoreNameStatusBarButton.ToolTipText = attributes.Ported ? "(ported) " : string.Empty;
} }
@ -2670,9 +2676,9 @@ namespace BizHawk.Client.EmuHawk
{ {
get get
{ {
if (Global.Emulator.CanPollInput()) if (Emulator.CanPollInput())
{ {
return Global.Emulator.AsInputPollable().IsLagFrame; return Emulator.AsInputPollable().IsLagFrame;
} }
return false; return false;
@ -2689,7 +2695,7 @@ namespace BizHawk.Client.EmuHawk
double frameAdvanceTimestampDeltaMs = (double)(currentTimestamp - _frameAdvanceTimestamp) / Stopwatch.Frequency * 1000.0; double frameAdvanceTimestampDeltaMs = (double)(currentTimestamp - _frameAdvanceTimestamp) / Stopwatch.Frequency * 1000.0;
bool frameProgressTimeElapsed = frameAdvanceTimestampDeltaMs >= Global.Config.FrameProgressDelayMs; bool frameProgressTimeElapsed = frameAdvanceTimestampDeltaMs >= Global.Config.FrameProgressDelayMs;
if (Global.Config.SkipLagFrame && IsLagFrame && frameProgressTimeElapsed && Global.Emulator.Frame > 0) if (Global.Config.SkipLagFrame && IsLagFrame && frameProgressTimeElapsed && Emulator.Frame > 0)
{ {
runFrame = true; runFrame = true;
} }
@ -2798,7 +2804,7 @@ namespace BizHawk.Client.EmuHawk
renderSound |= (_currAviWriter != null && _currAviWriter.UsesAudio); renderSound |= (_currAviWriter != null && _currAviWriter.UsesAudio);
bool render = !_throttle.skipnextframe || (_currAviWriter != null && _currAviWriter.UsesVideo); bool render = !_throttle.skipnextframe || (_currAviWriter != null && _currAviWriter.UsesVideo);
Global.Emulator.FrameAdvance(render, renderSound); Emulator.FrameAdvance(render, renderSound);
Global.MovieSession.HandleMovieAfterFrameLoop(); Global.MovieSession.HandleMovieAfterFrameLoop();
@ -2833,12 +2839,12 @@ namespace BizHawk.Client.EmuHawk
} }
if (GlobalWin.Tools.IsLoaded<TAStudio>() && if (GlobalWin.Tools.IsLoaded<TAStudio>() &&
GlobalWin.Tools.TAStudio.LastPositionFrame == Global.Emulator.Frame) GlobalWin.Tools.TAStudio.LastPositionFrame == Emulator.Frame)
{ {
if (PauseOnFrame.HasValue && if (PauseOnFrame.HasValue &&
PauseOnFrame.Value <= GlobalWin.Tools.TAStudio.LastPositionFrame) PauseOnFrame.Value <= GlobalWin.Tools.TAStudio.LastPositionFrame)
{ {
TasMovieRecord record = (Global.MovieSession.Movie as TasMovie)[Global.Emulator.Frame]; TasMovieRecord record = (Global.MovieSession.Movie as TasMovie)[Emulator.Frame];
if (!record.Lagged.HasValue && IsSeeking) if (!record.Lagged.HasValue && IsSeeking)
// haven't yet greenzoned the frame, hence it's after editing // haven't yet greenzoned the frame, hence it's after editing
// then we want to pause here. taseditor fasion // then we want to pause here. taseditor fasion
@ -2846,7 +2852,7 @@ namespace BizHawk.Client.EmuHawk
} }
} }
if (IsSeeking && Global.Emulator.Frame == PauseOnFrame.Value) if (IsSeeking && Emulator.Frame == PauseOnFrame.Value)
{ {
PauseEmulator(); PauseEmulator();
PauseOnFrame = null; PauseOnFrame = null;
@ -2977,14 +2983,14 @@ namespace BizHawk.Client.EmuHawk
aw = new AudioStretcher(aw); aw = new AudioStretcher(aw);
} }
aw.SetMovieParameters(Global.Emulator.CoreComm.VsyncNum, Global.Emulator.CoreComm.VsyncDen); aw.SetMovieParameters(Emulator.CoreComm.VsyncNum, Emulator.CoreComm.VsyncDen);
if (_avwriterResizew > 0 && _avwriterResizeh > 0) if (_avwriterResizew > 0 && _avwriterResizeh > 0)
{ {
aw.SetVideoParameters(_avwriterResizew, _avwriterResizeh); aw.SetVideoParameters(_avwriterResizew, _avwriterResizeh);
} }
else else
{ {
var videoProvider = Global.Emulator.AsVideoProvider(); var videoProvider = Emulator.AsVideoProvider();
aw.SetVideoParameters(videoProvider.BufferWidth, videoProvider.BufferHeight); aw.SetVideoParameters(videoProvider.BufferWidth, videoProvider.BufferHeight);
} }
@ -3080,13 +3086,13 @@ namespace BizHawk.Client.EmuHawk
if (_dumpaudiosync) if (_dumpaudiosync)
{ {
Global.Emulator.EndAsyncSound(); Emulator.EndAsyncSound();
} }
else else
{ {
_aviSoundInput = !Global.Emulator.StartAsyncSound() _aviSoundInput = !Emulator.StartAsyncSound()
? new MetaspuAsync(Global.Emulator.SyncSoundProvider, ESynchMethod.ESynchMethod_V) ? new MetaspuAsync(Emulator.SyncSoundProvider, ESynchMethod.ESynchMethod_V)
: Global.Emulator.SoundProvider; : Emulator.SoundProvider;
} }
_dumpProxy = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V); _dumpProxy = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V);
RewireSound(); RewireSound();
@ -3143,7 +3149,7 @@ namespace BizHawk.Client.EmuHawk
//is this the best time to handle this? or deeper inside? //is this the best time to handle this? or deeper inside?
if (_currAviWriterFrameList != null) if (_currAviWriterFrameList != null)
{ {
if (!_currAviWriterFrameList.Contains(Global.Emulator.Frame)) if (!_currAviWriterFrameList.Contains(Emulator.Frame))
goto HANDLE_AUTODUMP; goto HANDLE_AUTODUMP;
} }
@ -3162,7 +3168,7 @@ namespace BizHawk.Client.EmuHawk
} }
else else
{ {
var videoProvider = Global.Emulator.AsVideoProvider(); var videoProvider = Emulator.AsVideoProvider();
bbin = new BitmapBuffer(videoProvider.BufferWidth, videoProvider.BufferHeight, videoProvider.GetVideoBuffer()); bbin = new BitmapBuffer(videoProvider.BufferWidth, videoProvider.BufferHeight, videoProvider.GetVideoBuffer());
} }
@ -3174,7 +3180,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (_avwriterpad) if (_avwriterpad)
{ {
g.Clear(Color.FromArgb(Global.Emulator.AsVideoProvider().BackgroundColor)); g.Clear(Color.FromArgb(Emulator.AsVideoProvider().BackgroundColor));
g.DrawImageUnscaled(bmpin, (bmpout.Width - bmpin.Width) / 2, (bmpout.Height - bmpin.Height) / 2); g.DrawImageUnscaled(bmpin, (bmpout.Width - bmpin.Width) / 2, (bmpout.Height - bmpin.Height) / 2);
} }
else else
@ -3202,16 +3208,16 @@ namespace BizHawk.Client.EmuHawk
disposableOutput = (IDisposable)output; disposableOutput = (IDisposable)output;
} }
else else
output = Global.Emulator.AsVideoProvider(); output = Emulator.AsVideoProvider();
} }
_currAviWriter.SetFrame(Global.Emulator.Frame); _currAviWriter.SetFrame(Emulator.Frame);
short[] samp; short[] samp;
int nsamp; int nsamp;
if (_dumpaudiosync) if (_dumpaudiosync)
{ {
(_currAviWriter as VideoStretcher).DumpAV(output, Global.Emulator.SyncSoundProvider, out samp, out nsamp); (_currAviWriter as VideoStretcher).DumpAV(output, Emulator.SyncSoundProvider, out samp, out nsamp);
} }
else else
{ {
@ -3411,12 +3417,12 @@ namespace BizHawk.Client.EmuHawk
if (result) if (result)
{ {
Global.Emulator = loader.LoadedEmulator; Emulator = loader.LoadedEmulator;
Global.Game = loader.Game; Global.Game = loader.Game;
CoreFileProvider.SyncCoreCommInputSignals(nextComm); CoreFileProvider.SyncCoreCommInputSignals(nextComm);
InputManager.SyncControls(); InputManager.SyncControls();
if (Global.Emulator is TI83 && Global.Config.TI83autoloadKeyPad) if (Emulator is TI83 && Global.Config.TI83autoloadKeyPad)
{ {
GlobalWin.Tools.Load<TI83KeyPad>(); GlobalWin.Tools.Load<TI83KeyPad>();
} }
@ -3446,18 +3452,18 @@ namespace BizHawk.Client.EmuHawk
Global.Rewinder.ResetRewindBuffer(); Global.Rewinder.ResetRewindBuffer();
if (Global.Emulator.CoreComm.RomStatusDetails == null && loader.Rom != null) if (Emulator.CoreComm.RomStatusDetails == null && loader.Rom != null)
{ {
Global.Emulator.CoreComm.RomStatusDetails = string.Format( Emulator.CoreComm.RomStatusDetails = string.Format(
"{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n", "{0}\r\nSHA1:{1}\r\nMD5:{2}\r\n",
loader.Game.Name, loader.Game.Name,
loader.Rom.RomData.HashSHA1(), loader.Rom.RomData.HashSHA1(),
loader.Rom.RomData.HashMD5()); loader.Rom.RomData.HashMD5());
} }
if (Global.Emulator.BoardName != null) if (Emulator.BoardName != null)
{ {
Console.WriteLine("Core reported BoardID: \"{0}\"", Global.Emulator.BoardName); Console.WriteLine("Core reported BoardID: \"{0}\"", Emulator.BoardName);
} }
// restarts the lua console if a different rom is loaded. // restarts the lua console if a different rom is loaded.
@ -3531,7 +3537,7 @@ namespace BizHawk.Client.EmuHawk
// TODO: put all these in a single method or something // TODO: put all these in a single method or something
//The ROM has been loaded by a recursive invocation of the LoadROM method. //The ROM has been loaded by a recursive invocation of the LoadROM method.
if (!(Global.Emulator is NullEmulator)) if (!(Emulator is NullEmulator))
{ {
ApiHawk.ClientApi.OnRomLoaded(); ApiHawk.ClientApi.OnRomLoaded();
return true; return true;
@ -3558,11 +3564,11 @@ namespace BizHawk.Client.EmuHawk
private string CurrentlyOpenRomPoopForAdvancedLoaderPleaseRefactorME = ""; private string CurrentlyOpenRomPoopForAdvancedLoaderPleaseRefactorME = "";
private static void CommitCoreSettingsToConfig() private void CommitCoreSettingsToConfig()
{ {
// save settings object // save settings object
var t = Global.Emulator.GetType(); var t = Emulator.GetType();
var settable = new SettingsAdapter(Global.Emulator); var settable = new SettingsAdapter(Emulator);
if (settable.HasSettings) if (settable.HasSettings)
{ {
@ -3592,7 +3598,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.OSD.AddMessage("SRAM cleared."); GlobalWin.OSD.AddMessage("SRAM cleared.");
} }
} }
else if (Global.Emulator.HasSaveRam() && Global.Emulator.AsSaveRam().SaveRamModified) else if (Emulator.HasSaveRam() && Emulator.AsSaveRam().SaveRamModified)
{ {
SaveRam(); SaveRam();
} }
@ -3609,10 +3615,10 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Tools.Get<TraceLogger>().Restart(); GlobalWin.Tools.Get<TraceLogger>().Restart();
Global.CheatList.SaveOnClose(); Global.CheatList.SaveOnClose();
Global.Emulator.Dispose(); Emulator.Dispose();
var coreComm = CreateCoreComm(); var coreComm = CreateCoreComm();
CoreFileProvider.SyncCoreCommInputSignals(coreComm); CoreFileProvider.SyncCoreCommInputSignals(coreComm);
Global.Emulator = new NullEmulator(coreComm, Global.Config.GetCoreSettings<NullEmulator>()); Emulator = new NullEmulator(coreComm, Global.Config.GetCoreSettings<NullEmulator>());
Global.ActiveController = new Controller(NullEmulator.NullController); Global.ActiveController = new Controller(NullEmulator.NullController);
Global.AutoFireController = Global.AutofireNullControls; Global.AutoFireController = Global.AutofireNullControls;
RewireSound(); RewireSound();
@ -3631,7 +3637,7 @@ namespace BizHawk.Client.EmuHawk
CloseGame(clearSram); CloseGame(clearSram);
var coreComm = CreateCoreComm(); var coreComm = CreateCoreComm();
CoreFileProvider.SyncCoreCommInputSignals(coreComm); CoreFileProvider.SyncCoreCommInputSignals(coreComm);
Global.Emulator = new NullEmulator(coreComm, Global.Config.GetCoreSettings<NullEmulator>()); Emulator = new NullEmulator(coreComm, Global.Config.GetCoreSettings<NullEmulator>());
Global.Game = GameInfo.NullInstance; Global.Game = GameInfo.NullInstance;
GlobalWin.Tools.Restart(); GlobalWin.Tools.Restart();
@ -3709,7 +3715,7 @@ namespace BizHawk.Client.EmuHawk
public void LoadState(string path, string userFriendlyStateName, bool fromLua = false, bool supressOSD = false) // Move to client.common public void LoadState(string path, string userFriendlyStateName, bool fromLua = false, bool supressOSD = false) // Move to client.common
{ {
if (!Global.Emulator.HasSavestates()) if (!Emulator.HasSavestates())
{ {
return; return;
} }
@ -3757,7 +3763,7 @@ namespace BizHawk.Client.EmuHawk
public void LoadQuickSave(string quickSlotName, bool fromLua = false, bool supressOSD = false) public void LoadQuickSave(string quickSlotName, bool fromLua = false, bool supressOSD = false)
{ {
if (!Global.Emulator.HasSavestates()) if (!Emulator.HasSavestates())
{ {
return; return;
} }
@ -3788,7 +3794,7 @@ namespace BizHawk.Client.EmuHawk
public void SaveState(string path, string userFriendlyStateName, bool fromLua) public void SaveState(string path, string userFriendlyStateName, bool fromLua)
{ {
if (!Global.Emulator.HasSavestates()) if (!Emulator.HasSavestates())
{ {
return; return;
} }
@ -3820,7 +3826,7 @@ namespace BizHawk.Client.EmuHawk
// TODO: should backup logic be stuffed in into Client.Common.SaveStateManager? // TODO: should backup logic be stuffed in into Client.Common.SaveStateManager?
public void SaveQuickSave(string quickSlotName) public void SaveQuickSave(string quickSlotName)
{ {
if (!Global.Emulator.HasSavestates()) if (!Emulator.HasSavestates())
{ {
return; return;
} }
@ -3860,7 +3866,7 @@ namespace BizHawk.Client.EmuHawk
private void SaveStateAs() private void SaveStateAs()
{ {
if (!Global.Emulator.HasSavestates()) if (!Emulator.HasSavestates())
{ {
return; return;
} }
@ -3897,7 +3903,7 @@ namespace BizHawk.Client.EmuHawk
private void LoadStateAs() private void LoadStateAs()
{ {
if (!Global.Emulator.HasSavestates()) if (!Emulator.HasSavestates())
{ {
return; return;
} }
@ -3931,7 +3937,7 @@ namespace BizHawk.Client.EmuHawk
private void SelectSlot(int slot) private void SelectSlot(int slot)
{ {
if (Global.Emulator.HasSavestates()) if (Emulator.HasSavestates())
{ {
if (IsSlave && master.WantsToControlSavestates) if (IsSlave && master.WantsToControlSavestates)
{ {
@ -3947,7 +3953,7 @@ namespace BizHawk.Client.EmuHawk
private void PreviousSlot() private void PreviousSlot()
{ {
if (Global.Emulator.HasSavestates()) if (Emulator.HasSavestates())
{ {
if (IsSlave && master.WantsToControlSavestates) if (IsSlave && master.WantsToControlSavestates)
{ {
@ -3975,7 +3981,7 @@ namespace BizHawk.Client.EmuHawk
private void NextSlot() private void NextSlot()
{ {
if (Global.Emulator.HasSavestates()) if (Emulator.HasSavestates())
{ {
if (IsSlave && master.WantsToControlSavestates) if (IsSlave && master.WantsToControlSavestates)
{ {