mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-25 16:31:42 +00:00
With some degree of hit and hope, correct 65C02 results.
This commit is contained in:
parent
39ee75d94a
commit
4d6ffa7a2e
@ -48,10 +48,6 @@ class BCDTest: XCTestCase, CSTestMachineTrapHandler {
|
|||||||
testBCD(processor: .processor65C02)
|
testBCD(processor: .processor65C02)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func test6816BCD() {
|
|
||||||
// testBCD(processor: .processor65816)
|
|
||||||
// }
|
|
||||||
|
|
||||||
private var output: String = ""
|
private var output: String = ""
|
||||||
func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) {
|
func testMachine(_ testMachine: CSTestMachine, didTrapAtAddress address: UInt16) {
|
||||||
let machine6502 = testMachine as! CSTestMachine6502
|
let machine6502 = testMachine as! CSTestMachine6502
|
||||||
|
@ -298,6 +298,13 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
|
|||||||
// The bottom nibble is adjusted if there was carry into the top nibble;
|
// The bottom nibble is adjusted if there was carry into the top nibble;
|
||||||
// this doesn't cause additional carry.
|
// this doesn't cause additional carry.
|
||||||
if(!Numeric::carried_in<4>(a_, operand_, result)) {
|
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);
|
result = (result & 0xf0) | ((result + 0x0a) & 0xf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +315,7 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
|
|||||||
|
|
||||||
a_ = result;
|
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.
|
// 65C02 fix: set the N and Z flags based on the final, decimal result.
|
||||||
flags_.set_nz(a_);
|
flags_.set_nz(a_);
|
||||||
read_mem(operand_, address_.full);
|
read_mem(operand_, address_.full);
|
||||||
@ -351,7 +358,7 @@ template <Personality personality, typename T, bool uses_ready_line> void Proces
|
|||||||
|
|
||||||
a_ = result;
|
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
|
// 65C02 fix: N and Z are set correctly based on the final BCD result, at the cost of
|
||||||
// an extra cycle.
|
// an extra cycle.
|
||||||
flags_.set_nz(a_);
|
flags_.set_nz(a_);
|
||||||
|
Loading…
Reference in New Issue
Block a user