diff --git a/OSBindings/Mac/Clock SignalTests/BCDTest.swift b/OSBindings/Mac/Clock SignalTests/BCDTest.swift index aaf3ad3fc..e3befb41e 100644 --- a/OSBindings/Mac/Clock SignalTests/BCDTest.swift +++ b/OSBindings/Mac/Clock SignalTests/BCDTest.swift @@ -48,10 +48,6 @@ class BCDTest: XCTestCase, CSTestMachineTrapHandler { testBCD(processor: .processor65C02) } -// func test6816BCD() { -// testBCD(processor: .processor65816) -// } - private var output: String = "" func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) { let machine6502 = testMachine as! CSTestMachine6502 diff --git a/Processors/6502/Implementation/6502Implementation.hpp b/Processors/6502/Implementation/6502Implementation.hpp index bdfea893c..e891ce9a2 100644 --- a/Processors/6502/Implementation/6502Implementation.hpp +++ b/Processors/6502/Implementation/6502Implementation.hpp @@ -298,6 +298,13 @@ template void Proces // The bottom nibble is adjusted if there was carry into the top nibble; // this doesn't cause additional carry. if(!Numeric::carried_in<4>(a_, operand_, result)) { + // 65C02 difference: carry from the calculation below is applied as + // borrow to the nibble above. + if constexpr (is_65c02(personality)) { + if((result & 0xf) < 0x6) { + result -= 0x10; + } + } result = (result & 0xf0) | ((result + 0x0a) & 0xf); } @@ -308,7 +315,7 @@ template void Proces a_ = result; - if(is_65c02(personality)) { + if constexpr (is_65c02(personality)) { // 65C02 fix: set the N and Z flags based on the final, decimal result. flags_.set_nz(a_); read_mem(operand_, address_.full); @@ -351,7 +358,7 @@ template void Proces a_ = result; - if(is_65c02(personality)) { + if constexpr (is_65c02(personality)) { // 65C02 fix: N and Z are set correctly based on the final BCD result, at the cost of // an extra cycle. flags_.set_nz(a_);