1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-12-01 13:50:30 +00:00
8bitworkshop/presets/c64/bcd.c
2020-02-03 22:17:27 -06:00

14 lines
409 B
C

#include "common.h"
word bcd_add(word a, word b) {
register word c, d; // intermediate values
c = a + 0x0666; // add 6 to each BCD digit
d = c ^ b; // sum without carry propagation
c += b; // provisional sum
d = ~(c ^ d) & 0x1110; // just the BCD carry bits
d = (d >> 2) | (d >> 3); // correction
return c - d; // corrected BCD sum
}