[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with confirmation on a small bit of assembly?



David Empson wrote:

> On the 6502, if you use decimal mode, it doesn't implement some of the
> flags (if I remember right C is OK, but N, Z and V don't get modified by
> decimal ADC/SBC). This behaviour was amended on the 65C02 (and is the
> most reliable way of detecting a 6502 vs 65C02).

Not quite... they're being set, just not in a very useful fashion. The
following is the code from ADC in VICE (Commodore emulator):

> if (LOCAL_DECIMAL()) {                                                  \
>           tmp = (reg_a & 0xf) + (tmp_value & 0xf) + (reg_p & 0x1);            \
>           if (tmp > 0x9)                                                      \
>               tmp += 0x6;                                                     \
>           if (tmp <= 0x0f)                                                    \
>               tmp = (tmp & 0xf) + (reg_a & 0xf0) + (tmp_value & 0xf0);        \
>           else                                                                \
>               tmp = (tmp & 0xf) + (reg_a & 0xf0) + (tmp_value & 0xf0) + 0x10; \
>           LOCAL_SET_ZERO(!((reg_a + tmp_value + (reg_p & 0x1)) & 0xff));      \
>           LOCAL_SET_SIGN(tmp & 0x80);                                         \
>           LOCAL_SET_OVERFLOW(((reg_a ^ tmp) & 0x80)                           \
>                               && !((reg_a ^ tmp_value) & 0x80));              \
>           if ((tmp & 0x1f0) > 0x90)                                           \
>               tmp += 0x60;                                                    \
>           LOCAL_SET_CARRY((tmp & 0xff0) > 0xf0);                              \
>       }


All the best,
-- 
Linards Ticmanis