diff --git a/M6502/Core.cs b/M6502/Core.cs index 593f0fd..fc20c97 100644 --- a/M6502/Core.cs +++ b/M6502/Core.cs @@ -915,10 +915,7 @@ namespace M6502 { var operand = this.A; this.A = this.SUB(operand, CarryTest((byte)~this.P)); - this.PostSUB(operand); - //this.AdjustOverflowSubtract(operand); - //this.ResetFlag(StatusBits.CF, this.Intermediate.High); } private byte SUB(byte operand, int borrow) => this.Denary != 0 ? this.DecimalSUB(operand, borrow) : this.BinarySUB(operand, borrow); diff --git a/M6502/MOS6502.cs b/M6502/MOS6502.cs index bf953b3..ebfe62f 100644 --- a/M6502/MOS6502.cs +++ b/M6502/MOS6502.cs @@ -343,24 +343,24 @@ namespace M6502 protected override byte BinaryADC(byte data) { - var returned = base.BinaryADC(data); - this.AdjustNZ(returned); - return returned; + var result = base.BinaryADC(data); + this.AdjustNZ(result); + return result; } protected override byte BinarySUB(byte operand, int borrow = 0) { - var returned = base.BinarySUB(operand, borrow); - this.AdjustNZ(this.Intermediate.Low); - return returned; + var result = base.BinarySUB(operand, borrow); + this.AdjustNZ(result); + return result; } protected override byte DecimalSUB(byte operand, int borrow) { - var returned = base.DecimalSUB(operand, borrow); + var result = base.DecimalSUB(operand, borrow); this.AdjustNZ(this.Intermediate.Low); - return returned; + return result; } #endregion diff --git a/M6502/WDC65C02.cs b/M6502/WDC65C02.cs index 3e809f7..8b800f5 100644 --- a/M6502/WDC65C02.cs +++ b/M6502/WDC65C02.cs @@ -296,24 +296,18 @@ namespace M6502 return returned; } - protected override void SBC() + protected override void PostSUB(byte operand) { - base.SBC(); - if (this.Denary != 0) - { - this.AdjustNZ(this.A); - if (this.ImmediateInstruction) - this.MemoryRead(0x00, 0x00); - else - this.SwallowSpin(); - } + // PostSUB needs to be empty, so we can sort out the + // post calculations memory operations in DecimalSUB. } protected override byte BinarySUB(byte operand, int borrow = 0) { - var returned = base.BinarySUB(operand, borrow); - this.AdjustNZ(this.Intermediate.Low); - return returned; + var result = base.BinarySUB(operand, borrow); + base.PostSUB(operand); + this.AdjustNZ(result); + return result; } protected override byte DecimalSUB(byte operand, int borrow) @@ -334,6 +328,14 @@ namespace M6502 result -= 0x60; } + base.PostSUB(operand); + this.AdjustNZ(result); + + if (this.ImmediateInstruction) + this.MemoryRead(0x00, 0x00); + else + this.SwallowSpin(); + return result; }