1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-19 09:31:24 +00:00
8bitworkshop/presets/nes/bcd.c

14 lines
409 B
C
Raw Normal View History

#include "neslib.h"
word bcd_add(word a, word b) {
2019-03-16 00:34:17 +00:00
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
}