diff --git a/EightBit/MemoryMapping.cs b/EightBit/MemoryMapping.cs index da5fd5e..0a92995 100644 --- a/EightBit/MemoryMapping.cs +++ b/EightBit/MemoryMapping.cs @@ -4,21 +4,43 @@ namespace EightBit { - public sealed class MemoryMapping(Memory memory, ushort begin, ushort mask, AccessLevel access) + public sealed class MemoryMapping { + public MemoryMapping(Memory memory, ushort begin, ushort mask, AccessLevel access) + { + this._memory = memory; + this._begin = begin; + this._mask = mask; + this._access = access; + for (int i = ushort.MinValue; i < ushort.MaxValue + 1; ++i) + { + System.Diagnostics.Debug.Assert(i >= ushort.MinValue); + System.Diagnostics.Debug.Assert(i <= ushort.MaxValue); + this._offsets[i] = this.CalculateOffset((ushort)i); + } + } + public MemoryMapping(Memory memory, ushort begin, Mask mask, AccessLevel access) : this(memory, begin, (ushort)mask, access) { } - public Memory Memory { get; set; } = memory; + private readonly int[] _offsets = new int[ushort.MaxValue + 1]; + private readonly Memory _memory; + private readonly ushort _begin; + private readonly ushort _mask; + private readonly AccessLevel _access; - public ushort Begin { get; set; } = begin; + public Memory Memory => this._memory; - public ushort Mask { get; set; } = mask; + public ushort Begin => this._begin; - public AccessLevel Access { get; set; } = access; + public ushort Mask => this._mask; - public int Offset(ushort absolute) => (absolute - this.Begin) & this.Mask; + public AccessLevel Access => this._access; + + private int CalculateOffset(ushort absolute) => (absolute - this.Begin) & this.Mask; + + public int Offset(ushort absolute) => this._offsets[absolute]; } } diff --git a/EightBit/Register16.cs b/EightBit/Register16.cs index 098fb08..0c31602 100644 --- a/EightBit/Register16.cs +++ b/EightBit/Register16.cs @@ -89,7 +89,8 @@ namespace EightBit public void Assign(Register16 from) { - this.Assign(from.Low, from.High); + this.Low = from.Low; + this.High = from.High; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/M6502/Core.cs b/M6502/Core.cs index 80aa131..b05be1a 100644 --- a/M6502/Core.cs +++ b/M6502/Core.cs @@ -972,11 +972,11 @@ namespace M6502 private void JSR() { - this.Intermediate.Low = this.FetchByte(); + var low = this.FetchByte(); this.SwallowPop(); this.PushWord(this.PC); - this.PC.High = this.FetchByte(); - this.PC.Low = this.Intermediate.Low; + var high = this.FetchByte(); + this.PC.Assign(low, high); } private void PHP() => this.Push(SetBit(this.P, StatusBits.BF));