Skip to content

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

@univta0001

Description

@univta0001

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions