X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Fhexfile.c;h=6411166c5e8e80d97225e865902dcb0d2ec3e43d;hb=ce24c216aa7eaf099dda2c9efeb9603a4076c93e;hp=9716aad03bd37ea3aeb3f1f7caf179a4706ba8f4;hpb=b23541495010180e3a69e3e1f64c934b28775878;p=emu8051.git diff --git a/src/hexfile.c b/src/hexfile.c index 9716aad..6411166 100644 --- a/src/hexfile.c +++ b/src/hexfile.c @@ -36,6 +36,31 @@ #include "common.h" #include "memory.h" +/* Convert integer to ASCII hex string. */ +void +int2asciihex(int val, char *str, int width) +{ + if (width == 1) + sprintf(str , "%.1X", (u_int8_t) val); + else if (width == 2) + sprintf(str , "%.2X", (u_int8_t) val); + else if (width == 4) + sprintf(str , "%.4X", (u_int16_t) val); + else + sprintf(str , "Err"); +} + +/* 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 +84,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; } @@ -83,7 +110,7 @@ LoadHexFile(const char *filename) /* Trying to open the file. */ fp = fopen(filename, "r"); if (fp == NULL) { - perror(PACKAGE); + perror(filename); /*ErrorLocation(__FILE__, __LINE__);*/ exit(EXIT_FAILURE); }