diff --git a/EightBit/Processor.cs b/EightBit/Processor.cs index 6d7238c..5a50630 100644 --- a/EightBit/Processor.cs +++ b/EightBit/Processor.cs @@ -311,7 +311,7 @@ namespace EightBit this.SetWord(value); } - protected void Jump(ushort destination) => this.PC.Assign(destination); + protected void Jump(ushort destination) => this.PC.Word = destination; protected void Jump(Register16 destination) => this.PC.Assign(destination); diff --git a/EightBit/Register16.cs b/EightBit/Register16.cs index 2e7dc53..804f388 100644 --- a/EightBit/Register16.cs +++ b/EightBit/Register16.cs @@ -4,6 +4,7 @@ namespace EightBit { + using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [StructLayout(LayoutKind.Explicit, Size = 2)] @@ -20,7 +21,7 @@ namespace EightBit public Register16(ushort value) { - this.Assign(value); + this.Word = value; } public Register16() @@ -48,19 +49,22 @@ namespace EightBit this.High = rhs.High; } - public ushort Word + public unsafe ushort Word { get { - unsafe + fixed (byte* bytes = &this._low) { - fixed (byte* bytes = &this._low) - { - return *(ushort*)bytes; - } + return *(ushort*)bytes; + } + } + set + { + fixed (byte* bytes = &this._low) + { + *(ushort*)bytes = value; } } - set => this.Assign(value); } public ref byte Low => ref this._low; @@ -88,19 +92,10 @@ namespace EightBit this.Assign(from.Low, from.High); } - public void Assign(ushort from) - { - unsafe - { - fixed (byte* bytes = &this._low) - { - *(ushort*)bytes = from; - } - } - } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ushort Increment() => this.Word++; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ushort Decrement() => this.Word--; } }