Couple of small Register16 adjustments

This commit is contained in:
Adrian Conlon
2025-05-11 21:30:15 +01:00
parent 36e983526e
commit 8331b4818e
2 changed files with 15 additions and 20 deletions

View File

@@ -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);

View File

@@ -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)
{
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--;
}
}