From 15551adb68c8fa47747b039172281990811f0dad Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Wed, 24 Apr 2019 00:57:53 +0100 Subject: [PATCH] Correct a bunch of MC6809/MC6850 style issues. Signed-off-by: Adrian Conlon --- MC6809/MC6809.cs | 16 ++++++------- MC6809/StatusBits.cs | 54 +++++++++++++++++++++++--------------------- MC6850/MC6850.cs | 31 +++++++++++++------------ 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/MC6809/MC6809.cs b/MC6809/MC6809.cs index 0b23b1f..60ca91a 100644 --- a/MC6809/MC6809.cs +++ b/MC6809/MC6809.cs @@ -442,7 +442,7 @@ case 0b11: return this.S; default: - throw new ArgumentOutOfRangeException("which", which, "Which does not specify a valid register"); + throw new ArgumentOutOfRangeException(nameof(which), which, "Which does not specify a valid register"); } } @@ -671,7 +671,7 @@ } private bool Branch(Register16 destination, bool condition) => this.Branch(destination.Word, condition); - + private void BranchShort(bool condition) => this.Branch(this.Address_relative_byte(), condition); private void BranchLong(bool condition) @@ -711,11 +711,11 @@ case 0b1011: return ref this.DP; default: - throw new ArgumentOutOfRangeException("specifier", specifier, "Invalid specifier"); + throw new ArgumentOutOfRangeException(nameof(specifier), specifier, "Invalid specifier"); } } - Register16 ReferenceTransfer16(int specifier) + private Register16 ReferenceTransfer16(int specifier) { switch (specifier) { case 0b0000: @@ -731,7 +731,7 @@ case 0b0101: return this.PC; default: - throw new ArgumentOutOfRangeException("specifier", specifier, "Invalid specifier"); + throw new ArgumentOutOfRangeException(nameof(specifier), specifier, "Invalid specifier"); } } @@ -1106,7 +1106,6 @@ { switch (this.OpCode) { - // CMP // CMPD @@ -1175,7 +1174,6 @@ { switch (this.OpCode) { - // CMP // CMPU @@ -1299,7 +1297,7 @@ if (type1 != type2) { - throw new ArgumentOutOfRangeException("data", data, "Type specifications do not match"); + throw new ArgumentOutOfRangeException(nameof(data), data, "Type specifications do not match"); } if (type1 == 0) @@ -1536,7 +1534,7 @@ if (type1 != type2) { - throw new ArgumentOutOfRangeException("data", data, "Type specifications do not match"); + throw new ArgumentOutOfRangeException(nameof(data), data, "Type specifications do not match"); } if (type1 == 0) diff --git a/MC6809/StatusBits.cs b/MC6809/StatusBits.cs index a01465f..61342d7 100644 --- a/MC6809/StatusBits.cs +++ b/MC6809/StatusBits.cs @@ -9,40 +9,42 @@ namespace EightBit [Flags] public enum StatusBits : byte { - // Entire flag: set if the complete machine state was saved in the stack. - // If this bit is not set then only program counter and condition code - // registers were saved in the stack. This bit is used by interrupt - // handling routines only. - // The bit is cleared by fast interrupts, and set by all other interrupts. - EF = Bits.Bit7, + None = 0, - // Fast interrupt mask: set if the FIRQ interrupt is disabled. - FF = Bits.Bit6, + // Carry: set if there was a carry from the bit 7 during last add + // operation, or if there was a borrow from last subtract operation, + // or if bit 7 of the A register was set during last MUL operation. + CF = Bits.Bit0, - // Half carry: set if there was a carry from bit 3 to bit 4 of the result - // during the last add operation. - HF = Bits.Bit5, - - // Interrupt mask: set if the IRQ interrupt is disabled. - IF = Bits.Bit4, - - // Negative: set if the most significant bit of the result is set. - // This bit can be set not only by arithmetic and logical operations, - // but also by load / store operations. - NF = Bits.Bit3, + // Overflow: set if there was an overflow during last result calculation. + // Logical, load and store operations clear this bit. + VF = Bits.Bit1, // Zero: set if the result is zero. Like the N bit, this bit can be // set not only by arithmetic and logical operations, but also // by load / store operations. ZF = Bits.Bit2, - // Overflow: set if there was an overflow during last result calculation. - // Logical, load and store operations clear this bit. - VF = Bits.Bit1, + // Negative: set if the most significant bit of the result is set. + // This bit can be set not only by arithmetic and logical operations, + // but also by load / store operations. + NF = Bits.Bit3, - // Carry: set if there was a carry from the bit 7 during last add - // operation, or if there was a borrow from last subtract operation, - // or if bit 7 of the A register was set during last MUL operation. - CF = Bits.Bit0, + // Interrupt mask: set if the IRQ interrupt is disabled. + IF = Bits.Bit4, + + // Half carry: set if there was a carry from bit 3 to bit 4 of the result + // during the last add operation. + HF = Bits.Bit5, + + // Fast interrupt mask: set if the FIRQ interrupt is disabled. + FF = Bits.Bit6, + + // Entire flag: set if the complete machine state was saved in the stack. + // If this bit is not set then only program counter and condition code + // registers were saved in the stack. This bit is used by interrupt + // handling routines only. + // The bit is cleared by fast interrupts, and set by all other interrupts. + EF = Bits.Bit7, } } diff --git a/MC6850/MC6850.cs b/MC6850/MC6850.cs index 9fc6688..963220b 100644 --- a/MC6850/MC6850.cs +++ b/MC6850/MC6850.cs @@ -45,7 +45,6 @@ namespace EightBit // * Leading bit = LSB = Bit 0 // ** Data bit will be zero in 7-bit plus parity modes // *** Data bit is "don't care" in 7-bit plus parity modes - public sealed class MC6850 : ClockedChip { private PinLevel rxdataLine = PinLevel.Low; @@ -102,8 +101,10 @@ namespace EightBit public event EventHandler Received; + [Flags] public enum ControlRegisters { + None = 0, CR0 = 0b1, // Counter divide CR1 = 0b10, // " CR2 = 0b100, // Word select @@ -158,8 +159,11 @@ namespace EightBit // Information stored in this register indicates the status of the // Transmit Data Register, the Receive Data Register and error logic, // and the peripheral/modem status inputs of the ACIA + [Flags] public enum StatusRegisters { + None = 0, + // Receive Data Register Full (RDRF), Bit 0 - Receive Data // Register Full indicates that received data has been // transferred to the Receive Data Register. RDRF is cleared @@ -318,22 +322,21 @@ namespace EightBit private bool TransmitReadyHigh => this.transmitControl == TransmitterControl.ReadyHighInterruptDisabled; - private bool TransmitReadyLow => !this.TransmitReadyHigh; + //// private bool TransmitReadyLow => !this.TransmitReadyHigh; private byte Status { get { byte status = 0; - SetFlag(status, StatusRegisters.STATUS_RDRF, this.statusRDRF); - SetFlag(status, StatusRegisters.STATUS_TDRE, this.statusTDRE); - SetFlag(status, StatusRegisters.STATUS_DCD, this.DCD.Lowered()); - SetFlag(status, StatusRegisters.STATUS_CTS, this.CTS.Raised()); - ClearFlag(status, StatusRegisters.STATUS_FE); - SetFlag(status, StatusRegisters.STATUS_OVRN, this.statusOVRN); - ClearFlag(status, StatusRegisters.STATUS_PE); - SetFlag(status, StatusRegisters.STATUS_IRQ, this.IRQ.Lowered()); - return status; + status = SetFlag(status, StatusRegisters.STATUS_RDRF, this.statusRDRF); + status = SetFlag(status, StatusRegisters.STATUS_TDRE, this.statusTDRE); + status = SetFlag(status, StatusRegisters.STATUS_DCD, this.DCD.Lowered()); + status = SetFlag(status, StatusRegisters.STATUS_CTS, this.CTS.Raised()); + status = ClearFlag(status, StatusRegisters.STATUS_FE); + status = SetFlag(status, StatusRegisters.STATUS_OVRN, this.statusOVRN); + status = ClearFlag(status, StatusRegisters.STATUS_PE); + return SetFlag(status, StatusRegisters.STATUS_IRQ, this.IRQ.Lowered()); } } @@ -451,15 +454,15 @@ namespace EightBit return returned; } - private static byte SetFlag(byte f, StatusRegisters flag) => SetFlag(f, (byte)flag); + ////private static byte SetFlag(byte f, StatusRegisters flag) => SetFlag(f, (byte)flag); - private static byte SetFlag(byte f, StatusRegisters flag, int condition) => SetFlag(f, (byte)flag, condition); + ////private static byte SetFlag(byte f, StatusRegisters flag, int condition) => SetFlag(f, (byte)flag, condition); private static byte SetFlag(byte f, StatusRegisters flag, bool condition) => SetFlag(f, (byte)flag, condition); private static byte ClearFlag(byte f, StatusRegisters flag) => ClearFlag(f, (byte)flag); - private static byte ClearFlag(byte f, StatusRegisters flag, int condition) => ClearFlag(f, (byte)flag, condition); + ////private static byte ClearFlag(byte f, StatusRegisters flag, int condition) => ClearFlag(f, (byte)flag, condition); private void OnAccessing() => this.Accessing?.Invoke(this, EventArgs.Empty);