Add an IDriveLight Emulator service, and remove the CoreComm properties, and refactor accordingly

This commit is contained in:
adelikat 2014-12-12 01:49:54 +00:00
parent f447ab907b
commit 08fb509a1a
12 changed files with 75 additions and 25 deletions

View File

@ -2422,14 +2422,16 @@ namespace BizHawk.Client.EmuHawk
{ {
if (MainStatusBar.Visible) if (MainStatusBar.Visible)
{ {
if (Global.Emulator.CoreComm.UsesDriveLed) var hasDriveLight = Global.Emulator.HasDriveLight() && Global.Emulator.AsDriveLight().DriveLightEnabled;
if (hasDriveLight)
{ {
if (!LedLightStatusLabel.Visible) if (!LedLightStatusLabel.Visible)
{ {
LedLightStatusLabel.Visible = true; LedLightStatusLabel.Visible = true;
} }
LedLightStatusLabel.Image = Global.Emulator.CoreComm.DriveLED LedLightStatusLabel.Image = Global.Emulator.AsDriveLight().DriveLightOn
? StatusBarDiskLightOnImage ? StatusBarDiskLightOnImage
: StatusBarDiskLightOffImage; : StatusBarDiskLightOffImage;
} }

View File

@ -72,6 +72,7 @@
<Compile Include="Interfaces\IController.cs" /> <Compile Include="Interfaces\IController.cs" />
<Compile Include="Interfaces\ICoreFileProvider.cs" /> <Compile Include="Interfaces\ICoreFileProvider.cs" />
<Compile Include="Interfaces\IDebuggable.cs" /> <Compile Include="Interfaces\IDebuggable.cs" />
<Compile Include="Interfaces\IDriveLight.cs" />
<Compile Include="Interfaces\IEmulator.cs" /> <Compile Include="Interfaces\IEmulator.cs" />
<Compile Include="Interfaces\IEmulatorService.cs" /> <Compile Include="Interfaces\IEmulatorService.cs" />
<Compile Include="Interfaces\IInputCallbackSystem.cs" /> <Compile Include="Interfaces\IInputCallbackSystem.cs" />

View File

@ -35,9 +35,6 @@ namespace BizHawk.Emulation.Common
public int NominalWidth = 640; public int NominalWidth = 640;
public int NominalHeight = 480; public int NominalHeight = 480;
public bool DriveLED = false;
public bool UsesDriveLed = false;
public bool LinkConnected = false; public bool LinkConnected = false;
public bool UsesLinkCable = false; public bool UsesLinkCable = false;

View File

@ -77,6 +77,21 @@ namespace BizHawk.Emulation.Common.IEmulatorExtensions
return (IInputPollable)core.ServiceProvider.GetService<IInputPollable>(); return (IInputPollable)core.ServiceProvider.GetService<IInputPollable>();
} }
public static bool HasDriveLight(this IEmulator core)
{
if (core == null)
{
return false;
}
return core.ServiceProvider.HasService<IDriveLight>();
}
public static IDriveLight AsDriveLight(this IEmulator core)
{
return (IDriveLight)core.ServiceProvider.GetService<IDriveLight>();
}
public static bool CanDebug(this IEmulator core) public static bool CanDebug(this IEmulator core)
{ {
if (core == null) if (core == null)

View File

@ -0,0 +1,18 @@
namespace BizHawk.Emulation.Common
{
/// <summary>
/// Specifies an interface to returning the state of a LED drive light such as on Disk and CD Drives
/// </summary>
public interface IDriveLight : IEmulatorService
{
/// <summary>
/// Specifies whether there is currently a Drive light available
/// </summary>
bool DriveLightEnabled { get; }
/// <summary>
/// Specifies whether the light is currently lit
/// </summary>
bool DriveLightOn { get; }
}
}

View File

@ -14,7 +14,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
isReleased: false isReleased: false
)] )]
[ServiceNotApplicable(typeof(ISettable<,>))] [ServiceNotApplicable(typeof(ISettable<,>))]
sealed public partial class C64 : IEmulator, IMemoryDomains, IStatable, IInputPollable sealed public partial class C64 : IEmulator, IMemoryDomains, IStatable, IInputPollable, IDriveLight
{ {
// internal variables // internal variables
private bool _islag = true; private bool _islag = true;
@ -84,11 +84,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
CoreComm = comm; CoreComm = comm;
Init(Region.PAL); Init(Region.PAL);
cyclesPerFrame = board.vic.CyclesPerFrame; cyclesPerFrame = board.vic.CyclesPerFrame;
CoreComm.UsesDriveLed = true;
SetupMemoryDomains(); SetupMemoryDomains();
HardReset(); HardReset();
} }
public bool DriveLightEnabled { get { return true; } }
public bool DriveLightOn { get; private set; }
public IEmulatorServiceProvider ServiceProvider { get; private set; } public IEmulatorServiceProvider ServiceProvider { get; private set; }
public void Dispose() public void Dispose()
@ -169,7 +171,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
//Console.WriteLine("CPUPC: " + C64Util.ToHex(board.cpu.PC, 4) + " 1541PC: " + C64Util.ToHex(disk.PC, 4)); //Console.WriteLine("CPUPC: " + C64Util.ToHex(board.cpu.PC, 4) + " 1541PC: " + C64Util.ToHex(disk.PC, 4));
int test = board.cpu.LagCycles; int test = board.cpu.LagCycles;
CoreComm.DriveLED = DriveLED; DriveLightOn = DriveLED;
} }
private void HandleFirmwareError(string file) private void HandleFirmwareError(string file)

