From 133fc83e894e9cd431039520d114712ddd79665a Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 27 May 2019 10:53:44 +0100 Subject: [PATCH] Tidy the MC6850 a little, mainly to show that the step method is only called via the clock tick. Signed-off-by: Adrian Conlon --- MC6809/MC6809.Test/Board.cs | 1 - MC6850/MC6850.cs | 131 +++++++++++++++++------------------- 2 files changed, 60 insertions(+), 72 deletions(-) diff --git a/MC6809/MC6809.Test/Board.cs b/MC6809/MC6809.Test/Board.cs index a209e05..05c44d7 100644 --- a/MC6809/MC6809.Test/Board.cs +++ b/MC6809/MC6809.Test/Board.cs @@ -139,7 +139,6 @@ namespace EightBit if (this.ACIA.Selected) { this.ACIA.RW.Lower(); - this.ACIA.DATA = this.Data; this.AccessAcia(); } } diff --git a/MC6850/MC6850.cs b/MC6850/MC6850.cs index e7d0317..de79bb7 100644 --- a/MC6850/MC6850.cs +++ b/MC6850/MC6850.cs @@ -321,8 +321,6 @@ namespace EightBit private bool TransmitReadyHigh => this.transmitControl == TransmitterControl.ReadyHighInterruptDisabled; - //// private bool TransmitReadyLow => !this.TransmitReadyHigh; - private byte Status { get @@ -345,70 +343,6 @@ namespace EightBit this.startup = StartupCondition.ColdStart; } - public void Step() - { - this.ResetCycles(); - - if (!this.Activated) - { - return; - } - - this.OnAccessing(); - - var writing = this.RW.Lowered(); - var reading = !writing; - - var registers = this.RS.Lowered(); - var transferring = !registers; - - if (registers) - { - if (writing) - { - this.counterDivide = (CounterDivideSelect)(this.DATA & (byte)(ControlRegister.CR0 | ControlRegister.CR1)); - if (this.counterDivide == CounterDivideSelect.MasterReset) - { - this.Reset(); - } - else - { - this.wordSelect = (WordSelect)((this.DATA & (byte)(ControlRegister.CR2 | ControlRegister.CR3 | ControlRegister.CR4)) >> 2); - this.transmitControl = (TransmitterControl)((this.DATA & (byte)(ControlRegister.CR5 | ControlRegister.CR6)) >> 5); - this.receiveControl = (ReceiveControl)((this.DATA & (byte)ControlRegister.CR7) >> 7); - this.RTS.Match(this.TransmitReadyHigh); - } - } - else - { - this.DATA = this.Status; - } - } - else - { - this.IRQ.Raise(); - if (writing) - { - this.StartTransmit(); - } - else - { - this.CompleteReceive(); - } - } - - // Catch the transition to lost carrier - if (this.oldDcdLine.Lowered() && this.DCD.Raised()) - { - this.IRQ.Raise(); - this.statusRead = false; - } - - this.oldDcdLine = this.dcdLine; - - this.OnAccessed(); - } - public void MarkTransmitComplete() { this.statusTDRE = this.CTS.Lowered(); @@ -455,15 +389,70 @@ namespace EightBit this.Step(); } - ////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, StatusRegister flag, bool condition) => SetFlag(f, (byte)flag, condition); private static byte ClearFlag(byte f, StatusRegister flag) => ClearFlag(f, (byte)flag); - ////private static byte ClearFlag(byte f, StatusRegisters flag, int condition) => ClearFlag(f, (byte)flag, condition); + private void Step() + { + this.ResetCycles(); + + if (!this.Activated) + { + return; + } + + this.OnAccessing(); + + var writing = this.RW.Lowered(); + var registers = this.RS.Lowered(); + + if (registers) + { + if (writing) + { + this.counterDivide = (CounterDivideSelect)(this.DATA & (byte)(ControlRegister.CR0 | ControlRegister.CR1)); + if (this.counterDivide == CounterDivideSelect.MasterReset) + { + this.Reset(); + } + else + { + this.wordSelect = (WordSelect)((this.DATA & (byte)(ControlRegister.CR2 | ControlRegister.CR3 | ControlRegister.CR4)) >> 2); + this.transmitControl = (TransmitterControl)((this.DATA & (byte)(ControlRegister.CR5 | ControlRegister.CR6)) >> 5); + this.receiveControl = (ReceiveControl)((this.DATA & (byte)ControlRegister.CR7) >> 7); + this.RTS.Match(this.TransmitReadyHigh); + } + } + else + { + this.DATA = this.Status; + } + } + else + { + this.IRQ.Raise(); + if (writing) + { + this.StartTransmit(); + } + else + { + this.CompleteReceive(); + } + } + + // Catch the transition to lost carrier + if (this.oldDcdLine.Lowered() && this.DCD.Raised()) + { + this.IRQ.Raise(); + this.statusRead = false; + } + + this.oldDcdLine = this.dcdLine; + + this.OnAccessed(); + } private void OnAccessing() => this.Accessing?.Invoke(this, EventArgs.Empty);