From 8331b4818eef94063b5e77175ae2d0203c18e517 Mon Sep 17 00:00:00 2001 From: Adrian Conlon <98398945+AdrianConlon@users.noreply.github.com> Date: Sun, 11 May 2025 21:30:15 +0100 Subject: [PATCH] Couple of small Register16 adjustments --- EightBit/Processor.cs | 2 +- EightBit/Register16.cs | 33 ++++++++++++++------------------- 2 files changed, 15 insertions(+), 20 deletions(-) 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--; } }