X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Fhexfile.c;h=57540bc4d9f91f4cef9199f40498870e5e3a6925;hb=8d9b71ab3848729da1cf90a38a599be0b08cbb5c;hp=5ec2055abe1769982c82fd0b48ad504c5bac43fe;hpb=31155ac8672e72db0d3cab3e4167a3c00f73a2bc;p=emu8051.git diff --git a/src/hexfile.c b/src/hexfile.c index 5ec2055..57540bc 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)