From 665b3317979c89640eed4e120ee8e0758360d4d0 Mon Sep 17 00:00:00 2001 From: adelikat Date: Tue, 18 Feb 2020 10:42:14 -0600 Subject: [PATCH] simplify AmstradCPC constructor and related code --- .../AmstradCPC/AmstradCPC.InputPollable.cs | 2 +- .../Computers/AmstradCPC/AmstradCPC.cs | 36 +++++++------------ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.InputPollable.cs b/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.InputPollable.cs index 179f05e790..3a5ceb8e07 100644 --- a/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.InputPollable.cs +++ b/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.InputPollable.cs @@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC set => _isLag = value; } - public IInputCallbackSystem InputCallbacks { get; } + public IInputCallbackSystem InputCallbacks { get; } = new InputCallbackSystem(); private int _lagCount = 0; private bool _isLag = false; diff --git a/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.cs b/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.cs index 52c0acb33a..6f8644db86 100644 --- a/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.cs +++ b/BizHawk.Emulation.Cores/Computers/AmstradCPC/AmstradCPC.cs @@ -24,20 +24,17 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { var ser = new BasicServiceProvider(this); ServiceProvider = ser; - InputCallbacks = new InputCallbackSystem(); CoreComm = comm; _gameInfo = game; _cpu = new Z80A(); _tracer = new TraceBuffer { Header = _cpu.TraceHeader }; _files = files?.ToList() ?? new List(); - if (settings == null) - settings = new AmstradCPCSettings(); - if (syncSettings == null) - syncSettings = new AmstradCPCSyncSettings(); + settings ??= new AmstradCPCSettings(); + syncSettings ??= new AmstradCPCSyncSettings(); - PutSyncSettings((AmstradCPCSyncSettings)syncSettings ?? new AmstradCPCSyncSettings()); - PutSettings((AmstradCPCSettings)settings ?? new AmstradCPCSettings()); + PutSyncSettings((AmstradCPCSyncSettings)syncSettings); + PutSettings((AmstradCPCSettings)settings); DeterministicEmulation = ((AmstradCPCSyncSettings)syncSettings).DeterministicEmulation; @@ -83,13 +80,13 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC // set audio device settings if (_machine.AYDevice != null && _machine.AYDevice.GetType() == typeof(AY38912)) { - ((AY38912)_machine.AYDevice as AY38912).PanningConfiguration = ((AmstradCPCSettings)settings as AmstradCPCSettings).AYPanConfig; - _machine.AYDevice.Volume = ((AmstradCPCSettings)settings as AmstradCPCSettings).AYVolume; + ((AY38912)_machine.AYDevice).PanningConfiguration = ((AmstradCPCSettings)settings).AYPanConfig; + _machine.AYDevice.Volume = ((AmstradCPCSettings)settings).AYVolume; } if (_machine.TapeBuzzer != null) { - ((Beeper)_machine.TapeBuzzer as Beeper).Volume = ((AmstradCPCSettings)settings as AmstradCPCSettings).TapeVolume; + ((Beeper)_machine.TapeBuzzer).Volume = ((AmstradCPCSettings)settings).TapeVolume; } ser.Register(SoundMixer); @@ -168,7 +165,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { case MachineType.CPC464: _machine = new CPC464(this, _cpu, files, autoTape, bType); - List roms64 = new List(); + var roms64 = new List(); roms64.Add(RomData.InitROM(MachineType.CPC464, GetFirmware(0x4000, "OS464ROM"), RomData.ROMChipType.Lower)); roms64.Add(RomData.InitROM(MachineType.CPC464, GetFirmware(0x4000, "BASIC1-0ROM"), RomData.ROMChipType.Upper, 0)); _machine.InitROM(roms64.ToArray()); @@ -176,7 +173,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC case MachineType.CPC6128: _machine = new CPC6128(this, _cpu, files, autoTape, bType); - List roms128 = new List(); + var roms128 = new List(); roms128.Add(RomData.InitROM(MachineType.CPC6128, GetFirmware(0x4000, "OS6128ROM"), RomData.ROMChipType.Lower)); roms128.Add(RomData.InitROM(MachineType.CPC6128, GetFirmware(0x4000, "BASIC1-1ROM"), RomData.ROMChipType.Upper, 0)); roms128.Add(RomData.InitROM(MachineType.CPC6128, GetFirmware(0x4000, "AMSDOS0-5ROM"), RomData.ROMChipType.Upper, 7)); @@ -196,18 +193,9 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC public bool DriveLightEnabled => true; - public bool DriveLightOn - { - get - { - if (_machine != null && - (_machine.TapeDevice != null && _machine.TapeDevice.TapeIsPlaying) || - (_machine.UPDDiskDevice != null && _machine.UPDDiskDevice.DriveLight)) - return true; - - return false; - } - } + public bool DriveLightOn => + (_machine?.TapeDevice != null && _machine.TapeDevice.TapeIsPlaying) + || (_machine?.UPDDiskDevice != null && _machine.UPDDiskDevice.DriveLight); #endregion }