diff --git a/EightBit/Bus.cs b/EightBit/Bus.cs index 5832b44..81a2eba 100644 --- a/EightBit/Bus.cs +++ b/EightBit/Bus.cs @@ -87,16 +87,15 @@ namespace EightBit { var mapped = this.Mapping(absolute); var offset = (ushort)mapped.Offset(absolute); - if (mapped.Access == AccessLevel.ReadOnly) + if (mapped.Access != AccessLevel.ReadOnly) { - if (!this._writing) - { - this.Data = mapped.Memory.Peek(offset); - } - return ref this._data; + return ref mapped.Memory.Reference(offset); } - - return ref mapped.Memory.Reference(offset); + if (!this._writing) + { + this.Data = mapped.Memory.Peek(offset); + } + return ref this._data; } protected ref byte Reference() => ref this.Reference(this.Address.Joined); diff --git a/EightBit/Processor.cs b/EightBit/Processor.cs index c7d1a0d..7d0d588 100644 --- a/EightBit/Processor.cs +++ b/EightBit/Processor.cs @@ -186,7 +186,7 @@ namespace EightBit protected virtual void MemoryWrite() => this.BusWrite(); - protected virtual void BusWrite() => this.Bus.Write(); // N.B. Should be the only real call into the "Bus.Write" code. + protected void BusWrite() => this.Bus.Write(); // N.B. Should be the only real call into the "Bus.Write" code. protected void MemoryRead(byte low, byte high) { @@ -202,7 +202,7 @@ namespace EightBit protected virtual void MemoryRead() => this.BusRead(); - protected virtual void BusRead() => this.Bus.Read(); // N.B. Should be the only real call into the "Bus.Read" code. + protected void BusRead() => this.Bus.Read(); // N.B. Should be the only real call into the "Bus.Read" code. protected virtual void IncrementPC() => this.PC.Increment(); diff --git a/EightBit/Register16.cs b/EightBit/Register16.cs index d4d2763..1695af1 100644 --- a/EightBit/Register16.cs +++ b/EightBit/Register16.cs @@ -75,7 +75,11 @@ namespace EightBit public override bool Equals(object? obj) => this.Equals(obj as Register16); - public bool Equals(Register16? rhs) => ReferenceEquals(this, rhs) || (rhs is not null && rhs.Low == this.Low && rhs.High == this.High); + public bool Equals(Register16? rhs) + { + Debug.Assert(rhs is not null, "rhs cannot be null"); + return this.Joined == rhs.Joined; + } public void Assign(byte low, byte high = 0) { diff --git a/M6502/Core.cs b/M6502/Core.cs index 8d54cda..c738cc6 100644 --- a/M6502/Core.cs +++ b/M6502/Core.cs @@ -554,7 +554,7 @@ namespace M6502 // Can't use "FetchByte", since that would add an extra tick. this.ImmediateAddress(); - this.ReadFromBus(); + this.ReadFromMemory(); System.Diagnostics.Debug.Assert(this.Cycles == 1, "BUS read has introduced stray cycles"); this.RaiseSYNC(); @@ -566,32 +566,32 @@ namespace M6502 #region Bus/Memory access - protected sealed override void BusWrite() + protected sealed override void MemoryWrite() { this.OnWritingMemory(); this.Tick(); - this.WriteToBus(); + this.WriteToMemory(); this.OnWrittenMemory(); } - protected sealed override void BusRead() + protected sealed override void MemoryRead() { this.OnReadingMemory(); this.Tick(); - this.ReadFromBus(); + this.ReadFromMemory(); this.OnReadMemory(); } - private void ReadFromBus() + private void ReadFromMemory() { this.RaiseRW(); - base.BusRead(); + base.MemoryRead(); } - private void WriteToBus() + private void WriteToMemory() { this.LowerRW(); - base.BusWrite(); + base.MemoryWrite(); } protected abstract void ModifyWrite(byte data); diff --git a/MC6809/MC6809.cs b/MC6809/MC6809.cs index 5a58782..7d9731f 100644 --- a/MC6809/MC6809.cs +++ b/MC6809/MC6809.cs @@ -571,21 +571,21 @@ namespace MC6809 #region Bus control - protected override void BusWrite() + protected override void MemoryWrite() { this.OnWritingMemory(); this.Tick(); this.LowerRW(); - base.BusWrite(); + base.MemoryWrite(); this.OnWrittenMemory(); } - protected override void BusRead() + protected override void MemoryRead() { this.OnReadingMemory(); this.Tick(); this.RaiseRW(); - base.BusRead(); + base.MemoryRead(); this.OnReadMemory(); } @@ -772,7 +772,7 @@ namespace MC6809 else { // EA = ,R + 5-bit offset - this.EA.Joined = (ushort)(r.Joined + SignExtend(5, (byte)(type & (byte)Mask.Five))); + this.EA.Joined = (ushort)(r.Joined + SignExtend(5, type & (byte)Mask.Five)); this.SwallowCurrent(); this.SwallowRead(); }