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

Re: Why BCD For Apple II+ & Apple //e Show Differently?



Bryan Parkoff writes ...
> 
>     Here is my sample code.
> 
>     SED
>     LDA    #$99
>     CLC
>     ADC    #$01
>     CLD
> 
>     I tell decimal flag to turn on BCD (Binary Coded Demical).  The result
> for Apple II+ shows $20, but it for Apple //e shows $00.  I suspect that the
> result is not correct.  It may be something that BCD is not calculated
> correct.

     Are you sure your II+ gives 20 as the result? On our II+ the value that
results from the code is 00. Like, if you do a STA $FF (85 FF) after the CLD,
the value in location $00FF is 00.

     99 + 1 = 100; so 00 is right for a 1-byte result for the decimal addition.
(Plus, the Carry flag is set after the addition.)



>     Or, HEX converts to BCD before do BCD math, and then converts back to
> HEX.
 ....

     I think what happens is that, in Decimal mode, the registers just treat
the values as though they are decimal at the time of addition.

     For instance, if you have Decimal mode set (and Carry cleared) and happen
to load in a value of 3C and store it, the value stored is 3C. But, if you load
3C and add 00, the value stored is 30 + 12 = 42. (If Carry was set, the result
would be 30 + 12 + 1 = 43.)



Rubywand