Skip to content

ADC wrong N & Z flags in BCD #70

@adumont

Description

@adumont

I believe I've found a bug in ADC handling of N & Z flags in BCD mode:

the idea is to run this test:

; f8 38 a9 00 69 99
SED
SEC
LDA #$00
ADC #$99

So I run this piece of code:

from py65.devices.mpu65c02 import MPU as CMOS65C02

mpu = CMOS65C02()
mpu.memory = 0x10000 * [0xEA]

mpu.p |= mpu.DECIMAL
mpu.p |= mpu.CARRY
mpu.pc = 0x0000

mpu.a = 0
mpu.memory[0x0000]=0x69
mpu.memory[0x0001]=0x99
mpu.step()

which result in:

        PC  AC XR YR SP NV-BDIZC
65C02: 0002 00 00 00 ff 10111001

Accumulator is correctly set to 00 but the Z and N flags seem to have incorrect values.

Running the same test in Easy6502 (https://skilldrick.github.io/easy6502/), and Visual6502 (http://www.visual6502.org/JSSim/expert.html) return:

NV-BDIZC  A=$00 X=$00 Y=$00
00111011

so here N is not set (expected), and Z is set.

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