andrewem wrote:
I read that in when in decimal mode the Zero Flag is invalid. What does this mean? In other words, does it mean that the Zero Flag is not updated?
No, the Z flag will always be affected by a ADC or SBC instruction. Invalid means that the Z flag does not always correctly reflect the result in the accumulator. For example, after:
Code:
SED
CLC
LDA #$99
ADC #$01
the accumulator is $00, but the Z flag is clear.
On the other hand, after:
Code:
SED
SEC
LDA #$01
SBC #$01
the accumulator is $00, but the Z flag is set. So the Z flag is sometimes correct, sometimes not.
The Z flag is only invalid on the 6502. On the 65C02 and the 65816, the Z flag correctly reflect the accumulator contents.
On the 6502, if you want to predict the value of the Z flag after an ADC or SBC, just add or subtract the numbers (accounting for the carry) as though they were binary number rather than BCD numbers. In other words, after:
Code:
SED
ADC NUMBER
the Z flag will be the same as after:
Code:
CLD
ADC NUMBER
assuming, of course, that upon entry, the accumulator and carry were the same. The same is true of SBC.