- fixed decimal mode subtraction and addition
This commit is contained in:
steve 2018-07-05 19:03:32 +01:00
parent 913727407a
commit 37504437d4
2 changed files with 14 additions and 10 deletions

View file

@ -450,6 +450,19 @@ func testSubroutineInstructions(t *testing.T, mc *cpu.CPU, mem *MockMem) {
assert.CheckValueVCS(t, mc.SP, 255)
}
func testDecimalMode(t *testing.T, mc *cpu.CPU, mem *MockMem) {
var origin uint16
mem.Clear()
mc.Reset()
origin = mem.putInstructions(origin, 0xf8, 0xa9, 0x20, 0x38, 0xe9, 0x01)
step(t, mc) // SED
step(t, mc) // LDA #$20
step(t, mc) // SEC
step(t, mc) // SBC #$00
assert.CheckValueVCS(t, mc.A, 0x19)
}
func TestCPU(t *testing.T) {
mem := NewMockMem()
mc, err := cpu.New(mem)
@ -467,4 +480,5 @@ func TestCPU(t *testing.T) {
testJumps(t, mc, mem)
testComparisonInstructions(t, mc, mem)
testSubroutineInstructions(t, mc, mem)
testDecimalMode(t, mc, mem)
}

View file

@ -26,11 +26,6 @@ func (r *Register) AddDecimal(v interface{}, carry bool) (rcarry bool) {
panic(fmt.Sprintf("decimal mode addition only supported for uint8 values with 8 bit registers"))
}
// no need to do anything if operand is zero
if val == 0 {
return carry
}
runits := uint8(r.value) & 0x0f
rtens := (uint8(r.value) & 0xf0) >> 4
@ -69,11 +64,6 @@ func (r *Register) SubtractDecimal(v interface{}, carry bool) (rcarry bool) {
panic(fmt.Sprintf("decimal mode subtraction only supported for uint8 values with 8 bit registers"))
}
// no need to do anything if operand is zero
if val == 0 {
return carry
}
runits := int(r.value) & 0x0f
rtens := (int(r.value) & 0xf0) >> 4