diff --git a/EightBit/Bus.cs b/EightBit/Bus.cs index bca2e04..374e6f1 100644 --- a/EightBit/Bus.cs +++ b/EightBit/Bus.cs @@ -61,7 +61,8 @@ namespace EightBit public byte Read(Register16 absolute) { - return this.Read(absolute.Low, absolute.High); + this.Address.Assign(absolute); + return this.Read(); } public byte Read(byte low, byte high) @@ -92,18 +93,22 @@ namespace EightBit public void Write(ushort absolute, byte value) { this.Address.Word = absolute; - this.Write(value); + this.Data = value; + this.Write(); } public void Write(Register16 absolute, byte value) { - this.Write(absolute.Low, absolute.High, value); + this.Address.Assign(absolute); + this.Data = value; + this.Write(); } public void Write(byte low, byte high, byte value) { this.Address.Assign(low, high); - this.Write(value); + this.Data = value; + this.Write(); } [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1030:Use events where appropriate", Justification = "The word 'raise' is used in an electrical sense")] diff --git a/EightBit/IntelProcessor.cs b/EightBit/IntelProcessor.cs index 7cd84df..1677292 100644 --- a/EightBit/IntelProcessor.cs +++ b/EightBit/IntelProcessor.cs @@ -177,7 +177,7 @@ namespace EightBit protected void Restart(byte address) { - this.MEMPTR.Assign(address, 0); + this.MEMPTR.Assign(address); this.Call(this.MEMPTR); } diff --git a/EightBit/Processor.cs b/EightBit/Processor.cs index 5946cd1..ff156d2 100644 --- a/EightBit/Processor.cs +++ b/EightBit/Processor.cs @@ -202,23 +202,28 @@ namespace EightBit protected void MemoryWrite(byte low, byte high, byte data) { this.Bus.Address.Assign(low, high); - this.MemoryWrite(data); + this.Bus.Data = data; + this.MemoryWrite(); } protected void MemoryWrite(ushort address, byte data) { this.Bus.Address.Word = address; - this.MemoryWrite(data); + this.Bus.Data = data; + this.MemoryWrite(); } protected void MemoryWrite(Register16 address, byte data) { - this.MemoryWrite(address.Low, address.High, data); + this.Bus.Address.Assign(address); + this.Bus.Data = data; + this.MemoryWrite(); } protected void MemoryWrite(Register16 address) { - this.MemoryWrite(address.Low, address.High); + this.Bus.Address.Assign(address); + this.MemoryWrite(); } protected void MemoryWrite(byte data) @@ -245,7 +250,8 @@ namespace EightBit protected byte MemoryRead(Register16 address) { - return this.MemoryRead(address.Low, address.High); + this.Bus.Address.Assign(address); + return this.MemoryRead(); } protected virtual byte MemoryRead() @@ -279,7 +285,8 @@ namespace EightBit protected Register16 GetWordPaged(Register16 address) { - return this.GetWordPaged(address.High, address.Low); + this.Bus.Address.Assign(address); + return this.GetWordPaged(); } protected Register16 GetWordPaged(byte page, byte offset) @@ -292,7 +299,8 @@ namespace EightBit protected void SetWordPaged(Register16 address, Register16 value) { - this.SetWordPaged(address.High, address.Low, value); + this.Bus.Address.Assign(address); + this.SetWordPaged(value); } protected void SetWordPaged(byte page, byte offset, Register16 value) diff --git a/EightBit/Register16.cs b/EightBit/Register16.cs index 804f388..ac69f03 100644 --- a/EightBit/Register16.cs +++ b/EightBit/Register16.cs @@ -81,7 +81,7 @@ namespace EightBit public bool Equals(Register16? rhs) => ReferenceEquals(this, rhs) || (rhs is not null && rhs.Low == this.Low && rhs.High == this.High); - public void Assign(byte low, byte high) + public void Assign(byte low, byte high = 0) { this.Low = low; this.High = high; @@ -93,9 +93,17 @@ namespace EightBit } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ushort Increment() => this.Word++; + public Register16 Increment() + { + this.Word++; + return this; + } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ushort Decrement() => this.Word--; + public Register16 Decrement() + { + this.Word--; + return this; + } } } diff --git a/M6502/Core.cs b/M6502/Core.cs index 6312f3b..07d46a6 100644 --- a/M6502/Core.cs +++ b/M6502/Core.cs @@ -725,7 +725,7 @@ namespace M6502 protected void AbsoluteAddress() => this.FetchWordAddress(); - protected void ZeroPageAddress() => this.Bus.Address.Assign(this.FetchByte(), 0); + protected void ZeroPageAddress() => this.Bus.Address.Assign(this.FetchByte()); protected void ZeroPageIndirectAddress() {