diff options
author | XANTRONIX Development | 2023-09-10 23:34:52 -0400 |
---|---|---|
committer | XANTRONIX Development | 2023-09-10 23:34:52 -0400 |
commit | bd5268cd628d75dcf4214e7ee40f23904964baef (patch) | |
tree | 7ff39e0bcaf74c1f7a15f47069d7590f3c0c555b | |
parent | e1e296f8ee6b11b0f7c0af961fd12b3562595c68 (diff) | |
download | zxdump-bd5268cd628d75dcf4214e7ee40f23904964baef.tar.gz zxdump-bd5268cd628d75dcf4214e7ee40f23904964baef.tar.bz2 zxdump-bd5268cd628d75dcf4214e7ee40f23904964baef.zip |
Completely nail inverse video
-rw-r--r-- | main.c | 46 |
1 files changed, 34 insertions, 12 deletions
@@ -12,7 +12,7 @@ #define ZXDUMP_STRIDE_GROUP 2 #define ZXDUMP_CHARSET_LEN 64 -static uint16_t charset[ZXDUMP_CHARSET_LEN] = { +static uint32_t zx_charset[ZXDUMP_CHARSET_LEN] = { 0x0020, 0x2598, 0x259d, 0x2580, 0x2596, 0x258c, 0x259e, 0x259b, 0x2592, '.', '.', '"', 0x00a3, '$', ':', '?', '(', ')', '>', '<', '=', '+', '-', '*', @@ -63,7 +63,21 @@ static inline size_t utf8_encode(uint8_t *buf, uint32_t codepoint) { } } -static ssize_t dump_line(off_t offset, void *buf, size_t len) { +static inline int zx_putchar(uint8_t c) { + uint8_t sequence[4]; + size_t len = utf8_encode(sequence, zx_charset[c]); + + if (fwrite(sequence, len, 1, stdout) < 1) { + goto error_io; + } + + return 0; + +error_io: + return -1; +} + +static ssize_t dump_line(off_t offset, void *buf, size_t len, int tty) { size_t i; if (printf("%08zx: ", offset) < 0) { @@ -96,18 +110,26 @@ static ssize_t dump_line(off_t offset, void *buf, size_t len) { uint8_t c = ((uint8_t *)buf)[offset+i]; if (c < ZXDUMP_CHARSET_LEN) { - uint16_t codepoint = charset[c]; - uint8_t sequence[4]; - - size_t len = utf8_encode(sequence, codepoint); - - /* XXX: Implement support for inverse colours */ - if (fwrite(sequence, len, 1, stdout) < 1) { + if (zx_putchar(c) < 0) { goto error_io; } } else { - if (putchar('.') < 0) { - goto error_io; + if (c >= 0xa0 && c <= 0xbf) { + if (tty && printf("\033[7m") < 0) { + goto error_io; + } + + if (zx_putchar(c - 0xa0) < 0) { + goto error_io; + } + + if (tty && printf("\033[27m") < 0) { + goto error_io; + } + } else { + if (putchar('.') < 0) { + goto error_io; + } } } } @@ -148,7 +170,7 @@ static ssize_t dump_fd(int fd) { size_t left = len - i, linesz = left < ZXDUMP_STRIDE_LINE? left: ZXDUMP_STRIDE_LINE; - if (dump_line(offset, buf, linesz) < 0) { + if (dump_line(offset, buf, linesz, isatty(fileno(stdout))) < 0) { goto error_dump_line; } |