X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Fhexfile.c;h=ef828b84f49a0c8889ec491b55882c2e1a709532;hb=3e67c30ca5f1f959c06d1061556fa46c11163473;hp=9716aad03bd37ea3aeb3f1f7caf179a4706ba8f4;hpb=b23541495010180e3a69e3e1f64c934b28775878;p=emu8051.git diff --git a/src/hexfile.c b/src/hexfile.c index 9716aad..ef828b8 100644 --- a/src/hexfile.c +++ b/src/hexfile.c @@ -36,6 +36,27 @@ #include "common.h" #include "memory.h" +/* Convert integer to ASCII hex string. */ +void +int2asciihex(int val, char *str, int width) +{ + if (width == 2) + sprintf(str , "%.2X", (u_int8_t) val); + else if (width == 4) + sprintf(str , "%.4X", (u_int16_t) val); +} + +/* Convert ASCII hex string to integer. */ +int +asciihex2int(char *str) +{ + int val; + + sscanf(str, "%X", &val); + + return val; +} + /* Convert an ascii string to an hexadecimal number. */ unsigned int Ascii2Hex(char *istring, int length) @@ -59,8 +80,10 @@ Ascii2Hex(char *istring, int length) result <<= 4; result += ascii_code; - } else + } else { printf("%s: In Ascii2Hex(), syntax error.\n", PACKAGE); + printf(" str=%s, length=%d\n", istring, length); + } } return result; }