View File

@ -46,8 +46,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
Init(game, rom, fdsbios); Init(game, rom, fdsbios);
if (board is FDS) if (board is FDS)
{ {
CoreComm.UsesDriveLed = true; DriveLightEnabled = true;
(board as FDS).SetDriveLightCallback((val) => CoreComm.DriveLED = val); (board as FDS).SetDriveLightCallback((val) => DriveLightOn = val);
} }
PutSettings((NESSettings)Settings ?? new NESSettings()); PutSettings((NESSettings)Settings ?? new NESSettings());
} }
@ -59,6 +59,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
BootGodDB.Initialize(); BootGodDB.Initialize();
} }
public bool DriveLightEnabled { get; private set; }
public bool DriveLightOn { get; private set; }
public void WriteLogTimestamp() public void WriteLogTimestamp()
{ {
if (ppu != null) if (ppu != null)

View File

@ -23,7 +23,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
isReleased: true isReleased: true
)] )]
public sealed partial class PCEngine : IEmulator, IMemoryDomains, ISaveRam, IStatable, IInputPollable, public sealed partial class PCEngine : IEmulator, IMemoryDomains, ISaveRam, IStatable, IInputPollable,
IDebuggable, ISettable<PCEngine.PCESettings, PCEngine.PCESyncSettings> IDebuggable, ISettable<PCEngine.PCESettings, PCEngine.PCESyncSettings>, IDriveLight
{ {
// ROM // ROM
public byte[] RomData; public byte[] RomData;
@ -102,7 +102,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
CoreComm = comm; CoreComm = comm;
Tracer = new TraceBuffer(); Tracer = new TraceBuffer();
MemoryCallbacks = new MemoryCallbackSystem(); MemoryCallbacks = new MemoryCallbackSystem();
CoreComm.UsesDriveLed = true; DriveLightEnabled = true;
systemid = "PCECD"; systemid = "PCECD";
Type = NecSystemType.TurboCD; Type = NecSystemType.TurboCD;
this.disc = disc; this.disc = disc;
@ -152,6 +152,9 @@ namespace BizHawk.Emulation.Cores.PCEngine
SetControllerButtons(); SetControllerButtons();
} }
public bool DriveLightEnabled { get; private set; }
public bool DriveLightOn { get; internal set; }
void Init(GameInfo game, byte[] rom) void Init(GameInfo game, byte[] rom)
{ {
Controller = NullController.GetNullController(); Controller = NullController.GetNullController();
@ -317,7 +320,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
public void FrameAdvance(bool render, bool rendersound) public void FrameAdvance(bool render, bool rendersound)
{ {
lagged = true; lagged = true;
CoreComm.DriveLED = false; DriveLightOn = false;
Frame++; Frame++;
CheckSpriteLimit(); CheckSpriteLimit();
PSG.BeginFrame(Cpu.TotalExecutedCycles); PSG.BeginFrame(Cpu.TotalExecutedCycles);

View File

@ -170,7 +170,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
if (DataReadInProgress && pce.Cpu.TotalExecutedCycles > DataReadWaitTimer) if (DataReadInProgress && pce.Cpu.TotalExecutedCycles > DataReadWaitTimer)
{ {
if (SectorsLeftToRead > 0) if (SectorsLeftToRead > 0)
pce.CoreComm.DriveLED = true; pce.DriveLightOn = true;
if (DataIn.Count == 0) if (DataIn.Count == 0)
{ {

View File

@ -24,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn
portedUrl: "http://yabause.org" portedUrl: "http://yabause.org"
)] )]
public class Yabause : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam, IStatable, IInputPollable, public class Yabause : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam, IStatable, IInputPollable,
ISettable<object, Yabause.SaturnSyncSettings> ISettable<object, Yabause.SaturnSyncSettings>, IDriveLight
{ {
public static ControllerDefinition SaturnController = new ControllerDefinition public static ControllerDefinition SaturnController = new ControllerDefinition
{ {
@ -77,13 +77,16 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn
InputCallbackH = new LibYabause.InputCallback(() => InputCallbacks.Call()); InputCallbackH = new LibYabause.InputCallback(() => InputCallbacks.Call());
LibYabause.libyabause_setinputcallback(InputCallbackH); LibYabause.libyabause_setinputcallback(InputCallbackH);
CoreComm.UsesDriveLed = true; DriveLightEnabled = true;
DeactivateGL(); DeactivateGL();
} }
public IEmulatorServiceProvider ServiceProvider { get; private set; } public IEmulatorServiceProvider ServiceProvider { get; private set; }
public bool DriveLightEnabled { get; private set; }
public bool DriveLightOn { get; private set; }
static object glContext; static object glContext;
void ActivateGL() void ActivateGL()
@ -275,7 +278,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn
LibYabause.libyabause_setpads(p11, p12, p21, p22); LibYabause.libyabause_setpads(p11, p12, p21, p22);
CoreComm.DriveLED = false; DriveLightOn = false;
IsLagFrame = LibYabause.libyabause_frameadvance(out w, out h, out nsamp); IsLagFrame = LibYabause.libyabause_frameadvance(out w, out h, out nsamp);
BufferWidth = w; BufferWidth = w;
@ -686,7 +689,7 @@ namespace BizHawk.Emulation.Cores.Sega.Saturn
return 0; // failure return 0; // failure
} }
Marshal.Copy(data, 0, dest, 2352); Marshal.Copy(data, 0, dest, 2352);
CoreComm.DriveLED = true; DriveLightOn = true;
return 1; // success return 1; // success
} }
/// <summary> /// <summary>

View File

@ -25,7 +25,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
portedUrl: "https://code.google.com/p/genplus-gx/" portedUrl: "https://code.google.com/p/genplus-gx/"
)] )]
public class GPGX : IEmulator, ISyncSoundProvider, IVideoProvider, IMemoryDomains, ISaveRam, IStatable, public class GPGX : IEmulator, ISyncSoundProvider, IVideoProvider, IMemoryDomains, ISaveRam, IStatable,
IInputPollable, IDebuggable, ISettable<GPGX.GPGXSettings, GPGX.GPGXSyncSettings> IInputPollable, IDebuggable, ISettable<GPGX.GPGXSettings, GPGX.GPGXSyncSettings>, IDriveLight
{ {
static GPGX AttachedCore = null; static GPGX AttachedCore = null;
@ -164,7 +164,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
LibGPGX.gpgx_set_input_callback(InputCallback); LibGPGX.gpgx_set_input_callback(InputCallback);
if (CD != null) if (CD != null)
CoreComm.UsesDriveLed = true; DriveLightEnabled = true;
PutSettings((GPGXSettings)Settings ?? new GPGXSettings()); PutSettings((GPGXSettings)Settings ?? new GPGXSettings());
@ -180,6 +180,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
public IEmulatorServiceProvider ServiceProvider { get; private set; } public IEmulatorServiceProvider ServiceProvider { get; private set; }
public bool DriveLightEnabled { get; private set;}
public bool DriveLightOn { get; private set; }
/// <summary> /// <summary>
/// core callback for file loading /// core callback for file loading
/// </summary> /// </summary>
@ -430,7 +433,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
LagCount++; LagCount++;
if (CD != null) if (CD != null)
CoreComm.DriveLED = drivelight; DriveLightOn = drivelight;
} }
public int Frame { get; private set; } public int Frame { get; private set; }

