diff options
Diffstat (limited to 'a8xd.c')
-rw-r--r-- | a8xd.c | 67 |
1 files changed, 53 insertions, 14 deletions
@@ -16,6 +16,7 @@ const char *byte_format = "%02x"; int verbose = 0, color = 1, disp_offset = 0, maxlen = 0; int seek_whence = 0, seekpos = 0, filepos = 0, limit = 0; +int graphics = 0; const char *self; @@ -110,12 +111,27 @@ char *get_color(unsigned char c) { unsigned char c7 = c & 0x7f; static char outbuf[32]; - if(c == 0 || c == 0x9b) { - color = 1; /* red */ - } else if(c7 < 32 || c7 == 0x60 || c7 == 0x7b || c7 == 0x7d || c7 == 0x7e || c7 == 0x7f) { - color = 3; /* yellow/orange */ + if(graphics) { + if(c < 0x20) + color = 2; + else if(c >= 0x20 && c < 0x60) + color = 3; + else if(c >= 0x60 && c < 0x80) + color = 2; + else if(c >= 0x80 && c < 0xa0) + color = 1; + else if(c >= 0xa0 && c < 0xe0) + color = 6; /* cyan (blue is too dark on most terminals) */ + else /* c >= 0xe0 */ + color = 1; } else { - color = 2; + if(c == 0 || c == 0x9b) { + color = 1; /* red */ + } else if(c7 < 32 || c7 == 0x60 || c7 == 0x7b || c7 == 0x7d || c7 == 0x7e || c7 == 0x7f) { + color = 3; /* yellow/orange */ + } else { + color = 2; /* green */ + } } if(color) { @@ -127,6 +143,24 @@ char *get_color(unsigned char c) { return outbuf; } +/* in GR.1 or GR.2: + $00-$1F get displayed in green, as $20-$2F. + $20-$5F get displayed in orange, as themselves. + $60-$7F get displayed in green, as $40-$5F. + for $80-$FF, same thing, but green is red, and orange is blue. +*/ +char *get_graphics(unsigned char c) { + static char result[2]; + c &= 0x7f; + if(c < 0x20) + c += 0x20; + else if(c >= 0x60) + c -= 0x20; + result[0] = c; + result[1] = 0; + return result; +} + void fake_seek(FILE *input) { char junkbuf[1024]; int pos = 0, chunksize; @@ -168,6 +202,7 @@ void seek_input(FILE *input) { void dump_line(const unsigned char *buf, int len) { char hex[1024], asc[1024]; int hpos = 0, apos = 0, count = len; + unsigned char c, inv; memset(hex, 0, sizeof(hex)); memset(asc, 0, sizeof(asc)); @@ -176,17 +211,20 @@ void dump_line(const unsigned char *buf, int len) { fputs(": ", stdout); while(len) { - if(color) hpos += sprintf(hex + hpos, "%s", get_color(*buf)); - if(*buf & 0x80) hpos += sprintf(hex + hpos, "%s", inverse_on); - hpos += sprintf(hex + hpos, byte_format, *buf); - if(color || *buf & 0x80) hpos += sprintf(hex + hpos, "%s", color_off); + c = *buf; + inv = !graphics && (c & 0x80); + + if(color) hpos += sprintf(hex + hpos, "%s", get_color(c)); + if(inv) hpos += sprintf(hex + hpos, "%s", inverse_on); + hpos += sprintf(hex + hpos, byte_format, c); + if(color || inv) hpos += sprintf(hex + hpos, "%s", color_off); hex[hpos++] = ' '; if(count - len == 7) hex[hpos++] = ' '; - if(color) apos += sprintf(asc + apos, "%s", get_color(*buf)); - if(*buf & 0x80) apos += sprintf(asc + apos, "%s", inverse_on); - apos += sprintf(asc + apos, "%s", table[*buf & 0x7f]); - if(color || *buf & 0x80) apos += sprintf(asc + apos, "%s", color_off); + if(color) apos += sprintf(asc + apos, "%s", get_color(c)); + if(inv) apos += sprintf(asc + apos, "%s", inverse_on); + apos += sprintf(asc + apos, "%s", (graphics ? get_graphics(c) : table[c & 0x7f])); + if(color || inv) apos += sprintf(asc + apos, "%s", color_off); filepos++; buf++; @@ -245,7 +283,7 @@ int main(int argc, char **argv) { exit(0); } - while( (opt = getopt(argc, argv, "vhimus:o:l:")) != -1) { + while( (opt = getopt(argc, argv, "vhimus:o:l:g")) != -1) { switch(opt) { case 'v': verbose = 1; break; case 'h': print_help(); exit(0); break; @@ -255,6 +293,7 @@ int main(int argc, char **argv) { case 's': parse_seek_arg(optarg); break; case 'o': disp_offset = parse_offset_arg(optarg); break; case 'l': limit = parse_limit_arg(optarg); break; + case 'g': graphics = 1; break; default: print_help(); exit(1); break; } } |