FreeCalypso > hg > freecalypso-tools
comparison target-utils/libcommon/hexstrings.c @ 658:0da2cf5a999c
target-utils: libload eliminated
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Tue, 03 Mar 2020 06:06:17 +0000 |
| parents | target-utils/libload/hexstrings.c@e7502631a0f9 |
| children |
comparison
equal
deleted
inserted
replaced
| 657:742c99c1ff52 | 658:0da2cf5a999c |
|---|---|
| 1 /* | |
| 2 * The decode_hex_digits() function contained in this module | |
| 3 * will be used by the XRAM and flash loading commands | |
| 4 * which take SREC-like long hex string arguments. | |
| 5 */ | |
| 6 | |
| 7 #include <ctype.h> | |
| 8 #include "types.h" | |
| 9 | |
| 10 decode_hex_digits(str, ndigits, valp) | |
| 11 char *str; | |
| 12 int ndigits; | |
| 13 u32 *valp; | |
| 14 { | |
| 15 u32 accum; | |
| 16 int i, c; | |
| 17 | |
| 18 accum = 0; | |
| 19 for (i = 0; i < ndigits; i++) { | |
| 20 c = *str++; | |
| 21 if (!isxdigit(c)) | |
| 22 return(-1); | |
| 23 accum <<= 4; | |
| 24 if (isdigit(c)) | |
| 25 accum += c - '0'; | |
| 26 else if (islower(c)) | |
| 27 accum += c - 'a' + 10; | |
| 28 else | |
| 29 accum += c - 'A' + 10; | |
| 30 } | |
| 31 *valp = accum; | |
| 32 return(0); | |
| 33 } |
