1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-30 06:50:39 +00:00
8bitworkshop/presets/c64/bcd.c

14 lines
409 B
C
Raw Normal View History

2020-02-02 18:17:31 +00:00
#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
}