From 37c989c6611d1c4be7a1343bd87134d13eb7ef02 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 10 Apr 2017 11:24:53 -0500 Subject: [PATCH] more misc code cleanups, with some C#6isms --- .../movie/MultitrackRecording.cs | 34 ++++------ .../BasicServiceProvider.cs | 2 - .../Base Implementations/NullController.cs | 14 +--- .../Base Implementations/NullSound.cs | 2 +- .../Base Implementations/NullVideo.cs | 21 +++--- .../Base Implementations/TraceBuffer.cs | 7 +- .../Interfaces/Services/ICodeDataLogger.cs | 2 +- .../Interfaces/Services/IDisassemblable.cs | 2 +- .../Atari/2600/Atari2600.IDebuggable.cs | 17 ++--- .../Atari/2600/Atari2600.IInputPollable.cs | 2 +- .../Atari/2600/Atari2600.ISettable.cs | 15 ++-- .../Atari/2600/Atari2600.IStatable.cs | 7 +- .../Consoles/Atari/2600/Atari2600.cs | 13 ++-- .../Consoles/Coleco/ColecoControllerDeck.cs | 7 +- .../Consoles/Coleco/ColecoControllers.cs | 3 - .../Coleco/ColecoVision.IDebuggable.cs | 17 +++-- .../Coleco/ColecoVision.ISoundProvider.cs | 4 +- .../Consoles/Coleco/ColecoVision.IStatable.cs | 7 +- .../Consoles/Coleco/ColecoVision.cs | 68 +++++++++++-------- .../Consoles/Coleco/Input.cs | 12 ++-- .../Consoles/Intellivision/Cartridge.cs | 58 ++++++++++------ .../IntellivisionControllerDeck.cs | 5 +- .../Intellivision/Intellivision.IEmulator.cs | 46 ++++++------- 23 files changed, 177 insertions(+), 188 deletions(-) diff --git a/BizHawk.Client.Common/movie/MultitrackRecording.cs b/BizHawk.Client.Common/movie/MultitrackRecording.cs index 6b194295f5..ed5632de7e 100644 --- a/BizHawk.Client.Common/movie/MultitrackRecording.cs +++ b/BizHawk.Client.Common/movie/MultitrackRecording.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using BizHawk.Emulation.Common; +using BizHawk.Emulation.Common; namespace BizHawk.Client.Common { @@ -11,11 +10,11 @@ namespace BizHawk.Client.Common } public bool IsActive { get; set; } - public int CurrentPlayer{ get; set; } - public bool RecordAll { get; set; } + public int CurrentPlayer{ get; private set; } + public bool RecordAll { get; private set; } /// - /// A user friendly multitrack status + /// A user friendly multi-track status /// public string Status { @@ -94,14 +93,11 @@ namespace BizHawk.Client.Common public int PlayerSource { get; set; } public int PlayerTargetMask { get; set; } - public ControllerDefinition Definition { get { return Source.Definition; } } + public ControllerDefinition Definition => Source.Definition; - public bool this[string button] - { - get { return IsPressed(button); } - } + public bool this[string button] => IsPressed(button); - public bool IsPressed(string button) + public bool IsPressed(string button) { return Source.IsPressed(RemapButtonName(button)); } @@ -129,7 +125,7 @@ namespace BizHawk.Client.Common // Ok, this looks like a normal `P1 Button` type thing. we can handle it // Were we supposed to replace this one? - int foundPlayerMask = (1 << bnp.PlayerNum); + int foundPlayerMask = 1 << bnp.PlayerNum; if ((PlayerTargetMask & foundPlayerMask) == 0) { return button; @@ -163,14 +159,12 @@ namespace BizHawk.Client.Common { return null; } - else + + return new ButtonNameParser { - return new ButtonNameParser - { - PlayerNum = player, - ButtonPart = button.Substring(parts[0].Length + 1) - }; - } + PlayerNum = player, + ButtonPart = button.Substring(parts[0].Length + 1) + }; } public int PlayerNum { get; set; } @@ -178,7 +172,7 @@ namespace BizHawk.Client.Common public override string ToString() { - return string.Format("P{0} {1}", PlayerNum, ButtonPart); + return $"P{PlayerNum} {ButtonPart}"; } } } diff --git a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs index 67d9512152..ef2f731d9d 100644 --- a/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs +++ b/BizHawk.Emulation.Common/Base Implementations/BasicServiceProvider.cs @@ -48,8 +48,6 @@ namespace BizHawk.Emulation.Common /// /// the core can call this to register an additional service /// - /// - /// public void Register(T provider) where T : IEmulatorService { diff --git a/BizHawk.Emulation.Common/Base Implementations/NullController.cs b/BizHawk.Emulation.Common/Base Implementations/NullController.cs index 8ea8738bc4..f234f68266 100644 --- a/BizHawk.Emulation.Common/Base Implementations/NullController.cs +++ b/BizHawk.Emulation.Common/Base Implementations/NullController.cs @@ -7,22 +7,14 @@ /// public class NullController : IController { - private static readonly ControllerDefinition _definition = new ControllerDefinition + public ControllerDefinition Definition => new ControllerDefinition { Name = "Null Controller" }; - public ControllerDefinition Definition - { - get { return _definition; } - } + public bool this[string button] => false; - public bool this[string button] - { - get { return false; } - } - - public bool IsPressed(string button) + public bool IsPressed(string button) { return false; } diff --git a/BizHawk.Emulation.Common/Base Implementations/NullSound.cs b/BizHawk.Emulation.Common/Base Implementations/NullSound.cs index dc0be7c7b0..c2e2ff6a62 100644 --- a/BizHawk.Emulation.Common/Base Implementations/NullSound.cs +++ b/BizHawk.Emulation.Common/Base Implementations/NullSound.cs @@ -24,7 +24,7 @@ namespace BizHawk.Emulation.Common /// /// public NullSound(int spf) - :this() + : this() { _spfNumerator = spf; _spfDenominator = 1; diff --git a/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs b/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs index 2ebcdc4862..451cb3826d 100644 --- a/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs +++ b/BizHawk.Emulation.Common/Base Implementations/NullVideo.cs @@ -2,7 +2,7 @@ { /// /// A default IVideoProvider that simply returns - /// a black screen at an arbitruary size + /// a black screen at an arbitrary size /// /// public class NullVideo : IVideoProvider @@ -12,19 +12,18 @@ return new int[BufferWidth * BufferHeight]; } - public int VirtualWidth { get { return 256; } } - public int VirtualHeight { get { return 192; } } + public int VirtualWidth => 256; - public int BufferWidth { get { return 256; } } - public int BufferHeight { get { return 192; } } + public int VirtualHeight => 192; - public int BackgroundColor { get { return 0; } } + public int BufferWidth => 256; - private static NullVideo _nullVideo = new NullVideo(); + public int BufferHeight => 192; - public static NullVideo Instance - { - get { return _nullVideo; } - } + public int BackgroundColor => 0; + + private static readonly NullVideo _nullVideo = new NullVideo(); + + public static NullVideo Instance => _nullVideo; } } diff --git a/BizHawk.Emulation.Common/Base Implementations/TraceBuffer.cs b/BizHawk.Emulation.Common/Base Implementations/TraceBuffer.cs index a57488358d..fc4ce83276 100644 --- a/BizHawk.Emulation.Common/Base Implementations/TraceBuffer.cs +++ b/BizHawk.Emulation.Common/Base Implementations/TraceBuffer.cs @@ -17,8 +17,11 @@ namespace BizHawk.Emulation.Common public ITraceSink Sink { get; set; } - public bool Enabled { get { return Sink != null; } } + public bool Enabled => Sink != null; - public void Put(TraceInfo info) { Sink.Put(info); } + public void Put(TraceInfo info) + { + Sink.Put(info); + } } } diff --git a/BizHawk.Emulation.Common/Interfaces/Services/ICodeDataLogger.cs b/BizHawk.Emulation.Common/Interfaces/Services/ICodeDataLogger.cs index a2d064c923..48086f58a6 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/ICodeDataLogger.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/ICodeDataLogger.cs @@ -34,7 +34,7 @@ namespace BizHawk.Emulation.Common public interface ICodeDataLog : IDictionary { /// - /// Pins the managed arrays. Not that we expect them to be allocated, but in case we do, seeing thish ere will remind us to check for the pin condition and abort + /// Pins the managed arrays. Not that we expect them to be allocated, but in case we do, seeing this here will remind us to check for the pin condition and abort /// void Pin(); diff --git a/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs b/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs index 1b0491719f..413ec4a6b7 100644 --- a/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs +++ b/BizHawk.Emulation.Common/Interfaces/Services/IDisassemblable.cs @@ -7,7 +7,7 @@ namespace BizHawk.Emulation.Common /// /// This service provides the means to generate disassembly by the core for a given cpu and memory domain /// Tools such the debugger use this, but also lua scripting, and tools like trace logging and code data logging can make use of this tool - /// If unavailable the debugger tool will still be avilable but disable the disassembly window but still be available if the IDebuggable service is available + /// If unavailable the debugger tool will still be available but disable the disassembly window but still be available if the IDebuggable service is available /// public interface IDisassemblable : IEmulatorService { diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IDebuggable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IDebuggable.cs index 112bd0bdd7..de52b48868 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IDebuggable.cs @@ -56,7 +56,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 } } - public IMemoryCallbackSystem MemoryCallbacks { get; private set; } + public IMemoryCallbackSystem MemoryCallbacks { get; } = new MemoryCallbackSystem(); public bool CanStep(StepType type) { @@ -88,12 +88,9 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 } } - public int TotalExecutedCycles - { - get { return Cpu.TotalExecutedCycles; } - } + public int TotalExecutedCycles => Cpu.TotalExecutedCycles; - private void StepInto() + private void StepInto() { do { @@ -108,7 +105,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 if (instruction == JSR) { var destination = Cpu.PC + opsize[JSR]; - while(Cpu.PC != destination) + while (Cpu.PC != destination) { StepInto(); } @@ -159,8 +156,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private const byte JSR = 0x20; private const byte RTS = 0x60; - //the opsize table is used to quickly grab the instruction sizes (in bytes) - private readonly byte[] opsize = new byte[] + // the opsize table is used to quickly grab the instruction sizes (in bytes) + private readonly byte[] opsize = { /*0x00*/ 1,2,0,0,0,2,2,0,1,2,1,0,0,3,3,0, /*0x10*/ 2,2,0,0,0,2,2,0,1,3,0,0,0,3,3,0, @@ -193,7 +190,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 // 7 = Absolute,X // 8 = Zero Page,Y */ - private readonly byte[] optype = new byte[] + private readonly byte[] optype = { /*0x00*/ 0,1,0,0,0,2,2,0,0,0,0,0,0,3,3,0, /*0x10*/ 0,4,0,0,0,5,5,0,0,6,0,0,0,7,7,0, diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IInputPollable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IInputPollable.cs index 8d6efbf22d..2a9044428d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IInputPollable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IInputPollable.cs @@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 set { _islag = value; } } - public IInputCallbackSystem InputCallbacks { get; private set; } + public IInputCallbackSystem InputCallbacks { get; } = new InputCallbackSystem(); private bool _islag = true; private int _lagcount; diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.ISettable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.ISettable.cs index 5e0860fdb6..1ebc1639be 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.ISettable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.ISettable.cs @@ -25,10 +25,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { if (Settings == null || Settings.SECAMColors != o.SECAMColors) { - if (_tia != null) - { - _tia.SetSECAM(o.SECAMColors); - } + _tia?.SetSECAM(o.SECAMColors); } Settings = o; @@ -104,7 +101,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 [DefaultValue(24)] public int NTSCTopLine { - get { return this._ntscTopLine; } + get { return _ntscTopLine; } set { _ntscTopLine = Math.Min(64, Math.Max(value, 0)); } } @@ -122,8 +119,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 [DefaultValue(24)] public int PALTopLine { - get { return this._palTopLine; } - set { this._palTopLine = Math.Min(64, Math.Max(value, 0)); } + get { return _palTopLine; } + set { _palTopLine = Math.Min(64, Math.Max(value, 0)); } } [DisplayName("PAL Bottom Line")] @@ -131,8 +128,8 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 [DefaultValue(296)] public int PALBottomLine { - get { return this._palBottomLine; } - set { this._palBottomLine = Math.Min(310, Math.Max(value, 192)); } + get { return _palBottomLine; } + set { _palBottomLine = Math.Min(310, Math.Max(value, 192)); } } [DisplayName("Background Color")] diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IStatable.cs index 8feae5f4f5..1ca2bcf6e8 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.IStatable.cs @@ -7,12 +7,9 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 { public partial class Atari2600 : IStatable { - public bool BinarySaveStatesPreferred - { - get { return false; } - } + public bool BinarySaveStatesPreferred => false; - public void SaveStateText(TextWriter writer) + public void SaveStateText(TextWriter writer) { SyncState(Serializer.CreateTextWriter(writer)); } diff --git a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs index c2207e614d..affe158134 100644 --- a/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs +++ b/BizHawk.Emulation.Cores/Consoles/Atari/2600/Atari2600.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using BizHawk.Common; using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; @@ -22,7 +20,7 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 private readonly GameInfo _game; private int _frame; - private ITraceable Tracer { get; set; } + private ITraceable Tracer { get; } [CoreConstructor("A26")] public Atari2600(CoreComm comm, GameInfo game, byte[] rom, object settings, object syncSettings) @@ -30,9 +28,6 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 var ser = new BasicServiceProvider(this); ServiceProvider = ser; - MemoryCallbacks = new MemoryCallbackSystem(); - InputCallbacks = new InputCallbackSystem(); - Ram = new byte[128]; CoreComm = comm; Settings = (A2600Settings)settings ?? new A2600Settings(); @@ -76,11 +71,11 @@ namespace BizHawk.Emulation.Cores.Atari.Atari2600 get { return _pal ? DisplayType.PAL : Common.DisplayType.NTSC; } } - public string SystemId { get { return "A26"; } } + public string SystemId => "A26"; - public string BoardName { get { return _mapper.GetType().Name; } } + public string BoardName => _mapper.GetType().Name; - public CoreComm CoreComm { get; private set; } + public CoreComm CoreComm { get; private set; } public ControllerDefinition ControllerDefinition { get { return Atari2600ControllerDefinition; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs index 95c185184d..8b9c6371e6 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllerDeck.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using BizHawk.Common; @@ -24,7 +23,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision } Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1); - Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2); ; + Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2); Definition = new ControllerDefinition { @@ -41,8 +40,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision Definition.FloatRanges.AddRange(Port2.Definition.FloatRanges); } - public int wheel1; - public int wheel2; + private int wheel1; + private int wheel2; public byte ReadPort1(IController c, bool left_mode, bool update_wheel) { diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs index 86b92cdb8c..30b9fa711f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs @@ -4,7 +4,6 @@ using System.ComponentModel; using System.Linq; using BizHawk.Common; -using BizHawk.Common.ReflectionExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.ColecoVision @@ -12,7 +11,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision /// /// Represents a controller plugged into a controller port on the intellivision /// - /// public interface IPort { byte Read(IController c, bool left_mode, int wheel); @@ -24,7 +22,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision void SyncState(Serializer ser); int PortNum { get; } - } [DisplayName("Unplugged Controller")] diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IDebuggable.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IDebuggable.cs index 5d144974ab..356e02550d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IDebuggable.cs @@ -4,7 +4,6 @@ using System.Collections.Generic; using BizHawk.Common.NumberExtensions; using BizHawk.Emulation.Common; - namespace BizHawk.Emulation.Cores.ColecoVision { public partial class ColecoVision : IDebuggable @@ -121,16 +120,16 @@ namespace BizHawk.Emulation.Cores.ColecoVision } } - public IMemoryCallbackSystem MemoryCallbacks { get; private set; } + public IMemoryCallbackSystem MemoryCallbacks { get; } - public bool CanStep(StepType type) { return false; } + public bool CanStep(StepType type) => false; - [FeatureNotImplemented] - public void Step(StepType type) { throw new NotImplementedException(); } + [FeatureNotImplemented] + public void Step(StepType type) + { + throw new NotImplementedException(); + } - public int TotalExecutedCycles - { - get { return Cpu.TotalExecutedCycles; } - } + public int TotalExecutedCycles => Cpu.TotalExecutedCycles; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.ISoundProvider.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.ISoundProvider.cs index 424dbf003f..06a111348d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.ISoundProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.ISoundProvider.cs @@ -1,6 +1,4 @@ -using System; -using BizHawk.Emulation.Common; -using BizHawk.Emulation.Cores.Components; +using BizHawk.Emulation.Cores.Components; namespace BizHawk.Emulation.Cores.ColecoVision { diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IStatable.cs index 0f11d20682..e876bfb69c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.IStatable.cs @@ -7,12 +7,9 @@ namespace BizHawk.Emulation.Cores.ColecoVision { public partial class ColecoVision : IStatable { - public bool BinarySaveStatesPreferred - { - get { return false; } - } + public bool BinarySaveStatesPreferred => false; - public void SaveStateBinary(BinaryWriter bw) + public void SaveStateBinary(BinaryWriter bw) { SyncState(Serializer.CreateBinaryWriter(bw)); } diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.cs index 679857fdd1..8e8380a6be 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.cs @@ -2,7 +2,6 @@ using BizHawk.Emulation.Cores.Components; using BizHawk.Emulation.Cores.Components.Z80; using BizHawk.Common.NumberExtensions; -using System; namespace BizHawk.Emulation.Cores.ColecoVision { @@ -16,13 +15,13 @@ namespace BizHawk.Emulation.Cores.ColecoVision public sealed partial class ColecoVision : IEmulator, IDebuggable, IInputPollable, IStatable, ISettable { // ROM - public byte[] RomData; - public int RomLength; - public byte[] BiosRom; + private byte[] RomData; + private int RomLength; + private byte[] BiosRom; // Machine - public Z80A Cpu; - public TMS9918A VDP; + private Z80A Cpu; + private TMS9918A VDP; public byte[] Ram = new byte[1024]; private readonly TraceBuffer Tracer = new TraceBuffer(); @@ -36,18 +35,20 @@ namespace BizHawk.Emulation.Cores.ColecoVision _syncSettings = (ColecoSyncSettings)SyncSettings ?? new ColecoSyncSettings(); bool skipbios = _syncSettings.SkipBiosIntro; - Cpu = new Z80A(); - Cpu.ReadMemory = ReadMemory; - Cpu.WriteMemory = WriteMemory; - Cpu.ReadHardware = ReadPort; - Cpu.WriteHardware = WritePort; - Cpu.MemoryCallbacks = MemoryCallbacks; + Cpu = new Z80A + { + ReadMemory = ReadMemory, + WriteMemory = WriteMemory, + ReadHardware = ReadPort, + WriteHardware = WritePort, + MemoryCallbacks = MemoryCallbacks + }; - PSG = new SN76489(); + PSG = new SN76489(); _fakeSyncSound = new FakeSyncSound(PSG, 735); (ServiceProvider as BasicServiceProvider).Register(_fakeSyncSound); - ControllerDeck = new ColecoVisionControllerDeck(this._syncSettings.Port1, this._syncSettings.Port2); + ControllerDeck = new ColecoVisionControllerDeck(_syncSettings.Port1, _syncSettings.Port2); VDP = new TMS9918A(Cpu); (ServiceProvider as BasicServiceProvider).Register(VDP); @@ -57,9 +58,12 @@ namespace BizHawk.Emulation.Cores.ColecoVision // gamedb can overwrite the syncsettings; this is ok if (game["NoSkip"]) + { skipbios = false; + } + LoadRom(rom, skipbios); - this.game = game; + _game = game; SetupMemoryDomains(); Tracer.Header = Cpu.TraceHeader; @@ -68,16 +72,18 @@ namespace BizHawk.Emulation.Cores.ColecoVision serviceProvider.Register(Tracer); } - public IEmulatorServiceProvider ServiceProvider { get; private set; } + public IEmulatorServiceProvider ServiceProvider { get; } public ControllerDefinition ControllerDefinition { get { return ControllerDeck.Definition; } } - public ColecoVisionControllerDeck ControllerDeck { get; private set; } + + public ColecoVisionControllerDeck ControllerDeck { get; } + public IController Controller { get; set; } - const ushort RamSizeMask = 0x03FF; + private const ushort RamSizeMask = 0x03FF; public void FrameAdvance(bool render, bool renderSound) { @@ -106,7 +112,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision } } - void LoadRom(byte[] rom, bool skipbios) + private void LoadRom(byte[] rom, bool skipbios) { RomData = new byte[0x8000]; for (int i = 0; i < 0x8000; i++) @@ -120,28 +126,34 @@ namespace BizHawk.Emulation.Cores.ColecoVision } } - byte ReadPort(ushort port) + private byte ReadPort(ushort port) { port &= 0xFF; if (port >= 0xA0 && port < 0xC0) { if ((port & 1) == 0) + { return VDP.ReadData(); + } + return VDP.ReadVdpStatus(); } if (port >= 0xE0) { if ((port & 1) == 0) + { return ReadController1(); + } + return ReadController2(); } return 0xFF; } - void WritePort(ushort port, byte value) + private void WritePort(ushort port, byte value) { port &= 0xFF; @@ -173,9 +185,10 @@ namespace BizHawk.Emulation.Cores.ColecoVision } } - public bool DeterministicEmulation { get { return true; } } + public bool DeterministicEmulation => true; + + public void Dispose() { } - public void Dispose() { } public void ResetCounters() { Frame = 0; @@ -183,9 +196,10 @@ namespace BizHawk.Emulation.Cores.ColecoVision _isLag = false; } - public string SystemId { get { return "Coleco"; } } - public GameInfo game; - public CoreComm CoreComm { get; private set; } - public string BoardName { get { return null; } } + public string SystemId => "Coleco"; + + private GameInfo _game; + public CoreComm CoreComm { get; } + public string BoardName => null; } } \ No newline at end of file diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/Input.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/Input.cs index 76c4188e20..48c6d8bdaa 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/Input.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/Input.cs @@ -1,7 +1,4 @@ -using BizHawk.Emulation.Common; -using System; - -namespace BizHawk.Emulation.Cores.ColecoVision +namespace BizHawk.Emulation.Cores.ColecoVision { public partial class ColecoVision { @@ -25,7 +22,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision public enum InputPortMode { Left, Right } InputPortMode InputPortSelection; - byte ReadController1() + private byte ReadController1() { _isLag = false; byte retval; @@ -43,8 +40,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision return 0x7F; } - - byte ReadController2() + private byte ReadController2() { _isLag = false; byte retval; @@ -63,6 +59,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision } public int Frame { get { return frame; } set { frame = value; } } - int frame; + private int frame; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/Cartridge.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/Cartridge.cs index 17bbc9e02c..e46f57a7d0 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/Cartridge.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/Cartridge.cs @@ -1,7 +1,8 @@ -using BizHawk.Common; +using System; + +using BizHawk.Common; using BizHawk.Common.BufferExtensions; using BizHawk.Emulation.Common; -using System; namespace BizHawk.Emulation.Cores.Intellivision { @@ -64,15 +65,17 @@ namespace BizHawk.Emulation.Cores.Intellivision switch (mapper) { case 0: - if (addr>=0x5000 && addr<=0x6FFF) + if (addr >= 0x5000 && addr <= 0x6FFF) { - return Data[addr-0x5000]; + return Data[addr - 0x5000]; } - else if (addr>=0xD000 && addr<=0xDFFF) + + if (addr >= 0xD000 && addr <= 0xDFFF) { return Data[addr - 0xB000]; } - else if (addr>=0xF000 && addr<=0xFFFF) + + if (addr >= 0xF000 && addr <= 0xFFFF) { return Data[addr - 0xC000]; } @@ -83,7 +86,8 @@ namespace BizHawk.Emulation.Cores.Intellivision { return Data[addr - 0x5000]; } - else if (addr >= 0xD000 && addr <= 0xFFFF) + + if (addr >= 0xD000 && addr <= 0xFFFF) { return Data[addr - 0xB000]; } @@ -94,11 +98,13 @@ namespace BizHawk.Emulation.Cores.Intellivision { return Data[addr - 0x5000]; } - else if (addr >= 0x9000 && addr <= 0xBFFF) + + if (addr >= 0x9000 && addr <= 0xBFFF) { return Data[addr - 0x7000]; } - else if (addr >= 0xD000 && addr <= 0xDFFF) + + if (addr >= 0xD000 && addr <= 0xDFFF) { return Data[addr - 0x8000]; } @@ -109,15 +115,18 @@ namespace BizHawk.Emulation.Cores.Intellivision { return Data[addr - 0x5000]; } - else if (addr >= 0x9000 && addr <= 0xAFFF) + + if (addr >= 0x9000 && addr <= 0xAFFF) { return Data[addr - 0x7000]; } - else if (addr >= 0xD000 && addr <= 0xDFFF) + + if (addr >= 0xD000 && addr <= 0xDFFF) { return Data[addr - 0x9000]; } - else if (addr >= 0xF000 && addr <= 0xFFFF) + + if (addr >= 0xF000 && addr <= 0xFFFF) { return Data[addr - 0xA000]; } @@ -128,7 +137,8 @@ namespace BizHawk.Emulation.Cores.Intellivision { return Data[addr - 0x5000]; } - else if (addr >= 0xD000 && addr <= 0xD3FF) + + if (addr >= 0xD000 && addr <= 0xD3FF) { return Cart_Ram[addr - 0xD000]; } @@ -139,7 +149,8 @@ namespace BizHawk.Emulation.Cores.Intellivision { return Data[addr - 0x5000]; } - else if (addr >= 0x9000 && addr <= 0xBFFF) + + if (addr >= 0x9000 && addr <= 0xBFFF) { return Data[addr - 0x6000]; } @@ -175,19 +186,23 @@ namespace BizHawk.Emulation.Cores.Intellivision { return Data[addr - 0x5000]; } - else if (addr >= 0x9000 && addr <= 0xAFFF) + + if (addr >= 0x9000 && addr <= 0xAFFF) { return Data[addr - 0x7000]; } - else if (addr >= 0xD000 && addr <= 0xDFFF) + + if (addr >= 0xD000 && addr <= 0xDFFF) { return Data[addr - 0x9000]; } - else if (addr >= 0xF000 && addr <= 0xFFFF) + + if (addr >= 0xF000 && addr <= 0xFFFF) { return Data[addr - 0xA000]; } - else if (addr >= 0x8800 && addr <= 0x8FFF) + + if (addr >= 0x8800 && addr <= 0x8FFF) { return Cart_Ram[addr - 0x8800]; } @@ -198,11 +213,13 @@ namespace BizHawk.Emulation.Cores.Intellivision { return Data[addr - 0x5000]; } - else if (addr >= 0x8800 && addr <= 0xB7FF) + + if (addr >= 0x8800 && addr <= 0xB7FF) { return Data[addr - 0x6800]; } - else if (addr >= 0xD000 && addr <= 0xFFFF) + + if (addr >= 0xD000 && addr <= 0xFFFF) { return Data[addr - 0x8000]; } @@ -232,6 +249,7 @@ namespace BizHawk.Emulation.Cores.Intellivision } break; } + return false; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs index 2a5581ecfa..70e6b56019 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/Controllers/IntellivisionControllerDeck.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using BizHawk.Common; @@ -24,7 +23,7 @@ namespace BizHawk.Emulation.Cores.Intellivision } Port1 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller1Name], 1); - Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2); ; + Port2 = (IPort)Activator.CreateInstance(ValidControllerTypes[controller2Name], 2); Definition = new ControllerDefinition { @@ -51,7 +50,7 @@ namespace BizHawk.Emulation.Cores.Intellivision return Port2.Read(c); } - public ControllerDefinition Definition { get; private set; } + public ControllerDefinition Definition { get; } public void SyncState(Serializer ser) { diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs index f6efe84e1c..ec1e7ef4a5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs @@ -1,28 +1,29 @@ using BizHawk.Emulation.Common; -using System; namespace BizHawk.Emulation.Cores.Intellivision { public sealed partial class Intellivision : IEmulator { - public IEmulatorServiceProvider ServiceProvider { get; private set; } + public IEmulatorServiceProvider ServiceProvider { get; } - public ControllerDefinition ControllerDefinition - { - get { return ControllerDeck.Definition; } - } + public ControllerDefinition ControllerDefinition => ControllerDeck.Definition; - public IController Controller { get; set; } + public IController Controller { get; set; } public void FrameAdvance(bool render, bool rendersound) { if (Tracer.Enabled) + { _cpu.TraceCallback = (s) => Tracer.Put(s); + } else + { _cpu.TraceCallback = null; + } _frame++; stic_row = -1; + // read the controller state here for now get_controller_state(); @@ -30,13 +31,13 @@ namespace BizHawk.Emulation.Cores.Intellivision int delay_cycles = 700; int delay_timer = -1; - _cpu.PendingCycles = (14934 - 3791 + _cpu.GetPendingCycles()); + _cpu.PendingCycles = 14934 - 3791 + _cpu.GetPendingCycles(); _stic.Sr1 = true; islag = true; bool active_display = _stic.active_display; - //also at the start of every frame the color stack is reset + // also at the start of every frame the color stack is reset _stic.ColorSP = 0x0028; while (_cpu.GetPendingCycles() > 0) @@ -57,7 +58,7 @@ namespace BizHawk.Emulation.Cores.Intellivision } } - if (delay_cycles>= 750 && active_display) + if (delay_cycles >= 750 && active_display) { delay_cycles = -1; delay_timer = 110; @@ -67,7 +68,8 @@ namespace BizHawk.Emulation.Cores.Intellivision _stic.in_vb_2 = true; _stic.Background(stic_row); _stic.in_vb_2 = false; - } + } + stic_row++; } Connect(); @@ -85,7 +87,7 @@ namespace BizHawk.Emulation.Cores.Intellivision _stic.active_display = false; _stic.Sr1 = false; - _cpu.PendingCycles = (3000 + _cpu.GetPendingCycles()); + _cpu.PendingCycles = 3000 + _cpu.GetPendingCycles(); while (_cpu.GetPendingCycles() > 0) { @@ -95,7 +97,7 @@ namespace BizHawk.Emulation.Cores.Intellivision } // vblank phase 2 - _cpu.PendingCycles = (791 + _cpu.GetPendingCycles()); + _cpu.PendingCycles = 791 + _cpu.GetPendingCycles(); _stic.in_vb_1 = false; while (_cpu.GetPendingCycles() > 0) @@ -121,25 +123,23 @@ namespace BizHawk.Emulation.Cores.Intellivision public bool islag; public int lagcount; private int stic_row; - public int Frame { get { return _frame; } } - public string SystemId - { - get { return "INTV"; } - } + public int Frame => _frame; - public bool DeterministicEmulation { get { return true; } } + public string SystemId => "INTV"; - [FeatureNotImplemented] - public string BoardName { get { return null; } } + public bool DeterministicEmulation => true; - public void ResetCounters() + [FeatureNotImplemented] + public string BoardName => null; + + public void ResetCounters() { _frame = 0; lagcount = 0; } - public CoreComm CoreComm { get; private set; } + public CoreComm CoreComm { get; } public void Dispose() {