View File

@ -21,7 +21,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
isPorted: true, isPorted: true,
isReleased: false isReleased: false
)] )]
public unsafe class Octoshock : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam public unsafe class Octoshock : IEmulator, IVideoProvider, ISyncSoundProvider, IMemoryDomains, ISaveRam, IDriveLight
{ {
public string SystemId { get { return "PSX"; } } public string SystemId { get { return "PSX"; } }
@ -174,7 +174,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
ServiceProvider = new BasicServiceProvider(this); ServiceProvider = new BasicServiceProvider(this);
CoreComm = comm; CoreComm = comm;
CoreComm.UsesDriveLed = true; DriveLightEnabled = true;
Attach(); Attach();
@ -190,7 +190,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
{ {
//if current disc this delegate disc, activity is happening //if current disc this delegate disc, activity is happening
if (disc == this.disc) if (disc == this.disc)
CoreComm.DriveLED = true; DriveLightOn = true;
}); });
//determine region of the provided disc //determine region of the provided disc
@ -253,6 +253,9 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
public IEmulatorServiceProvider ServiceProvider { get; private set; } public IEmulatorServiceProvider ServiceProvider { get; private set; }
public bool DriveLightEnabled { get; private set; }
public bool DriveLightOn { get; private set; }
void Attach() void Attach()
{ {
//attach this core as the current //attach this core as the current
@ -309,7 +312,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
public void FrameAdvance(bool render, bool rendersound) public void FrameAdvance(bool render, bool rendersound)
{ {
Frame++; Frame++;
CoreComm.DriveLED = false; DriveLightOn = false;
SetInput(); SetInput();