2021-03-02 01:38:55 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <lib/blib.h>
|
2021-08-22 19:29:18 +03:00
|
|
|
#include <lib/print.h>
|
|
|
|
|
2021-09-06 09:52:41 +03:00
|
|
|
bool verbose = true;
|
2021-11-20 23:47:51 +03:00
|
|
|
bool quiet = false;
|
2022-02-07 04:10:57 +03:00
|
|
|
bool serial = false;
|
2021-09-06 09:52:41 +03:00
|
|
|
|
2021-03-02 01:38:55 +03:00
|
|
|
uint8_t bcd_to_int(uint8_t val) {
|
|
|
|
return (val & 0x0f) + ((val & 0xf0) >> 4) * 10;
|
|
|
|
}
|
2021-11-01 23:38:36 +03:00
|
|
|
uint8_t int_to_bcd(uint8_t val) {
|
|
|
|
return (val % 10) | (val / 10) << 4;
|
|
|
|
}
|
2021-03-02 01:38:55 +03:00
|
|
|
|
|
|
|
int digit_to_int(char c) {
|
|
|
|
if (c >= 'a' && c <= 'f') {
|
|
|
|
return (c - 'a') + 10;
|
|
|
|
}
|
|
|
|
if (c >= 'A' && c <= 'F') {
|
|
|
|
return (c - 'A') + 10;
|
|
|
|
}
|
|
|
|
if (c >= '0' && c <= '9'){
|
|
|
|
return c - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t strtoui(const char *s, const char **end, int base) {
|
|
|
|
uint64_t n = 0;
|
|
|
|
for (size_t i = 0; ; i++) {
|
|
|
|
int d = digit_to_int(s[i]);
|
|
|
|
if (d == -1) {
|
|
|
|
if (end != NULL)
|
|
|
|
*end = &s[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n = n * base + d;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|