diff --git a/EightBit/BigEndianProcessor.cs b/EightBit/BigEndianProcessor.cs index 179ac5f..2a00b7d 100644 --- a/EightBit/BigEndianProcessor.cs +++ b/EightBit/BigEndianProcessor.cs @@ -51,8 +51,10 @@ namespace EightBit protected override void PopInto(Register16 into) { //ArgumentNullException.ThrowIfNull(into); - into.High = this.Pop(); - into.Low = this.Pop(); + this.Pop(); + into.High = this.Bus.Data; + this.Pop(); + into.Low = this.Bus.Data; } protected override void PushShort(Register16 value) diff --git a/EightBit/IntelProcessor.cs b/EightBit/IntelProcessor.cs index 2263dfe..b1c14ea 100644 --- a/EightBit/IntelProcessor.cs +++ b/EightBit/IntelProcessor.cs @@ -148,11 +148,10 @@ namespace EightBit this.MemoryWrite(this.SP, value); } - protected sealed override byte Pop() + protected sealed override void Pop() { this.MemoryRead(this.SP); this.SP.Increment(); - return this.Bus.Data; } protected sealed override void GetShort() diff --git a/EightBit/LittleEndianProcessor.cs b/EightBit/LittleEndianProcessor.cs index fd48011..4ad6497 100644 --- a/EightBit/LittleEndianProcessor.cs +++ b/EightBit/LittleEndianProcessor.cs @@ -52,8 +52,10 @@ namespace EightBit protected override void PopInto(Register16 into) { //ArgumentNullException.ThrowIfNull(into); - into.Low = this.Pop(); - into.High = this.Pop(); + this.Pop(); + into.Low = this.Bus.Data; + this.Pop(); + into.High = this.Bus.Data; } protected override void PushShort(Register16 value) diff --git a/EightBit/Processor.cs b/EightBit/Processor.cs index c4e406b..e6795d1 100644 --- a/EightBit/Processor.cs +++ b/EightBit/Processor.cs @@ -267,7 +267,7 @@ namespace EightBit protected abstract void Push(byte value); - protected abstract byte Pop(); + protected abstract void Pop(); protected abstract void PushShort(Register16 value); diff --git a/LR35902/LR35902.FuseTest/TestRunner.cs b/LR35902/LR35902.FuseTest/TestRunner.cs index 7101267..c89d509 100644 --- a/LR35902/LR35902.FuseTest/TestRunner.cs +++ b/LR35902/LR35902.FuseTest/TestRunner.cs @@ -22,12 +22,14 @@ namespace LR35902.FuseTest private readonly Test test = test; private readonly Result result = result; private readonly EightBit.Ram ram = new(0x10000); + private EightBit.MemoryMapping? mapping; public bool Failed { get; private set; } = false; public bool Unimplemented { get; private set; } = false; - public override EightBit.MemoryMapping Mapping(ushort address) => new(this.ram, 0, EightBit.Mask.Sixteen, EightBit.AccessLevel.ReadWrite); + public override EightBit.MemoryMapping Mapping(ushort address) => + this.mapping ??= new EightBit.MemoryMapping(this.ram, 0, EightBit.Mask.Sixteen, EightBit.AccessLevel.ReadWrite); public void Run() { diff --git a/M6502/Core.cs b/M6502/Core.cs index 7c7c2bd..ee3a76c 100644 --- a/M6502/Core.cs +++ b/M6502/Core.cs @@ -586,11 +586,10 @@ namespace M6502 #region Stack access - protected override byte Pop() + protected override void Pop() { this.RaiseStack(); this.MemoryRead(); - return this.Bus.Data; } protected override void Push(byte value) @@ -861,7 +860,7 @@ namespace M6502 private void STX() => this.MemoryWrite(this.X); - private void LDY() => this.Y = this.Through(); + protected void LDY() => this.Y = this.Through(); private void STY() => this.MemoryWrite(this.Y); @@ -1105,7 +1104,8 @@ namespace M6502 private void PLA() { this.SwallowPop(); - this.A = this.Through(this.Pop()); + this.Pop(); + this.LDA(); } private void PHP() => this.Push(SetBit(this.P, StatusBits.BF)); @@ -1113,7 +1113,8 @@ namespace M6502 private void PLP() { this.SwallowPop(); - this.P = ClearBit(SetBit(this.Pop(), StatusBits.RF), StatusBits.BF); + this.Pop(); + this.P = ClearBit(SetBit(this.Bus.Data, StatusBits.RF), StatusBits.BF); } private void RTI() diff --git a/M6502/M6502.HarteTest/TestRunner.cs b/M6502/M6502.HarteTest/TestRunner.cs index b55e263..063bdf6 100644 --- a/M6502/M6502.HarteTest/TestRunner.cs +++ b/M6502/M6502.HarteTest/TestRunner.cs @@ -6,8 +6,8 @@ { public Ram RAM { get; } = new(0x10000); - public MOS6502 CPU { get; } - //public WDC65C02 CPU { get; } + //public MOS6502 CPU { get; } + public WDC65C02 CPU { get; } private readonly MemoryMapping _mapping; diff --git a/M6502/WDC65C02.cs b/M6502/WDC65C02.cs index c27b0cf..e492264 100644 --- a/M6502/WDC65C02.cs +++ b/M6502/WDC65C02.cs @@ -353,7 +353,8 @@ namespace M6502 private void PLX() { this.SwallowPop(); - this.X = this.Through(this.Pop()); + this.Pop(); + this.LDX(); } private void PHY() => this.Push(this.Y); @@ -361,7 +362,8 @@ namespace M6502 private void PLY() { this.SwallowPop(); - this.Y = this.Through(this.Pop()); + this.Pop(); + this.LDY(); } private void BRA() => this.Branch(true); diff --git a/MC6809/MC6809.cs b/MC6809/MC6809.cs index 97ea5cc..3ebff59 100644 --- a/MC6809/MC6809.cs +++ b/MC6809/MC6809.cs @@ -593,7 +593,7 @@ namespace MC6809 #region Push/Pop - protected override byte Pop() => this.PopS(); + protected override void Pop() => this.PopS(); protected override void Push(byte value) => this.PushS(value); @@ -611,19 +611,20 @@ namespace MC6809 this.Push(stack, value.High); } - protected byte Pop(Register16 stack) + protected void Pop(Register16 stack) { this.MemoryRead(stack); stack.Increment(); - return this.Bus.Data; } - private byte PopS() => this.Pop(this.S); + private void PopS() => this.Pop(this.S); protected Register16 PopWord(Register16 stack) { - this.Intermediate.High = this.Pop(stack); - this.Intermediate.Low = this.Pop(stack); + this.Pop(stack); + this.Intermediate.High = this.Bus.Data; + this.Pop(stack); + this.Intermediate.Low = this.Bus.Data; return this.Intermediate; } @@ -1054,22 +1055,26 @@ namespace MC6809 if ((control & (byte)Bits.Bit0) != 0) { - this.CC = this.Pop(stack); + this.Pop(stack); + this.CC = this.Bus.Data; } if ((control & (byte)Bits.Bit1) != 0) { - this.A = this.Pop(stack); + this.Pop(stack); + this.A = this.Bus.Data; } if ((control & (byte)Bits.Bit2) != 0) { - this.B = this.Pop(stack); + this.Pop(stack); + this.B = this.Bus.Data; } if ((control & (byte)Bits.Bit3) != 0) { - this.DP = this.Pop(stack); + this.Pop(stack); + this.DP = this.Bus.Data; } // Sixteen-bit registers