Better arrangement of decimal SBC/ADC implementations

This commit is contained in:
Adrian Conlon committed 2026-05-15 22:50:11 +01:00
1 parent 6d4d2f22e2
commit b5f646c641
3 files changed
+23 -24

No files matched your search

-3
View File
@@ -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);
+8 -8
View File
@@ -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
+15 -13
View File
@@ -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;
}