apple2js icon indicating copy to clipboard operation
apple2js copied to clipboard

Apple 2 jse 65c02 sub opcode with decimal with invalid bcd generate wrong value

Open univta0001 opened this issue 7 months ago • 0 comments

For the SUB opcode in the decimal mode with invalid BCD value, it behaves differently for 6502 and 65C02.

Example code to demonstrate this different is mentioned in section 4.1 of http://www.6502.org/tutorials/decimal_mode.html.

SED      ; decimal mode
SEC
LDA #$90
SBC #$0F ; invalid BCD!

In 6502 CPU, accumulator returns 0x8B. However, in 65C02, accumulator returns 0x7B.

For Apple2JSE, it is returning 0x8B instead of 0x7B.

In 65C02, the fix up of the BCD of the low nibble will propagate to the high nibble. It uses 0xfa instead of the usual (0xa or -0x6) in most emulator implementation for 6502.

More details can be found at https://stackoverflow.com/questions/29193303/6502-emulation-proper-way-to-implement-adc-and-sbc

univta0001 avatar Jul 21 '24 08:07 univta0001