summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..8be15a4
--- /dev/null
+++ b/util.c
@@ -0,0 +1,38 @@
+#include "project.h"
+
+int set_parity (uint8_t *d, unsigned s, unsigned e)
+{
+ unsigned i;
+ uint8_t p = 0;
+
+ for (i = s; i <= e; ++i)
+ p ^= d[i];
+
+ return !p;
+}
+
+
+void bcd_set (uint8_t *d, unsigned s, unsigned e, unsigned v)
+{
+ unsigned c, i, w;
+
+
+ w = v % 10;
+
+ for (i = e, c = 1 ; i >= s; --i) {
+
+ d[i] = !! (c & w) ;
+
+ if (c & 0x77777777)
+ c <<= 1;
+ else {
+ c >>= 3;
+ c *= 10;
+ v = v / 10;
+ w = v % 10;
+ }
+ }
+}
+
+
+