From cf4e63303452941a3342928384f1ab0967a15060 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Thu, 14 Feb 2019 23:51:32 +0000 Subject: [PATCH] Implement some suggestions from the code analysis. Signed-off-by: Adrian Conlon --- EightBit/Bus.cs | 10 ++------- EightBit/IMapper.cs | 2 +- EightBit/IntelOpCodeDecoded.cs | 10 ++++----- EightBit/Memory.cs | 5 +---- EightBit/Register16.cs | 25 +++++---------------- M6502/StatusBits.cs | 40 ++++++++++++++++++---------------- 6 files changed, 35 insertions(+), 57 deletions(-) diff --git a/EightBit/Bus.cs b/EightBit/Bus.cs index e7c7758..4a91db7 100644 --- a/EightBit/Bus.cs +++ b/EightBit/Bus.cs @@ -55,10 +55,7 @@ namespace EightBit return this.Read(); } - public byte Read(Register16 absolute) - { - return this.Read(absolute.Word); - } + public byte Read(Register16 absolute) => this.Read(absolute.Word); public byte Read(byte low, byte high) { @@ -86,10 +83,7 @@ namespace EightBit this.Write(value); } - public void Write(Register16 absolute, byte value) - { - this.Write(absolute.Word, value); - } + public void Write(Register16 absolute, byte value) => this.Write(absolute.Word, value); public void Write(byte low, byte high, byte value) { diff --git a/EightBit/IMapper.cs b/EightBit/IMapper.cs index a352cbc..c7cf074 100644 --- a/EightBit/IMapper.cs +++ b/EightBit/IMapper.cs @@ -6,6 +6,6 @@ namespace EightBit { public interface IMapper { - MemoryMapping Mapping(ushort address); + MemoryMapping Mapping(ushort absolute); } } diff --git a/EightBit/IntelOpCodeDecoded.cs b/EightBit/IntelOpCodeDecoded.cs index 6dcc07c..6c8c8b5 100644 --- a/EightBit/IntelOpCodeDecoded.cs +++ b/EightBit/IntelOpCodeDecoded.cs @@ -6,11 +6,11 @@ namespace EightBit { public class IntelOpCodeDecoded { - private int x; - private int y; - private int z; - private int p; - private int q; + private readonly int x; + private readonly int y; + private readonly int z; + private readonly int p; + private readonly int q; public IntelOpCodeDecoded() { diff --git a/EightBit/Memory.cs b/EightBit/Memory.cs index f16e3cf..e1259d9 100644 --- a/EightBit/Memory.cs +++ b/EightBit/Memory.cs @@ -16,10 +16,7 @@ namespace EightBit public abstract byte Peek(ushort address); - public virtual ref byte Reference(ushort address) - { - throw new NotImplementedException(); - } + public virtual ref byte Reference(ushort address) => throw new NotImplementedException(); public abstract int Load(FileStream file, int writeOffset = 0, int readOffset = 0, int limit = -1); diff --git a/EightBit/Register16.cs b/EightBit/Register16.cs index 5374b5c..f2ca900 100644 --- a/EightBit/Register16.cs +++ b/EightBit/Register16.cs @@ -48,25 +48,13 @@ namespace EightBit this.Word = rhs.Word; } - public static Register16 operator ++(Register16 value) - { - return Increment(value); - } + public static Register16 operator ++(Register16 value) => Increment(value); - public static Register16 operator --(Register16 value) - { - return Decrement(value); - } + public static Register16 operator --(Register16 value) => Decrement(value); - public static bool operator ==(Register16 left, Register16 right) - { - return left.Equals(right); - } + public static bool operator ==(Register16 left, Register16 right) => left.Equals(right); - public static bool operator !=(Register16 left, Register16 right) - { - return !(left == right); - } + public static bool operator !=(Register16 left, Register16 right) => !(left == right); public static Register16 Increment(Register16 value) { @@ -91,9 +79,6 @@ namespace EightBit return rhs.Word == this.Word; } - public override int GetHashCode() - { - return this.Word; - } + public override int GetHashCode() => this.Word; } } diff --git a/M6502/StatusBits.cs b/M6502/StatusBits.cs index 9f1aece..c48e41b 100644 --- a/M6502/StatusBits.cs +++ b/M6502/StatusBits.cs @@ -9,28 +9,30 @@ namespace EightBit [Flags] public enum StatusBits : byte { - // Negative - NF = Bits.Bit7, + None = 0, - // Overflow - VF = Bits.Bit6, - - // reserved - RF = Bits.Bit5, - - // Brk - BF = Bits.Bit4, - - // D (use BCD for arithmetic) - DF = Bits.Bit3, - - // I (IRQ disable) - IF = Bits.Bit2, + // Carry + CF = Bits.Bit0, // Zero ZF = Bits.Bit1, - // Carry - CF = Bits.Bit0, - } + // I (IRQ disable) + IF = Bits.Bit2, + + // D (use BCD for arithmetic) + DF = Bits.Bit3, + + // Brk + BF = Bits.Bit4, + + // reserved + RF = Bits.Bit5, + + // Overflow + VF = Bits.Bit6, + + // Negative + NF = Bits.Bit7, + } }