[stella] Question about Circus Atari and BCD addition
bob.montgomery at thomson.com
bob.montgomery at thomson.com
Wed Jun 20 11:28:45 CDT 2007
Hi,
this is how Stella does BCD adds:
// Compute the BCD lookup table
uInt16 t;
for(t = 0; t < 256; ++t)
{
ourBCDTable[0][t] = ((t >> 4) * 10) + (t & 0x0f);
ourBCDTable[1][t] = (((t % 100) / 10) << 4) | (t % 10);
}
define(M6502_ADC, `{
uInt8 oldA = A;
{
Int16 sum = ourBCDTable[0][A] + ourBCDTable[0][operand] + (C ? 1 :
0);
C = (sum > 99);
A = ourBCDTable[1][sum & 0xff];
notZ = A;
N = A & 0x80;
V = ((oldA ^ A) & 0x80) && ((A ^ operand) & 0x80);
}
}')
If that's correct, then it looks like the 6507 first converts both
operands to BCD, treating each nibble like a decimal digit (whether or
not the nibble is <= 9), so $F0 = 150 and $FF = 165.
Then it adds the operands together, throws away the hundreds digit and
that's your result.
So $FF + $09 = 165 + 9 = 174 = $74
The real trickiness is when the result of adding the two operands is >
255. Then it wraps. So $FF + $FF = 165 + 165 = 74 (i.e., 330 - 256) =
$74
So apparently adding $0A is exactly the same as adding $10.
All assuming that Stella is accurate.
-Bob
More information about the Stella
mailing list